Style the welcome screen

This commit is contained in:
Savanni D'Gerinel 2023-12-19 10:10:02 -05:00
parent db188ea75a
commit beedeba8dc
3 changed files with 69 additions and 22 deletions

View File

@ -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;
}

View File

@ -80,13 +80,13 @@ impl WelcomeView {
{ {
let s: Self = Object::builder().build(); let s: Self = Object::builder().build();
s.set_orientation(gtk::Orientation::Vertical); 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 // Replace this with the welcome screen that we set up in the fitnesstrax/unconfigured-page
// branch. // branch.
let title = gtk::Label::builder() let title = gtk::Label::builder()
.label("Welcome to FitnessTrax") .label("Welcome to FitnessTrax")
.css_classes(["modal-title"]) .css_classes(["welcome-title"])
.build(); .build();
let content = gtk::Box::builder() let content = gtk::Box::builder()

View File

@ -56,45 +56,71 @@ impl FileChooserRow {
{ {
let s: Self = Object::builder().build(); let s: Self = Object::builder().build();
s.set_css_classes(&["dialog-row", "card"]);
s.set_orientation(gtk::Orientation::Horizontal); 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 // 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 // button that triggers a file chooser dialog. Once the dialog returns, the box should be
// updated to reflect the chosen path. // updated to reflect the chosen path.
s.imp().label.set_text("No database selected"); 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)); 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 s = s.clone();
let on_selected = on_selected.clone();
move |file_id: Result<gio::File, glib::Error>| 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 |_| { move |_| {
let no_window: Option<&gtk::Window> = None; let no_window: Option<&gtk::Window> = None;
let not_cancellable: Option<&gio::Cancellable> = None; let not_cancellable: Option<&gio::Cancellable> = None;
let s = s.clone(); let handle_file_selection = handle_file_selection.clone();
let on_selected = on_selected.clone(); gtk::FileDialog::builder().build().open(
gtk::FileDialog::builder().build().save(
no_window, no_window,
not_cancellable, not_cancellable,
move |file_id| match file_id { move |file_id| handle_file_selection(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),
},
); );
} }
}); });
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<&gtk::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(&s.imp().label);
s.append(&db_file_chooser_button); s.append(&import_button);
s.append(&new_button);
s s
} }