Mercurial > tablet-emu
comparison src/main.rs @ 4:2e074d185151
Simplify tool buttons.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 09 Oct 2020 16:13:25 +0200 |
parents | 72e63d6a3f8a |
children | cdbf3a2c9af8 |
comparison
equal
deleted
inserted
replaced
3:72e63d6a3f8a | 4:2e074d185151 |
---|---|
237 window.set_position(gtk::WindowPosition::Center); | 237 window.set_position(gtk::WindowPosition::Center); |
238 | 238 |
239 let hbox = gtk::Box::new(gtk::Orientation::Horizontal, 0); | 239 let hbox = gtk::Box::new(gtk::Orientation::Horizontal, 0); |
240 let tools_box = gtk::Box::new(gtk::Orientation::Vertical, 0); | 240 let tools_box = gtk::Box::new(gtk::Orientation::Vertical, 0); |
241 | 241 |
242 let tool1 = gtk::Button::with_label("Pen"); | 242 macro_rules! impl_tool { |
243 let tool2 = gtk::Button::with_label("Rubber"); | 243 ($tool:tt) => { |
244 let tool3 = gtk::Button::with_label("Brush"); | 244 let tool = gtk::Button::with_label($tool); |
245 let tool4 = gtk::Button::with_label("Pencil"); | |
246 let tool5 = gtk::Button::with_label("Airbrush"); | |
247 | |
248 macro_rules! impl_tool_signal { | |
249 ($tool:ident) => { | |
250 let state_weak = Arc::downgrade(&state); | 245 let state_weak = Arc::downgrade(&state); |
251 $tool.connect_clicked(move |b| { | 246 tool.connect_clicked(move |b| { |
252 let state = state_weak.upgrade().unwrap(); | 247 let state = state_weak.upgrade().unwrap(); |
253 let mut state = state.lock().unwrap(); | 248 let mut state = state.lock().unwrap(); |
254 state.selected_tool = match b.get_label().unwrap().as_str() { | 249 state.selected_tool = match b.get_label().unwrap().as_str() { |
255 "Pen" => Key::ButtonToolPen, | 250 "Pen" => Key::ButtonToolPen, |
256 "Rubber" => Key::ButtonToolRubber, | 251 "Rubber" => Key::ButtonToolRubber, |
258 "Pencil" => Key::ButtonToolPencil, | 253 "Pencil" => Key::ButtonToolPencil, |
259 "Airbrush" => Key::ButtonToolAirbrush, | 254 "Airbrush" => Key::ButtonToolAirbrush, |
260 _ => unreachable!(), | 255 _ => unreachable!(), |
261 }; | 256 }; |
262 }); | 257 }); |
258 tools_box.add(&tool); | |
263 }; | 259 }; |
264 }; | 260 }; |
265 impl_tool_signal!(tool1); | 261 impl_tool!("Pen"); |
266 impl_tool_signal!(tool2); | 262 impl_tool!("Rubber"); |
267 impl_tool_signal!(tool3); | 263 impl_tool!("Brush"); |
268 impl_tool_signal!(tool4); | 264 impl_tool!("Pencil"); |
269 impl_tool_signal!(tool5); | 265 impl_tool!("Airbrush"); |
270 | |
271 tools_box.add(&tool1); | |
272 tools_box.add(&tool2); | |
273 tools_box.add(&tool3); | |
274 tools_box.add(&tool4); | |
275 tools_box.add(&tool5); | |
276 | 266 |
277 let drawing_area = gtk::DrawingArea::new(); | 267 let drawing_area = gtk::DrawingArea::new(); |
278 drawing_area.set_size_request(WIDTH, HEIGHT); | 268 drawing_area.set_size_request(WIDTH, HEIGHT); |
279 drawing_area.set_hexpand(true); | 269 drawing_area.set_hexpand(true); |
280 drawing_area.set_events( | 270 drawing_area.set_events( |