Merge pull request #1649 from iced-rs/generic-widget-operations
Introduce `custom` method to `widget::Operation` trait
This commit is contained in:
commit
5ef0648bf4
4 changed files with 24 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ use crate::{
|
||||||
Clipboard, Color, Layout, Length, Point, Rectangle, Shell, Widget,
|
Clipboard, Color, Layout, Length, Point, Rectangle, Shell, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use std::any::Any;
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
|
|
||||||
/// A generic [`Widget`].
|
/// A generic [`Widget`].
|
||||||
|
|
@ -333,6 +334,10 @@ where
|
||||||
) {
|
) {
|
||||||
self.operation.text_input(state, id);
|
self.operation.text_input(state, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn custom(&mut self, state: &mut dyn Any, id: Option<&widget::Id>) {
|
||||||
|
self.operation.custom(state, id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.widget.operate(
|
self.widget.operate(
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ use crate::renderer;
|
||||||
use crate::widget;
|
use crate::widget;
|
||||||
use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size, Vector};
|
use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size, Vector};
|
||||||
|
|
||||||
|
use std::any::Any;
|
||||||
|
|
||||||
/// A generic [`Overlay`].
|
/// A generic [`Overlay`].
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct Element<'a, Message, Renderer> {
|
pub struct Element<'a, Message, Renderer> {
|
||||||
|
|
@ -188,6 +190,10 @@ where
|
||||||
) {
|
) {
|
||||||
self.operation.text_input(state, id)
|
self.operation.text_input(state, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn custom(&mut self, state: &mut dyn Any, id: Option<&widget::Id>) {
|
||||||
|
self.operation.custom(state, id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.content
|
self.content
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use crate::widget::Id;
|
||||||
|
|
||||||
use iced_futures::MaybeSend;
|
use iced_futures::MaybeSend;
|
||||||
|
|
||||||
|
use std::any::Any;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// An operation to be performed on the widget tree.
|
/// An operation to be performed on the widget tree.
|
||||||
|
|
@ -84,6 +85,10 @@ where
|
||||||
) {
|
) {
|
||||||
self.operation.focusable(state, id);
|
self.operation.focusable(state, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn custom(&mut self, state: &mut dyn Any, id: Option<&Id>) {
|
||||||
|
self.operation.custom(state, id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let Self { operation, .. } = self;
|
let Self { operation, .. } = self;
|
||||||
|
|
@ -118,6 +123,10 @@ where
|
||||||
self.operation.text_input(state, id);
|
self.operation.text_input(state, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn custom(&mut self, state: &mut dyn Any, id: Option<&Id>) {
|
||||||
|
self.operation.custom(state, id);
|
||||||
|
}
|
||||||
|
|
||||||
fn finish(&self) -> operation::Outcome<B> {
|
fn finish(&self) -> operation::Outcome<B> {
|
||||||
match self.operation.finish() {
|
match self.operation.finish() {
|
||||||
operation::Outcome::None => operation::Outcome::None,
|
operation::Outcome::None => operation::Outcome::None,
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ pub use text_input::TextInput;
|
||||||
|
|
||||||
use crate::widget::Id;
|
use crate::widget::Id;
|
||||||
|
|
||||||
|
use std::any::Any;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
/// A piece of logic that can traverse the widget tree of an application in
|
/// A piece of logic that can traverse the widget tree of an application in
|
||||||
|
|
@ -33,6 +34,9 @@ pub trait Operation<T> {
|
||||||
/// Operates on a widget that has text input.
|
/// Operates on a widget that has text input.
|
||||||
fn text_input(&mut self, _state: &mut dyn TextInput, _id: Option<&Id>) {}
|
fn text_input(&mut self, _state: &mut dyn TextInput, _id: Option<&Id>) {}
|
||||||
|
|
||||||
|
/// Operates on a custom widget with some state.
|
||||||
|
fn custom(&mut self, _state: &mut dyn Any, _id: Option<&Id>) {}
|
||||||
|
|
||||||
/// Finishes the [`Operation`] and returns its [`Outcome`].
|
/// Finishes the [`Operation`] and returns its [`Outcome`].
|
||||||
fn finish(&self) -> Outcome<T> {
|
fn finish(&self) -> Outcome<T> {
|
||||||
Outcome::None
|
Outcome::None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue