Struct fltk_grid::Grid

source ·
pub struct Grid { /* private fields */ }
Expand description

A grid widget

Implementations§

source§

impl Grid

source

pub fn new<S: Into<Option<&'static str>>>( x: i32, y: i32, w: i32, h: i32, label: S ) -> Self

Creates a new grid widget

source

pub fn default_fill() -> Self

Creates a default value grid widget filling the parent

Examples found in repository?
examples/grid_in_grid.rs (line 56)
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
fn main() {
    let a = app::App::default();
    let mut win = window::Window::default().with_size(800, 600);
    let mut grid = Grid::default_fill();
    grid.debug(false);
    grid.set_layout(1, 2);
    let mut panel1 = Panel::default();
    let mut panel2 = Panel::default();
    grid.insert_grid(&mut *panel1, 0, 0);
    grid.insert_grid(&mut *panel2, 0, 1);
    win.end();
    win.make_resizable(true);
    win.show();

    a.run().unwrap();
}
More examples
Hide additional examples
examples/form.rs (line 14)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    pub fn default() -> Self {
        let mut grid = Grid::default_fill();
        grid.set_layout(10, 5); // construct a new grid
        let name = input::Input::default();
        let age = input::IntInput::default();
        let occupation = input::Input::default();
        let btn = button::Button::default().with_label("Submit");
        let mut g = Self {
            grid,
            name,
            age,
            occupation,
            btn,
        };
        g.fill();
        g
    }
examples/simple.rs (line 7)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let a = app::App::default().with_scheme(app::Scheme::Gtk);
    let mut win = window::Window::default().with_size(500, 300);
    let mut grid = Grid::default_fill();
    grid.debug(false); // set to true to show cell outlines and numbers
    grid.set_layout(5, 5); // 5 rows, 5 columns
    grid.insert(&mut button::Button::default(), 0, 1); // widget, row, col
    grid.insert(&mut button::Button::default(), 2..3, 1..4); // widget, row range, col range
                                                             // or
                                                             // grid.insert_ext(&mut button::Button::default(), 2, 1, 3, 1); // widget, row, col, row_span, col_span
    win.end();
    win.show();
    a.run().unwrap();
}
source

pub fn set_layout(&mut self, rows: i32, cols: i32)

Sets the rows and columns of the widget

Examples found in repository?
examples/form.rs (line 15)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    pub fn default() -> Self {
        let mut grid = Grid::default_fill();
        grid.set_layout(10, 5); // construct a new grid
        let name = input::Input::default();
        let age = input::IntInput::default();
        let occupation = input::Input::default();
        let btn = button::Button::default().with_label("Submit");
        let mut g = Self {
            grid,
            name,
            age,
            occupation,
            btn,
        };
        g.fill();
        g
    }
More examples
Hide additional examples
examples/simple.rs (line 9)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let a = app::App::default().with_scheme(app::Scheme::Gtk);
    let mut win = window::Window::default().with_size(500, 300);
    let mut grid = Grid::default_fill();
    grid.debug(false); // set to true to show cell outlines and numbers
    grid.set_layout(5, 5); // 5 rows, 5 columns
    grid.insert(&mut button::Button::default(), 0, 1); // widget, row, col
    grid.insert(&mut button::Button::default(), 2..3, 1..4); // widget, row range, col range
                                                             // or
                                                             // grid.insert_ext(&mut button::Button::default(), 2, 1, 3, 1); // widget, row, col, row_span, col_span
    win.end();
    win.show();
    a.run().unwrap();
}
examples/grid_in_grid.rs (line 15)
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
    pub fn default() -> Self {
        let mut grid = Grid::default();
        grid.debug(false);
        grid.set_layout(6, 1);
        let mut label = frame::Frame::default().with_label("ARTERY:");

        let mut cb1 = button::CheckButton::default().with_label("Normal");
        let mut cb2 = button::CheckButton::default().with_label("Normal");

        let cbvec = vec![cb1.clone(), cb2.clone()];

        let mut btn = button::Button::default().with_label("Submit");
        grid.insert(&mut label, 0, 0);
        grid.insert(&mut cb1, 1, 0);
        grid.insert(&mut cb2, 2, 0);
        grid.insert(&mut btn, 5, 0);
        btn.set_callback(move |btn| {
            for cb in cbvec.clone() {
                println!(
                    "CB status: {}",
                    if cb.is_checked() {
                        "Checked"
                    } else {
                        "Not_checked"
                    }
                );
            }
            println!("--------------");
        });
        Panel {
            grid,
            label,
            cb1,
            cb2,
            btn,
        }
    } // end default fn;
} // end impl Panel;

fltk::widget_extends!(Panel, Grid, grid);

fn main() {
    let a = app::App::default();
    let mut win = window::Window::default().with_size(800, 600);
    let mut grid = Grid::default_fill();
    grid.debug(false);
    grid.set_layout(1, 2);
    let mut panel1 = Panel::default();
    let mut panel2 = Panel::default();
    grid.insert_grid(&mut *panel1, 0, 0);
    grid.insert_grid(&mut *panel2, 0, 1);
    win.end();
    win.make_resizable(true);
    win.show();

    a.run().unwrap();
}
source

