Browse Source

Add Response::request_focus and surrender_focus

pull/309/head
Emil Ernerfeldt 4 years ago
parent
commit
96a2732735
  1. 1
      CHANGELOG.md
  2. 5
      egui/src/memory.rs
  3. 10
      egui/src/response.rs

1
CHANGELOG.md

@ -9,6 +9,7 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [
### Added ⭐ ### Added ⭐
* Make labels interactive with `Label::sense(Sense::click())`. * Make labels interactive with `Label::sense(Sense::click())`.
* Add `Response::request_focus` and `Response::surrender_focus`.
### Fixed 🐛 ### Fixed 🐛
* Fix [defocus-bug on touch screens](https://github.com/emilk/egui/issues/288) * Fix [defocus-bug on touch screens](https://github.com/emilk/egui/issues/288)

5
egui/src/memory.rs

@ -300,11 +300,14 @@ impl Memory {
self.interaction.focus.id == Some(id) self.interaction.focus.id == Some(id)
} }
/// Give keyboard focus to a specific widget /// Give keyboard focus to a specific widget.
/// See also [`crate::Response::request_focus`].
pub fn request_focus(&mut self, id: Id) { pub fn request_focus(&mut self, id: Id) {
self.interaction.focus.id = Some(id); self.interaction.focus.id = Some(id);
} }
/// Surrender keyboard focus for a specific widget.
/// See also [`crate::Response::surrender_focus`].
#[inline(always)] #[inline(always)]
pub fn surrender_focus(&mut self, id: Id) { pub fn surrender_focus(&mut self, id: Id) {
if self.interaction.focus.id == Some(id) { if self.interaction.focus.id == Some(id) {

10
egui/src/response.rs

@ -199,6 +199,16 @@ impl Response {
self.lost_focus() self.lost_focus()
} }
/// Request that this widget get keyboard focus.
pub fn request_focus(&self) {
self.ctx.memory().request_focus(self.id)
}
/// Surrender keyboard focus for this widget.
pub fn surrender_focus(&self) {
self.ctx.memory().surrender_focus(self.id)
}
/// The widgets is being dragged. /// The widgets is being dragged.
/// ///
/// To find out which button(s), query [`crate::PointerState::button_down`] /// To find out which button(s), query [`crate::PointerState::button_down`]

Loading…
Cancel
Save