pub struct App {}
Expand description
Basic Application struct, used to instantiate, set the scheme and run the event loop
Implementations
sourceimpl App
impl App
sourcepub fn default() -> App
pub fn default() -> App
Instantiates an App type
Examples found in repository?
More examples
examples/paint.rs (line 89)
88 89 90 91 92 93 94 95 96 97 98 99 100 101
fn main() {
let app = app::App::default().with_scheme(app::Scheme::Gtk);
let mut wind = Window::default()
.with_size(WIDTH, HEIGHT)
.with_label("RustyPainter");
Canvas::new(WIDTH - 10, HEIGHT - 10);
wind.end();
wind.show();
app.run().unwrap();
}
examples/terminal.rs (line 213)
212 213 214 215 216 217 218 219 220 221 222 223 224 225
fn main() {
let app = app::App::default().with_scheme(app::Scheme::Plastic);
let mut wind = Window::default()
.with_size(WIDTH, HEIGHT)
.with_label("ColorTerminal");
let _term = Term::new();
wind.make_resizable(true);
wind.end();
wind.show();
app.run().unwrap();
}
examples/tabs.rs (line 42)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
fn main() {
let app = app::App::default().with_scheme(app::Scheme::Gtk);
app::background(221, 221, 221);
let mut wind = Window::default()
.with_size(500, 450)
.with_label("Tabs")
.center_screen();
draw_gallery();
wind.make_resizable(true);
wind.end();
wind.show();
app.run().unwrap();
}
examples/hello_button.rs (line 4)
3 4 5 6 7 8 9 10 11 12 13 14
fn main() {
let app = app::App::default();
let mut wind = Window::default().with_size(400, 300);
let mut frame = Frame::default().with_size(200, 100).center_of(&wind);
let mut but = Button::new(160, 210, 80, 40, "Click me!");
wind.end();
wind.show();
but.set_callback(move |_| frame.set_label("Hello world"));
app.run().unwrap();
}
examples/flex.rs (line 4)
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() {
let a = app::App::default().with_scheme(app::Scheme::Gtk);
let mut win = window::Window::default().with_size(640, 480);
let mut col = group::Flex::default_fill().column();
main_panel(&mut col);
col.end();
win.resizable(&col);
win.set_color(enums::Color::from_rgb(250, 250, 250));
win.end();
win.show();
win.size_range(600, 400, 0, 0);
a.run().unwrap();
}
Additional examples can be found in:
- examples/wizard.rs
- examples/custom_choice.rs
- examples/custom_dial.rs
- examples/hello.rs
- examples/image.rs
- examples/messages.rs
- examples/animations.rs
- examples/composite_widgets.rs
- examples/widget_table.rs
- examples/menubutton.rs
- examples/rounded_images.rs
- examples/widget_id.rs
- examples/system_fonts.rs
- examples/rgb.rs
- examples/gradients.rs
- examples/custom_popup.rs
- examples/fb.rs
- examples/charts.rs
- examples/counter2.rs
- examples/counter4.rs
- examples/spreadsheet.rs
- examples/defaults.rs
- examples/temp_converter2.rs
- examples/table.rs
- examples/tree.rs
- examples/frames.rs
- examples/closable_tab.rs
- examples/temp_converter.rs
- examples/counter3.rs
- examples/counter.rs
- examples/popup_browser.rs
- examples/custom_widgets.rs
- examples/threads_windows.rs
- examples/pong.rs
- examples/editor.rs
- examples/calculator.rs
- examples/calculator2.rs
- examples/format_text.rs
sourcepub fn set_scheme(&mut self, scheme: Scheme)
pub fn set_scheme(&mut self, scheme: Scheme)
Sets the scheme of the application
sourcepub fn with_scheme(self, scheme: Scheme) -> App
pub fn with_scheme(self, scheme: Scheme) -> App
Sets the scheme of the application
Examples found in repository?
examples/paint.rs (line 89)
88 89 90 91 92 93 94 95 96 97 98 99 100 101
fn main() {
let app = app::App::default().with_scheme(app::Scheme::Gtk);
let mut wind = Window::default()
.with_size(WIDTH, HEIGHT)
.with_label("RustyPainter");
Canvas::new(WIDTH - 10, HEIGHT - 10);
wind.end();
wind.show();
app.run().unwrap();
}
More examples
examples/terminal.rs (line 213)
212 213 214 215 216 217 218 219 220 221 222 223 224 225
fn main() {
let app = app::App::default().with_scheme(app::Scheme::Plastic);
let mut wind = Window::default()
.with_size(WIDTH, HEIGHT)
.with_label("ColorTerminal");
let _term = Term::new();
wind.make_resizable(true);
wind.end();
wind.show();
app.run().unwrap();
}
examples/tabs.rs (line 42)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
fn main() {
let app = app::App::default().with_scheme(app::Scheme::Gtk);
app::background(221, 221, 221);
let mut wind = Window::default()
.with_size(500, 450)
.with_label("Tabs")
.center_screen();
draw_gallery();
wind.make_resizable(true);
wind.end();
wind.show();
app.run().unwrap();
}
examples/flex.rs (line 4)
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() {
let a = app::App::default().with_scheme(app::Scheme::Gtk);
let mut win = window::Window::default().with_size(640, 480);
let mut col = group::Flex::default_fill().column();
main_panel(&mut col);
col.end();
win.resizable(&col);
win.set_color(enums::Color::from_rgb(250, 250, 250));
win.end();
win.show();
win.size_range(600, 400, 0, 0);
a.run().unwrap();
}
examples/wizard.rs (line 56)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
fn main() {
let app = app::App::default().with_scheme(app::Scheme::Gtk);
let mut win = window::Window::default().with_size(400, 300);
let _but = {
let mut b = button::Button::default()
.with_size(160, 40)
.with_label("Show wizard")
.center_of(&win);
b.set_callback(show_wizard);
b
};
win.end();
win.show();
app.run().unwrap();
}
examples/hello.rs (line 4)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
fn main() {
let app = app::App::default().with_scheme(app::Scheme::Gleam);
let mut wind = Window::new(100, 100, 400, 300, "Hello from rust");
let mut frame = Frame::default().with_size(360, 260).center_of(&wind);
frame.set_frame(FrameType::EngravedBox);
let mut image = SvgImage::load("screenshots/RustLogo.svg").unwrap();
image.scale(200, 200, true, true);
frame.set_image(Some(image));
wind.make_resizable(true);
wind.end();
wind.show();
app.run().unwrap();
}
Additional examples can be found in:
sourcepub fn run(self) -> Result<(), FltkError>
pub fn run(self) -> Result<(), FltkError>
Examples found in repository?
More examples
examples/paint.rs (line 100)
88 89 90 91 92 93 94 95 96 97 98 99 100 101
fn main() {
let app = app::App::default().with_scheme(app::Scheme::Gtk);
let mut wind = Window::default()
.with_size(WIDTH, HEIGHT)
.with_label("RustyPainter");
Canvas::new(WIDTH - 10, HEIGHT - 10);
wind.end();
wind.show();
app.run().unwrap();
}
examples/terminal.rs (line 224)
212 213 214 215 216 217 218 219 220 221 222 223 224 225
fn main() {
let app = app::App::default().with_scheme(app::Scheme::Plastic);
let mut wind = Window::default()
.with_size(WIDTH, HEIGHT)
.with_label("ColorTerminal");
let _term = Term::new();
wind.make_resizable(true);
wind.end();
wind.show();
app.run().unwrap();
}
examples/tabs.rs (line 56)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
fn main() {
let app = app::App::default().with_scheme(app::Scheme::Gtk);
app::background(221, 221, 221);
let mut wind = Window::default()
.with_size(500, 450)
.with_label("Tabs")
.center_screen();
draw_gallery();
wind.make_resizable(true);
wind.end();
wind.show();
app.run().unwrap();
}
examples/hello_button.rs (line 13)
3 4 5 6 7 8 9 10 11 12 13 14
fn main() {
let app = app::App::default();
let mut wind = Window::default().with_size(400, 300);
let mut frame = Frame::default().with_size(200, 100).center_of(&wind);
let mut but = Button::new(160, 210, 80, 40, "Click me!");
wind.end();
wind.show();
but.set_callback(move |_| frame.set_label("Hello world"));
app.run().unwrap();
}
examples/flex.rs (line 14)
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() {
let a = app::App::default().with_scheme(app::Scheme::Gtk);
let mut win = window::Window::default().with_size(640, 480);
let mut col = group::Flex::default_fill().column();
main_panel(&mut col);
col.end();
win.resizable(&col);
win.set_color(enums::Color::from_rgb(250, 250, 250));
win.end();
win.show();
win.size_range(600, 400, 0, 0);
a.run().unwrap();
}
Additional examples can be found in:
- examples/wizard.rs
- examples/custom_choice.rs
- examples/custom_dial.rs
- examples/hello.rs
- examples/image.rs
- examples/animations.rs
- examples/composite_widgets.rs
- examples/widget_table.rs
- examples/menubutton.rs
- examples/rounded_images.rs
- examples/widget_id.rs
- examples/rgb.rs
- examples/gradients.rs
- examples/custom_popup.rs
- examples/fb.rs
- examples/charts.rs
- examples/counter4.rs
- examples/spreadsheet.rs
- examples/defaults.rs
- examples/table.rs
- examples/tree.rs
- examples/frames.rs
- examples/temp_converter.rs
- examples/counter3.rs
- examples/counter.rs
- examples/popup_browser.rs
- examples/custom_widgets.rs
- examples/pong.rs
- examples/format_text.rs
sourcepub fn wait(self) -> bool
pub fn wait(self) -> bool
Wait for incoming messages. Calls to redraw within wait require an explicit sleep
Examples found in repository?
examples/messages.rs (line 30)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
fn main() {
let app = app::App::default();
let mut wind = Window::default().with_size(400, 300);
let mut frame = Frame::default().size_of(&wind).with_label("0");
let mut val = 0;
wind.show();
let (s, r) = app::channel::<Message>();
std::thread::spawn(move || loop {
app::sleep(1.);
s.send(Message::Increment(2));
});
while app.wait() {
if let Some(Message::Increment(step)) = r.recv() {
inc_frame(&mut frame, &mut val, step)
}
}
}
More examples
examples/temp_converter2.rs (line 84)
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
pub fn run(&mut self) {
while self.a.wait() {
if let Some(msg) = self.r.recv() {
match msg {
Message::CelciusChanged => {
self.inp2.set_value(&format!(
"{:.4}",
c_to_f(self.inp1.value().parse().unwrap_or(0.0))
));
}
Message::FahrenheitChanged => {
self.inp1.set_value(&format!(
"{:.4}",
f_to_c(self.inp2.value().parse().unwrap_or(0.0))
));
}
}
}
}
}
examples/system_fonts.rs (line 41)
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
fn main() {
let app = app::App::default().load_system_fonts();
// To load a font by path, check the App::load_font() method
let fonts = app::fonts();
// println!("{:?}", fonts);
let mut wind = window::Window::default().with_size(400, 300);
let mut frame = frame::Frame::default().size_of(&wind);
frame.set_label_size(30);
wind.set_color(enums::Color::White);
wind.end();
wind.show();
println!("The system has {} fonts!\nStarting slideshow!", fonts.len());
let mut i = 0;
while app.wait() {
if i == fonts.len() {
i = 0;
}
frame.set_label(&format!("[{}]", fonts[i]));
frame.set_label_font(enums::Font::by_index(i));
app::sleep(0.5);
i += 1;
}
}
examples/counter2.rs (line 26)
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
fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = app::App::default();
let mut wind = Window::default().with_size(160, 200).with_label("Counter");
let mut pack = Pack::default().with_size(120, 140).center_of(&wind);
pack.set_spacing(10);
let mut but_inc = Button::default().with_size(0, 40).with_label("+");
let mut frame = Frame::default().with_size(0, 40).with_label("0");
let mut but_dec = Button::default().with_size(0, 40).with_label("-");
pack.end();
wind.end();
wind.show();
let (s, r) = app::channel::<Message>();
but_inc.emit(s, Message::Increment);
but_dec.emit(s, Message::Decrement);
while app.wait() {
let label: i32 = frame.label().parse()?;
if let Some(msg) = r.recv() {
match msg {
Message::Increment => frame.set_label(&(label + 1).to_string()),
Message::Decrement => frame.set_label(&(label - 1).to_string()),
}
}
}
Ok(())
}
examples/closable_tab.rs (line 180)
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
fn main() {
use fltk::{prelude::*, *};
// Create groups to be used as content for tabs
pub fn create_tab(from: i32, to: i32) -> group::Group {
let grp = group::Group::new(0, 0, 800, 600, None);
for idx in from..to {
button::Button::new(
idx * 10 + (idx - from) * 42,
idx * 10 + (idx - from) * 42,
80,
40,
None,
)
.with_label(&format!("button {}", idx));
}
grp.end();
grp
}
let app = app::App::default();
let mut win = window::Window::default().with_size(800, 600);
let (s, r) = app::channel::<closable_tab::Message>();
let mut tabs = closable_tab::ClosableTab::new(0, 0, 800, 600, &s);
win.end();
win.show();
tabs.add(&mut create_tab(1, 3), "tab 1");
tabs.add(&mut create_tab(4, 7), "tab 2");
tabs.add(&mut create_tab(8, 11), "tab 3");
tabs.add(&mut create_tab(12, 15), "tab 4");
tabs.add(&mut create_tab(16, 22), "tab 5");
tabs.set_foreground(2);
while app.wait() {
use closable_tab::Message::*;
if let Some(msg) = r.recv() {
match msg {
Foreground(idx) => {
tabs.set_foreground(idx);
}
Delete(idx) => {
tabs.remove(idx);
}
InsertNew(_) => {}
}
}
}
}
examples/threads_windows.rs (line 59)
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
fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = app::App::default();
let mut wind = Window::default().with_size(160, 200).with_label("Counter");
let mut pack = Pack::default().with_size(120, 140).center_of(&wind);
pack.set_spacing(10);
let mut but_inc = Button::default().with_size(0, 40).with_label("+");
let mut frame = Frame::default().with_size(0, 40).with_label("0");
let mut but_dec = Button::default().with_size(0, 40).with_label("-");
pack.end();
wind.end();
wind.show();
let mut msg_wind = Window::default().with_size(120, 100).with_label("Message");
let mut msgview = HelpView::default().with_size(120, 100);
msgview.set_align(Align::Center);
msg_wind.end();
let (s, r) = app::channel::<Message>();
but_inc.set_callback({
move |_| {
s.send(Message::Deactivate);
thread::spawn(move || {
thread::sleep(Duration::from_secs(1));
s.send(Message::Increment);
s.send(Message::Message("Incremented"));
s.send(Message::Activate);
});
}
});
but_dec.set_callback({
move |_| {
s.send(Message::Deactivate);
thread::spawn(move || {
thread::sleep(Duration::from_secs(1));
s.send(Message::Decrement);
s.send(Message::Message("Decremented"));
s.send(Message::Activate);
});
}
});
while app.wait() {
if let Some(msg) = r.recv() {
let label: i32 = frame.label().parse()?;
match msg {
Message::Increment => frame.set_label(&(label + 1).to_string()),
Message::Decrement => frame.set_label(&(label - 1).to_string()),
Message::Activate => {
but_inc.activate();
but_dec.activate();
}
Message::Deactivate => {
but_inc.deactivate();
but_dec.deactivate();
}
Message::Message(s) => {
msgview.set_value(s);
msg_wind.show();
}
}
}
}
Ok(())
}
Additional examples can be found in:
sourcepub fn load_system_fonts(self) -> Self
pub fn load_system_fonts(self) -> Self
Loads system fonts
Examples found in repository?
examples/system_fonts.rs (line 29)
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
fn main() {
let app = app::App::default().load_system_fonts();
// To load a font by path, check the App::load_font() method
let fonts = app::fonts();
// println!("{:?}", fonts);
let mut wind = window::Window::default().with_size(400, 300);
let mut frame = frame::Frame::default().size_of(&wind);
frame.set_label_size(30);
wind.set_color(enums::Color::White);
wind.end();
wind.show();
println!("The system has {} fonts!\nStarting slideshow!", fonts.len());
let mut i = 0;
while app.wait() {
if i == fonts.len() {
i = 0;
}
frame.set_label(&format!("[{}]", fonts[i]));
frame.set_label_font(enums::Font::by_index(i));
app::sleep(0.5);
i += 1;
}
}
sourcepub fn load_font<P: AsRef<Path>>(self, path: P) -> Result<String, FltkError>
pub fn load_font<P: AsRef<Path>>(self, path: P) -> Result<String, FltkError>
Loads a font from a path.
On success, returns a String with the ttf Font Family name. The font’s index is always 16.
As such only one font can be loaded at a time.
The font name can be used with Font::by_name
, and index with Font::by_index
.
Examples
use fltk::{prelude::*, *};
let app = app::App::default();
let font = app.load_font("font.ttf").unwrap();
let mut frame = frame::Frame::new(0, 0, 400, 100, "Hello");
frame.set_label_font(enums::Font::by_name(&font));
Errors
Returns ResourceNotFound
if the Font file was not found
sourcepub fn set_visual(self, mode: Mode) -> Result<(), FltkError>
pub fn set_visual(self, mode: Mode) -> Result<(), FltkError>
Set the visual of the application
Errors
Returns FailedOperation
if FLTK failed to set the visual mode
sourcepub fn quit(self)
pub fn quit(self)
Quit the application
Examples found in repository?
examples/editor.rs (line 420)
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
pub fn launch(&mut self) {
while self.app.wait() {
use Message::*;
if let Some(msg) = self.r.recv() {
match msg {
Changed => {
if !self.modified {
self.modified = true;
self.menu.menu.find_item("&File/Save\t").unwrap().activate();
self.menu.menu.find_item("&File/Quit\t").unwrap().set_label_color(Color::Red);
let name = match &self.filename {
Some(f) => f.to_string_lossy().to_string(),
None => "(Untitled)".to_string(),
};
self.main_win.set_label(&format!("* {} - RustyEd",name));
}
}
New => {
if self.buf.text() != "" {
let clear = if let Some(x) = dialog::choice2(center().0 - 200, center().1 - 100, "File unsaved, Do you wish to continue?", "Yes", "No!", "") {
x == 0
} else {
false
};
if clear {
self.buf.set_text("");
}
}
},
Open => {
let mut dlg = dialog::FileDialog::new(dialog::FileDialogType::BrowseFile);
dlg.set_option(dialog::FileDialogOptions::NoOptions);
dlg.set_filter("*.{txt,rs,toml}");
dlg.show();
let filename = dlg.filename();
if !filename.to_string_lossy().to_string().is_empty() {
if filename.exists() {
match self.buf.load_file(&filename) {
Ok(_) => self.filename = Some(filename),
Err(e) => dialog::alert(center().0 - 200, center().1 - 100, &format!("An issue occured while loading the file: {}", e)),
}
} else {
dialog::alert(center().0 - 200, center().1 - 100, "File does not exist!")
}
}
},
Save => { self.save_file().unwrap(); },
SaveAs => { self.save_file_as().unwrap(); },
Print => {
let mut printer = printer::Printer::default();
if printer.begin_job(0).is_ok() {
let (w, h) = printer.printable_rect();
self.printable.set_size(w - 40, h - 40);
// Needs cleanup
let line_count = self.printable.count_lines(0, self.printable.buffer().unwrap().length(), true) / 45;
for i in 0..=line_count {
self.printable.scroll(45 * i, 0);
printer.begin_page().ok();
printer.print_widget(&self.printable, 20, 20);
printer.end_page().ok();
}
printer.end_job();
}
},
Quit => {
if self.modified {
match dialog::choice2(center().0 - 200, center().1 - 100,
"Would you like to save your work?", "Yes", "No", "") {
Some(0) => {
if self.save_file().unwrap() {
self.app.quit();
}
},
Some(1) => { self.app.quit() },
Some(_) | None => (),
}
} else {
self.app.quit();
}
},
Cut => self.editor.cut(),
Copy => self.editor.copy(),
Paste => self.editor.paste(),
About => dialog::message(center().0 - 300, center().1 - 100, "This is an example application written in Rust and using the FLTK Gui library."),
}
}
}
}
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for App
impl Send for App
impl Sync for App
impl Unpin for App
impl UnwindSafe for App
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more