Skip to content

Commit

Permalink
Fix scrolling in alarm overview
Browse files Browse the repository at this point in the history
This fixes an issue where the alarm overview would get pushed out of the
output bounds rather than showing a scrollbar when the number of alarms
exceeds the maximum number visible at once.
  • Loading branch information
chrisduerr committed Oct 28, 2023
1 parent 0ca4e75 commit ac0d710
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions gtk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use gtk4::glib::{ExitCode, MainContext, OptionArg, OptionFlags};
use gtk4::prelude::*;
use gtk4::{
AlertDialog, Align, Application, ApplicationWindow, Button, CssProvider, Label, Orientation,
Window,
ScrolledWindow, Window,
};
use rezz::Alarm;
use time::macros::format_description;
Expand Down Expand Up @@ -223,8 +223,8 @@ impl AlarmGtk {
/// Alarm overview and landing page.
pub struct Overview {
ringing_alarm_page: RingingAlarmPage,
alarms: ScrolledWindow,
container: gtk4::Box,
alarms: gtk4::Box,
}

impl Overview {
Expand All @@ -237,8 +237,7 @@ impl Overview {
container.set_valign(Align::End);

// Create alarms container.
let alarms = gtk4::Box::new(Orientation::Vertical, 0);
alarms.set_valign(Align::End);
let alarms = ScrolledWindow::new();
container.append(&alarms);

// Button to create new alarms.
Expand Down Expand Up @@ -266,10 +265,18 @@ impl Overview {
container.append(&Self::alarm_components(alarm));
}

// Create scroll box.
let scroll = ScrolledWindow::new();
scroll.set_propagate_natural_height(true);
scroll.set_child(Some(&container));

// Put scrollbox at bottom by default.
scroll.vadjustment().connect_upper_notify(|adj| adj.set_value(adj.upper()));

// Swap containers.
self.container.remove(&self.alarms);
self.container.prepend(&container);
self.alarms = container;
self.container.prepend(&scroll);
self.alarms = scroll;
}

/// Ring an alarm.
Expand Down

0 comments on commit ac0d710

Please sign in to comment.