Remove Id for container, scrollable, and text_input
This commit is contained in:
parent
63142d34fc
commit
fbe60feb7e
9 changed files with 68 additions and 179 deletions
|
|
@ -29,6 +29,12 @@ impl From<&'static str> for Id {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<String> for Id {
|
||||||
|
fn from(value: String) -> Self {
|
||||||
|
Self::new(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
enum Internal {
|
enum Internal {
|
||||||
Unique(usize),
|
Unique(usize),
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,6 @@ use iced::widget::{
|
||||||
};
|
};
|
||||||
use iced::{Border, Center, Color, Element, Fill, Task, Theme};
|
use iced::{Border, Center, Color, Element, Fill, Task, Theme};
|
||||||
|
|
||||||
use std::sync::LazyLock;
|
|
||||||
|
|
||||||
static SCROLLABLE_ID: LazyLock<scrollable::Id> =
|
|
||||||
LazyLock::new(scrollable::Id::unique);
|
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
iced::application(
|
iced::application(
|
||||||
ScrollableDemo::default,
|
ScrollableDemo::default,
|
||||||
|
|
@ -65,19 +60,13 @@ impl ScrollableDemo {
|
||||||
self.current_scroll_offset = scrollable::RelativeOffset::START;
|
self.current_scroll_offset = scrollable::RelativeOffset::START;
|
||||||
self.scrollable_direction = direction;
|
self.scrollable_direction = direction;
|
||||||
|
|
||||||
scrollable::snap_to(
|
scrollable::snap_to(SCROLLABLE, self.current_scroll_offset)
|
||||||
SCROLLABLE_ID.clone(),
|
|
||||||
self.current_scroll_offset,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Message::AlignmentChanged(alignment) => {
|
Message::AlignmentChanged(alignment) => {
|
||||||
self.current_scroll_offset = scrollable::RelativeOffset::START;
|
self.current_scroll_offset = scrollable::RelativeOffset::START;
|
||||||
self.anchor = alignment;
|
self.anchor = alignment;
|
||||||
|
|
||||||
scrollable::snap_to(
|
scrollable::snap_to(SCROLLABLE, self.current_scroll_offset)
|
||||||
SCROLLABLE_ID.clone(),
|
|
||||||
self.current_scroll_offset,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Message::ScrollbarWidthChanged(width) => {
|
Message::ScrollbarWidthChanged(width) => {
|
||||||
self.scrollbar_width = width;
|
self.scrollbar_width = width;
|
||||||
|
|
@ -97,18 +86,12 @@ impl ScrollableDemo {
|
||||||
Message::ScrollToBeginning => {
|
Message::ScrollToBeginning => {
|
||||||
self.current_scroll_offset = scrollable::RelativeOffset::START;
|
self.current_scroll_offset = scrollable::RelativeOffset::START;
|
||||||
|
|
||||||
scrollable::snap_to(
|
scrollable::snap_to(SCROLLABLE, self.current_scroll_offset)
|
||||||
SCROLLABLE_ID.clone(),
|
|
||||||
self.current_scroll_offset,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Message::ScrollToEnd => {
|
Message::ScrollToEnd => {
|
||||||
self.current_scroll_offset = scrollable::RelativeOffset::END;
|
self.current_scroll_offset = scrollable::RelativeOffset::END;
|
||||||
|
|
||||||
scrollable::snap_to(
|
scrollable::snap_to(SCROLLABLE, self.current_scroll_offset)
|
||||||
SCROLLABLE_ID.clone(),
|
|
||||||
self.current_scroll_offset,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Message::Scrolled(viewport) => {
|
Message::Scrolled(viewport) => {
|
||||||
self.current_scroll_offset = viewport.relative_offset();
|
self.current_scroll_offset = viewport.relative_offset();
|
||||||
|
|
@ -226,7 +209,7 @@ impl ScrollableDemo {
|
||||||
))
|
))
|
||||||
.width(Fill)
|
.width(Fill)
|
||||||
.height(Fill)
|
.height(Fill)
|
||||||
.id(SCROLLABLE_ID.clone())
|
.id(SCROLLABLE)
|
||||||
.on_scroll(Message::Scrolled),
|
.on_scroll(Message::Scrolled),
|
||||||
Direction::Horizontal => scrollable(
|
Direction::Horizontal => scrollable(
|
||||||
row![
|
row![
|
||||||
|
|
@ -252,7 +235,7 @@ impl ScrollableDemo {
|
||||||
))
|
))
|
||||||
.width(Fill)
|
.width(Fill)
|
||||||
.height(Fill)
|
.height(Fill)
|
||||||
.id(SCROLLABLE_ID.clone())
|
.id(SCROLLABLE)
|
||||||
.on_scroll(Message::Scrolled),
|
.on_scroll(Message::Scrolled),
|
||||||
Direction::Multi => scrollable(
|
Direction::Multi => scrollable(
|
||||||
//horizontal content
|
//horizontal content
|
||||||
|
|
@ -299,7 +282,7 @@ impl ScrollableDemo {
|
||||||
})
|
})
|
||||||
.width(Fill)
|
.width(Fill)
|
||||||
.height(Fill)
|
.height(Fill)
|
||||||
.id(SCROLLABLE_ID.clone())
|
.id(SCROLLABLE)
|
||||||
.on_scroll(Message::Scrolled),
|
.on_scroll(Message::Scrolled),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -348,3 +331,5 @@ fn progress_bar_custom_style(theme: &Theme) -> progress_bar::Style {
|
||||||
border: Border::default(),
|
border: Border::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SCROLLABLE: &str = "scrollable";
|
||||||
|
|
|
||||||
|
|
@ -305,8 +305,8 @@ pub enum TaskMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Task {
|
impl Task {
|
||||||
fn text_input_id(i: usize) -> text_input::Id {
|
fn text_input_id(i: usize) -> widget::Id {
|
||||||
text_input::Id::new(format!("task-{i}"))
|
widget::Id::new(format!("task-{i}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(description: String) -> Self {
|
fn new(description: String) -> Self {
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ impl Example {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
Message::Scrolled | Message::WindowResized => Task::batch(vec![
|
Message::Scrolled | Message::WindowResized => Task::batch(vec![
|
||||||
container::visible_bounds(OUTER_CONTAINER.clone())
|
container::visible_bounds(OUTER_CONTAINER)
|
||||||
.map(Message::OuterBoundsFetched),
|
.map(Message::OuterBoundsFetched),
|
||||||
container::visible_bounds(INNER_CONTAINER.clone())
|
container::visible_bounds(INNER_CONTAINER)
|
||||||
.map(Message::InnerBoundsFetched),
|
.map(Message::InnerBoundsFetched),
|
||||||
]),
|
]),
|
||||||
Message::OuterBoundsFetched(outer_bounds) => {
|
Message::OuterBoundsFetched(outer_bounds) => {
|
||||||
|
|
@ -113,7 +113,7 @@ impl Example {
|
||||||
text("Scroll me!"),
|
text("Scroll me!"),
|
||||||
vertical_space().height(400),
|
vertical_space().height(400),
|
||||||
container(text("I am the outer container!"))
|
container(text("I am the outer container!"))
|
||||||
.id(OUTER_CONTAINER.clone())
|
.id(OUTER_CONTAINER)
|
||||||
.padding(40)
|
.padding(40)
|
||||||
.style(container::rounded_box),
|
.style(container::rounded_box),
|
||||||
vertical_space().height(400),
|
vertical_space().height(400),
|
||||||
|
|
@ -122,7 +122,7 @@ impl Example {
|
||||||
text("Scroll me!"),
|
text("Scroll me!"),
|
||||||
vertical_space().height(400),
|
vertical_space().height(400),
|
||||||
container(text("I am the inner container!"))
|
container(text("I am the inner container!"))
|
||||||
.id(INNER_CONTAINER.clone())
|
.id(INNER_CONTAINER)
|
||||||
.padding(40)
|
.padding(40)
|
||||||
.style(container::rounded_box),
|
.style(container::rounded_box),
|
||||||
vertical_space().height(400),
|
vertical_space().height(400),
|
||||||
|
|
@ -157,9 +157,5 @@ impl Example {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::sync::LazyLock;
|
const OUTER_CONTAINER: &str = "outer";
|
||||||
|
const INNER_CONTAINER: &str = "inner";
|
||||||
static OUTER_CONTAINER: LazyLock<container::Id> =
|
|
||||||
LazyLock::new(|| container::Id::new("outer"));
|
|
||||||
static INNER_CONTAINER: LazyLock<container::Id> =
|
|
||||||
LazyLock::new(|| container::Id::new("inner"));
|
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ use iced::widget::{
|
||||||
};
|
};
|
||||||
use iced::{Center, Element, Fill, Subscription, Task, color};
|
use iced::{Center, Element, Fill, Subscription, Task, color};
|
||||||
|
|
||||||
use std::sync::LazyLock;
|
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
iced::application(WebSocket::new, WebSocket::update, WebSocket::view)
|
iced::application(WebSocket::new, WebSocket::update, WebSocket::view)
|
||||||
.subscription(WebSocket::subscription)
|
.subscription(WebSocket::subscription)
|
||||||
|
|
@ -76,7 +74,7 @@ impl WebSocket {
|
||||||
self.messages.push(message);
|
self.messages.push(message);
|
||||||
|
|
||||||
scrollable::snap_to(
|
scrollable::snap_to(
|
||||||
MESSAGE_LOG.clone(),
|
MESSAGE_LOG,
|
||||||
scrollable::RelativeOffset::END,
|
scrollable::RelativeOffset::END,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +103,7 @@ impl WebSocket {
|
||||||
column(self.messages.iter().map(text).map(Element::from))
|
column(self.messages.iter().map(text).map(Element::from))
|
||||||
.spacing(10),
|
.spacing(10),
|
||||||
)
|
)
|
||||||
.id(MESSAGE_LOG.clone())
|
.id(MESSAGE_LOG)
|
||||||
.height(Fill)
|
.height(Fill)
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.into()
|
.into()
|
||||||
|
|
@ -142,5 +140,4 @@ enum State {
|
||||||
Connected(echo::Connection),
|
Connected(echo::Connection),
|
||||||
}
|
}
|
||||||
|
|
||||||
static MESSAGE_LOG: LazyLock<scrollable::Id> =
|
const MESSAGE_LOG: &str = "message_log";
|
||||||
LazyLock::new(scrollable::Id::unique);
|
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ impl Selector for Id {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn description(&self) -> String {
|
fn description(&self) -> String {
|
||||||
format!("id == \"{:?}\"", self)
|
format!("id == {:?}", self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ pub struct Container<
|
||||||
Theme: Catalog,
|
Theme: Catalog,
|
||||||
Renderer: core::Renderer,
|
Renderer: core::Renderer,
|
||||||
{
|
{
|
||||||
id: Option<Id>,
|
id: Option<widget::Id>,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
|
|
@ -108,7 +108,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the [`Id`] of the [`Container`].
|
/// Sets the [`Id`] of the [`Container`].
|
||||||
pub fn id(mut self, id: impl Into<Id>) -> Self {
|
pub fn id(mut self, id: impl Into<widget::Id>) -> Self {
|
||||||
self.id = Some(id.into());
|
self.id = Some(id.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
@ -284,7 +284,7 @@ where
|
||||||
renderer: &Renderer,
|
renderer: &Renderer,
|
||||||
operation: &mut dyn Operation,
|
operation: &mut dyn Operation,
|
||||||
) {
|
) {
|
||||||
operation.container(self.id.as_ref().map(|id| &id.0), layout.bounds());
|
operation.container(self.id.as_ref(), layout.bounds());
|
||||||
operation.traverse(&mut |operation| {
|
operation.traverse(&mut |operation| {
|
||||||
self.content.as_widget().operate(
|
self.content.as_widget().operate(
|
||||||
tree,
|
tree,
|
||||||
|
|
@ -457,39 +457,9 @@ pub fn draw_background<Renderer>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The identifier of a [`Container`].
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub struct Id(widget::Id);
|
|
||||||
|
|
||||||
impl Id {
|
|
||||||
/// Creates a custom [`Id`].
|
|
||||||
pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
|
|
||||||
Self(widget::Id::new(id))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a unique [`Id`].
|
|
||||||
///
|
|
||||||
/// This function produces a different [`Id`] every time it is called.
|
|
||||||
pub fn unique() -> Self {
|
|
||||||
Self(widget::Id::unique())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Id> for widget::Id {
|
|
||||||
fn from(id: Id) -> Self {
|
|
||||||
id.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&'static str> for Id {
|
|
||||||
fn from(value: &'static str) -> Self {
|
|
||||||
Id::new(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Produces a [`Task`] that queries the visible screen bounds of the
|
/// Produces a [`Task`] that queries the visible screen bounds of the
|
||||||
/// [`Container`] with the given [`Id`].
|
/// [`Container`] with the given [`Id`].
|
||||||
pub fn visible_bounds(_id: impl Into<Id>) -> Task<Option<Rectangle>> {
|
pub fn visible_bounds(_id: impl Into<widget::Id>) -> Task<Option<Rectangle>> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ pub struct Scrollable<
|
||||||
Theme: Catalog,
|
Theme: Catalog,
|
||||||
Renderer: core::Renderer,
|
Renderer: core::Renderer,
|
||||||
{
|
{
|
||||||
id: Option<Id>,
|
id: Option<widget::Id>,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
|
|
@ -150,7 +150,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the [`Id`] of the [`Scrollable`].
|
/// Sets the [`Id`] of the [`Scrollable`].
|
||||||
pub fn id(mut self, id: impl Into<Id>) -> Self {
|
pub fn id(mut self, id: impl Into<widget::Id>) -> Self {
|
||||||
self.id = Some(id.into());
|
self.id = Some(id.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
@ -542,7 +542,7 @@ where
|
||||||
state.translation(self.direction, bounds, content_bounds);
|
state.translation(self.direction, bounds, content_bounds);
|
||||||
|
|
||||||
operation.scrollable(
|
operation.scrollable(
|
||||||
self.id.as_ref().map(|id| &id.0),
|
self.id.as_ref(),
|
||||||
bounds,
|
bounds,
|
||||||
content_bounds,
|
content_bounds,
|
||||||
translation,
|
translation,
|
||||||
|
|
@ -1262,59 +1262,38 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The identifier of a [`Scrollable`].
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub struct Id(widget::Id);
|
|
||||||
|
|
||||||
impl Id {
|
|
||||||
/// Creates a custom [`Id`].
|
|
||||||
pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
|
|
||||||
Self(widget::Id::new(id))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a unique [`Id`].
|
|
||||||
///
|
|
||||||
/// This function produces a different [`Id`] every time it is called.
|
|
||||||
pub fn unique() -> Self {
|
|
||||||
Self(widget::Id::unique())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Id> for widget::Id {
|
|
||||||
fn from(id: Id) -> Self {
|
|
||||||
id.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&'static str> for Id {
|
|
||||||
fn from(id: &'static str) -> Self {
|
|
||||||
Self::new(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Produces a [`Task`] that snaps the [`Scrollable`] with the given [`Id`]
|
/// Produces a [`Task`] that snaps the [`Scrollable`] with the given [`Id`]
|
||||||
/// to the provided [`RelativeOffset`].
|
/// to the provided [`RelativeOffset`].
|
||||||
pub fn snap_to<T>(id: impl Into<Id>, offset: RelativeOffset) -> Task<T> {
|
pub fn snap_to<T>(
|
||||||
|
id: impl Into<widget::Id>,
|
||||||
|
offset: RelativeOffset,
|
||||||
|
) -> Task<T> {
|
||||||
task::effect(Action::widget(operation::scrollable::snap_to(
|
task::effect(Action::widget(operation::scrollable::snap_to(
|
||||||
id.into().0,
|
id.into(),
|
||||||
offset,
|
offset,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Produces a [`Task`] that scrolls the [`Scrollable`] with the given [`Id`]
|
/// Produces a [`Task`] that scrolls the [`Scrollable`] with the given [`Id`]
|
||||||
/// to the provided [`AbsoluteOffset`].
|
/// to the provided [`AbsoluteOffset`].
|
||||||
pub fn scroll_to<T>(id: impl Into<Id>, offset: AbsoluteOffset) -> Task<T> {
|
pub fn scroll_to<T>(
|
||||||
|
id: impl Into<widget::Id>,
|
||||||
|
offset: AbsoluteOffset,
|
||||||
|
) -> Task<T> {
|
||||||
task::effect(Action::widget(operation::scrollable::scroll_to(
|
task::effect(Action::widget(operation::scrollable::scroll_to(
|
||||||
id.into().0,
|
id.into(),
|
||||||
offset,
|
offset,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Produces a [`Task`] that scrolls the [`Scrollable`] with the given [`Id`]
|
/// Produces a [`Task`] that scrolls the [`Scrollable`] with the given [`Id`]
|
||||||
/// by the provided [`AbsoluteOffset`].
|
/// by the provided [`AbsoluteOffset`].
|
||||||
pub fn scroll_by<T>(id: impl Into<Id>, offset: AbsoluteOffset) -> Task<T> {
|
pub fn scroll_by<T>(
|
||||||
|
id: impl Into<widget::Id>,
|
||||||
|
offset: AbsoluteOffset,
|
||||||
|
) -> Task<T> {
|
||||||
task::effect(Action::widget(operation::scrollable::scroll_by(
|
task::effect(Action::widget(operation::scrollable::scroll_by(
|
||||||
id.into().0,
|
id.into(),
|
||||||
offset,
|
offset,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ pub struct TextInput<
|
||||||
Theme: Catalog,
|
Theme: Catalog,
|
||||||
Renderer: text::Renderer,
|
Renderer: text::Renderer,
|
||||||
{
|
{
|
||||||
id: Option<Id>,
|
id: Option<widget::Id>,
|
||||||
placeholder: String,
|
placeholder: String,
|
||||||
value: Value,
|
value: Value,
|
||||||
is_secure: bool,
|
is_secure: bool,
|
||||||
|
|
@ -157,7 +157,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the [`Id`] of the [`TextInput`].
|
/// Sets the [`Id`] of the [`TextInput`].
|
||||||
pub fn id(mut self, id: impl Into<Id>) -> Self {
|
pub fn id(mut self, id: impl Into<widget::Id>) -> Self {
|
||||||
self.id = Some(id.into());
|
self.id = Some(id.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
@ -688,17 +688,8 @@ where
|
||||||
) {
|
) {
|
||||||
let state = tree.state.downcast_mut::<State<Renderer::Paragraph>>();
|
let state = tree.state.downcast_mut::<State<Renderer::Paragraph>>();
|
||||||
|
|
||||||
operation.focusable(
|
operation.text_input(self.id.as_ref(), layout.bounds(), state);
|
||||||
self.id.as_ref().map(|id| &id.0),
|
operation.focusable(self.id.as_ref(), layout.bounds(), state);
|
||||||
layout.bounds(),
|
|
||||||
state,
|
|
||||||
);
|
|
||||||
|
|
||||||
operation.text_input(
|
|
||||||
self.id.as_ref().map(|id| &id.0),
|
|
||||||
layout.bounds(),
|
|
||||||
state,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(
|
fn update(
|
||||||
|
|
@ -1454,82 +1445,47 @@ pub enum Side {
|
||||||
Right,
|
Right,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The identifier of a [`TextInput`].
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub struct Id(widget::Id);
|
|
||||||
|
|
||||||
impl Id {
|
|
||||||
/// Creates a custom [`Id`].
|
|
||||||
pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
|
|
||||||
Self(widget::Id::new(id))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a unique [`Id`].
|
|
||||||
///
|
|
||||||
/// This function produces a different [`Id`] every time it is called.
|
|
||||||
pub fn unique() -> Self {
|
|
||||||
Self(widget::Id::unique())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Id> for widget::Id {
|
|
||||||
fn from(id: Id) -> Self {
|
|
||||||
id.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&'static str> for Id {
|
|
||||||
fn from(id: &'static str) -> Self {
|
|
||||||
Self::new(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<String> for Id {
|
|
||||||
fn from(id: String) -> Self {
|
|
||||||
Self::new(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Produces a [`Task`] that returns whether the [`TextInput`] with the given [`Id`] is focused or not.
|
/// Produces a [`Task`] that returns whether the [`TextInput`] with the given [`Id`] is focused or not.
|
||||||
pub fn is_focused(id: impl Into<Id>) -> Task<bool> {
|
pub fn is_focused(id: impl Into<widget::Id>) -> Task<bool> {
|
||||||
task::widget(operation::focusable::is_focused(id.into().into()))
|
task::widget(operation::focusable::is_focused(id.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Produces a [`Task`] that focuses the [`TextInput`] with the given [`Id`].
|
/// Produces a [`Task`] that focuses the [`TextInput`] with the given [`Id`].
|
||||||
pub fn focus<T>(id: impl Into<Id>) -> Task<T> {
|
pub fn focus<T>(id: impl Into<widget::Id>) -> Task<T> {
|
||||||
task::effect(Action::widget(operation::focusable::focus(id.into().0)))
|
task::effect(Action::widget(operation::focusable::focus(id.into())))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Produces a [`Task`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the
|
/// Produces a [`Task`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the
|
||||||
/// end.
|
/// end.
|
||||||
pub fn move_cursor_to_end<T>(id: impl Into<Id>) -> Task<T> {
|
pub fn move_cursor_to_end<T>(id: impl Into<widget::Id>) -> Task<T> {
|
||||||
task::effect(Action::widget(operation::text_input::move_cursor_to_end(
|
task::effect(Action::widget(operation::text_input::move_cursor_to_end(
|
||||||
id.into().0,
|
id.into(),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Produces a [`Task`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the
|
/// Produces a [`Task`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the
|
||||||
/// front.
|
/// front.
|
||||||
pub fn move_cursor_to_front<T>(id: impl Into<Id>) -> Task<T> {
|
pub fn move_cursor_to_front<T>(id: impl Into<widget::Id>) -> Task<T> {
|
||||||
task::effect(Action::widget(operation::text_input::move_cursor_to_front(
|
task::effect(Action::widget(operation::text_input::move_cursor_to_front(
|
||||||
id.into().0,
|
id.into(),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Produces a [`Task`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the
|
/// Produces a [`Task`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the
|
||||||
/// provided position.
|
/// provided position.
|
||||||
pub fn move_cursor_to<T>(id: impl Into<Id>, position: usize) -> Task<T> {
|
pub fn move_cursor_to<T>(
|
||||||
|
id: impl Into<widget::Id>,
|
||||||
|
position: usize,
|
||||||
|
) -> Task<T> {
|
||||||
task::effect(Action::widget(operation::text_input::move_cursor_to(
|
task::effect(Action::widget(operation::text_input::move_cursor_to(
|
||||||
id.into().0,
|
id.into(),
|
||||||
position,
|
position,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Produces a [`Task`] that selects all the content of the [`TextInput`] with the given [`Id`].
|
/// Produces a [`Task`] that selects all the content of the [`TextInput`] with the given [`Id`].
|
||||||
pub fn select_all<T>(id: impl Into<Id>) -> Task<T> {
|
pub fn select_all<T>(id: impl Into<widget::Id>) -> Task<T> {
|
||||||
task::effect(Action::widget(operation::text_input::select_all(
|
task::effect(Action::widget(operation::text_input::select_all(id.into())))
|
||||||
id.into().0,
|
|
||||||
)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The state of a [`TextInput`].
|
/// The state of a [`TextInput`].
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue