rute 0.0.6

UI library implemented on top of Qt
Documentation
// This file is auto-generated by rute_gen. DO NOT EDIT.
use std::cell::Cell;
use std::rc::Rc;

#[allow(unused_imports)]
use std::marker::PhantomData;

#[allow(unused_imports)]
use std::os::raw::c_void;

#[allow(unused_imports)]
use std::mem::transmute;

#[allow(unused_imports)]
use std::ffi::{CStr, CString};

use rute_ffi_base::*;

#[allow(unused_imports)]
use auto::*;

/// **Notice these docs are heavy WIP and not very relevent yet**
///
/// The size policy of a widget is an expression of its willingness to
/// be resized in various ways, and affects how the widget is treated
/// by the [layout engine](Layout%20Management)
/// . Each widget returns a
/// QSizePolicy that describes the horizontal and vertical resizing
/// policy it prefers when being laid out. You can change this for
/// a specific widget by changing its QWidget::sizePolicy property.
///
/// QSizePolicy contains two independent QSizePolicy::Policy values
/// and two stretch factors; one describes the widgets's horizontal
/// size policy, and the other describes its vertical size policy. It
/// also contains a flag to indicate whether the height and width of
/// its preferred size are related.
///
/// The horizontal and vertical policies can be set in the
/// constructor, and altered using the setHorizontalPolicy() and
/// setVerticalPolicy() functions. The stretch factors can be set
/// using the setHorizontalStretch() and setVerticalStretch()
/// functions. The flag indicating whether the widget's
/// [sizeHint()](QWidget::sizeHint())
/// is width-dependent (such as a
/// menu bar or a word-wrapping label) can be set using the
/// setHeightForWidth() function.
///
/// The current size policies and stretch factors be retrieved using
/// the horizontalPolicy(), verticalPolicy(), horizontalStretch() and
/// verticalStretch() functions. Alternatively, use the transpose()
/// function to swap the horizontal and vertical policies and
/// stretches. The hasHeightForWidth() function returns the current
/// status of the flag indicating the size hint dependencies.
///
/// Use the expandingDirections() function to determine whether the
/// associated widget can make use of more space than its
/// [sizeHint()](QWidget::sizeHint())
/// function indicates, as well as
/// find out in which directions it can expand.
///
/// Finally, the QSizePolicy class provides operators comparing this
/// size policy to a given policy, as well as a QVariant operator
/// storing this QSizePolicy as a QVariant object.
///
/// **See also:** [`Size`]
/// [`Widget::size_hint`]
/// [`Widget::size_policy()`]
/// [`LayoutItem::size_hint`]
/// # Licence
///
/// The documentation is an adoption of the original [Qt Documentation](http://doc.qt.io/) and provided herein is licensed under the terms of the [GNU Free Documentation License version 1.3](http://www.gnu.org/licenses/fdl.html) as published by the Free Software Foundation.
#[derive(Clone)]
pub struct SizePolicy<'a> {
    #[doc(hidden)]
    pub data: Rc<Cell<Option<*const RUBase>>>,
    #[doc(hidden)]
    pub all_funcs: *const RUSizePolicyAllFuncs,
    #[doc(hidden)]
    pub owned: bool,
    #[doc(hidden)]
    pub _marker: PhantomData<::std::cell::Cell<&'a ()>>,
}

impl<'a> SizePolicy<'a> {
    pub fn new() -> SizePolicy<'a> {
        let data = Rc::new(Cell::new(None));

        let ffi_data = unsafe {
            ((*rute_ffi_get()).create_size_policy)(
                ::std::ptr::null(),
                transmute(rute_object_delete_callback as usize),
                Rc::into_raw(data.clone()) as *const c_void,
            )
        };

        data.set(Some(ffi_data.qt_data));

