Fix scrolling item into view when using arrow keys

This commit is contained in:
Jason Rodney Hansen 2024-08-16 08:13:25 -06:00
parent aebc652006
commit 6def8b7f8b

View file

@ -924,6 +924,7 @@ pub struct Tab {
pub dialog: Option<DialogKind>, pub dialog: Option<DialogKind>,
pub scroll_opt: Option<AbsoluteOffset>, pub scroll_opt: Option<AbsoluteOffset>,
pub size_opt: Cell<Option<Size>>, pub size_opt: Cell<Option<Size>>,
pub item_view_size_opt: Cell<Option<Size>>,
pub edit_location: Option<Location>, pub edit_location: Option<Location>,
pub edit_location_id: widget::Id, pub edit_location_id: widget::Id,
pub history_i: usize, pub history_i: usize,
@ -950,6 +951,7 @@ impl Tab {
dialog: None, dialog: None,
scroll_opt: None, scroll_opt: None,
size_opt: Cell::new(None), size_opt: Cell::new(None),
item_view_size_opt: Cell::new(None),
edit_location: None, edit_location: None,
edit_location_id: widget::Id::unique(), edit_location_id: widget::Id::unique(),
history_i: 0, history_i: 0,
@ -1129,7 +1131,10 @@ impl Tab {
Some(offset) => Point::new(0.0, offset.y), Some(offset) => Point::new(0.0, offset.y),
None => Point::new(0.0, 0.0), None => Point::new(0.0, 0.0),
}; };
let size = self.size_opt.get().unwrap_or_else(|| Size::new(0.0, 0.0)); let size = self
.item_view_size_opt
.get()
.unwrap_or_else(|| Size::new(0.0, 0.0));
Rectangle::new(point, size) Rectangle::new(point, size)
}; };
@ -2517,9 +2522,16 @@ impl Tab {
} }
} }
} }
let spacer_height = height
.checked_sub(max_bottom + 7 * (space_xxs as usize)) let top_deduct = 7 * (space_xxs as usize);
.unwrap_or(0);
self.item_view_size_opt
.set(self.size_opt.get().map(|s| Size {
width: s.width,
height: s.height - top_deduct as f32,
}));
let spacer_height = height.checked_sub(max_bottom + top_deduct).unwrap_or(0);
if spacer_height > 0 { if spacer_height > 0 {
children.push( children.push(
widget::container(vertical_space(Length::Fixed(spacer_height as f32))) widget::container(vertical_space(Length::Fixed(spacer_height as f32)))
@ -2871,12 +2883,18 @@ impl Tab {
} }
//TODO: HACK If we don't reach the bottom of the view, go ahead and add a spacer to do that //TODO: HACK If we don't reach the bottom of the view, go ahead and add a spacer to do that
{ {
let spacer_height = let top_deduct = (if condensed { 6 } else { 9 }) * space_xxs;
size.height as i32 - y as i32 - (if condensed { 6 } else { 9 }) * space_xxs as i32;
if spacer_height > 0 { self.item_view_size_opt
children.push( .set(self.size_opt.get().map(|s| Size {
widget::container(vertical_space(Length::Fixed(spacer_height as f32))).into(), width: s.width,
); height: s.height - top_deduct as f32,
}));
let spacer_height = size.height - y as f32 - top_deduct as f32;
if spacer_height > 0. {
children
.push(widget::container(vertical_space(Length::Fixed(spacer_height))).into());
} }
} }
let drag_col = (!drag_items.is_empty()).then(|| { let drag_col = (!drag_items.is_empty()).then(|| {