This repository has been archived by the owner on Jun 8, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
tool_button.rs
158 lines (126 loc) · 4.72 KB
/
tool_button.rs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// This file was generated by gir (b7f5189) from gir-files (71d73f0)
// DO NOT EDIT
use Actionable;
use Bin;
use Container;
use Object;
use ToolItem;
use Widget;
use ffi;
use glib::object::Downcast;
use glib::object::IsA;
use glib::signal::connect;
use glib::translate::*;
use glib_ffi;
use std::boxed::Box as Box_;
use std::mem::transmute;
glib_wrapper! {
pub struct ToolButton(Object<ffi::GtkToolButton>): ToolItem, Bin, Container, Widget, Actionable;
match fn {
get_type => || ffi::gtk_tool_button_get_type(),
}
}
impl ToolButton {
pub fn new<'a, T: IsA<Widget>, U: Into<Option<&'a str>>>(icon_widget: Option<&T>, label: U) -> ToolButton {
assert_initialized_main_thread!();
unsafe {
ToolItem::from_glib_none(ffi::gtk_tool_button_new(icon_widget.to_glib_none().0, label.into().to_glib_none().0)).downcast_unchecked()
}
}
pub fn new_from_stock(stock_id: &str) -> ToolButton {
assert_initialized_main_thread!();
unsafe {
ToolItem::from_glib_none(ffi::gtk_tool_button_new_from_stock(stock_id.to_glib_none().0)).downcast_unchecked()
}
}
}
pub trait ToolButtonExt {
fn get_icon_name(&self) -> Option<String>;
fn get_icon_widget(&self) -> Option<Widget>;
fn get_label(&self) -> Option<String>;
fn get_label_widget(&self) -> Option<Widget>;
fn get_stock_id(&self) -> Option<String>;
fn get_use_underline(&self) -> bool;
fn set_icon_name<'a, T: Into<Option<&'a str>>>(&self, icon_name: T);
fn set_icon_widget<T: IsA<Widget>>(&self, icon_widget: Option<&T>);
fn set_label<'a, T: Into<Option<&'a str>>>(&self, label: T);
fn set_label_widget<T: IsA<Widget>>(&self, label_widget: Option<&T>);
fn set_stock_id<'a, T: Into<Option<&'a str>>>(&self, stock_id: T);
fn set_use_underline(&self, use_underline: bool);
fn connect_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> u64;
}
impl<O: IsA<ToolButton> + IsA<Object>> ToolButtonExt for O {
fn get_icon_name(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gtk_tool_button_get_icon_name(self.to_glib_none().0))
}
}
fn get_icon_widget(&self) -> Option<Widget> {
unsafe {
from_glib_none(ffi::gtk_tool_button_get_icon_widget(self.to_glib_none().0))
}
}
fn get_label(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gtk_tool_button_get_label(self.to_glib_none().0))
}
}
fn get_label_widget(&self) -> Option<Widget> {
unsafe {
from_glib_none(ffi::gtk_tool_button_get_label_widget(self.to_glib_none().0))
}
}
fn get_stock_id(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gtk_tool_button_get_stock_id(self.to_glib_none().0))
}
}
fn get_use_underline(&self) -> bool {
unsafe {
from_glib(ffi::gtk_tool_button_get_use_underline(self.to_glib_none().0))
}
}
fn set_icon_name<'a, T: Into<Option<&'a str>>>(&self, icon_name: T) {
unsafe {
ffi::gtk_tool_button_set_icon_name(self.to_glib_none().0, icon_name.into().to_glib_none().0);
}
}
fn set_icon_widget<T: IsA<Widget>>(&self, icon_widget: Option<&T>) {
unsafe {
ffi::gtk_tool_button_set_icon_widget(self.to_glib_none().0, icon_widget.to_glib_none().0);
}
}
fn set_label<'a, T: Into<Option<&'a str>>>(&self, label: T) {
unsafe {
ffi::gtk_tool_button_set_label(self.to_glib_none().0, label.into().to_glib_none().0);
}
}
fn set_label_widget<T: IsA<Widget>>(&self, label_widget: Option<&T>) {
unsafe {
ffi::gtk_tool_button_set_label_widget(self.to_glib_none().0, label_widget.to_glib_none().0);
}
}
fn set_stock_id<'a, T: Into<Option<&'a str>>>(&self, stock_id: T) {
unsafe {
ffi::gtk_tool_button_set_stock_id(self.to_glib_none().0, stock_id.into().to_glib_none().0);
}
}
fn set_use_underline(&self, use_underline: bool) {
unsafe {
ffi::gtk_tool_button_set_use_underline(self.to_glib_none().0, use_underline.to_glib());
}
}
fn connect_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> u64 {
unsafe {
let f: Box_<Box_<Fn(&Self) + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "clicked",
transmute(clicked_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
}
}
}
unsafe extern "C" fn clicked_trampoline<T>(this: *mut ffi::GtkToolButton, f: glib_ffi::gpointer)
where T: IsA<ToolButton> {
callback_guard!();
let f: &Box_<Fn(&T) + 'static> = transmute(f);
f(&ToolButton::from_glib_none(this).downcast_unchecked())
}