pub fn insert_ext<W: 'static + Clone + WidgetExt>( &mut self, widget: &mut W, row: i32, col: i32, row_span: i32, col_span: i32 )

Adds a widget to the grid. The row_span refers to the passed row value and is counted in columns. The col_span refers to the passed column value and is counted in rows.

source

pub fn insert<W: 'static + Clone + WidgetExt>( &mut self, widget: &mut W, row: impl Into<GridRange>, col: impl Into<GridRange> )

Insert a widget with a single span

Examples found in repository?
examples/simple.rs (line 10)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let a = app::App::default().with_scheme(app::Scheme::Gtk);
    let mut win = window::Window::default().with_size(500, 300);
    let mut grid = Grid::default_fill();
    grid.debug(false); // set to true to show cell outlines and numbers
    grid.set_layout(5, 5); // 5 rows, 5 columns
    grid.insert(&mut button::Button::default(), 0, 1); // widget, row, col
    grid.insert(&mut button::Button::default(), 2..3, 1..4); // widget, row range, col range
                                                             // or
                                                             // grid.insert_ext(&mut button::Button::default(), 2, 1, 3, 1); // widget, row, col, row_span, col_span
    win.end();
    win.show();
    a.run().unwrap();
}
More examples
Hide additional examples
examples/form.rs (lines 38-43)
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    fn fill(&mut self) {
        let grid = &mut self.grid;
        grid.debug(false); // set to true to see cell outlines
        let mut title = frame::Frame::default().with_label("Employee Form");
        title.set_frame(enums::FrameType::FlatBox);
        title.set_color(enums::Color::Red);
        title.set_label_color(enums::Color::White);
        grid.insert(
            // insert widgets
            &mut title,
            0,
            1..4,
        );
        grid.insert(&mut frame::Frame::default().with_label("Name"), 2, 1);
        grid.insert(&mut self.name, 2, 3);
        grid.insert(&mut frame::Frame::default().with_label("Age"), 4, 1);
        grid.insert(&mut self.age, 4, 3);
        grid.insert(&mut frame::Frame::default().with_label("Occupation"), 6, 1);
        grid.insert(&mut self.occupation, 6, 3);
        grid.insert(&mut self.btn, 8, 2);
    }
examples/grid_in_grid.rs (line 24)
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
    pub fn default() -> Self {
        let mut grid = Grid::default();
        grid.debug(false);
        grid.set_layout(6, 1);
        let mut label = frame::Frame::default().with_label("ARTERY:");

        let mut cb1 = button::CheckButton::default().with_label("Normal");
        let mut cb2 = button::CheckButton::default().with_label("Normal");

        let cbvec = vec![cb1.clone(), cb2.clone()];

        let mut btn = button::Button::default().with_label("Submit");
        grid.insert(&mut label, 0, 0);
        grid.insert(&mut cb1, 1, 0);
        grid.insert(&mut cb2, 2, 0);
        grid.insert(&mut btn, 5, 0);
        btn.set_callback(move |btn| {
            for cb in cbvec.clone() {
                println!(
                    "CB status: {}",
                    if cb.is_checked() {
                        "Checked"
                    } else {
                        "Not_checked"
                    }
                );
            }
            println!("--------------");
        });
        Panel {
            grid,
            label,
            cb1,
            cb2,
            btn,
        }
    }
source

pub fn insert_grid_ext( &mut self, widget: &mut Grid, row: i32, col: i32, row_span: i32, col_span: i32 )

Adds a widget to the grid. The row_span refers to the passed row value and is counted in columns. The col_span refers to the passed column value and is counted in rows.

source

pub fn insert_grid( &mut self, widget: &mut Grid, row: impl Into<GridRange>, col: impl Into<GridRange> )

Insert a widget with a single span

Examples found in repository?
examples/grid_in_grid.rs (line 61)
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
fn main() {
    let a = app::App::default();
    let mut win = window::Window::default().with_size(800, 600);
    let mut grid = Grid::default_fill();
    grid.debug(false);
    grid.set_layout(1, 2);
    let mut panel1 = Panel::default();
    let mut panel2 = Panel::default();
    grid.insert_grid(&mut *panel1, 0, 0);
    grid.insert_grid(&mut *panel2, 0, 1);
    win.end();
    win.make_resizable(true);
    win.show();

    a.run().unwrap();
}
source

pub fn remove<W: WidgetExt>(&mut self, widget: &W)

Removes a widget

source

pub fn resize(&mut self, x: i32, y: i32, w: i32, h: i32)

Determine how a grid is resized

Examples found in repository?
examples/form.rs (line 67)
66
67
68
    pub fn resize(&mut self, x: i32, y: i32, w: i32, h: i32) {
        self.grid.resize(x, y, w, h); // determine how it's resized
    }
source

pub fn debug(&mut self, flag: bool)

Show cell outlines and numbering

