fractal/utils/
template_callbacks.rs1use gtk::glib;
4
5pub struct TemplateCallbacks {}
7
8#[gtk::template_callbacks(functions)]
9impl TemplateCallbacks {
10 #[template_callback]
12 pub fn string_not_empty(string: Option<&str>) -> bool {
13 !string.unwrap_or_default().is_empty()
14 }
15
16 #[template_callback]
18 pub fn unwrap_string_or_empty(string: Option<&str>) -> &str {
19 string.unwrap_or_default()
20 }
21
22 #[template_callback]
24 pub fn object_is_some(obj: Option<&glib::Object>) -> bool {
25 obj.is_some()
26 }
27
28 #[template_callback]
30 pub fn invert_boolean(boolean: bool) -> bool {
31 !boolean
32 }
33
34 #[template_callback]
36 pub fn guint_is_zero(u: u32) -> bool {
37 u == 0
38 }
39
40 #[template_callback]
42 pub fn logical_and(lhs: bool, rhs: bool) -> bool {
43 lhs && rhs
44 }
45
46 #[template_callback]
48 pub fn logical_or(lhs: bool, rhs: bool) -> bool {
49 lhs || rhs
50 }
51
52 #[template_callback]
55 pub fn ternary_string(test: bool, positive: String, negative: String) -> String {
56 if test { positive } else { negative }
57 }
58}