Trait relm4::RelmWidgetExt

source ·
pub trait RelmWidgetExt {
    // Required methods
    fn set_size_group(&self, size_group: &SizeGroup);
    fn toplevel_window(&self) -> Option<Window>;
    fn set_margin_vertical(&self, margin: i32);
    fn set_margin_horizontal(&self, margin: i32);
    fn set_class_active(&self, class: &str, active: bool);
    fn inline_css(&self, style: &str);
    fn set_tooltip(&self, test: &str);

    // Provided method
    fn set_margin_all(&self, margin: i32) { ... }
}
Expand description

Trait that extends gtk::prelude::WidgetExt.

This trait’s main goal is to reduce redundant code and to provide helpful methods for the widgets macro of relm4-macros.

Required Methods§

source

fn set_size_group(&self, size_group: &SizeGroup)

Attach widget to a gtk::SizeGroup.

source

fn toplevel_window(&self) -> Option<Window>

Locate the top level window this widget is attached to.

Equivalent to widget.ancestor(gtk::Window::static_type()), then casting.

source

fn set_margin_vertical(&self, margin: i32)

Set margin at top and bottom at once.

source

fn set_margin_horizontal(&self, margin: i32)

Set margin at start and end at once.

source

fn set_class_active(&self, class: &str, active: bool)

Add class name if active is true and remove class name if active is false

source

fn inline_css(&self, style: &str)

Add inline CSS instructions to a widget.

widget.inline_css("border: 1px solid red");
source

fn set_tooltip(&self, test: &str)

Sets the tooltip text of a widget and enables is.

This is basically, the same as using WidgetExt::set_has_tooltip() and WidgetExt::set_tooltip_text(), but with fewer steps.

Provided Methods§

source

fn set_margin_all(&self, margin: i32)

Set margin at start, end, top and bottom all at once.

Examples found in repository?
examples/simple_manual.rs (line 55)
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
    fn init(
        counter: Self::Init,
        window: &Self::Root,
        sender: ComponentSender<Self>,
    ) -> ComponentParts<Self> {
        let model = App { counter };

        let vbox = gtk::Box::builder()
            .orientation(gtk::Orientation::Vertical)
            .spacing(5)
            .build();

        let inc_button = gtk::Button::with_label("Increment");
        let dec_button = gtk::Button::with_label("Decrement");

        let label = gtk::Label::new(Some(&format!("Counter: {}", model.counter)));
        label.set_margin_all(5);

        window.set_child(Some(&vbox));
        vbox.set_margin_all(5);
        vbox.append(&inc_button);
        vbox.append(&dec_button);
        vbox.append(&label);

        inc_button.connect_clicked(clone!(@strong sender => move |_| {
            sender.input(Msg::Increment);
        }));

        dec_button.connect_clicked(clone!(@strong sender => move |_| {
            sender.input(Msg::Decrement);
        }));

        let widgets = AppWidgets { label };

        ComponentParts { model, widgets }
    }

Implementors§

source§

impl<T: IsA<Widget>> RelmWidgetExt for T