// Take a look at the license at the top of the repository in the LICENSE file.
use gtk::{glib, prelude::*, subclass::prelude::*};
mod imp {
use super::*;
#[derive(Debug, Default, gtk::CompositeTemplate)]
#[template(string = r#"
"#)]
pub struct MyWidget {
#[template_child]
pub label: TemplateChild,
#[template_child(id = "my_label2")]
pub label2: gtk::TemplateChild,
}
#[glib::object_subclass]
impl ObjectSubclass for MyWidget {
const NAME: &'static str = "MyWidget";
type Type = super::MyWidget;
type ParentType = gtk::Widget;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject) {
obj.init_template();
}
}
impl ObjectImpl for MyWidget {
fn dispose(&self) {
while let Some(child) = self.obj().first_child() {
child.unparent();
}
}
}
impl WidgetImpl for MyWidget {}
}
glib::wrapper! {
pub struct MyWidget(ObjectSubclass) @extends gtk::Widget;
}
#[gtk::test]
fn template_string() {
let widget: MyWidget = glib::Object::new();
assert_eq!(widget.imp().label.label(), "foobar");
assert_eq!(widget.imp().label2.label(), "foobaz");
}
mod imp2 {
use std::cell::RefCell;
use futures_channel::mpsc;
use super::*;
#[derive(Debug, gtk::CompositeTemplate)]
#[template(string = r#"
"#)]
pub struct MyWidget2 {
#[template_child]
button: TemplateChild,
tx: RefCell>,
rx: RefCell