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§
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_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?
examples/typed_grid_view.rs (line 44)
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
fn setup(_item: >k::ListItem) -> (gtk::Box, Widgets) {
relm4::view! {
my_box = gtk::Box {
set_orientation: gtk::Orientation::Horizontal,
set_margin_all: 2,
set_spacing: 5,
#[name = "label"]
gtk::Label,
#[name = "label2"]
gtk::Label,
#[name = "button"]
gtk::CheckButton,
}
}
let widgets = Widgets {
label,
label2,
button,
};
(my_box, widgets)
}
More examples
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 }
}