From 3969a9df9ea6541fc6e35ae7d41fd0678ad8e214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Wed, 9 Jul 2025 13:46:39 -0700 Subject: [PATCH 1/6] Create SearchResultItem widget --- po/POTFILES | 1 + src/MainWindow.vala | 35 +++-------------------- src/SearchResultItem.vala | 58 +++++++++++++++++++++++++++++++++++++++ src/meson.build | 1 + 4 files changed, 64 insertions(+), 31 deletions(-) create mode 100644 src/SearchResultItem.vala diff --git a/po/POTFILES b/po/POTFILES index 3a1eb86..35bf45f 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -2,3 +2,4 @@ data/atlas.desktop.in data/atlas.metainfo.xml.in src/Application.vala src/MainWindow.vala +src/SearchResultItem.vala diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 3e5fc74..51efc39 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -30,7 +30,6 @@ public class Atlas.MainWindow : Adw.ApplicationWindow { }; private int current_busy_reason = 0; private uint search_begin_timeout = 0; - private string unknown_text = _("Unknown"); private ListStore location_store; private Cancellable? search_cancellable = null; @@ -77,6 +76,7 @@ public class Atlas.MainWindow : Adw.ApplicationWindow { search_res_list = new Gtk.ListBox () { selection_mode = Gtk.SelectionMode.BROWSE }; + search_res_list.add_css_class (Granite.STYLE_CLASS_RICH_LIST); search_res_list.bind_model (location_store, construct_search_res); search_res_list.set_placeholder (search_placeholder); @@ -287,39 +287,12 @@ public class Atlas.MainWindow : Adw.ApplicationWindow { private Gtk.Widget construct_search_res (Object item) { unowned var place = item as Geocode.Place; - var icon = new Gtk.Image.from_gicon (place.icon); - - var place_name_label = new Gtk.Label (place.name) { - halign = Gtk.Align.START - }; - place_name_label.add_css_class ("title-4"); - - string street = place.street ?? unknown_text; - string postal_code = place.postal_code ?? unknown_text; - string town = place.town ?? unknown_text; - - string info_text = "%s, %s, %s".printf (street, postal_code, town); - - var info_label = new Gtk.Label (info_text) { - halign = Gtk.Align.START - }; - info_label.add_css_class ("dim-label"); - - var label_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6); - label_box.append (place_name_label); - label_box.append (info_label); - - var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) { - margin_top = 6, - margin_bottom = 6, - margin_start = 6, - margin_end = 6 + var result_item = new SearchResultItem () { + place = place }; - box.append (icon); - box.append (label_box); var row = new PlaceListBoxRow (place) { - child = box + child = result_item }; return row; diff --git a/src/SearchResultItem.vala b/src/SearchResultItem.vala new file mode 100644 index 0000000..ae2fc9b --- /dev/null +++ b/src/SearchResultItem.vala @@ -0,0 +1,58 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) + * 2018-2025 Ryo Nakano + * 2014-2015 Atlas Developers + */ + +public class Atlas.SearchResultItem : Gtk.Box { + private Geocode.Place? _place = null; + public Geocode.Place? place { + get { + return _place; + } + + set { + _place = value; + + var street = place.street ?? unknown_text; + var postal_code = place.postal_code ?? unknown_text; + var town = place.town ?? unknown_text; + + image.gicon = place.icon; + name_label.label = place.name; + info_label.label = "%s, %s, %s".printf (street, postal_code, town); + } + } + + private string unknown_text = _("Unknown"); + + private Gtk.Image image; + private Gtk.Label name_label; + private Gtk.Label info_label; + + construct { + image = new Gtk.Image () { + icon_size = LARGE + }; + + name_label = new Gtk.Label (null) { + halign = START + }; + + info_label = new Gtk.Label (null) { + halign = START + }; + info_label.add_css_class (Granite.STYLE_CLASS_SMALL_LABEL); + info_label.add_css_class (Granite.STYLE_CLASS_DIM_LABEL); + + var label_box = new Gtk.Box (VERTICAL, 0); + label_box.append (name_label); + label_box.append (info_label); + + spacing = 6; + + append (image); + append (label_box); + } +} diff --git a/src/meson.build b/src/meson.build index b0c12d6..b38f256 100644 --- a/src/meson.build +++ b/src/meson.build @@ -24,6 +24,7 @@ sources = files( 'MainWindow.vala', 'MapWidget.vala', 'MarkerLayerManager.vala', + 'SearchResultItem.vala', 'Util.vala', ) From 1b4ab6bbc611f188fc4c3f0ea9da60d8f6fdd6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Wed, 9 Jul 2025 13:47:44 -0700 Subject: [PATCH 2/6] Subclass Bin --- src/SearchResultItem.vala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/SearchResultItem.vala b/src/SearchResultItem.vala index ae2fc9b..d07da24 100644 --- a/src/SearchResultItem.vala +++ b/src/SearchResultItem.vala @@ -5,7 +5,7 @@ * 2014-2015 Atlas Developers */ -public class Atlas.SearchResultItem : Gtk.Box { +public class Atlas.SearchResultItem : Granite.Bin { private Geocode.Place? _place = null; public Geocode.Place? place { get { @@ -50,9 +50,10 @@ public class Atlas.SearchResultItem : Gtk.Box { label_box.append (name_label); label_box.append (info_label); - spacing = 6; + var box = new Gtk.Box (HORIZONTAL, 6); + box.append (image); + box.append (label_box); - append (image); - append (label_box); + child = box; } } From 3861b9d93bee45ecbac580a39436632d16a4a225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sun, 13 Jul 2025 10:13:07 -0700 Subject: [PATCH 3/6] Bump granite dep to 7.6 --- src/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meson.build b/src/meson.build index 7bf9fda..6bbfd78 100644 --- a/src/meson.build +++ b/src/meson.build @@ -15,7 +15,7 @@ dependencies = [ # Version limitation for GLib.ApplicationFlags.DEFAULT_FLAGS dependency('glib-2.0', version: '>= 2.74'), # Version limitation for automatic load of Application.css in Granite.init() - dependency('granite-7', version: '>= 7.3.0'), + dependency('granite-7', version: '>= 7.6.0'), dependency('gtk4'), dependency('libadwaita-1'), dependency('libgeoclue-2.0'), From 054569fd1155492cbaba543048ec8e351dabec79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sun, 13 Jul 2025 10:14:36 -0700 Subject: [PATCH 4/6] Don't make place nullable --- src/SearchResultItem.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SearchResultItem.vala b/src/SearchResultItem.vala index d07da24..ebbfb44 100644 --- a/src/SearchResultItem.vala +++ b/src/SearchResultItem.vala @@ -7,7 +7,7 @@ public class Atlas.SearchResultItem : Granite.Bin { private Geocode.Place? _place = null; - public Geocode.Place? place { + public Geocode.Place place { get { return _place; } From 4d366e49e061456cf6f43ea38eaed229849b77b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sun, 13 Jul 2025 10:15:16 -0700 Subject: [PATCH 5/6] Namespace as Maps --- src/MainWindow.vala | 2 +- src/SearchResultItem.vala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index f939b8e..1729e1a 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -288,7 +288,7 @@ public class Atlas.MainWindow : Adw.ApplicationWindow { private Gtk.Widget construct_search_res (Object item) { unowned var place = item as Geocode.Place; - var result_item = new SearchResultItem () { + var result_item = new Maps.SearchResultItem () { place = place }; diff --git a/src/SearchResultItem.vala b/src/SearchResultItem.vala index ebbfb44..536c2a4 100644 --- a/src/SearchResultItem.vala +++ b/src/SearchResultItem.vala @@ -5,7 +5,7 @@ * 2014-2015 Atlas Developers */ -public class Atlas.SearchResultItem : Granite.Bin { +public class Maps.SearchResultItem : Granite.Bin { private Geocode.Place? _place = null; public Geocode.Place place { get { From 151bd37e3d98811aa76855b58ac9f0832077e9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sun, 13 Jul 2025 15:34:31 -0700 Subject: [PATCH 6/6] Update meson.build Co-authored-by: Ryo Nakano --- src/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meson.build b/src/meson.build index 6bbfd78..61815a5 100644 --- a/src/meson.build +++ b/src/meson.build @@ -14,7 +14,7 @@ dependencies = [ dependency('gio-2.0'), # Version limitation for GLib.ApplicationFlags.DEFAULT_FLAGS dependency('glib-2.0', version: '>= 2.74'), - # Version limitation for automatic load of Application.css in Granite.init() + # Version limitation for Granite.Bin dependency('granite-7', version: '>= 7.6.0'), dependency('gtk4'), dependency('libadwaita-1'),