Merge remote-tracking branch 'origin/master' into feat/multi-window-support
# Conflicts: # winit/src/window.rs
This commit is contained in:
commit
744cef5608
70 changed files with 807 additions and 542 deletions
9
examples/checkbox/Cargo.toml
Normal file
9
examples/checkbox/Cargo.toml
Normal file
|
|
@ -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 = "../.." }
|
||||
12
examples/checkbox/README.md
Normal file
12
examples/checkbox/README.md
Normal file
|
|
@ -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
|
||||
BIN
examples/checkbox/fonts/icons.ttf
Normal file
BIN
examples/checkbox/fonts/icons.ttf
Normal file
Binary file not shown.
63
examples/checkbox/src/main.rs
Normal file
63
examples/checkbox/src/main.rs
Normal file
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
@ -301,11 +301,11 @@ impl<C: ColorSpace + Copy> ColorPicker<C> {
|
|||
}
|
||||
|
||||
row![
|
||||
text(C::LABEL).width(Length::Units(50)),
|
||||
text(C::LABEL).width(50),
|
||||
slider(cr1, c1, move |v| C::new(v, c2, c3)),
|
||||
slider(cr2, c2, move |v| C::new(c1, v, c3)),
|
||||
slider(cr3, c3, move |v| C::new(c1, c2, v)),
|
||||
text(color.to_string()).width(Length::Units(185)).size(14),
|
||||
text(color.to_string()).width(185).size(14),
|
||||
]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center)
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ mod numeric_input {
|
|||
.horizontal_alignment(alignment::Horizontal::Center)
|
||||
.vertical_alignment(alignment::Vertical::Center),
|
||||
)
|
||||
.width(Length::Units(50))
|
||||
.width(50)
|
||||
.on_press(on_press)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ impl Application for Events {
|
|||
.width(Length::Fill)
|
||||
.horizontal_alignment(alignment::Horizontal::Center),
|
||||
)
|
||||
.width(Length::Units(100))
|
||||
.width(100)
|
||||
.padding(10)
|
||||
.on_press(Message::Exit);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ impl Program for Controls {
|
|||
let background_color = self.background_color;
|
||||
|
||||
let sliders = Row::new()
|
||||
.width(Length::Units(500))
|
||||
.width(500)
|
||||
.spacing(20)
|
||||
.push(
|
||||
Slider::new(0.0..=1.0, background_color.r, move |r| {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ impl Program for Controls {
|
|||
let text = &self.text;
|
||||
|
||||
let sliders = Row::new()
|
||||
.width(Length::Units(500))
|
||||
.width(500)
|
||||
.spacing(20)
|
||||
.push(
|
||||
slider(0.0..=1.0, background_color.r, move |r| {
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ impl Application for App {
|
|||
]
|
||||
.spacing(20),
|
||||
)
|
||||
.width(Length::Units(300))
|
||||
.width(300)
|
||||
.padding(10)
|
||||
.style(theme::Container::Box);
|
||||
|
||||
|
|
|
|||
|
|
@ -43,10 +43,10 @@ impl Sandbox for Example {
|
|||
.placeholder("Choose a language...");
|
||||
|
||||
let content = column![
|
||||
vertical_space(Length::Units(600)),
|
||||
vertical_space(600),
|
||||
"Which is your favorite language?",
|
||||
pick_list,
|
||||
vertical_space(Length::Units(600)),
|
||||
vertical_space(600),
|
||||
]
|
||||
.width(Length::Fill)
|
||||
.align_items(Alignment::Center)
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ impl Pokemon {
|
|||
{
|
||||
let bytes = reqwest::get(&url).await?.bytes().await?;
|
||||
|
||||
Ok(image::Handle::from_memory(bytes.as_ref().to_vec()))
|
||||
Ok(image::Handle::from_memory(bytes))
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
|
|
|
|||
|
|
@ -21,10 +21,7 @@ impl Sandbox for QRGenerator {
|
|||
type Message = Message;
|
||||
|
||||
fn new() -> Self {
|
||||
QRGenerator {
|
||||
qr_code: qr_code::State::new("").ok(),
|
||||
..Self::default()
|
||||
}
|
||||
QRGenerator::default()
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
|
|
@ -36,7 +33,12 @@ impl Sandbox for QRGenerator {
|
|||
Message::DataChanged(mut data) => {
|
||||
data.truncate(100);
|
||||
|
||||
self.qr_code = qr_code::State::new(&data).ok();
|
||||
self.qr_code = if data.is_empty() {
|
||||
None
|
||||
} else {
|
||||
qr_code::State::new(&data).ok()
|
||||
};
|
||||
|
||||
self.data = data;
|
||||
}
|
||||
}
|
||||
|
|
@ -56,7 +58,7 @@ impl Sandbox for QRGenerator {
|
|||
.padding(15);
|
||||
|
||||
let mut content = column![title, input]
|
||||
.width(Length::Units(700))
|
||||
.width(700)
|
||||
.spacing(20)
|
||||
.align_items(Alignment::Center);
|
||||
|
||||
|
|
|
|||
|
|
@ -187,9 +187,9 @@ impl Application for ScrollableDemo {
|
|||
column![
|
||||
scroll_to_end_button(),
|
||||
text("Beginning!"),
|
||||
vertical_space(Length::Units(1200)),
|
||||
vertical_space(1200),
|
||||
text("Middle!"),
|
||||
vertical_space(Length::Units(1200)),
|
||||
vertical_space(1200),
|
||||
text("End!"),
|
||||
scroll_to_beginning_button(),
|
||||
]
|
||||
|
|
@ -211,13 +211,13 @@ impl Application for ScrollableDemo {
|
|||
row![
|
||||
scroll_to_end_button(),
|
||||
text("Beginning!"),
|
||||
horizontal_space(Length::Units(1200)),
|
||||
horizontal_space(1200),
|
||||
text("Middle!"),
|
||||
horizontal_space(Length::Units(1200)),
|
||||
horizontal_space(1200),
|
||||
text("End!"),
|
||||
scroll_to_beginning_button(),
|
||||
]
|
||||
.height(Length::Units(450))
|
||||
.height(450)
|
||||
.align_items(Alignment::Center)
|
||||
.padding([0, 40, 0, 40])
|
||||
.spacing(40),
|
||||
|
|
@ -237,26 +237,26 @@ impl Application for ScrollableDemo {
|
|||
row![
|
||||
column![
|
||||
text("Let's do some scrolling!"),
|
||||
vertical_space(Length::Units(2400))
|
||||
vertical_space(2400)
|
||||
],
|
||||
scroll_to_end_button(),
|
||||
text("Horizontal - Beginning!"),
|
||||
horizontal_space(Length::Units(1200)),
|
||||
horizontal_space(1200),
|
||||
//vertical content
|
||||
column![
|
||||
text("Horizontal - Middle!"),
|
||||
scroll_to_end_button(),
|
||||
text("Vertical - Beginning!"),
|
||||
vertical_space(Length::Units(1200)),
|
||||
vertical_space(1200),
|
||||
text("Vertical - Middle!"),
|
||||
vertical_space(Length::Units(1200)),
|
||||
vertical_space(1200),
|
||||
text("Vertical - End!"),
|
||||
scroll_to_beginning_button(),
|
||||
vertical_space(Length::Units(40)),
|
||||
vertical_space(40),
|
||||
]
|
||||
.align_items(Alignment::Fill)
|
||||
.spacing(40),
|
||||
horizontal_space(Length::Units(1200)),
|
||||
horizontal_space(1200),
|
||||
text("Horizontal - End!"),
|
||||
scroll_to_beginning_button(),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -38,11 +38,11 @@ impl Sandbox for Slider {
|
|||
|
||||
let h_slider =
|
||||
container(slider(0..=100, value, Message::SliderChanged))
|
||||
.width(Length::Units(250));
|
||||
.width(250);
|
||||
|
||||
let v_slider =
|
||||
container(vertical_slider(0..=100, value, Message::SliderChanged))
|
||||
.height(Length::Units(200));
|
||||
.height(200);
|
||||
|
||||
let text = text(format!("{value}"));
|
||||
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ impl Application for Stopwatch {
|
|||
text(label).horizontal_alignment(alignment::Horizontal::Center),
|
||||
)
|
||||
.padding(10)
|
||||
.width(Length::Units(80))
|
||||
.width(80)
|
||||
};
|
||||
|
||||
let toggle_button = {
|
||||
|
|
|
|||
|
|
@ -108,14 +108,10 @@ impl Sandbox for Styling {
|
|||
let progress_bar = progress_bar(0.0..=100.0, self.slider_value);
|
||||
|
||||
let scrollable = scrollable(
|
||||
column![
|
||||
"Scroll me!",
|
||||
vertical_space(Length::Units(800)),
|
||||
"You did it!"
|
||||
]
|
||||
.width(Length::Fill),
|
||||
column!["Scroll me!", vertical_space(800), "You did it!"]
|
||||
.width(Length::Fill),
|
||||
)
|
||||
.height(Length::Units(100));
|
||||
.height(100);
|
||||
|
||||
let checkbox = checkbox(
|
||||
"Check me!",
|
||||
|
|
@ -143,7 +139,7 @@ impl Sandbox for Styling {
|
|||
column![checkbox, toggler].spacing(20)
|
||||
]
|
||||
.spacing(10)
|
||||
.height(Length::Units(100))
|
||||
.height(100)
|
||||
.align_items(Alignment::Center),
|
||||
]
|
||||
.spacing(20)
|
||||
|
|
|
|||
|
|
@ -460,7 +460,7 @@ fn empty_message(message: &str) -> Element<'_, Message> {
|
|||
.style(Color::from([0.7, 0.7, 0.7])),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Units(200))
|
||||
.height(200)
|
||||
.center_y()
|
||||
.into()
|
||||
}
|
||||
|
|
@ -474,7 +474,7 @@ const ICONS: Font = Font::External {
|
|||
fn icon(unicode: char) -> Text<'static> {
|
||||
text(unicode.to_string())
|
||||
.font(ICONS)
|
||||
.width(Length::Units(20))
|
||||
.width(20)
|
||||
.horizontal_alignment(alignment::Horizontal::Center)
|
||||
.size(20)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -513,14 +513,14 @@ impl<'a> Step {
|
|||
text("Tip: You can use the scrollbar to scroll down faster!")
|
||||
.size(16),
|
||||
)
|
||||
.push(vertical_space(Length::Units(4096)))
|
||||
.push(vertical_space(4096))
|
||||
.push(
|
||||
text("You are halfway there!")
|
||||
.width(Length::Fill)
|
||||
.size(30)
|
||||
.horizontal_alignment(alignment::Horizontal::Center),
|
||||
)
|
||||
.push(vertical_space(Length::Units(4096)))
|
||||
.push(vertical_space(4096))
|
||||
.push(ferris(300))
|
||||
.push(
|
||||
text("You made it!")
|
||||
|
|
@ -605,7 +605,7 @@ fn ferris<'a>(width: u16) -> Container<'a, StepMessage> {
|
|||
} else {
|
||||
image(format!("{}/images/ferris.png", env!("CARGO_MANIFEST_DIR")))
|
||||
}
|
||||
.width(Length::Units(width)),
|
||||
.width(width),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.center_x()
|
||||
|
|
@ -616,7 +616,7 @@ fn button<'a, Message: Clone>(label: &str) -> Button<'a, Message> {
|
|||
text(label).horizontal_alignment(alignment::Horizontal::Center),
|
||||
)
|
||||
.padding(12)
|
||||
.width(Length::Units(100))
|
||||
.width(100)
|
||||
}
|
||||
|
||||
fn color_slider<'a>(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue