Introduce Program API
This commit is contained in:
parent
0524e9b457
commit
c22269bff3
43 changed files with 1141 additions and 831 deletions
|
|
@ -1,4 +1,3 @@
|
|||
use iced::executor;
|
||||
use iced::keyboard;
|
||||
use iced::mouse;
|
||||
use iced::widget::{
|
||||
|
|
@ -6,15 +5,19 @@ use iced::widget::{
|
|||
row, scrollable, text,
|
||||
};
|
||||
use iced::{
|
||||
color, Alignment, Application, Command, Element, Font, Length, Point,
|
||||
Rectangle, Renderer, Settings, Subscription, Theme,
|
||||
color, Alignment, Element, Font, Length, Point, Rectangle, Renderer,
|
||||
Subscription, Theme,
|
||||
};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
Layout::run(Settings::default())
|
||||
iced::sandbox(Layout::update, Layout::view)
|
||||
.title(Layout::title)
|
||||
.subscription(Layout::subscription)
|
||||
.theme(Layout::theme)
|
||||
.run()
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Default, Debug)]
|
||||
struct Layout {
|
||||
example: Example,
|
||||
explain: bool,
|
||||
|
|
@ -29,28 +32,12 @@ enum Message {
|
|||
ThemeSelected(Theme),
|
||||
}
|
||||
|
||||
impl Application for Layout {
|
||||
type Message = Message;
|
||||
type Theme = Theme;
|
||||
type Executor = executor::Default;
|
||||
type Flags = ();
|
||||
|
||||
fn new(_flags: Self::Flags) -> (Self, Command<Message>) {
|
||||
(
|
||||
Self {
|
||||
example: Example::default(),
|
||||
explain: false,
|
||||
theme: Theme::Light,
|
||||
},
|
||||
Command::none(),
|
||||
)
|
||||
}
|
||||
|
||||
impl Layout {
|
||||
fn title(&self) -> String {
|
||||
format!("{} - Layout - Iced", self.example.title)
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Self::Message) -> Command<Message> {
|
||||
fn update(&mut self, message: Message) {
|
||||
match message {
|
||||
Message::Next => {
|
||||
self.example = self.example.next();
|
||||
|
|
@ -65,8 +52,6 @@ impl Application for Layout {
|
|||
self.theme = theme;
|
||||
}
|
||||
}
|
||||
|
||||
Command::none()
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue