diff --git a/emigui/README.md b/emigui/README.md index 97928b7d..f4a5c64b 100644 --- a/emigui/README.md +++ b/emigui/README.md @@ -80,7 +80,10 @@ Add extremely quick animations for some things, maybe 2-3 frames. For instance: ### Names and structure * [ ] Rename things to be more consistent with Dear ImGui -* [ ] Combine Emigui and Context +* [ ] Combine Emigui and Context? +* [ ] Solve which parts of Context are behind a mutex + * [ ] All of Context behind one mutex? + * [ } Break up Context into Input, State, Output ? * [ ] Rename Region to something shorter? * `region: &Region` `region.add(...)` :/ * `gui: &Gui` `gui.add(...)` :) diff --git a/emigui/src/containers/collapsing_header.rs b/emigui/src/containers/collapsing_header.rs index 2f399605..e2416dad 100644 --- a/emigui/src/containers/collapsing_header.rs +++ b/emigui/src/containers/collapsing_header.rs @@ -68,7 +68,7 @@ impl CollapsingHeader { }); if interact.clicked { state.open = !state.open; - state.toggle_time = region.ctx.input.time; + state.toggle_time = region.ctx.input().time; } *state }; @@ -93,7 +93,7 @@ impl CollapsingHeader { ); let animation_time = region.style().animation_time; - let time_since_toggle = (region.ctx.input.time - state.toggle_time) as f32; + let time_since_toggle = (region.ctx.input().time - state.toggle_time) as f32; let animate = time_since_toggle < animation_time; if animate { region.indent(id, |region| { diff --git a/emigui/src/containers/floating.rs b/emigui/src/containers/floating.rs index e6d176e7..c91985c3 100644 --- a/emigui/src/containers/floating.rs +++ b/emigui/src/containers/floating.rs @@ -101,8 +101,8 @@ impl Floating { let margin = 32.0; state.pos = state.pos.max(pos2(margin - state.size.x, 0.0)); state.pos = state.pos.min(pos2( - ctx.input.screen_size.x - margin, - ctx.input.screen_size.y - margin, + ctx.input().screen_size.x - margin, + ctx.input().screen_size.y - margin, )); state.pos = state.pos.round(); @@ -115,8 +115,8 @@ impl Floating { } fn mouse_pressed_on_floating(ctx: &Context, id: Id) -> bool { - if let Some(mouse_pos) = ctx.input.mouse_pos { - ctx.input.mouse_pressed && ctx.memory().layer_at(mouse_pos) == Layer::Window(id) + if let Some(mouse_pos) = ctx.input().mouse_pos { + ctx.input().mouse_pressed && ctx.memory().layer_at(mouse_pos) == Layer::Window(id) } else { false } diff --git a/emigui/src/containers/scroll_area.rs b/emigui/src/containers/scroll_area.rs index 3e1560d9..ac53e234 100644 --- a/emigui/src/containers/scroll_area.rs +++ b/emigui/src/containers/scroll_area.rs @@ -101,12 +101,12 @@ impl ScrollArea { let content_interact = outer_region.interact_rect(&inner_rect, scroll_area_id.with("area")); if content_interact.active { // Dragging scroll area to scroll: - state.offset.y -= ctx.input.mouse_move.y; + state.offset.y -= ctx.input().mouse_move.y; } // TODO: check that nothing else is being inteacted with if outer_region.contains_mouse(&outer_rect) && ctx.memory().active_id.is_none() { - state.offset.y -= ctx.input.scroll_delta.y; + state.offset.y -= ctx.input().scroll_delta.y; } let show_scroll_this_frame = content_size.y > inner_size.y || self.always_show_scroll; @@ -134,11 +134,11 @@ impl ScrollArea { let interact_id = scroll_area_id.with("vertical"); let handle_interact = outer_region.interact_rect(&handle_rect, interact_id); - if let Some(mouse_pos) = ctx.input.mouse_pos { + if let Some(mouse_pos) = ctx.input().mouse_pos { if handle_interact.active { if inner_rect.top() <= mouse_pos.y && mouse_pos.y <= inner_rect.bottom() { state.offset.y += - ctx.input.mouse_move.y * content_size.y / inner_rect.height(); + ctx.input().mouse_move.y * content_size.y / inner_rect.height(); } } else { // Check for mouse down outside handle: diff --git a/emigui/src/context.rs b/emigui/src/context.rs index 63090332..123cdfc2 100644 --- a/emigui/src/context.rs +++ b/emigui/src/context.rs @@ -5,21 +5,26 @@ use parking_lot::Mutex; use crate::{layout::align_rect, *}; /// Contains the input, style and output of all GUI commands. +/// Regions keep an Arc pointer to this. +/// This allows us to create several child regions at once, +/// all working against the same shared Context. pub struct Context { /// The default style for new regions - pub(crate) style: Mutex