fltk_builder/
lib.rs

1#![doc = include_str!("../README.md")]
2
3use fltk::{prelude::*, app::App};
4
5
6#[cfg(feature = "id_map")]
7#[macro_use]
8extern crate lazy_static;
9
10/// Holds several extension traits to enable a builder pattern
11pub mod extensions;
12
13#[cfg(feature = "id_map")]
14mod id_map;
15#[cfg(feature = "id_map")]
16pub use id_map::{get_widget_by_id, IdMapError};
17
18/// Starting point for the UI
19#[derive(Debug)]
20pub struct FltkBuilder<W> 
21where W: WindowExt {
22    app: App,
23    window: Option<W>
24}
25
26impl<W> FltkBuilder<W>
27where W: WindowExt
28{
29    /// Creates a new FltkBuilder struct
30    pub fn new(app: App) -> Self { Self { app, window: None } }
31
32    /// Get the fltk builder's app
33    #[must_use]
34    pub fn app(&self) -> App {
35        self.app
36    }
37
38    /// Set the main window of the fltk app
39    pub fn window(mut self, window: W) -> Self{
40        window.end();
41        self.window = Some(window);
42        self
43    }
44
45    /// Call show on the window if it's available
46    pub fn show(&mut self) {
47        if self.window.is_some() {
48            let win = self.window.as_mut().unwrap();
49            win.show();
50        }
51    }
52
53    /// Get a mutable reference to the fltk builder's window.
54    #[must_use]
55    pub fn get_window_mut(&mut self) -> &mut Option<W> {
56        &mut self.window
57    }
58}
59
60/// Reexports of all fltk_builder traits 
61pub mod prelude;