shapedwindow_taskbar/
shapedwindow_taskbar.rs1use fltk::{prelude::*, *};
2
3fn main() {
18 let app = app::App::default();
19
20 let mut dock_win = window::Window::default()
22 .with_size(1, 1) .with_label("TestApplication");
24 dock_win.set_center_screen();
25 dock_win.size_range(0, 0, 0, 0);
26 dock_win.make_resizable(false);
27
28 dock_win.show();
29 dock_win.end();
30
31 let mut win = window::Window::default()
32 .with_size(900, 500)
33 .with_label("TestApplication");
34 win.set_center_screen();
35 win.set_color(enums::Color::from_rgb(26, 25, 55));
36
37 let mut but = button::Button::default()
38 .with_label("Button")
39 .with_size(80, 80)
40 .center_of_parent();
41 but.set_frame(enums::FrameType::OFlatBox);
42 but.set_color(enums::Color::Cyan);
43 but.clear_visible_focus();
44 but.set_callback(|_| println!("Clicked"));
45
46 win.show();
47 win.end();
48
49 let win_shape = prep_shape(win.w(), win.h());
50
51 win.set_shape(Some(win_shape));
53
54 win.handle({
55 let mut x = 0;
56 let mut y = 0;
57 let mut dock_win = dock_win.clone();
58 move |wself, event| match event {
59 enums::Event::Push => {
60 let coords = app::event_coords();
61 x = coords.0;
62 y = coords.1;
63
64 true
65 }
66 enums::Event::Drag => {
67 wself.resize(
68 app::event_x_root() - x,
69 app::event_y_root() - y,
70 wself.w(),
71 wself.h(),
72 );
73
74 dock_win.resize(
76 wself.x() + (wself.w() / 2),
77 wself.y() + (wself.w() / 2),
78 dock_win.w(),
79 dock_win.h(),
80 );
81
82 true
83 }
84 enums::Event::Close => {
85 app.quit();
86
87 true
88 }
89 enums::Event::Hide => {
90 app.quit();
91
92 true
93 }
94 _ => false,
95 }
96 });
97
98 dock_win.handle({
100 let mut win = win.clone();
101 move |_wself, event| match event {
102 enums::Event::Focus => {
103 let win_shape = prep_shape(win.w(), win.h());
104
105 win.show();
106 win.set_shape(Some(win_shape));
107
108 true
109 }
110 enums::Event::Hide => {
111 win.hide();
112
113 true
114 }
115 enums::Event::Close => {
116 app.quit();
117
118 true
119 }
120 _ => false,
121 }
122 });
123
124 app.run().unwrap();
125}
126
127fn prep_shape(w: i32, h: i32) -> image::RgbImage {
128 let surf = surface::ImageSurface::new(w, h, false);
129
130 surface::ImageSurface::push_current(&surf);
131
132 draw::set_draw_color(enums::Color::Black);
133 draw::draw_rectf(-1, -1, w + 2, h + 2);
134
135 draw::set_draw_color(enums::Color::White);
136 draw::draw_rounded_rectf(0, 0, w, h, 16);
137
138 let img = surf.image().unwrap();
139
140 surface::ImageSurface::pop_current();
141
142 img
143}