Refactor: remove has_kb_focus/lost_kb_focus bools from Reponse
Just forward the queries to Memory
This commit is contained in:
parent
4df8418e41
commit
6fd7c422ab
4 changed files with 10 additions and 25 deletions
|
@ -179,9 +179,6 @@ impl CtxRef {
|
||||||
) -> Response {
|
) -> Response {
|
||||||
let hovered = hovered && enabled; // can't even hover disabled widgets
|
let hovered = hovered && enabled; // can't even hover disabled widgets
|
||||||
|
|
||||||
let has_kb_focus = self.memory().has_kb_focus(id);
|
|
||||||
let lost_kb_focus = self.memory().lost_kb_focus(id);
|
|
||||||
|
|
||||||
let mut response = Response {
|
let mut response = Response {
|
||||||
ctx: self.clone(),
|
ctx: self.clone(),
|
||||||
layer_id,
|
layer_id,
|
||||||
|
@ -196,8 +193,6 @@ impl CtxRef {
|
||||||
drag_released: false,
|
drag_released: false,
|
||||||
is_pointer_button_down_on: false,
|
is_pointer_button_down_on: false,
|
||||||
interact_pointer_pos: None,
|
interact_pointer_pos: None,
|
||||||
has_kb_focus,
|
|
||||||
lost_kb_focus,
|
|
||||||
changed: false, // must be set by the widget itself
|
changed: false, // must be set by the widget itself
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -60,12 +60,6 @@ pub struct Response {
|
||||||
/// `None` if the widget is not being interacted with.
|
/// `None` if the widget is not being interacted with.
|
||||||
pub(crate) interact_pointer_pos: Option<Pos2>,
|
pub(crate) interact_pointer_pos: Option<Pos2>,
|
||||||
|
|
||||||
/// This widget has the keyboard focus (i.e. is receiving key presses).
|
|
||||||
pub(crate) has_kb_focus: bool,
|
|
||||||
|
|
||||||
/// The widget had keyboard focus and lost it.
|
|
||||||
pub(crate) lost_kb_focus: bool,
|
|
||||||
|
|
||||||
/// What the underlying data changed?
|
/// What the underlying data changed?
|
||||||
/// e.g. the slider was dragged, text was entered in a `TextEdit` etc.
|
/// e.g. the slider was dragged, text was entered in a `TextEdit` etc.
|
||||||
/// Always `false` for something like a `Button`.
|
/// Always `false` for something like a `Button`.
|
||||||
|
@ -88,8 +82,6 @@ impl std::fmt::Debug for Response {
|
||||||
drag_released,
|
drag_released,
|
||||||
is_pointer_button_down_on,
|
is_pointer_button_down_on,
|
||||||
interact_pointer_pos,
|
interact_pointer_pos,
|
||||||
has_kb_focus,
|
|
||||||
lost_kb_focus,
|
|
||||||
changed,
|
changed,
|
||||||
} = self;
|
} = self;
|
||||||
f.debug_struct("Response")
|
f.debug_struct("Response")
|
||||||
|
@ -105,8 +97,6 @@ impl std::fmt::Debug for Response {
|
||||||
.field("drag_released", drag_released)
|
.field("drag_released", drag_released)
|
||||||
.field("is_pointer_button_down_on", is_pointer_button_down_on)
|
.field("is_pointer_button_down_on", is_pointer_button_down_on)
|
||||||
.field("interact_pointer_pos", interact_pointer_pos)
|
.field("interact_pointer_pos", interact_pointer_pos)
|
||||||
.field("has_kb_focus", has_kb_focus)
|
|
||||||
.field("lost_kb_focus", lost_kb_focus)
|
|
||||||
.field("changed", changed)
|
.field("changed", changed)
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
@ -162,7 +152,12 @@ impl Response {
|
||||||
|
|
||||||
/// This widget has the keyboard focus (i.e. is receiving key presses).
|
/// This widget has the keyboard focus (i.e. is receiving key presses).
|
||||||
pub fn has_kb_focus(&self) -> bool {
|
pub fn has_kb_focus(&self) -> bool {
|
||||||
self.has_kb_focus
|
self.ctx.memory().has_kb_focus(self.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// True if this widget has keyboard focus this frame, but didn't last frame.
|
||||||
|
pub fn gained_kb_focus(&self) -> bool {
|
||||||
|
self.ctx.memory().gained_kb_focus(self.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The widget had keyboard focus and lost it,
|
/// The widget had keyboard focus and lost it,
|
||||||
|
@ -179,7 +174,7 @@ impl Response {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn lost_kb_focus(&self) -> bool {
|
pub fn lost_kb_focus(&self) -> bool {
|
||||||
self.lost_kb_focus
|
self.ctx.memory().lost_kb_focus(self.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The widgets is being dragged.
|
/// The widgets is being dragged.
|
||||||
|
@ -374,8 +369,6 @@ impl Response {
|
||||||
is_pointer_button_down_on: self.is_pointer_button_down_on
|
is_pointer_button_down_on: self.is_pointer_button_down_on
|
||||||
|| other.is_pointer_button_down_on,
|
|| other.is_pointer_button_down_on,
|
||||||
interact_pointer_pos: self.interact_pointer_pos.or(other.interact_pointer_pos),
|
interact_pointer_pos: self.interact_pointer_pos.or(other.interact_pointer_pos),
|
||||||
has_kb_focus: self.has_kb_focus || other.has_kb_focus,
|
|
||||||
lost_kb_focus: self.lost_kb_focus || other.lost_kb_focus,
|
|
||||||
changed: self.changed || other.changed,
|
changed: self.changed || other.changed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,7 +243,7 @@ pub struct Widgets {
|
||||||
|
|
||||||
impl Widgets {
|
impl Widgets {
|
||||||
pub fn style(&self, response: &Response) -> &WidgetVisuals {
|
pub fn style(&self, response: &Response) -> &WidgetVisuals {
|
||||||
if response.is_pointer_button_down_on() || response.has_kb_focus {
|
if response.is_pointer_button_down_on() || response.has_kb_focus() {
|
||||||
&self.active
|
&self.active
|
||||||
} else if response.hovered() {
|
} else if response.hovered() {
|
||||||
&self.hovered
|
&self.hovered
|
||||||
|
|
|
@ -248,7 +248,7 @@ impl<'t> Widget for TextEdit<'t> {
|
||||||
if frame {
|
if frame {
|
||||||
let visuals = ui.style().interact(&response);
|
let visuals = ui.style().interact(&response);
|
||||||
let frame_rect = response.rect.expand(visuals.expansion);
|
let frame_rect = response.rect.expand(visuals.expansion);
|
||||||
let shape = if response.has_kb_focus {
|
let shape = if response.has_kb_focus() {
|
||||||
Shape::Rect {
|
Shape::Rect {
|
||||||
rect: frame_rect,
|
rect: frame_rect,
|
||||||
corner_radius: visuals.corner_radius,
|
corner_radius: visuals.corner_radius,
|
||||||
|
@ -541,10 +541,7 @@ impl<'t> TextEdit<'t> {
|
||||||
|
|
||||||
ui.memory().text_edit.insert(id, state);
|
ui.memory().text_edit.insert(id, state);
|
||||||
|
|
||||||
Response {
|
response
|
||||||
lost_kb_focus: ui.memory().lost_kb_focus(id), // we may have lost it during the course of this function
|
|
||||||
..response
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue