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
|
|
@ -67,7 +67,7 @@ pub struct Container<
|
|||
Theme: Catalog,
|
||||
Renderer: core::Renderer,
|
||||
{
|
||||
id: Option<Id>,
|
||||
id: Option<widget::Id>,
|
||||
padding: Padding,
|
||||
width: Length,
|
||||
height: Length,
|
||||
|
|
@ -108,7 +108,7 @@ where
|
|||
}
|
||||
|
||||
/// 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
|
||||
}
|
||||
|
|
@ -284,7 +284,7 @@ where
|
|||
renderer: &Renderer,
|
||||
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| {
|
||||
self.content.as_widget().operate(
|
||||
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
|
||||
/// [`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!()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ pub struct Scrollable<
|
|||
Theme: Catalog,
|
||||
Renderer: core::Renderer,
|
||||
{
|
||||
id: Option<Id>,
|
||||
id: Option<widget::Id>,
|
||||
width: Length,
|
||||
height: Length,
|
||||
direction: Direction,
|
||||
|
|
@ -150,7 +150,7 @@ where
|
|||
}
|
||||
|
||||
/// 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
|
||||
}
|
||||
|
|
@ -542,7 +542,7 @@ where
|
|||
state.translation(self.direction, bounds, content_bounds);
|
||||
|
||||
operation.scrollable(
|
||||
self.id.as_ref().map(|id| &id.0),
|
||||
self.id.as_ref(),
|
||||
bounds,
|
||||
content_bounds,
|
||||
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`]
|
||||
/// 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(
|
||||
id.into().0,
|
||||
id.into(),
|
||||
offset,
|
||||
)))
|
||||
}
|
||||
|
||||
/// Produces a [`Task`] that scrolls the [`Scrollable`] with the given [`Id`]
|
||||
/// 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(
|
||||
id.into().0,
|
||||
id.into(),
|
||||
offset,
|
||||
)))
|
||||
}
|
||||
|
||||
/// Produces a [`Task`] that scrolls the [`Scrollable`] with the given [`Id`]
|
||||
/// 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(
|
||||
id.into().0,
|
||||
id.into(),
|
||||
offset,
|
||||
)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ pub struct TextInput<
|
|||
Theme: Catalog,
|
||||
Renderer: text::Renderer,
|
||||
{
|
||||
id: Option<Id>,
|
||||
id: Option<widget::Id>,
|
||||
placeholder: String,
|
||||
value: Value,
|
||||
is_secure: bool,
|
||||
|
|
@ -157,7 +157,7 @@ where
|
|||
}
|
||||
|
||||
/// 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
|
||||
}
|
||||
|
|
@ -688,17 +688,8 @@ where
|
|||
) {
|
||||
let state = tree.state.downcast_mut::<State<Renderer::Paragraph>>();
|
||||
|
||||
operation.focusable(
|
||||
self.id.as_ref().map(|id| &id.0),
|
||||
layout.bounds(),
|
||||
state,
|
||||
);
|
||||
|
||||
operation.text_input(
|
||||
self.id.as_ref().map(|id| &id.0),
|
||||
layout.bounds(),
|
||||
state,
|
||||
);
|
||||
operation.text_input(self.id.as_ref(), layout.bounds(), state);
|
||||
operation.focusable(self.id.as_ref(), layout.bounds(), state);
|
||||
}
|
||||
|
||||
fn update(
|
||||
|
|
@ -1454,82 +1445,47 @@ pub enum Side {
|
|||
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.
|
||||
pub fn is_focused(id: impl Into<Id>) -> Task<bool> {
|
||||
task::widget(operation::focusable::is_focused(id.into().into()))
|
||||
pub fn is_focused(id: impl Into<widget::Id>) -> Task<bool> {
|
||||
task::widget(operation::focusable::is_focused(id.into()))
|
||||
}
|
||||
|
||||
/// Produces a [`Task`] that focuses the [`TextInput`] with the given [`Id`].
|
||||
pub fn focus<T>(id: impl Into<Id>) -> Task<T> {
|
||||
task::effect(Action::widget(operation::focusable::focus(id.into().0)))
|
||||
pub fn focus<T>(id: impl Into<widget::Id>) -> Task<T> {
|
||||
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
|
||||
/// 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(
|
||||
id.into().0,
|
||||
id.into(),
|
||||
)))
|
||||
}
|
||||
|
||||
/// Produces a [`Task`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the
|
||||
/// 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(
|
||||
id.into().0,
|
||||
id.into(),
|
||||
)))
|
||||
}
|
||||
|
||||
/// Produces a [`Task`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the
|
||||
/// 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(
|
||||
id.into().0,
|
||||
id.into(),
|
||||
position,
|
||||
)))
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
task::effect(Action::widget(operation::text_input::select_all(
|
||||
id.into().0,
|
||||
)))
|
||||
pub fn select_all<T>(id: impl Into<widget::Id>) -> Task<T> {
|
||||
task::effect(Action::widget(operation::text_input::select_all(id.into())))
|
||||
}
|
||||
|
||||
/// The state of a [`TextInput`].
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue