[refactor] small cleanup and typo fixes
This commit is contained in:
parent
0bbf7edaee
commit
b02530b6fb
4 changed files with 28 additions and 16 deletions
|
@ -32,8 +32,8 @@ impl Default for State {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
pub fn from_memory_with_default_open(ui: &Ui, id: Id, default_open: bool) -> Self {
|
pub fn from_memory_with_default_open(ctx: &Context, id: Id, default_open: bool) -> Self {
|
||||||
*ui.memory().collapsing_headers.entry(id).or_insert(State {
|
*ctx.memory().collapsing_headers.entry(id).or_insert(State {
|
||||||
open: default_open,
|
open: default_open,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
@ -112,7 +112,7 @@ impl State {
|
||||||
} else {
|
} else {
|
||||||
// First frame of expansion.
|
// First frame of expansion.
|
||||||
// We don't know full height yet, but we will next frame.
|
// 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
|
10.0
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -215,7 +215,7 @@ impl CollapsingHeader {
|
||||||
let interact = ui.interact(rect, id, Sense::click());
|
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 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 {
|
if interact.clicked {
|
||||||
state.toggle(ui);
|
state.toggle(ui);
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,7 +244,7 @@ impl<'open> Window<'open> {
|
||||||
|
|
||||||
let default_expanded = true;
|
let default_expanded = true;
|
||||||
let mut collapsing = collapsing_header::State::from_memory_with_default_open(
|
let mut collapsing = collapsing_header::State::from_memory_with_default_open(
|
||||||
&frame.content_ui,
|
ctx,
|
||||||
collapsing_id,
|
collapsing_id,
|
||||||
default_expanded,
|
default_expanded,
|
||||||
);
|
);
|
||||||
|
|
|
@ -55,7 +55,7 @@ impl RawInput {
|
||||||
/// What egui maintains
|
/// What egui maintains
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct InputState {
|
pub struct InputState {
|
||||||
/// The raw input we got this fraem
|
/// The raw input we got this frame
|
||||||
pub raw: RawInput,
|
pub raw: RawInput,
|
||||||
|
|
||||||
pub mouse: MouseInput,
|
pub mouse: MouseInput,
|
||||||
|
@ -339,7 +339,7 @@ impl RawInput {
|
||||||
ui.add(label!("screen_size: {:?} points", self.screen_size));
|
ui.add(label!("screen_size: {:?} points", self.screen_size));
|
||||||
ui.add(label!("pixels_per_point: {:?}", self.pixels_per_point))
|
ui.add(label!("pixels_per_point: {:?}", self.pixels_per_point))
|
||||||
.tooltip_text(
|
.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!("time: {:.3} s", self.time));
|
||||||
ui.add(label!(
|
ui.add(label!(
|
||||||
|
|
|
@ -52,9 +52,14 @@ impl Default for CursorIcon {
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
// #[cfg_attr(feature = "serde", derive(serde::Serialize))]
|
// #[cfg_attr(feature = "serde", derive(serde::Serialize))]
|
||||||
pub struct InteractInfo {
|
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).
|
/// The senses (click or drag) that the widget is interested in (if any).
|
||||||
pub sense: Sense,
|
pub sense: Sense,
|
||||||
|
|
||||||
|
// OUT:
|
||||||
/// The mouse is hovering above this thing
|
/// The mouse is hovering above this thing
|
||||||
pub hovered: bool,
|
pub hovered: bool,
|
||||||
|
|
||||||
|
@ -68,33 +73,37 @@ pub struct InteractInfo {
|
||||||
|
|
||||||
/// This widget has the keyboard focus (i.e. is receiving key pressed)
|
/// This widget has the keyboard focus (i.e. is receiving key pressed)
|
||||||
pub has_kb_focus: bool,
|
pub has_kb_focus: bool,
|
||||||
|
|
||||||
/// The region of the screen we are talking about
|
|
||||||
pub rect: Rect,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InteractInfo {
|
impl InteractInfo {
|
||||||
pub fn nothing() -> Self {
|
pub fn nothing() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
rect: Rect::nothing(),
|
||||||
sense: Sense::nothing(),
|
sense: Sense::nothing(),
|
||||||
hovered: false,
|
hovered: false,
|
||||||
clicked: false,
|
clicked: false,
|
||||||
double_clicked: false,
|
double_clicked: false,
|
||||||
active: false,
|
active: false,
|
||||||
has_kb_focus: 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 {
|
pub fn union(self, other: Self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
rect: self.rect.union(other.rect),
|
||||||
sense: self.sense.union(other.sense),
|
sense: self.sense.union(other.sense),
|
||||||
hovered: self.hovered || other.hovered,
|
hovered: self.hovered || other.hovered,
|
||||||
clicked: self.clicked || other.clicked,
|
clicked: self.clicked || other.clicked,
|
||||||
double_clicked: self.double_clicked || other.double_clicked,
|
double_clicked: self.double_clicked || other.double_clicked,
|
||||||
active: self.active || other.active,
|
active: self.active || other.active,
|
||||||
has_kb_focus: self.has_kb_focus || other.has_kb_focus,
|
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.
|
/// This lets you know whether or not a widget has been clicked this frame.
|
||||||
/// It also lets you easily show a tooltip on hover.
|
/// It also lets you easily show a tooltip on hover.
|
||||||
pub struct GuiResponse {
|
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).
|
/// The senses (click or drag) that the widget is interested in (if any).
|
||||||
pub sense: Sense,
|
pub sense: Sense,
|
||||||
|
|
||||||
|
// OUT:
|
||||||
/// The mouse is hovering above this
|
/// The mouse is hovering above this
|
||||||
pub hovered: bool,
|
pub hovered: bool,
|
||||||
|
|
||||||
|
@ -123,9 +137,7 @@ pub struct GuiResponse {
|
||||||
/// This widget has the keyboard focus (i.e. is receiving key pressed)
|
/// This widget has the keyboard focus (i.e. is receiving key pressed)
|
||||||
pub has_kb_focus: bool,
|
pub has_kb_focus: bool,
|
||||||
|
|
||||||
/// The area of the screen we are talking about
|
// CONTEXT:
|
||||||
pub rect: Rect,
|
|
||||||
|
|
||||||
/// Used for optionally showing a tooltip
|
/// Used for optionally showing a tooltip
|
||||||
pub ctx: Arc<Context>,
|
pub ctx: Arc<Context>,
|
||||||
}
|
}
|
||||||
|
@ -150,13 +162,13 @@ impl GuiResponse {
|
||||||
impl Into<InteractInfo> for GuiResponse {
|
impl Into<InteractInfo> for GuiResponse {
|
||||||
fn into(self) -> InteractInfo {
|
fn into(self) -> InteractInfo {
|
||||||
InteractInfo {
|
InteractInfo {
|
||||||
|
rect: self.rect,
|
||||||
sense: self.sense,
|
sense: self.sense,
|
||||||
hovered: self.hovered,
|
hovered: self.hovered,
|
||||||
clicked: self.clicked,
|
clicked: self.clicked,
|
||||||
double_clicked: self.double_clicked,
|
double_clicked: self.double_clicked,
|
||||||
active: self.active,
|
active: self.active,
|
||||||
has_kb_focus: self.has_kb_focus,
|
has_kb_focus: self.has_kb_focus,
|
||||||
rect: self.rect,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue