Add support for click and double-click events.
This commit is contained in:
parent
b3ced6106b
commit
8269cca95d
2 changed files with 23 additions and 4 deletions
|
@ -40,6 +40,12 @@ impl Output {
|
|||
// only describe last event:
|
||||
if let Some(event) = self.events.iter().rev().next() {
|
||||
match event {
|
||||
OutputEvent::Clicked(widget_info) => {
|
||||
return widget_info.description();
|
||||
}
|
||||
OutputEvent::DoubleClicked(widget_info) => {
|
||||
return widget_info.description();
|
||||
}
|
||||
OutputEvent::FocusGained(widget_info) => {
|
||||
return widget_info.description();
|
||||
}
|
||||
|
@ -204,6 +210,10 @@ impl Default for CursorIcon {
|
|||
/// In particular, these events may be useful for accessability, i.e. for screen readers.
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum OutputEvent {
|
||||
// A widget was clicked.
|
||||
Clicked(WidgetInfo),
|
||||
// A widget was double-clicked.
|
||||
DoubleClicked(WidgetInfo),
|
||||
/// A widget gained keyboard focus (by tab key).
|
||||
FocusGained(WidgetInfo),
|
||||
}
|
||||
|
@ -211,6 +221,8 @@ pub enum OutputEvent {
|
|||
impl std::fmt::Debug for OutputEvent {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Clicked(wi) => write!(f, "Clicked({:?})", wi),
|
||||
Self::DoubleClicked(wi) => write!(f, "DoubleClicked({:?})", wi),
|
||||
Self::FocusGained(wi) => write!(f, "FocusGained({:?})", wi),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -428,10 +428,17 @@ impl Response {
|
|||
///
|
||||
/// Call after interacting and potential calls to [`Self::mark_changed`].
|
||||
pub fn widget_info(&self, make_info: impl Fn() -> crate::WidgetInfo) {
|
||||
if self.gained_focus() {
|
||||
use crate::output::OutputEvent;
|
||||
let widget_info = make_info();
|
||||
let event = OutputEvent::FocusGained(widget_info);
|
||||
use crate::output::OutputEvent;
|
||||
let event = if self.clicked() {
|
||||
Some(OutputEvent::Clicked(make_info()))
|
||||
} else if self.double_clicked() {
|
||||
Some(OutputEvent::DoubleClicked(make_info()))
|
||||
} else if self.gained_focus() {
|
||||
Some(OutputEvent::FocusGained(make_info()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(event) = event {
|
||||
self.ctx.output().events.push(event);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue