Browse Source

A bit more cleanup

Getty Ritter 3 years ago
parent
commit
2df66cf078
2 changed files with 24 additions and 10 deletions
  1. 1 2
      src/main.rs
  2. 23 8
      src/view.rs

+ 1 - 2
src/main.rs

@@ -6,8 +6,7 @@ fn main() {
     if gtk::init().is_err() {
         eprintln!("Failed to initialize GTK application");
     } else {
-        view::View::create().setup().show();
-        // view::mk_app();
+        view::View::run();
         gtk::main();
     }
 }

+ 23 - 8
src/view.rs

@@ -39,7 +39,14 @@ pub struct View {
 }
 
 impl View {
-    pub fn create() -> View {
+    /// Setup and run the program
+    pub fn run() {
+        View::create().setup().show()
+    }
+
+    /// Create and arrange the widgets that will be used for drawing
+    /// the UI
+    fn create() -> View {
         let window = gtk::Window::new(gtk::WindowType::Toplevel);
         let app = App::new();
         // left pane: the icon choices
@@ -82,7 +89,9 @@ impl View {
         }
     }
 
-    pub fn setup(&self) -> &Self {
+    /// Bind callbacks and set up default configuration values for the
+    /// provided widgets
+    fn setup(&self) -> &Self {
         // setup window properties and callbacks
         self.window.connect_delete_event(move |_, _| {
             gtk::main_quit();
@@ -104,14 +113,17 @@ impl View {
         self
     }
 
-    pub fn icon_button_clicked(self, ch: char, button: &gtk::Button) {
+    /// Setup the callback for an icon-chooser button
+    fn icon_button_clicked(self, ch: char, button: &gtk::Button) {
         button.connect_clicked(move |_| {
             self.app.data.borrow_mut().symbol = ch;
             self.window.queue_draw_area(0, 0, 500, 200);
         });
     }
 
-    pub fn color_entry_changed(self, entry: &gtk::Entry) {
+    /// Setup the callback that fires when the text changes for the
+    /// DMC thread input box
+    fn color_entry_changed(self, entry: &gtk::Entry) {
         entry.connect_changed(move |s| {
             let str = s.get_text();
             if let Some(color) = dmc::LOOKUP.get(str.as_str()) {
@@ -127,7 +139,9 @@ impl View {
         });
     }
 
-    pub fn submit_clicked(self, button: &gtk::Button) {
+    /// Setup the callback that fires when the 'EXPORT IT' button is
+    /// clicked
+    fn submit_clicked(self, button: &gtk::Button) {
         button.connect_clicked(move |_| {
             let dialog = gtk::FileChooserDialog::with_buttons(
                 Some("Select filename"),
@@ -160,9 +174,9 @@ impl View {
         });
     }
 
-    pub fn canvas_draw(self, canvas: &gtk::DrawingArea) {
+    /// Setup the callback that handles drawing the canvas
+    fn canvas_draw(self, canvas: &gtk::DrawingArea) {
         canvas.connect_draw(move |cv, ctx| {
-            println!("drawing");
             let w = cv.get_allocated_width();
             let h = cv.get_allocated_height();
             if let Err(err) = self.app.data.borrow_mut().render(ctx, w as f64, h as f64) {
@@ -172,7 +186,8 @@ impl View {
         });
     }
 
-    pub fn show(&self) {
+    /// Show the whole thing
+    fn show(&self) {
         self.window.show_all();
     }
 }