pub struct DoubleWindow { /* private fields */ }
Expand description
Creates a double (buffered) window widget
Implementations§
Source§impl DoubleWindow
impl DoubleWindow
Sourcepub unsafe fn find_by_handle(handle: RawHandle) -> Option<impl WindowExt>
pub unsafe fn find_by_handle(handle: RawHandle) -> Option<impl WindowExt>
Find an Fl_Window
through a raw handle. The window must have been instantiated by the app.
void *
to: (Windows: HWND
, X11: Xid
(u64
), macOS: NSWindow
)
§Safety
The data must be valid and is OS-dependent.
Sourcepub fn show_with_env_args(&mut self)
pub fn show_with_env_args(&mut self)
Use FLTK specific arguments for the application: More info here. The options are:
-bg2 color
-bg color
-di[splay] host:n.n
-dn[d]
-fg color
-g[eometry] WxH+X+Y
-i[conic]
-k[bd]
-na[me] classname
-nod[nd]
-nok[bd]
-not[ooltips]
-s[cheme] scheme
-ti[tle] windowtitle
-to[oltips]
Examples found in repository?
56fn main() {
57 let app = app::App::default();
58 let mut wind = Window::default().with_label("timeout").with_size(720, 486);
59 wind.set_center_screen();
60 let mut frame = Frame::new(-200, 150, 200, 200, "");
61 let mut pxm = Pixmap::new(PXM).unwrap();
62 pxm.scale(200, 200, true, true);
63 frame.set_image_scaled(Some(pxm));
64 wind.set_color(enums::Color::White);
65 wind.end();
66 wind.show_with_env_args();
67
68 app::add_timeout(0.016, move |handle| {
69 let frame = frame.clone();
70 move_image(frame, handle);
71 });
72 app.run().unwrap();
73}
Sourcepub fn show_with_args(&mut self, args: &[&str])
pub fn show_with_args(&mut self, args: &[&str])
Use FLTK specific arguments for the application: More info here. The options are:
-bg2 color
-bg color
-di[splay] host:n.n
-dn[d]
-fg color
-g[eometry] WxH+X+Y
-i[conic]
-k[bd]
-na[me] classname
-nod[nd]
-nok[bd]
-not[ooltips]
-s[cheme] scheme
-ti[tle] windowtitle
-to[oltips]
Examples found in repository?
89fn main() {
90 let app = app::App::default();
91 let win_w = 400;
92 let win_h = 500;
93 let border = 20;
94 let but_row = 180;
95
96 let mut operation = Ops::None;
97 let mut txt = String::from("0");
98 let mut old_val = String::from("0");
99 let mut new_val: String;
100
101 let mut wind = Window::default()
102 .with_label("FLTK Calc")
103 .with_size(win_w, win_h);
104 wind.set_center_screen();
105 wind.set_color(Color::Light3);
106
107 let mut out = Output::new(border, border, win_w - 40, 140, "");
108 out.set_text_size(36);
109 out.set_value("0");
110
111 let vpack = Pack::new(border, but_row, win_w - 40, 300, "");
112
113 let mut hpack = Pack::new(0, 0, win_w - 40, 60, "");
114 let but_ce = MyButton::new("CE");
115 let but_c = MyButton::new("C");
116 let but_back = MyButton::new("@<-");
117 let but_div = MyButton::new("/");
118 hpack.end();
119 hpack.set_type(PackType::Horizontal);
120
121 let mut hpack = Pack::new(0, 0, win_w - 40, 60, "");
122 let mut but7 = MyButton::new("7");
123 let mut but8 = MyButton::new("8");
124 let mut but9 = MyButton::new("9");
125 let but_mul = MyButton::new("x");
126 hpack.end();
127 hpack.set_type(PackType::Horizontal);
128
129 let mut hpack = Pack::new(0, 0, win_w - 40, 60, "");
130 let mut but4 = MyButton::new("4");
131 let mut but5 = MyButton::new("5");
132 let mut but6 = MyButton::new("6");
133 let but_sub = MyButton::new("-");
134 hpack.end();
135 hpack.set_type(PackType::Horizontal);
136
137 let mut hpack = Pack::new(0, 0, win_w - 40, 60, "");
138 let mut but1 = MyButton::new("1");
139 let mut but2 = MyButton::new("2");
140 let mut but3 = MyButton::new("3");
141 let but_add = MyButton::new("+");
142 hpack.end();
143 hpack.set_type(PackType::Horizontal);
144
145 let mut hpack = Pack::new(0, 0, win_w - 40, 60, "");
146 let mut but_dot = MyButton::new(".");
147 let mut but0 = MyButton::new("0");
148 let but_eq = MyButton::new("=");
149 hpack.end();
150 hpack.set_type(PackType::Horizontal);
151
152 vpack.end();
153
154 wind.make_resizable(false);
155 wind.end();
156 wind.show_with_args(&["-scheme", "gtk+", "-nokbd"]);
157
158 app::set_focus(&*but1);
159
160 let but_vec = vec![
161 &mut but1, &mut but2, &mut but3, &mut but4, &mut but5, &mut but6, &mut but7, &mut but8,
162 &mut but9, &mut but0,
163 ];
164
165 let but_op_vec = vec![
166 but_add, but_sub, but_mul, but_div, but_c, but_ce, but_back, but_eq,
167 ];
168
169 let (s, r) = app::channel::<Message>();
170
171 for but in but_vec {
172 let label = but.label().unwrap();
173 but.emit(s, Message::Number(label.parse().unwrap()));
174 }
175
176 for mut but in but_op_vec {
177 let op = match but.label().unwrap().as_str() {
178 "+" => Ops::Add,
179 "-" => Ops::Sub,
180 "x" => Ops::Mul,
181 "/" => Ops::Div,
182 "=" => Ops::Eq,
183 "CE" => Ops::CE,
184 "C" => Ops::C,
185 "@<-" => Ops::Back,
186 _ => Ops::None,
187 };
188 but.emit(s, Message::Op(op));
189 }
190
191 but_dot.emit(s, Message::Dot);
192
193 while app.wait() {
194 if let Some(val) = r.recv() {
195 match val {
196 Message::Number(num) => {
197 if out.value() == "0" {
198 txt.clear();
199 }
200 txt.push_str(&num.to_string());
201 out.set_value(txt.as_str());
202 }
203 Message::Dot => {
204 if operation == Ops::Eq {
205 txt.clear();
206 operation = Ops::None;
207 out.set_value("0.");
208 txt.push_str("0.");
209 }
210 if !txt.contains('.') {
211 txt.push('.');
212 out.set_value(txt.as_str());
213 }
214 }
215 Message::Op(op) => match op {
216 Ops::Add | Ops::Sub | Ops::Div | Ops::Mul => {
217 old_val.clear();
218 old_val.push_str(&out.value());
219 operation = op;
220 out.set_value("0");
221 }
222 Ops::Back => {
223 let val = out.value();
224 txt.pop();
225 if val.len() > 1 {
226 out.set_value(txt.as_str());
227 } else {
228 out.set_value("0");
229 }
230 }
231 Ops::CE => {
232 txt.clear();
233 old_val.clear();
234 txt.push('0');
235 out.set_value(txt.as_str());
236 }
237 Ops::C => {
238 txt.clear();
239 txt.push('0');
240 out.set_value(txt.as_str());
241 }
242 Ops::Eq => {
243 new_val = out.value();
244 let old: f64 = old_val.parse().unwrap();
245 let new: f64 = new_val.parse().unwrap();
246 let val = match operation {
247 Ops::Div => old / new,
248 Ops::Mul => old * new,
249 Ops::Add => old + new,
250 Ops::Sub => old - new,
251 _ => new,
252 };
253 operation = Ops::None;
254 txt = String::from("0");
255 out.set_value(&val.to_string());
256 }
257 _ => (),
258 },
259 }
260 }
261 }
262}
Sourcepub fn set_on_top(&mut self)
pub fn set_on_top(&mut self)
Set the window to be on top of other windows. Must only be called after the window has been shown.
Sourcepub fn un_maximize(&mut self)
pub fn un_maximize(&mut self)
Unmaximize the window
Sourcepub fn maximize_active(&self) -> bool
pub fn maximize_active(&self) -> bool
Checks whether the window is maximized
Sourcepub fn default_xclass() -> Option<String>
pub fn default_xclass() -> Option<String>
Get the default XA_WM_CLASS
property for all windows of your application
Sourcepub fn set_default_xclass(s: &str)
pub fn set_default_xclass(s: &str)
Set the default XA_WM_CLASS
property for all windows of your application.
This should be called before showing with window
Source§impl DoubleWindow
impl DoubleWindow
Source§impl DoubleWindow
impl DoubleWindow
Sourcepub fn new<'a, T: Into<Option<&'a str>>>(
x: i32,
y: i32,
w: i32,
h: i32,
title: T,
) -> Self
pub fn new<'a, T: Into<Option<&'a str>>>( x: i32, y: i32, w: i32, h: i32, title: T, ) -> Self
Creates a new window, with title as its window title if the window is decorated
Examples found in repository?
5fn main() {
6 let app = app::App::default().with_scheme(app::Scheme::Gleam);
7
8 let mut wind = Window::new(100, 100, 400, 300, "Hello from rust");
9
10 let mut frame = Frame::default().with_size(360, 260).center_of_parent();
11 frame.set_frame(FrameType::EngravedBox);
12 let mut image1 = SvgImage::load("screenshots/RustLogo.svg").unwrap();
13 image1.scale(200, 200, true, true);
14 frame.set_image(Some(image1));
15
16 wind.make_resizable(true);
17 wind.end();
18 wind.show();
19
20 app.run().unwrap();
21}
More examples
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}
3fn main() {
4 let app = app::App::default().with_scheme(app::Scheme::Gtk);
5 let mut win = window::Window::new(100, 100, 800, 600, "Charts");
6 let mut chart = misc::Chart::default().size_of_parent();
7 chart.set_type(misc::ChartType::Pie);
8 chart.set_bounds(0.0, 100.0);
9 chart.set_text_size(18);
10 chart.add(88.4, "Rust", enums::Color::from_u32(0xcc9c59));
11 chart.add(8.4, "C++", enums::Color::Red);
12 chart.add(3.2, "C", enums::Color::Black);
13 chart.set_color(enums::Color::White);
14 let mut choice = menu::Choice::new(300, 5, 200, 40, "Chart type");
15 choice.add_choice("Bar|HorzBar|Line|Fill|Spike|Pie|SpecialPie");
16 choice.set_value(5);
17 choice.set_color(enums::Color::White);
18 win.end();
19 win.show();
20
21 choice.set_callback(move |c| {
22 chart.set_type(misc::ChartType::from_i32(c.value()));
23 chart.redraw();
24 });
25
26 app.run().unwrap();
27}
3fn main() {
4 let app = app::App::default();
5 let mut window = window::Window::default().with_size(300, 300);
6 window.set_frame(FrameType::NoBox);
7 window.make_resizable(true);
8
9 let dx = 20;
10 let dy = dx; // border width of resizable() - see below
11 let tile = group::Tile::default_fill();
12
13 // create the symmetrical resize box with dx and dy pixels distance, resp.
14 // from the borders of the Fl_Tile widget before all other children
15 let r = frame::Frame::new(
16 tile.x() + dx,
17 tile.y() + dy,
18 tile.w() - 2 * dx,
19 tile.h() - 2 * dy,
20 None,
21 );
22 tile.resizable(&r);
23
24 let mut box0 = frame::Frame::new(0, 0, 150, 150, "0");
25 box0.set_frame(FrameType::DownBox);
26 box0.set_color(Color::by_index(9));
27 box0.set_label_size(36);
28 box0.set_align(Align::Clip);
29
30 let mut w1 = window::Window::new(150, 0, 150, 150, "1");
31 w1.set_frame(FrameType::NoBox);
32 let mut box1 = frame::Frame::new(0, 0, 150, 150, "1\nThis is a child window");
33 box1.set_frame(FrameType::DownBox);
34 box1.set_color(Color::by_index(19));
35 box1.set_label_size(18);
36 box1.set_align(Align::Clip | Align::Inside | Align::Wrap);
37 w1.resizable(&box1);
38 w1.end();
39
40 let mut box2a = frame::Frame::new(0, 150, 70, 150, "2a");
41 box2a.set_frame(FrameType::DownBox);
42 box2a.set_color(Color::by_index(12));
43 box2a.set_label_size(36);
44 box2a.set_align(Align::Clip);
45
46 let mut box2b = frame::Frame::new(70, 150, 80, 150, "2b");
47 box2b.set_frame(FrameType::DownBox);
48 box2b.set_color(Color::by_index(13));
49 box2b.set_label_size(36);
50 box2b.set_align(Align::Clip);
51
52 let mut box3a = frame::Frame::new(150, 150, 150, 70, "3a");
53 box3a.set_frame(FrameType::DownBox);
54 box3a.set_color(Color::by_index(12));
55 box3a.set_label_size(36);
56 box3a.set_align(Align::Clip);
57
58 let mut box3b = frame::Frame::new(150, 150 + 70, 150, 80, "3b");
59 box3b.set_frame(FrameType::DownBox);
60 box3b.set_color(Color::by_index(13));
61 box3b.set_label_size(36);
62 box3b.set_align(Align::Clip);
63
64 tile.end();
65 window.end();
66
67 w1.show();
68 window.show();
69
70 app.run().unwrap();
71}
20fn main() {
21 let app = fltk::app::App::default();
22
23 // Set panic handler for main thread (will become UI thread)
24 std::panic::set_hook(Box::new({
25 |e| {
26 eprintln!("!!!!PANIC!!!!{:#?}", e);
27 error_box(e.to_string()); // Only works from the UI thread
28 std::process::exit(2);
29 }
30 }));
31
32 let mut main_win = Window::new(
33 2285,
34 180,
35 WIN_WIDTH,
36 WIN_HEIGHT,
37 "FLTK/Terminal Rust wrapper test",
38 );
39 main_win.set_type(WindowType::Double);
40 main_win.make_resizable(true);
41
42 let mut menu_bar = MenuBar::new(0, 0, WIN_WIDTH, 30, None);
43
44 let mut term = Terminal::new(0, 30, WIN_WIDTH, WIN_HEIGHT - 30, None);
45 term.set_label("term");
46 main_win.resizable(&term);
47 term.set_label_type(LabelType::None);
48
49 let idx = menu_bar.add_choice("Test&1");
50 menu_bar.at(idx).unwrap().set_callback({
51 let mut term1 = term.clone();
52 move |c| mb_test1_cb(c, &mut term1)
53 });
54 menu_bar
55 .at(idx)
56 .unwrap()
57 .set_shortcut(unsafe { std::mem::transmute(0x80031) }); // Alt-1
58
59 let idx = menu_bar.add_choice("Test&2");
60 menu_bar.at(idx).unwrap().set_callback({
61 let mut term1 = term.clone();
62 move |c| mb_test2_cb(c, &mut term1)
63 });
64 menu_bar
65 .at(idx)
66 .unwrap()
67 .set_shortcut(unsafe { std::mem::transmute(0x80032) }); // Alt-2
68
69 let idx = menu_bar.add_choice("Test&3");
70 menu_bar.at(idx).unwrap().set_callback({
71 let mut term1 = term.clone();
72 move |c| mb_test3_cb(c, &mut term1)
73 });
74 menu_bar
75 .at(idx)
76 .unwrap()
77 .set_shortcut(unsafe { std::mem::transmute(0x80033) }); // Alt-3
78
79 let idx = menu_bar.add_choice("Test&4");
80 menu_bar.at(idx).unwrap().set_callback({
81 let mut term1 = term.clone();
82 move |c| mb_test4_cb(c, &mut term1)
83 });
84 menu_bar
85 .at(idx)
86 .unwrap()
87 .set_shortcut(unsafe { std::mem::transmute(0x80034) }); // Alt-4
88
89 let idx = menu_bar.add_choice("Test&5");
90 menu_bar.at(idx).unwrap().set_callback({
91 let mut term1 = term.clone();
92 move |c| mb_test5_cb(c, &mut term1)
93 });
94 menu_bar
95 .at(idx)
96 .unwrap()
97 .set_shortcut(unsafe { std::mem::transmute(0x80035) }); // Alt-5
98
99 menu_bar.end();
100
101 main_win.end();
102 main_win.show();
103
104 // Worker thread that drives the startup tests
105 let _worker_thread: std::thread::JoinHandle<_> = std::thread::spawn({
106 let mut term = term.clone();
107 move || {
108 println!("Startup tests\n");
109 term.append("Startup tests\n\n");
110 term.append("<tmp>\n"); // This line will be overwritten later
111
112 term.cursor_up(2, false);
113 assert_eq!(term.text(false), "Startup tests\n\n"); // Ignores lines below cursor
114 assert_eq!(
115 term.text(true),
116 "Startup tests\n\n<tmp>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
117 );
118
119 // Testing ansi() and set_ansi() methods
120 assert!(term.ansi(), "Default ANSI mode should be ON at startup");
121 term.append("ANSI mode is \x1b[4mON\x1b[0m\n");
122 term.set_ansi(false);
123 assert!(!term.ansi());
124 term.append("ANSI mode is \x1b[4mOFF\x1b[0m\n");
125 // append() method is already being used/tested. Test the u8, ascii, and utf8 variants
126 term.append_u8(b"Appending u8 array\n");
127 term.append_ascii("Appending ASCII array ↑ (up-arrow is dropped)\n");
128 term.set_ansi(true); // Restore ANSI state
129
130 // Play with the horizontal scrollbar
131 assert_eq!(term.hscrollbar_style(), ScrollbarStyle::AUTO);
132 term.set_hscrollbar_style(ScrollbarStyle::ON);
133 assert_eq!(term.hscrollbar_style(), ScrollbarStyle::ON);
134
135 // Test show_unknown() as incidental part of testing append methods
136 term.set_show_unknown(true);
137 assert!(term.show_unknown());
138 term.append_ascii(
139 "Appending ASCII array with show_unknown() ↑ (up-arrow is three unknown bytes)\n",
140 );
141 term.set_show_unknown(false);
142 assert!(!term.show_unknown());
143
144 term.append_utf8("Appending UTF8 array ↑ (up-arrow is visible)\n");
145 term.append_utf8_u8(b"Appending UTF8 array as u8 \xe2\x86\x91 (up-arrow is visible)\n");
146
147 let r = term.cursor_row();
148 assert_eq!(term.cursor_col(), 0);
149 term.append(&format!("Testing cursor row/col {r}"));
150 assert_eq!(term.cursor_col(), 24);
151 assert_eq!(term.cursor_row(), r);
152
153 // Test cursor color methods
154 assert_eq!(
155 term.cursor_bg_color(),
156 Color::XtermGreen,
157 "Default cursor bg at startup"
158 );
159 term.set_cursor_bg_color(Color::Red);
160 assert_eq!(term.cursor_bg_color(), Color::Red);
161 term.set_cursor_fg_color(Color::Blue);
162 assert_eq!(term.cursor_bg_color(), Color::Red);
163 assert_eq!(term.cursor_fg_color(), Color::Blue);
164 term.set_cursor_bg_color(Color::XtermGreen); // Restore the defaults
165 term.set_cursor_fg_color(Color::from_hex(0xff_ff_f0));
166 assert_eq!(term.cursor_bg_color(), Color::XtermGreen);
167 assert_eq!(term.cursor_fg_color(), Color::from_hex(0xff_ff_f0));
168
169 // The default display_rows() will derive from the window size
170 let dr = term.display_rows();
171 let height = term.h();
172 assert_eq!(height, term.h());
173 assert!(dr > 20, "Default display_rows at startup");
174 term.resize(term.x(), term.y(), term.w(), height * 2);
175 assert_eq!(term.h(), height * 2);
176 assert_eq!(height * 2, term.h());
177 assert!(term.display_rows() > dr);
178 term.resize(term.x(), term.y(), term.w(), height);
179
180 // The default display_columns() will derive from the window size
181 let dc = term.display_columns();
182 assert!(dc > 80, "Default display_rows at startup");
183 term.set_display_columns(200);
184 assert_eq!(term.display_columns(), 200);
185 term.append("\n 1 2 3 4 5 6 7 8 9");
186 term.append("\n123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
187 term.append("[This text should be truncated by display_columns() call below.]\n"); // We shouldn't see this on screen
188 term.set_display_columns(90);
189 assert_eq!(term.display_columns(), 90);
190 term.set_display_columns(dc); // Set back to default
191 assert_eq!(term.display_columns(), dc);
192
193 assert_eq!(term.history_rows(), 100, "Default history_rows at startup");
194 term.set_history_rows(50);
195 assert_eq!(term.history_rows(), 50);
196 term.set_history_rows(100); // Set back to default
197 assert_eq!(term.history_rows(), 100);
198
199 let hu = term.history_use();
200 term.append(&format!(
201 "history_use = {hu} (it's not clear what this means)\n"
202 ));
203 // assert_eq!(term.history_use(), hu+1);
204
205 term.append(&format!(
206 "margins = b:{} l:{} r:{} t{}\n",
207 term.margin_bottom(),
208 term.margin_left(),
209 term.margin_right(),
210 term.margin_top()
211 ));
212 assert_eq!(term.margin_bottom(), 3);
213 assert_eq!(term.margin_left(), 3);
214 assert_eq!(term.margin_right(), 3);
215 assert_eq!(term.margin_top(), 3);
216
217 term.set_margin_bottom(5);
218 term.set_margin_left(10);
219 term.set_margin_right(15);
220 term.set_margin_top(20);
221 assert_eq!(term.margin_bottom(), 5);
222 assert_eq!(term.margin_left(), 10);
223 assert_eq!(term.margin_right(), 15);
224 assert_eq!(term.margin_top(), 20);
225
226 term.append("Single character: '");
227 term.print_char('X');
228 term.append("', single UTF-8 character: '");
229 term.print_char_utf8('↑');
230 term.append("'\n");
231
232 let rr = term.redraw_rate();
233 assert_eq!(rr, 0.1, "Default redraw rate at startup");
234 term.append(&format!("Redraw rate {rr}\n"));
235 term.set_redraw_rate(1.0);
236 assert_eq!(term.redraw_rate(), 1.0);
237 term.set_redraw_rate(rr);
238 assert_eq!(term.redraw_rate(), rr);
239
240 let rs = term.redraw_style();
241 term.append(&format!("Redraw style {rs:?}\n"));
242 assert_eq!(
243 rs,
244 RedrawStyle::RateLimited,
245 "Default redraw style at startup"
246 );
247 term.set_redraw_style(RedrawStyle::NoRedraw);
248 assert_eq!(term.redraw_style(), RedrawStyle::NoRedraw);
249 term.set_redraw_style(rs);
250 assert_eq!(term.redraw_style(), rs);
251
252 // Sanity checks: enum values are implicitly assigned in the C++ code so could change unexpectedly
253 assert_eq!(
254 RedrawStyle::NoRedraw.bits(),
255 0x0000,
256 "RedrawStyle enum values have been reassigned"
257 );
258 assert_eq!(
259 RedrawStyle::RateLimited.bits(),
260 0x0001,
261 "RedrawStyle enum values have been reassigned"
262 );
263 assert_eq!(
264 RedrawStyle::PerWrite.bits(),
265 0x0002,
266 "RedrawStyle enum values have been reassigned"
267 );
268
269 let sb = term.scrollbar();
270 let hsb = term.hscrollbar();
271 // Both vertical and horizontal scrollbars are at zero
272 assert_eq!(sb.value(), 0.0);
273 assert_eq!(hsb.value(), 0.0);
274 term.set_hscrollbar_style(ScrollbarStyle::AUTO);
275
276 term.append(&format!(
277 "Scrollbar actual size {}\n",
278 term.scrollbar_actual_size()
279 ));
280 assert_eq!(term.scrollbar_actual_size(), 16);
281 term.append(&format!("Scrollbar size {}\n", term.scrollbar_size()));
282 assert_eq!(
283 term.scrollbar_size(),
284 0,
285 "Default scrollbar size at startup"
286 );
287 term.set_scrollbar_size(40);
288 assert_eq!(term.scrollbar_size(), 40);
289 assert_eq!(term.scrollbar_actual_size(), 40);
290 term.append(&format!(
291 "Scrollbar actual size {}\n",
292 term.scrollbar_actual_size()
293 ));
294 term.set_scrollbar_size(0); // Restore default
295 assert_eq!(term.scrollbar_size(), 0);
296 assert_eq!(term.scrollbar_actual_size(), 16);
297
298 let sfc = term.selection_fg_color();
299 let sbc = term.selection_bg_color();
300 assert_eq!(sfc, Color::Black);
301 assert_eq!(sbc, Color::White);
302 term.append(&format!("Selection colors: {sfc} {sbc}\n"));
303 term.set_selection_fg_color(Color::Green);
304 term.set_selection_bg_color(Color::DarkBlue);
305 assert_eq!(term.selection_fg_color(), Color::Green);
306 assert_eq!(term.selection_bg_color(), Color::DarkBlue);
307 term.set_selection_fg_color(sfc);
308 term.set_selection_bg_color(sbc);
309 assert_eq!(term.selection_fg_color(), Color::Black);
310 assert_eq!(term.selection_bg_color(), Color::White);
311
312 let tfcd = term.text_fg_color_default();
313 let tbcd = term.text_bg_color_default();
314 assert_eq!(tfcd, Color::XtermWhite);
315 assert_eq!(tbcd, Color::TransparentBg);
316 term.append(&format!("Default text colors: {sfc} {sbc}\n"));
317 term.set_text_fg_color_default(Color::Green);
318 term.set_text_bg_color_default(Color::DarkBlue);
319 assert_eq!(term.text_fg_color_default(), Color::Green);
320 assert_eq!(term.text_bg_color_default(), Color::DarkBlue);
321 term.set_text_fg_color_default(tfcd);
322 term.set_text_bg_color_default(tbcd);
323 assert_eq!(term.text_fg_color_default(), Color::XtermWhite);
324 assert_eq!(term.text_bg_color_default(), Color::TransparentBg);
325
326 let tfc = term.text_fg_color();
327 let tbc = term.text_bg_color();
328 assert_eq!(tfc, Color::XtermWhite);
329 assert_eq!(tbc, Color::TransparentBg);
330 term.append(&format!("Text colors: {sfc} {sbc}\n"));
331 term.set_text_fg_color(Color::Green);
332 term.set_text_bg_color(Color::DarkBlue);
333 assert_eq!(term.text_fg_color(), Color::Green);
334 assert_eq!(term.text_bg_color(), Color::DarkBlue);
335 term.set_text_fg_color(tfc);
336 term.set_text_bg_color(tbc);
337 assert_eq!(term.text_fg_color(), Color::XtermWhite);
338 assert_eq!(term.text_bg_color(), Color::TransparentBg);
339
340 let tf = term.text_font();
341 term.append(&format!("Text font: {tf:?}\n"));
342 assert_eq!(tf, Font::Courier);
343 term.set_text_font(Font::Screen);
344 assert_eq!(term.text_font(), Font::Screen);
345 term.set_text_font(tf);
346 assert_eq!(term.text_font(), Font::Courier);
347
348 let ts = term.text_size();
349 let r = term.h_to_row(100);
350 let c = term.w_to_col(100);
351 term.append(&format!(
352 "Text size: {ts}, h_to_row(100): {r}, w_to_col(100): {c}\n"
353 ));
354 assert_eq!(ts, 14);
355 term.set_text_size(30);
356 assert_eq!(term.text_size(), 30);
357 term.append(&format!(
358 "Text size: {}, h_to_row(100): {}, w_to_col(100): {}\n",
359 term.text_size(),
360 term.h_to_row(100),
361 term.w_to_col(100)
362 ));
363 term.set_text_size(ts);
364 assert_eq!(term.text_size(), ts);
365 term.append(&format!(
366 "Text size: {}, h_to_row(100): {}, w_to_col(100): {}\n",
367 term.text_size(),
368 term.h_to_row(100),
369 term.w_to_col(100)
370 ));
371
372 // Keyboard handler
373 term.handle({
374 move |term, e| {
375 match e {
376 fltk::enums::Event::KeyDown
377 if fltk::app::event_key() == fltk::enums::Key::Escape =>
378 {
379 // false to let FLTK handle ESC. true to hide ESC
380 false
381 }
382
383 fltk::enums::Event::KeyDown
384 if fltk::app::event_length() == 1 && fltk::app::is_event_ctrl() =>
385 {
386 // We handle control keystroke
387 let k = fltk::app::event_text().unwrap();
388 term.append_utf8(&k);
389 true
390 }
391
392 fltk::enums::Event::KeyDown
393 if fltk::app::event_length() == 1 && !fltk::app::is_event_alt() =>
394 {
395 // We handle normal printable keystroke
396 let k = fltk::app::event_text().unwrap();
397 term.take_focus().unwrap();
398 term.append(&k);
399 true
400 }
401
402 // fltk docs say that keyboard handler should always claim Focus and Unfocus events
403 // We can do this, or else ignore them (return false)
404 // fltk::enums::Event::Focus | fltk::enums::Event::Unfocus => {
405 // term.redraw();
406 // true
407 // }
408 _ => false, // Let FLTK handle everything else
409 }
410 }
411 });
412
413 let attr_save = term.text_attrib();
414 term.set_text_attrib(Attrib::Inverse | Attrib::Italic);
415 term.append("\nStartup tests complete. Keyboard is live.\n");
416 assert_eq!(term.text_attrib(), Attrib::Inverse | Attrib::Italic);
417 term.set_text_attrib(attr_save);
418 assert_eq!(term.text_attrib(), attr_save);
419 term.redraw();
420 }
421 });
422
423 app.run().unwrap();
424}
Sourcepub fn flush(&mut self)
pub fn flush(&mut self)
Forces the window to be drawn, this window is also made current and calls draw()
Sourcepub fn platform_show(&self)
pub fn platform_show(&self)
Show a window after it had been hidden. Works on Windows and X11 systems
Sourcepub fn platform_hide(&self)
pub fn platform_hide(&self)
Hide a window using the platforms hide call. Works on Windows and X11 systems
Trait Implementations§
Source§impl Clone for DoubleWindow
impl Clone for DoubleWindow
Source§fn clone(&self) -> DoubleWindow
fn clone(&self) -> DoubleWindow
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for DoubleWindow
impl Debug for DoubleWindow
Source§impl Default for DoubleWindow
impl Default for DoubleWindow
Source§impl GroupExt for DoubleWindow
impl GroupExt for DoubleWindow
Source§fn find<W: WidgetExt>(&self, widget: &W) -> i32
fn find<W: WidgetExt>(&self, widget: &W) -> i32
Source§fn insert<W: WidgetExt>(&mut self, widget: &W, index: i32)
fn insert<W: WidgetExt>(&mut self, widget: &W, index: i32)
Source§fn remove<W: WidgetExt>(&mut self, widget: &W)
fn remove<W: WidgetExt>(&mut self, widget: &W)
Source§fn remove_by_index(&mut self, idx: i32)
fn remove_by_index(&mut self, idx: i32)
Source§fn resizable<W: WidgetExt>(&self, widget: &W)
fn resizable<W: WidgetExt>(&self, widget: &W)
Source§fn make_resizable(&mut self, val: bool)
fn make_resizable(&mut self, val: bool)
Source§fn add_resizable<W: WidgetExt>(&mut self, widget: &W)
fn add_resizable<W: WidgetExt>(&mut self, widget: &W)
Source§fn set_clip_children(&mut self, flag: bool)
fn set_clip_children(&mut self, flag: bool)
Source§fn clip_children(&self) -> bool
fn clip_children(&self) -> bool
clip_children
is setSource§fn draw_child<W: WidgetExt>(&self, w: &mut W)
fn draw_child<W: WidgetExt>(&self, w: &mut W)
WidgetBase::draw
methodSource§fn update_child<W: WidgetExt>(&self, w: &mut W)
fn update_child<W: WidgetExt>(&self, w: &mut W)
WidgetBase::draw
methodSource§fn draw_outside_label<W: WidgetExt>(&self, w: &mut W)
fn draw_outside_label<W: WidgetExt>(&self, w: &mut W)
WidgetBase::draw
methodSource§fn draw_children(&mut self)
fn draw_children(&mut self)
WidgetBase::draw
methodSource§fn init_sizes(&mut self)
fn init_sizes(&mut self)
Source§impl IntoIterator for DoubleWindow
impl IntoIterator for DoubleWindow
Source§impl PartialEq for DoubleWindow
impl PartialEq for DoubleWindow
Source§impl WidgetBase for DoubleWindow
impl WidgetBase for DoubleWindow
Source§unsafe fn from_widget_ptr(ptr: *mut Fl_Widget) -> Self
unsafe fn from_widget_ptr(ptr: *mut Fl_Widget) -> Self
Source§unsafe fn from_widget<W: WidgetExt>(w: W) -> Self
unsafe fn from_widget<W: WidgetExt>(w: W) -> Self
Source§fn handle<F: FnMut(&mut Self, Event) -> bool + 'static>(&mut self, cb: F)
fn handle<F: FnMut(&mut Self, Event) -> bool + 'static>(&mut self, cb: F)
Fl_Widget::handle(int)
.
Handled or ignored events should return true, unhandled events should return false.
takes the widget as a closure argument.
The ability to handle an event might depend on handling other events, as explained hereSource§fn draw<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
fn draw<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
WidgetBase::draw
actually calls drawing functionsSource§fn resize_callback<F: FnMut(&mut Self, i32, i32, i32, i32) + 'static>(
&mut self,
cb: F,
)
fn resize_callback<F: FnMut(&mut Self, i32, i32, i32, i32) + 'static>( &mut self, cb: F, )
Source§unsafe fn assume_derived(&mut self)
unsafe fn assume_derived(&mut self)
Source§impl WidgetExt for DoubleWindow
impl WidgetExt for DoubleWindow
Source§fn set_label(&mut self, title: &str)
fn set_label(&mut self, title: &str)
@
sign.
and for the associated formatting.Source§fn unset_label(&mut self)
fn unset_label(&mut self)
Source§fn measure_label(&self) -> (i32, i32)
fn measure_label(&self) -> (i32, i32)
Source§fn as_widget_ptr(&self) -> *mut Fl_Widget
fn as_widget_ptr(&self) -> *mut Fl_Widget
Fl_Widget
, for internal useSource§fn deactivate(&mut self)
fn deactivate(&mut self)
Source§fn redraw_label(&mut self)
fn redraw_label(&mut self)
Source§fn resize(&mut self, x: i32, y: i32, width: i32, height: i32)
fn resize(&mut self, x: i32, y: i32, width: i32, height: i32)
Source§fn widget_resize(&mut self, x: i32, y: i32, width: i32, height: i32)
fn widget_resize(&mut self, x: i32, y: i32, width: i32, height: i32)
Source§fn set_tooltip(&mut self, txt: &str)
fn set_tooltip(&mut self, txt: &str)
Source§fn label_color(&self) -> Color
fn label_color(&self) -> Color
Source§fn set_label_color(&mut self, color: Color)
fn set_label_color(&mut self, color: Color)
Source§fn label_font(&self) -> Font
fn label_font(&self) -> Font
Source§fn set_label_font(&mut self, font: Font)
fn set_label_font(&mut self, font: Font)
Source§fn label_size(&self) -> i32
fn label_size(&self) -> i32
Source§fn set_label_size(&mut self, sz: i32)
fn set_label_size(&mut self, sz: i32)
Source§fn label_type(&self) -> LabelType
fn label_type(&self) -> LabelType
Source§fn set_label_type(&mut self, typ: LabelType)
fn set_label_type(&mut self, typ: LabelType)
Source§fn set_changed(&mut self)
fn set_changed(&mut self)
Source§fn clear_changed(&mut self)
fn clear_changed(&mut self)
Source§fn set_when(&mut self, trigger: When)
fn set_when(&mut self, trigger: When)
when()
Source§fn selection_color(&self) -> Color
fn selection_color(&self) -> Color
Source§fn set_selection_color(&mut self, color: Color)
fn set_selection_color(&mut self, color: Color)
Source§fn do_callback(&mut self)
fn do_callback(&mut self)
Source§fn top_window(&self) -> Option<Box<dyn WindowExt>>
fn top_window(&self) -> Option<Box<dyn WindowExt>>
Source§fn takes_events(&self) -> bool
fn takes_events(&self) -> bool
Source§fn set_visible_focus(&mut self)
fn set_visible_focus(&mut self)
Source§fn clear_visible_focus(&mut self)
fn clear_visible_focus(&mut self)
Source§fn visible_focus(&mut self, v: bool)
fn visible_focus(&mut self, v: bool)
Source§fn has_visible_focus(&self) -> bool
fn has_visible_focus(&self) -> bool
Source§fn was_deleted(&self) -> bool
fn was_deleted(&self) -> bool
Source§fn set_damage(&mut self, flag: bool)
fn set_damage(&mut self, flag: bool)
Source§fn damage_type(&self) -> Damage
fn damage_type(&self) -> Damage
Source§fn set_damage_type(&mut self, mask: Damage)
fn set_damage_type(&mut self, mask: Damage)
Source§fn set_damage_area(&mut self, mask: Damage, x: i32, y: i32, w: i32, h: i32)
fn set_damage_area(&mut self, mask: Damage, x: i32, y: i32, w: i32, h: i32)
Source§fn clear_damage(&mut self)
fn clear_damage(&mut self)
Source§fn as_window(&self) -> Option<Box<dyn WindowExt>>
fn as_window(&self) -> Option<Box<dyn WindowExt>>
Source§fn as_group(&self) -> Option<Group>
fn as_group(&self) -> Option<Group>
Source§fn inside<W: WidgetExt>(&self, wid: &W) -> bool
fn inside<W: WidgetExt>(&self, wid: &W) -> bool
Source§fn get_type<T: WidgetType>(&self) -> T
fn get_type<T: WidgetType>(&self) -> T
Source§fn set_type<T: WidgetType>(&mut self, typ: T)
fn set_type<T: WidgetType>(&mut self, typ: T)
Source§fn set_image_scaled<I: ImageExt>(&mut self, image: Option<I>)
fn set_image_scaled<I: ImageExt>(&mut self, image: Option<I>)
Source§fn set_deimage<I: ImageExt>(&mut self, image: Option<I>)
fn set_deimage<I: ImageExt>(&mut self, image: Option<I>)
Source§fn set_deimage_scaled<I: ImageExt>(&mut self, image: Option<I>)
fn set_deimage_scaled<I: ImageExt>(&mut self, image: Option<I>)
Source§fn deimage(&self) -> Option<Box<dyn ImageExt>>
fn deimage(&self) -> Option<Box<dyn ImageExt>>
Source§fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
Source§fn emit<T: 'static + Clone + Send + Sync>(&mut self, sender: Sender<T>, msg: T)
fn emit<T: 'static + Clone + Send + Sync>(&mut self, sender: Sender<T>, msg: T)
Source§unsafe fn as_widget<W: WidgetBase>(&self) -> W
unsafe fn as_widget<W: WidgetBase>(&self) -> W
WidgetExt
to some widget type Read moreSource§fn visible_r(&self) -> bool
fn visible_r(&self) -> bool
Source§fn is_same<W: WidgetExt>(&self, other: &W) -> bool
fn is_same<W: WidgetExt>(&self, other: &W) -> bool
Source§fn active_r(&self) -> bool
fn active_r(&self) -> bool
Source§fn handle_event(&mut self, event: Event) -> bool
fn handle_event(&mut self, event: Event) -> bool
Source§fn is_derived(&self) -> bool
fn is_derived(&self) -> bool
Source§fn as_base_widget(&self) -> Widgetwhere
Self: Sized,
fn as_base_widget(&self) -> Widgetwhere
Self: Sized,
WidgetExt
to a WidgetSource§impl WidgetProps for DoubleWindow
impl WidgetProps for DoubleWindow
Source§fn with_label(self, title: &str) -> Self
fn with_label(self, title: &str) -> Self
Initialize with a label
Source§fn with_align(self, align: Align) -> Self
fn with_align(self, align: Align) -> Self
Initialize with alignment
Source§fn with_type<T: WidgetType>(self, typ: T) -> Self
fn with_type<T: WidgetType>(self, typ: T) -> Self
Initialize with type
Source§fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize at bottom of another widget
Source§fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize above of another widget
Source§fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize right of another widget
Source§fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize left of another widget
Source§fn center_x<W: WidgetExt>(self, w: &W) -> Self
fn center_x<W: WidgetExt>(self, w: &W) -> Self
Initialize center of another widget on the x axis
Source§fn center_y<W: WidgetExt>(self, w: &W) -> Self
fn center_y<W: WidgetExt>(self, w: &W) -> Self
Initialize center of another widget on the y axis
Source§fn center_of_parent(self) -> Self
fn center_of_parent(self) -> Self
Initialize center of parent
Source§fn size_of_parent(self) -> Self
fn size_of_parent(self) -> Self
Initialize to the size of the parent
Source§impl WindowExt for DoubleWindow
impl WindowExt for DoubleWindow
Source§fn set_center_screen(&mut self)
fn set_center_screen(&mut self)
Source§fn make_modal(&mut self, val: bool)
fn make_modal(&mut self, val: bool)
show
Source§fn fullscreen(&mut self, val: bool)
fn fullscreen(&mut self, val: bool)
Source§fn make_current(&mut self)
fn make_current(&mut self)
Source§fn set_icon(&mut self, image: Option<RgbImage>)
fn set_icon(&mut self, image: Option<RgbImage>)
Source§fn set_cursor(&mut self, cursor: Cursor)
fn set_cursor(&mut self, cursor: Cursor)
Source§fn set_border(&mut self, flag: bool)
fn set_border(&mut self, flag: bool)
Source§fn free_position(&mut self)
fn free_position(&mut self)
Source§fn raw_handle(&self) -> RawHandle
fn raw_handle(&self) -> RawHandle
Source§unsafe fn set_region(&mut self, region: Region)
unsafe fn set_region(&mut self, region: Region)
Source§fn iconize(&mut self)
fn iconize(&mut self)
Source§fn fullscreen_active(&self) -> bool
fn fullscreen_active(&self) -> bool
Source§fn decorated_w(&self) -> i32
fn decorated_w(&self) -> i32
Source§fn decorated_h(&self) -> i32
fn decorated_h(&self) -> i32
Source§fn size_range(&mut self, min_w: i32, min_h: i32, max_w: i32, max_h: i32)
fn size_range(&mut self, min_w: i32, min_h: i32, max_w: i32, max_h: i32)
max_w
and max_h
to allow unlimited upward resize of the window.Source§fn set_shape(&mut self, image: Option<RgbImage>)
fn set_shape(&mut self, image: Option<RgbImage>)
Source§fn default_cursor(&mut self, cursor: Cursor)
fn default_cursor(&mut self, cursor: Cursor)
Source§fn screen_num(&self) -> i32
fn screen_num(&self) -> i32
Source§fn set_screen_num(&mut self, n: i32)
fn set_screen_num(&mut self, n: i32)
Source§fn wait_for_expose(&self)
fn wait_for_expose(&self)
show()
.
More info hereSource§fn set_opacity(&mut self, val: f64)
fn set_opacity(&mut self, val: f64)
Source§fn set_xclass(&mut self, s: &str)
fn set_xclass(&mut self, s: &str)
XA_WM_CLASS
property.
This should be called before showing the windowSource§fn clear_modal_states(&mut self)
fn clear_modal_states(&mut self)
Source§fn force_position(&mut self, flag: bool)
fn force_position(&mut self, flag: bool)
Source§fn set_override(&mut self)
fn set_override(&mut self)
Source§fn is_override(&self) -> bool
fn is_override(&self) -> bool
Source§fn set_icon_label(&mut self, label: &str)
fn set_icon_label(&mut self, label: &str)
Source§fn icon_label(&self) -> Option<String>
fn icon_label(&self) -> Option<String>
impl Eq for DoubleWindow
impl Send for DoubleWindow
single-threaded
only.impl Sync for DoubleWindow
single-threaded
only.