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
|
|
@ -4,11 +4,6 @@ use iced::widget::{
|
|||
};
|
||||
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 {
|
||||
iced::application(
|
||||
ScrollableDemo::default,
|
||||
|
|
@ -65,19 +60,13 @@ impl ScrollableDemo {
|
|||
self.current_scroll_offset = scrollable::RelativeOffset::START;
|
||||
self.scrollable_direction = direction;
|
||||
|
||||
scrollable::snap_to(
|
||||
SCROLLABLE_ID.clone(),
|
||||
self.current_scroll_offset,
|
||||
)
|
||||
scrollable::snap_to(SCROLLABLE, self.current_scroll_offset)
|
||||
}
|
||||
Message::AlignmentChanged(alignment) => {
|
||||
self.current_scroll_offset = scrollable::RelativeOffset::START;
|
||||
self.anchor = alignment;
|
||||
|
||||
scrollable::snap_to(
|
||||
SCROLLABLE_ID.clone(),
|
||||
self.current_scroll_offset,
|
||||
)
|
||||
scrollable::snap_to(SCROLLABLE, self.current_scroll_offset)
|
||||
}
|
||||
Message::ScrollbarWidthChanged(width) => {
|
||||
self.scrollbar_width = width;
|
||||
|
|
@ -97,18 +86,12 @@ impl ScrollableDemo {
|
|||
Message::ScrollToBeginning => {
|
||||
self.current_scroll_offset = scrollable::RelativeOffset::START;
|
||||
|
||||
scrollable::snap_to(
|
||||
SCROLLABLE_ID.clone(),
|
||||
self.current_scroll_offset,
|
||||
)
|
||||
scrollable::snap_to(SCROLLABLE, self.current_scroll_offset)
|
||||
}
|
||||
Message::ScrollToEnd => {
|
||||
self.current_scroll_offset = scrollable::RelativeOffset::END;
|
||||
|
||||
scrollable::snap_to(
|
||||
SCROLLABLE_ID.clone(),
|
||||
self.current_scroll_offset,
|
||||
)
|
||||
scrollable::snap_to(SCROLLABLE, self.current_scroll_offset)
|
||||
}
|
||||
Message::Scrolled(viewport) => {
|
||||
self.current_scroll_offset = viewport.relative_offset();
|
||||
|
|
@ -226,7 +209,7 @@ impl ScrollableDemo {
|
|||
))
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.id(SCROLLABLE_ID.clone())
|
||||
.id(SCROLLABLE)
|
||||
.on_scroll(Message::Scrolled),
|
||||
Direction::Horizontal => scrollable(
|
||||
row![
|
||||
|
|
@ -252,7 +235,7 @@ impl ScrollableDemo {
|
|||
))
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.id(SCROLLABLE_ID.clone())
|
||||
.id(SCROLLABLE)
|
||||
.on_scroll(Message::Scrolled),
|
||||
Direction::Multi => scrollable(
|
||||
//horizontal content
|
||||
|
|
@ -299,7 +282,7 @@ impl ScrollableDemo {
|
|||
})
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.id(SCROLLABLE_ID.clone())
|
||||
.id(SCROLLABLE)
|
||||
.on_scroll(Message::Scrolled),
|
||||
});
|
||||
|
||||
|
|
@ -348,3 +331,5 @@ fn progress_bar_custom_style(theme: &Theme) -> progress_bar::Style {
|
|||
border: Border::default(),
|
||||
}
|
||||
}
|
||||
|
||||
const SCROLLABLE: &str = "scrollable";
|
||||
|
|
|
|||
|
|
@ -305,8 +305,8 @@ pub enum TaskMessage {
|
|||
}
|
||||
|
||||
impl Task {
|
||||
fn text_input_id(i: usize) -> text_input::Id {
|
||||
text_input::Id::new(format!("task-{i}"))
|
||||
fn text_input_id(i: usize) -> widget::Id {
|
||||
widget::Id::new(format!("task-{i}"))
|
||||
}
|
||||
|
||||
fn new(description: String) -> Self {
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ impl Example {
|
|||
Task::none()
|
||||
}
|
||||
Message::Scrolled | Message::WindowResized => Task::batch(vec![
|
||||
container::visible_bounds(OUTER_CONTAINER.clone())
|
||||
container::visible_bounds(OUTER_CONTAINER)
|
||||
.map(Message::OuterBoundsFetched),
|
||||
container::visible_bounds(INNER_CONTAINER.clone())
|
||||
container::visible_bounds(INNER_CONTAINER)
|
||||
.map(Message::InnerBoundsFetched),
|
||||
]),
|
||||
Message::OuterBoundsFetched(outer_bounds) => {
|
||||
|
|
@ -113,7 +113,7 @@ impl Example {
|
|||
text("Scroll me!"),
|
||||
vertical_space().height(400),
|
||||
container(text("I am the outer container!"))
|
||||
.id(OUTER_CONTAINER.clone())
|
||||
.id(OUTER_CONTAINER)
|
||||
.padding(40)
|
||||
.style(container::rounded_box),
|
||||
vertical_space().height(400),
|
||||
|
|
@ -122,7 +122,7 @@ impl Example {
|
|||
text("Scroll me!"),
|
||||
vertical_space().height(400),
|
||||
container(text("I am the inner container!"))
|
||||
.id(INNER_CONTAINER.clone())
|
||||
.id(INNER_CONTAINER)
|
||||
.padding(40)
|
||||
.style(container::rounded_box),
|
||||
vertical_space().height(400),
|
||||
|
|
@ -157,9 +157,5 @@ impl Example {
|
|||
}
|
||||
}
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
static OUTER_CONTAINER: LazyLock<container::Id> =
|
||||
LazyLock::new(|| container::Id::new("outer"));
|
||||
static INNER_CONTAINER: LazyLock<container::Id> =
|
||||
LazyLock::new(|| container::Id::new("inner"));
|
||||
const OUTER_CONTAINER: &str = "outer";
|
||||
const INNER_CONTAINER: &str = "inner";
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ use iced::widget::{
|
|||
};
|
||||
use iced::{Center, Element, Fill, Subscription, Task, color};
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
iced::application(WebSocket::new, WebSocket::update, WebSocket::view)
|
||||
.subscription(WebSocket::subscription)
|
||||
|
|
@ -76,7 +74,7 @@ impl WebSocket {
|
|||
self.messages.push(message);
|
||||
|
||||
scrollable::snap_to(
|
||||
MESSAGE_LOG.clone(),
|
||||
MESSAGE_LOG,
|
||||
scrollable::RelativeOffset::END,
|
||||
)
|
||||
}
|
||||
|
|
@ -105,7 +103,7 @@ impl WebSocket {
|
|||
column(self.messages.iter().map(text).map(Element::from))
|
||||
.spacing(10),
|
||||
)
|
||||
.id(MESSAGE_LOG.clone())
|
||||
.id(MESSAGE_LOG)
|
||||
.height(Fill)
|
||||
.spacing(10)
|
||||
.into()
|
||||
|
|
@ -142,5 +140,4 @@ enum State {
|
|||
Connected(echo::Connection),
|
||||
}
|
||||
|
||||
static MESSAGE_LOG: LazyLock<scrollable::Id> =
|
||||
LazyLock::new(scrollable::Id::unique);
|
||||
const MESSAGE_LOG: &str = "message_log";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue