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
|
use fltk::{app::*, button::*, draw::*, frame::*, menu::*, text::*, window::*};
#[derive(Clone, Copy)]
enum GUIMessage {
None,
Test,
}
struct GUIBoard {
frame: Frame,
test: bool,
}
impl GUIBoard {
fn new(frame: Frame) -> GUIBoard {
let mut g = GUIBoard { frame, test: false };
g.frame.draw2(g.draw());
g
}
fn change(&mut self) {
self.test = !self.test;
self.frame.draw2(self.draw());
self.frame.set_damage(true);
}
fn draw(&self) -> impl Fn(&mut Frame) {
let tc = self.test;
move |frame: &mut Frame| {
const BOARD_PAD_INNER: i32 = 5;
let bx = frame.x() + BOARD_PAD_INNER;
let by = frame.y() + BOARD_PAD_INNER;
push_clip(frame.x(), frame.y(), frame.width(), frame.height());
set_draw_color(if tc { Color::Blue } else { Color::Red });
draw_rectf(bx, by, 100, 30);
pop_clip();
}
}
}
pub struct GUI {
app: App,
window: Window,
board: GUIBoard,
log: TextDisplay,
sender: Sender<GUIMessage>,
receiver: Receiver<GUIMessage>,
}
impl GUI {
pub fn new() -> GUI {
let app = App::default();
// TODO: Why is this not the same as
/*
let mut window = Window::default()
.with_size(800, 600)
.with_label("Takwrap")
.center_screen();
*/
// Windows made that way are not resizable?
let mut window = Window::new(0, 0, 800, 600, "Takwrap").center_screen();
let (sender, receiver) = channel::<GUIMessage>();
let mut menu = SysMenuBar::default().with_size(800, 24);
// menu.set_text_font(Font::Helvetica);
menu.set_color(Color::Light2);
menu.add_emit(
"&File/New...\t",
Shortcut::None,
MenuFlag::Normal,
sender,
GUIMessage::None,
);
menu.add_emit(
"&File/Open...\t",
Shortcut::None,
MenuFlag::Normal,
sender,
GUIMessage::Test,
);
const LOG_WIDTH: i32 = 10 * 16;
const LOG_PAD: i32 = 0;
let mut log = TextDisplay::default()
.with_size(LOG_WIDTH, 600 - 2 * LOG_PAD - menu.height())
.with_pos(800 - LOG_WIDTH - LOG_PAD, menu.height());
log.set_buffer(Some(TextBuffer::default()));
log.insert("test");
const BOARD_PAD: i32 = 0;
let mut board_frame = Frame::default()
.with_size(
800 - LOG_WIDTH - LOG_PAD * 2 - BOARD_PAD,
600 - 2 * BOARD_PAD - menu.height(),
)
.below_of(&menu, BOARD_PAD);
board_frame.set_frame(FrameType::EmbossedBox);
window.resizable(&mut board_frame);
window.end();
window.show();
let board = GUIBoard::new(board_frame);
// button.emit(sender, GUIMessage::Foo);
GUI {
app,
board,
window,
log,
sender,
receiver,
}
}
pub fn run(&mut self) -> Result<(), fltk::prelude::FltkError> {
// self.window.show();
while self.app.wait() {
if let Some(msg) = self.receiver.recv() {
match msg {
GUIMessage::Test => {
self.board.change();
}
_ => (),
}
}
}
Ok(())
}
}
|