fltk_builder/extensions/builder/
window.rs1use fltk::{
2 draw::Region,
3 enums::Cursor,
4 image::RgbImage,
5 prelude::{ImageExt, WidgetExt, WindowExt},
6 window::RawHandle,
7};
8
9pub trait WindowBuilderExt {
11 fn as_modal(self, val: bool) -> Self;
13 fn as_fullscreen(self, val: bool) -> Self;
15 fn with_icon<T: ImageExt>(self, image: Option<T>) -> Self
18 where
19 Self: Sized;
20 fn with_cursor(self, cursor: Cursor) -> Self;
23 fn with_border(self, flag: bool) -> Self;
25 #[doc(hidden)]
26 unsafe fn with_raw_handle(self, handle: RawHandle) -> Self;
31 unsafe fn with_region(self, region: Region) -> Self;
35 fn with_size_range(self, min_w: i32, min_h: i32, max_w: i32, max_h: i32) -> Self;
38 fn with_hotspot<W: WidgetExt>(self, w: &W) -> Self
40 where
41 Self: Sized;
42 fn with_shape<I: ImageExt>(self, image: Option<I>) -> Self
48 where
49 Self: Sized;
50 fn with_cursor_image(self, image: RgbImage, hot_x: i32, hot_y: i32) -> Self;
52 fn with_default_cursor(self, cursor: Cursor) -> Self;
54 fn with_screen_num(self, n: i32) -> Self;
56 fn with_opacity(self, val: f64) -> Self;
64 fn with_xclass(self, s: &str) -> Self;
67 fn with_override(self) -> Self;
69 fn with_force_position(self, flag: bool) -> Self;
71}
72
73impl<E> WindowBuilderExt for E
74where
75 E: WindowExt,
76{
77 fn as_modal(mut self, val: bool) -> Self {
78 self.make_modal(val);
79 self
80 }
81
82 fn as_fullscreen(mut self, val: bool) -> Self {
83 self.fullscreen(val);
84 self
85 }
86
87 fn with_icon<T: ImageExt>(mut self, image: Option<T>) -> Self
88 where
89 Self: Sized,
90 {
91 self.set_icon(image);
92 self
93 }
94
95 fn with_cursor(mut self, cursor: Cursor) -> Self {
96 self.set_cursor(cursor);
97 self
98 }
99
100 fn with_border(mut self, flag: bool) -> Self {
101 self.set_border(flag);
102 self
103 }
104
105 unsafe fn with_raw_handle(mut self, handle: RawHandle) -> Self {
106 self.set_raw_handle(handle);
107 self
108 }
109
110 unsafe fn with_region(mut self, region: Region) -> Self {
111 self.set_region(region);
112 self
113 }
114
115 fn with_size_range(mut self, min_w: i32, min_h: i32, max_w: i32, max_h: i32) -> Self {
116 self.size_range(min_w, min_h, max_w, max_h);
117 self
118 }
119
120 fn with_hotspot<W: WidgetExt>(mut self, w: &W) -> Self
121 where
122 Self: Sized,
123 {
124 self.hotspot(w);
125 self
126 }
127
128 fn with_shape<I: ImageExt>(mut self, image: Option<I>) -> Self
129 where
130 Self: Sized,
131 {
132 self.set_shape(image);
133 self
134 }
135
136 fn with_cursor_image(mut self, image: RgbImage, hot_x: i32, hot_y: i32) -> Self {
137 self.set_cursor_image(image, hot_x, hot_y);
138 self
139 }
140
141 fn with_default_cursor(mut self, cursor: Cursor) -> Self {
142 self.default_cursor(cursor);
143 self
144 }
145
146 fn with_screen_num(mut self, n: i32) -> Self {
147 self.set_screen_num(n);
148 self
149 }
150
151 fn with_opacity(mut self, val: f64) -> Self {
152 self.set_opacity(val);
153 self
154 }
155
156 fn with_xclass(mut self, s: &str) -> Self {
157 self.set_xclass(s);
158 self
159 }
160
161 fn with_override(mut self) -> Self {
162 self.set_override();
163 self
164 }
165
166 fn with_force_position(mut self, flag: bool) -> Self {
167 self.force_position(flag);
168 self
169 }
170}