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 /// Parses a condition from a string.
144 ///
145 /// Length conditions are specified as `<type>: <value>[<unit>]`, where:
146 ///
147 /// - `<type>` can be `min-width`, `max-width`, `min-height` or `max-height`
148 /// - `<value>` is a fractional number
149 /// - `<unit>` can be `px`, `pt` or `sp`
150 ///
151 /// If the unit is omitted, `px` is assumed.
152 ///
153 /// See `BreakpointCondition::new_length()`.
154 ///
155 /// Examples:
156 ///
157 /// - `min-width: 500px`
158 /// - `min-height: 400pt`
159 /// - `max-width: 100sp`
160 /// - `max-height: 500`
161 ///
162 /// Ratio conditions are specified as `<type>: <width>[/<height>]`, where:
163 ///
164 /// - `<type>` can be `min-aspect-ratio` or `max-aspect-ratio`
165 /// - `<width>` and `<height>` are integer numbers
166 ///
167 /// See `BreakpointCondition::new_ratio()`.
168 ///
169 /// The ratio is represented as `<width>` divided by `<height>`.
170 ///
171 /// If `<height>` is omitted, it's assumed to be 1.
172 ///
173 /// Examples:
174 ///
175 /// - `min-aspect-ratio: 4/3`
176 /// - `max-aspect-ratio: 1`
177 ///
178 /// The logical operators `and`, `or` can be used to compose a complex condition
179 /// as follows:
180 ///
181 /// - `<condition> and <condition>`: the condition is true when both
182 /// `<condition>`s are true, same as when using
183 /// `BreakpointCondition::new_and()`
184 /// - `<condition> or <condition>`: the condition is true when either of the
185 /// `<condition>`s is true, same as when using
186 /// `BreakpointCondition::new_or()`
187 ///
188 /// Examples:
189 ///
190 /// - `min-width: 400px and max-aspect-ratio: 4/3`
191 /// - `max-width: 360sp or max-width: 360px`
192 ///
193 /// Conditions can be further nested using parentheses, for example:
194 ///
195 /// - `min-width: 400px and (max-aspect-ratio: 4/3 or max-height: 400px)`
196 ///
197 /// If parentheses are omitted, the first operator takes priority.
198 /// ## `str`
199 /// the string specifying the condition
200 ///
201 /// # Returns
202 ///
203 /// the parsed condition
204 #[doc(alias = "adw_breakpoint_condition_parse")]
205 pub fn parse(str: &str) -> Result<BreakpointCondition, glib::BoolError> {
206 assert_initialized_main_thread!();
207 unsafe {
208 Option::<_>::from_glib_full(ffi::adw_breakpoint_condition_parse(str.to_glib_none().0))
209 .ok_or_else(|| glib::bool_error!("Invalid condition"))
210 }
211 }
212}
213
214impl std::fmt::Display for BreakpointCondition {
215 #[inline]
216 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
217 f.write_str(&self.to_str())
218 }
219}