Totally rewrite dashboard as a GTK application #54

Merged
savanni merged 14 commits from dashboard-gtk into main 2023-08-09 18:14:01 +00:00
1 changed files with 19 additions and 10 deletions
Showing only changes of commit 6f31ac1e8d - Show all commits

View File

@ -204,26 +204,26 @@ impl Date {
}
#[derive(Default)]
pub struct DayPrivate {
pub struct ClockPrivate {
info: Rc<RefCell<Option<SunMoon>>>,
}
#[glib::object_subclass]
impl ObjectSubclass for DayPrivate {
const NAME: &'static str = "Day";
type Type = Day;
impl ObjectSubclass for ClockPrivate {
const NAME: &'static str = "Clock";
type Type = Clock;
type ParentType = gtk::DrawingArea;
}
impl ObjectImpl for DayPrivate {}
impl WidgetImpl for DayPrivate {}
impl DrawingAreaImpl for DayPrivate {}
impl ObjectImpl for ClockPrivate {}
impl WidgetImpl for ClockPrivate {}
impl DrawingAreaImpl for ClockPrivate {}
glib::wrapper! {
pub struct Day(ObjectSubclass<DayPrivate>) @extends gtk::DrawingArea, gtk::Widget;
pub struct Clock(ObjectSubclass<ClockPrivate>) @extends gtk::DrawingArea, gtk::Widget;
}
impl Day {
impl Clock {
pub fn new(sun_moon_info: SunMoon) -> Self {
let s: Self = Object::builder().build();
s.set_width_request(500);
@ -244,6 +244,15 @@ impl Day {
context.arc(width as f64 / 2., height as f64 / 2., 200., 0., PI * 2.);
let _ = context.stroke();
(0..24).for_each(|hour| {
context.translate(width as f64 / 2., height as f64 / 2.);
context.rotate(PI / 12. * hour as f64);
context.move_to(210., 0.);
context.line_to(230., 0.);
context.identity_matrix();
let _ = context.stroke();
});
if let Some(info) = info.deref() {
context.move_to(width as f64 / 2., height as f64 / 2.);
let full_day = Duration::days(1).num_seconds() as f64;
@ -287,7 +296,7 @@ pub fn main() {
.orientation(Orientation::Vertical)
.build();
let date = Date::new();
let day = Day::new(SunMoon {
let day = Clock::new(SunMoon {
sunrise: NaiveTime::from_hms_opt(6, 0, 0).unwrap(),
sunset: NaiveTime::from_hms_opt(0, 0, 0).unwrap(),
moonrise: NaiveTime::from_hms_opt(15, 0, 0),