Drag scroll area background to scroll

This commit is contained in:
Emil Ernerfeldt 2020-04-22 17:38:36 +02:00
parent dbf8520e63
commit 0b61d952e6
2 changed files with 21 additions and 2 deletions

View file

@ -13,8 +13,14 @@ This is the core library crate Emigui. It is fully platform independent without
* [x] Movable/resizable windows
* [ ] Kinetic windows
* [ ] Scroll areas
* [x] Vertical scrolling
* [ ] Horizontal scrolling
* [ ] Scroll-wheel input
* [x] Drag background to scroll
* [ ] Kinetic scrolling
* [ ] Menu bar (File, Edit, etc)
* [ ] One-line TextField
* [ ] Clipboard copy/paste
* [ ] Color picker
* [ ] Style editor
@ -45,6 +51,8 @@ I think A) is the correct solution, but might be tedious to get right for every
* [ ] Draw as hotmap
### Names and structure
* [ ] Rename things to be more consistent with Dear ImGui
* Foldable -> Collapsible etc
* [ ] Combine Emigui and Context
* [ ] Rename Region to something shorter?
* `region: &Region` `region.add(...)` :/

View file

@ -51,6 +51,16 @@ impl ScrollArea {
add_contents(&mut content_region);
let content_size = content_region.bounding_size;
let content_interact = ctx.interact(
outer_region.layer,
inner_rect,
Some(scroll_area_id.with("area")),
);
if content_interact.active {
// Dragging scroll area to scroll:
state.offset.y -= ctx.input.mouse_move.y;
}
let show_scroll = content_size.y > inner_size.y;
if show_scroll {
let corner_radius = scroll_bar_width / 2.0;
@ -103,8 +113,6 @@ impl ScrollArea {
if inner_rect.min().y <= mouse_pos.y && mouse_pos.y <= inner_rect.max().y {
state.offset.y +=
ctx.input.mouse_move.y * content_size.y / inner_rect.height();
state.offset.y = state.offset.y.max(0.0);
state.offset.y = state.offset.y.min(content_size.y - inner_rect.height());
}
}
}
@ -132,6 +140,9 @@ impl ScrollArea {
let size = content_size.min(content_region.clip_rect.size());
outer_region.reserve_space_without_padding(size);
state.offset.y = state.offset.y.max(0.0);
state.offset.y = state.offset.y.min(content_size.y - inner_rect.height());
outer_region
.ctx()
.memory