Skip to content

Commit

Permalink
use draw_rbox
Browse files Browse the repository at this point in the history
  • Loading branch information
MoAlyousef committed Oct 6, 2022
1 parent 7a2e53c commit e168812
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 146 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fltk-theme"
version = "0.5.0"
version = "0.6.0"
authors = ["MoAlyousef <[email protected]>"]
edition = "2018"
description = "A theming crate for fltk-rs"
Expand All @@ -13,7 +13,8 @@ license = "MIT"
exclude = ["/screenshots", "./examples"]

[dependencies]
fltk = "1.3.6"
# fltk = "1.3.6"
fltk = { git = "https://github.com/fltk-rs/fltk-rs" }
lazy_static = "1.4"

[target.'cfg(target_os = "macos")'.dependencies]
Expand Down
12 changes: 2 additions & 10 deletions examples/aqua_dark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,9 @@ use fltk_theme::colors::aqua::dark::*; // get all the dark aqua colors
fn main() {
let a = app::App::default();
let bg = windowBackgroundColor.to_rgb();
app::background(
bg.0,
bg.1,
bg.2,
);
app::background(bg.0, bg.1, bg.2);
let ctrl = controlAccentColor.to_rgb();
app::background2(
ctrl.0,
ctrl.1,
ctrl.2,
);
app::background2(ctrl.0, ctrl.1, ctrl.2);
let lbl = labelColor.to_rgb();
app::foreground(lbl.0, lbl.1, lbl.2);
app::set_color(Color::Selection, 255, 255, 255);
Expand Down
14 changes: 1 addition & 13 deletions examples/fluent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,11 @@ fn main() {
);
let theme = WidgetScheme::new(SchemeType::Fluent);
theme.apply();
let mut win = window::Window::default().with_size(400, 300);
let mut win = window::SingleWindow::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(FrameType::FlatBox);
choice.draw(|c| {
draw::set_draw_color(Color::Background);
draw::draw_polygon(
c.x() + c.w() - 18,
(c.y() + c.h() / 2) - 6,
c.x() + c.w() - 13,
(c.y() + c.h() / 2) - 1,
c.x() + c.w() - 7,
(c.y() + c.h() / 2) - 6,
);
draw::end_polygon();
});
let mut check = button::CheckButton::new(160, 150, 80, 30, " Check");
check.set_value(true);
check.set_frame(FrameType::FlatBox);
Expand Down
2 changes: 1 addition & 1 deletion examples/html_colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use fltk_theme::colors::html::*;
macro_rules! col {
($e: expr) => {
Color::from_rgb($e.0, $e.1, $e.2)
}
};
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/colors/aqua/dark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ lazy_static::lazy_static! {
pub static ref systemTealColor: Color = Color::from_rgba_tuple((76, 187, 242, 255));
pub static ref systemYellowColor: Color = Color::from_rgba_tuple((254, 207, 14, 255));
pub static ref systemBlueColor: Color = Color::from_rgba_tuple((16, 106, 254, 255));
pub static ref systemCyanColor: Color = Color::from_rgba_tuple((90, 200, 245, 255));
pub static ref systemCyanColor: Color = Color::from_rgba_tuple((90, 200, 245, 255));
}
1 change: 0 additions & 1 deletion src/colors/aqua/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ lazy_static::lazy_static! {
pub static ref systemBlueColor: Color = Color::from_rgba_tuple((10, 95, 254, 255));
pub static ref systemCyanColor: Color = Color::from_rgba_tuple((85, 190, 240, 255));
}

2 changes: 1 addition & 1 deletion src/colors/aqua/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pub mod sys;
// const fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> Color {
// let val = ((r as u32 & 0xff) << 24) + ((g as u32 & 0xff) << 16) + ((b as u32 & 0xff) << 8) + (a as u32 & 0xff);
// Color::from_rgbi(val)
// }
// }
1 change: 0 additions & 1 deletion src/colors/aqua/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,3 @@ lazy_static::lazy_static! {
pub static ref systemBlueColor: (u8, u8, u8, u8) = get_colors!(get_systemBlueColor);
// pub static ref systemCyanColor: (u8, u8, u8, u8) = get_colors!(get_systemCyanColor); // beta
}

2 changes: 1 addition & 1 deletion src/colors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod aqua;
pub mod html;
pub mod html;
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ fn main() {

use fltk::{app, enums::Color};
pub mod color_themes;
pub mod colors;
pub mod widget_schemes;
pub mod widget_themes;
pub mod colors;

/// Color map struct. (index, r, g, b)
#[derive(Default, Clone, Debug)]
Expand Down
104 changes: 16 additions & 88 deletions src/widget_schemes/aqua.rs
Original file line number Diff line number Diff line change
@@ -1,111 +1,39 @@
use fltk::{
app, draw,
enums::{Color, FrameType},
image,
prelude::ImageExt,
};

fn up_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let col1 = c.to_rgb();
let col = Color::color_average(c, Color::Background, 0.8).to_rgb();
let svg = format!(
"<svg viewBox='0 0 {0} {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='98%' height='98%' rx='5' fill='url(#grad1)' />
</svg>",
w,
h,
col.0,
col.1,
col.2,
col1.0,
col1.1,
col1.2,
);
let mut image = image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
draw::draw_rbox(x, y, w, h, 5, true, Color::from_rgb(col.0, col.1, col.2));
}

fn default_button_up_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let col1 = c.to_rgb();
let col = Color::color_average(c, Color::Background, 0.8).to_rgb();
let svg = format!(
"<svg viewBox='0 0 {0} {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>s
</defs>
<rect width='98%' height='98%' rx='5' fill='url(#grad1)' />
</svg>",
w,
h,
col.0,
col.1,
col.2,
col1.0,
col1.1,
col1.2,
);
let mut image = image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
let col1 = c.to_rgb();
let col = Color::color_average(c, Color::Background, 0.8).to_rgb();
draw::draw_rbox(x, y, w, h, 5, true, Color::from_rgb(col.0, col.1, col.2));
}

