Skip to content

Commit

Permalink
Merge pull request #23 from ErikKalkoken/improve-tables
Browse files Browse the repository at this point in the history
Change: Improve performance of all tables
  • Loading branch information
ErikKalkoken authored Nov 7, 2024
2 parents ba70875 + ef693ae commit 7a67d83
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 122 deletions.
2 changes: 1 addition & 1 deletion FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Website = "https://github.com/ErikKalkoken/evebuddy"
Icon = "icon.png"
Name = "EVE Buddy"
ID = "io.github.erikkalkoken.evebuddy"
Version = "0.6.3"
Version = "0.7.0"
Build = 1

[Release]
Expand Down
29 changes: 14 additions & 15 deletions internal/app/ui/assetsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func (u *UI) newAssetSearchArea() *assetSearchArea {
a := &assetSearchArea{
u: u,
assetsFiltered: make([]*assetSearchRow, 0),
iconSortAsc: theme.MoveUpIcon(),
iconSortDesc: theme.MoveDownIcon(),
iconSortOff: theme.NewThemedResource(resourceBlankSvg),
iconSortAsc: theme.NewThemedResource(resourceSortAscendingSvg),
iconSortDesc: theme.NewThemedResource(resourceSortDescendingSvg),
iconSortOff: theme.NewThemedResource(resourceSortSvg),
total: widget.NewLabel(""),
found: widget.NewLabel(""),
}
Expand Down Expand Up @@ -127,7 +127,7 @@ func (a *assetSearchArea) makeAssetsTable() *widget.Table {
width float32
}{
{"Name", 300},
{"Quantity", 75},
{"Qty.", 75},
{"Group", 200},
{"Location", 350},
{"Character", 200},
Expand All @@ -143,24 +143,23 @@ func (a *assetSearchArea) makeAssetsTable() *widget.Table {
return len(a.assetsFiltered), len(headers)
},
func() fyne.CanvasObject {
label := widget.NewLabel("Template")
label.Truncation = fyne.TextTruncateEllipsis
return label
return widget.NewLabel("Template")
},
func(tci widget.TableCellID, co fyne.CanvasObject) {
if tci.Row >= len(a.assetsFiltered) {
if tci.Row >= len(a.assetsFiltered) || tci.Row < 0 {
return
}
r := a.assetsFiltered[tci.Row]
label := co.(*widget.Label)
l := co.(*widget.Label)
l.Truncation = fyne.TextTruncateClip
l.Alignment = fyne.TextAlignLeading
var t string
var ta fyne.TextAlign
switch tci.Col {
case 0:
t = r.name
case 1:
t = r.quantityDisplay
ta = fyne.TextAlignTrailing
l.Alignment = fyne.TextAlignTrailing
case 2:
t = r.groupName
case 3:
Expand All @@ -169,10 +168,10 @@ func (a *assetSearchArea) makeAssetsTable() *widget.Table {
t = r.characterName
case 5:
t = r.priceDisplay
l.Alignment = fyne.TextAlignTrailing
}
label.Text = t
label.Alignment = ta
label.Refresh()
l.Text = t
l.Refresh()
},
)
t.ShowHeaderRow = true
Expand Down Expand Up @@ -222,7 +221,7 @@ func (a *assetSearchArea) makeAssetsTable() *widget.Table {
}
t.OnSelected = func(tci widget.TableCellID) {
defer t.UnselectAll()
if tci.Row >= len(a.assetsFiltered) {
if tci.Row >= len(a.assetsFiltered) || tci.Row < 0 {
return
}
r := a.assetsFiltered[tci.Row]
Expand Down
4 changes: 2 additions & 2 deletions internal/app/ui/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func (u *UI) newMailArea() *mailArea {
a.toolbar = a.makeToolbar()
a.toolbar.Hide()
a.subject.TextStyle = fyne.TextStyle{Bold: true}
a.subject.Truncation = fyne.TextTruncateEllipsis
a.header.Truncation = fyne.TextTruncateEllipsis
a.subject.Truncation = fyne.TextTruncateClip
a.header.Truncation = fyne.TextTruncateClip
wrapper := container.NewVBox(a.toolbar, a.subject, a.header)
a.body.Wrapping = fyne.TextWrapWord
a.mailSection = container.NewBorder(wrapper, nil, nil, nil, container.NewVScroll(a.body))
Expand Down
147 changes: 56 additions & 91 deletions internal/app/ui/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log/slog"
"strings"
"time"

"fyne.io/fyne/v2"
Expand Down Expand Up @@ -63,119 +64,103 @@ func (u *UI) newOverviewArea() *overviewArea {

func (a *overviewArea) makeTable() *widget.Table {
var headers = []struct {
text string
width float32
action func(overviewCharacter)
text string
maxChars int
}{
{"Name", 200, nil},
{"Corporation", 200, nil},
{"Alliance", 200, nil},
{"Security", 80, nil},
{"Unread", 80, func(oc overviewCharacter) {
a.u.selectCharacterAndTab(oc.id, a.u.mailTab, 0)
}},
{"Total SP", 80, func(oc overviewCharacter) {
a.u.selectCharacterAndTab(oc.id, a.u.skillTab, 1)
}},
{"Unall. SP", 80, func(oc overviewCharacter) {
a.u.selectCharacterAndTab(oc.id, a.u.skillTab, 1)
}},
{"Training", 80, func(oc overviewCharacter) {
a.u.selectCharacterAndTab(oc.id, a.u.skillTab, 0)
}},
{"Wallet", 80, func(oc overviewCharacter) {
a.u.selectCharacterAndTab(oc.id, a.u.walletTab, 0)
}},
{"Assets", 80, func(oc overviewCharacter) {
a.u.selectCharacterAndTab(oc.id, a.u.assetTab, 0)
}},
{"Location", 150, func(oc overviewCharacter) {
if oc.location != nil {
a.u.showLocationInfoWindow(oc.location.ID)
}
}},
{"System", 150, nil},
{"Region", 150, nil},
{"Ship", 150, func(oc overviewCharacter) {
if oc.ship != nil {
a.u.showTypeInfoWindow(oc.ship.ID, a.u.characterID())
}
}},
{"Last Login", 100, nil},
{"Home", 150, func(oc overviewCharacter) {
if oc.home != nil {
a.u.showLocationInfoWindow(oc.home.ID)
}
}},
{"Age", 100, nil},
{"Name", 20},
{"Corporation", 20},
{"Alliance", 20},
{"Security", 5},
{"Unread", 5},
{"Total SP", 5},
{"Unall. SP", 5},
{"Training", 5},
{"Wallet", 5},
{"Assets", 5},
{"Location", 20},
{"System", 15},
{"Region", 15},
{"Ship", 15},
{"Last Login", 10},
{"Home", 20},
{"Age", 10},
}

t := widget.NewTable(
func() (rows int, cols int) {
return len(a.characters), len(headers)
},
func() fyne.CanvasObject {
x := widget.NewLabel("Template")
x.Truncation = fyne.TextTruncateEllipsis
return x
return widget.NewLabel("Template")
},
func(tci widget.TableCellID, co fyne.CanvasObject) {
l := co.(*widget.Label)
if tci.Row >= len(a.characters) {
if tci.Row >= len(a.characters) || tci.Row < 0 {
return
}
c := a.characters[tci.Row]
l.Alignment = fyne.TextAlignLeading
l.Importance = widget.MediumImportance
var text string
switch tci.Col {
case 0:
l.Text = c.name
text = c.name
case 1:
l.Text = c.corporation
text = c.corporation
case 2:
l.Text = c.alliance
text = c.alliance
case 3:
l.Text = fmt.Sprintf("%.1f", c.security)
text = fmt.Sprintf("%.1f", c.security)
if c.security > 0 {
l.Importance = widget.SuccessImportance
} else if c.security < 0 {
l.Importance = widget.DangerImportance
}
l.Alignment = fyne.TextAlignTrailing
case 4:
l.Text = ihumanize.Optional(c.unreadCount, "?")
text = ihumanize.Optional(c.unreadCount, "?")
l.Alignment = fyne.TextAlignTrailing
case 5:
l.Text = ihumanize.Optional(c.totalSP, "?")
text = ihumanize.Optional(c.totalSP, "?")
l.Alignment = fyne.TextAlignTrailing
case 6:
l.Text = ihumanize.Optional(c.unallocatedSP, "?")
text = ihumanize.Optional(c.unallocatedSP, "?")
l.Alignment = fyne.TextAlignTrailing
case 7:
if c.training.IsEmpty() {
l.Text = "Inactive"
text = "Inactive"
l.Importance = widget.WarningImportance
} else {
l.Text = ihumanize.Duration(c.training.MustValue())
text = ihumanize.Duration(c.training.MustValue())
}
case 8:
l.Text = ihumanize.OptionalFloat(c.walletBalance, 1, "?")
text = ihumanize.OptionalFloat(c.walletBalance, 1, "?")
l.Alignment = fyne.TextAlignTrailing
case 9:
l.Text = ihumanize.OptionalFloat(c.assetValue, 1, "?")
text = ihumanize.OptionalFloat(c.assetValue, 1, "?")
l.Alignment = fyne.TextAlignTrailing
case 10:
l.Text = entityNameOrFallback(c.location, "?")
text = entityNameOrFallback(c.location, "?")
case 11:
if c.solarSystem == nil || c.systemSecurity.IsEmpty() {
l.Text = "?"
text = "?"
} else {
l.Text = fmt.Sprintf("%s %.1f", c.solarSystem.Name, c.systemSecurity.MustValue())
text = fmt.Sprintf("%s %.1f", c.solarSystem.Name, c.systemSecurity.MustValue())
}
case 12:
l.Text = entityNameOrFallback(c.region, "?")
text = entityNameOrFallback(c.region, "?")
case 13:
l.Text = entityNameOrFallback(c.ship, "?")
text = entityNameOrFallback(c.ship, "?")
case 14:
l.Text = ihumanize.Optional(c.lastLoginAt, "?")
text = ihumanize.Optional(c.lastLoginAt, "?")
case 15:
l.Text = entityNameOrFallback(c.home, "?")
text = entityNameOrFallback(c.home, "?")
case 16:
l.Text = humanize.RelTime(c.birthday, time.Now(), "", "")
text = humanize.RelTime(c.birthday, time.Now(), "", "")
l.Alignment = fyne.TextAlignTrailing
}
l.Text = text
l.Truncation = fyne.TextTruncateClip
l.Refresh()
},
)
Expand All @@ -187,40 +172,20 @@ func (a *overviewArea) makeTable() *widget.Table {
t.UpdateHeader = func(tci widget.TableCellID, co fyne.CanvasObject) {
s := headers[tci.Col]
label := co.(*widget.Label)
label.Text = s.text
if headers[tci.Col].action != nil {
label.Importance = widget.HighImportance
} else {
label.Importance = widget.MediumImportance
}
label.Refresh()
label.SetText(s.text)
}
t.OnSelected = func(tci widget.TableCellID) {
defer t.UnselectAll()
if tci.Row <= len(a.characters) {
return
}
c := a.characters[tci.Row]
if action := headers[tci.Col].action; action != nil {
action(c)
}
}

for i, h := range headers {
t.SetColumnWidth(i, h.width)
x := widget.NewLabel(strings.Repeat("w", h.maxChars))
w := x.MinSize().Width
t.SetColumnWidth(i, w)
}
return t
}

func (u *UI) selectCharacterAndTab(characterID int32, tab *container.TabItem, subIndex int) {
if err := u.loadCharacter(context.TODO(), characterID); err != nil {
panic(err)
}
u.tabs.Select(tab)
t := tab.Content.(*container.AppTabs)
t.SelectIndex(subIndex)
}

func (a *overviewArea) refresh() {
t, i, err := func() (string, widget.Importance, error) {
totals, err := a.updateCharacters()
Expand Down
15 changes: 15 additions & 0 deletions internal/app/ui/resource.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions internal/app/ui/walletjournal.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,14 @@ func (a *walletJournalArea) makeTable() *widget.Table {
return len(a.entries), len(headers)
},
func() fyne.CanvasObject {
x := widget.NewLabel("Template")
x.Truncation = fyne.TextTruncateEllipsis
return x
return widget.NewLabel("Template Template")
},
func(tci widget.TableCellID, co fyne.CanvasObject) {
l := co.(*widget.Label)
l.Importance = widget.MediumImportance
l.Alignment = fyne.TextAlignLeading
if tci.Row >= len(a.entries) {
l.Truncation = fyne.TextTruncateOff
if tci.Row >= len(a.entries) || tci.Row < 0 {
return
}
w := a.entries[tci.Row]
Expand All @@ -117,8 +116,8 @@ func (a *walletJournalArea) makeTable() *widget.Table {
l.Alignment = fyne.TextAlignTrailing
l.Text = humanize.FormatFloat(myFloatFormat, w.balance)
case 4:
l.Truncation = fyne.TextTruncateEllipsis
l.Text = w.descriptionWithReason()
l.Truncation = fyne.TextTruncateClip
}
l.Refresh()
},
Expand All @@ -136,7 +135,7 @@ func (a *walletJournalArea) makeTable() *widget.Table {
}
t.OnSelected = func(tci widget.TableCellID) {
defer t.UnselectAll()
if tci.Row >= len(a.entries) {
if tci.Row >= len(a.entries) || tci.Row < 0 {
return
}
e := a.entries[tci.Row]
Expand Down
Loading

0 comments on commit 7a67d83

Please sign in to comment.