diff --git a/fitnesstrax/app/resources/style.css b/fitnesstrax/app/resources/style.css index e69de29..314fd86 100644 --- a/fitnesstrax/app/resources/style.css +++ b/fitnesstrax/app/resources/style.css @@ -0,0 +1,21 @@ +.welcome { + margin: 64px; +} + +.welcome-title { + font-size: larger; + padding: 8px; +} + +.welcome-content { + padding: 8px; +} + +.welcome-footer { +} + +.dialog-row { + margin: 8px 0px 8px 0px; + padding: 8px; +} + diff --git a/fitnesstrax/app/src/main.rs b/fitnesstrax/app/src/main.rs index 3eb3bc9..3507182 100644 --- a/fitnesstrax/app/src/main.rs +++ b/fitnesstrax/app/src/main.rs @@ -80,13 +80,13 @@ impl WelcomeView { { let s: Self = Object::builder().build(); s.set_orientation(gtk::Orientation::Vertical); - s.set_css_classes(&["modal"]); + s.set_css_classes(&["welcome"]); // Replace this with the welcome screen that we set up in the fitnesstrax/unconfigured-page // branch. let title = gtk::Label::builder() .label("Welcome to FitnessTrax") - .css_classes(["modal-title"]) + .css_classes(["welcome-title"]) .build(); let content = gtk::Box::builder() diff --git a/fitnesstrax/app/src/ui/mod.rs b/fitnesstrax/app/src/ui/mod.rs index 2327823..14f1243 100644 --- a/fitnesstrax/app/src/ui/mod.rs +++ b/fitnesstrax/app/src/ui/mod.rs @@ -56,45 +56,71 @@ impl FileChooserRow { { let s: Self = Object::builder().build(); + s.set_css_classes(&["dialog-row", "card"]); s.set_orientation(gtk::Orientation::Horizontal); + s.set_spacing(8); // The database selection row should be a box that shows a default database path, along with a // button that triggers a file chooser dialog. Once the dialog returns, the box should be // updated to reflect the chosen path. s.imp().label.set_text("No database selected"); - let db_file_chooser_button = gtk::Button::builder().label("Select Database").build(); let on_selected = Rc::new(Box::new(on_selected)); - db_file_chooser_button.connect_clicked({ + + let import_button = gtk::Button::builder().label("Import a Database").build(); + + let handle_file_selection = Rc::new(Box::new({ let s = s.clone(); + let on_selected = on_selected.clone(); + move |file_id: Result| match file_id { + Ok(file_id) => match file_id.path() { + Some(path) => { + s.imp().label.set_text(path.to_str().unwrap()); + on_selected(path.clone()); + *s.imp().path.borrow_mut() = Some(path); + } + None => { + *s.imp().path.borrow_mut() = None; + s.imp().label.set_text("No database selected"); + } + }, + Err(err) => println!("file opening failed: {}", err), + } + })); + + import_button.connect_clicked({ + let handle_file_selection = handle_file_selection.clone(); move |_| { let no_window: Option<>k::Window> = None; let not_cancellable: Option<&gio::Cancellable> = None; - let s = s.clone(); - let on_selected = on_selected.clone(); - gtk::FileDialog::builder().build().save( + let handle_file_selection = handle_file_selection.clone(); + gtk::FileDialog::builder().build().open( no_window, not_cancellable, - move |file_id| match file_id { - Ok(file_id) => match file_id.path() { - Some(path) => { - s.imp().label.set_text(path.to_str().unwrap()); - on_selected(path.clone()); - *s.imp().path.borrow_mut() = Some(path); - } - None => { - *s.imp().path.borrow_mut() = None; - s.imp().label.set_text("No database selected"); - } - }, - Err(err) => println!("file opening failed: {}", err), - }, + move |file_id| handle_file_selection(file_id), ); } }); + let new_button = gtk::Button::builder().label("Create Database").build(); + new_button.connect_clicked({ + let handle_file_selection = handle_file_selection.clone(); + move |_| { + let no_window: Option<>k::Window> = None; + let not_cancellable: Option<&gio::Cancellable> = None; + let handle_file_selection = handle_file_selection.clone(); + gtk::FileDialog::builder().build().save( + no_window, + not_cancellable, + move |file_id| handle_file_selection(file_id), + ); + } + }); + + s.imp().label.set_halign(gtk::Align::Start); s.append(&s.imp().label); - s.append(&db_file_chooser_button); + s.append(&import_button); + s.append(&new_button); s }