rounded_images/
rounded_images.rs1use fltk::{prelude::*, *};
2
3struct RoundImageBox;
4
5impl RoundImageBox {
6 pub fn new(radius: i32, mut image: image::RgbImage) -> Self {
7 let mut frame = frame::Frame::new(0, 0, radius * 2, radius * 2, None);
8 frame.set_frame(enums::FrameType::FlatBox);
9 frame.draw(move |f| {
10 image.scale(f.w(), f.h(), false, true);
11 image.draw(f.x(), f.y(), f.w(), f.h());
12 let color = f.color().to_rgb();
13 let s = format!(
14 "<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n
15 <svg width='{}' height='{}'>\n
16 <rect x='{}'
17 y='{}'
18 rx='{}'
19 ry='{}'
20 width='{}'
21 height='{}'
22 fill='none'
23 stroke='rgb({}, {}, {})'
24 stroke-width='{}' />\n
25 </svg>\n",
26 f.w(),
27 f.h(),
28 -f.w() / 2,
29 -f.w() / 2,
30 f.w(),
31 f.w(),
32 f.w() + f.w(),
33 f.h() + f.w(),
34 color.0,
35 color.1,
36 color.2,
37 f.w()
38 );
39 let mut s = image::SvgImage::from_data(&s).unwrap();
40 s.draw(f.x(), f.y(), f.w(), f.h());
41 });
42 Self
43 }
44}
45
46fn main() {
47 let app = app::App::default().with_scheme(app::Scheme::Gleam);
48 app::background(0, 0, 0);
49 let image = image::SharedImage::load("screenshots/calc2.jpg")
50 .unwrap()
51 .as_rgb_image()
52 .unwrap();
53
54 let mut wind = window::Window::new(100, 100, 800, 400, "Hello from rust");
55 let row = group::Flex::default()
56 .row()
57 .with_size(800, 200)
58 .center_of_parent();
59 for i in 1..=4 {
60 let color_depth = enums::ColorDepth::from_u8(i).unwrap();
61 let image = image.convert(color_depth).unwrap();
62 RoundImageBox::new(100, image);
63 }
64 row.end();
65 wind.end();
66 wind.show();
67
68 app.run().unwrap();
69}