examples: Move composite template struct to module
Brings the example in line with other gtk-rs examples.
@@ -8,29 +8,33 @@ extern crate glib;
extern crate gtk;
use gio::{prelude::ApplicationExtManual, ApplicationExt};
-use glib::subclass;
use glib::subclass::prelude::*;
use glib::{Cast, StaticType};
+use gtk::WidgetExt;
+
+mod imp {
+ use super::*;
+ use glib::subclass;
use gtk::subclass::prelude::*;
use gtk::subclass::widget::*;
use gtk::WidgetExt;
/// The private struct, which can hold widgets and other data.
#[derive(Debug, CompositeTemplate)]
-pub struct ExApplicationWindowPriv {
+ pub struct ExApplicationWindow {
// The #[template_child] attribute tells the CompositeTemplate macro
// that a field is meant to be a child within the template.
#[template_child(id = "headerbar")]
- headerbar: TemplateChild<gtk::HeaderBar>,
+ pub headerbar: TemplateChild<gtk::HeaderBar>,
#[template_child(id = "label")]
- label: TemplateChild<gtk::Label>,
+ pub label: TemplateChild<gtk::Label>,
#[template_child(id = "subtitle_label")]
- subtitle: TemplateChild<gtk::Label>,
+ pub subtitle: TemplateChild<gtk::Label>,
}
-impl ObjectSubclass for ExApplicationWindowPriv {
+ impl ObjectSubclass for ExApplicationWindow {
const NAME: &'static str = "ExApplicationWindow";
- type Type = ExApplicationWindow;
+ type Type = super::ExApplicationWindow;
type ParentType = gtk::ApplicationWindow;
type Instance = subclass::simple::InstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
@@ -57,19 +61,21 @@ impl ObjectSubclass for ExApplicationWindowPriv {
}
}
-impl ObjectImpl for ExApplicationWindowPriv {
+ impl ObjectImpl for ExApplicationWindow {
fn constructed(&self, obj: &Self::Type) {
obj.init_template();
obj.init_label();
self.parent_constructed(obj);
}
}
-impl WidgetImpl for ExApplicationWindowPriv {}
-impl WindowImpl for ExApplicationWindowPriv {}
-impl ApplicationWindowImpl for ExApplicationWindowPriv {}
+
+ impl WidgetImpl for ExApplicationWindow {}
+ impl WindowImpl for ExApplicationWindow {}
+ impl ApplicationWindowImpl for ExApplicationWindow {}
+}
glib_wrapper! {
- pub struct ExApplicationWindow(ObjectSubclass<ExApplicationWindowPriv>)
+ pub struct ExApplicationWindow(ObjectSubclass<imp::ExApplicationWindow>)
@extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, @implements gio::ActionMap, gio::ActionGroup;
}
@@ -84,7 +90,7 @@ impl ExApplicationWindow {
pub fn init_label(&self) {
// To access fields such as template children, you must get
// the private struct.
- let self_ = ExApplicationWindowPriv::from_instance(self);
+ let self_ = imp::ExApplicationWindow::from_instance(self);
self_
.subtitle
.get()