        SizePolicy {
            data,
            all_funcs: ffi_data.all_funcs,
            owned: true,
            _marker: PhantomData,
        }
    }
    #[allow(dead_code)]
    pub(crate) fn new_from_rc(ffi_data: RUSizePolicy) -> SizePolicy<'a> {
        SizePolicy {
            data: unsafe { Rc::from_raw(ffi_data.host_data as *const Cell<Option<*const RUBase>>) },
            all_funcs: ffi_data.all_funcs,
            owned: false,
            _marker: PhantomData,
        }
    }

    #[allow(dead_code)]
    pub(crate) fn new_from_owned(ffi_data: RUSizePolicy) -> SizePolicy<'a> {
        SizePolicy {
            data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
            all_funcs: ffi_data.all_funcs,
            owned: true,
            _marker: PhantomData,
        }
    }

    #[allow(dead_code)]
    pub(crate) fn new_from_temporary(ffi_data: RUSizePolicy) -> SizePolicy<'a> {
        SizePolicy {
            data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
            all_funcs: ffi_data.all_funcs,
            owned: false,
            _marker: PhantomData,
        }
    }
    ///
    /// Returns the horizontal component of the size policy.
    ///
    /// **See also:** [`set_horizontal_policy()`]
    /// [`vertical_policy()`]
    /// [`horizontal_stretch()`]
    pub fn horizontal_policy(&self) -> Policy {
        let (obj_data, funcs) = self.get_size_policy_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).horizontal_policy)(obj_data);
            let ret_val = { transmute::<u32, Policy>(ret_val) };
            ret_val
        }
    }
    ///
    /// Returns the vertical component of the size policy.
    ///
    /// **See also:** [`set_vertical_policy()`]
    /// [`horizontal_policy()`]
    /// [`vertical_stretch()`]
    pub fn vertical_policy(&self) -> Policy {
        let (obj_data, funcs) = self.get_size_policy_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).vertical_policy)(obj_data);
            let ret_val = { transmute::<u32, Policy>(ret_val) };
            ret_val
        }
    }
    ///
    /// Sets the horizontal component to the given *policy.*
    ///
    /// **See also:** [`horizontal_policy()`]
    /// [`set_vertical_policy()`]
    /// [`set_horizontal_stretch()`]
    pub fn set_horizontal_policy(&self, d: Policy) -> &Self {
        let enum_d_1 = d as u32;

        let (obj_data, funcs) = self.get_size_policy_obj_funcs();
        unsafe {
            ((*funcs).set_horizontal_policy)(obj_data, enum_d_1);
        }
        self
    }
    ///
    /// Sets the vertical component to the given *policy.*
    ///
    /// **See also:** [`vertical_policy()`]
    /// [`set_horizontal_policy()`]
    /// [`set_vertical_stretch()`]
    pub fn set_vertical_policy(&self, d: Policy) -> &Self {
        let enum_d_1 = d as u32;

        let (obj_data, funcs) = self.get_size_policy_obj_funcs();
        unsafe {
            ((*funcs).set_vertical_policy)(obj_data, enum_d_1);
        }
        self
    }
    ///
    /// Returns whether a widget can make use of more space than the
    /// QWidget::sizeHint() function indicates.
    ///
    /// A value of Qt::Horizontal or Qt::Vertical means that the widget
    /// can grow horizontally or vertically (i.e., the horizontal or
    /// vertical policy is [Expanding](Expanding)
    /// or [MinimumExpanding),](MinimumExpanding),)
    /// whereas
    /// Qt::Horizontal | Qt::Vertical means that it can grow in both
    /// dimensions.
    ///
    /// **See also:** [`horizontal_policy()`]
    /// [`vertical_policy()`]
    pub fn expanding_directions(&self) -> Orientations {
        let (obj_data, funcs) = self.get_size_policy_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).expanding_directions)(obj_data);
            let ret_val = Orientations::from_bits_truncate(ret_val);
            ret_val
        }
    }
    ///
    /// Sets the flag determining whether the widget's preferred height
    /// depends on its width, to *dependent.*
    ///
    /// **See also:** [`has_height_for_width()`]
    /// [`set_width_for_height()`]
    pub fn set_height_for_width(&self, b: bool) -> &Self {
        let (obj_data, funcs) = self.get_size_policy_obj_funcs();
        unsafe {
            ((*funcs).set_height_for_width)(obj_data, b);
        }
        self
    }
    ///
    /// Returns `true` if the widget's preferred height depends on its
    /// width; otherwise returns `false.`
    ///
    /// **See also:** [`set_height_for_width()`]
    pub fn has_height_for_width(&self) -> bool {
        let (obj_data, funcs) = self.get_size_policy_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).has_height_for_width)(obj_data);
            ret_val
        }
    }
    ///
    /// Sets the flag determining whether the widget's width
    /// depends on its height, to *dependent.*
    ///
    /// This is only supported for QGraphicsLayout's subclasses.
    /// It is not possible to have a layout with both height-for-width
    /// and width-for-height constraints at the same time.
    ///
    /// **See also:** [`has_width_for_height()`]
    /// [`set_height_for_width()`]
    pub fn set_width_for_height(&self, b: bool) -> &Self {
        let (obj_data, funcs) = self.get_size_policy_obj_funcs();
        unsafe {
            ((*funcs).set_width_for_height)(obj_data, b);
        }
        self
    }
    ///
    /// Returns `true` if the widget's width depends on its
    /// height; otherwise returns `false.`
    ///
    /// **See also:** [`set_width_for_height()`]
    pub fn has_width_for_height(&self) -> bool {
        let (obj_data, funcs) = self.get_size_policy_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).has_width_for_height)(obj_data);
            ret_val
        }
    }
    ///
    /// Returns whether the layout should retain the widget's size when it is hidden.
    /// This is `false` by default.
    ///
    /// **See also:** [`set_retain_size_when_hidden()`]
    pub fn retain_size_when_hidden(&self) -> bool {
        let (obj_data, funcs) = self.get_size_policy_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).retain_size_when_hidden)(obj_data);
            ret_val
        }
    }
    ///
    /// Sets whether a layout should retain the widget's size when it is hidden.
    /// If *retainSize* is `true,` the layout will not be changed by hiding the widget.
    ///
    /// **See also:** [`retain_size_when_hidden()`]
    pub fn set_retain_size_when_hidden(&self, retain_size: bool) -> &Self {
        let (obj_data, funcs) = self.get_size_policy_obj_funcs();
        unsafe {
            ((*funcs).set_retain_size_when_hidden)(obj_data, retain_size);
        }
        self
    }

    pub fn build(&self) -> Self {
        self.clone()
    }
}
pub trait SizePolicyTrait<'a> {
    #[inline]
    #[doc(hidden)]
    fn get_size_policy_obj_funcs(&self) -> (*const RUBase, *const RUSizePolicyFuncs);
}

