From b02530b6fb555e5ae8e9bab2b3f25cd3b1ebf0f9 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 28 Aug 2020 16:15:51 +0200 Subject: [PATCH] [refactor] small cleanup and typo fixes --- egui/src/containers/collapsing_header.rs | 8 +++---- egui/src/containers/window.rs | 2 +- egui/src/input.rs | 4 ++-- egui/src/types.rs | 30 +++++++++++++++++------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/egui/src/containers/collapsing_header.rs b/egui/src/containers/collapsing_header.rs index 88270d64..e50dbb38 100644 --- a/egui/src/containers/collapsing_header.rs +++ b/egui/src/containers/collapsing_header.rs @@ -32,8 +32,8 @@ impl Default for State { } impl State { - pub fn from_memory_with_default_open(ui: &Ui, id: Id, default_open: bool) -> Self { - *ui.memory().collapsing_headers.entry(id).or_insert(State { + pub fn from_memory_with_default_open(ctx: &Context, id: Id, default_open: bool) -> Self { + *ctx.memory().collapsing_headers.entry(id).or_insert(State { open: default_open, ..Default::default() }) @@ -112,7 +112,7 @@ impl State { } else { // First frame of expansion. // We don't know full height yet, but we will next frame. - // Just use a placehodler value that shows some movement: + // Just use a placeholder value that shows some movement: 10.0 } } else { @@ -215,7 +215,7 @@ impl CollapsingHeader { let interact = ui.interact(rect, id, Sense::click()); let text_pos = pos2(text_pos.x, interact.rect.center().y - galley.size.y / 2.0); - let mut state = State::from_memory_with_default_open(ui, id, default_open); + let mut state = State::from_memory_with_default_open(ui.ctx(), id, default_open); if interact.clicked { state.toggle(ui); } diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index 027962fd..f217f75c 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -244,7 +244,7 @@ impl<'open> Window<'open> { let default_expanded = true; let mut collapsing = collapsing_header::State::from_memory_with_default_open( - &frame.content_ui, + ctx, collapsing_id, default_expanded, ); diff --git a/egui/src/input.rs b/egui/src/input.rs index 630edaff..371f656f 100644 --- a/egui/src/input.rs +++ b/egui/src/input.rs @@ -55,7 +55,7 @@ impl RawInput { /// What egui maintains #[derive(Clone, Debug, Default)] pub struct InputState { - /// The raw input we got this fraem + /// The raw input we got this frame pub raw: RawInput, pub mouse: MouseInput, @@ -339,7 +339,7 @@ impl RawInput { ui.add(label!("screen_size: {:?} points", self.screen_size)); ui.add(label!("pixels_per_point: {:?}", self.pixels_per_point)) .tooltip_text( - "Also called hdpi factor.\nNumber of physical pixels per each logical pixel.", + "Also called HDPI factor.\nNumber of physical pixels per each logical pixel.", ); ui.add(label!("time: {:.3} s", self.time)); ui.add(label!( diff --git a/egui/src/types.rs b/egui/src/types.rs index 82a49d21..0474fca8 100644 --- a/egui/src/types.rs +++ b/egui/src/types.rs @@ -52,9 +52,14 @@ impl Default for CursorIcon { #[derive(Clone, Copy, Debug)] // #[cfg_attr(feature = "serde", derive(serde::Serialize))] pub struct InteractInfo { + // IN: + /// The region of the screen we are talking about + pub rect: Rect, + /// The senses (click or drag) that the widget is interested in (if any). pub sense: Sense, + // OUT: /// The mouse is hovering above this thing pub hovered: bool, @@ -68,33 +73,37 @@ pub struct InteractInfo { /// This widget has the keyboard focus (i.e. is receiving key pressed) pub has_kb_focus: bool, - - /// The region of the screen we are talking about - pub rect: Rect, } impl InteractInfo { pub fn nothing() -> Self { Self { + rect: Rect::nothing(), sense: Sense::nothing(), hovered: false, clicked: false, double_clicked: false, active: false, has_kb_focus: false, - rect: Rect::nothing(), + } + } + + pub fn from_rect(rect: Rect) -> Self { + Self { + rect, + ..Self::nothing() } } pub fn union(self, other: Self) -> Self { Self { + rect: self.rect.union(other.rect), sense: self.sense.union(other.sense), hovered: self.hovered || other.hovered, clicked: self.clicked || other.clicked, double_clicked: self.double_clicked || other.double_clicked, active: self.active || other.active, has_kb_focus: self.has_kb_focus || other.has_kb_focus, - rect: self.rect.union(other.rect), } } } @@ -106,9 +115,14 @@ impl InteractInfo { /// This lets you know whether or not a widget has been clicked this frame. /// It also lets you easily show a tooltip on hover. pub struct GuiResponse { + // IN: + /// The area of the screen we are talking about + pub rect: Rect, + /// The senses (click or drag) that the widget is interested in (if any). pub sense: Sense, + // OUT: /// The mouse is hovering above this pub hovered: bool, @@ -123,9 +137,7 @@ pub struct GuiResponse { /// This widget has the keyboard focus (i.e. is receiving key pressed) pub has_kb_focus: bool, - /// The area of the screen we are talking about - pub rect: Rect, - + // CONTEXT: /// Used for optionally showing a tooltip pub ctx: Arc, } @@ -150,13 +162,13 @@ impl GuiResponse { impl Into for GuiResponse { fn into(self) -> InteractInfo { InteractInfo { + rect: self.rect, sense: self.sense, hovered: self.hovered, clicked: self.clicked, double_clicked: self.double_clicked, active: self.active, has_kb_focus: self.has_kb_focus, - rect: self.rect, } } }