Skip to content

Commit

Permalink
move aqua stuff to scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
MoAlyousef committed Sep 28, 2021
1 parent 8d6a20f commit 071b8da
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 467 deletions.
19 changes: 13 additions & 6 deletions examples/aqua_dark.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
use fltk::{prelude::*, *};
use fltk_theme::{widget_themes, WidgetTheme, ThemeType};
use fltk::{prelude::*, enums::*, *};
use fltk_theme::{WidgetScheme, SchemeType};
use fltk_theme::widget_schemes::aqua::dark::*; // get all the dark aqua colors

fn main() {
let a = app::App::default();
let widget_theme = WidgetTheme::new(ThemeType::AquaDark);
widget_theme.apply();
app::background(BG_COL.0, BG_COL.1, BG_COL.2);
app::background2(CTRL_ACC_COL.0, CTRL_ACC_COL.1, CTRL_ACC_COL.2);
app::foreground(FG_COL.0, FG_COL.1, FG_COL.2);
app::set_color(Color::Selection, 255, 255, 255);
let widget_scheme = WidgetScheme::new(SchemeType::Aqua);
widget_scheme.apply();
let mut win = window::Window::default().with_size(400, 300);
input::Input::new(50, 50, 300, 30, None);
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));
let mut check = button::CheckButton::new(160, 150, 80, 30, " Check");
check.set_value(true);
check.set_frame(enums::FrameType::FlatBox);
let mut round = button::RoundButton::new(160, 180, 80, 30, " Round");
round.set_value(true);
round.set_frame(enums::FrameType::FlatBox);
let mut btn = button::Button::new(160, 230, 80, 30, "Hello");
btn.set_frame(widget_themes::OS_DEFAULT_BUTTON_UP_BOX);
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));
win.end();
win.make_resizable(true);
win.show();
Expand Down
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ pub enum ThemeType {
Metro,
/// Classic MacOS
AquaClassic,
/// Modern MacOS using system colors, Dark theme
AquaDark,
/// Modern MacOS using system colors, light theme
AquaLight,
/// Xfce
Greybird,
/// Windows 2000
Expand Down Expand Up @@ -167,8 +163,6 @@ impl WidgetTheme {
ThemeType::Classic => widget_themes::classic::use_classic_theme(),
ThemeType::Aero => widget_themes::aero::use_aero_theme(),
ThemeType::AquaClassic => widget_themes::aqua_classic::use_aqua_classic_theme(),
ThemeType::AquaDark => widget_themes::aqua_dark::use_aqua_dark_theme(),
ThemeType::AquaLight => widget_themes::aqua_light::use_aqua_light_theme(),
ThemeType::Dark => widget_themes::dark::use_dark_theme(),
ThemeType::HighContrast => widget_themes::high_contrast::use_high_contrast_theme(),
ThemeType::Blue => widget_themes::blue::use_blue_theme(),
Expand All @@ -182,6 +176,8 @@ impl WidgetTheme {
/// Lists supported schemes
#[derive(Debug, Clone, Copy)]
pub enum SchemeType {
/// A scheme mimicking modern Aqua
Aqua,
/// Taken from the NTK fork
Clean,
/// Taken from the NTK fork
Expand Down Expand Up @@ -214,6 +210,7 @@ impl WidgetScheme {
/// Apply the widget theme
pub fn apply(&self) {
match self.scheme {
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::Gleam => widget_schemes::gleam::use_gleam_scheme(),
Expand Down
260 changes: 260 additions & 0 deletions src/widget_schemes/aqua.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
#[cfg(target_os = "macos")]
use crate::cocoa_helper::*;
use fltk::{app, enums::{Color, FrameType}, image, prelude::ImageExt};

#[cfg(target_os = "macos")]
fn convert_colors(colors: (f64, f64, f64, f64)) -> (u8, u8, u8, u8) {
let r = (colors.0 * 255.0) as u8;
let g = (colors.1 * 255.0) as u8;
let b = (colors.2 * 255.0) as u8;
let a = (colors.3 * 255.0) as u8;
(r, g, b, a)
}

#[cfg(target_os = "macos")]
macro_rules! get_colors {
($s:ident) => {{
let mut r = 1.0;
let mut g = 1.0;
let mut b = 1.0;
let mut a = 1.0;
unsafe {
$s(&mut r, &mut g, &mut b, &mut a);
}
convert_colors((r, g, b, a))
}};
}

#[cfg(target_os = "macos")]
mod sys {
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);
pub static ref CTRL_BG_COL: (u8, u8, u8, u8) = get_colors!(my_controlBackgroundColor);
pub static ref FRAME_COL: (u8, u8, u8, u8) = get_colors!(my_windowFrameColor);
pub static ref LABEL2_COL: (u8, u8, u8, u8) = get_colors!(my_secondaryLabelColor);
pub static ref LABEL3_COL: (u8, u8, u8, u8) = get_colors!(my_tertiaryLabelColor);
pub static ref LABEL4_COL: (u8, u8, u8, u8) = get_colors!(my_quaternaryLabelColor);
pub static ref TXT_COL: (u8, u8, u8, u8) = get_colors!(my_textColor);
pub static ref PH_TXT_COL: (u8, u8, u8, u8) = get_colors!(my_placeholderTextColor);
pub static ref SEL_TXT_COL: (u8, u8, u8, u8) = get_colors!(my_selectedTextColor);
pub static ref TXT_BG_COL: (u8, u8, u8, u8) = get_colors!(my_textBackgroundColor);
pub static ref SEL_TXT_BG_COL: (u8, u8, u8, u8) = get_colors!(my_selectedTextBackgroundColor);
pub static ref KB_IND_COL: (u8, u8, u8, u8) = get_colors!(my_keyboardFocusIndicatorColor);
pub static ref SEL_TXT2_COL: (u8, u8, u8, u8) = get_colors!(my_unemphasizedSelectedTextColor);
pub static ref SEL_TXT_BG2_COL: (u8, u8, u8, u8) = get_colors!(my_unemphasizedSelectedTextBackgroundColor);
pub static ref LINK_COL: (u8, u8, u8, u8) = get_colors!(my_linkColor);
pub static ref SEP_COL: (u8, u8, u8, u8) = get_colors!(my_separatorColor);
pub static ref SEL_BG_COL: (u8, u8, u8, u8) = get_colors!(my_selectedContentBackgroundColor);
pub static ref SEL_BG2_COL: (u8, u8, u8, u8) = get_colors!(my_unemphasizedSelectedContentBackgroundColor);
pub static ref SEL_MEN_TXT_COL: (u8, u8, u8, u8) = get_colors!(my_selectedMenuItemTextColor);
pub static ref GRID_COL: (u8, u8, u8, u8) = get_colors!(my_gridColor);
pub static ref HDR_COL: (u8, u8, u8, u8) = get_colors!(my_headerTextColor);
pub static ref CTRL_ACC_COL: (u8, u8, u8, u8) = get_colors!(my_controlAccentColor);
pub static ref CTRL_COL: (u8, u8, u8, u8) = get_colors!(my_controlColor);
pub static ref CTRL_TXT_COL: (u8, u8, u8, u8) = get_colors!(my_controlTextColor);
pub static ref DIS_CTRL_TXT_COL: (u8, u8, u8, u8) = get_colors!(my_disabledControlTextColor);
pub static ref SEL_CTRL_COL: (u8, u8, u8, u8) = get_colors!(my_selectedControlColor);
pub static ref SEL_CTRL_TXT_COL: (u8, u8, u8, u8) = get_colors!(my_selectedControlTextColor);
pub static ref ALT_SEL_CTRL_TXT_COL: (u8, u8, u8, u8) = get_colors!(my_alternateSelectedControlTextColor);
pub static ref SCRUB_BG_COL: (u8, u8, u8, u8) = get_colors!(my_scrubberTexturedBackgroundColor);
pub static ref WIN_FRM_TXT_COL: (u8, u8, u8, u8) = get_colors!(my_windowFrameTextColor);
pub static ref PAGE_BG_COL: (u8, u8, u8, u8) = get_colors!(my_underPageBackgroundColor);
pub static ref FIND_HLT_COL: (u8, u8, u8, u8) = get_colors!(my_findHighlightColor);
pub static ref HLT_COL: (u8, u8, u8, u8) = get_colors!(my_highlightColor);
pub static ref SHDW_COL: (u8, u8, u8, u8) = get_colors!(my_shadowColor);
}
}

pub mod dark {
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);
pub static ref BG_COL: (u8, u8, u8, u8) = (37, 37, 37, 255);
pub static ref FG_COL: (u8, u8, u8, u8) = (255, 254, 254, 216);
pub static ref CTRL_BG_COL: (u8, u8, u8, u8) = (22, 22, 22, 255);
pub static ref FRAME_COL: (u8, u8, u8, u8) = (153, 153, 153, 255);
pub static ref LABEL2_COL: (u8, u8, u8, u8) = (255, 254, 254, 140);
pub static ref LABEL3_COL: (u8, u8, u8, u8) = (255, 254, 254, 63);
pub static ref LABEL4_COL: (u8, u8, u8, u8) = (255, 254, 254, 25);
pub static ref TXT_COL: (u8, u8, u8, u8) = (255, 254, 254, 255);
pub static ref PH_TXT_COL: (u8, u8, u8, u8) = (255, 254, 254, 63);
pub static ref SEL_TXT_COL: (u8, u8, u8, u8) = (255, 255, 255, 255);
pub static ref TXT_BG_COL: (u8, u8, u8, u8) = (22, 22, 22, 255);
pub static ref SEL_TXT_BG_COL: (u8, u8, u8, u8) = (48, 79, 120, 255);
pub static ref KB_IND_COL: (u8, u8, u8, u8) = (27, 149, 254, 76);
pub static ref SEL_TXT2_COL: (u8, u8, u8, u8) = (255, 255, 255, 255);
pub static ref SEL_TXT_BG2_COL: (u8, u8, u8, u8) = (54, 54, 54, 255);
pub static ref LINK_COL: (u8, u8, u8, u8) = (52, 134, 254, 255);
pub static ref SEP_COL: (u8, u8, u8, u8) = (255, 254, 254, 25);
pub static ref SEL_BG_COL: (u8, u8, u8, u8) = (5, 63, 197, 255);
pub static ref SEL_BG2_COL: (u8, u8, u8, u8) = (54, 54, 54, 255);
pub static ref SEL_MEN_TXT_COL: (u8, u8, u8, u8) = (255, 254, 254, 255);
pub static ref GRID_COL: (u8, u8, u8, u8) = (20, 20, 20, 255);
pub static ref HDR_COL: (u8, u8, u8, u8) = (255, 254, 254, 255);
pub static ref CTRL_ACC_COL: (u8, u8, u8, u8) = (10, 95, 254, 255);
pub static ref CTRL_COL: (u8, u8, u8, u8) = (255, 254, 254, 63);
pub static ref CTRL_TXT_COL: (u8, u8, u8, u8) = (255, 254, 254, 216);
pub static ref DIS_CTRL_TXT_COL: (u8, u8, u8, u8) = (255, 254, 254, 63);
pub static ref SEL_CTRL_COL: (u8, u8, u8, u8) = (48, 79, 120, 255);
pub static ref SEL_CTRL_TXT_COL: (u8, u8, u8, u8) = (255, 254, 254, 216);
pub static ref ALT_SEL_CTRL_TXT_COL: (u8, u8, u8, u8) = (255, 254, 254, 255);
pub static ref SCRUB_BG_COL: (u8, u8, u8, u8) = (255, 254, 254, 255);
pub static ref WIN_FRM_TXT_COL: (u8, u8, u8, u8) = (255, 254, 254, 216);
pub static ref PAGE_BG_COL: (u8, u8, u8, u8) = (29, 29, 29, 255);
pub static ref FIND_HLT_COL: (u8, u8, u8, u8) = (255, 255, 10, 255);
pub static ref HLT_COL: (u8, u8, u8, u8) = (164, 164, 164, 255);
pub static ref SHDW_COL: (u8, u8, u8, u8) = (0, 0, 0, 255);
}
}

pub mod light {
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);
pub static ref BG_COL: (u8, u8, u8, u8) = (231, 231, 231, 255);
pub static ref FG_COL: (u8, u8, u8, u8) = (0, 0, 0, 216);
pub static ref CTRL_BG_COL: (u8, u8, u8, u8) = (255, 254, 254, 255);
pub static ref FRAME_COL: (u8, u8, u8, u8) = (153, 153, 153, 255);
pub static ref LABEL2_COL: (u8, u8, u8, u8) = (0, 0, 0, 127);
pub static ref LABEL3_COL: (u8, u8, u8, u8) = (0, 0, 0, 66);
pub static ref LABEL4_COL: (u8, u8, u8, u8) = (0, 0, 0, 25);
pub static ref TXT_COL: (u8, u8, u8, u8) = (0, 0, 0, 255);
pub static ref PH_TXT_COL: (u8, u8, u8, u8) = (0, 0, 0, 63);
pub static ref SEL_TXT_COL: (u8, u8, u8, u8) = (0, 0, 0, 255);
pub static ref TXT_BG_COL: (u8, u8, u8, u8) = (255, 254, 254, 255);
pub static ref SEL_TXT_BG_COL: (u8, u8, u8, u8) = (164, 204, 254, 255);
pub static ref KB_IND_COL: (u8, u8, u8, u8) = (7, 75, 240, 63);
pub static ref SEL_TXT2_COL: (u8, u8, u8, u8) = (0, 0, 0, 255);
pub static ref SEL_TXT_BG2_COL: (u8, u8, u8, u8) = (211, 211, 211, 255);
pub static ref LINK_COL: (u8, u8, u8, u8) = (8, 79, 209, 255);
pub static ref SEP_COL: (u8, u8, u8, u8) = (0, 0, 0, 25);
pub static ref SEL_BG_COL: (u8, u8, u8, u8) = (7, 73, 217, 255);
pub static ref SEL_BG2_COL: (u8, u8, u8, u8) = (211, 211, 211, 255);
pub static ref SEL_MEN_TXT_COL: (u8, u8, u8, u8) = (255, 254, 254, 255);
pub static ref GRID_COL: (u8, u8, u8, u8) = (223, 223, 223, 255);
pub static ref HDR_COL: (u8, u8, u8, u8) = (0, 0, 0, 216);
pub static ref CTRL_ACC_COL: (u8, u8, u8, u8) = (10, 95, 254, 255);
pub static ref CTRL_COL: (u8, u8, u8, u8) = (255, 254, 254, 255);
pub static ref CTRL_TXT_COL: (u8, u8, u8, u8) = (0, 0, 0, 216);
pub static ref DIS_CTRL_TXT_COL: (u8, u8, u8, u8) = (0, 0, 0, 63);
pub static ref SEL_CTRL_COL: (u8, u8, u8, u8) = (164, 204, 254, 255);
pub static ref SEL_CTRL_TXT_COL: (u8, u8, u8, u8) = (0, 0, 0, 216);
pub static ref ALT_SEL_CTRL_TXT_COL: (u8, u8, u8, u8) = (255, 254, 254, 255);
pub static ref SCRUB_BG_COL: (u8, u8, u8, u8) = (255, 254, 254, 255);
pub static ref WIN_FRM_TXT_COL: (u8, u8, u8, u8) = (0, 0, 0, 216);
pub static ref PAGE_BG_COL: (u8, u8, u8, u8) = (131, 131, 131, 229);
pub static ref FIND_HLT_COL: (u8, u8, u8, u8) = (255, 255, 10, 255);
pub static ref HLT_COL: (u8, u8, u8, u8) = (255, 254, 254, 255);
pub static ref SHDW_COL: (u8, u8, u8, u8) = (0, 0, 0, 255);
}
}

fn button_up_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let col = c.to_rgb();
let bg = Color::BackGround.to_rgb();
let svg = format!(
"<svg width='{0}' height='{1}'>
<defs>
<linearGradient id='grad1' x1='0%' y1='0%' x2='0%' y2='100%'>
<stop offset='0%' style='stop-color:rgb({2},{3},{4});stop-opacity:{5}' />
<stop offset='100%' style='stop-color:rgb({6},{7},{8});stop-opacity:{5}' />
</linearGradient>
</defs>
<rect width='{0}' height='{1}' rx='{9}' fill='rgb({10},{11},{12})' />
<rect width='{0}' height='{1}' rx='{9}' fill='url(#grad1)' />
</svg>",
w,
h,
col.0,
col.1,
col.2,
if bg.0 > 230 && bg.1 > 230 && bg.2 > 230 {
1.0
} else {
63 as f64 / 255.0
},
col.0 - 10,
col.1 - 10,
col.2 - 10,
h / 4,
bg.0,
bg.1,
bg.2
);
let mut image = image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
}

