Introduce Program API

This commit is contained in:
Héctor Ramón Jiménez 2024-03-16 05:33:47 +01:00
parent 0524e9b457
commit c22269bff3
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
43 changed files with 1141 additions and 831 deletions

View file

@ -1,12 +1,13 @@
use iced::executor;
use iced::font::{self, Font};
use iced::widget::{checkbox, column, container, row, text};
use iced::{Application, Command, Element, Length, Settings, Theme};
use iced::{Element, Font, Length};
const ICON_FONT: Font = Font::with_name("icons");
pub fn main() -> iced::Result {
Example::run(Settings::default())
iced::sandbox(Example::update, Example::view)
.title("Checkbox - Iced")
.fonts([include_bytes!("../fonts/icons.ttf").as_slice().into()])
.run()
}
#[derive(Default)]
@ -21,28 +22,10 @@ enum Message {
DefaultToggled(bool),
CustomToggled(bool),
StyledToggled(bool),
FontLoaded(Result<(), font::Error>),
}
impl Application for Example {
type Message = Message;
type Flags = ();
type Executor = executor::Default;
type Theme = Theme;
fn new(_flags: Self::Flags) -> (Self, Command<Message>) {
(
Self::default(),
font::load(include_bytes!("../fonts/icons.ttf").as_slice())
.map(Message::FontLoaded),
)
}
fn title(&self) -> String {
String::from("Checkbox - Iced")
}
fn update(&mut self, message: Message) -> Command<Message> {
impl Example {
fn update(&mut self, message: Message) {
match message {
Message::DefaultToggled(default) => {
self.default = default;
@ -53,10 +36,7 @@ impl Application for Example {
Message::CustomToggled(custom) => {
self.custom = custom;
}
Message::FontLoaded(_) => (),
}
Command::none()
}
fn view(&self) -> Element<Message> {