Introduce selector flag and decouple iced_widget from iced_runtime
This commit is contained in:
parent
34a42b5ad4
commit
81d1eda7fe
22 changed files with 118 additions and 67 deletions
88
runtime/src/widget/operation.rs
Normal file
88
runtime/src/widget/operation.rs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
//! Change internal widget state.
|
||||
use crate::core::widget::Id;
|
||||
use crate::core::widget::operation;
|
||||
use crate::task;
|
||||
use crate::{Action, Task};
|
||||
|
||||
pub use crate::core::widget::operation::scrollable::{
|
||||
AbsoluteOffset, RelativeOffset,
|
||||
};
|
||||
|
||||
/// Snaps the scrollable with the given [`Id`] to the provided [`RelativeOffset`].
|
||||
pub fn snap_to<T>(id: impl Into<Id>, offset: RelativeOffset) -> Task<T> {
|
||||
task::effect(Action::widget(operation::scrollable::snap_to(
|
||||
id.into(),
|
||||
offset,
|
||||
)))
|
||||
}
|
||||
|
||||
/// Snaps the scrollable with the given [`Id`] to the [`RelativeOffset::END`].
|
||||
pub fn snap_to_end<T>(id: impl Into<Id>) -> Task<T> {
|
||||
task::effect(Action::widget(operation::scrollable::snap_to(
|
||||
id.into(),
|
||||
RelativeOffset::END,
|
||||
)))
|
||||
}
|
||||
|
||||
/// Scrolls the scrollable with the given [`Id`] to the provided [`AbsoluteOffset`].
|
||||
pub fn scroll_to<T>(id: impl Into<Id>, offset: AbsoluteOffset) -> Task<T> {
|
||||
task::effect(Action::widget(operation::scrollable::scroll_to(
|
||||
id.into(),
|
||||
offset,
|
||||
)))
|
||||
}
|
||||
|
||||
/// Scrolls the scrollable with the given [`Id`] by the provided [`AbsoluteOffset`].
|
||||
pub fn scroll_by<T>(id: impl Into<Id>, offset: AbsoluteOffset) -> Task<T> {
|
||||
task::effect(Action::widget(operation::scrollable::scroll_by(
|
||||
id.into(),
|
||||
offset,
|
||||
)))
|
||||
}
|
||||
|
||||
/// Focuses the previous focusable widget.
|
||||
pub fn focus_previous<T>() -> Task<T> {
|
||||
task::effect(Action::widget(operation::focusable::focus_previous()))
|
||||
}
|
||||
|
||||
/// Focuses the next focusable widget.
|
||||
pub fn focus_next<T>() -> Task<T> {
|
||||
task::effect(Action::widget(operation::focusable::focus_next()))
|
||||
}
|
||||
|
||||
/// Returns whether the widget with the given [`Id`] is focused or not.
|
||||
pub fn is_focused(id: impl Into<Id>) -> Task<bool> {
|
||||
task::widget(operation::focusable::is_focused(id.into()))
|
||||
}
|
||||
|
||||
/// Focuses the widget with the given [`Id`].
|
||||
pub fn focus<T>(id: impl Into<Id>) -> Task<T> {
|
||||
task::effect(Action::widget(operation::focusable::focus(id.into())))
|
||||
}
|
||||
|
||||
/// Moves the cursor of the widget with the given [`Id`] to the end.
|
||||
pub fn move_cursor_to_end<T>(id: impl Into<Id>) -> Task<T> {
|
||||
task::effect(Action::widget(operation::text_input::move_cursor_to_end(
|
||||
id.into(),
|
||||
)))
|
||||
}
|
||||
|
||||
/// Moves the cursor of the widget with the given [`Id`] to the front.
|
||||
pub fn move_cursor_to_front<T>(id: impl Into<Id>) -> Task<T> {
|
||||
task::effect(Action::widget(operation::text_input::move_cursor_to_front(
|
||||
id.into(),
|
||||
)))
|
||||
}
|
||||
|
||||
/// Moves the cursor of the widget with the given [`Id`] to the provided position.
|
||||
pub fn move_cursor_to<T>(id: impl Into<Id>, position: usize) -> Task<T> {
|
||||
task::effect(Action::widget(operation::text_input::move_cursor_to(
|
||||
id.into(),
|
||||
position,
|
||||
)))
|
||||
}
|
||||
|
||||
/// Selects all the content of the widget with the given [`Id`].
|
||||
pub fn select_all<T>(id: impl Into<Id>) -> Task<T> {
|
||||
task::effect(Action::widget(operation::text_input::select_all(id.into())))
|
||||
}
|
||||
18
runtime/src/widget/selector.rs
Normal file
18
runtime/src/widget/selector.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
//! Find and query widgets in your applications.
|
||||
pub use iced_selector::Selector;
|
||||
|
||||
pub use iced_selector::target::{Bounded, Match, Target, Text};
|
||||
|
||||
use crate::Task;
|
||||
use crate::core::widget;
|
||||
use crate::task;
|
||||
|
||||
/// Finds a widget by the given [`widget::Id`].
|
||||
pub fn find_by_id(id: impl Into<widget::Id>) -> Task<Option<Match>> {
|
||||
task::widget(id.into().find())
|
||||
}
|
||||
|
||||
/// Finds a widget that contains the given text.
|
||||
pub fn find_by_text(text: impl Into<String>) -> Task<Option<Text>> {
|
||||
task::widget(Selector::find(text.into()))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue