-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1707 from casperstorm/feat/checkbox-icon
Added the ability to change `Checkbox` icon
- Loading branch information
Showing
8 changed files
with
123 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "checkbox" | ||
version = "0.1.0" | ||
authors = ["Casper Rogild Storm<casper@rogildstorm.com>"] | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
iced = { path = "../.." } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## Checkbox | ||
|
||
A box that can be checked. | ||
|
||
The __[`main`]__ file contains all the code of the example. | ||
|
||
You can run it with `cargo run`: | ||
``` | ||
cargo run --package pick_list | ||
``` | ||
|
||
[`main`]: src/main.rs |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use iced::widget::{checkbox, column, container}; | ||
use iced::{Element, Font, Length, Sandbox, Settings}; | ||
|
||
const ICON_FONT: Font = Font::External { | ||
name: "Icons", | ||
bytes: include_bytes!("../fonts/icons.ttf"), | ||
}; | ||
|
||
pub fn main() -> iced::Result { | ||
Example::run(Settings::default()) | ||
} | ||
|
||
#[derive(Default)] | ||
struct Example { | ||
default_checkbox: bool, | ||
custom_checkbox: bool, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
enum Message { | ||
DefaultChecked(bool), | ||
CustomChecked(bool), | ||
} | ||
|
||
impl Sandbox for Example { | ||
type Message = Message; | ||
|
||
fn new() -> Self { | ||
Default::default() | ||
} | ||
|
||
fn title(&self) -> String { | ||
String::from("Checkbox - Iced") | ||
} | ||
|
||
fn update(&mut self, message: Message) { | ||
match message { | ||
Message::DefaultChecked(value) => self.default_checkbox = value, | ||
Message::CustomChecked(value) => self.custom_checkbox = value, | ||
} | ||
} | ||
|
||
fn view(&self) -> Element<Message> { | ||
let default_checkbox = | ||
checkbox("Default", self.default_checkbox, Message::DefaultChecked); | ||
let custom_checkbox = | ||
checkbox("Custom", self.custom_checkbox, Message::CustomChecked) | ||
.icon(checkbox::Icon { | ||
font: ICON_FONT, | ||
code_point: '\u{e901}', | ||
size: None, | ||
}); | ||
|
||
let content = column![default_checkbox, custom_checkbox].spacing(22); | ||
|
||
container(content) | ||
.width(Length::Fill) | ||
.height(Length::Fill) | ||
.center_x() | ||
.center_y() | ||
.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters