Skip to content

Commit

Permalink
swapped out font types
Browse files Browse the repository at this point in the history
  • Loading branch information
Redhawk18 committed Nov 20, 2023
1 parent 9c55289 commit 78cc6fc
Show file tree
Hide file tree
Showing 25 changed files with 31,983 additions and 4,294 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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).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).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).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).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down
6 changes: 3 additions & 3 deletions examples/floating_element/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use iced::{
};

use iced_aw::floating_element::Anchor;
use iced_aw::{helpers::floating_element, Icon, ICON_FONT};
use iced_aw::{helpers::floating_element, Icon, BOOTSTRAP_FONT};

fn main() -> iced::Result {
FloatingElementExample::run(Settings::default())
Expand Down Expand Up @@ -45,7 +45,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).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down Expand Up @@ -107,7 +107,7 @@ impl Application for FloatingElementExample {
.style(theme::Container::Box),
Button::new(
Text::new(Icon::Plus.to_string())
.font(ICON_FONT)
.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).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).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).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).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).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 BOOTSTRAP_FONT: &[u8] = include_bytes!("../fonts/icons.ttf");
const BOOTSTRAP_FONT: 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(BOOTSTRAP_FONT).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)
.BOOTSTRAP_FONT(BOOTSTRAP_FONT)
.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).map(Message::FontLoaded),
Command::perform(load(), Message::Loaded),
]),
)
Expand Down
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 78cc6fc

Please sign in to comment.