libadwaita/auto/breakpoint_condition.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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT
use crate::{ffi, BreakpointConditionLengthType, BreakpointConditionRatioType, LengthUnit};
use glib::translate::*;
glib::wrapper! {
/// Describes condition for an [`Breakpoint`][crate::Breakpoint].
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct BreakpointCondition(Boxed<ffi::AdwBreakpointCondition>);
match fn {
copy => |ptr| ffi::adw_breakpoint_condition_copy(mut_override(ptr)),
free => |ptr| ffi::adw_breakpoint_condition_free(ptr),
type_ => || ffi::adw_breakpoint_condition_get_type(),
}
}
impl BreakpointCondition {
/// Creates a condition that triggers when @condition_1 and @condition_2 are both
/// true.
/// ## `condition_1`
/// first condition
/// ## `condition_2`
/// second condition
///
/// # Returns
///
/// the newly created condition
#[doc(alias = "adw_breakpoint_condition_new_and")]
pub fn new_and(
condition_1: BreakpointCondition,
condition_2: BreakpointCondition,
) -> BreakpointCondition {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::adw_breakpoint_condition_new_and(
condition_1.into_glib_ptr(),
condition_2.into_glib_ptr(),
))
}
}
/// Creates a condition that triggers on length changes.
/// ## `type_`
/// the length type
/// ## `value`
/// the length value
/// ## `unit`
/// the length unit
///
/// # Returns
///
/// the newly created condition
#[doc(alias = "adw_breakpoint_condition_new_length")]
pub fn new_length(
type_: BreakpointConditionLengthType,
value: f64,
unit: LengthUnit,
) -> BreakpointCondition {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::adw_breakpoint_condition_new_length(
type_.into_glib(),
value,
unit.into_glib(),
))
}
}
/// Creates a condition that triggers when either @condition_1 or @condition_2 is
/// true.
/// ## `condition_1`
/// first condition
/// ## `condition_2`
/// second condition
///
/// # Returns
///
/// the newly created condition
#[doc(alias = "adw_breakpoint_condition_new_or")]
pub fn new_or(
condition_1: BreakpointCondition,
condition_2: BreakpointCondition,
) -> BreakpointCondition {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::adw_breakpoint_condition_new_or(
condition_1.into_glib_ptr(),
condition_2.into_glib_ptr(),
))
}
}
/// Creates a condition that triggers on ratio changes.
///
/// The ratio is represented as @width divided by @height.
/// ## `type_`
/// the ratio type
/// ## `width`
/// ratio width
/// ## `height`
/// ratio height
///
/// # Returns
///
/// the newly created condition
#[doc(alias = "adw_breakpoint_condition_new_ratio")]
pub fn new_ratio(
type_: BreakpointConditionRatioType,
width: i32,
height: i32,
) -> BreakpointCondition {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::adw_breakpoint_condition_new_ratio(
type_.into_glib(),
width,
height,
))
}
}
/// Returns a textual representation of @self.
///
/// The returned string can be parsed by `parse()`.
///
/// # Returns
///
/// A newly allocated text string
#[doc(alias = "adw_breakpoint_condition_to_string")]
#[doc(alias = "to_string")]
pub fn to_str(&self) -> glib::GString {
unsafe {
from_glib_full(ffi::adw_breakpoint_condition_to_string(mut_override(
self.to_glib_none().0,
)))
}
}
/// Parses a condition from a string.
///
/// Length conditions are specified as `<type>: <value>[<unit>]`, where:
///
/// - `<type>` can be `min-width`, `max-width`, `min-height` or `max-height`
/// - `<value>` is a fractional number
/// - `<unit>` can be `px`, `pt` or `sp`
///
/// If the unit is omitted, `px` is assumed.
///
/// See `BreakpointCondition::new_length()`.
///
/// Examples:
///
/// - `min-width: 500px`
/// - `min-height: 400pt`
/// - `max-width: 100sp`
/// - `max-height: 500`
///
/// Ratio conditions are specified as `<type>: <width>[/<height>]`, where:
///
/// - `<type>` can be `min-aspect-ratio` or `max-aspect-ratio`
/// - `<width>` and `<height>` are integer numbers
///
/// See `BreakpointCondition::new_ratio()`.
///
/// The ratio is represented as `<width>` divided by `<height>`.
///
/// If `<height>` is omitted, it's assumed to be 1.
///
/// Examples:
///
/// - `min-aspect-ratio: 4/3`
/// - `max-aspect-ratio: 1`
///
/// The logical operators `and`, `or` can be used to compose a complex condition
/// as follows:
///
/// - `<condition> and <condition>`: the condition is true when both
/// `<condition>`s are true, same as when using
/// `BreakpointCondition::new_and()`
/// - `<condition> or <condition>`: the condition is true when either of the
/// `<condition>`s is true, same as when using
/// `BreakpointCondition::new_or()`
///
/// Examples:
///
/// - `min-width: 400px and max-aspect-ratio: 4/3`
/// - `max-width: 360sp or max-width: 360px`
///
/// Conditions can be further nested using parentheses, for example:
///
/// - `min-width: 400px and (max-aspect-ratio: 4/3 or max-height: 400px)`
///
/// If parentheses are omitted, the first operator takes priority.
/// ## `str`
/// the string specifying the condition
///
/// # Returns
///
/// the parsed condition
#[doc(alias = "adw_breakpoint_condition_parse")]
pub fn parse(str: &str) -> Result<BreakpointCondition, glib::BoolError> {
assert_initialized_main_thread!();
unsafe {
Option::<_>::from_glib_full(ffi::adw_breakpoint_condition_parse(str.to_glib_none().0))
.ok_or_else(|| glib::bool_error!("Invalid condition"))
}
}
}
impl std::fmt::Display for BreakpointCondition {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(&self.to_str())
}
}