diff --git a/examples/composite_template/ex_menu_button/ex_menu_button.ui b/examples/composite_template/ex_menu_button/ex_menu_button.ui
index b38458ed3fb1..a8d9048c1ba7 100644
--- a/examples/composite_template/ex_menu_button/ex_menu_button.ui
+++ b/examples/composite_template/ex_menu_button/ex_menu_button.ui
@@ -6,6 +6,7 @@
+
Hello from a custom child widget!
diff --git a/examples/composite_template/ex_menu_button/imp.rs b/examples/composite_template/ex_menu_button/imp.rs
index f85b6c4e3bc0..81764d90e4b0 100644
--- a/examples/composite_template/ex_menu_button/imp.rs
+++ b/examples/composite_template/ex_menu_button/imp.rs
@@ -3,7 +3,7 @@ use gtk::subclass::prelude::*;
use gtk::{glib, CompositeTemplate};
#[derive(Debug, Default, CompositeTemplate)]
-#[template(file = "ex_menu_button.ui")]
+#[template(file = "ex_menu_button.ui", callbacks)]
pub struct ExMenuButton {
#[template_child]
pub toggle: TemplateChild,
@@ -26,25 +26,21 @@ impl ObjectSubclass for ExMenuButton {
}
}
-impl ObjectImpl for ExMenuButton {
- fn constructed(&self, obj: &Self::Type) {
- self.parent_constructed(obj);
-
- let popover = &*self.popover;
- self.toggle
- .connect_toggled(glib::clone!(@weak popover => move |toggle| {
- if toggle.is_active() {
- popover.popup();
- }
- }));
-
- let toggle = &*self.toggle;
- self.popover
- .connect_closed(glib::clone!(@weak toggle => move |_| {
- toggle.set_active(false);
- }));
+#[gtk::template_callbacks]
+impl ExMenuButton {
+ #[template_callback]
+ fn toggle_toggled(&self, toggle: gtk::ToggleButton) {
+ if toggle.is_active() {
+ self.popover.popup();
+ }
}
+ #[template_callback(name = "popover_closed")]
+ fn unset_toggle(&self) {
+ self.toggle.set_active(false);
+ }
+}
+impl ObjectImpl for ExMenuButton {
// Needed for direct subclasses of GtkWidget;
// Here you need to unparent all direct children
// of your template.