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
// SPDX-License-Identifier: MPL-2.0
//! A labeled container around a child control.
use crate::prelude::*;
impl Ui {
/// Creates a new [`Group`] with the given title.
pub fn create_group<'ui>(
&'ui self,
title: impl Into<Vec<u8>>,
) -> Result<&'ui mut Group, crate::Error> {
let title = self.make_cstring(title)?;
unsafe { call_libui_new_fn!(ui: self, fn: uiNewGroup(title.as_ptr()) -> Group) }
}
}
/// A labeled container around a child control.
///
/// Groups enclose a single child control, providing a descriptive title of the contents. They
/// are traditionally rendered as a rectangular border with an inline label. A group [can
/// optionally be margined](Self::set_margined), in which case empty space is inserted outside
/// the border.
#[subcontrol(handle = "uiGroup")]
pub struct Group;
impl<'ui> Group<'ui> {
/// The title of this group.
#[bind_text(fn = "uiGroupTitle")]
pub fn title(&self) -> _;
/// Sets the title of this group.
///
/// This overrides the title supplied to [`Ui::create_group`].
pub fn set_title(&self, title: impl Into<Vec<u8>>) -> Result<(), crate::Error> {
let title = self.ui.make_cstring(title)?;
unsafe { uiGroupSetTitle(self.as_ptr(), title.as_ptr()) };
Ok(())
}
/// Sets the child control of this group.
///
/// This is unset by default.
#[bind_set_child(fn = "uiGroupSetChild")]
pub fn set_child(&self, ...) -> _;
/// Clears the child control of this group if one is set.
#[inline]
pub fn clear(&self) {
unsafe { uiGroupSetChild(self.as_ptr(), std::ptr::null_mut()) };
}
/// Determines if this group has margins.
///
/// Groups are not margined by default.
#[inline]
pub fn is_margined(&self) -> bool {
bool_from_libui(unsafe { uiGroupMargined(self.as_ptr()) })
}
/// Sets whether or not this group has margins.
#[inline]
pub fn set_margined(&self, value: bool) {
unsafe { uiGroupSetMargined(self.as_ptr(), value.into()) };
}
}