Compare commits
5 Commits
22ba4f575d
...
c1ca4c591b
Author | SHA1 | Date |
---|---|---|
Savanni D'Gerinel | c1ca4c591b | |
Savanni D'Gerinel | 28505c15cb | |
Savanni D'Gerinel | 9354e3bd8a | |
Savanni D'Gerinel | aaca733a4c | |
Savanni D'Gerinel | 9c27610cb9 |
|
@ -1026,6 +1026,7 @@ dependencies = [
|
|||
"dimensioned 0.8.0",
|
||||
"emseries",
|
||||
"ft-core",
|
||||
"gdk4",
|
||||
"gio",
|
||||
"glib",
|
||||
"glib-build-tools 0.18.0",
|
||||
|
@ -1941,6 +1942,16 @@ dependencies = [
|
|||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icon-test"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"gio",
|
||||
"glib",
|
||||
"gtk4",
|
||||
"libadwaita",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.1.5"
|
||||
|
|
|
@ -16,6 +16,7 @@ members = [
|
|||
"geo-types",
|
||||
"gm-control-panel",
|
||||
"hex-grid",
|
||||
"icon-test",
|
||||
"ifc",
|
||||
"kifu/core",
|
||||
"kifu/gtk",
|
||||
|
|
|
@ -15,6 +15,7 @@ emseries = { path = "../../emseries" }
|
|||
ft-core = { path = "../core" }
|
||||
gio = { version = "0.18" }
|
||||
glib = { version = "0.18" }
|
||||
gdk = { version = "0.7", package = "gdk4" }
|
||||
gtk = { version = "0.7", package = "gtk4", features = [ "v4_10" ] }
|
||||
thiserror = { version = "1.0" }
|
||||
tokio = { version = "1.34", features = [ "full" ] }
|
||||
|
|
|
@ -3,4 +3,11 @@
|
|||
<gresource prefix="/com/luminescent-dreams/fitnesstrax/">
|
||||
<file>style.css</file>
|
||||
</gresource>
|
||||
<gresource prefix="/com/luminescent-dreams/fitnesstrax/icons/scalable/actions/">
|
||||
<file preprocess="xml-stripblanks">walking2-symbolic.svg</file>
|
||||
</gresource>
|
||||
|
||||
<gresource prefix="/com/luminescent-dreams/fitnesstrax/icons/scalable/actions">
|
||||
<file preprocess="xml-stripblanks">running-symbolic.svg</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/org/gtk/example/icons/scalable/actions/">
|
||||
<file preprocess="xml-stripblanks">start-here-symbolic.svg</file>
|
||||
</gresource>
|
||||
</gresources>
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="16px" viewBox="0 0 16 16" width="16px"><filter id="a" height="100%" width="100%" x="0%" y="0%"><feColorMatrix color-interpolation-filters="sRGB" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/></filter><mask id="b"><g filter="url(#a)"><path d="m -1.6 -1.6 h 19.2 v 19.2 h -19.2 z" fill-opacity="0.5"/></g></mask><clipPath id="c"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><mask id="d"><g filter="url(#a)"><path d="m -1.6 -1.6 h 19.2 v 19.2 h -19.2 z" fill-opacity="0.7"/></g></mask><clipPath id="e"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><mask id="f"><g filter="url(#a)"><path d="m -1.6 -1.6 h 19.2 v 19.2 h -19.2 z" fill-opacity="0.35"/></g></mask><clipPath id="g"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><path d="m 8.5 0 c -0.828125 0 -1.5 0.671875 -1.5 1.5 s 0.671875 1.5 1.5 1.5 s 1.5 -0.671875 1.5 -1.5 s -0.671875 -1.5 -1.5 -1.5 z m -2.5 4 c -0.117188 0 -0.230469 0.027344 -0.335938 0.082031 l -2 1 c -0.144531 0.070313 -0.261718 0.1875 -0.332031 0.332031 l -1 2 c -0.1875 0.371094 -0.039062 0.820313 0.332031 1.007813 c 0.371094 0.183594 0.820313 0.035156 1.003907 -0.335937 l 0.890625 -1.777344 l 1.5625 -0.773438 c -0.042969 0.074219 -0.726563 2.835938 -0.726563 2.835938 c -0.230469 0.949218 0.398438 1.523437 0.398438 1.523437 l 3.351562 2.703125 l 0.90625 2.71875 c 0.175781 0.523438 0.742188 0.808594 1.265625 0.632813 c 0.523438 -0.175781 0.808594 -0.742188 0.632813 -1.265625 l -1 -3 c -0.0625 -0.183594 -0.171875 -0.34375 -0.324219 -0.464844 l -2 -1.597656 l 0.679688 -2.714844 l 0.25 0.625 c 0.085937 0.222656 0.28125 0.390625 0.515624 0.449219 l 2 0.5 c 0.402344 0.097656 0.808594 -0.144531 0.910157 -0.546875 c 0.097656 -0.40625 -0.144531 -0.8125 -0.546875 -0.910156 l -1.628906 -0.40625 l -0.855469 -2.144532 c -0.117188 -0.285156 -0.390625 -0.472656 -0.699219 -0.472656 z m -1.164062 6.328125 l -0.710938 2.128906 l -1.832031 1.835938 c -0.390625 0.390625 -0.390625 1.023437 0 1.414062 s 1.023437 0.390625 1.414062 0 l 2 -2 c 0.109375 -0.109375 0.191407 -0.242187 0.242188 -0.390625 l 0.542969 -1.628906 z m 0 0"/><g mask="url(#b)"><g clip-path="url(#c)" transform="matrix(1 0 0 1 -620 -120)"><path d="m 550 182 c -0.351562 0.003906 -0.695312 0.101562 -1 0.28125 v 3.4375 c 0.304688 0.179688 0.648438 0.277344 1 0.28125 c 1.105469 0 2 -0.894531 2 -2 s -0.894531 -2 -2 -2 z m 0 5 c -0.339844 0 -0.679688 0.058594 -1 0.175781 v 6.824219 h 4 v -4 c 0 -1.65625 -1.34375 -3 -3 -3 z m 0 0"/></g></g><g mask="url(#d)"><g clip-path="url(#e)" transform="matrix(1 0 0 1 -620 -120)"><path d="m 569 182 v 4 c 1.105469 0 2 -0.894531 2 -2 s -0.894531 -2 -2 -2 z m 0 5 v 7 h 3 v -4 c 0 -1.65625 -1.34375 -3 -3 -3 z m 0 0"/></g></g><g mask="url(#f)"><g clip-path="url(#g)" transform="matrix(1 0 0 1 -620 -120)"><path d="m 573 182.269531 v 3.449219 c 0.613281 -0.355469 0.996094 -1.007812 1 -1.71875 c 0 -0.714844 -0.382812 -1.375 -1 -1.730469 z m 0 4.90625 v 6.824219 h 2 v -4 c 0 -1.269531 -0.800781 -2.402344 -2 -2.824219 z m 0 0"/></g></g></svg>
|
After Width: | Height: | Size: 3.0 KiB |
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="16px" viewBox="0 0 16 16" width="16px"><filter id="a" height="100%" width="100%" x="0%" y="0%"><feColorMatrix color-interpolation-filters="sRGB" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/></filter><mask id="b"><g filter="url(#a)"><path d="m -1.6 -1.6 h 19.2 v 19.2 h -19.2 z" fill-opacity="0.5"/></g></mask><clipPath id="c"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><mask id="d"><g filter="url(#a)"><path d="m -1.6 -1.6 h 19.2 v 19.2 h -19.2 z" fill-opacity="0.7"/></g></mask><clipPath id="e"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><mask id="f"><g filter="url(#a)"><path d="m -1.6 -1.6 h 19.2 v 19.2 h -19.2 z" fill-opacity="0.35"/></g></mask><clipPath id="g"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><path d="m 9.5 1.5 c 0 0.828125 -0.671875 1.5 -1.5 1.5 s -1.5 -0.671875 -1.5 -1.5 s 0.671875 -1.5 1.5 -1.5 s 1.5 0.671875 1.5 1.5 z m 0 0"/><path d="m 7 4 c -0.550781 0 -1 0.449219 -1 1 v 4 c 0 0.265625 0.105469 0.519531 0.292969 0.707031 l 0.445312 0.449219 l -2.59375 4.328125 c -0.285156 0.476563 -0.132812 1.089844 0.34375 1.375 c 0.472657 0.28125 1.085938 0.128906 1.367188 -0.34375 l 2.34375 -3.902344 l 0.925781 0.929688 l 0.925781 2.773437 c 0.082031 0.25 0.265625 0.460938 0.5 0.578125 c 0.238281 0.121094 0.515625 0.140625 0.765625 0.054688 c 0.25 -0.082031 0.460938 -0.265625 0.578125 -0.5 c 0.121094 -0.238281 0.140625 -0.515625 0.054688 -0.765625 l -1 -3 c -0.050781 -0.148438 -0.132813 -0.28125 -0.242188 -0.390625 l -1.707031 -1.707031 v -4.585938 c 0 -0.550781 -0.449219 -1 -1 -1 z m 0 0"/><path d="m 6 4 c -0.101562 0 -0.207031 0.019531 -0.300781 0.0625 c 0 0 -2.113281 0.847656 -2.199219 2.90625 v 0.03125 v 2.25 c 0 0.414062 0.335938 0.75 0.75 0.75 s 0.75 -0.335938 0.75 -0.75 v -2.21875 c 0.039062 -0.894531 1.050781 -1.449219 1.207031 -1.53125 h 2.332031 l 1.042969 2.085938 c 0.097657 0.195312 0.273438 0.339843 0.488281 0.394531 l 2 0.5 c 0.191407 0.046875 0.394532 0.015625 0.566407 -0.085938 c 0.171875 -0.101562 0.292969 -0.269531 0.34375 -0.460937 c 0.046875 -0.195313 0.015625 -0.398438 -0.085938 -0.570313 c -0.101562 -0.171875 -0.269531 -0.292969 -0.464843 -0.34375 l -1.664063 -0.414062 l -1.097656 -2.191407 c -0.125 -0.253906 -0.382813 -0.414062 -0.667969 -0.414062 z m 0 0"/><g mask="url(#b)"><g clip-path="url(#c)" transform="matrix(1 0 0 1 -620 -100)"><path d="m 550 182 c -0.351562 0.003906 -0.695312 0.101562 -1 0.28125 v 3.4375 c 0.304688 0.179688 0.648438 0.277344 1 0.28125 c 1.105469 0 2 -0.894531 2 -2 s -0.894531 -2 -2 -2 z m 0 5 c -0.339844 0 -0.679688 0.058594 -1 0.175781 v 6.824219 h 4 v -4 c 0 -1.65625 -1.34375 -3 -3 -3 z m 0 0"/></g></g><g mask="url(#d)"><g clip-path="url(#e)" transform="matrix(1 0 0 1 -620 -100)"><path d="m 569 182 v 4 c 1.105469 0 2 -0.894531 2 -2 s -0.894531 -2 -2 -2 z m 0 5 v 7 h 3 v -4 c 0 -1.65625 -1.34375 -3 -3 -3 z m 0 0"/></g></g><g mask="url(#f)"><g clip-path="url(#g)" transform="matrix(1 0 0 1 -620 -100)"><path d="m 573 182.269531 v 3.449219 c 0.613281 -0.355469 0.996094 -1.007812 1 -1.71875 c 0 -0.714844 -0.382812 -1.375 -1 -1.730469 z m 0 4.90625 v 6.824219 h 2 v -4 c 0 -1.269531 -0.800781 -2.402344 -2 -2.824219 z m 0 0"/></g></g></svg>
|
After Width: | Height: | Size: 3.2 KiB |
|
@ -54,7 +54,7 @@ impl AppWindow {
|
|||
let window = adw::ApplicationWindow::builder()
|
||||
.application(adw_app)
|
||||
.width_request(800)
|
||||
.height_request(600)
|
||||
.height_request(746)
|
||||
.build();
|
||||
|
||||
let stylesheet = String::from_utf8(
|
||||
|
|
|
@ -17,13 +17,17 @@ You should have received a copy of the GNU General Public License along with Fit
|
|||
// use chrono::NaiveDate;
|
||||
// use ft_core::TraxRecord;
|
||||
use crate::{
|
||||
components::{steps_editor, weight_editor, ActionGroup, Steps, Weight},
|
||||
components::{steps_editor, time_distance_summary, weight_editor, ActionGroup, Steps, Weight},
|
||||
view_models::DayDetailViewModel,
|
||||
};
|
||||
use dimensioned::si;
|
||||
use ft_core::{RecordType, TraxRecord};
|
||||
use glib::Object;
|
||||
use gtk::{prelude::*, subclass::prelude::*};
|
||||
use std::cell::RefCell;
|
||||
|
||||
use super::time_distance_detail;
|
||||
|
||||
pub struct DaySummaryPrivate {
|
||||
date: gtk::Label,
|
||||
}
|
||||
|
@ -96,8 +100,10 @@ impl DaySummary {
|
|||
label.set_label(&format!("{} steps", s.to_string()));
|
||||
}
|
||||
row.append(&label);
|
||||
|
||||
self.append(&row);
|
||||
|
||||
let biking_summary = view_model.biking_summary();
|
||||
time_distance_summary(biking_summary.0, biking_summary.1).map(|label| self.append(&label));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,51 +176,18 @@ impl DayDetail {
|
|||
|
||||
s.append(&top_row);
|
||||
|
||||
/*
|
||||
records.into_iter().for_each(|record| {
|
||||
let record_view = match record {
|
||||
Record {
|
||||
data: ft_core::TraxRecord::BikeRide(record),
|
||||
..
|
||||
} => Some(
|
||||
TimeDistanceView::new(ft_core::RecordType::BikeRide, record)
|
||||
.upcast::<gtk::Widget>(),
|
||||
),
|
||||
Record {
|
||||
data: ft_core::TraxRecord::Row(record),
|
||||
..
|
||||
} => Some(
|
||||
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
|
||||
),
|
||||
Record {
|
||||
data: ft_core::TraxRecord::Run(record),
|
||||
..
|
||||
} => Some(
|
||||
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
|
||||
),
|
||||
Record {
|
||||
data: ft_core::TraxRecord::Swim(record),
|
||||
..
|
||||
} => Some(
|
||||
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
|
||||
),
|
||||
Record {
|
||||
data: ft_core::TraxRecord::Walk(record),
|
||||
..
|
||||
} => Some(
|
||||
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
|
||||
),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(record_view) = record_view {
|
||||
record_view.add_css_class("day-detail");
|
||||
record_view.set_halign(gtk::Align::Start);
|
||||
|
||||
s.append(&record_view);
|
||||
let records = view_model.records();
|
||||
for emseries::Record { data, .. } in records {
|
||||
match data {
|
||||
TraxRecord::BikeRide(ride) => {
|
||||
s.append(&time_distance_detail(RecordType::BikeRide, ride))
|
||||
}
|
||||
TraxRecord::Row(row) => s.append(&time_distance_detail(RecordType::Row, row)),
|
||||
TraxRecord::Run(run) => s.append(&time_distance_detail(RecordType::Run, run)),
|
||||
TraxRecord::Walk(walk) => s.append(&time_distance_detail(RecordType::Walk, walk)),
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
s
|
||||
}
|
||||
|
@ -255,51 +228,11 @@ impl DayEdit {
|
|||
let s: Self = Object::builder().build();
|
||||
s.set_orientation(gtk::Orientation::Vertical);
|
||||
s.set_hexpand(true);
|
||||
|
||||
*s.imp().on_finished.borrow_mut() = Box::new(on_finished);
|
||||
|
||||
s.append(
|
||||
&ActionGroup::builder()
|
||||
.primary_action("Save", {
|
||||
let s = s.clone();
|
||||
let view_model = view_model.clone();
|
||||
move || {
|
||||
view_model.save();
|
||||
s.finish();
|
||||
}
|
||||
})
|
||||
.secondary_action("Cancel", {
|
||||
let s = s.clone();
|
||||
let view_model = view_model.clone();
|
||||
move || {
|
||||
view_model.revert();
|
||||
s.finish();
|
||||
}
|
||||
})
|
||||
.build(),
|
||||
);
|
||||
|
||||
let top_row = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
.build();
|
||||
top_row.append(
|
||||
&weight_editor(view_model.weight(), {
|
||||
let view_model = view_model.clone();
|
||||
move |w| {
|
||||
view_model.set_weight(w);
|
||||
}
|
||||
})
|
||||
.widget(),
|
||||
);
|
||||
|
||||
top_row.append(
|
||||
&steps_editor(view_model.steps(), {
|
||||
let view_model = view_model.clone();
|
||||
move |s| view_model.set_steps(s)
|
||||
})
|
||||
.widget(),
|
||||
);
|
||||
s.append(&top_row);
|
||||
s.append(&control_buttons(&s, &view_model));
|
||||
s.append(&weight_and_steps_row(&view_model));
|
||||
s.append(&workout_buttons());
|
||||
|
||||
s
|
||||
}
|
||||
|
@ -308,3 +241,82 @@ impl DayEdit {
|
|||
(self.imp().on_finished.borrow())()
|
||||
}
|
||||
}
|
||||
|
||||
fn control_buttons(s: &DayEdit, view_model: &DayDetailViewModel) -> ActionGroup {
|
||||
ActionGroup::builder()
|
||||
.primary_action("Save", {
|
||||
let s = s.clone();
|
||||
let view_model = view_model.clone();
|
||||
move || {
|
||||
view_model.save();
|
||||
s.finish();
|
||||
}
|
||||
})
|
||||
.secondary_action("Cancel", {
|
||||
let s = s.clone();
|
||||
let view_model = view_model.clone();
|
||||
move || {
|
||||
view_model.revert();
|
||||
s.finish();
|
||||
}
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
||||
fn weight_and_steps_row(view_model: &DayDetailViewModel) -> gtk::Box {
|
||||
let row = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
.build();
|
||||
row.append(
|
||||
&weight_editor(view_model.weight(), {
|
||||
let view_model = view_model.clone();
|
||||
move |w| {
|
||||
view_model.set_weight(w);
|
||||
}
|
||||
})
|
||||
.widget(),
|
||||
);
|
||||
|
||||
row.append(
|
||||
&steps_editor(view_model.steps(), {
|
||||
let view_model = view_model.clone();
|
||||
move |s| view_model.set_steps(s)
|
||||
})
|
||||
.widget(),
|
||||
);
|
||||
|
||||
row
|
||||
}
|
||||
|
||||
fn workout_buttons() -> gtk::Box {
|
||||
let sunrise_button = gtk::Button::builder()
|
||||
.icon_name("daytime-sunrise-symbolic")
|
||||
.width_request(64)
|
||||
.height_request(64)
|
||||
.build();
|
||||
|
||||
let walking_button = gtk::Button::builder()
|
||||
.icon_name("walking2-symbolic")
|
||||
.width_request(64)
|
||||
.height_request(64)
|
||||
.build();
|
||||
|
||||
let running_button = gtk::Button::builder()
|
||||
.icon_name("running-symbolic")
|
||||
.width_request(64)
|
||||
.height_request(64)
|
||||
.build();
|
||||
|
||||
let layout = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Vertical)
|
||||
.build();
|
||||
let row = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
.build();
|
||||
row.append(&sunrise_button);
|
||||
row.append(&walking_button);
|
||||
row.append(&running_button);
|
||||
layout.append(&row);
|
||||
|
||||
layout
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ mod text_entry;
|
|||
pub use text_entry::{ParseError, TextEntry};
|
||||
|
||||
mod time_distance;
|
||||
pub use time_distance::TimeDistanceView;
|
||||
pub use time_distance::{time_distance_detail, time_distance_summary};
|
||||
|
||||
mod weight;
|
||||
pub use weight::{weight_editor, Weight};
|
||||
|
|
|
@ -17,92 +17,90 @@ You should have received a copy of the GNU General Public License along with Fit
|
|||
// use crate::components::{EditView, ParseError, TextEntry};
|
||||
// use chrono::{Local, NaiveDate};
|
||||
// use dimensioned::si;
|
||||
use dimensioned::si;
|
||||
use ft_core::{RecordType, TimeDistance};
|
||||
use glib::Object;
|
||||
use gtk::{prelude::*, subclass::prelude::*};
|
||||
use std::cell::RefCell;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TimeDistanceViewPrivate {
|
||||
#[allow(unused)]
|
||||
record: RefCell<Option<TimeDistance>>,
|
||||
pub fn time_distance_summary(
|
||||
distance: si::Meter<f64>,
|
||||
duration: si::Second<f64>,
|
||||
) -> Option<gtk::Label> {
|
||||
let text = match (distance > si::M, duration > si::S) {
|
||||
(true, true) => Some(format!(
|
||||
"{} kilometers of biking in {} minutes",
|
||||
distance.value_unsafe / 1000.,
|
||||
duration.value_unsafe / 60.
|
||||
)),
|
||||
(true, false) => Some(format!(
|
||||
"{} kilometers of biking",
|
||||
distance.value_unsafe / 1000.
|
||||
)),
|
||||
(false, true) => Some(format!("{} seconds of biking", duration.value_unsafe / 60.)),
|
||||
(false, false) => None,
|
||||
};
|
||||
|
||||
text.map(|text| gtk::Label::new(Some(&text)))
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for TimeDistanceViewPrivate {
|
||||
const NAME: &'static str = "TimeDistanceView";
|
||||
type Type = TimeDistanceView;
|
||||
type ParentType = gtk::Box;
|
||||
}
|
||||
|
||||
impl ObjectImpl for TimeDistanceViewPrivate {}
|
||||
impl WidgetImpl for TimeDistanceViewPrivate {}
|
||||
impl BoxImpl for TimeDistanceViewPrivate {}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct TimeDistanceView(ObjectSubclass<TimeDistanceViewPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
||||
}
|
||||
|
||||
impl TimeDistanceView {
|
||||
pub fn new(type_: RecordType, record: TimeDistance) -> Self {
|
||||
let s: Self = Object::builder().build();
|
||||
s.set_orientation(gtk::Orientation::Vertical);
|
||||
s.set_hexpand(true);
|
||||
|
||||
let first_row = gtk::Box::builder().homogeneous(true).build();
|
||||
|
||||
first_row.append(
|
||||
>k::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label(record.datetime.format("%H:%M").to_string())
|
||||
.build(),
|
||||
);
|
||||
|
||||
first_row.append(
|
||||
>k::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label(format!("{:?}", type_))
|
||||
.build(),
|
||||
);
|
||||
|
||||
first_row.append(
|
||||
>k::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label(
|
||||
record
|
||||
.distance
|
||||
.map(|dist| format!("{}", dist))
|
||||
.unwrap_or("".to_owned()),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
|
||||
first_row.append(
|
||||
>k::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label(
|
||||
record
|
||||
.duration
|
||||
.map(|duration| format!("{}", duration))
|
||||
.unwrap_or("".to_owned()),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
|
||||
s.append(&first_row);
|
||||
|
||||
s.append(
|
||||
>k::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label(
|
||||
record
|
||||
.comments
|
||||
.map(|comments| comments.to_string())
|
||||
.unwrap_or("".to_owned()),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
|
||||
s
|
||||
}
|
||||
pub fn time_distance_detail(type_: ft_core::RecordType, record: ft_core::TimeDistance) -> gtk::Box {
|
||||
let layout = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Vertical)
|
||||
.hexpand(true)
|
||||
.build();
|
||||
let first_row = gtk::Box::builder().homogeneous(true).build();
|
||||
|
||||
first_row.append(
|
||||
>k::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label(record.datetime.format("%H:%M").to_string())
|
||||
.build(),
|
||||
);
|
||||
|
||||
first_row.append(
|
||||
>k::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label(format!("{:?}", type_))
|
||||
.build(),
|
||||
);
|
||||
|
||||
first_row.append(
|
||||
>k::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label(
|
||||
record
|
||||
.distance
|
||||
.map(|dist| format!("{}", dist))
|
||||
.unwrap_or("".to_owned()),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
|
||||
first_row.append(
|
||||
>k::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label(
|
||||
record
|
||||
.duration
|
||||
.map(|duration| format!("{}", duration))
|
||||
.unwrap_or("".to_owned()),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
|
||||
layout.append(&first_row);
|
||||
|
||||
layout.append(
|
||||
>k::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label(
|
||||
record
|
||||
.comments
|
||||
.map(|comments| comments.to_string())
|
||||
.unwrap_or("".to_owned()),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
layout
|
||||
}
|
||||
|
|
|
@ -60,6 +60,9 @@ fn main() {
|
|||
.build();
|
||||
|
||||
adw_app.connect_activate(move |adw_app| {
|
||||
let icon_theme = gtk::IconTheme::for_display(&gdk::Display::default().unwrap());
|
||||
icon_theme.add_resource_path(&(RESOURCE_BASE_PATH.to_owned() + "/icons/scalable/actions"));
|
||||
|
||||
AppWindow::new(app_id, RESOURCE_BASE_PATH, adw_app, ft_app.clone());
|
||||
});
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Fit
|
|||
use crate::app::App;
|
||||
use dimensioned::si;
|
||||
use emseries::{Record, RecordId, Recordable};
|
||||
use ft_core::TraxRecord;
|
||||
use ft_core::{TimeDistance, TraxRecord};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
ops::Deref,
|
||||
|
@ -44,6 +44,15 @@ impl<T: Clone + emseries::Recordable> RecordState<T> {
|
|||
}
|
||||
}
|
||||
|
||||
fn data(&self) -> Option<&Record<T>> {
|
||||
match self {
|
||||
RecordState::Original(ref r) => Some(&r),
|
||||
RecordState::New(ref r) => None,
|
||||
RecordState::Updated(ref r) => Some(&r),
|
||||
RecordState::Deleted(ref r) => Some(&r),
|
||||
}
|
||||
}
|
||||
|
||||
fn with_value(self, value: T) -> RecordState<T> {
|
||||
match self {
|
||||
RecordState::Original(r) => RecordState::Updated(Record { data: value, ..r }),
|
||||
|
@ -86,43 +95,24 @@ pub struct DayDetailViewModel {
|
|||
weight: Arc<RwLock<Option<RecordState<ft_core::Weight>>>>,
|
||||
steps: Arc<RwLock<Option<RecordState<ft_core::Steps>>>>,
|
||||
records: Arc<RwLock<HashMap<RecordId, RecordState<TraxRecord>>>>,
|
||||
|
||||
original_records: Vec<Record<TraxRecord>>,
|
||||
}
|
||||
|
||||
impl DayDetailViewModel {
|
||||
pub fn new(date: chrono::NaiveDate, records: Vec<Record<TraxRecord>>, app: App) -> Self {
|
||||
let (weight_records, records): (Vec<Record<TraxRecord>>, Vec<Record<TraxRecord>>) =
|
||||
records.into_iter().partition(|r| r.data.is_weight());
|
||||
let (step_records, records): (Vec<Record<TraxRecord>>, Vec<Record<TraxRecord>>) =
|
||||
records.into_iter().partition(|r| r.data.is_steps());
|
||||
Self {
|
||||
let s = Self {
|
||||
app: Some(app),
|
||||
date,
|
||||
weight: Arc::new(RwLock::new(
|
||||
weight_records
|
||||
.first()
|
||||
.and_then(|r| match r.data {
|
||||
TraxRecord::Weight(ref w) => Some((r.id.clone(), w.clone())),
|
||||
_ => None,
|
||||
})
|
||||
.map(|(id, w)| RecordState::Original(Record { id, data: w })),
|
||||
)),
|
||||
steps: Arc::new(RwLock::new(
|
||||
step_records
|
||||
.first()
|
||||
.and_then(|r| match r.data {
|
||||
TraxRecord::Steps(ref w) => Some((r.id.clone(), w.clone())),
|
||||
_ => None,
|
||||
})
|
||||
.map(|(id, w)| RecordState::Original(Record { id, data: w })),
|
||||
)),
|
||||
|
||||
records: Arc::new(RwLock::new(
|
||||
records
|
||||
.into_iter()
|
||||
.map(|r| (r.id.clone(), RecordState::Original(r)))
|
||||
.collect::<HashMap<RecordId, RecordState<TraxRecord>>>(),
|
||||
)),
|
||||
}
|
||||
weight: Arc::new(RwLock::new(None)),
|
||||
steps: Arc::new(RwLock::new(None)),
|
||||
records: Arc::new(RwLock::new(HashMap::new())),
|
||||
|
||||
original_records: records,
|
||||
};
|
||||
s.populate_records();
|
||||
s
|
||||
}
|
||||
|
||||
pub fn weight(&self) -> Option<si::Kilogram<f64>> {
|
||||
|
@ -163,6 +153,40 @@ impl DayDetailViewModel {
|
|||
*record = Some(new_record);
|
||||
}
|
||||
|
||||
pub fn biking_summary(&self) -> (si::Meter<f64>, si::Second<f64>) {
|
||||
self.records.read().unwrap().iter().fold(
|
||||
(0. * si::M, 0. * si::S),
|
||||
|(acc_distance, acc_duration), (_, record)| match record.data() {
|
||||
Some(Record {
|
||||
data:
|
||||
TraxRecord::BikeRide(TimeDistance {
|
||||
distance, duration, ..
|
||||
}),
|
||||
..
|
||||
}) => (
|
||||
distance
|
||||
.map(|distance| acc_distance + distance)
|
||||
.unwrap_or(acc_distance),
|
||||
(duration
|
||||
.map(|duration| acc_duration + duration)
|
||||
.unwrap_or(acc_duration)),
|
||||
),
|
||||
|
||||
_ => (acc_distance, acc_duration),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn records(&self) -> Vec<Record<TraxRecord>> {
|
||||
let read_lock = self.records.read().unwrap();
|
||||
read_lock
|
||||
.iter()
|
||||
.map(|(_, record_state)| record_state.data())
|
||||
.filter_map(|r| r)
|
||||
.cloned()
|
||||
.collect::<Vec<Record<TraxRecord>>>()
|
||||
}
|
||||
|
||||
pub fn save(&self) {
|
||||
glib::spawn_future({
|
||||
let s = self.clone();
|
||||
|
@ -230,6 +254,64 @@ impl DayDetailViewModel {
|
|||
}
|
||||
|
||||
pub fn revert(&self) {
|
||||
unimplemented!();
|
||||
self.populate_records();
|
||||
}
|
||||
|
||||
fn populate_records(&self) {
|
||||
let records = self.original_records.clone();
|
||||
|
||||
let (weight_records, records): (Vec<Record<TraxRecord>>, Vec<Record<TraxRecord>>) =
|
||||
records.into_iter().partition(|r| r.data.is_weight());
|
||||
let (step_records, records): (Vec<Record<TraxRecord>>, Vec<Record<TraxRecord>>) =
|
||||
records.into_iter().partition(|r| r.data.is_steps());
|
||||
|
||||
*self.weight.write().unwrap() = weight_records
|
||||
.first()
|
||||
.and_then(|r| match r.data {
|
||||
TraxRecord::Weight(ref w) => Some((r.id.clone(), w.clone())),
|
||||
_ => None,
|
||||
})
|
||||
.map(|(id, w)| RecordState::Original(Record { id, data: w }));
|
||||
|
||||
*self.steps.write().unwrap() = step_records
|
||||
.first()
|
||||
.and_then(|r| match r.data {
|
||||
TraxRecord::Steps(ref w) => Some((r.id.clone(), w.clone())),
|
||||
_ => None,
|
||||
})
|
||||
.map(|(id, w)| RecordState::Original(Record { id, data: w }));
|
||||
|
||||
*self.records.write().unwrap() = records
|
||||
.into_iter()
|
||||
.map(|r| (r.id.clone(), RecordState::Original(r)))
|
||||
.collect::<HashMap<RecordId, RecordState<TraxRecord>>>();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
struct SavedRecordIterator<'a> {
|
||||
read_lock: RwLockReadGuard<'a, HashMap<RecordId, RecordState<TraxRecord>>>,
|
||||
iter: Box<dyn Iterator<Item = &'a Record<TraxRecord>> + 'a>,
|
||||
}
|
||||
|
||||
impl<'a> SavedRecordIterator<'a> {
|
||||
fn new(records: Arc<RwLock<HashMap<RecordId, RecordState<TraxRecord>>>>) -> Self {
|
||||
let read_lock = records.read().unwrap();
|
||||
let iter = read_lock
|
||||
.iter()
|
||||
.map(|(_, record_state)| record_state.data())
|
||||
.filter_map(|r| r);
|
||||
Self {
|
||||
read_lock,
|
||||
iter: Box::new(iter),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for SavedRecordIterator<'a> {
|
||||
type Item = &'a Record<TraxRecord>;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
None
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -118,6 +118,14 @@ impl TraxRecord {
|
|||
pub fn is_steps(&self) -> bool {
|
||||
matches!(self, TraxRecord::Steps(_))
|
||||
}
|
||||
|
||||
pub fn is_bike_ride(&self) -> bool {
|
||||
matches!(self, TraxRecord::BikeRide(_))
|
||||
}
|
||||
|
||||
pub fn is_run(&self) -> bool {
|
||||
matches!(self, TraxRecord::Run(_))
|
||||
}
|
||||
}
|
||||
|
||||
impl Recordable for TraxRecord {
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
pkgs.gst_all_1.gstreamer
|
||||
pkgs.gtk4
|
||||
pkgs.libadwaita
|
||||
pkgs.librsvg
|
||||
pkgs.nodejs
|
||||
pkgs.openssl
|
||||
pkgs.pipewire
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "icon-test"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
adw = { version = "0.5", package = "libadwaita", features = [ "v1_4" ] }
|
||||
gio = { version = "0.18" }
|
||||
glib = { version = "0.18" }
|
||||
gtk = { version = "0.7", package = "gtk4", features = [ "v4_10" ] }
|
|
@ -0,0 +1,38 @@
|
|||
use adw::prelude::*;
|
||||
|
||||
fn main() {
|
||||
let adw_app = adw::Application::builder().build();
|
||||
|
||||
adw_app.connect_activate(move |adw_app| {
|
||||
let window = gtk::ApplicationWindow::builder()
|
||||
.application(adw_app)
|
||||
.width_request(400)
|
||||
.height_request(400)
|
||||
.build();
|
||||
|
||||
let sunrise_button = gtk::Button::builder()
|
||||
.icon_name("daytime-sunrise-symbolic")
|
||||
.width_request(64)
|
||||
.height_request(64)
|
||||
.build();
|
||||
|
||||
let walking_button = gtk::Button::builder()
|
||||
.icon_name("walking2-symbolic")
|
||||
.width_request(64)
|
||||
.height_request(64)
|
||||
.build();
|
||||
|
||||
let layout = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
.valign(gtk::Align::Start)
|
||||
.build();
|
||||
layout.append(&sunrise_button);
|
||||
layout.append(&walking_button);
|
||||
|
||||
window.set_child(Some(&layout));
|
||||
window.present();
|
||||
});
|
||||
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
ApplicationExtManual::run_with_args(&adw_app, &args);
|
||||
}
|
Loading…
Reference in New Issue