diff --git a/Cargo.toml b/Cargo.toml index 7ffc522..02222dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fltk-theme" -version = "0.1.8" +version = "0.2.0" authors = ["MoAlyousef "] edition = "2018" description = "A theming crate for fltk-rs" diff --git a/examples/aqua_dark.rs b/examples/aqua_dark.rs index 8ccc31a..b54646d 100644 --- a/examples/aqua_dark.rs +++ b/examples/aqua_dark.rs @@ -12,7 +12,7 @@ fn main() { widget_scheme.apply(); let mut win = window::Window::default().with_size(400, 300); let mut inp = input::Input::new(50, 50, 300, 30, None); - inp.set_color(Color::from_rgb(FRAME_COL.0, FRAME_COL.1, FRAME_COL.2)); + inp.set_color(Color::from_tup(*FRAME_COL)); let mut check = button::CheckButton::new(160, 150, 80, 30, " Check"); check.set_value(true); check.set_frame(enums::FrameType::FlatBox); @@ -20,8 +20,8 @@ fn main() { round.set_value(true); round.set_frame(enums::FrameType::FlatBox); let mut btn = button::Button::new(160, 230, 80, 30, "Hello"); - btn.set_color(Color::from_rgb(CTRL_COL.0, CTRL_COL.1, CTRL_COL.2)); - btn.set_selection_color(Color::from_rgb(SYS_CYAN.0, SYS_CYAN.1, SYS_CYAN.2)); + btn.set_color(Color::from_tup(*CTRL_COL)); + btn.set_selection_color(Color::from_tup(*SYS_CYAN)); win.end(); win.make_resizable(true); win.show(); diff --git a/examples/fluent.rs b/examples/fluent.rs index b102c80..af94338 100644 --- a/examples/fluent.rs +++ b/examples/fluent.rs @@ -1,36 +1,42 @@ -use fltk::{prelude::*, *}; -use fltk_theme::{widget_themes, ThemeType, WidgetTheme}; +use fltk::{prelude::*, enums::*, *}; +use fltk_theme::{SchemeType, WidgetScheme}; +use fltk_theme::widget_schemes::fluent::frames::*; +use fltk_theme::widget_schemes::fluent::colors::*; fn main() { let a = app::App::default(); - let theme = WidgetTheme::new(ThemeType::Fluent); + app::background(0xF0, 0xF0, 0xF0); + app::background2(0xFF, 0xFF, 0xFF); + app::foreground(0x00, 0x00, 0x00); + app::set_color(Color::Selection, SEL_COL.0, SEL_COL.1, SEL_COL.2); + let theme = WidgetScheme::new(SchemeType::Fluent); theme.apply(); let mut win = window::Window::default().with_size(400, 300); let mut choice = menu::Choice::new(100, 100, 200, 30, None); choice.add_choice("Fluent"); choice.set_value(0); - choice.set_frame(widget_themes::OS_PANEL_THIN_UP_BOX); + choice.set_frame(FrameType::FlatBox); let mut check = button::CheckButton::new(160, 150, 80, 30, " Check"); check.set_value(true); - check.set_frame(enums::FrameType::FlatBox); + check.set_frame(FrameType::FlatBox); let mut round = button::RoundButton::new(160, 180, 80, 30, " Round"); round.set_value(true); - round.set_frame(enums::FrameType::FlatBox); + round.set_frame(FrameType::FlatBox); let mut toggle = button::ToggleButton::new(100, 220, 80, 30, "Toggle"); - toggle.set_color(enums::Color::from_hex(0x0078D4)); - toggle.set_label_color(enums::Color::White); + toggle.set_color(Color::from_tup(*ACCENT_COL)); + toggle.set_label_color(Color::White); toggle.set_selection_color(toggle.color().darker()); let mut btn = button::Button::new(220, 220, 80, 30, "Hello"); - btn.set_frame(widget_themes::OS_DEFAULT_BUTTON_UP_BOX); - btn.set_down_frame(widget_themes::OS_DEFAULT_DEPRESSED_DOWN_BOX); + btn.set_frame(OS_DEFAULT_BUTTON_UP_BOX); + btn.set_down_frame(OS_DEFAULT_DEPRESSED_DOWN_BOX); btn.handle(|b, ev| match ev { - enums::Event::Enter => { - b.set_frame(widget_themes::OS_HOVERED_UP_BOX); + Event::Enter => { + b.set_frame(OS_HOVERED_UP_BOX); b.redraw(); true }, - enums::Event::Leave => { - b.set_frame(widget_themes::OS_DEFAULT_BUTTON_UP_BOX); + Event::Leave => { + b.set_frame(OS_DEFAULT_BUTTON_UP_BOX); b.redraw(); true }, diff --git a/examples/frames.rs b/examples/frames.rs index 039668f..b23ae85 100644 --- a/examples/frames.rs +++ b/examples/frames.rs @@ -7,7 +7,7 @@ fn main() { theme.apply(); let mut win = window::Window::default().with_size(800, 800); let mut choice = menu::Choice::new(300, 10, 200, 30, None); - choice.add_choice("Classic|Aero|Metro|AquaClassic|Greybird|Blue|HighContrast|Dark|Fluent"); + choice.add_choice("Classic|Aero|Metro|AquaClassic|Greybird|Blue|HighContrast|Dark"); choice.set_value(6); choice.set_frame(OS_PANEL_THIN_UP_BOX); let mut vgrid = group::VGrid::new(50, 100, 700, 700, None); @@ -110,7 +110,6 @@ fn main() { 5 => WidgetTheme::new(ThemeType::Blue), 6 => WidgetTheme::new(ThemeType::HighContrast), 7 => WidgetTheme::new(ThemeType::Dark), - 8 => WidgetTheme::new(ThemeType::Fluent), _ => unimplemented!(), }; theme.apply(); diff --git a/examples/widget_theme.rs b/examples/widget_theme.rs index 8a85dc2..76e6a57 100644 --- a/examples/widget_theme.rs +++ b/examples/widget_theme.rs @@ -7,7 +7,7 @@ fn main() { theme.apply(); let mut win = window::Window::default().with_size(400, 300); let mut choice = menu::Choice::new(100, 100, 200, 30, None); - choice.add_choice("Classic|Aero|Metro|AquaClassic|Greybird|Blue|HighContrast|Dark|Fluent"); + choice.add_choice("Classic|Aero|Metro|AquaClassic|Greybird|Blue|HighContrast|Dark"); choice.set_value(3); choice.set_frame(widget_themes::OS_PANEL_THIN_UP_BOX); let mut check = button::CheckButton::new(160, 150, 80, 30, " Check"); @@ -30,7 +30,6 @@ fn main() { 5 => WidgetTheme::new(ThemeType::Blue), 6 => WidgetTheme::new(ThemeType::HighContrast), 7 => WidgetTheme::new(ThemeType::Dark), - 8 => WidgetTheme::new(ThemeType::Fluent), _ => WidgetTheme::new(ThemeType::Classic), }; theme.apply(); diff --git a/src/lib.rs b/src/lib.rs index dd76dbf..79f97c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -142,8 +142,6 @@ pub enum ThemeType { Dark, /// High Contrast HighContrast, - /// Windows 10 - Fluent, } #[derive(Debug, Clone, Copy)] @@ -168,7 +166,6 @@ impl WidgetTheme { ThemeType::Blue => widget_themes::blue::use_blue_theme(), ThemeType::Metro => widget_themes::metro::use_metro_theme(), ThemeType::Greybird => widget_themes::greybird::use_greybird_theme(), - ThemeType::Fluent => widget_themes::fluent::use_fluent_theme(), } } } @@ -182,6 +179,8 @@ pub enum SchemeType { Clean, /// Taken from the NTK fork Crystal, + /// Windows 10 + Fluent, /// Taken from the NTK fork, a modification of the FLTK Gleam scheme Gleam, /** @@ -213,8 +212,19 @@ impl WidgetScheme { SchemeType::Aqua => widget_schemes::aqua::use_aqua_scheme(), SchemeType::Clean => widget_schemes::clean::use_clean_scheme(), SchemeType::Crystal => widget_schemes::crystal::use_crystal_scheme(), + SchemeType::Fluent => widget_schemes::fluent::use_fluent_scheme(), SchemeType::Gleam => widget_schemes::gleam::use_gleam_scheme(), SchemeType::SvgBased => widget_schemes::svg_based::use_svg_based_scheme(), } } } + +pub trait FromColor { + fn from_tup(tup: (u8, u8, u8, u8)) -> Color; +} + +impl FromColor for Color { + fn from_tup(tup: (u8, u8, u8, u8)) -> Color { + Color::from_rgb(tup.0, tup.1, tup.2) + } +} diff --git a/src/widget_schemes/aqua.rs b/src/widget_schemes/aqua.rs index 9e65c76..a532f4b 100644 --- a/src/widget_schemes/aqua.rs +++ b/src/widget_schemes/aqua.rs @@ -27,6 +27,7 @@ macro_rules! get_colors { #[cfg(target_os = "macos")] mod sys { + pub use crate::FromColor; lazy_static::lazy_static! { pub static ref BG_COL: (u8, u8, u8, u8) = get_colors!(my_windowBackgroundColor); pub static ref FG_COL: (u8, u8, u8, u8) = get_colors!(my_labelColor); @@ -67,6 +68,7 @@ mod sys { } pub mod dark { + pub use crate::FromColor; lazy_static::lazy_static! { pub static ref BG2_COL: (u8, u8, u8, u8) = (0, 0, 0, 255); pub static ref SYS_CYAN: (u8, u8, u8, u8) = (90, 200 , 245, 255); @@ -109,6 +111,7 @@ pub mod dark { } pub mod light { + pub use crate::FromColor; lazy_static::lazy_static! { pub static ref BG2_COL: (u8, u8, u8, u8) = (255, 255, 255, 255); pub static ref SYS_CYAN: (u8, u8, u8, u8) = (85, 190 , 240, 255); diff --git a/src/widget_themes/fluent.rs b/src/widget_schemes/fluent.rs similarity index 66% rename from src/widget_themes/fluent.rs rename to src/widget_schemes/fluent.rs index 4e1e3f8..1b81085 100644 --- a/src/widget_themes/fluent.rs +++ b/src/widget_schemes/fluent.rs @@ -1,4 +1,5 @@ use super::*; +use fltk::{image, prelude::ImageExt}; fn rect(x: i32, y: i32, w: i32, h: i32, c: Color) { draw_rect_fill(x, y, w, h, c); @@ -48,9 +49,22 @@ fn border_box(x: i32, y: i32, w: i32, h: i32, c: Color) { } fn round_box(x: i32, y: i32, w: i32, h: i32, c: Color) { - rectf(x, y, w, h, c); - set_draw_color(Color::from_rgb(0x00, 0x00, 0x00)); - draw_arc(x - 1, y - 1, w + 2, h + 2, 0.0, 360.0); + let col = c.to_rgb(); + let svg = format!( + " + + ", + w, + h, + w / 2, + h / 2, + (w as f64 - 1.0) / 2.0, + col.0, + col.1, + col.2 + ); + let mut image = image::SvgImage::from_data(&svg).unwrap(); + image.draw(x, y, w, h); } fn hover_up_frame(x: i32, y: i32, w: i32, h: i32, c: Color) { @@ -91,7 +105,10 @@ fn depressed_down_box(x: i32, y: i32, w: i32, h: i32, c: Color) { draw_rectf(x, y, w, h); } -fn use_fluent_scheme() { +pub(crate) fn use_fluent_scheme() { + app::set_visible_focus(false); + app::set_scrollbar_size(15); + use self::frames::*; use fltk::enums::FrameType::*; app::set_scheme(app::Scheme::Base); app::set_frame_type_cb(UpBox, up_box, 1, 1, 2, 2); @@ -119,19 +136,29 @@ fn use_fluent_scheme() { app::set_frame_type2(OS_INPUT_THIN_DOWN_BOX, DownBox); } -fn use_fluent_colors() { - app::background(0xF0, 0xF0, 0xF0); - app::background2(0xFF, 0xFF, 0xFF); - app::foreground(0x00, 0x00, 0x00); - app::set_color(Color::Inactive, 0x6F, 0x6F, 0x6F); - app::set_color(Color::Selection, 0x33, 0x99, 0xFF); - app::set_color(Color::Free, 0xFF, 0xFF, 0xFF); - Tooltip::set_color(Color::from_rgb(0xFF, 0xFF, 0xFF)); - Tooltip::set_text_color(Color::ForeGround); -} - -pub(crate) fn use_fluent_theme() { - use_fluent_scheme(); - use_fluent_colors(); - use_native_settings(); -} +pub mod frames { + use fltk::enums::FrameType::{self, *}; + + pub const OS_BUTTON_UP_FRAME: FrameType = GtkUpFrame; + pub const OS_DEFAULT_BUTTON_UP_BOX: FrameType = DiamondUpBox; + pub const OS_BUTTON_UP_BOX: FrameType = GtkUpBox; + pub const OS_CHECK_DOWN_BOX: FrameType = GtkDownBox; + pub const OS_CHECK_DOWN_FRAME: FrameType = GtkDownFrame; + pub const OS_HOVERED_UP_FRAME: FrameType = PlasticUpFrame; + pub const OS_HOVERED_UP_BOX: FrameType = PlasticUpBox; + pub const OS_RADIO_ROUND_DOWN_BOX: FrameType = FrameType::GtkRoundDownBox; + pub const OS_DEPRESSED_DOWN_FRAME: FrameType = PlasticDownFrame; + pub const OS_DEPRESSED_DOWN_BOX: FrameType = PlasticDownBox; + pub const OS_DEFAULT_DEPRESSED_DOWN_BOX: FrameType = DiamondDownBox; + pub const OS_DEFAULT_HOVERED_UP_BOX: FrameType = PlasticThinUpBox; + pub const OS_INPUT_THIN_DOWN_FRAME: FrameType = PlasticRoundDownBox; + pub const OS_INPUT_THIN_DOWN_BOX: FrameType = PlasticThinDownBox; +} + +pub mod colors { + pub use crate::FromColor; + lazy_static::lazy_static! { + pub static ref ACCENT_COL: (u8, u8, u8, u8) = (0x00, 0x78, 0xD4, 0xff); + pub static ref SEL_COL: (u8, u8, u8, u8) = (0x33, 0x99, 0xFF, 0xFF); + } +} \ No newline at end of file diff --git a/src/widget_schemes/mod.rs b/src/widget_schemes/mod.rs index 97d50c7..aa245d1 100644 --- a/src/widget_schemes/mod.rs +++ b/src/widget_schemes/mod.rs @@ -7,5 +7,6 @@ use fltk::{app, draw::*, enums::Color}; pub mod aqua; pub(crate) mod clean; pub(crate) mod crystal; +pub mod fluent; pub(crate) mod gleam; pub(crate) mod svg_based; diff --git a/src/widget_themes/mod.rs b/src/widget_themes/mod.rs index 63de0f4..6655335 100644 --- a/src/widget_themes/mod.rs +++ b/src/widget_themes/mod.rs @@ -14,7 +14,6 @@ pub(crate) mod aqua_classic; pub(crate) mod blue; pub(crate) mod classic; pub(crate) mod dark; -pub(crate) mod fluent; pub(crate) mod greybird; pub(crate) mod high_contrast; pub(crate) mod metro;