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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
pub use crate::prelude::*;
use fltk_sys::menu::*;
use std::{ffi::{CStr, CString}, mem, os::raw};
#[derive(WidgetTrait, MenuTrait, Debug, Clone)]
pub struct MenuBar {
_inner: *mut Fl_Menu_Bar,
}
#[derive(WidgetTrait, MenuTrait, Debug, Clone)]
pub struct MenuButton {
_inner: *mut Fl_Menu_Button,
}
#[derive(WidgetTrait, MenuTrait, Debug, Clone)]
pub struct Choice {
_inner: *mut Fl_Choice,
}
#[derive(Debug, Clone)]
pub struct MenuItem {
_inner: *mut Fl_Menu_Item,
_title: CString,
}
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum MenuFlag {
Normal = 0,
Inactive = 1,
Toggle = 2,
Value = 4,
Radio = 8,
Invisible = 0x10,
SubmenuPointer = 0x20,
Submenu = 0x40,
MenuDivider = 0x80,
MenuHorizontal = 0x100,
}
impl MenuItem {
pub fn label(&self) -> String {
unsafe {
CStr::from_ptr(Fl_Menu_Item_label(self._inner) as *mut raw::c_char)
.to_string_lossy().to_string()
}
}
pub fn set_label(&mut self, txt: &str) {
unsafe {
let txt = CString::new(txt).unwrap();
Fl_Menu_Item_set_label(self._inner, txt.into_raw() as *const raw::c_char);
}
}
pub fn label_type<T: WidgetType>(&self) -> T {
unsafe { T::from_i32(Fl_Menu_Item_label_type(self._inner)) }
}
pub fn set_label_type<T: WidgetType>(&mut self, typ: T) {
unsafe {
Fl_Menu_Item_set_label_type(self._inner, typ.to_int());
}
}
pub fn label_color(&self) -> Color {
unsafe { mem::transmute(Fl_Menu_Item_label_color(self._inner)) }
}
pub fn set_label_color(&mut self, color: Color) {
unsafe { Fl_Menu_Item_set_label_color(self._inner, color as i32) }
}
pub fn label_font(&self) -> Font {
unsafe { mem::transmute(Fl_Menu_Item_label_font(self._inner)) }
}
pub fn set_label_font(&mut self, font: Font) {
unsafe { Fl_Menu_Item_set_label_color(self._inner, font as i32) }
}
pub fn label_size(&self) -> usize {
unsafe { Fl_Menu_Item_label_size(self._inner) as usize }
}
pub fn set_label_size(&mut self, sz: usize) {
unsafe { Fl_Menu_Item_set_label_size(self._inner, sz as i32) }
}
pub fn value(&self) -> bool {
unsafe {
match Fl_Menu_Item_value(self._inner) {
0 => false,
_ => true,
}
}
}
pub fn set(&mut self) {
unsafe { Fl_Menu_Item_set(self._inner) }
}
pub fn clear(&mut self) {
unsafe { Fl_Menu_Item_clear(self._inner) }
}
pub fn visible(&self) -> bool {
unsafe {
match Fl_Menu_Item_visible(self._inner) {
0 => false,
_ => true,
}
}
}
pub fn active(&mut self) -> bool {
unsafe {
match Fl_Menu_Item_active(self._inner) {
0 => false,
_ => true,
}
}
}
pub fn activate(&mut self) {
unsafe { Fl_Menu_Item_activate(self._inner) }
}
pub fn deactivate(&mut self) {
unsafe { Fl_Menu_Item_deactivate(self._inner) }
}
pub fn show(&mut self) {
unsafe { Fl_Menu_Item_show(self._inner) }
}
pub fn hide(&mut self) {
unsafe { Fl_Menu_Item_hide(self._inner) }
}
}