Start drawing the transit clock using libadwaita colors
This commit is contained in:
parent
bfd23bff5b
commit
63884a32f6
|
@ -335,12 +335,14 @@ dependencies = [
|
|||
"fluent",
|
||||
"fluent-ergonomics",
|
||||
"futures",
|
||||
"gdk4",
|
||||
"geo-types",
|
||||
"gio",
|
||||
"glib",
|
||||
"gtk4",
|
||||
"ifc",
|
||||
"lazy_static",
|
||||
"libadwaita",
|
||||
"memorycache",
|
||||
"reqwest",
|
||||
"serde",
|
||||
|
@ -1263,6 +1265,39 @@ version = "0.5.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
|
||||
|
||||
[[package]]
|
||||
name = "libadwaita"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ab9c0843f9f23ff25634df2743690c3a1faffe0a190e60c490878517eb81abf"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"gdk-pixbuf",
|
||||
"gdk4",
|
||||
"gio",
|
||||
"glib",
|
||||
"gtk4",
|
||||
"libadwaita-sys",
|
||||
"libc",
|
||||
"pango",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libadwaita-sys"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4231cb2499a9f0c4cdfa4885414b33e39901ddcac61150bc0bb4ff8a57ede404"
|
||||
dependencies = [
|
||||
"gdk4-sys",
|
||||
"gio-sys",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"gtk4-sys",
|
||||
"libc",
|
||||
"pango-sys",
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.147"
|
||||
|
|
|
@ -6,6 +6,7 @@ edition = "2018"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
adw = { version = "0.4", package = "libadwaita", features = [ "v1_2" ] }
|
||||
cairo-rs = { version = "0.17" }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
fluent-ergonomics = { path = "../fluent-ergonomics/" }
|
||||
|
@ -14,6 +15,7 @@ futures = { version = "0.3" }
|
|||
geo-types = { path = "../geo-types/" }
|
||||
gio = { version = "0.17" }
|
||||
glib = { version = "0.17" }
|
||||
gdk = { version = "0.6", package = "gdk4" }
|
||||
gtk = { version = "0.6", package = "gtk4" }
|
||||
ifc = { path = "../ifc/" }
|
||||
lazy_static = { version = "1.4" }
|
||||
|
|
|
@ -2,19 +2,20 @@ use crate::{
|
|||
components::{Date, TransitClock},
|
||||
types::State,
|
||||
};
|
||||
use adw::prelude::AdwApplicationWindowExt;
|
||||
use gtk::prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ApplicationWindow {
|
||||
pub window: gtk::ApplicationWindow,
|
||||
pub window: adw::ApplicationWindow,
|
||||
pub date_label: Date,
|
||||
pub next_event: gtk::Label,
|
||||
pub transit_clock: TransitClock,
|
||||
}
|
||||
|
||||
impl ApplicationWindow {
|
||||
pub fn new(app: >k::Application) -> Self {
|
||||
let window = gtk::ApplicationWindow::new(app);
|
||||
pub fn new(app: &adw::Application) -> Self {
|
||||
let window = adw::ApplicationWindow::new(app);
|
||||
|
||||
let layout = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Vertical)
|
||||
|
@ -38,7 +39,7 @@ impl ApplicationWindow {
|
|||
let transit_clock = TransitClock::new();
|
||||
layout.append(&transit_clock);
|
||||
|
||||
window.set_child(Some(&layout));
|
||||
window.set_content(Some(&layout));
|
||||
|
||||
Self {
|
||||
window,
|
||||
|
|
|
@ -43,6 +43,7 @@ impl TransitClock {
|
|||
s.set_draw_func({
|
||||
let s = s.clone();
|
||||
move |_, context, width, height| {
|
||||
let style_context = WidgetExt::style_context(&s);
|
||||
let center_x = width as f64 / 2.;
|
||||
let center_y = height as f64 / 2.;
|
||||
let radius = width.min(height) as f64 / 2. * 0.9;
|
||||
|
@ -51,20 +52,35 @@ impl TransitClock {
|
|||
let sunrise = info.sunrise - NaiveTime::from_hms_opt(0, 0, 0).unwrap();
|
||||
let sunset = info.sunset - NaiveTime::from_hms_opt(0, 0, 0).unwrap();
|
||||
|
||||
PieChart::new()
|
||||
let night_color = style_context.lookup_color("dark_5").unwrap();
|
||||
let day_color = style_context.lookup_color("blue_1").unwrap();
|
||||
|
||||
PieChart::new(&style_context)
|
||||
.center(center_x, center_y)
|
||||
.radius(radius)
|
||||
.rotation(-PI / 2.)
|
||||
.wedges(
|
||||
vec![Wedge {
|
||||
start_angle: (PI * 2.) * sunset.num_seconds() as f64 / full_day,
|
||||
end_angle: (PI * 2.) * sunrise.num_seconds() as f64 / full_day,
|
||||
color: Color {
|
||||
r: 0.1,
|
||||
g: 0.1,
|
||||
b: 0.8,
|
||||
vec![
|
||||
Wedge {
|
||||
start_angle: (PI * 2.) * sunset.num_seconds() as f64 / full_day,
|
||||
end_angle: (PI * 2.) * sunrise.num_seconds() as f64 / full_day,
|
||||
color: Color {
|
||||
r: night_color.red() as f64,
|
||||
g: night_color.green() as f64,
|
||||
b: night_color.blue() as f64,
|
||||
},
|
||||
},
|
||||
}]
|
||||
Wedge {
|
||||
start_angle: (PI * 2.) * sunrise.num_seconds() as f64
|
||||
/ full_day,
|
||||
end_angle: (PI * 2.) * sunset.num_seconds() as f64 / full_day,
|
||||
color: Color {
|
||||
r: day_color.red() as f64,
|
||||
g: day_color.green() as f64,
|
||||
b: day_color.blue() as f64,
|
||||
},
|
||||
},
|
||||
]
|
||||
.into_iter(),
|
||||
)
|
||||
.draw(context);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use cairo::Context;
|
||||
use gtk::{gdk::RGBA, prelude::*, StyleContext};
|
||||
use std::f64::consts::PI;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -21,16 +22,19 @@ pub struct PieChart {
|
|||
center_x: f64,
|
||||
center_y: f64,
|
||||
radius: f64,
|
||||
|
||||
border_color: RGBA,
|
||||
}
|
||||
|
||||
impl PieChart {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(style_context: &StyleContext) -> Self {
|
||||
Self {
|
||||
rotation: 0.,
|
||||
wedges: vec![],
|
||||
center_x: 0.,
|
||||
center_y: 0.,
|
||||
radius: 0.,
|
||||
border_color: style_context.lookup_color("theme_fg_color").unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,7 +85,11 @@ impl PieChart {
|
|||
},
|
||||
);
|
||||
|
||||
context.set_source_rgb(1., 1., 1.);
|
||||
context.set_source_rgb(
|
||||
self.border_color.red() as f64,
|
||||
self.border_color.green() as f64,
|
||||
self.border_color.blue() as f64,
|
||||
);
|
||||
context.arc(self.center_x, self.center_y, self.radius, 0., 2. * PI);
|
||||
let _ = context.stroke();
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ pub struct Core {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
let app = gtk::Application::builder()
|
||||
let app = adw::Application::builder()
|
||||
.application_id("com.luminescent-dreams.dashboard")
|
||||
.resource_base_path("/com/luminescent-dreams/dashboard")
|
||||
.build();
|
||||
|
|
Loading…
Reference in New Issue