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
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 crate::gui::{control::impl_control, impl_layout, Layout, LayoutTrait};
/// The panel trait.
pub trait PanelTrait {
/// Returns a raw pointer to the panel object.
fn as_ptr(&self) -> *mut nappgui_sys::Panel;
/// Sets the default size of the visible area of a panel.
fn size(&self, width: f32, height: f32) {
let size = nappgui_sys::S2Df { width, height };
unsafe {
panel_size(self.as_ptr(), size);
}
}
/// Add a layout to a panel.
fn layout<T>(&self, layout: T)
where
T: LayoutTrait,
{
unsafe {
panel_layout(self.as_ptr(), layout.as_ptr());
}
}
/// Get a layout of a panel.
fn get_layout(&self, index: usize) -> Option<Layout> {
let layout = unsafe { panel_get_layout(self.as_ptr(), index as _) };
if layout.is_null() {
None
} else {
Some(Layout { inner: layout })
}
}
/// Set the active layout inside the panel.
///
/// # Remarks
/// To make the change effective, you have to call panel_update.
fn visible_layout(&self, index: usize) {
unsafe {
panel_visible_layout(self.as_ptr(), index as _);
}
}
/// Update the window that contains the panel.
///
/// # Remarks
/// It is equivalent to calling window_update.
fn update(&self) {
unsafe {
panel_update(self.as_ptr());
}
}
/// 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.
fn scroll_width(&self) -> f32 {
unsafe { panel_scroll_width(self.as_ptr()) }
}
/// Gets the height of the scroll bar.
fn scroll_height(&self) -> f32 {
unsafe { panel_scroll_height(self.as_ptr()) }
}
}
/// 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.
///
/// # Remark
/// This type is managed by nappgui itself. Rust does not have its ownership. When the window object is dropped, all
/// components assciated with it will be automatically released.
#[repr(transparent)]
#[derive(Clone, Copy, Debug)]
pub struct Panel {
pub(crate) inner: *mut nappgui_sys::Panel,
}
impl PanelTrait for Panel {
fn as_ptr(&self) -> *mut nappgui_sys::Panel {
self.inner
}
}
impl Panel {
/// Create a panel.
pub fn new() -> Self {
let panel = unsafe { panel_create() };
Self { inner: panel }
}
/// Create a panel with scroll bars.
pub fn new_scroll(hscroll: bool, vscroll: bool) -> Self {
let panel = unsafe { panel_scroll(hscroll as _, vscroll as _) };
Self { inner: panel }
}
/// Create a fully configurable panel.
pub fn new_custom(hscroll: bool, vscroll: bool, border: bool) -> Self {
let panel = unsafe { panel_custom(hscroll as _, vscroll as _, border as _) };
Self { inner: panel }
}
}
impl_control!(Panel, guicontrol_panel);
impl_layout!(Panel, PanelTrait, layout_panel);