//! 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( id: impl Into, offset: impl Into>>, ) -> Task { task::effect(Action::widget(operation::scrollable::snap_to( id.into(), offset.into(), ))) } /// Snaps the scrollable with the given [`Id`] to the [`RelativeOffset::END`]. pub fn snap_to_end(id: impl Into) -> Task { task::effect(Action::widget(operation::scrollable::snap_to( id.into(), RelativeOffset::END.into(), ))) } /// Scrolls the scrollable with the given [`Id`] to the provided [`AbsoluteOffset`]. pub fn scroll_to( id: impl Into, offset: impl Into>>, ) -> Task { task::effect(Action::widget(operation::scrollable::scroll_to( id.into(), offset.into(), ))) } /// Scrolls the scrollable with the given [`Id`] by the provided [`AbsoluteOffset`]. pub fn scroll_by(id: impl Into, offset: AbsoluteOffset) -> Task { task::effect(Action::widget(operation::scrollable::scroll_by( id.into(), offset, ))) } /// Focuses the previous focusable widget. pub fn focus_previous() -> Task { task::effect(Action::widget(operation::focusable::focus_previous())) } /// Focuses the next focusable widget. pub fn focus_next() -> Task { 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) -> Task { task::widget(operation::focusable::is_focused(id.into())) } /// Focuses the widget with the given [`Id`]. pub fn focus(id: impl Into) -> Task { 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(id: impl Into) -> Task { 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(id: impl Into) -> Task { 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(id: impl Into, position: usize) -> Task { 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(id: impl Into) -> Task { task::effect(Action::widget(operation::text_input::select_all(id.into()))) } /// Selects the given content range of the widget with the given [`Id`]. pub fn select_range(id: impl Into, start: usize, end: usize) -> Task { task::effect(Action::widget(operation::text_input::select_range( id.into(), start, end, ))) }