summaryrefslogtreecommitdiffstats
path: root/examples/websocket
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-08-04 03:55:41 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-08-04 03:55:41 +0200
commit13dd1ca0a83cc95eea52e2106da9dc1ee1f37958 (patch)
tree4b142110e23fe45b8d5d21935034c951f548d7e8 /examples/websocket
parent6eb3dd7e5edc8847875c288c41d1dec8b1dad06e (diff)
downloadiced-13dd1ca0a83cc95eea52e2106da9dc1ee1f37958.tar.gz
iced-13dd1ca0a83cc95eea52e2106da9dc1ee1f37958.tar.bz2
iced-13dd1ca0a83cc95eea52e2106da9dc1ee1f37958.zip
Implement `scrollable::snap_to` operation
Diffstat (limited to 'examples/websocket')
-rw-r--r--examples/websocket/Cargo.toml1
-rw-r--r--examples/websocket/src/main.rs22
2 files changed, 17 insertions, 6 deletions
diff --git a/examples/websocket/Cargo.toml b/examples/websocket/Cargo.toml
index db131dd7..c582733f 100644
--- a/examples/websocket/Cargo.toml
+++ b/examples/websocket/Cargo.toml
@@ -9,6 +9,7 @@ publish = false
iced = { path = "../..", features = ["tokio", "debug"] }
iced_native = { path = "../../native" }
iced_futures = { path = "../../futures" }
+lazy_static = "1.4"
[dependencies.async-tungstenite]
version = "0.16"
diff --git a/examples/websocket/src/main.rs b/examples/websocket/src/main.rs
index 28a9de37..3902e04c 100644
--- a/examples/websocket/src/main.rs
+++ b/examples/websocket/src/main.rs
@@ -49,37 +49,42 @@ impl Application for WebSocket {
match message {
Message::NewMessageChanged(new_message) => {
self.new_message = new_message;
+
+ Command::none()
}
Message::Send(message) => match &mut self.state {
State::Connected(connection) => {
self.new_message.clear();
connection.send(message);
+
+ Command::none()
}
- State::Disconnected => {}
+ State::Disconnected => Command::none(),
},
Message::Echo(event) => match event {
echo::Event::Connected(connection) => {
self.state = State::Connected(connection);
self.messages.push(echo::Message::connected());
+
+ Command::none()
}
echo::Event::Disconnected => {
self.state = State::Disconnected;
self.messages.push(echo::Message::disconnected());
+
+ Command::none()
}
echo::Event::MessageReceived(message) => {
self.messages.push(message);
- // TODO
- // self.message_log.snap_to(1.0);
+ scrollable::snap_to(MESSAGE_LOG.clone(), 1.0)
}
},
- Message::Server => {}
+ Message::Server => Command::none(),
}
-
- Command::none()
}
fn subscription(&self) -> Subscription<Message> {
@@ -110,6 +115,7 @@ impl Application for WebSocket {
.width(Length::Fill)
.spacing(10),
)
+ .id(MESSAGE_LOG.clone())
.height(Length::Fill)
.into()
};
@@ -158,3 +164,7 @@ impl Default for State {
Self::Disconnected
}
}
+
+lazy_static::lazy_static! {
+ static ref MESSAGE_LOG: scrollable::Id = scrollable::Id::unique();
+}