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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use fltk::{prelude::*, *};
/*
Event handling for win and dock_win can be changed.
In fn prep_shape(), if you want a different shape as your background e.g a pie (circle),
change draw::draw_rounded_rectf(0, 0, w, h, 16) to your desired background e.g draw::pie
x, y, w, h, r
* DO NOT CHANGE ANYTHING ELSE IN THE prep_shape() FUNCTION *
.center_screen(); -- Not a requirement
.with_size(1, 1); -- If you use .center_screen(), (x, y) MUST be >0 otherwise a panic!() will be thrown
win.set_color(Color::from_rgb(25, 26, 55)); -- Can be refactored to any color, no requirement e.g enums::Color::White
button::Button::default(); -- Not a requirement, remove if need be and import your own Widgets
*/
fn main() {
let app = app::App::default();
// Act as the application in the taskbar (scroll to event handling)
let mut dock_win = window::Window::default()
.with_size(1, 1) // So we can place it at the center of the screen (needs a size >0 to be centered)
.with_label("TestApplication")
.center_screen();
dock_win.size_range(0, 0, 0, 0);
dock_win.make_resizable(false);
dock_win.show();
dock_win.end();
let mut win = window::Window::default()
.with_size(900, 500)
.with_label("TestApplication")
.center_screen();
win.set_color(enums::Color::from_rgb(26, 25, 55));
let mut but = button::Button::default()
.with_label("Button")
.with_size(80, 80)
.center_of_parent();
but.set_frame(enums::FrameType::OFlatFrame);
but.set_color(enums::Color::Cyan);
but.clear_visible_focus();
but.set_callback(|_| println!("Clicked"));
win.show();
win.end();
let win_shape = prep_shape(win.w(), win.h());
// Called after showing window
win.set_shape(Some(win_shape));
win.handle({
let mut x = 0;
let mut y = 0;
let mut dock_win = dock_win.clone();
move |wself, event| match event {
enums::Event::Push => {
let coords = app::event_coords();
x = coords.0;
y = coords.1;
true
}
enums::Event::Drag => {
wself.set_pos(app::event_x_root() - x, app::event_y_root() - y);
// Changing dock window position so it's close enough to the center of the application (not "visible" to user)
dock_win.set_pos(wself.x() + (wself.w() / 2), wself.y() + (wself.w() / 2));
true
}
enums::Event::Close => {
app.quit();
true
}
enums::Event::Hide => {
app.quit();
true
}
_ => false,
}
});
// Make main window appear when "opened" via Alt+Tab or Taskbar
dock_win.handle({
let mut win = win.clone();
move |_wself, event| match event {
enums::Event::Focus => {
let win_shape = prep_shape(win.w(), win.h());
win.show();
win.set_shape(Some(win_shape));
true
}
enums::Event::Hide => {
win.hide();
true
}
enums::Event::Close => {
app.quit();
true
}
_ => false,
}
});
app.run().unwrap();
}
fn prep_shape(w: i32, h: i32) -> image::RgbImage {
let surf = surface::ImageSurface::new(w, h, false);
surface::ImageSurface::push_current(&surf);
draw::set_draw_color(enums::Color::Black);
draw::draw_rectf(-1, -1, w + 2, h + 2);
draw::set_draw_color(enums::Color::White);
draw::draw_rounded_rectf(0, 0, w, h, 16);
let img = surf.image().unwrap();
surface::ImageSurface::pop_current();
img
}