Skip to content

Commit

Permalink
Merge pull request #197 from Redhawk18/main
Browse files Browse the repository at this point in the history
icon fonts
  • Loading branch information
Andrew Wheeler(Genusis) authored Nov 22, 2023
2 parents 99e5bc1 + 3aec381 commit 75a8531
Show file tree
Hide file tree
Showing 27 changed files with 31,986 additions and 4,295 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ default = [
]

[dependencies]
cfg-if = "1.0"
num-traits = { version = "0.2.16", optional = true }
time = { version = "0.3.23", features = ["local-offset"], optional = true }
chrono = { version = "0.4.26", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion examples/WidgetIDReturn/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Application for NumberInputDemo {
(
NumberInputDemo::Loading,
Command::batch(vec![
font::load(iced_aw::graphics::icons::ICON_FONT_BYTES).map(Message::FontLoaded),
font::load(iced_aw::graphics::icons::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down
2 changes: 1 addition & 1 deletion examples/card/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Application for CardExample {
(
CardExample::Loading,
Command::batch(vec![
font::load(iced_aw::graphics::icons::ICON_FONT_BYTES).map(Message::FontLoaded),
font::load(iced_aw::graphics::icons::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down
2 changes: 1 addition & 1 deletion examples/color_picker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Application for ColorPickerExample {
(
ColorPickerExample::Loading,
Command::batch(vec![
font::load(iced_aw::graphics::icons::ICON_FONT_BYTES).map(Message::FontLoaded),
font::load(iced_aw::graphics::icons::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down
2 changes: 1 addition & 1 deletion examples/date_picker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Application for DatePickerExample {
(
DatePickerExample::Loading,
Command::batch(vec![
font::load(iced_aw::graphics::icons::ICON_FONT_BYTES).map(Message::FontLoaded),
font::load(iced_aw::graphics::icons::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down
10 changes: 6 additions & 4 deletions examples/floating_element/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use iced::{
};

use iced_aw::floating_element::Anchor;
use iced_aw::{helpers::floating_element, Icon, ICON_FONT};
use iced_aw::graphics::icons::bootstrap::icon_to_string;
use iced_aw::BootstrapIcon;
use iced_aw::{helpers::floating_element, BOOTSTRAP_FONT};

fn main() -> iced::Result {
FloatingElementExample::run(Settings::default())
Expand Down Expand Up @@ -45,7 +47,7 @@ impl Application for FloatingElementExample {
(
FloatingElementExample::Loading,
Command::batch(vec![
font::load(iced_aw::graphics::icons::ICON_FONT_BYTES).map(Message::FontLoaded),
font::load(iced_aw::graphics::icons::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down Expand Up @@ -106,8 +108,8 @@ impl Application for FloatingElementExample {
.max_height(600)
.style(theme::Container::Box),
Button::new(
Text::new(Icon::Plus.to_string())
.font(ICON_FONT)
Text::new(icon_to_string(BootstrapIcon::Plus))
.font(BOOTSTRAP_FONT)
.size(35)
.line_height(1.0)
.shaping(text::Shaping::Advanced),
Expand Down
2 changes: 1 addition & 1 deletion examples/modal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Application for ModalExample {
(
ModalExample::Loading,
Command::batch(vec![
font::load(iced_aw::graphics::icons::ICON_FONT_BYTES).map(Message::FontLoaded),
font::load(iced_aw::graphics::icons::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down
2 changes: 1 addition & 1 deletion examples/modal_component/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Application for ModalExample {
(
ModalExample::Loading,
Command::batch(vec![
font::load(iced_aw::graphics::icons::ICON_FONT_BYTES).map(Message::FontLoaded),
font::load(iced_aw::graphics::icons::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple_modals/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Application for MultipleModalsExample {
state: State::Start,
button_pressed: None,
},
font::load(iced_aw::graphics::icons::ICON_FONT_BYTES).map(Message::FontLoaded),
font::load(iced_aw::graphics::icons::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded),
)
}

Expand Down
2 changes: 1 addition & 1 deletion examples/number_input/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Application for NumberInputDemo {
(
NumberInputDemo::Loading,
Command::batch(vec![
font::load(iced_aw::graphics::icons::ICON_FONT_BYTES).map(Message::FontLoaded),
font::load(iced_aw::graphics::icons::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down
2 changes: 1 addition & 1 deletion examples/tab_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Application for TabBarExample {
(
TabBarExample::Loading,
Command::batch(vec![
font::load(iced_aw::graphics::icons::ICON_FONT_BYTES).map(Message::FontLoaded),
font::load(iced_aw::graphics::icons::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down
8 changes: 4 additions & 4 deletions examples/tabs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use settings::{SettingsMessage, SettingsTab, TabBarPosition};

const HEADER_SIZE: u16 = 32;
const TAB_PADDING: u16 = 16;
const ICON_FONT_BYTES: &[u8] = include_bytes!("../fonts/icons.ttf");
const ICON_FONT: Font = Font::with_name("icons");
const ICON_BYTES: &[u8] = include_bytes!("../fonts/icons.ttf");
const ICON: Font = Font::with_name("icons");

enum Icon {
User,
Expand Down Expand Up @@ -89,7 +89,7 @@ impl Application for TabBarExample {
(
TabBarExample::Loading,
Command::batch(vec![
font::load(ICON_FONT_BYTES).map(Message::FontLoaded),
font::load(ICON_BYTES).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down Expand Up @@ -173,7 +173,7 @@ impl Application for TabBarExample {
)
.set_active_tab(&state.active_tab)
.tab_bar_style(theme.clone())
.icon_font(ICON_FONT)
.icon_font(ICON)
.tab_bar_position(match position {
TabBarPosition::Top => iced_aw::TabBarPosition::Top,
TabBarPosition::Bottom => iced_aw::TabBarPosition::Bottom,
Expand Down
2 changes: 1 addition & 1 deletion examples/time_picker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Application for TimePickerExample {
(
TimePickerExample::Loading,
Command::batch(vec![
font::load(iced_aw::graphics::icons::ICON_FONT_BYTES).map(Message::FontLoaded),
font::load(iced_aw::graphics::icons::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down
Binary file modified src/graphics/fonts/bootstrap-icons.ttf
Binary file not shown.
Binary file added src/graphics/fonts/nerd-icons.ttf
Binary file not shown.
55 changes: 19 additions & 36 deletions src/graphics/icons.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,30 @@
//! The default icon font of the widgets of this library.
use cfg_if::cfg_if;
use iced_widget::core::Font;

#[cfg(feature = "icons")]
mod bootstrap;
#[cfg(feature = "icons")]
pub use bootstrap::*;
cfg_if! {
if #[cfg(feature = "icons")] {
pub mod bootstrap;
pub mod nerd;

#[cfg(not(feature = "icons"))]
mod required;
#[cfg(not(feature = "icons"))]
pub use required::*;
/// The default icon font bytes for loading the font into iced.
pub const BOOTSTRAP_FONT_BYTES: &[u8] = include_bytes!("./fonts/bootstrap-icons.ttf");
/// the icon font that has all nerd fonts.
pub const NERD_FONT_BYTES: &[u8] = include_bytes!("./fonts/nerd-icons.ttf");

/// The default icon font bytes for loading the font into iced.
#[cfg(feature = "icons")]
pub const ICON_FONT_BYTES: &[u8] = include_bytes!("./fonts/bootstrap-icons.ttf");
/// The bootstrap icon font.
pub const BOOTSTRAP_FONT: Font = Font::with_name("bootstrap-icons");
/// The nerd icon font.
pub const NERD_FONT: Font = Font::with_name("nerd-icons");

/// The default icon font bytes for loading the font into iced.
#[cfg(not(feature = "icons"))]
pub const ICON_FONT_BYTES: &[u8] = include_bytes!("./fonts/required-icons.ttf");
} else {
pub mod required;

/// The default icon font.
#[cfg(feature = "icons")]
pub const ICON_FONT: Font = Font::with_name("bootstrap-icons");

/// The default icon font.
#[cfg(not(feature = "icons"))]
pub const ICON_FONT: Font = Font::with_name("required-icons");

impl From<Icon> for char {
fn from(icon: Icon) -> Self {
icon_to_char(icon)
/// The default icon font bytes for loading the font into iced.
pub const BOOTSTRAP_FONT_BYTES: &[u8] = include_bytes!("./fonts/required-icons.ttf");
/// The default icon font.
pub const BOOTSTRAP_FONT: Font = Font::with_name("required-icons");
}
}

impl From<Icon> for String {
fn from(icon: Icon) -> Self {
format!("{}", icon_to_char(icon))
}
}

impl std::fmt::Display for Icon {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", icon_to_char(*self))
}
}
Loading

0 comments on commit 75a8531

Please sign in to comment.