Struct fltk::group::HGrid

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

Defines a Horizontal Grid (custom widget). Requires setting the params manually using the set_params method, which takes the rows, columns and spacing.

use fltk::{prelude::*, *};
fn main() {
    let app = app::App::default();
    let mut win = window::Window::default().with_size(400, 300);
    let mut grid = group::HGrid::new(0, 0, 400, 300, "");
    grid.set_params(3, 3, 5);
    button::Button::default();
    button::Button::default();
    button::Button::default();
    button::Button::default();
    button::Button::default();
    button::Button::default();
    button::Button::default();
    button::Button::default();
    grid.end();
    win.end();
    win.show();
    app.run().unwrap();
}

Implementations§

source§

impl HGrid

source

pub fn default_fill() -> Self

Constructs a widget with the size of its parent

source

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

Creates a new horizontal grid

source

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

Sets the params for the grid

source

pub fn add<W: WidgetExt>(&mut self, w: &W)

Adds widgets to the grid

source

pub fn end(&mut self)

End the grid

source§

impl HGrid

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

Methods from Deref<Target = Pack>§

source

pub fn spacing(&self) -> i32

Get the spacing of the pack

source

pub fn set_spacing(&mut self, spacing: i32)

Set the spacing of the pack

Examples found in repository?
examples/composite_widgets.rs (line 49)
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
fn main() {
    let app = app::App::default();
    app::set_visible_focus(false);
    let mut win = window::Window::default().with_size(500, 400);
    win.make_resizable(true);
    win.set_color(enums::Color::Black);
    let mut pack = group::Pack::default().size_of(&win);
    pack.set_spacing(10);

    for i in 0..3 {
        let label = format!("Button {}", i + 1);
        let mut but = MyButton::new(500, 100);
        but.set_label(&label);
        but.set_callback(move |_| println!("{label}"));
    }

    pack.end();
    win.end();
    win.show();
    app.run().unwrap();
}
More examples
Hide additional examples
examples/closable_tabs2.rs (line 48)
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
        pub fn new(x: i32, y: i32, w: i32, h: i32, snd: &'a app::Sender<Message>) -> Self {
            let current = None;
            let parent_grp = group::Group::new(x, y, w, h, None);
            let mut tab_labels = group::Pack::new(x + 5, y, w - 10, 40, None);
            tab_labels.set_spacing(3);
            tab_labels.set_type(group::PackType::Horizontal);
            tab_labels.end();
            let mut contents = group::Group::new(x, y + 40, w, h - 40, None);
            contents.set_frame(FrameType::NoBox);
            contents.end();
            parent_grp.end();
            Self {
                current,
                snd,
                contents,
                tab_labels,
            }
        }
