|
@@ -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: >k::Button) {
|
|
|
+ /// Setup the callback for an icon-chooser button
|
|
|
+ fn icon_button_clicked(self, ch: char, button: >k::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: >k::Entry) {
|
|
|
+ /// Setup the callback that fires when the text changes for the
|
|
|
+ /// DMC thread input box
|
|
|
+ fn color_entry_changed(self, entry: >k::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: >k::Button) {
|
|
|
+ /// Setup the callback that fires when the 'EXPORT IT' button is
|
|
|
+ /// clicked
|
|
|
+ fn submit_clicked(self, button: >k::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: >k::DrawingArea) {
|
|
|
+ /// Setup the callback that handles drawing the canvas
|
|
|
+ fn canvas_draw(self, canvas: >k::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();
|
|
|
}
|
|
|
}
|