Implement scrollable::snap_to operation

This commit is contained in:
Héctor Ramón Jiménez 2022-08-04 03:55:41 +02:00
parent 6eb3dd7e5e
commit 13dd1ca0a8
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
13 changed files with 293 additions and 204 deletions

View file

@ -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"

View file

@ -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();
}