[refactor] small cleanup and typo fixes

This commit is contained in:
Emil Ernerfeldt 2020-08-28 16:15:51 +02:00
parent 0bbf7edaee
commit b02530b6fb
4 changed files with 28 additions and 16 deletions

View file

@ -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);
}

View file

@ -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,
);

View file

@ -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!(

View file

@ -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<Context>,
}
@ -150,13 +162,13 @@ impl GuiResponse {
impl Into<InteractInfo> 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,
}
}
}