-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathcode.rs
More file actions
66 lines (53 loc) · 1.64 KB
/
code.rs
File metadata and controls
66 lines (53 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::workbench;
use gtk::{glib, subclass::prelude::*};
mod imp {
use super::*;
#[derive(Debug, Default, gtk::CompositeTemplate)]
// The file will be provided by Workbench when the demo compiles, it just contains the template.
#[template(file = "workbench_template.ui")]
pub struct AwesomeButton {}
#[glib::object_subclass]
impl ObjectSubclass for AwesomeButton {
const NAME: &'static str = "AwesomeButton";
type Type = super::AwesomeButton;
type ParentType = gtk::Button;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
#[gtk::template_callbacks]
impl AwesomeButton {
#[template_callback]
fn onclicked(_button: >k::Button) {
println!("Clicked")
}
}
impl ObjectImpl for AwesomeButton {}
impl WidgetImpl for AwesomeButton {}
impl ButtonImpl for AwesomeButton {}
}
glib::wrapper! {
pub struct AwesomeButton(ObjectSubclass<imp::AwesomeButton>) @extends gtk::Widget, gtk::Button;
}
impl AwesomeButton {
pub fn new() -> Self {
glib::Object::new()
}
}
pub fn main() {
gtk::init().unwrap();
let container = gtk::ScrolledWindow::new();
let flow_box = gtk::FlowBox::builder().hexpand(true).build();
container.set_child(&flow_box);
let mut widgets = Vec::with_capacity(100);
for _ in 0..100 {
widgets.push(AwesomeButton::new());
}
for widget in &widgets {
flow_box.append(widget);
}
workbench::preview(&container)
}