Changes
4 changed files (+123/-3)
-
-
@@ -13,9 +13,7 @@ Object(application_id: Config.APP_ID);} protected override void activate() { var window = new Gtk.ApplicationWindow(this) { title = "Sample" }; var window = new TimeTracker.Widget.MainWindow(this); window.present(); }
-
-
-
@@ -0,0 +1,36 @@// 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 { public class MainWindow : Adw.ApplicationWindow { public Model.Model model { get; construct; } public MainWindow(Gtk.Application app) { Object(application: app, model: new Model.Model()); } construct { var view = new Adw.ToolbarView(); var header_bar = new Adw.HeaderBar(); view.add_top_bar(header_bar); var list = new TimerList(model.active_timers); view.content = list; this.title = "Time Tracker"; this.content = view; model.update(new Event.TimerStarted("Foo")); model.update(new Event.TimerStarted("Bar")); model.update(new Event.TimerStarted("Baz")); } } }
-
-
-
@@ -0,0 +1,35 @@// 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 TimerList : Gtk.Box { public ListModel timers { get; set construct; } public TimerList(ListModel timers) { Object(timers: timers); } construct { var factory = new Gtk.SignalListItemFactory(); factory.setup.connect(TimerListRow.setup); factory.bind.connect(TimerListRow.bind); var list = new Gtk.ListView(null, factory); list.hexpand = true; list.hexpand_set = true; this.append(list); this.bind_property("timers", list, "model", SYNC_CREATE, (_binding, from, ref to) => { to = new Gtk.NoSelection((ListModel) from); }); } } }
-
-
-
@@ -0,0 +1,51 @@// 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 TimerListRow : Gtk.Box { public Model.Timer? timer { get; set construct; } private Binding? timer_binding = null; private Gtk.Label label = new Gtk.Label(""); construct { this.notify["timer"].connect(() => { if (timer_binding != null) { timer_binding.unbind(); timer_binding = null; } if (timer != null) { timer_binding = timer.bind_property("title", label, "label", SYNC_CREATE); } }); this.margin_top = 8; this.margin_bottom = 8; this.margin_start = 8; this.margin_end = 8; this.append(label); } public static void setup(Gtk.ListItemFactory _factory, Object object) { var list_item = (Gtk.ListItem) object; list_item.child = new TimerListRow(); } public static void bind(Gtk.ListItemFactory _factory, Object object) { var list_item = (Gtk.ListItem) object; var timer = (Model.Timer) list_item.item; var row = (TimerListRow) list_item.child; row.timer = timer; } } }
-