fn depressed_down_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let col = c.to_rgb();
let svg = format!(
"<svg width='{0}' height='{1}'>
<defs>
<linearGradient id='grad1' x1='0%' y1='0%' x2='0%' y2='100%'>
<stop offset='0%' style='stop-color:rgb({2},{3},{4});stop-opacity:1' />
<stop offset='100%' style='stop-color:rgb({5},{6},{7});stop-opacity:1' />
</linearGradient>
</defs>
<rect width='{0}' height='{1}' rx='{8}' fill='url(#grad1)' />
</svg>",
w,
h,
col.0 - 10,
col.1 - 10,
col.2 - 10,
col.0,
col.1,
col.2,
h / 4
);
let mut image = image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
}

fn radio_round_down_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let col = c.to_rgb();
let svg = format!(
"<svg width='{}' height='{}'>
<circle cx='{}' cy='{}' r='{}' fill='rgb({},{},{})'/>
</svg>",
w,
h,
w / 2,
h / 2,
w / 2,
col.0,
col.1,
col.2
);
let mut image = image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
}

fn use_scheme() {
app::set_scheme(app::Scheme::Gtk);
app::set_frame_type_cb(FrameType::UpBox, button_up_box, 1, 1, 2, 2);
app::set_frame_type_cb(
FrameType::DownBox,
depressed_down_box,
1,
1,
2,
2,
);
app::set_frame_type_cb(
FrameType::RoundDownBox,
radio_round_down_box,
2,
2,
4,
4,
);
// app::set_frame_type_cb(OS_BG_DOWN_BOX, OS_BG_BOX);
}

pub(crate) fn use_aqua_scheme() {
use_scheme();
app::set_visible_focus(false);
app::set_scrollbar_size(15);
}
2 changes: 1 addition & 1 deletion src/widget_schemes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::activated_color;
use fltk::{app, draw::*, enums::Color};

// taken from NTK's themes
pub mod aqua;
pub(crate) mod clean;
pub(crate) mod crystal;
pub(crate) mod gleam;
Expand Down
Loading

0 comments on commit 071b8da

Please sign in to comment.