Add clock ticks
This commit is contained in:
parent
96fc16d0f0
commit
6f31ac1e8d
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue