Skip to content

Commit

Permalink
fixed Icon Fonts functions so they are the same name if one is turned…
Browse files Browse the repository at this point in the history
… off
  • Loading branch information
genusistimelord committed Dec 18, 2023
1 parent 0d2750c commit 9504405
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 55 deletions.
3 changes: 2 additions & 1 deletion src/graphics/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cfg_if! {
pub mod bootstrap;
pub mod nerd;

pub use bootstrap::{BootstrapIcon, icon_to_char, icon_to_string};
/// 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.
Expand All @@ -20,7 +21,7 @@ cfg_if! {

} else {
pub mod required;

pub use required::{BootstrapIcon, icon_to_char, icon_to_string};
/// 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.
Expand Down
40 changes: 23 additions & 17 deletions src/graphics/icons/required.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/// Bootstrap RequiredIcons
#[derive(Copy, Clone, Debug, Hash)]
pub enum RequiredRequiredIcon {
pub enum BootstrapIcon {
/// caret-down-fill
CaretDownFill,
/// caret-left-fill
Expand All @@ -18,32 +18,38 @@ pub enum RequiredRequiredIcon {
X,
}

/// Converts an RequiredIcon into a char.
/// Converts an BootstrapIcon into a char.
#[must_use]
pub const fn icon_to_char(RequiredIcon: RequiredRequiredIcon) -> char {
match RequiredIcon {
RequiredIcon::CaretDownFill => '\u{f217}',
RequiredIcon::CaretLeftFill => '\u{f21b}',
RequiredIcon::CaretRightFill => '\u{f21f}',
RequiredIcon::CaretUpFill => '\u{f223}',
RequiredIcon::Check => '\u{f25c}',
RequiredIcon::X => '\u{f5ae}',
pub const fn icon_to_char(icon: BootstrapIcon) -> char {
match icon {
BootstrapIcon::CaretDownFill => '\u{f217}',
BootstrapIcon::CaretLeftFill => '\u{f21b}',
BootstrapIcon::CaretRightFill => '\u{f21f}',
BootstrapIcon::CaretUpFill => '\u{f223}',
BootstrapIcon::Check => '\u{f25c}',
BootstrapIcon::X => '\u{f5ae}',
}
}

impl From<RequiredIcon> for char {
fn from(RequiredIcon: RequiredIcon) -> Self {
icon_to_char(RequiredIcon)
/// Converts an BootstrapIcon into a String.
#[must_use]
pub fn icon_to_string(icon: BootstrapIcon) -> String {
icon_to_char(icon).to_string()
}

impl From<BootstrapIcon> for char {
fn from(icon: BootstrapIcon) -> Self {
icon_to_char(icon)
}
}

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

impl std::fmt::Display for RequiredIcon {
impl std::fmt::Display for BootstrapIcon {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", icon_to_char(*self))
}
Expand Down
10 changes: 3 additions & 7 deletions src/native/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
//!
//! *This API requires the following crate features to be activated: card*

use crate::graphics::icons::{
bootstrap::{icon_to_string, BootstrapIcon},
BOOTSTRAP_FONT,
};
use crate::graphics::icons::{icon_to_string, BootstrapIcon, BOOTSTRAP_FONT};

use iced_widget::{
core::{
Expand Down Expand Up @@ -779,16 +776,15 @@ fn draw_head<Message, Renderer>(
let close_bounds = close_layout.bounds();
let is_mouse_over_close = close_bounds.contains(cursor.position().unwrap_or_default());


renderer.fill_text(
core::text::Text {
content: &Icon::X.to_string(),
content: &icon_to_string(BootstrapIcon::X),
bounds: Size::new(close_bounds.width, close_bounds.height),
size: Pixels(
close_size.unwrap_or_else(|| renderer.default_size().0)
+ if is_mouse_over_close { 1.0 } else { 0.0 },
),
font: ICON_FONT,
font: BOOTSTRAP_FONT,
horizontal_alignment: Horizontal::Center,
vertical_alignment: Vertical::Center,
line_height: LineHeight::Relative(1.3),
Expand Down
17 changes: 8 additions & 9 deletions src/native/number_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ use num_traits::{Num, NumAssignOps};
use std::{fmt::Display, str::FromStr};

pub use crate::{
graphics::icons::{bootstrap::BootstrapIcon, BOOTSTRAP_FONT},
graphics::icons::{
bootstrap::{icon_to_string, BootstrapIcon},
BOOTSTRAP_FONT,
},
style::number_input::{self, Appearance, StyleSheet},
};

Expand Down Expand Up @@ -724,15 +727,12 @@ where
.unwrap_or(Background::Color(Color::TRANSPARENT)),
);

let mut buffer = [0; 4];


renderer.fill_text(
core::text::Text {
content: char::from(Icon::CaretDownFill).encode_utf8(&mut buffer),
content: &icon_to_string(BootstrapIcon::CaretDownFill),
bounds: Size::new(dec_bounds.width, dec_bounds.height),
size: icon_size,
font: ICON_FONT,
font: BOOTSTRAP_FONT,
horizontal_alignment: Horizontal::Center,
vertical_alignment: Vertical::Center,
line_height: LineHeight::Relative(1.3),
Expand All @@ -743,7 +743,6 @@ where
dec_bounds,
);


// increase button section
renderer.fill_quad(
renderer::Quad {
Expand All @@ -759,10 +758,10 @@ where

renderer.fill_text(
core::text::Text {
content: char::from(Icon::CaretUpFill).encode_utf8(&mut buffer),
content: &icon_to_string(BootstrapIcon::CaretUpFill),
bounds: Size::new(inc_bounds.width, inc_bounds.height),
size: icon_size,
font: ICON_FONT,
font: BOOTSTRAP_FONT,
horizontal_alignment: Horizontal::Center,
vertical_alignment: Vertical::Center,
line_height: LineHeight::Relative(1.3),
Expand Down
2 changes: 1 addition & 1 deletion src/native/overlay/color_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ fn rgba_color<Theme>(
content: label,
bounds: Size::new(label_layout.bounds().width, label_layout.bounds().height),
size: renderer.default_size(),
font: crate::ICON_FONT,
font: crate::BOOTSTRAP_FONT,
horizontal_alignment: Horizontal::Center,
vertical_alignment: Vertical::Center,
line_height: text::LineHeight::Relative(1.3),
Expand Down
18 changes: 8 additions & 10 deletions src/native/overlay/date_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ where
.width(Length::Fill)
.push(Container::new(
Row::new().push(
Text::new(char::from(Icon::CaretLeftFill).to_string())
Text::new(icon_to_string(BootstrapIcon::CaretLeftFill))
.size(font_size.0 + 1.0)
.font(crate::BOOTSTRAP_FONT),
),
Expand All @@ -416,7 +416,7 @@ where
.push(
// Right Month arrow
Container::new(
Text::new(char::from(Icon::CaretRightFill).to_string())
Text::new(icon_to_string(BootstrapIcon::CaretRightFill))
.size(font_size.0 + 1.0)
.font(crate::BOOTSTRAP_FONT),
)
Expand All @@ -427,10 +427,9 @@ where
.push(
Row::new()
.width(Length::Fill)

.push(Container::new(
Row::new().push(
Text::new(char::from(Icon::CaretLeftFill).to_string())
Text::new(icon_to_string(BootstrapIcon::CaretLeftFill))
.size(font_size.0 + 1.0)
.font(BOOTSTRAP_FONT),
),
Expand All @@ -443,11 +442,12 @@ where
// Right Year arrow
Container::new(
Row::new().push(
Text::new(char::from(Icon::CaretRightFill).to_string())
Text::new(icon_to_string(BootstrapIcon::CaretRightFill))
.size(font_size.0 + 1.0)
.font(BOOTSTRAP_FONT),
),
) .height(Length::Shrink)
)
.height(Length::Shrink)
.width(Length::Shrink),
),
);
Expand Down Expand Up @@ -1125,13 +1125,11 @@ fn month_year<Theme>(
);
}

let mut buffer = [0; 4];

// Left caret

renderer.fill_text(
core::text::Text {
content: char::from(Icon::CaretLeftFill).encode_utf8(&mut buffer),
content: &icon_to_string(BootstrapIcon::CaretLeftFill),
bounds: Size::new(left_bounds.width, left_bounds.height),
size: core::Pixels(
renderer.default_size().0 + if left_arrow_hovered { 1.0 } else { 0.0 },
Expand Down Expand Up @@ -1173,7 +1171,7 @@ fn month_year<Theme>(
// Right caret
renderer.fill_text(
core::text::Text {
content: char::from(BootstrapIcon::CaretRightFill).encode_utf8(&mut buffer),
content: &icon_to_string(BootstrapIcon::CaretRightFill),
bounds: Size::new(right_bounds.width, right_bounds.height),
size: core::Pixels(
renderer.default_size().0 + if right_arrow_hovered { 1.0 } else { 0.0 },
Expand Down
6 changes: 6 additions & 0 deletions src/native/overlay/time_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,12 @@ fn draw_digital_clock<Message, Theme>(
vertical_alignment: Vertical::Center,
line_height: text::LineHeight::Relative(1.3),
shaping: text::Shaping::Basic,
},
Point::new(down_bounds.center_x(), down_bounds.center_y()),
style
.get(&StyleState::Active)
.expect("Style Sheet not found.")
.text_color,
down_bounds,
);
};
Expand Down
16 changes: 6 additions & 10 deletions src/native/tab_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ where
match tab_label {
TabLabel::Icon(icon) => Column::new()
.align_items(Alignment::Center)
.push(layout_icon(icon, self.icon_size + 1.0, self.icon_font)),
.push(layout_icon(icon, self.icon_size + 1.0, self.font)),

TabLabel::Text(text) => Column::new()
.padding(5.0)
Expand All @@ -410,18 +410,16 @@ where
match self.position {
Position::Top => {
column = column

.push(layout_icon(
icon,
self.icon_size + 1.0,
self.icon_font,
self.font,
))
.push(layout_text(
text,
self.text_size + 1.0,
self.text_font,
));

}
Position::Right => {
column = column.push(
Expand All @@ -430,14 +428,13 @@ where
.push(layout_icon(
icon,
self.icon_size + 1.0,
self.icon_font,
self.font,
))
.push(layout_text(
text,
self.text_size + 1.0,
self.text_font,
)),

);
}
Position::Left => {
Expand All @@ -447,7 +444,7 @@ where
.push(layout_text(
text,
self.icon_size + 1.0,
self.icon_font,
self.font,
))
.push(layout_icon(
icon,
Expand All @@ -461,7 +458,7 @@ where
.push(layout_text(
text,
self.icon_size + 1.0,
self.icon_font,
self.font,
))
.push(layout_icon(
icon,
Expand Down Expand Up @@ -807,10 +804,9 @@ fn draw_tab<Renderer>(
let cross_bounds = cross_layout.bounds();
let is_mouse_over_cross = cursor.is_over(cross_bounds);


renderer.fill_text(
core::text::Text {
content:&icon_to_string(BootstrapIcon::X),
content: &icon_to_string(BootstrapIcon::X),
bounds: Size::new(cross_bounds.width, cross_bounds.height),
size: core::Pixels(close_size + if is_mouse_over_cross { 1.0 } else { 0.0 }),
font: BOOTSTRAP_FONT,
Expand Down

0 comments on commit 9504405

Please sign in to comment.