Skip to content

Commit

Permalink
update 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MoAlyousef committed Sep 28, 2021
1 parent 071b8da commit 0d502da
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fltk-theme"
version = "0.1.8"
version = "0.2.0"
authors = ["MoAlyousef <[email protected]>"]
edition = "2018"
description = "A theming crate for fltk-rs"
Expand Down
6 changes: 3 additions & 3 deletions examples/aqua_dark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ 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);
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_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();
Expand Down
34 changes: 20 additions & 14 deletions examples/fluent.rs
Original file line number Diff line number Diff line change
@@ -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
},
Expand Down
3 changes: 1 addition & 2 deletions examples/frames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions examples/widget_theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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();
Expand Down
16 changes: 13 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ pub enum ThemeType {
Dark,
/// High Contrast
HighContrast,
/// Windows 10
Fluent,
}

#[derive(Debug, Clone, Copy)]
Expand All @@ -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(),
}
}
}
Expand All @@ -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,
/**
Expand Down Expand Up @@ -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)
}
}
3 changes: 3 additions & 0 deletions src/widget_schemes/aqua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
67 changes: 47 additions & 20 deletions src/widget_themes/fluent.rs → src/widget_schemes/fluent.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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!(
"<svg width='{}' height='{}'>
<circle cx='{}' cy='{}' r='{}' stroke='black' stroke-width='1' fill='rgb({},{},{})'/>
</svg>",
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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions src/widget_schemes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 0 additions & 1 deletion src/widget_themes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0d502da

Please sign in to comment.