1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use fltk::{prelude::*, *};

struct RoundImageBox;

impl RoundImageBox {
    pub fn new(radius: i32, mut image: image::RgbImage) -> Self {
        let mut frame = frame::Frame::new(0, 0, radius * 2, radius * 2, None);
        frame.set_frame(enums::FrameType::FlatBox);
        frame.draw(move |f| {
            image.scale(f.w(), f.h(), false, true);
            image.draw(f.x(), f.y(), f.w(), f.h());
            let color = f.color().to_rgb();
            let s = format!(
                "<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n
              <svg width='{}' height='{}'>\n
                <rect x='{}' 
                    y='{}' 
                    rx='{}' 
                    ry='{}' 
                    width='{}' 
                    height='{}' 
                    fill='none' 
                    stroke='rgb({}, {}, {})' 
                    stroke-width='{}' />\n
              </svg>\n",
                f.w(),
                f.h(),
                -f.w() / 2,
                -f.w() / 2,
                f.w(),
                f.w(),
                f.w() + f.w(),
                f.h() + f.w(),
                color.0,
                color.1,
                color.2,
                f.w()
            );
            let mut s = image::SvgImage::from_data(&s).unwrap();
            s.draw(f.x(), f.y(), f.w(), f.h());
        });
        Self
    }
}

fn main() {
    let app = app::App::default().with_scheme(app::Scheme::Gleam);
    app::background(0, 0, 0);
    let image = image::SharedImage::load("screenshots/calc2.jpg")
        .unwrap()
        .to_rgb()
        .unwrap();

    let mut wind = window::Window::new(100, 100, 800, 400, "Hello from rust");
    let row = group::Flex::default()
        .row()
        .with_size(800, 200)
        .center_of_parent();
    for i in 1..=4 {
        let color_depth = enums::ColorDepth::from_u8(i).unwrap();
        let image = image.convert(color_depth).unwrap();
        RoundImageBox::new(100, image);
    }
    row.end();
    wind.end();
    wind.show();

    app.run().unwrap();
}