Remove a level of indirection, exposing the widget event on the top level.
This commit is contained in:
parent
0fd88e52da
commit
50c8310de5
2 changed files with 5 additions and 13 deletions
|
@ -40,7 +40,7 @@ impl Output {
|
||||||
// only describe last event:
|
// only describe last event:
|
||||||
if let Some(event) = self.events.iter().rev().next() {
|
if let Some(event) = self.events.iter().rev().next() {
|
||||||
match event {
|
match event {
|
||||||
OutputEvent::WidgetEvent(WidgetEvent::Focus, widget_info) => {
|
OutputEvent::FocusGained(widget_info) => {
|
||||||
return widget_info.description();
|
return widget_info.description();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,25 +205,17 @@ impl Default for CursorIcon {
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub enum OutputEvent {
|
pub enum OutputEvent {
|
||||||
/// A widget gained keyboard focus (by tab key).
|
/// A widget gained keyboard focus (by tab key).
|
||||||
WidgetEvent(WidgetEvent, WidgetInfo),
|
FocusGained(WidgetInfo),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for OutputEvent {
|
impl std::fmt::Debug for OutputEvent {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::WidgetEvent(we, wi) => write!(f, "{:?}: {:?}", we, wi),
|
Self::FocusGained(wi) => write!(f, "FocusGained({:?})", wi),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
||||||
pub enum WidgetEvent {
|
|
||||||
/// Keyboard focused moved onto the widget.
|
|
||||||
Focus,
|
|
||||||
// /// Started hovering a new widget.
|
|
||||||
// Hover, // TODO: cursor hovered events
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Describes a widget such as a [`crate::Button`] or a [`crate::TextEdit`].
|
/// Describes a widget such as a [`crate::Button`] or a [`crate::TextEdit`].
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct WidgetInfo {
|
pub struct WidgetInfo {
|
||||||
|
|
|
@ -429,9 +429,9 @@ impl Response {
|
||||||
/// Call after interacting and potential calls to [`Self::mark_changed`].
|
/// Call after interacting and potential calls to [`Self::mark_changed`].
|
||||||
pub fn widget_info(&self, make_info: impl Fn() -> crate::WidgetInfo) {
|
pub fn widget_info(&self, make_info: impl Fn() -> crate::WidgetInfo) {
|
||||||
if self.gained_focus() {
|
if self.gained_focus() {
|
||||||
use crate::output::{OutputEvent, WidgetEvent};
|
use crate::output::OutputEvent;
|
||||||
let widget_info = make_info();
|
let widget_info = make_info();
|
||||||
let event = OutputEvent::WidgetEvent(WidgetEvent::Focus, widget_info);
|
let event = OutputEvent::FocusGained(widget_info);
|
||||||
self.ctx.output().events.push(event);
|
self.ctx.output().events.push(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue