Elaborate a little more on the welcome dialog

This commit is contained in:
Savanni D'Gerinel 2023-12-18 11:13:43 -05:00
parent 9afc7d73c0
commit d1c61a638b
1 changed files with 60 additions and 8 deletions

View File

@ -8,9 +8,11 @@ use std::cell::RefCell;
pub struct ModalPrivate { pub struct ModalPrivate {
title: gtk::Label, title: gtk::Label,
content: RefCell<gtk::Widget>, content: RefCell<gtk::Widget>,
primary_action: gtk::Button, primary_action: RefCell<gtk::Button>,
secondary_action: Option<gtk::Button>, secondary_action: RefCell<Option<gtk::Button>>,
tertiary_action: Option<gtk::Button>, tertiary_action: RefCell<Option<gtk::Button>>,
footer: gtk::Box,
} }
#[glib::object_subclass] #[glib::object_subclass]
@ -23,13 +25,22 @@ impl ObjectSubclass for ModalPrivate {
let title = gtk::Label::builder().label("Modal").build(); let title = gtk::Label::builder().label("Modal").build();
let content = gtk::Box::new(gtk::Orientation::Vertical, 0); let content = gtk::Box::new(gtk::Orientation::Vertical, 0);
let actions = gtk::Box::new(gtk::Orientation::Horizontal, 0); let actions = gtk::Box::new(gtk::Orientation::Horizontal, 0);
let primary_action = gtk::Button::builder().label("Primary").build();
let footer = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal)
.hexpand(true)
.build();
footer.append(&primary_action);
Self { Self {
title, title,
content: RefCell::new(content.upcast()), content: RefCell::new(content.upcast()),
primary_action: gtk::Button::new(), primary_action: RefCell::new(primary_action),
secondary_action: None, secondary_action: RefCell::new(None),
tertiary_action: None, tertiary_action: RefCell::new(None),
footer,
} }
} }
} }
@ -39,16 +50,22 @@ impl WidgetImpl for ModalPrivate {}
impl BoxImpl for ModalPrivate {} impl BoxImpl for ModalPrivate {}
glib::wrapper! { glib::wrapper! {
pub struct Modal(ObjectSubclass<ModalPrivate>) @extends gtk::Box, gtk::Widget; pub struct Modal(ObjectSubclass<ModalPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
} }
impl Modal { impl Modal {
pub fn new() -> Self { pub fn new() -> Self {
let s: Self = Object::builder().build(); let s: Self = Object::builder().build();
s.set_margin_start(100);
s.set_margin_end(100);
s.set_margin_top(100);
s.set_margin_bottom(100);
s.set_orientation(gtk::Orientation::Vertical);
s.append(&s.imp().title); s.append(&s.imp().title);
s.append(&*s.imp().content.borrow()); s.append(&*s.imp().content.borrow());
// s.append(&s.imp().actions); s.append(&s.imp().footer);
s s
} }
@ -62,6 +79,16 @@ impl Modal {
self.insert_child_after(&content, Some(&self.imp().title)); self.insert_child_after(&content, Some(&self.imp().title));
*self.imp().content.borrow_mut() = content; *self.imp().content.borrow_mut() = content;
} }
pub fn set_primary_action(&self, action: gtk::Button) {
self.imp()
.footer
.remove(&*self.imp().primary_action.borrow());
*self.imp().primary_action.borrow_mut() = action;
self.imp()
.footer
.append(&*self.imp().primary_action.borrow());
}
} }
/// The welcome modal is the first thing the user will see when FitnessTrax starts up if the /// The welcome modal is the first thing the user will see when FitnessTrax starts up if the
@ -71,5 +98,30 @@ impl Modal {
pub fn welcome_modal() -> Modal { pub fn welcome_modal() -> Modal {
let modal = Modal::new(); let modal = Modal::new();
modal.set_title("Welcome to FitnessTrax"); modal.set_title("Welcome to FitnessTrax");
// The content should be a friendly dialog that explains to the user that they're going to set
// up the database.
let content = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.build();
content.append(&gtk::Label::new(Some("Welcome to FitnessTrax. The application has not yet been configured, so I will walk you through that. Let's start out by selecting your database.")));
// 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.
let db_row = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal)
.build();
db_row.append(
&gtk::Label::builder()
.label("No Path Selected")
.hexpand(true)
.build(),
);
db_row.append(&gtk::Button::builder().label("Select Database").build());
modal.set_content(content.upcast());
modal.set_primary_action(gtk::Button::builder().label("Save Settings").build());
modal modal
} }