Skip to content

Commit

Permalink
NightLightView
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Jan 9, 2024
1 parent 4a74f3a commit 32fdc4e
Showing 1 changed file with 21 additions and 31 deletions.
52 changes: 21 additions & 31 deletions src/Views/NightLightView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,16 @@

public class Display.NightLightView : Gtk.Box {
construct {
var nightlight_header = new Granite.HeaderLabel (_("Night Light"));
var nightlight_header = new Granite.HeaderLabel (_("Night Light")) {
secondary_text = _("Making the colors of your display warmer may help prevent eye strain and sleeplessness")
};

var nightlight_switch = new Gtk.Switch () {
halign = END,
hexpand = true,
valign = CENTER
};

// FIXME: Replace with Granite.HeaderLabel secondary_text in Gtk4
var nightlight_subtitle = new Gtk.Label (
_("Making the colors of your display warmer may help prevent eye strain and sleeplessness")
) {
wrap = true,
xalign = 0
};
nightlight_subtitle.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);

var temp_adjustment = new Gtk.Adjustment (0, 1500, 6000, 10, 0, 0);

var temp_scale = new Gtk.Scale (HORIZONTAL, temp_adjustment) {
Expand All @@ -33,46 +26,44 @@ public class Display.NightLightView : Gtk.Box {
temp_scale.add_mark (1500, Gtk.PositionType.BOTTOM, _("More Warm"));
temp_scale.add_mark (4500, Gtk.PositionType.BOTTOM, null);
temp_scale.add_mark (6000, Gtk.PositionType.BOTTOM, _("Less Warm"));
temp_scale.get_style_context ().add_class ("warmth");
temp_scale.add_css_class ("warmth");

var nightlight_grid = new Gtk.Grid () {
column_spacing = 12
};
nightlight_grid.attach (nightlight_header, 0, 0);
nightlight_grid.attach (nightlight_subtitle, 0, 1);
nightlight_grid.attach (nightlight_switch, 1, 0, 1, 2);
nightlight_grid.attach (temp_scale, 0, 2, 2);
nightlight_grid.attach (nightlight_switch, 1, 0);
nightlight_grid.attach (temp_scale, 0, 1, 2);

var schedule_header = new Granite.HeaderLabel (_("Schedule"));

var schedule_sunset_radio = new Gtk.RadioButton.with_label_from_widget (
null,
_("Sunset to Sunrise")
);
var schedule_sunset_radio = new Gtk.CheckButton.with_label (_("Sunset to Sunrise"));

var from_label = new Gtk.Label (_("From:"));

var from_time = new Granite.Widgets.TimePicker () {
var from_time = new Granite.TimePicker () {
hexpand = true,
margin_end = 6
};

var to_label = new Gtk.Label (_("To:"));

var to_time = new Granite.Widgets.TimePicker () {
var to_time = new Granite.TimePicker () {
hexpand = true
};

var schedule_manual_box = new Gtk.Box (HORIZONTAL, 6);
schedule_manual_box.add (from_label);
schedule_manual_box.add (from_time);
schedule_manual_box.add (to_label);
schedule_manual_box.add (to_time);
schedule_manual_box.append (from_label);
schedule_manual_box.append (from_time);
schedule_manual_box.append (to_label);
schedule_manual_box.append (to_time);

var schedule_manual_radio = new Gtk.RadioButton.from_widget (schedule_sunset_radio);
var schedule_manual_radio = new Gtk.CheckButton () {
group = schedule_sunset_radio
};

var schedule_grid = new Gtk.Grid () {
column_spacing = 7, // Off by one with Gtk.RadioButton
column_spacing = 7, // Off by one with Gtk.CheckButton
row_spacing = 6
};
schedule_grid.attach (schedule_header, 0, 3, 2);
Expand All @@ -81,18 +72,17 @@ public class Display.NightLightView : Gtk.Box {
schedule_grid.attach (schedule_manual_box, 1, 6);

var box = new Gtk.Box (VERTICAL, 24);
box.add (nightlight_grid);
box.add (schedule_grid);
box.append (nightlight_grid);
box.append (schedule_grid);

var clamp = new Hdy.Clamp () {
var clamp = new Adw.Clamp () {
child = box
};

add (clamp);
append (clamp);
margin_start = 12;
margin_end = 12;
margin_bottom = 12;
show_all ();

var settings = new Settings ("org.gnome.settings-daemon.plugins.color");
settings.bind ("night-light-enabled", nightlight_switch, "active", DEFAULT);
Expand Down

0 comments on commit 32fdc4e

Please sign in to comment.