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
118
119
120
121
122
123
124
125
126
127
use std::ffi::CString;
use crate::{
draw_2d::{Color, Font},
prelude::FStyle,
util::macros::callback,
};
use nappgui_sys::{
align_t, label_OnClick, label_align, label_bgcolor, label_bgcolor_over, label_color,
label_color_over, label_create, label_font, label_multiline, label_size_text, label_style_over,
label_text,
};
/// Label controls are used to insert small blocks of text into windows and forms. They are of uniform format,
/// that is, the font and color attributes will be applied to the entire text. In most cases the content will
/// be limited to a single line, although it is possible to show blocks that extend in several lines. The control
/// size will be adjusted to the text it contains
pub struct Label {
pub(crate) inner: *mut nappgui_sys::Label,
}
impl Label {
pub(crate) fn new(ptr: *mut nappgui_sys::Label) -> Self {
if ptr.is_null() {
panic!("ptr is null");
}
Self { inner: ptr }
}
/// Activate or deactivate the multiline attribute.
pub fn create() -> Label {
let label = unsafe { label_create() };
Self::new(label)
}
callback! {
/// Set the OnClick event handler.
pub on_click(Label) => label_OnClick;
}
/// Set the text that the label will display.
pub fn text(&self, text: &str) {
let text = CString::new(text).unwrap();
unsafe {
label_text(self.inner, text.as_ptr());
}
}
/// Set the text with which the control will be sized.
///
/// # Remarks
/// By default, a Label control will be sized to the exact size of the text it
/// contains. See Dynamic labels.
pub fn size_text(&self, text: &str) {
let text = CString::new(text).unwrap();
unsafe {
label_size_text(self.inner, text.as_ptr());
}
}
/// Set the text font.
pub fn font(&self, font: &Font) {
unsafe {
label_font(self.inner, font.inner);
}
}
/// Set the font modifiers, when the mouse is over the control.
pub fn style_over(&self, style: FStyle) {
unsafe {
label_style_over(self.inner, (style as i32).try_into().unwrap());
}
}
/// Create a multi-line text control.
pub fn multiline(&self, multiline: bool) {
unsafe { label_multiline(self.inner, multiline as i8) };
}
/// Sets the horizontal alignment of the text with respect to the size of the control.
pub fn align(&self, align: align_t) {
unsafe {
label_align(self.inner, align);
}
}
/// Set the text color.
///
/// # Remarks
/// RGB values may not be fully portable.
pub fn color(&self, color: Color) {
unsafe {
label_color(self.inner, color.inner);
}
}
/// Set the color of the text, when the mouse is over the control.
///
/// # Remarks
/// RGB values may not be fully portable.
pub fn color_over(&self, color: Color) {
unsafe {
label_color_over(self.inner, color.inner);
}
}
/// Set the background color of the text.
///
/// # Remarks
/// RGB values may not be fully portable.
pub fn bgcolor(&self, color: Color) {
unsafe {
label_bgcolor(self.inner, color.inner);
}
}
/// Set the background color of the text, when the mouse is over the control.
///
/// # Remarks
/// RGB values may not be fully portable.
pub fn bgcolor_over(&self, color: Color) {
unsafe {
label_bgcolor_over(self.inner, color.inner);
}
}
}