examples/counter2.rs (line 13)
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/counter4.rs (line 45)
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
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = app::App::default();
    let counter = Counter::new(0);
    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(&counter.value().to_string());
    let mut but_dec = Button::default().with_size(0, 40).with_label("-");
    pack.end();
    wind.end();
    wind.show();

    but_inc.set_callback({
        let mut c = counter.clone();
        move |_| c.increment()
    });

    but_dec.set_callback({
        let mut c = counter.clone();
        move |_| c.decrement()
    });

    frame.handle(move |f, ev| {
        if ev == MyEvent::CHANGED.into() {
            f.set_label(&counter.clone().value().to_string());
            true
        } else {
            false
        }
    });

    Ok(app.run()?)
}
examples/tabs.rs (line 18)
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
fn draw_gallery() {
    let tab = Tabs::new(10, 10, 500 - 20, 450 - 20, "");

    let grp1 = Group::new(10, 35, 500 - 20, 450 - 45, "Tab1\t\t");

    let mut pack = Pack::new(15, 45, 150, 450 - 45, "");
    pack.set_spacing(10);
    let _but1 = Button::default().with_size(0, 30).with_label("Button");
    let _but2 = RoundButton::default().with_size(0, 30).with_label("Round");
    let _but3 = CheckButton::default().with_size(0, 30).with_label("Check");
    let _but4 = LightButton::default().with_size(0, 30).with_label("Light");
    let mut but5 = MenuButton::default().with_size(0, 30).with_label("Menu");
    but5.add_choice("Hello|World|From|Rust");
    let _but6 = ReturnButton::default()
        .with_size(0, 30)
        .with_label("Return");
    let mut chce = Choice::new(50, 240, 90, 30, "");
    chce.add_choice("Hello");
    let _inp = Input::default().with_size(0, 30).with_label("");
    let _out = Output::default().with_size(0, 30).with_label("");

    pack.end();
    grp1.end();

    let grp2 = Group::new(10, 35, 500 - 30, 450 - 25, "Tab2\t\t");
    grp2.end();
    tab.end();
}
examples/frames.rs (line 37)
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
82
83
fn main() {
    let app = app::App::default();
    let mut win = window::Window::default()
        .with_size(1000, 800)
        .with_label("Frames")
        .center_screen();

    let mut hpack = group::Pack::new(20, 0, 1000, 800, "");

    let mut pack = group::Pack::default().with_size(150, 800);
    for i in 0..9 {
        let _ = MyFrame::new(i);
    }
    pack.end();
    pack.set_spacing(10);

    let mut pack = group::Pack::default().with_size(150, 800);
    for i in 9..18 {
        let _ = MyFrame::new(i);
    }
    pack.end();
    pack.set_spacing(10);

    let mut pack = group::Pack::default().with_size(150, 800);
    for i in 18..27 {
        let _ = MyFrame::new(i);
    }
    pack.end();
    pack.set_spacing(10);

    let mut pack = group::Pack::default().with_size(150, 800);
    for i in 27..36 {
        let _ = MyFrame::new(i);
    }
    pack.end();
    pack.set_spacing(10);

    let mut pack = group::Pack::default().with_size(150, 800);
    for i in 36..45 {
        let _ = MyFrame::new(i);
    }
    pack.end();
    pack.set_spacing(10);

    let mut pack = group::Pack::default().with_size(150, 800);
    for i in 45..54 {
        let _ = MyFrame::new(i);
    }
    pack.end();
    pack.set_spacing(10);

    hpack.end();
    hpack.set_spacing(10);
    hpack.set_type(group::PackType::Horizontal);

    win.end();
    win.show();
    win.set_color(enums::Color::White);

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

pub fn auto_layout(&mut self)

Layout the children of the pack automatically. Must be called on existing children

Examples found in repository?
examples/custom_popup.rs (line 73)
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
    pub fn new(choices: &[&str]) -> Self {
        let val = Rc::from(RefCell::from(String::from("")));
        let mut win = window::Window::default().with_size(120, choices.len() as i32 * 25);
        let mut pack = group::Pack::default().size_of_parent();
        pack.set_frame(FrameType::ThinUpFrame);
        pack.set_color(Color::Black);
        win.set_border(false);
        win.make_modal(true);
        win.end();
        for choice in choices {
            let mut but = PopupButton::new(choice);
            but.clear_visible_focus();
            but.set_callback({
                let mut win = win.clone();
                let val = val.clone();
                move |b| {
                    *val.borrow_mut() = b.label();
                    win.hide();
                }
            });
            pack.add(&*but);
        }
        pack.auto_layout();
        Self { win, val }
    }
More examples
Hide additional examples
examples/custom_choice.rs (line 79)
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
82
83
84
85
86
87
88
    pub fn new(choices: &[&str]) -> Self {
        let val = Rc::from(RefCell::from(String::from("")));
        let idx = RefCell::from(0);
        let mut win = window::Window::default().with_size(120, choices.len() as i32 * 25);
        win.set_color(Color::White);
        win.set_frame(FrameType::BorderBox);
        let mut pack = group::Pack::new(1, 1, win.w() - 2, win.h() - 2, None);
        win.set_border(false);
        win.end();
        for (i, choice) in choices.iter().enumerate() {
            let mut but = PopupButton::new(choice);
            but.clear_visible_focus();
            but.set_callback({
                let mut win = win.clone();
                let val = val.clone();
                let idx = idx.clone();
                move |b| {
                    *val.borrow_mut() = b.label();
                    *idx.borrow_mut() = i as i32;
                    win.hide();
                }
            });
            pack.add(&*but);
        }
        pack.auto_layout();
        win.handle(|w, ev| match ev {
            Event::Unfocus => {
                w.hide();
                true
            }
            _ => false,
        });
        Self { win, val, idx }
    }

Trait Implementations§

source§

impl Clone for HGrid

source§

fn clone(&self) -> HGrid

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 HGrid

source§

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

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

impl Default for HGrid

source§

fn default() -> Self

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

impl Deref for HGrid

§

type Target = Pack

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl DerefMut for HGrid

source§

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

Mutably dereferences the value.

Auto Trait Implementations§

§

impl RefUnwindSafe for HGrid

§

impl Send for HGrid

§

impl Sync for HGrid

§

impl Unpin for HGrid

§

impl UnwindSafe for HGrid

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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.
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.
source§

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

Performs the conversion.