changeset 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
files src/main.rs
diffstat 1 files changed, 10 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.rs
+++ b/src/main.rs
@@ -239,16 +239,11 @@ fn build_ui(application: &gtk::Applicati
     let hbox = gtk::Box::new(gtk::Orientation::Horizontal, 0);
     let tools_box = gtk::Box::new(gtk::Orientation::Vertical, 0);
 
-    let tool1 = gtk::Button::with_label("Pen");
-    let tool2 = gtk::Button::with_label("Rubber");
-    let tool3 = gtk::Button::with_label("Brush");
-    let tool4 = gtk::Button::with_label("Pencil");
-    let tool5 = gtk::Button::with_label("Airbrush");
-
-    macro_rules! impl_tool_signal {
-        ($tool:ident) => {
+    macro_rules! impl_tool {
+        ($tool:tt) => {
+            let tool = gtk::Button::with_label($tool);
             let state_weak = Arc::downgrade(&state);
-            $tool.connect_clicked(move |b| {
+            tool.connect_clicked(move |b| {
                 let state = state_weak.upgrade().unwrap();
                 let mut state = state.lock().unwrap();
                 state.selected_tool = match b.get_label().unwrap().as_str() {
@@ -260,19 +255,14 @@ fn build_ui(application: &gtk::Applicati
                     _ => unreachable!(),
                 };
             });
+            tools_box.add(&tool);
         };
     };
-    impl_tool_signal!(tool1);
-    impl_tool_signal!(tool2);
-    impl_tool_signal!(tool3);
-    impl_tool_signal!(tool4);
-    impl_tool_signal!(tool5);
-
-    tools_box.add(&tool1);
-    tools_box.add(&tool2);
-    tools_box.add(&tool3);
-    tools_box.add(&tool4);
-    tools_box.add(&tool5);
+    impl_tool!("Pen");
+    impl_tool!("Rubber");
+    impl_tool!("Brush");
+    impl_tool!("Pencil");
+    impl_tool!("Airbrush");
 
     let drawing_area = gtk::DrawingArea::new();
     drawing_area.set_size_request(WIDTH, HEIGHT);