impl<'a> SizePolicyTrait<'a> for SizePolicy<'a> {
    #[doc(hidden)]
    fn get_size_policy_obj_funcs(&self) -> (*const RUBase, *const RUSizePolicyFuncs) {
        let obj = self.data.get().unwrap();
        unsafe { (obj, (*self.all_funcs).size_policy_funcs) }
    }
}
bitflags! {
    pub struct PolicyFlag: u32 {
        const GrowFlag = 0x1;
        const ExpandFlag = 0x2;
        const ShrinkFlag = 0x4;
        const IgnoreFlag = 0x8;
    }
}

#[repr(u32)]
pub enum Policy {
    Fixed = 0,
    Minimum = 1,
    Maximum = 4,
    Preferred = 5,
    MinimumExpanding = 3,
    Expanding = 7,
    Ignored = 13,
}

bitflags! {
    pub struct ControlType: u32 {
        const DefaultType = 0x1;
        const ButtonBox = 0x2;
        const CheckBox = 0x4;
        const ComboBox = 0x8;
        const Frame = 0x10;
        const GroupBox = 0x20;
        const Label = 0x40;
        const Line = 0x80;
        const LineEdit = 0x100;
        const PushButton = 0x200;
        const RadioButton = 0x400;
        const Slider = 0x800;
        const SpinBox = 0x1000;
        const TabWidget = 0x2000;
        const ToolButton = 0x4000;
    }
}

pub type ControlTypes = ControlType;