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
use nappgui_sys::{
panel_create, panel_custom, panel_get_layout, panel_layout, panel_scroll, panel_scroll_height,
panel_scroll_width, panel_size, panel_update, panel_visible_layout,
};
use super::Layout;
/// A Panel is a control within a window that groups other controls. It defines its own reference system,
/// that is, if we move a panel all its descendants will move in unison since their locations will be
/// relative to its origin. It will support other (sub)-panels as descendants, which allows to form a
/// Window Hierarchy. A Panel is a control within a window that groups other controls.
pub struct Panel {
pub(crate) inner: *mut nappgui_sys::Panel,
}
impl Panel {
pub(crate) fn new(ptr: *mut nappgui_sys::Panel) -> Self {
if ptr.is_null() {
panic!("ptr is null");
}
Self { inner: ptr }
}
/// Create a panel.
pub fn create() -> Self {
let panel = unsafe { panel_create() };
Self::new(panel)
}
/// Create a panel with scroll bars.
pub fn scroll(hscroll: bool, vscroll: bool) -> Self {
let panel = unsafe { panel_scroll(hscroll as i8, vscroll as i8) };
Self::new(panel)
}
/// Create a fully configurable panel.
pub fn custom(hscroll: bool, vscroll: bool, border: bool) -> Self {
let panel = unsafe { panel_custom(hscroll as i8, vscroll as i8, border as i8) };
Self::new(panel)
}
/// Sets the default size of the visible area of a panel.
pub fn size(&self, width: f32, height: f32) {
let size = nappgui_sys::S2Df { width, height };
unsafe {
panel_size(self.inner, size);
}
}
/// Add a layout to a panel.
pub fn layout(&self, layout: &Layout) {
unsafe {
panel_layout(self.inner, layout.inner);
}
}
/// Get a layout of a panel.
pub fn get_layout(&self, index: u32) -> Option<Layout> {
let layout = unsafe { panel_get_layout(self.inner, index) };
if layout.is_null() {
None
} else {
Some(Layout::new(layout))
}
}
/// Set the active layout inside the panel.
///
/// # Remarks
/// To make the change effective, you have to call panel_update.
pub fn visible_layout(&self, index: u32) {
unsafe {
panel_visible_layout(self.inner, index);
}
}
/// Update the window that contains the panel.
///
/// # Remarks
/// It is equivalent to calling window_update.
pub fn update(&self) {
unsafe {
panel_update(self.inner);
}
}
/// Gets the width of the scroll bar of the associated panel.
///
/// # Remarks
/// Only valid if the panel has been created with panel_scroll. Useful if we want to take into
/// account the size of the scroll bars when setting the margins of the Layout.
pub fn scroll_width(&self) -> f32 {
unsafe { panel_scroll_width(self.inner) }
}
/// Gets the height of the scroll bar.
pub fn scroll_height(&self) -> f32 {
unsafe { panel_scroll_height(self.inner) }
}
}