-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbutton.rs
91 lines (80 loc) · 3.78 KB
/
button.rs
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
//! Example based on http://sourceforge.net/p/iup/iup/HEAD/tree/trunk/iup/html/examples/Lua/button.lua
//!
//! Creates four buttons. The first uses images, the second turns the first on and off, the third
//! exits the application and the last does nothing
//!
#[macro_use]
extern crate iup;
use iup::prelude::*;
use iup::control::{Button, Text};
use iup::layout::{VBox, HBox, Fill};
use iup::image::Image;
use iup::callback::button::{MouseButton, MouseButtonState};
fn main() {
iup::with_iup(|| {
// We can create a image inline to be embedded in a control...
let img_release = Image::with(pixels![
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2],
[1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2],
[1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2],
[1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2],
[1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2],
[1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2],
[1,1,3,3,3,3,3,3,4,4,3,3,3,3,2,2],
[1,1,3,3,3,3,3,4,4,4,4,3,3,3,2,2],
[1,1,3,3,3,3,3,4,4,4,4,3,3,3,2,2],
[1,1,3,3,3,3,3,3,4,4,3,3,3,3,2,2],
[1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2],
[1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2],
[1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2],
[1,1,3,3,3,3,3,3,3,3,3,3,3,3,2,2],
[1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
[2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
]).set_colors([(0, 0, 0), (215,215,215), (40, 40, 40), (30, 50, 210), (240, 0, 0)]);
// Creates a text box
let mut text = Text::new()
.set_attrib("READONLY", "YES")
.set_attrib("EXPAND", "YES");
// Creates a button with image
let mut btn_image = Button::with_title("Button with image")
.set_attrib_handle("IMAGE", img_release)
.set_button_cb(move |(_, button, state, _, _, _)| {
if button == MouseButton::Button1 {
text.set_attrib("VALUE", format!("Odd button {}", match state {
MouseButtonState::Pressed => "pressed",
MouseButtonState::Released => "released",
}));
}
});
// Creates a [useless] button
let btn_big = Button::with_title("Big useless button")
.set_attrib("SIZE", "0.125x0.125");
// Creates a button entitled Exit
let btn_exit = Button::with_title("Exit")
.set_action(|_| CallbackReturn::Close);
// Creates a button entitled 'Activate'
let btn_on_off = Button::with_title("Activate")
.set_action(move |_| {
if btn_image.attrib("ACTIVE").unwrap() == "YES" {
btn_image.set_attrib("ACTIVE", "NO");
} else {
btn_image.set_attrib("ACTIVE", "YES");
}
});
// Creates a dialog window
Dialog::new(
VBox::new(elements![
HBox::new(elements![
Fill::new(), btn_image, btn_on_off, btn_exit, Fill::new()
]),
text, btn_big
])
).set_attrib("TITLE", "Button")
.set_attrib("RESIZE", "NO") // Turn of resize
.set_attrib("MENUBOX", "NO") // ... menu box
.set_attrib("MAXBOX", "NO") // ... maximize
.set_attrib("MINBOX", "NO") // and minimize
.show()
}).unwrap();
}