Refactor: remove has_kb_focus/lost_kb_focus bools from Reponse

Just forward the queries to Memory
This commit is contained in:
Emil Ernerfeldt 2021-03-07 13:06:47 +01:00
parent 4df8418e41
commit 6fd7c422ab
4 changed files with 10 additions and 25 deletions

View file

@ -179,9 +179,6 @@ impl CtxRef {
) -> Response {
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 {
ctx: self.clone(),
layer_id,
@ -196,8 +193,6 @@ impl CtxRef {
drag_released: false,
is_pointer_button_down_on: false,
interact_pointer_pos: None,
has_kb_focus,
lost_kb_focus,
changed: false, // must be set by the widget itself
};

View file

@ -60,12 +60,6 @@ pub struct Response {
/// `None` if the widget is not being interacted with.
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?
/// e.g. the slider was dragged, text was entered in a `TextEdit` etc.
/// Always `false` for something like a `Button`.
@ -88,8 +82,6 @@ impl std::fmt::Debug for Response {
drag_released,
is_pointer_button_down_on,
interact_pointer_pos,
has_kb_focus,
lost_kb_focus,
changed,
} = self;
f.debug_struct("Response")
@ -105,8 +97,6 @@ impl std::fmt::Debug for Response {
.field("drag_released", drag_released)
.field("is_pointer_button_down_on", is_pointer_button_down_on)
.field("interact_pointer_pos", interact_pointer_pos)
.field("has_kb_focus", has_kb_focus)
.field("lost_kb_focus", lost_kb_focus)
.field("changed", changed)
.finish()
}
@ -162,7 +152,12 @@ impl Response {
/// This widget has the keyboard focus (i.e. is receiving key presses).
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,
@ -179,7 +174,7 @@ impl Response {
/// }
/// ```
pub fn lost_kb_focus(&self) -> bool {
self.lost_kb_focus
self.ctx.memory().lost_kb_focus(self.id)
}
/// The widgets is being dragged.
@ -374,8 +369,6 @@ impl Response {
is_pointer_button_down_on: self.is_pointer_button_down_on
|| other.is_pointer_button_down_on,
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,
}
}

View file

@ -243,7 +243,7 @@ pub struct Widgets {
impl Widgets {
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
} else if response.hovered() {
&self.hovered

View file

@ -248,7 +248,7 @@ impl<'t> Widget for TextEdit<'t> {
if frame {
let visuals = ui.style().interact(&response);
let frame_rect = response.rect.expand(visuals.expansion);
let shape = if response.has_kb_focus {
let shape = if response.has_kb_focus() {
Shape::Rect {
rect: frame_rect,
corner_radius: visuals.corner_radius,
@ -541,10 +541,7 @@ impl<'t> TextEdit<'t> {
ui.memory().text_edit.insert(id, state);
Response {
lost_kb_focus: ui.memory().lost_kb_focus(id), // we may have lost it during the course of this function
..response
}
response
}
}