Skip to content

Commit

Permalink
updated cupertino to newest iced, moved font to Graphics folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
genusistimelord committed Jul 27, 2023
1 parent 5b2c65d commit 31ca63a
Show file tree
Hide file tree
Showing 19 changed files with 308 additions and 256 deletions.
54 changes: 54 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,60 @@
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'cupertino-button'",
"cargo": {
"args": [
"build",
"--bin=cupertino-button",
"--package=cupertino-button"
],
"filter": {
"name": "cupertino-button",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'cupertino-switch'",
"cargo": {
"args": [
"build",
"--bin=cupertino-switch",
"--package=cupertino-switch"
],
"filter": {
"name": "cupertino-switch",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'cupertino-alert'",
"cargo": {
"args": [
"build",
"--bin=cupertino-alert",
"--package=cupertino-alert"
],
"filter": {
"name": "cupertino-alert",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
Expand Down
13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ default = [
"quad",
"context_menu",
"spinner",
#"cupertino",
"cupertino",
]

[dependencies]
Expand Down Expand Up @@ -89,11 +89,10 @@ members = [
"examples/badge",
"examples/card",
"examples/color_picker",
#"examples/cupertino/cupertino_alert",
#"examples/cupertino/cupertino_button",
# "examples/cupertino/cupertino_slider",
#"examples/cupertino/cupertino_spinner",
#"examples/cupertino/cupertino_switch",
"examples/cupertino/cupertino_alert",
"examples/cupertino/cupertino_button",
"examples/cupertino/cupertino_spinner",
"examples/cupertino/cupertino_switch",
"examples/date_picker",
"examples/floating_element",
"examples/floating_element_anchors",
Expand All @@ -117,7 +116,7 @@ members = [
git = "https://github.com/iced-rs/iced.git"
#rev = "8221794"
#version = "0.9.0"
features = ["advanced", "lazy"]
features = ["advanced", "lazy", "tokio"]

[workspace.dependencies.iced_aw]
path = "./"
Expand Down
2 changes: 1 addition & 1 deletion examples/cupertino/cupertino_alert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2021"
publish = false

[dependencies]
iced = { version = "0.9.0", features = [] }
iced.workspace = true
iced_aw = { path = "../../../", features = ["cupertino"] }

16 changes: 13 additions & 3 deletions examples/cupertino/cupertino_alert/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use iced::widget::{column, container, Text};
use iced::{alignment, executor, Application, Command, Element, Length, Settings, Theme};
use iced::{alignment, executor, font, Application, Command, Element, Length, Settings, Theme};
use iced_aw::native::cupertino::cupertino_alert::{CupertinoAlert, CupertinoDialogAction};
use iced_aw::native::cupertino::cupertino_button::CupertinoButton;
use iced_aw::native::cupertino::cupertino_colours::system_red;
Expand Down Expand Up @@ -28,6 +28,8 @@ enum Message {
ConfirmEvent,
DialogEscape,
ShowModal,
Loaded(Result<(), String>),
FontLoaded(Result<(), font::Error>),
}

#[rustfmt::skip]
Expand All @@ -40,6 +42,10 @@ mod constants {

use constants::*;

async fn load() -> Result<(), String> {
Ok(())
}

// `cargo fmt` becomes unreadable for this example, so switching off //
#[rustfmt::skip]
impl Application for Alert {
Expand All @@ -49,7 +55,10 @@ impl Application for Alert {
type Flags = ();

fn new(_flags: ()) -> (Self, Command<Message>) {
(Alert::Loading, Command::none())
(Alert::Loading, Command::batch(vec![
font::load(iced_aw::graphics::SF_UI_ROUNDED_BYTES).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]))
}

fn title(&self) -> String {
Expand All @@ -63,6 +72,7 @@ impl Application for Alert {
Message::ConfirmEvent => *self = Alert::ConfirmEvent,
Message::DialogEscape => *self = Alert::DialogEscape,
Message::ShowModal => *self = Alert::ShowModal,
_ => {}
}

Command::none()
Expand Down Expand Up @@ -117,7 +127,7 @@ impl Application for Alert {
CupertinoButton::new()
.body(Text::new("Click to show the CupertinoAlertDialog")
.size(24.0)
.width(Length::Fixed(200.0))
.width(Length::Shrink)
.height(Length::Fixed(75.0))
.horizontal_alignment(alignment::Horizontal::Center)
)
Expand Down
2 changes: 1 addition & 1 deletion examples/cupertino/cupertino_button/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2021"
publish = false

[dependencies]
iced = { version = "0.9.0", features = [] }
iced.workspace = true
iced_aw = { path = "../../../", features = ["cupertino"] }

14 changes: 12 additions & 2 deletions examples/cupertino/cupertino_button/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use iced::{
alignment, executor,
alignment, executor, font,
widget::{column, container, text, Text},
Application, Command, Element, Length, Renderer, Settings, Theme,
};
Expand All @@ -23,6 +23,12 @@ enum ButtonApp {
enum Message {
EnabledButtonClicked,
EnabledFilledButtonClicked,
Loaded(Result<(), String>),
FontLoaded(Result<(), font::Error>),
}

async fn load() -> Result<(), String> {
Ok(())
}

// `cargo fmt` becomes unreadable for this example, so switching off //
Expand All @@ -34,7 +40,10 @@ impl Application for ButtonApp {
type Flags = ();

fn new(_flags: ()) -> (Self, Command<Message>) {
(ButtonApp::Loading, Command::none())
(ButtonApp::Loading, Command::batch(vec![
font::load(iced_aw::graphics::SF_UI_ROUNDED_BYTES).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]))
}

fn title(&self) -> String {
Expand All @@ -52,6 +61,7 @@ impl Application for ButtonApp {
println!("You clicked the filled enabled button!");
*self = ButtonApp::EnabledFilledButtonClicked;
},
_ => {}
}

Command::none()
Expand Down
4 changes: 2 additions & 2 deletions examples/cupertino/cupertino_spinner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
publish = false

[dependencies]
iced = { workspace = true, features = ["canvas", "debug", "tokio"] }
iced.workspace = true
iced_aw = { path = "../../../", features = ["cupertino"] }
tokio = { version = "1.27.0", features = ["time"] }
tokio = { version = "1.29.1", features = ["time"] }

2 changes: 1 addition & 1 deletion examples/cupertino/cupertino_switch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2021"
publish = false

[dependencies]
iced = { version = "0.9.0", features = [] }
iced.workspace = true
iced_aw = { path = "../../../", features = ["cupertino"] }

12 changes: 6 additions & 6 deletions examples/menu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl Application for App {
SizeOption::Uniform => {
menu_bar!(menu_1(self), menu_2(self), menu_3(self), menu_4(self))
.item_width(ItemWidth::Uniform(180))
.item_height(ItemHeight::Uniform(25))
.item_height(ItemHeight::Uniform(30))
}
SizeOption::Static => menu_bar!(
menu_1(self),
Expand All @@ -179,7 +179,7 @@ impl Application for App {
menu_5(self),
)
.item_width(ItemWidth::Static(180))
.item_height(ItemHeight::Static(25)),
.item_height(ItemHeight::Static(30)),
}
.spacing(4.0)
.bounds_expand(30)
Expand Down Expand Up @@ -323,7 +323,7 @@ fn debug_sub_menu<'a>(
fn separator<'a>() -> MenuTree<'a, Message, iced::Renderer> {
menu_tree!(quad::Quad {
color: [0.5; 3].into(),
border_radius: [4.0; 4].into(),
border_radius: [4.0; 4],
inner_bounds: quad::InnerBounds::Ratio(0.98, 0.1),
..Default::default()
})
Expand All @@ -341,13 +341,13 @@ fn dot_separator<'a>() -> MenuTree<'a, Message, iced::Renderer> {
fn labeled_separator(label: &'_ str) -> MenuTree<'_, Message, iced::Renderer> {
let q_1 = quad::Quad {
color: [0.5; 3].into(),
border_radius: [4.0; 4].into(),
border_radius: [4.0; 4],
inner_bounds: quad::InnerBounds::Ratio(0.98, 0.1),
..Default::default()
};
let q_2 = quad::Quad {
color: [0.5; 3].into(),
border_radius: [4.0; 4].into(),
border_radius: [4.0; 4],
inner_bounds: quad::InnerBounds::Ratio(0.98, 0.1),
..Default::default()
};
Expand All @@ -367,7 +367,7 @@ fn circle(color: Color) -> quad::Quad {
quad::Quad {
color,
inner_bounds: quad::InnerBounds::Square(radius * 2.0),
border_radius: [radius; 4].into(),
border_radius: [radius; 4],
..Default::default()
}
}
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions src/graphics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
//! A module fitting `iced_graphics`.

pub mod icons;

/// The default cupertino font bytes for loading the font into the system.
#[cfg(feature = "cupertino")]
pub const SF_UI_ROUNDED_BYTES: &[u8] = include_bytes!("./fonts/SFUIRounded.ttf");

/// The default cupertino font for alerts and button.
#[cfg(feature = "cupertino")]
pub const SF_UI_ROUNDED: iced_widget::core::Font =
iced_widget::core::Font::with_name("sfuiRounded");
Loading

0 comments on commit 31ca63a

Please sign in to comment.