rust_macios/appkit/
ns_layout_constraint.rs

1use objc::{msg_send, sel, sel_impl};
2
3use crate::{
4    foundation::NSArray,
5    object,
6    objective_c_runtime::{macros::interface_impl, traits::PNSObject},
7};
8
9object! {
10    /// The relationship between two user interface objects that must be satisfied by the constraint-based layout system.
11    unsafe pub struct NSLayoutConstraint;
12}
13
14#[interface_impl(NSObject)]
15impl NSLayoutConstraint {
16    /* Activating and Deactivating Constraints
17     */
18
19    /// The active state of the constraint.
20    #[property]
21    pub fn active(&self) -> bool {
22        unsafe { msg_send![self.m_self(), isActive] }
23    }
24
25    /// Sets the active state of the constraint.
26    ///
27    /// # Arguments
28    ///
29    /// * `active` - The active state of the constraint.
30    #[property]
31    pub fn set_active(&self, active: bool) {
32        unsafe { msg_send![self.m_self(), setActive: active] }
33    }
34
35    /// Activates each constraint in the specified array.
36    ///
37    /// # Arguments
38    ///
39    /// * `constraints` - The array of constraints to activate.
40    #[method]
41    pub fn activate_constraints(constraints: NSArray<NSLayoutConstraint>) {
42        unsafe { msg_send![Self::m_class(), activateConstraints: constraints] }
43    }
44
45    /// Deactivates each constraint in the specified array.
46    ///
47    /// # Arguments
48    ///
49    /// * `constraints` - The array of constraints to deactivate.
50    #[method]
51    pub fn deactivate_constraints(constraints: NSArray<NSLayoutConstraint>) {
52        unsafe { msg_send![Self::m_class(), deactivateConstraints: constraints] }
53    }
54}