Skip to content

Commit fbde666

Browse files
Enabled horizontal scrolling for select_focus_scroll()
1 parent 05b88ff commit fbde666

1 file changed

Lines changed: 64 additions & 26 deletions

File tree

src/tab.rs

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3398,35 +3398,73 @@ impl Tab {
33983398
let items = self.items_opt.as_ref()?;
33993399
let item = items.get(self.select_focus?)?;
34003400
let rect = item.rect_opt.get()?;
3401+
3402+
// Horizontal scrollbar
3403+
if self.config.view == View::Column {
34013404

3402-
//TODO: move to function
3403-
let visible_rect = {
3404-
let point = match self.scroll_opt {
3405-
Some(offset) => Point::new(0.0, offset.y),
3406-
None => Point::new(0.0, 0.0),
3405+
//TODO: move to function
3406+
let visible_rect = {
3407+
let point = match self.scroll_opt {
3408+
Some(offset) => Point::new(offset.x, 0.0),
3409+
None => Point::new(0.0, 0.0),
3410+
};
3411+
let size = self
3412+
.item_view_size_opt
3413+
.get()
3414+
.unwrap_or_else(|| Size::new(0.0, 0.0));
3415+
Rectangle::new(point, size)
34073416
};
3408-
let size = self
3409-
.item_view_size_opt
3410-
.get()
3411-
.unwrap_or_else(|| Size::new(0.0, 0.0));
3412-
Rectangle::new(point, size)
3413-
};
34143417

3415-
if rect.y < visible_rect.y {
3416-
// Scroll up to rect
3417-
self.scroll_opt = Some(AbsoluteOffset { x: 0.0, y: rect.y });
3418-
self.scroll_opt
3419-
} else if (rect.y + rect.height) > (visible_rect.y + visible_rect.height) {
3420-
// Scroll down to rect
3421-
self.scroll_opt = Some(AbsoluteOffset {
3422-
x: 0.0,
3423-
y: rect.y + rect.height - visible_rect.height,
3424-
});
3425-
self.scroll_opt
3426-
} else {
3427-
// Do not scroll
3428-
None
3418+
if rect.x < visible_rect.x {
3419+
// Scroll left to rect
3420+
self.scroll_opt = Some(AbsoluteOffset { x: rect.x, y: 0.0 });
3421+
self.scroll_opt
3422+
} else if (rect.x + rect.width) > (visible_rect.x + visible_rect.width) {
3423+
// Scroll right to rect
3424+
self.scroll_opt = Some(AbsoluteOffset {
3425+
x: rect.x + rect.width - visible_rect.width,
3426+
y: 0.0,
3427+
});
3428+
self.scroll_opt
3429+
} else {
3430+
// Do not scroll
3431+
None
3432+
}
34293433
}
3434+
3435+
// Vertical scrollbar
3436+
else {
3437+
3438+
//TODO: move to function
3439+
let visible_rect = {
3440+
let point = match self.scroll_opt {
3441+
Some(offset) => Point::new(0.0, offset.y),
3442+
None => Point::new(0.0, 0.0),
3443+
};
3444+
let size = self
3445+
.item_view_size_opt
3446+
.get()
3447+
.unwrap_or_else(|| Size::new(0.0, 0.0));
3448+
Rectangle::new(point, size)
3449+
};
3450+
3451+
if rect.y < visible_rect.y {
3452+
// Scroll up to rect
3453+
self.scroll_opt = Some(AbsoluteOffset { x: 0.0, y: rect.y });
3454+
self.scroll_opt
3455+
} else if (rect.y + rect.height) > (visible_rect.y + visible_rect.height) {
3456+
// Scroll down to rect
3457+
self.scroll_opt = Some(AbsoluteOffset {
3458+
x: 0.0,
3459+
y: rect.y + rect.height - visible_rect.height,
3460+
});
3461+
self.scroll_opt
3462+
} else {
3463+
// Do not scroll
3464+
None
3465+
}
3466+
}
3467+
34303468
}
34313469

34323470
fn rows_per_page(&self) -> usize {
@@ -5002,7 +5040,7 @@ impl Tab {
50025040
}
50035041
}
50045042

5005-
// Scroll to top if needed
5043+
// Scroll to top-left if needed
50065044
if self.scroll_opt.is_none() {
50075045
let offset = AbsoluteOffset { x: 0.0, y: 0.0 };
50085046
self.scroll_opt = Some(offset);

0 commit comments

Comments
 (0)