Changes
2 changed files (+56/-8)
-
src/Widget/TimeSpan.vala (new)
-
@@ -0,0 +1,52 @@// Copyright 2025 Shota FUJI // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. // // SPDX-License-Identifier: MPL-2.0 using GLib; namespace TimeTracker.Widget { private class TimeSpan : Gtk.Widget { public bool compact { get; set; default = false; } public GLib.TimeSpan span { get; set construct; } private Gtk.Label label = new Gtk.Label(""); public TimeSpan(GLib.TimeSpan span = 0) { Object(span: span); } construct { this.layout_manager = new Gtk.BinLayout(); label.set_parent(this); this.notify["compact"].connect(this.render); this.notify["span"].connect(this.render); this.render(); } public override void dispose() { label.unparent(); } private string format() { var hours = (int) (span / GLib.TimeSpan.HOUR); var minutes = (int) (span / GLib.TimeSpan.MINUTE) % 60; var seconds = (int) (span / GLib.TimeSpan.SECOND) % 60; if (compact && hours == 0) { return "%02d:%02d".printf(minutes, seconds); } return "%02d:%02d:%02d".printf(hours, minutes, seconds); } private void render() { label.label = this.format(); } } }
-
-
-
@@ -19,7 +19,9 @@ public Model.Timer? timer { get; set construct; }private Binding? timer_binding = null; private Gtk.Label title = new Gtk.Label(""); private Gtk.Label elapsed = new Gtk.Label("--:--:--"); private TimeSpan elapsed = new TimeSpan() { compact = true }; private Gtk.Button stop_button = new Gtk.Button(); construct {
-
@@ -83,13 +85,7 @@ private void update_elapsed() {var start = new DateTime.from_unix_utc(timer.started_at); var end = timer.is_stopped ? new DateTime.from_unix_utc(timer.stopped_at) : new DateTime.now_utc(); var diff = end.difference(start); elapsed.label = "%02d:%02d:%02d".printf( (int) (diff / TimeSpan.HOUR), (int) (diff / TimeSpan.MINUTE) % 60, (int) (diff / TimeSpan.SECOND) % 60 ); elapsed.span = end.difference(start); } } }
-