I have a main WidgetTemplate view, which includes another WidgetTemplate inside of it:
adw::Window {
// ...
#[template]
MainWidget {
#[template_child] // Can't access MainWidget->SettingsPage->btn_dark_mode like this
btn_dark_mode {
connect_clicked => Message::DarkMode,
},
},
}
Here is the MainWidget
template:
#[relm4::widget_template(pub)]
impl WidgetTemplate for MainWidget {
view! {
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
gtk::Stack{
set_margin_all: 11,
set_margin_top: 7,
#[template]
add_child = &SettingsPage {} -> {
set_name: "settings",
},
#[template]
add_child = &MainPage {} -> {
set_name: "main",
},
}
}
}
}
And inside of the SettingsPage
template, there is a button which should send a Message:
#[relm4::widget_template(pub)]
impl WidgetTemplate for SettingsPage {
view! {
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_spacing: 3,
#[name = "btn_dark_mode"] // I NEED TO HANDLE connect_clicked OF THIS WIDGET FROM ROOT VIEW
gtk::Button {
#[wrap(Some)]
set_child = >k::Image {
set_icon_name: Some("night-light-symbolic"), // When this clicked, I need to send Message::DarkMode
},
},
}
}
}
Question: Basically I want to handle connect_clicked of btn_dark_mode. I couldn't write directly on the template because it doesn't have the sender
. I need to declare it on main view!
but I can't access a template_child of a template_child from main view!
.
How can I do this?