all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer] tui: fix incorrect scrolling of form view contents
Date: Thu,  6 Jul 2023 14:27:50 +0200	[thread overview]
Message-ID: <20230706122801.253855-1-c.heiss@proxmox.com> (raw)

See the inline comment for what & why.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-tui-installer/src/views/mod.rs | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/proxmox-tui-installer/src/views/mod.rs b/proxmox-tui-installer/src/views/mod.rs
index b1a1a13..3426294 100644
--- a/proxmox-tui-installer/src/views/mod.rs
+++ b/proxmox-tui-installer/src/views/mod.rs
@@ -4,7 +4,7 @@ use cursive::{
     event::{Event, EventResult},
     view::{Resizable, ViewWrapper},
     views::{EditView, LinearLayout, NamedView, ResizedView, SelectView, TextView},
-    View,
+    Rect, Vec2, View,
 };
 
 use crate::utils::CidrAddress;
@@ -367,6 +367,22 @@ impl FormView {
 
 impl ViewWrapper for FormView {
     cursive::wrap_impl!(self.view: LinearLayout);
+
+    fn wrap_important_area(&self, size: Vec2) -> Rect {
+        // This fixes scrolling on small screen when many elements are present, e.g. bootdisk/RAID
+        // list. Without this, scrolling completely down and then back up would not properly
+        // display the currently selected form element.
+        // tl;dr: For whatever reason, the inner `LinearLayout` calculates the rect with a line
+        // height of 2. So e.g. if the first form element is selected, the y-coordinate is 2, if
+        // the second is selected it is 4 and so on. Knowing that, this can fortunately be quite
+        // easy fixed by just dividing the y-coordinate by 2 and adjusting the size of the area
+        // rectanglo to 1.
+
+        let inner = self.view.important_area(size);
+        let top_left = inner.top_left().map_y(|y| y / 2);
+
+        Rect::from_size(top_left, (inner.width(), 1))
+    }
 }
 
 pub struct CidrAddressEditView {
-- 
2.41.0





             reply	other threads:[~2023-07-06 12:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-06 12:27 Christoph Heiss [this message]
2023-07-13 13:54 ` [pve-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230706122801.253855-1-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal