Skip to content

Commit

Permalink
add aqua2 theme which checks system colors
Browse files Browse the repository at this point in the history
  • Loading branch information
MoAlyousef committed Sep 19, 2021
1 parent 01176b0 commit cbfad7e
Show file tree
Hide file tree
Showing 11 changed files with 511 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ exclude = ["/screenshots", "./examples"]
[dependencies]
fltk = "1.1.6"

[target.'cfg(target_os = "macos")'.dependencies]
lazy_static = "1.4"

[target.'cfg(target_os = "macos")'.build-dependencies]
cc = "1"
1 change: 1 addition & 0 deletions bind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bindgen src/cocoa_helper.h -o src/cocoa_helper.rs
9 changes: 9 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[cfg(target_os = "macos")]
fn main() {
let mut build = cc::Build::new();
build.file("src/cocoa_helper.m");
build.compile("cocoa");
}

#[cfg(not(target_os = "macos"))]
fn main() {}
1 change: 1 addition & 0 deletions examples/widget_theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ fn main() {
};
theme.apply();
});

a.run().unwrap();
}
25 changes: 25 additions & 0 deletions src/cocoa_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#ifndef COCOA_COLOR_DEFINITION

#define COLOR_GET(color) \
void my_##color(double *r, double *g, double *b, double *a);

#else

#define COLOR_GET(color) \
void my_##color(double *r, double *g, double *b, double *a) { \
NSColor *i = [NSColor color]; \
NSColor *c = [i colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]]; \
[c getRed:r green:g blue:b alpha:a]; \
}

#endif

COLOR_GET(windowBackgroundColor)

COLOR_GET(labelColor)

COLOR_GET(controlBackgroundColor)


4 changes: 4 additions & 0 deletions src/cocoa_helper.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import <Cocoa/Cocoa.h>

#define COCOA_COLOR_DEFINITION
#include "cocoa_helper.h"
11 changes: 11 additions & 0 deletions src/cocoa_helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* automatically generated by rust-bindgen 0.57.0 */

extern "C" {
pub fn my_windowBackgroundColor(r: *mut f64, g: *mut f64, b: *mut f64, a: *mut f64);
}
extern "C" {
pub fn my_labelColor(r: *mut f64, g: *mut f64, b: *mut f64, a: *mut f64);
}
extern "C" {
pub fn my_controlBackgroundColor(r: *mut f64, g: *mut f64, b: *mut f64, a: *mut f64);
}
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ fn main() {
*/

use fltk::{app, enums::Color};
#[cfg(target_os = "macos")]
mod cocoa_helper;
pub mod color_themes;
pub mod widget_themes;
pub mod widget_schemes;
pub mod widget_themes;

/// Color map struct. (index, r, g, b)
#[derive(Default, Clone, Debug)]
Expand Down Expand Up @@ -129,8 +131,11 @@ pub enum ThemeType {
Aero,
/// Windows 8
Metro,
/// MacOS
/// Classic MacOS
Aqua,
#[cfg(target_os = "macos")]
/// Modern MacOS using system colors, supports Dark theme
Aqua2,
/// Xfce
Greybird,
/// Windows 2000
Expand Down Expand Up @@ -160,6 +165,8 @@ impl WidgetTheme {
ThemeType::Classic => widget_themes::classic::use_classic_theme(),
ThemeType::Aero => widget_themes::aero::use_aero_theme(),
ThemeType::Aqua => widget_themes::aqua::use_aqua_theme(),
#[cfg(target_os = "macos")]
ThemeType::Aqua2 => widget_themes::aqua2::use_aqua2_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 Down
1 change: 0 additions & 1 deletion src/widget_schemes/svg_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ fn oflat_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
image.draw(x, y, w, h);
}


pub(crate) fn use_svg_based_scheme() {
use fltk::enums::FrameType::*;
app::reload_scheme().ok();
Expand Down
Loading

0 comments on commit cbfad7e

Please sign in to comment.