Skip to content

Commit

Permalink
raw color support
Browse files Browse the repository at this point in the history
  • Loading branch information
Redhawk18 committed Jul 20, 2023
1 parent e585de8 commit a274767
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::path::PathBuf;

use iced::theme::Text;
use iced::widget::text;
use iced::widget::text_input;
use iced::widget::Column;
Expand All @@ -10,7 +9,7 @@ mod file_dialog;
mod theme;

pub use elements::menu_bar;
use theme::{Theme, Element};
use theme::{Element, Theme};

#[derive(Debug, Clone)]
pub enum Message {
Expand Down
4 changes: 1 addition & 3 deletions src/gui/theme/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use iced::widget::{button, text, text_input};
use iced::{application, color, Color, Background};
use iced::{application, color, Background, Color};
use iced_aw::menu;
use iced_aw::style::tab_bar; //FIXME https:/iced-rs/iced_aw/issues/151


pub type Renderer = iced::Renderer<Theme>;
pub type Element<'msg, Message> = iced::Element<'msg, Message, Renderer>;

Expand Down Expand Up @@ -53,7 +52,6 @@ impl tab_bar::StyleSheet for Theme {
fn hovered(&self, style: Self::Style, is_active: bool) -> tab_bar::Appearance {
Default::default()
}

}

impl text::StyleSheet for Theme {
Expand Down
43 changes: 41 additions & 2 deletions src/gui/theme/palette.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,43 @@
use iced::Color;

/// raw hex colors from the theme files
pub struct Palette {

}
accent: Color,
background: Color,
primary: Color,
secondary: Color,
text: Color,
}

impl Default for Palette {
fn default() -> Palette {
Palette {
accent: hex_to_color("#000000").unwrap(),
background: hex_to_color("#ffffff").unwrap(),
primary: hex_to_color("#4685ff").unwrap(),
secondary: hex_to_color("#f2f2f2").unwrap(),
text: hex_to_color("#ffb084").unwrap(),
}
}
}

fn hex_to_color(hex: &str) -> Option<Color> {
if hex.len() == 7 {
let hash = &hex[0..1];
let r = u8::from_str_radix(&hex[1..3], 16);
let g = u8::from_str_radix(&hex[3..5], 16);
let b = u8::from_str_radix(&hex[5..7], 16);

return match (hash, r, g, b) {
("#", Ok(r), Ok(g), Ok(b)) => Some(Color {
r: r as f32 / 255.0,
g: g as f32 / 255.0,
b: b as f32 / 255.0,
a: 1.0,
}),
_ => None,
};
}

None
}

0 comments on commit a274767

Please sign in to comment.