Skip to content

Commit

Permalink
Enable colonies for mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikKalkoken committed Jan 28, 2025
1 parent 52bd62c commit f0f7f20
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 108 deletions.
118 changes: 42 additions & 76 deletions internal/app/ui/colonies.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,21 @@ type colonyRow struct {

// ColoniesArea is the UI area that shows the skillqueue
type ColoniesArea struct {
Content *fyne.Container
rows []colonyRow
table *widget.Table
top *widget.Label
u *BaseUI
Content fyne.CanvasObject

body fyne.CanvasObject
rows []colonyRow
top *widget.Label
u *BaseUI
}

func (u *BaseUI) NewColoniesArea() *ColoniesArea {
a := ColoniesArea{
top: widget.NewLabel(""),
rows: make([]colonyRow, 0),
top: makeTopLabel(),
u: u,
}
a.top.TextStyle.Bold = true

top := container.NewVBox(a.top, widget.NewSeparator())
a.table = a.makeTable()
a.Content = container.NewBorder(top, nil, nil, nil, a.table)
return &a
}

func (a *ColoniesArea) makeTable() *widget.Table {
var headers = []struct {
text string
width float32
}{
headers := []headerDef{
{"Planet", 150},
{"Sec.", 50},
{"Type", 100},
Expand All @@ -64,64 +53,41 @@ func (a *ColoniesArea) makeTable() *widget.Table {
{"Region", 150},
{"Character", 150},
}
t := widget.NewTable(
func() (rows int, cols int) {
return len(a.rows), len(headers)
},
func() fyne.CanvasObject {
return widget.NewLabel("Template")
},
func(tci widget.TableCellID, co fyne.CanvasObject) {
l := co.(*widget.Label)
l.Importance = widget.MediumImportance
l.Alignment = fyne.TextAlignLeading
l.Truncation = fyne.TextTruncateOff
if tci.Row >= len(a.rows) || tci.Row < 0 {
return
}
w := a.rows[tci.Row]
switch tci.Col {
case 0:
l.Text = w.planet
case 1:
l.Text = w.security
l.Importance = w.securityImportance
l.Alignment = fyne.TextAlignTrailing
case 2:
l.Text = w.planetType
case 3:
l.Text = w.extracting
l.Truncation = fyne.TextTruncateEllipsis
case 4:
l.Text = w.due
l.Importance = w.dueImportance
case 5:
l.Text = w.producing
l.Truncation = fyne.TextTruncateEllipsis
case 6:
l.Text = w.region
case 7:
l.Text = w.character
l.Truncation = fyne.TextTruncateEllipsis
}
l.Refresh()
},
)
t.ShowHeaderRow = true
t.CreateHeader = func() fyne.CanvasObject {
return widget.NewLabel("Template")
}
t.UpdateHeader = func(tci widget.TableCellID, co fyne.CanvasObject) {
s := headers[tci.Col]
co.(*widget.Label).SetText(s.text)
}
for i, h := range headers {
t.SetColumnWidth(i, h.width)
makeDataLabel := func(col int, w colonyRow) (string, fyne.TextAlign, widget.Importance) {
var align fyne.TextAlign
var importance widget.Importance
var text string
switch col {
case 0:
text = w.planet
case 1:
text = w.security
importance = w.securityImportance
align = fyne.TextAlignTrailing
case 2:
text = w.planetType
case 3:
text = w.extracting
case 4:
text = w.due
importance = w.dueImportance
case 5:
text = w.producing
case 6:
text = w.region
case 7:
text = w.character
}
return text, align, importance
}
t.OnSelected = func(id widget.TableCellID) {
t.UnselectAll()
if a.u.IsDesktop() {
a.body = makeDataTableForDesktop(headers, &a.rows, makeDataLabel)
} else {
a.body = makeDataTableForMobile(headers, &a.rows, makeDataLabel)
}
return t
top := container.NewVBox(a.top, widget.NewSeparator())
a.Content = container.NewBorder(top, nil, nil, nil, a.body)
return &a
}

func (a *ColoniesArea) Refresh() {
Expand All @@ -137,7 +103,7 @@ func (a *ColoniesArea) Refresh() {
a.top.Text = t
a.top.Importance = i
a.top.Refresh()
a.table.Refresh()
a.body.Refresh()
}

func (a *ColoniesArea) makeTopText() (string, widget.Importance) {
Expand Down
24 changes: 12 additions & 12 deletions internal/app/ui/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ func (u *BaseUI) NewOverviewArea() *OverviewArea {
}
top := container.NewVBox(a.top, widget.NewSeparator())
headers := []headerDef{
{"Name", 20},
{"Corporation", 20},
{"Alliance", 20},
{"Security", 5},
{"Unread", 5},
{"Wallet", 5},
{"Assets", 5},
{"Last Login", 10},
{"Home", 20},
{"Age", 10},
{"Name", 250},
{"Corporation", 250},
{"Alliance", 250},
{"Security", 50},
{"Unread", 100},
{"Wallet", 100},
{"Assets", 100},
{"Last Login", 100},
{"Home", 250},
{"Age", 100},
}
makeDataLabel := func(col int, c overviewCharacter) (string, fyne.TextAlign, widget.Importance) {
var align fyne.TextAlign
Expand Down Expand Up @@ -99,9 +99,9 @@ func (u *BaseUI) NewOverviewArea() *OverviewArea {
return text, align, importance
}
if a.u.IsDesktop() {
a.body = makeDataTable(headers, &a.characters, makeDataLabel)
a.body = makeDataTableForDesktop(headers, &a.characters, makeDataLabel)
} else {
a.body = makeVTable(headers, &a.characters, makeDataLabel)
a.body = makeDataTableForMobile(headers, &a.characters, makeDataLabel)
}
a.Content = container.NewBorder(top, nil, nil, nil, a.body)
return &a
Expand Down
20 changes: 6 additions & 14 deletions internal/app/ui/tableHelper.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package ui

import (
"strings"

kxlayout "github.com/ErikKalkoken/fyne-kx/layout"

"fyne.io/fyne/v2"
Expand All @@ -14,8 +12,8 @@ import (
)

type headerDef struct {
text string
maxChars int
text string
width float32
}

func maxHeaderWidth(headers []headerDef) float32 {
Expand All @@ -34,7 +32,7 @@ func makeTopLabel() *widget.Label {
return x
}

func makeDataTable[S ~[]E, E any](
func makeDataTableForDesktop[S ~[]E, E any](
headers []headerDef,
data *S,
makeLabel func(int, E) (string, fyne.TextAlign, widget.Importance),
Expand Down Expand Up @@ -70,19 +68,13 @@ func makeDataTable[S ~[]E, E any](
t.OnSelected = func(tci widget.TableCellID) {
defer t.UnselectAll()
}
adjustColumnWidth(t, headers)
return t
}

func adjustColumnWidth(t *widget.Table, headers []headerDef) {
for i, h := range headers {
x := widget.NewLabel(strings.Repeat("w", h.maxChars))
w := x.MinSize().Width
t.SetColumnWidth(i, w)
t.SetColumnWidth(i, h.width)
}
return t
}

func makeVTable[S ~[]E, E any](
func makeDataTableForMobile[S ~[]E, E any](
headers []headerDef,
data *S,
makeLabel func(int, E) (string, fyne.TextAlign, widget.Importance),
Expand Down
12 changes: 6 additions & 6 deletions internal/app/ui/training.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func (u *BaseUI) NewTrainingArea() *TrainingArea {
u: u,
}
headers := []headerDef{
{"Name", 20},
{"SP", 5},
{"Unall. SP", 5},
{"Training", 5},
{"Name", 250},
{"SP", 100},
{"Unall. SP", 100},
{"Training", 100},
}
makeDataLabel := func(col int, c trainingCharacter) (string, fyne.TextAlign, widget.Importance) {
var align fyne.TextAlign
Expand All @@ -68,9 +68,9 @@ func (u *BaseUI) NewTrainingArea() *TrainingArea {
return text, align, importance
}
if a.u.IsDesktop() {
a.body = makeDataTable(headers, &a.characters, makeDataLabel)
a.body = makeDataTableForDesktop(headers, &a.characters, makeDataLabel)
} else {
a.body = makeVTable(headers, &a.characters, makeDataLabel)
a.body = makeDataTableForMobile(headers, &a.characters, makeDataLabel)
}
top2 := container.NewVBox(a.top, widget.NewSeparator())
a.Content = container.NewBorder(top2, nil, nil, nil, a.body)
Expand Down

0 comments on commit f0f7f20

Please sign in to comment.