Examples found in repository?
examples/simple.rs (line 8)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let a = app::App::default().with_scheme(app::Scheme::Gtk);
    let mut win = window::Window::default().with_size(500, 300);
    let mut grid = Grid::default_fill();
    grid.debug(false); // set to true to show cell outlines and numbers
    grid.set_layout(5, 5); // 5 rows, 5 columns
    grid.insert(&mut button::Button::default(), 0, 1); // widget, row, col
    grid.insert(&mut button::Button::default(), 2..3, 1..4); // widget, row range, col range
                                                             // or
                                                             // grid.insert_ext(&mut button::Button::default(), 2, 1, 3, 1); // widget, row, col, row_span, col_span
    win.end();
    win.show();
    a.run().unwrap();
}
More examples
Hide additional examples
examples/form.rs (line 33)
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    fn fill(&mut self) {
        let grid = &mut self.grid;
        grid.debug(false); // set to true to see cell outlines
        let mut title = frame::Frame::default().with_label("Employee Form");
        title.set_frame(enums::FrameType::FlatBox);
        title.set_color(enums::Color::Red);
        title.set_label_color(enums::Color::White);
        grid.insert(
            // insert widgets
            &mut title,
            0,
            1..4,
        );
        grid.insert(&mut frame::Frame::default().with_label("Name"), 2, 1);
        grid.insert(&mut self.name, 2, 3);
        grid.insert(&mut frame::Frame::default().with_label("Age"), 4, 1);
        grid.insert(&mut self.age, 4, 3);
        grid.insert(&mut frame::Frame::default().with_label("Occupation"), 6, 1);
        grid.insert(&mut self.occupation, 6, 3);
        grid.insert(&mut self.btn, 8, 2);
    }
examples/grid_in_grid.rs (line 14)
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
    pub fn default() -> Self {
        let mut grid = Grid::default();
        grid.debug(false);
        grid.set_layout(6, 1);
        let mut label = frame::Frame::default().with_label("ARTERY:");

        let mut cb1 = button::CheckButton::default().with_label("Normal");
        let mut cb2 = button::CheckButton::default().with_label("Normal");

        let cbvec = vec![cb1.clone(), cb2.clone()];

        let mut btn = button::Button::default().with_label("Submit");
        grid.insert(&mut label, 0, 0);
        grid.insert(&mut cb1, 1, 0);
        grid.insert(&mut cb2, 2, 0);
        grid.insert(&mut btn, 5, 0);
        btn.set_callback(move |btn| {
            for cb in cbvec.clone() {
                println!(
                    "CB status: {}",
                    if cb.is_checked() {
                        "Checked"
                    } else {
                        "Not_checked"
                    }
                );
            }
            println!("--------------");
        });
        Panel {
            grid,
            label,
            cb1,
            cb2,
            btn,
        }
    } // end default fn;
} // end impl Panel;

fltk::widget_extends!(Panel, Grid, grid);

fn main() {
    let a = app::App::default();
    let mut win = window::Window::default().with_size(800, 600);
    let mut grid = Grid::default_fill();
    grid.debug(false);
    grid.set_layout(1, 2);
    let mut panel1 = Panel::default();
    let mut panel2 = Panel::default();
    grid.insert_grid(&mut *panel1, 0, 0);
    grid.insert_grid(&mut *panel2, 0, 1);
    win.end();
    win.make_resizable(true);
    win.show();

    a.run().unwrap();
}
source§

impl Grid

source

pub fn with_pos(self, x: i32, y: i32) -> Self

Initialize to position x, y

source

pub fn with_size(self, width: i32, height: i32) -> Self

Initialize to size width, height

source

pub fn with_label(self, title: &str) -> Self

Initialize with a label

source

pub fn with_align(self, align: Align) -> Self

Initialize with alignment

source

pub fn with_type<T: WidgetType>(self, typ: T) -> Self

Initialize with type

source

pub fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self

Initialize at bottom of another widget

source

pub fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self

Initialize above of another widget

source

pub fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self

Initialize right of another widget

source

pub fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self

Initialize left of another widget

source

pub fn center_of<W: WidgetExt>(self, w: &W) -> Self

Initialize center of another widget

source

pub fn center_x<W: WidgetExt>(self, w: &W) -> Self

Initialize center of another widget on the x axis

source

pub fn center_y<W: WidgetExt>(self, w: &W) -> Self

Initialize center of another widget on the y axis

source

pub fn center_of_parent(self) -> Self

Initialize center of parent

source

pub fn size_of<W: WidgetExt>(self, w: &W) -> Self

Initialize to the size of another widget

source

pub fn size_of_parent(self) -> Self

Initialize to the size of the parent

Trait Implementations§

source§

impl Clone for Grid

source§

fn clone(&self) -> Grid

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Grid

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Grid

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Deref for Grid

§

type Target = Table

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for Grid

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Grid

§

impl !Send for Grid

§

impl !Sync for Grid

§

impl Unpin for Grid

§

impl !UnwindSafe for Grid

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.