]> git.proxmox.com Git - pve-installer.git/commitdiff
tui: fix incorrect scrolling of form view contents
authorChristoph Heiss <c.heiss@proxmox.com>
Thu, 6 Jul 2023 12:27:50 +0000 (14:27 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 13 Jul 2023 13:51:02 +0000 (15:51 +0200)
See the inline comment for what & why.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
proxmox-tui-installer/src/views/mod.rs

index b1a1a138ff4cbf6ada25b9d49c9591b85493cb52..3426294fc5ea02a487918d365d9458d42d2acb4d 100644 (file)
@@ -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 {