summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@dfupdate.se>2023-04-01 12:39:50 +0200
committerMarcus Lundblad <ml@dfupdate.se>2023-04-27 22:03:38 +0200
commit9215b57d13322c5c50e255413c1ae59401865ac1 (patch)
treefd35c6361bf8665cfaf10ee0c34f1c17353010b5
parente487974bc747a7806fc2b0923843cce2666bcaa0 (diff)
downloadgnome-maps-9215b57d13322c5c50e255413c1ae59401865ac1.tar.gz
placeListRow: Add support for showing distance label
-rw-r--r--data/ui/place-list-row.ui19
-rw-r--r--src/placeListRow.js18
2 files changed, 35 insertions, 2 deletions
diff --git a/data/ui/place-list-row.ui b/data/ui/place-list-row.ui
index a13ef944..f6bd295e 100644
--- a/data/ui/place-list-row.ui
+++ b/data/ui/place-list-row.ui
@@ -16,6 +16,7 @@
</child>
<child>
<object class="GtkBox">
+ <property name="hexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">3</property>
<child>
@@ -44,9 +45,25 @@
<object class="GtkImage" id="typeIcon">
<property name="halign">end</property>
<property name="valign">center</property>
- <property name="hexpand">True</property>
+ <property name="hexpand">False</property>
</object>
</child>
+ <child>
+ <object class="GtkLabel" id="distanceLabel">
+ <property name="valign">center</property>
+ <property name="halign">end</property>
+ <property name="hexpand">False</property>
+ <property name="xalign">1.0</property>
+ <property name="visible">False</property>
+ <attributes>
+ <attribute name="font-features" value="tnum"></attribute>
+ </attributes>
+ <style>
+ <class name="dim-label"/>
+ <class name="italic"/>
+ </style>
+ </object>
+ </child>"
</object>
</property>
</template>
diff --git a/src/placeListRow.js b/src/placeListRow.js
index 65069805..63abc93f 100644
--- a/src/placeListRow.js
+++ b/src/placeListRow.js
@@ -27,10 +27,12 @@ import * as Utils from './utils.js';
export class PlaceListRow extends Gtk.ListBoxRow {
- constructor({place, searchString, type, ...params}) {
+ constructor({place, searchString, type, sizeGroup, ...params}) {
super(params);
this.update(place, type, searchString || '');
+ if (sizeGroup)
+ sizeGroup.add_widget(this._distanceLabel);
}
update(place, type, searchString) {
@@ -52,6 +54,19 @@ export class PlaceListRow extends Gtk.ListBoxRow {
this._typeIcon.icon_name = 'starred-symbolic';
else
this._typeIcon.icon_name = null;
+
+ /* hide distance by default so that a previous content from a POI
+ * search doesn't keep the distance when updating with a new search
+ * result
+ */
+ this._distanceLabel.visible = false;
+ }
+
+ setDistanceFrom(location) {
+ let distance = this.place.location.get_distance_from(location) * 1000;
+
+ this._distanceLabel.label = Utils.prettyDistance(distance);
+ this._distanceLabel.visible = true;
}
_boldMatch(title, string) {
@@ -73,5 +88,6 @@ GObject.registerClass({
InternalChildren: [ 'icon',
'name',
'details',
+ 'distanceLabel',
'typeIcon' ],
}, PlaceListRow);