Add Response::request_focus and surrender_focus
This commit is contained in:
parent
daf2e13238
commit
96a2732735
3 changed files with 15 additions and 1 deletions
|
@ -9,6 +9,7 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [
|
|||
|
||||
### Added ⭐
|
||||
* Make labels interactive with `Label::sense(Sense::click())`.
|
||||
* Add `Response::request_focus` and `Response::surrender_focus`.
|
||||
|
||||
### Fixed 🐛
|
||||
* Fix [defocus-bug on touch screens](https://github.com/emilk/egui/issues/288)
|
||||
|
|
|
@ -300,11 +300,14 @@ impl Memory {
|
|||
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) {
|
||||
self.interaction.focus.id = Some(id);
|
||||
}
|
||||
|
||||
/// Surrender keyboard focus for a specific widget.
|
||||
/// See also [`crate::Response::surrender_focus`].
|
||||
#[inline(always)]
|
||||
pub fn surrender_focus(&mut self, id: Id) {
|
||||
if self.interaction.focus.id == Some(id) {
|
||||
|
|
|
@ -199,6 +199,16 @@ impl Response {
|
|||
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.
|
||||
///
|
||||
/// To find out which button(s), query [`crate::PointerState::button_down`]
|
||||
|
|
Loading…
Reference in a new issue