Browse Source

Thread window to allow other refreshing

Getty Ritter 3 years ago
parent
commit
65d619f3f0
1 changed files with 7 additions and 6 deletions
  1. 7 6
      src/main.rs

+ 7 - 6
src/main.rs

@@ -53,29 +53,30 @@ impl AppData {
 #[derive(Clone)]
 struct App {
     data: Rc<RefCell<AppData>>,
+    window: gtk::Window,
 }
 
 impl App {
-    fn new() -> App {
+    fn new(window: gtk::Window) -> App {
         let app_data = AppData {
             symbol: 'X',
             dmc: None,
         };
         let data = Rc::new(RefCell::new(app_data));
-        App { data }
+        App { data, window }
     }
 }
 
 fn mk_app() {
-    let app = App::new();
     let window = gtk::Window::new(gtk::WindowType::Toplevel);
+    let app = App::new(window.clone());
     window.connect_delete_event(move |_, _| {
         gtk::main_quit();
         gtk::Inhibit(false)
     });
 
     window.set_title("I Am Legend");
-    window.set_default_size(500, 100);
+    window.set_default_size(500, 200);
     window.set_resizable(false);
     let container = gtk::Box::new(gtk::Orientation::Vertical, 4);
     container.pack_start(&mk_icon_choice('A', app.clone()), false, true, 0);
@@ -103,7 +104,7 @@ fn mk_app() {
                 app.data.borrow_mut().dmc = None;
                 label.set_text("");
             }
-            window.queue_draw_area(0, 0, 500, 100);
+            window.queue_draw_area(0, 0, 500, 200);
         });
         container.pack_start(&color, false, true, 0);
     }
@@ -141,7 +142,7 @@ fn mk_icon_choice(choice: char, cell: App) -> gtk::Button {
     let button = gtk::Button::with_label(&choice.to_string());
     button.connect_clicked(move |_| {
         cell.data.borrow_mut().symbol = choice;
-        println!("Choosing '{}'", choice);
+        cell.window.queue_draw_area(0, 0, 500, 200);
     });
     button
 }