From 95044055e1cb6d6d2e22f36f8946c7b795d749a4 Mon Sep 17 00:00:00 2001 From: genusistimelord Date: Mon, 18 Dec 2023 14:10:15 -0500 Subject: [PATCH] fixed Icon Fonts functions so they are the same name if one is turned off --- src/graphics/icons.rs | 3 ++- src/graphics/icons/required.rs | 40 +++++++++++++++++------------- src/native/card.rs | 10 +++----- src/native/number_input.rs | 17 ++++++------- src/native/overlay/color_picker.rs | 2 +- src/native/overlay/date_picker.rs | 18 ++++++-------- src/native/overlay/time_picker.rs | 6 +++++ src/native/tab_bar.rs | 16 +++++------- 8 files changed, 57 insertions(+), 55 deletions(-) diff --git a/src/graphics/icons.rs b/src/graphics/icons.rs index 2c9495b3..334ed50c 100644 --- a/src/graphics/icons.rs +++ b/src/graphics/icons.rs @@ -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. @@ -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. diff --git a/src/graphics/icons/required.rs b/src/graphics/icons/required.rs index c1208e86..ab363098 100644 --- a/src/graphics/icons/required.rs +++ b/src/graphics/icons/required.rs @@ -3,7 +3,7 @@ /// Bootstrap RequiredIcons #[derive(Copy, Clone, Debug, Hash)] -pub enum RequiredRequiredIcon { +pub enum BootstrapIcon { /// caret-down-fill CaretDownFill, /// caret-left-fill @@ -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 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 for char { + fn from(icon: BootstrapIcon) -> Self { + icon_to_char(icon) } } -impl From for String { - fn from(RequiredIcon: RequiredIcon) -> Self { - format!("{}", icon_to_char(RequiredIcon)) +impl From 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)) } diff --git a/src/native/card.rs b/src/native/card.rs index 62fe95b2..de04d128 100644 --- a/src/native/card.rs +++ b/src/native/card.rs @@ -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::{ @@ -779,16 +776,15 @@ fn draw_head( 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), diff --git a/src/native/number_input.rs b/src/native/number_input.rs index cd97d136..f156dd15 100644 --- a/src/native/number_input.rs +++ b/src/native/number_input.rs @@ -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}, }; @@ -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), @@ -743,7 +743,6 @@ where dec_bounds, ); - // increase button section renderer.fill_quad( renderer::Quad { @@ -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), diff --git a/src/native/overlay/color_picker.rs b/src/native/overlay/color_picker.rs index ccfa3804..6cf535c8 100644 --- a/src/native/overlay/color_picker.rs +++ b/src/native/overlay/color_picker.rs @@ -1412,7 +1412,7 @@ fn rgba_color( 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), diff --git a/src/native/overlay/date_picker.rs b/src/native/overlay/date_picker.rs index 9d87477d..394e3839 100644 --- a/src/native/overlay/date_picker.rs +++ b/src/native/overlay/date_picker.rs @@ -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), ), @@ -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), ) @@ -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), ), @@ -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), ), ); @@ -1125,13 +1125,11 @@ fn month_year( ); } - 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 }, @@ -1173,7 +1171,7 @@ fn month_year( // 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 }, diff --git a/src/native/overlay/time_picker.rs b/src/native/overlay/time_picker.rs index 3fa0179f..338c19c1 100644 --- a/src/native/overlay/time_picker.rs +++ b/src/native/overlay/time_picker.rs @@ -1498,6 +1498,12 @@ fn draw_digital_clock( 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, ); }; diff --git a/src/native/tab_bar.rs b/src/native/tab_bar.rs index c1507fcb..3c49b7a7 100644 --- a/src/native/tab_bar.rs +++ b/src/native/tab_bar.rs @@ -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) @@ -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( @@ -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 => { @@ -447,7 +444,7 @@ where .push(layout_text( text, self.icon_size + 1.0, - self.icon_font, + self.font, )) .push(layout_icon( icon, @@ -461,7 +458,7 @@ where .push(layout_text( text, self.icon_size + 1.0, - self.icon_font, + self.font, )) .push(layout_icon( icon, @@ -807,10 +804,9 @@ fn draw_tab( 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,