Fix checkbox example
This commit is contained in:
parent
b2c87cdd23
commit
700262e05c
3 changed files with 20 additions and 10 deletions
Binary file not shown.
|
|
@ -1,10 +1,9 @@
|
||||||
|
use iced::executor;
|
||||||
|
use iced::font::{self, Font};
|
||||||
use iced::widget::{checkbox, column, container};
|
use iced::widget::{checkbox, column, container};
|
||||||
use iced::{Element, Font, Length, Sandbox, Settings};
|
use iced::{Application, Command, Element, Length, Settings, Theme};
|
||||||
|
|
||||||
const ICON_FONT: Font = Font::External {
|
const ICON_FONT: Font = Font::Name("icons");
|
||||||
name: "Icons",
|
|
||||||
bytes: include_bytes!("../fonts/icons.ttf"),
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
Example::run(Settings::default())
|
Example::run(Settings::default())
|
||||||
|
|
@ -20,24 +19,35 @@ struct Example {
|
||||||
enum Message {
|
enum Message {
|
||||||
DefaultChecked(bool),
|
DefaultChecked(bool),
|
||||||
CustomChecked(bool),
|
CustomChecked(bool),
|
||||||
|
FontLoaded(Result<(), font::Error>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sandbox for Example {
|
impl Application for Example {
|
||||||
type Message = Message;
|
type Message = Message;
|
||||||
|
type Flags = ();
|
||||||
|
type Executor = executor::Default;
|
||||||
|
type Theme = Theme;
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new(_flags: Self::Flags) -> (Self, Command<Message>) {
|
||||||
Default::default()
|
(
|
||||||
|
Self::default(),
|
||||||
|
font::load(include_bytes!("../fonts/icons.ttf").as_ref())
|
||||||
|
.map(Message::FontLoaded),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn title(&self) -> String {
|
fn title(&self) -> String {
|
||||||
String::from("Checkbox - Iced")
|
String::from("Checkbox - Iced")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, message: Message) {
|
fn update(&mut self, message: Message) -> Command<Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::DefaultChecked(value) => self.default_checkbox = value,
|
Message::DefaultChecked(value) => self.default_checkbox = value,
|
||||||
Message::CustomChecked(value) => self.custom_checkbox = value,
|
Message::CustomChecked(value) => self.custom_checkbox = value,
|
||||||
|
Message::FontLoaded(_) => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Command::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element<Message> {
|
fn view(&self) -> Element<Message> {
|
||||||
|
|
|
||||||
|
|
@ -267,7 +267,7 @@ where
|
||||||
code_point,
|
code_point,
|
||||||
size,
|
size,
|
||||||
} = &self.icon;
|
} = &self.icon;
|
||||||
let size = size.map(f32::from).unwrap_or(bounds.height * 0.7);
|
let size = size.unwrap_or(bounds.height * 0.7);
|
||||||
|
|
||||||
if self.is_checked {
|
if self.is_checked {
|
||||||
renderer.fill_text(text::Text {
|
renderer.fill_text(text::Text {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue