Skip to content

Commit

Permalink
some changes to the SvgBased scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
MoAlyousef committed Aug 4, 2021
1 parent f8771a1 commit ead9dbd
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 69 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.7"
version = "0.1.8"
authors = ["MoAlyousef <[email protected]>"]
edition = "2018"
description = "A theming crate for fltk-rs"
Expand Down
8 changes: 1 addition & 7 deletions examples/svg_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ const FRAMES: &[FrameType] = &[
RoundedFrame,
RoundedBox,
RFlatBox,
RShadowBox,
RoundUpBox,
RoundDownBox,
OvalBox,
OvalFrame,
OFlatFrame,
OShadowBox,
];

fn add_frames(frames: &[FrameType]) {
Expand All @@ -30,10 +26,8 @@ fn main() {
scheme.apply();
let mut win = window::Window::default().with_size(600, 400);
let mut vgrid = group::VGrid::new(5, 5, 590, 390, None);
vgrid.set_params(4, 3, 5);
vgrid.set_params(3, 2, 5);
add_frames(FRAMES);
frame::Frame::default();
frame::Frame::default();
vgrid.end();
win.end();
win.show();
Expand Down
1 change: 0 additions & 1 deletion examples/widget_scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ fn main() {
let a = app::App::default();
let scheme = WidgetScheme::new(SchemeType::Clean);
scheme.apply();
app::background(0xfa, 0xfa, 0xfa);
let mut win = window::Window::default().with_size(400, 300);
let mut choice = menu::Choice::new(100, 100, 200, 30, None);
choice.add_choice("Clean|Crystal|Gleam");
Expand Down
Binary file modified screenshots/svgbased.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,9 @@ pub enum SchemeType {
- RoundedFrame
- RoundedBox
- RFlatBox
- RShadowBox
- RoundUpBox
- RoundDownBox
- OvalBox
- OvalFrame
- OFlatFrame
- OShadowBox
*/
SvgBased,
}
Expand Down
68 changes: 12 additions & 56 deletions src/widget_schemes/svg_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use fltk::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!("<?xml version='1.0'?><svg width='{}' height='{}' xmlns='http://www.w3.org/2000/svg'>
<rect stroke-width='1' rx='15' width='{}' height='{}' stroke='rgb({}, {}, {})' fill='none' y='1' x='1'/>
<rect stroke-width='2' rx='15' width='{}' height='{}' stroke='rgb({}, {}, {})' fill='none' y='1' x='1'/>
</svg>",w, h, w - 2, h - 2, r, g, b);
let mut image = fltk::image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
Expand All @@ -13,7 +13,7 @@ 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!("<?xml version='1.0'?><svg width='{}' height='{}' xmlns='http://www.w3.org/2000/svg'>
<rect stroke-width='1' stroke='black' rx='15' width='{}' height='{}' fill='rgb({}, {}, {})' y='1' x='1'/>
<rect stroke-width='2' stroke='rgb(200, 200, 200)' rx='15' width='{}' height='{}' fill='rgb({}, {}, {})' y='1' x='1'/>
</svg>",w, h, w - 2, h - 2, r, g, b);
let mut image = fltk::image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
Expand All @@ -22,46 +22,16 @@ fn rounded_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
fn rflat_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let (r, g, b) = c.to_rgb();
let svg = format!("<?xml version='1.0'?><svg width='{}' height='{}' xmlns='http://www.w3.org/2000/svg'>
<rect stroke-width='1' stroke='none' rx='15' width='{}' height='{}' fill='rgb({}, {}, {})' y='1' x='1'/>
<rect stroke-width='2' stroke='none' rx='15' width='{}' height='{}' fill='rgb({}, {}, {})' y='1' x='1'/>
</svg>",w, h, w - 2, h - 2, r, g, b);
let mut image = fltk::image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
}

fn rshadow_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let (r, g, b) = c.to_rgb();
let svg = format!("<?xml version='1.0'?><svg width='{}' height='{}' xmlns='http://www.w3.org/2000/svg'>
<rect stroke-width='1' stroke='black' rx='15' width='{}' height='{}' fill='black' y='2' x='2'/>
<rect stroke-width='1' stroke='black' rx='15' width='{}' height='{}' fill='rgb({}, {}, {})' y='1' x='1'/>
</svg>",w, h, w - 2 , h - 2 , w - 2, h -2, r, g, b);
let mut image = fltk::image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
}

fn round_up_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let (r, g, b) = c.to_rgb();
let svg = format!("<?xml version='1.0'?><svg width='{}' height='{}' xmlns='http://www.w3.org/2000/svg'>
<rect stroke-width='1' stroke='black' rx='35' width='{}' height='{}' fill='black' y='2' x='2'/>
<rect stroke-width='1' stroke='black' rx='35' width='{}' height='{}' fill='rgb({}, {}, {})' y='1' x='1'/>
</svg>",w, h, w - 2 , h - 2 , w - 2, h -2, r, g, b);
let mut image = fltk::image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
}

fn round_down_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let (r, g, b) = c.to_rgb();
let svg = format!("<?xml version='1.0'?><svg width='{}' height='{}' xmlns='http://www.w3.org/2000/svg'>
<rect stroke-width='1' stroke='black' rx='35' width='{}' height='{}' fill='black' y='1' x='1'/>
<rect stroke-width='1' stroke='black' rx='35' width='{}' height='{}' fill='rgb({}, {}, {})' y='2' x='2'/>
</svg>",w, h, w -2, h - 2 , w - 2, h -2, r, g, b);
let mut image = fltk::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!("<?xml version='1.0'?><svg width='{}' height='{}' xmlns='http://www.w3.org/2000/svg'>
<rect stroke-width='1' stroke='black' rx='90' width='{}' height='{}' fill='rgb({}, {}, {})' y='1' x='1'/>
<rect stroke-width='2' stroke='rgb(200, 200, 200)' rx='90' width='{}' height='{}' fill='rgb({}, {}, {})' y='1' x='1'/>
</svg>",w, h, w - 2, h - 2, r, g, b);
let mut image = fltk::image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
Expand All @@ -70,7 +40,7 @@ fn oval_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
fn oval_frame(x: i32, y: i32, w: i32, h: i32, c: Color) {
let (r, g, b) = c.to_rgb();
let svg = format!("<?xml version='1.0'?><svg width='{}' height='{}' xmlns='http://www.w3.org/2000/svg'>
<rect stroke-width='1' rx='90' width='{}' height='{}' stroke='rgb({}, {}, {})' fill='none' y='1' x='1'/>
<rect stroke-width='2' rx='90' width='{}' height='{}' stroke='rgb({}, {}, {})' fill='none' y='1' x='1'/>
</svg>",w, h, w - 2, h - 2, r, g, b);
let mut image = fltk::image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
Expand All @@ -79,35 +49,21 @@ 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!("<?xml version='1.0'?><svg width='{}' height='{}' xmlns='http://www.w3.org/2000/svg'>
<rect stroke-width='1' stroke='none' rx='90' width='{}' height='{}' fill='rgb({}, {}, {})' y='1' x='1'/>
<rect stroke-width='2' stroke='none' rx='90' width='{}' height='{}' fill='rgb({}, {}, {})' y='1' x='1'/>
</svg>",w, h, w - 2, h - 2, r, g, b);
let mut image = fltk::image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
}

fn oshadow_box(x: i32, y: i32, w: i32, h: i32, c: Color) {
let (r, g, b) = c.to_rgb();
let svg = format!("<?xml version='1.0'?><svg width='{}' height='{}' xmlns='http://www.w3.org/2000/svg'>
<rect stroke-width='1' stroke='black' rx='90' width='{}' height='{}' fill='black' y='2' x='2'/>
<rect stroke-width='1' stroke='black' rx='90' width='{}' height='{}' fill='rgb({}, {}, {})' y='1' x='1'/>
</svg>",w, h, w - 2 , h - 2 , w - 2, h -2, r, g, b);
let mut image = fltk::image::SvgImage::from_data(&svg).unwrap();
image.draw(x, y, w, h);
}


pub(crate) fn use_svg_based_scheme() {
use fltk::enums::FrameType::*;
app::reload_scheme().ok();
app::set_scheme(app::Scheme::Base);
app::set_frame_type_cb(RoundedFrame, rounded_frame, 1, 1, 2, 2);
app::set_frame_type_cb(RoundedBox, rounded_box, 1, 1, 2, 2);
app::set_frame_type_cb(RFlatBox, rflat_box, 1, 1, 2, 2);
app::set_frame_type_cb(RShadowBox, rshadow_box, 1, 1, 2, 2);
app::set_frame_type_cb(RoundUpBox, round_up_box, 1, 1, 2, 2);
app::set_frame_type_cb(RoundDownBox, round_down_box, 1, 1, 2, 2);
app::set_frame_type_cb(OvalBox, oval_box, 1, 1, 2, 2);
app::set_frame_type_cb(OvalFrame, oval_frame, 1, 1, 2, 2);
app::set_frame_type_cb(OFlatFrame, oflat_box, 1, 1, 2, 2);
app::set_frame_type_cb(OShadowBox, oshadow_box, 1, 1, 2, 2);
app::set_frame_type_cb(RoundedFrame, rounded_frame, 0, 0, 0, 0);
app::set_frame_type_cb(RoundedBox, rounded_box, 0, 0, 0, 0);
app::set_frame_type_cb(RFlatBox, rflat_box, 0, 0, 0, 0);
app::set_frame_type_cb(OvalBox, oval_box, 0, 0, 0, 0);
app::set_frame_type_cb(OvalFrame, oval_frame, 0, 0, 0, 0);
app::set_frame_type_cb(OFlatFrame, oflat_box, 0, 0, 0, 0);
}

0 comments on commit ead9dbd

Please sign in to comment.