libadwaita/auto/breakpoint_condition.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files.git)
4// DO NOT EDIT
5
6use crate::{BreakpointConditionLengthType, BreakpointConditionRatioType, LengthUnit, ffi};
7use glib::translate::*;
8
9glib::wrapper! {
10 /// Describes condition for an [`Breakpoint`][crate::Breakpoint].
11 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
12 pub struct BreakpointCondition(Boxed<ffi::AdwBreakpointCondition>);
13
14 match fn {
15 copy => |ptr| ffi::adw_breakpoint_condition_copy(mut_override(ptr)),
16 free => |ptr| ffi::adw_breakpoint_condition_free(ptr),
17 type_ => || ffi::adw_breakpoint_condition_get_type(),
18 }
19}
20
21impl BreakpointCondition {
22 /// Creates a condition that triggers when @condition_1 and @condition_2 are both
23 /// true.
24 /// ## `condition_1`
25 /// first condition
26 /// ## `condition_2`
27 /// second condition
28 ///
29 /// # Returns
30 ///
31 /// the newly created condition
32 #[doc(alias = "adw_breakpoint_condition_new_and")]
33 pub fn new_and(
34 condition_1: BreakpointCondition,
35 condition_2: BreakpointCondition,
36 ) -> BreakpointCondition {
37 assert_initialized_main_thread!();
38 unsafe {
39 from_glib_full(ffi::adw_breakpoint_condition_new_and(
40 condition_1.into_glib_ptr(),
41 condition_2.into_glib_ptr(),
42 ))
43 }
44 }
45
46 /// Creates a condition that triggers on length changes.
47 /// ## `type_`
48 /// the length type
49 /// ## `value`
50 /// the length value
51 /// ## `unit`
52 /// the length unit
53 ///
54 /// # Returns
55 ///
56 /// the newly created condition
57 #[doc(alias = "adw_breakpoint_condition_new_length")]
58 pub fn new_length(
59 type_: BreakpointConditionLengthType,
60 value: f64,
61 unit: LengthUnit,
62 ) -> BreakpointCondition {
63 assert_initialized_main_thread!();
64 unsafe {
65 from_glib_full(ffi::adw_breakpoint_condition_new_length(
66 type_.into_glib(),
67 value,
68 unit.into_glib(),
69 ))
70 }
71 }
72
73 /// Creates a condition that triggers when either @condition_1 or @condition_2 is
74 /// true.
75 /// ## `condition_1`
76 /// first condition
77 /// ## `condition_2`
78 /// second condition
79 ///
80 /// # Returns
81 ///
82 /// the newly created condition
83 #[doc(alias = "adw_breakpoint_condition_new_or")]
84 pub fn new_or(
85 condition_1: BreakpointCondition,
86 condition_2: BreakpointCondition,
87 ) -> BreakpointCondition {
88 assert_initialized_main_thread!();
89 unsafe {
90 from_glib_full(ffi::adw_breakpoint_condition_new_or(
91 condition_1.into_glib_ptr(),
92 condition_2.into_glib_ptr(),
93 ))
94 }
95 }
96
97 /// Creates a condition that triggers on ratio changes.
98 ///
99 /// The ratio is represented as @width divided by @height.
100 /// ## `type_`
101 /// the ratio type
102 /// ## `width`
103 /// ratio width
104 /// ## `height`
105 /// ratio height
106 ///
107 /// # Returns
108 ///
109 /// the newly created condition
110 #[doc(alias = "adw_breakpoint_condition_new_ratio")]
111 pub fn new_ratio(
112 type_: BreakpointConditionRatioType,
113 width: i32,
114 height: i32,
115 ) -> BreakpointCondition {
116 assert_initialized_main_thread!();
117 unsafe {
118 from_glib_full(ffi::adw_breakpoint_condition_new_ratio(
119 type_.into_glib(),
120 width,
121 height,
122 ))
123 }
124 }
125
126 /// Returns a textual representation of @self.
127 ///
128 /// The returned string can be parsed by `parse()`.
129 ///
130 /// # Returns
131 ///
132 /// A newly allocated text string
133 #[doc(alias = "adw_breakpoint_condition_to_string")]
134 #[doc(alias = "to_string")]
135 pub fn to_str(&self) -> glib::GString {
136 unsafe {
137 from_glib_full(ffi::adw_breakpoint_condition_to_string(mut_override(
138 self.to_glib_none().0,
139 )))
140 }
141 }
142
143 /// `s is true, same as when using
144 /// `BreakpointCondition::new_or()`
145 ///
146 /// Examples:
147 ///
148 /// - `min-width: 400px and max-aspect-ratio: 4/3`
149 /// - `max-width: 360sp or max-width: 360px`
150 ///
151 /// Conditions can be further nested using parentheses, for example:
152 ///
153 /// - `min-width: 400px and (max-aspect-ratio: 4/3 or max-height: 400px)`
154 ///
155 /// If parentheses are omitted, the first operator takes priority.
156 /// ## `str`
157 /// the string specifying the condition
158 ///
159 /// # Returns
160 ///
161 /// the parsed condition
162 #[doc(alias = "adw_breakpoint_condition_parse")]
163 pub fn parse(str: &str) -> Result<BreakpointCondition, glib::BoolError> {
164 assert_initialized_main_thread!();
165 unsafe {
166 Option::<_>::from_glib_full(ffi::adw_breakpoint_condition_parse(str.to_glib_none().0))
167 .ok_or_else(|| glib::bool_error!("Invalid condition"))
168 }
169 }
170}
171
172impl std::fmt::Display for BreakpointCondition {
173 #[inline]
174 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
175 f.write_str(&self.to_str())
176 }
177}