fn down_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let col1 = c.to_rgb();
let col = Color::color_average(c, Color::Background, 0.8).to_rgb();
let svg = format!(
"<svg viewBox='0 0 {0} {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='98%' height='98%' rx='5' fill='url(#grad1)' />
</svg>",
w,
h,
col.0,
col.1,
col.2,
col1.0,
col1.1,
col1.2,
);
let mut image = image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
let col1 = c.to_rgb();
let col = Color::color_average(c, Color::Background, 0.8).to_rgb();
draw::draw_rbox(x, y, w, h, 5, true, Color::from_rgb(col.0, col.1, col.2));
}

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

fn border_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
draw::draw_box(
FrameType::RFlatBox,
x + 1,
y + 1,
w - 2,
h - 2,
draw::draw_rbox(
x,
y,
w,
h,
5,
true,
*crate::colors::aqua::dark::systemBlueColor,
);
}
Expand All @@ -117,7 +45,7 @@ fn use_scheme() {
app::set_frame_type_cb(FrameType::DiamondUpBox, default_button_up_box, 2, 2, 4, 4);
app::set_frame_type_cb(FrameType::DownBox, down_box, 2, 2, 4, 4);
app::set_frame_type_cb(FrameType::DiamondDownBox, down_box, 2, 2, 4, 4);
app::set_frame_type_cb(FrameType::RoundDownBox, radio_round_down_box, 2, 2,4, 4);
app::set_frame_type_cb(FrameType::RoundDownBox, radio_round_down_box, 2, 2, 4, 4);
app::set_frame_type_cb(FrameType::BorderBox, border_box, 2, 2, 4, 4);
}

Expand Down
21 changes: 4 additions & 17 deletions src/widget_schemes/fluent.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use fltk::{image, prelude::ImageExt};
use fltk::{draw, enums::FrameType};

fn rect(x: i32, y: i32, w: i32, h: i32, c: Color) {
draw_rect_fill(x, y, w, h, c);
Expand Down Expand Up @@ -50,22 +50,9 @@ 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) {
let col = Color::Background.to_rgb();
let fg = Color::contrast(Color::Background, Color::Background).to_rgb();
let svg = format!(
"<svg viewBox='0 0 {} {}'>
<circle cx='50%' cy='48%' r='46%' stroke='rgb({},{},{})' stroke-width='0.5' fill='rgb({},{},{})'/>
</svg>",
w,
h,
fg.0,
fg.1,
fg.2,
col.0,
col.1,
col.2
);
let mut image = image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
let fg = Color::contrast(Color::Background, Color::Background);
draw::draw_box(FrameType::OFlatFrame, x, y, w, h, Color::Background);
draw::draw_box(FrameType::OvalFrame, x, y, w, h, fg);
}

fn hover_up_frame(x: i32, y: i32, w: i32, h: i32, c: Color) {
Expand Down
30 changes: 21 additions & 9 deletions src/widget_schemes/svg_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use fltk::{image, prelude::ImageExt};

fn rounded_frame(x: i32, y: i32, w: i32, h: i32, c: Color) {
let (r, g, b) = c.to_rgb();
let svg = format!("<svg viewBox='0 0 {} {}'>
let svg = format!("<svg viewBox='0 0 {} {}'>
<rect x='1%' y='1%' stroke-width='2' rx='10%' width='96%' height='96%' stroke='rgb({}, {}, {})' fill='none' />
</svg>",w, h, r, g, b);
let mut image = image::SvgImage::from_data(&svg).unwrap();
Expand All @@ -12,27 +12,36 @@ fn rounded_frame(x: i32, y: i32, w: i32, h: i32, c: Color) {

fn rounded_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let (r, g, b) = c.to_rgb();
let svg = format!("<svg viewBox='0 0 {} {}'>
let svg = format!(
"<svg viewBox='0 0 {} {}'>
<rect x='1%' y='1%' rx='10%' width='96%' height='96%' fill='rgb({}, {}, {})' />
</svg>",w, h, r, g, b);
</svg>",
w, h, r, g, b
);
let mut image = image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
}

fn rflat_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let (r, g, b) = c.to_rgb();
let svg = format!("<svg viewBox='0 0 {} {}'>
let svg = format!(
"<svg viewBox='0 0 {} {}'>
<rect x='1%' y='1%' rx='10%' width='96%' height='96%' fill='rgb({}, {}, {})' />
</svg>",w, h, r, g, b);
</svg>",
w, h, r, g, b
);
let mut image = image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
}

fn oval_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let (r, g, b) = c.to_rgb();
let svg = format!("<svg viewBox='0 0 {} {}'>
let svg = format!(
"<svg viewBox='0 0 {} {}'>
<rect x='1%' y='1%' rx='100%' width='96%' height='96%' fill='rgb({}, {}, {})' />
</svg>",w, h, r, g, b);
</svg>",
w, h, r, g, b
);
let mut image = image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
}
Expand All @@ -48,9 +57,12 @@ fn oval_frame(x: i32, y: i32, w: i32, h: i32, c: Color) {

fn oflat_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let (r, g, b) = c.to_rgb();
let svg = format!("<svg viewBox='0 0 {} {}'>
let svg = format!(
"<svg viewBox='0 0 {} {}'>
<rect x='1%' y='1%' rx='100%' width='96%' height='96%' fill='rgb({}, {}, {})' />
</svg>",w, h, r, g, b);
</svg>",
w, h, r, g, b
);
let mut image = image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
}
Expand Down

0 comments on commit e168812

Please sign in to comment.