align numeric list columns to the right

This commit is contained in:
Drew Weymouth
2023-02-03 18:44:00 -08:00
parent 320bd9d8c3
commit 3b3dc780af
4 changed files with 24 additions and 8 deletions
+3 -1
View File
@@ -99,7 +99,8 @@ func NewPlaylistList() *PlaylistList {
a := &PlaylistList{ a := &PlaylistList{
columnsLayout: layouts.NewColumnsLayout([]float32{-1, -1, 200, 125}), columnsLayout: layouts.NewColumnsLayout([]float32{-1, -1, 200, 125}),
} }
a.header = widgets.NewListHeader([]string{"Name", "Description", "Owner", "Track Count"}, a.columnsLayout) a.header = widgets.NewListHeader(
[]widgets.ListColumn{{"Name", false}, {"Description", false}, {"Owner", false}, {"Track Count", true}}, a.columnsLayout)
a.list = widget.NewList( a.list = widget.NewList(
func() int { func() int {
return len(a.Playlists) return len(a.Playlists)
@@ -155,6 +156,7 @@ func NewPlaylistListRow(layout *layouts.ColumnsLayout) *PlaylistListRow {
ownerLabel: widget.NewLabel(""), ownerLabel: widget.NewLabel(""),
trackCountLabel: widget.NewLabel(""), trackCountLabel: widget.NewLabel(""),
} }
a.trackCountLabel.Alignment = fyne.TextAlignTrailing
a.ownerLabel.Wrapping = fyne.TextTruncate a.ownerLabel.Wrapping = fyne.TextTruncate
a.container = container.New(layout, a.nameLabel, a.descrptionLabel, a.ownerLabel, a.trackCountLabel) a.container = container.New(layout, a.nameLabel, a.descrptionLabel, a.ownerLabel, a.trackCountLabel)
a.ExtendBaseWidget(a) a.ExtendBaseWidget(a)
+4 -2
View File
@@ -47,10 +47,12 @@ type ArtistGenrePlaylistRow struct {
func NewArtistGenrePlaylistRow(layout *layouts.ColumnsLayout) *ArtistGenrePlaylistRow { func NewArtistGenrePlaylistRow(layout *layouts.ColumnsLayout) *ArtistGenrePlaylistRow {
a := &ArtistGenrePlaylistRow{ a := &ArtistGenrePlaylistRow{
nameLabel: widget.NewLabel(""), nameLabel: widget.NewLabel(""),
albumCountLabel: widget.NewLabel("alCount"), albumCountLabel: widget.NewLabel(""),
trackCountLabel: widget.NewLabel(""), trackCountLabel: widget.NewLabel(""),
} }
a.ExtendBaseWidget(a) a.ExtendBaseWidget(a)
a.albumCountLabel.Alignment = fyne.TextAlignTrailing
a.trackCountLabel.Alignment = fyne.TextAlignTrailing
a.container = container.New(layout, a.nameLabel, a.albumCountLabel, a.trackCountLabel) a.container = container.New(layout, a.nameLabel, a.albumCountLabel, a.trackCountLabel)
return a return a
} }
@@ -61,7 +63,7 @@ func NewArtistGenrePlaylist(items []ArtistGenrePlaylistItemModel) *ArtistGenrePl
columnsLayout: layouts.NewColumnsLayout([]float32{-1, 125, 125}), columnsLayout: layouts.NewColumnsLayout([]float32{-1, 125, 125}),
} }
a.ExtendBaseWidget(a) a.ExtendBaseWidget(a)
a.hdr = NewListHeader([]string{"Name", "Album Count", "Track Count"}, a.columnsLayout) a.hdr = NewListHeader([]ListColumn{{"Name", false}, {"Album Count", true}, {"Track Count", true}}, a.columnsLayout)
a.list = widget.NewList( a.list = widget.NewList(
func() int { return len(a.Items) }, func() int { return len(a.Items) },
func() fyne.CanvasObject { func() fyne.CanvasObject {
+13 -3
View File
@@ -10,17 +10,22 @@ import (
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
) )
type ListColumn struct {
Text string
AlignTrailing bool
}
type ListHeader struct { type ListHeader struct {
widget.BaseWidget widget.BaseWidget
columns []string columns []ListColumn
columnsLayout *layouts.ColumnsLayout columnsLayout *layouts.ColumnsLayout
columnsContainer *fyne.Container columnsContainer *fyne.Container
container *fyne.Container container *fyne.Container
} }
func NewListHeader(cols []string, layout *layouts.ColumnsLayout) *ListHeader { func NewListHeader(cols []ListColumn, layout *layouts.ColumnsLayout) *ListHeader {
l := &ListHeader{ l := &ListHeader{
columns: cols, columns: cols,
columnsLayout: layout, columnsLayout: layout,
@@ -42,8 +47,13 @@ func (l *ListHeader) SetColumnVisible(colNum int, visible bool) {
func (l *ListHeader) buildColumns() { func (l *ListHeader) buildColumns() {
for _, c := range l.columns { for _, c := range l.columns {
t := widget.NewRichTextWithText(c) t := widget.NewRichTextWithText(c.Text)
t.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = true t.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = true
al := fyne.TextAlignLeading
if c.AlignTrailing {
al = fyne.TextAlignTrailing
}
t.Segments[0].(*widget.TextSegment).Style.Alignment = al
l.columnsContainer.Add(t) l.columnsContainer.Add(t)
} }
} }
+4 -2
View File
@@ -34,11 +34,13 @@ func NewTrackRow(layout *layouts.ColumnsLayout) *TrackRow {
t := &TrackRow{} t := &TrackRow{}
t.ExtendBaseWidget(t) t.ExtendBaseWidget(t)
t.num = widget.NewRichTextWithText("") t.num = widget.NewRichTextWithText("")
t.num.Segments[0].(*widget.TextSegment).Style.Alignment = fyne.TextAlignTrailing
t.name = widget.NewRichTextWithText("") t.name = widget.NewRichTextWithText("")
t.name.Wrapping = fyne.TextTruncate t.name.Wrapping = fyne.TextTruncate
t.artist = widget.NewRichTextWithText("") t.artist = widget.NewRichTextWithText("")
t.artist.Wrapping = fyne.TextTruncate t.artist.Wrapping = fyne.TextTruncate
t.dur = widget.NewRichTextWithText("") t.dur = widget.NewRichTextWithText("")
t.dur.Segments[0].(*widget.TextSegment).Style.Alignment = fyne.TextAlignTrailing
t.container = container.New(layout, t.container = container.New(layout,
t.num, t.name, t.artist, t.dur) t.num, t.name, t.artist, t.dur)
@@ -96,8 +98,8 @@ type Tracklist struct {
func NewTracklist(tracks []*subsonic.Child) *Tracklist { func NewTracklist(tracks []*subsonic.Child) *Tracklist {
t := &Tracklist{Tracks: tracks, nowPlayingIdx: -1} t := &Tracklist{Tracks: tracks, nowPlayingIdx: -1}
t.ExtendBaseWidget(t) t.ExtendBaseWidget(t)
t.colLayout = layouts.NewColumnsLayout([]float32{35, -1, -1, 55}) t.colLayout = layouts.NewColumnsLayout([]float32{35, -1, -1, 60})
t.hdr = NewListHeader([]string{"#", "Title", "Artist", "Time"}, t.colLayout) t.hdr = NewListHeader([]ListColumn{{"#", true}, {"Title", false}, {"Artist", false}, {"Time", true}}, t.colLayout)
t.list = widget.NewList( t.list = widget.NewList(
func() int { return len(t.Tracks) }, func() int { return len(t.Tracks) },
func() fyne.CanvasObject { return NewTrackRow(t.colLayout) }, func() fyne.CanvasObject { return NewTrackRow(t.colLayout) },