Fix alignment of tracks on Cover panel (close #106)

GTK 4 centers marks of the Scale widget even when the scale has a vertical
orientation. Unfortunately, the Scale widget does not provide a way to set the
alignment or to access the internal Label widget in any way. To left-align the
labels this commit add a method that traverses the all children of the songs
scale recursively and adjusts the alignment if it is a Label widget.
This commit is contained in:
coderkun 2025-04-06 16:48:11 +02:00
commit 162e2d2d36
2 changed files with 22 additions and 1 deletions

View file

@ -141,6 +141,7 @@
<child> <child>
<object class="GtkScale" id="songs_scale"> <object class="GtkScale" id="songs_scale">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="halign">start</property>
<property name="valign">fill</property> <property name="valign">fill</property>
<property name="vexpand">true</property> <property name="vexpand">true</property>
<property name="restrict-to-fill-level">False</property> <property name="restrict-to-fill-level">False</property>
@ -158,4 +159,3 @@
</child> </child>
</template> </template>
</interface> </interface>

View file

@ -180,6 +180,27 @@ class CoverPanel(Gtk.Overlay):
length, Gtk.PositionType.RIGHT, length, Gtk.PositionType.RIGHT,
"{0[0]:02d}:{0[1]:02d} minutes".format(divmod(length, 60))) "{0[0]:02d}:{0[1]:02d} minutes".format(divmod(length, 60)))
# Align marks
self._align_songs_scale_marks()
def _align_songs_scale_marks(self):
self._align_songs_scale_mark(self.songs_scale)
def _align_songs_scale_mark(self, widget):
child = widget.get_first_child()
while child:
if type(child) is Gtk.Label:
print("label found:", child.get_label())
child.set_halign(Gtk.Align.START)
else:
self._align_songs_scale_mark(child)
child = child.get_next_sibling()
def test_child(self, widget):
if type(widget) is Gtk.Label:
print("label found:", widget.get_label())
widget.set_halign(Gtk.Align.START)
def _enable_tracklist(self): def _enable_tracklist(self):
if self._current_album: if self._current_album:
# enable # enable