Use Program API in websocket example
This commit is contained in:
parent
78e78d20b6
commit
acb9321296
1 changed files with 8 additions and 20 deletions
|
|
@ -1,17 +1,17 @@
|
||||||
mod echo;
|
mod echo;
|
||||||
|
|
||||||
use iced::alignment::{self, Alignment};
|
use iced::alignment::{self, Alignment};
|
||||||
use iced::executor;
|
|
||||||
use iced::widget::{
|
use iced::widget::{
|
||||||
button, column, container, row, scrollable, text, text_input,
|
button, column, container, row, scrollable, text, text_input,
|
||||||
};
|
};
|
||||||
use iced::{
|
use iced::{color, Command, Element, Length, Subscription};
|
||||||
color, Application, Command, Element, Length, Settings, Subscription, Theme,
|
|
||||||
};
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
WebSocket::run(Settings::default())
|
iced::program("WebSocket - Iced", WebSocket::update, WebSocket::view)
|
||||||
|
.load(WebSocket::load)
|
||||||
|
.subscription(WebSocket::subscription)
|
||||||
|
.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
@ -29,21 +29,9 @@ enum Message {
|
||||||
Server,
|
Server,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application for WebSocket {
|
impl WebSocket {
|
||||||
type Message = Message;
|
fn load() -> Command<Message> {
|
||||||
type Theme = Theme;
|
Command::perform(echo::server::run(), |_| Message::Server)
|
||||||
type Flags = ();
|
|
||||||
type Executor = executor::Default;
|
|
||||||
|
|
||||||
fn new(_flags: Self::Flags) -> (Self, Command<Message>) {
|
|
||||||
(
|
|
||||||
Self::default(),
|
|
||||||
Command::perform(echo::server::run(), |_| Message::Server),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn title(&self) -> String {
|
|
||||||
String::from("WebSocket - Iced")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, message: Message) -> Command<Message> {
|
fn update(&mut self, message: Message) -> Command<Message> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue