Struct relm4::ComponentBuilder
source · Expand description
A component that is ready for docking and launch.
Fields§
§root: C::Root
The root widget of the component.
Implementations§
source§impl<C: Component> ComponentBuilder<C>
impl<C: Component> ComponentBuilder<C>
sourcepub fn update_root<F: FnOnce(&mut C::Root)>(self, func: F) -> Self
pub fn update_root<F: FnOnce(&mut C::Root)>(self, func: F) -> Self
Configure the root widget before launching.
sourcepub const fn widget(&self) -> &C::Root
pub const fn widget(&self) -> &C::Root
Access the root widget before the component is initialized.
sourcepub fn priority(self, priority: Priority) -> Self
pub fn priority(self, priority: Priority) -> Self
Change the priority at which the messages of this component are handled.
- Use [
glib::PRIORITY_HIGH
] for high priority event sources. - Use [
glib::PRIORITY_LOW
] for very low priority background tasks. - Use [
glib::PRIORITY_DEFAULT_IDLE
] for default priority idle functions. - Use [
glib::PRIORITY_HIGH_IDLE
] for high priority idle functions.
source§impl<C: Component> ComponentBuilder<C>where
C::Root: AsRef<Widget>,
impl<C: Component> ComponentBuilder<C>where
C::Root: AsRef<Widget>,
sourcepub fn attach_to(self, container: &impl RelmContainerExt) -> Self
pub fn attach_to(self, container: &impl RelmContainerExt) -> Self
Attach the component’s root widget to a given container.
source§impl<C: Component> ComponentBuilder<C>where
C::Root: AsRef<Window> + Clone,
impl<C: Component> ComponentBuilder<C>where
C::Root: AsRef<Window> + Clone,
sourcepub fn transient_for(self, widget: impl AsRef<Widget>) -> Self
pub fn transient_for(self, widget: impl AsRef<Widget>) -> Self
Set the component’s root widget transient for a given window.
This function doesn’t require a gtk::Window
as parameter,
but instead uses RelmWidgetExt::toplevel_window()
to retrieve the toplevel
window of any gtk::Widget
.
Therefore, you don’t have to pass a window to every component.
If the root widget is a native dialog, such as gtk::FileChooserNative
,
you should use transient_for_native
instead.
source§impl<C: Component> ComponentBuilder<C>where
C::Root: AsRef<NativeDialog> + Clone,
impl<C: Component> ComponentBuilder<C>where
C::Root: AsRef<NativeDialog> + Clone,
sourcepub fn transient_for_native(self, widget: impl AsRef<Widget>) -> Self
pub fn transient_for_native(self, widget: impl AsRef<Widget>) -> Self
Set the component’s root widget transient for a given window.
This function doesn’t require a gtk::Window
as parameter,
but instead uses RelmWidgetExt::toplevel_window()
to retrieve the toplevel
window of any gtk::Widget
.
Therefore, you don’t have to pass a window to every component.
Applicable to native dialogs only, such as gtk::FileChooserNative
.
If the root widget is a non-native dialog,
you should use transient_for
instead.
source§impl<C: Component> ComponentBuilder<C>
impl<C: Component> ComponentBuilder<C>
sourcepub fn launch(self, payload: C::Init) -> Connector<C>
pub fn launch(self, payload: C::Init) -> Connector<C>
Starts the component, passing ownership to a future attached to a [gtk::glib::MainContext].
Examples found in repository?
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 84 85 86 87 88 89 90 91 92
pub fn run_with_args<C, S>(self, payload: C::Init, args: &[S])
where
C: Component,
C::Root: IsA<gtk::Window> + WidgetExt,
S: AsRef<str>,
{
use std::cell::Cell;
let Self { app } = self;
let payload = Cell::new(Some(payload));
app.connect_activate(move |app| {
if let Some(payload) = payload.take() {
assert!(
app.is_registered(),
"App should be already registered when activated"
);
let builder = ComponentBuilder::<C>::default();
let connector = builder.launch(payload);
// Run late initialization for transient windows for example.
crate::late_initialization::run_late_init();
let mut controller = connector.detach();
let window = controller.widget().clone();
controller.detach_runtime();
app.add_window(window.as_ref());
window.show();
} else {
panic!("Can't start Relm4 applications twice");
}
});
app.run_with_args(args);
}
sourcepub fn launch_with_broker(
self,
payload: C::Init,
broker: &MessageBroker<C>
) -> Connector<C>
pub fn launch_with_broker(
self,
payload: C::Init,
broker: &MessageBroker<C>
) -> Connector<C>
Similar to launch()
but also initializes a MessageBroker
.
Panics
This method panics if the message broker was already initialized in another launch.
source§impl<C> ComponentBuilder<C>where
C: Component<Root = (), Widgets = ()> + Send,
C::Input: Send,
C::Output: Send,
C::CommandOutput: Send,
impl<C> ComponentBuilder<C>where
C: Component<Root = (), Widgets = ()> + Send,
C::Input: Send,
C::Output: Send,
C::CommandOutput: Send,
sourcepub fn detach_worker(self, payload: C::Init) -> WorkerHandle<C>
pub fn detach_worker(self, payload: C::Init) -> WorkerHandle<C>
Starts a worker on a separate thread, passing ownership to a future attached to a [gtk::glib::MainContext].