Compare commits
No commits in common. "56a8133dd5896ea1109cdae68eb1199eba9240f2" and "f6bba16b264f1b506683cab2e5e788f40b1a6ba7" have entirely different histories.
56a8133dd5
...
f6bba16b26
|
@ -11,7 +11,7 @@ emseries = { path = "../../emseries" }
|
||||||
ft-core = { path = "../core" }
|
ft-core = { path = "../core" }
|
||||||
gio = { version = "0.18" }
|
gio = { version = "0.18" }
|
||||||
glib = { version = "0.18" }
|
glib = { version = "0.18" }
|
||||||
gtk = { version = "0.7", package = "gtk4", features = [ "v4_10" ] }
|
gtk = { version = "0.7", package = "gtk4", features = [ "v4_8" ] }
|
||||||
tokio = { version = "1.34", features = [ "full" ] }
|
tokio = { version = "1.34", features = [ "full" ] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
.modal {
|
|
||||||
margin: 64px;
|
|
||||||
background-color: @view_bg_color;
|
|
||||||
border: 1px solid grey;
|
|
||||||
border-radius: 10px
|
|
||||||
}
|
|
||||||
|
|
||||||
.modal-title {
|
|
||||||
font-size: larger;
|
|
||||||
padding: 8px;
|
|
||||||
background-color: @headerbar_bg_color;
|
|
||||||
border-bottom: 1px solid @headerbar_border_color;
|
|
||||||
border-radius: 10px 10px 0px 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.modal-content {
|
|
||||||
padding: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.modal-footer {
|
|
||||||
}
|
|
|
@ -23,7 +23,6 @@ use gio::resources_lookup_data;
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{subclass::prelude::*, STYLE_PROVIDER_PRIORITY_USER};
|
use gtk::{subclass::prelude::*, STYLE_PROVIDER_PRIORITY_USER};
|
||||||
use std::{
|
use std::{
|
||||||
cell::RefCell,
|
|
||||||
env,
|
env,
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
|
@ -137,7 +136,7 @@ enum MainView {
|
||||||
Unconfigured(UnconfiguredView),
|
Unconfigured(UnconfiguredView),
|
||||||
|
|
||||||
/// The Historical view shows a history of records and whatnot.
|
/// The Historical view shows a history of records and whatnot.
|
||||||
Historical(HistoricalView),
|
HistoricalView(HistoricalView),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The application window, or the main window, is the main user interface for the app.
|
/// The application window, or the main window, is the main user interface for the app.
|
||||||
|
@ -145,12 +144,7 @@ struct AppWindow {
|
||||||
app: App,
|
app: App,
|
||||||
window: adw::ApplicationWindow,
|
window: adw::ApplicationWindow,
|
||||||
overlay: gtk::Overlay,
|
overlay: gtk::Overlay,
|
||||||
|
current_view: MainView,
|
||||||
current_view: RefCell<MainView>,
|
|
||||||
|
|
||||||
// We have to keep around a reference to the modal so that we know what to remove from the
|
|
||||||
// overlay.
|
|
||||||
modal: RefCell<Option<gtk::Widget>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppWindow {
|
impl AppWindow {
|
||||||
|
@ -161,46 +155,6 @@ impl AppWindow {
|
||||||
///
|
///
|
||||||
/// app is a core [App] object which encapsulates all of the basic logic.
|
/// app is a core [App] object which encapsulates all of the basic logic.
|
||||||
fn new(adw_app: &adw::Application, app: App) -> AppWindow {
|
fn new(adw_app: &adw::Application, app: App) -> AppWindow {
|
||||||
let window = adw::ApplicationWindow::builder()
|
|
||||||
.application(adw_app)
|
|
||||||
.width_request(800)
|
|
||||||
.height_request(600)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// GTK overlays aren't all that well documented. The Overlay object needs to be the
|
|
||||||
// content/child of the window. The main content should then be added to the overlay as
|
|
||||||
// `set_child`. The overlays/modals should be added as `add_overlay` and then removed with
|
|
||||||
// `remove_overlay`.
|
|
||||||
let overlay = gtk::Overlay::new();
|
|
||||||
window.set_content(Some(&overlay));
|
|
||||||
|
|
||||||
let current_view = if app.database.read().unwrap().is_none() {
|
|
||||||
let view = UnconfiguredView::new();
|
|
||||||
/*
|
|
||||||
overlay.set_child(Some(&view));
|
|
||||||
|
|
||||||
// I have to access the overlay directly here because I haven't fully constructed Self
|
|
||||||
// yet, and so I don't have access to `open_modal` yet.
|
|
||||||
*/
|
|
||||||
|
|
||||||
MainView::Unconfigured(view)
|
|
||||||
} else {
|
|
||||||
let view = HistoricalView::new();
|
|
||||||
/*
|
|
||||||
overlay.set_child(Some(&view));
|
|
||||||
*/
|
|
||||||
|
|
||||||
MainView::Historical(view)
|
|
||||||
};
|
|
||||||
|
|
||||||
let s = Self {
|
|
||||||
app,
|
|
||||||
window: window.clone(),
|
|
||||||
overlay,
|
|
||||||
current_view: RefCell::new(current_view),
|
|
||||||
modal: RefCell::new(None),
|
|
||||||
};
|
|
||||||
|
|
||||||
let stylesheet = String::from_utf8(
|
let stylesheet = String::from_utf8(
|
||||||
resources_lookup_data(
|
resources_lookup_data(
|
||||||
&format!("{}style.css", RESOURCE_BASE_PATH),
|
&format!("{}style.css", RESOURCE_BASE_PATH),
|
||||||
|
@ -214,28 +168,30 @@ impl AppWindow {
|
||||||
let provider = gtk::CssProvider::new();
|
let provider = gtk::CssProvider::new();
|
||||||
provider.load_from_data(&stylesheet);
|
provider.load_from_data(&stylesheet);
|
||||||
|
|
||||||
|
let window = adw::ApplicationWindow::builder()
|
||||||
|
.application(adw_app)
|
||||||
|
.width_request(800)
|
||||||
|
.height_request(600)
|
||||||
|
.build();
|
||||||
|
|
||||||
let context = window.style_context();
|
let context = window.style_context();
|
||||||
context.add_provider(&provider, STYLE_PROVIDER_PRIORITY_USER);
|
context.add_provider(&provider, STYLE_PROVIDER_PRIORITY_USER);
|
||||||
|
|
||||||
window.present();
|
window.present();
|
||||||
|
|
||||||
s.redraw();
|
// GTK overlays aren't all that well documented. The Overlay object needs to be the
|
||||||
|
// content/child of the window. The main content should then be added to the overlay as
|
||||||
|
// `add_overlay`. The overlays/modals should be added as `set_child`.
|
||||||
|
let overlay = gtk::Overlay::new();
|
||||||
|
window.set_content(Some(&overlay));
|
||||||
|
|
||||||
s
|
|
||||||
|
|
||||||
/*
|
|
||||||
let current_view = if app.database.read().unwrap().is_none() {
|
let current_view = if app.database.read().unwrap().is_none() {
|
||||||
let view = UnconfiguredView::new();
|
let view = UnconfiguredView::new();
|
||||||
overlay.set_child(Some(&view));
|
overlay.set_child(Some(&view));
|
||||||
|
|
||||||
// I have to access the overlay directly here because I haven't fully constructed Self
|
// I have to access the overlay directly here because I haven't fully constructed Self
|
||||||
// yet, and so I don't have access to `open_modal` yet.
|
// yet, and so I don't have access to `open_modal` yet.
|
||||||
overlay.add_overlay(&welcome_modal(|path| {
|
overlay.add_overlay(&welcome_modal());
|
||||||
// When a path gets selected, I want to set the path in the configuration system,
|
|
||||||
// and I want to open the database. After that, this window should be redrawn with
|
|
||||||
// its new state. So the view state also needs to change.
|
|
||||||
println!("path: {}", path.to_str().unwrap())
|
|
||||||
}));
|
|
||||||
|
|
||||||
MainView::Unconfigured(view)
|
MainView::Unconfigured(view)
|
||||||
} else {
|
} else {
|
||||||
|
@ -244,26 +200,24 @@ impl AppWindow {
|
||||||
|
|
||||||
MainView::HistoricalView(view)
|
MainView::HistoricalView(view)
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
|
Self {
|
||||||
|
app,
|
||||||
|
window,
|
||||||
|
overlay,
|
||||||
|
current_view,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn redraw(&self) {
|
/// Use [modal] as a modal overlay of the application window.
|
||||||
match *self.current_view.borrow() {
|
fn open_modal(&self, modal: Modal) {
|
||||||
MainView::Unconfigured(ref view) => {
|
self.overlay.set_child(Some(&modal));
|
||||||
self.overlay.set_child(Some(view));
|
|
||||||
|
|
||||||
let modal = welcome_modal(|path| {
|
|
||||||
// When a path gets selected, I want to set the path in the configuration system,
|
|
||||||
// and I want to open the database. After that, this window should be redrawn with
|
|
||||||
// its new state. So the view state also needs to change.
|
|
||||||
println!("path: {}", path.to_str().unwrap())
|
|
||||||
});
|
|
||||||
|
|
||||||
self.overlay.add_overlay(&modal);
|
|
||||||
*self.modal.borrow_mut() = Some(modal.upcast());
|
|
||||||
}
|
|
||||||
MainView::Historical(ref view) => self.overlay.set_child(Some(view)),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Close the modal by discarding the component.
|
||||||
|
fn close_modal(&self) {
|
||||||
|
let none: Option<>k::Widget> = None;
|
||||||
|
self.overlay.set_child(none);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,7 @@
|
||||||
//! component.
|
//! component.
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
use std::{
|
use std::cell::RefCell;
|
||||||
cell::RefCell,
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
rc::Rc,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct ModalPrivate {
|
pub struct ModalPrivate {
|
||||||
title: gtk::Label,
|
title: gtk::Label,
|
||||||
|
@ -26,17 +22,14 @@ impl ObjectSubclass for ModalPrivate {
|
||||||
type ParentType = gtk::Box;
|
type ParentType = gtk::Box;
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let title = gtk::Label::builder()
|
let title = gtk::Label::builder().label("Modal").build();
|
||||||
.label("Modal")
|
|
||||||
.css_classes(["modal-title"])
|
|
||||||
.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 primary_action = gtk::Button::builder().label("Primary").build();
|
let primary_action = gtk::Button::builder().label("Primary").build();
|
||||||
|
|
||||||
let footer = gtk::Box::builder()
|
let footer = gtk::Box::builder()
|
||||||
.orientation(gtk::Orientation::Horizontal)
|
.orientation(gtk::Orientation::Horizontal)
|
||||||
.hexpand(true)
|
.hexpand(true)
|
||||||
.css_classes(["modal-footer"])
|
|
||||||
.build();
|
.build();
|
||||||
footer.append(&primary_action);
|
footer.append(&primary_action);
|
||||||
|
|
||||||
|
@ -63,8 +56,11 @@ glib::wrapper! {
|
||||||
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_css_classes(&["modal"]);
|
|
||||||
|
|
||||||
|
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.set_orientation(gtk::Orientation::Vertical);
|
||||||
|
|
||||||
s.append(&s.imp().title);
|
s.append(&s.imp().title);
|
||||||
|
@ -80,9 +76,6 @@ impl Modal {
|
||||||
|
|
||||||
pub fn set_content(&self, content: gtk::Widget) {
|
pub fn set_content(&self, content: gtk::Widget) {
|
||||||
self.remove(&*self.imp().content.borrow());
|
self.remove(&*self.imp().content.borrow());
|
||||||
content.add_css_class("modal-content");
|
|
||||||
content.set_hexpand(true);
|
|
||||||
content.set_vexpand(true);
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -102,10 +95,7 @@ impl Modal {
|
||||||
/// database has not been configured yet.
|
/// database has not been configured yet.
|
||||||
///
|
///
|
||||||
/// This is a [Modal] component with all of the welcome content.
|
/// This is a [Modal] component with all of the welcome content.
|
||||||
pub fn welcome_modal<F>(database_selected: F) -> Modal
|
pub fn welcome_modal() -> Modal {
|
||||||
where
|
|
||||||
F: Fn(&Path) + 'static,
|
|
||||||
{
|
|
||||||
let modal = Modal::new();
|
let modal = Modal::new();
|
||||||
modal.set_title("Welcome to FitnessTrax");
|
modal.set_title("Welcome to FitnessTrax");
|
||||||
|
|
||||||
|
@ -115,106 +105,23 @@ where
|
||||||
.orientation(gtk::Orientation::Vertical)
|
.orientation(gtk::Orientation::Vertical)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let instructions = gtk::Label::builder()
|
content.append(>k::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.")));
|
||||||
.wrap(true)
|
|
||||||
.label("The application has not yet been configured, so I will walk you through that. Fortunately, it is very easy, and we only need to select the location for your database.").build();
|
|
||||||
content.append(&instructions);
|
|
||||||
|
|
||||||
let db_row = DatabaseFileChooserRow::new(database_selected);
|
// The database selection row should be a box that shows a default database path, along with a
|
||||||
content.append(&db_row);
|
// 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(
|
||||||
|
>k::Label::builder()
|
||||||
|
.label("No Path Selected")
|
||||||
|
.hexpand(true)
|
||||||
|
.build(),
|
||||||
|
);
|
||||||
|
db_row.append(>k::Button::builder().label("Select Database").build());
|
||||||
|
|
||||||
modal.set_content(content.upcast());
|
modal.set_content(content.upcast());
|
||||||
modal.set_primary_action(gtk::Button::builder().label("Save Settings").build());
|
modal.set_primary_action(gtk::Button::builder().label("Save Settings").build());
|
||||||
modal
|
modal
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DatabaseFileChooserRowPrivate {
|
|
||||||
path: RefCell<Option<PathBuf>>,
|
|
||||||
label: gtk::Label,
|
|
||||||
on_selected_: RefCell<Box<dyn Fn(&Path)>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[glib::object_subclass]
|
|
||||||
impl ObjectSubclass for DatabaseFileChooserRowPrivate {
|
|
||||||
const NAME: &'static str = "DatabaseFileChooser";
|
|
||||||
type Type = DatabaseFileChooserRow;
|
|
||||||
type ParentType = gtk::Box;
|
|
||||||
|
|
||||||
fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
path: RefCell::new(None),
|
|
||||||
label: gtk::Label::builder().hexpand(true).build(),
|
|
||||||
on_selected_: RefCell::new(Box::new(|_| {})),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ObjectImpl for DatabaseFileChooserRowPrivate {}
|
|
||||||
impl WidgetImpl for DatabaseFileChooserRowPrivate {}
|
|
||||||
impl BoxImpl for DatabaseFileChooserRowPrivate {}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub struct DatabaseFileChooserRow(ObjectSubclass<DatabaseFileChooserRowPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DatabaseFileChooserRow {
|
|
||||||
pub fn new<F>(database_selected: F) -> Self
|
|
||||||
where
|
|
||||||
F: Fn(&Path) + 'static,
|
|
||||||
{
|
|
||||||
let s: Self = Object::builder().build();
|
|
||||||
|
|
||||||
s.set_orientation(gtk::Orientation::Horizontal);
|
|
||||||
|
|
||||||
// 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");
|
|
||||||
|
|
||||||
*s.imp().on_selected_.borrow_mut() = Box::new(database_selected);
|
|
||||||
|
|
||||||
let db_file_chooser_button = gtk::Button::builder().label("Select Database").build();
|
|
||||||
db_file_chooser_button.connect_clicked({
|
|
||||||
let s = s.clone();
|
|
||||||
move |_| {
|
|
||||||
let no_window: Option<>k::Window> = None;
|
|
||||||
let not_cancellable: Option<&gio::Cancellable> = None;
|
|
||||||
let s = s.clone();
|
|
||||||
gtk::FileDialog::builder().build().open(
|
|
||||||
no_window,
|
|
||||||
not_cancellable,
|
|
||||||
move |file_id| s.on_selected(file_id),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
s.append(&s.imp().label);
|
|
||||||
s.append(&db_file_chooser_button);
|
|
||||||
|
|
||||||
s
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_selected(&self, m_file_id: Result<gio::File, glib::Error>) {
|
|
||||||
match m_file_id {
|
|
||||||
Ok(file_id) => {
|
|
||||||
println!("The user selected {:?}", file_id.path());
|
|
||||||
*self.imp().path.borrow_mut() = file_id.path();
|
|
||||||
match *self.imp().path.borrow() {
|
|
||||||
Some(ref path) => {
|
|
||||||
(*self.imp().on_selected_.borrow())(path);
|
|
||||||
self.redraw();
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => println!("file opening failed: {}", err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn redraw(&self) {
|
|
||||||
match *self.imp().path.borrow() {
|
|
||||||
Some(ref path) => self.imp().label.set_text(path.to_str().unwrap()),
|
|
||||||
None => self.imp().label.set_text("No database selected"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue