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_expand(&self, expand: bool);
fn set_align(&self, align: Align);
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§
Sourcefn set_size_group(&self, size_group: &SizeGroup)
fn set_size_group(&self, size_group: &SizeGroup)
Attach widget to a gtk::SizeGroup.
Sourcefn toplevel_window(&self) -> Option<Window>
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.
Sourcefn set_margin_vertical(&self, margin: i32)
fn set_margin_vertical(&self, margin: i32)
Set margin at top and bottom at once.
Sourcefn set_margin_horizontal(&self, margin: i32)
fn set_margin_horizontal(&self, margin: i32)
Set margin at start and end at once.
Sourcefn set_expand(&self, expand: bool)
fn set_expand(&self, expand: bool)
Set both horizontal and vertical expand properties at once.
Sourcefn set_class_active(&self, class: &str, active: bool)
fn set_class_active(&self, class: &str, active: bool)
Sourcefn inline_css(&self, style: &str)
fn inline_css(&self, style: &str)
Add inline CSS instructions to a widget.
widget.inline_css("border: 1px solid red");Sourcefn set_tooltip(&self, test: &str)
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§
Sourcefn set_margin_all(&self, margin: i32)
fn set_margin_all(&self, margin: i32)
Set margin at start, end, top and bottom all at once.
Examples found in repository?
relm4/examples/typed_grid_view.rs (line 44)
40 fn setup(_item: >k::ListItem) -> (gtk::Box, Widgets) {
41 relm4::view! {
42 my_box = gtk::Box {
43 set_orientation: gtk::Orientation::Horizontal,
44 set_margin_all: 2,
45 set_spacing: 5,
46
47 #[name = "label"]
48 gtk::Label,
49
50 #[name = "label2"]
51 gtk::Label,
52
53 #[name = "button"]
54 gtk::CheckButton,
55 }
56 }
57
58 let widgets = Widgets {
59 label,
60 label2,
61 button,
62 };
63
64 (my_box, widgets)
65 }More examples
relm4/examples/message_from_grid_view.rs (line 58)
52 fn setup(item: >k::ListItem) -> (gtk::Box, Widgets) {
53 item.set_activatable(false);
54 item.set_focusable(false);
55 relm4::view! {
56 my_box = gtk::Box {
57 set_orientation: gtk::Orientation::Horizontal,
58 set_margin_all: 2,
59 set_spacing: 5,
60
61 #[name = "button"]
62 gtk::Button {
63 set_hexpand: true,
64 #[name = "label"]
65 gtk::Label {
66 set_halign: gtk::Align::Center,
67 }
68 }
69 }
70 }
71
72 let widgets = Widgets { label, button };
73
74 (my_box, widgets)
75 }relm4/examples/simple_manual.rs (line 55)
39 fn init(
40 counter: Self::Init,
41 window: Self::Root,
42 sender: ComponentSender<Self>,
43 ) -> ComponentParts<Self> {
44 let model = AppModel { counter };
45
46 let vbox = gtk::Box::builder()
47 .orientation(gtk::Orientation::Vertical)
48 .spacing(5)
49 .build();
50
51 let inc_button = gtk::Button::with_label("Increment");
52 let dec_button = gtk::Button::with_label("Decrement");
53
54 let label = gtk::Label::new(Some(&format!("Counter: {}", model.counter)));
55 label.set_margin_all(5);
56
57 window.set_child(Some(&vbox));
58 vbox.set_margin_all(5);
59 vbox.append(&inc_button);
60 vbox.append(&dec_button);
61 vbox.append(&label);
62
63 inc_button.connect_clicked(clone!(
64 #[strong]
65 sender,
66 move |_| {
67 sender.input(AppMsg::Increment);
68 }
69 ));
70
71 dec_button.connect_clicked(clone!(
72 #[strong]
73 sender,
74 move |_| {
75 sender.input(AppMsg::Decrement);
76 }
77 ));
78
79 let widgets = AppWidgets { label };
80
81 ComponentParts { model, widgets }
82 }