Make Widget::on_event return an event::Status
This commit is contained in:
parent
1db11ba69a
commit
3f968b8c87
20 changed files with 136 additions and 70 deletions
|
|
@ -4,9 +4,11 @@
|
|||
//!
|
||||
//! [`Button`]: struct.Button.html
|
||||
//! [`State`]: struct.State.html
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::{
|
||||
layout, mouse, Clipboard, Element, Event, Hasher, Layout, Length, Point,
|
||||
Rectangle, Widget,
|
||||
Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Widget,
|
||||
};
|
||||
use std::hash::Hash;
|
||||
|
||||
|
|
@ -184,7 +186,7 @@ where
|
|||
messages: &mut Vec<Message>,
|
||||
_renderer: &Renderer,
|
||||
_clipboard: Option<&dyn Clipboard>,
|
||||
) {
|
||||
) -> event::Status {
|
||||
match event {
|
||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
|
||||
if self.on_press.is_some() {
|
||||
|
|
@ -209,6 +211,8 @@ where
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
//! Show toggle controls using checkboxes.
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::row;
|
||||
use crate::text;
|
||||
use crate::{
|
||||
layout, mouse, row, text, Align, Clipboard, Element, Event, Hasher,
|
||||
HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text,
|
||||
VerticalAlignment, Widget,
|
||||
Align, Clipboard, Element, Hasher, HorizontalAlignment, Layout, Length,
|
||||
Point, Rectangle, Row, Text, VerticalAlignment, Widget,
|
||||
};
|
||||
|
||||
/// A box that can be checked.
|
||||
|
|
@ -161,7 +165,7 @@ where
|
|||
messages: &mut Vec<Message>,
|
||||
_renderer: &Renderer,
|
||||
_clipboard: Option<&dyn Clipboard>,
|
||||
) {
|
||||
) -> event::Status {
|
||||
match event {
|
||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
|
||||
let mouse_over = layout.bounds().contains(cursor_position);
|
||||
|
|
@ -172,6 +176,8 @@ where
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
//! Distribute content vertically.
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::overlay;
|
||||
use crate::{
|
||||
Align, Clipboard, Element, Event, Hasher, Layout, Length, Point, Rectangle,
|
||||
Widget,
|
||||
Align, Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Widget,
|
||||
};
|
||||
|
||||
use std::u32;
|
||||
|
|
@ -162,19 +162,21 @@ where
|
|||
messages: &mut Vec<Message>,
|
||||
renderer: &Renderer,
|
||||
clipboard: Option<&dyn Clipboard>,
|
||||
) {
|
||||
) -> event::Status {
|
||||
self.children.iter_mut().zip(layout.children()).for_each(
|
||||
|(child, layout)| {
|
||||
child.widget.on_event(
|
||||
let _ = child.widget.on_event(
|
||||
event.clone(),
|
||||
layout,
|
||||
cursor_position,
|
||||
messages,
|
||||
renderer,
|
||||
clipboard,
|
||||
)
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
//! Decorate content and apply alignment.
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::overlay;
|
||||
use crate::{
|
||||
layout, overlay, Align, Clipboard, Element, Event, Hasher, Layout, Length,
|
||||
Point, Rectangle, Widget,
|
||||
Align, Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Widget,
|
||||
};
|
||||
|
||||
use std::u32;
|
||||
|
|
@ -174,7 +176,7 @@ where
|
|||
messages: &mut Vec<Message>,
|
||||
renderer: &Renderer,
|
||||
clipboard: Option<&dyn Clipboard>,
|
||||
) {
|
||||
) -> event::Status {
|
||||
self.content.widget.on_event(
|
||||
event,
|
||||
layout.children().next().unwrap(),
|
||||
|
|
|
|||
|
|
@ -28,9 +28,16 @@ pub use split::Split;
|
|||
pub use state::{Focus, State};
|
||||
pub use title_bar::TitleBar;
|
||||
|
||||
use crate::container;
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::overlay;
|
||||
use crate::row;
|
||||
use crate::text;
|
||||
use crate::{
|
||||
container, layout, mouse, overlay, row, text, Clipboard, Element, Event,
|
||||
Hasher, Layout, Length, Point, Rectangle, Size, Vector, Widget,
|
||||
Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Vector,
|
||||
Widget,
|
||||
};
|
||||
|
||||
/// A collection of panes distributed using either vertical or horizontal splits
|
||||
|
|
@ -386,7 +393,7 @@ where
|
|||
messages: &mut Vec<Message>,
|
||||
renderer: &Renderer,
|
||||
clipboard: Option<&dyn Clipboard>,
|
||||
) {
|
||||
) -> event::Status {
|
||||
match event {
|
||||
Event::Mouse(mouse_event) => match mouse_event {
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left) => {
|
||||
|
|
@ -484,6 +491,8 @@ where
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ where
|
|||
layout
|
||||
};
|
||||
|
||||
self.body.on_event(
|
||||
let _ = self.body.on_event(
|
||||
event,
|
||||
body_layout,
|
||||
cursor_position,
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@ where
|
|||
let _ = children.next();
|
||||
let controls_layout = children.next().unwrap();
|
||||
|
||||
controls.on_event(
|
||||
let _ = controls.on_event(
|
||||
event,
|
||||
controls_layout,
|
||||
cursor_position,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
//! Display a dropdown list of selectable values.
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::overlay;
|
||||
use crate::overlay::menu::{self, Menu};
|
||||
use crate::scrollable;
|
||||
use crate::text;
|
||||
use crate::{
|
||||
layout, mouse, overlay,
|
||||
overlay::menu::{self, Menu},
|
||||
scrollable, text, Clipboard, Element, Event, Hasher, Layout, Length, Point,
|
||||
Rectangle, Size, Widget,
|
||||
Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
|
||||
|
|
@ -223,7 +227,7 @@ where
|
|||
messages: &mut Vec<Message>,
|
||||
_renderer: &Renderer,
|
||||
_clipboard: Option<&dyn Clipboard>,
|
||||
) {
|
||||
) -> event::Status {
|
||||
match event {
|
||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
|
||||
if *self.is_open {
|
||||
|
|
@ -248,6 +252,8 @@ where
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
//! Create choices using radio buttons.
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::row;
|
||||
use crate::text;
|
||||
use crate::{
|
||||
layout, mouse, row, text, Align, Clipboard, Element, Event, Hasher,
|
||||
HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text,
|
||||
VerticalAlignment, Widget,
|
||||
Align, Clipboard, Element, Hasher, HorizontalAlignment, Layout, Length,
|
||||
Point, Rectangle, Row, Text, VerticalAlignment, Widget,
|
||||
};
|
||||
|
||||
use std::hash::Hash;
|
||||
|
|
@ -166,7 +170,7 @@ where
|
|||
messages: &mut Vec<Message>,
|
||||
_renderer: &Renderer,
|
||||
_clipboard: Option<&dyn Clipboard>,
|
||||
) {
|
||||
) -> event::Status {
|
||||
match event {
|
||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
|
||||
if layout.bounds().contains(cursor_position) {
|
||||
|
|
@ -175,6 +179,8 @@ where
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
//! Distribute content horizontally.
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::overlay;
|
||||
use crate::{
|
||||
Align, Clipboard, Element, Event, Hasher, Layout, Length, Point, Rectangle,
|
||||
Widget,
|
||||
Align, Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Widget,
|
||||
};
|
||||
|
||||
use std::hash::Hash;
|
||||
|
|
@ -162,19 +162,21 @@ where
|
|||
messages: &mut Vec<Message>,
|
||||
renderer: &Renderer,
|
||||
clipboard: Option<&dyn Clipboard>,
|
||||
) {
|
||||
) -> event::Status {
|
||||
self.children.iter_mut().zip(layout.children()).for_each(
|
||||
|(child, layout)| {
|
||||
child.widget.on_event(
|
||||
let _ = child.widget.on_event(
|
||||
event.clone(),
|
||||
layout,
|
||||
cursor_position,
|
||||
messages,
|
||||
renderer,
|
||||
clipboard,
|
||||
)
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
//! Navigate an endless amount of content with a scrollbar.
|
||||
use crate::column;
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::overlay;
|
||||
use crate::{
|
||||
column, layout, mouse, overlay, Align, Clipboard, Column, Element, Event,
|
||||
Hasher, Layout, Length, Point, Rectangle, Size, Vector, Widget,
|
||||
Align, Clipboard, Column, Element, Hasher, Layout, Length, Point,
|
||||
Rectangle, Size, Vector, Widget,
|
||||
};
|
||||
|
||||
use std::{f32, hash::Hash, u32};
|
||||
|
|
@ -184,7 +189,7 @@ where
|
|||
messages: &mut Vec<Message>,
|
||||
renderer: &Renderer,
|
||||
clipboard: Option<&dyn Clipboard>,
|
||||
) {
|
||||
) -> event::Status {
|
||||
let bounds = layout.bounds();
|
||||
let is_mouse_over = bounds.contains(cursor_position);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@
|
|||
//!
|
||||
//! [`Slider`]: struct.Slider.html
|
||||
//! [`State`]: struct.State.html
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::{
|
||||
layout, mouse, Clipboard, Element, Event, Hasher, Layout, Length, Point,
|
||||
Rectangle, Size, Widget,
|
||||
Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
|
||||
};
|
||||
|
||||
use std::{hash::Hash, ops::RangeInclusive};
|
||||
|
|
@ -202,7 +204,7 @@ where
|
|||
messages: &mut Vec<Message>,
|
||||
_renderer: &Renderer,
|
||||
_clipboard: Option<&dyn Clipboard>,
|
||||
) {
|
||||
) -> event::Status {
|
||||
let mut change = || {
|
||||
let bounds = layout.bounds();
|
||||
if cursor_position.x <= bounds.x {
|
||||
|
|
@ -251,6 +253,8 @@ where
|
|||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
|
|||
|
|
@ -14,11 +14,13 @@ pub use value::Value;
|
|||
|
||||
use editor::Editor;
|
||||
|
||||
use crate::event::{self, Event};
|
||||
use crate::keyboard;
|
||||
use crate::layout;
|
||||
use crate::mouse::{self, click};
|
||||
use crate::text;
|
||||
use crate::{
|
||||
keyboard, layout,
|
||||
mouse::{self, click},
|
||||
text, Clipboard, Element, Event, Hasher, Layout, Length, Point, Rectangle,
|
||||
Size, Widget,
|
||||
Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
|
||||
};
|
||||
|
||||
use std::u32;
|
||||
|
|
@ -218,7 +220,7 @@ where
|
|||
messages: &mut Vec<Message>,
|
||||
renderer: &Renderer,
|
||||
clipboard: Option<&dyn Clipboard>,
|
||||
) {
|
||||
) -> event::Status {
|
||||
match event {
|
||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
|
||||
let is_clicked = layout.bounds().contains(cursor_position);
|
||||
|
|
@ -489,6 +491,8 @@ where
|
|||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue