Skip to content

Commit

Permalink
Improve widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikKalkoken committed Jan 28, 2025
1 parent 77f6d7c commit 5268318
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 37 deletions.
1 change: 0 additions & 1 deletion internal/app/ui/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ type AssetsArea struct {
func (u *BaseUI) NewAssetsArea() *AssetsArea {
lp := widget.NewLabel("")
lp.Wrapping = fyne.TextWrapWord
lp.TextStyle.Bold = true
a := AssetsArea{
assets: make([]*app.CharacterAsset, 0),
assetsBottom: widget.NewLabel(""),
Expand Down
16 changes: 5 additions & 11 deletions internal/app/ui/mobile/appbarwidget.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"

"github.com/ErikKalkoken/evebuddy/internal/app/widgets"
kxwidget "github.com/ErikKalkoken/fyne-kx/widget"
)

Expand All @@ -23,7 +24,7 @@ type AppBar struct {

body fyne.CanvasObject
bg *canvas.Rectangle
title *widget.RichText
title *widgets.SubHeading
items []widget.ToolbarItem
}

Expand All @@ -38,23 +39,16 @@ func NewAppBar(title string, body fyne.CanvasObject, items ...widget.ToolbarItem
}
w.ExtendBaseWidget(w)
if title != "" {
w.title = widget.NewRichText(&widget.TextSegment{
Style: widget.RichTextStyle{
ColorName: theme.ColorNameForeground,
Inline: false,
SizeName: theme.SizeNameSubHeadingText,
},
Text: title,
})
w.title = widgets.NewSubHeading(title)
}
return w
}

func (w *AppBar) Title() string {
if w.title == nil || len(w.title.Segments) == 0 {
if w.title == nil {
return ""
}
return w.title.Segments[0].Textual()
return w.title.Text
}

func (w *AppBar) Refresh() {
Expand Down
1 change: 0 additions & 1 deletion internal/app/ui/mobile/navbarwidget.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func (w *destination) disable() {
}

func (w *destination) CreateRenderer() fyne.WidgetRenderer {
// p := theme.Padding()
c := container.New(layout.NewCustomPaddedVBoxLayout(0),
w.icon,
container.NewHBox(layout.NewSpacer(), w.label, layout.NewSpacer()),
Expand Down
19 changes: 17 additions & 2 deletions internal/app/widgets/assetbadge.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ type assetBadge struct {
widget.BaseWidget

quantity *canvas.Text
bg *canvas.Rectangle
}

func NewAssetBadge() *assetBadge {
q := canvas.NewText("", theme.Color(theme.ColorNameForeground))
q.TextSize = theme.CaptionTextSize()
w := &assetBadge{quantity: q}
w := &assetBadge{
quantity: q,
bg: canvas.NewRectangle(theme.Color(theme.ColorNameBackground)),
}
w.ExtendBaseWidget(w)
return w
}
Expand All @@ -29,12 +33,23 @@ func (w *assetBadge) SetQuantity(q int) {
w.quantity.Refresh()
}

func (w *assetBadge) Refresh() {
th := w.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()
w.quantity.Color = th.Color(theme.ColorNameForeground, v)
w.quantity.Refresh()
w.bg.FillColor = th.Color(theme.ColorNameBackground, v)
w.bg.Refresh()
w.BaseWidget.Refresh()
}

func (w *assetBadge) CreateRenderer() fyne.WidgetRenderer {
p := theme.Padding()
bgPadding := layout.NewCustomPaddedLayout(0, 0, p, p)
customPadding := layout.NewCustomPaddedLayout(p/2, p/2, p/2, p/2)

c := container.New(customPadding, container.NewStack(
canvas.NewRectangle(theme.Color(theme.ColorNameBackground)),
w.bg,
container.New(bgPadding, w.quantity),
))
return widget.NewSimpleRenderer(c)
Expand Down
10 changes: 10 additions & 0 deletions internal/app/widgets/assetlabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ func (w *assetLabel) SetText(s string) {
w.label2.Refresh()
}

func (w *assetLabel) Refresh() {
th := w.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()
w.label1.Color = th.Color(theme.ColorNameForeground, v)
w.label1.Refresh()
w.label2.Color = th.Color(theme.ColorNameForeground, v)
w.label2.Refresh()
w.BaseWidget.Refresh()
}

func (w *assetLabel) CreateRenderer() fyne.WidgetRenderer {
customVBox := layout.NewCustomPaddedVBoxLayout(0)
customHBox := layout.NewCustomPaddedHBoxLayout(0)
Expand Down
64 changes: 42 additions & 22 deletions internal/app/widgets/planet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,39 @@ const (
planetImageSize = 256
planetWidgetSizeDesktop = 120
planetWidgetSizeMobile = 60
planetBackgroundColor = theme.ColorNameInputBackground
)

type Planet struct {
widget.BaseWidget

bg *canvas.Rectangle
extracting *widget.Label
post *widget.Label
image *canvas.Image
post *widget.Label
producing *widget.Label
security *widget.Label
title *widget.Label
location *widget.Label
}

func NewPlanet() *Planet {
image := canvas.NewImageFromResource(theme.BrokenImageIcon())
image.FillMode = canvas.ImageFillContain
isMobile := fyne.CurrentDevice().IsMobile()
var size float32
if isMobile {
size = planetWidgetSizeMobile
} else {
size = planetWidgetSizeDesktop
}
image.SetMinSize(fyne.Size{Width: size, Height: size})
image.SetMinSize(fyne.Size{Width: planetWidgetSizeDesktop, Height: planetWidgetSizeDesktop})
extracting := widget.NewLabel("")
extracting.Truncation = fyne.TextTruncateEllipsis
producing := widget.NewLabel("")
producing.Truncation = fyne.TextTruncateEllipsis
location := widget.NewLabel("")
location.Truncation = fyne.TextTruncateEllipsis
w := &Planet{
post: widget.NewLabel(""),
extracting: widget.NewLabel(""),
bg: canvas.NewRectangle(theme.Color(planetBackgroundColor)),
extracting: extracting,
image: image,
producing: widget.NewLabel(""),
post: widget.NewLabel(""),
producing: producing,
security: widget.NewLabel(""),
title: widget.NewLabel(""),
location: location,
}
w.ExtendBaseWidget(w)
return w
Expand All @@ -66,7 +69,7 @@ func (w *Planet) Set(cp *app.CharacterPlanet) {
w.security.Importance = cp.EvePlanet.SolarSystem.SecurityType().ToImportance()
w.security.Refresh()
s := fmt.Sprintf("%s - %s - %d installations", cp.EvePlanet.Name, cp.EvePlanet.TypeDisplay(), len(cp.Pins))
w.title.SetText(s)
w.location.SetText(s)

extracted := strings.Join(cp.ExtractedTypeNames(), ",")
var deadline string
Expand Down Expand Up @@ -104,19 +107,36 @@ func (w *Planet) Set(cp *app.CharacterPlanet) {
w.producing.SetText(produced)
}

func (w *Planet) Refresh() {
th := w.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()
w.bg.FillColor = th.Color(planetBackgroundColor, v)
w.bg.Refresh()
w.BaseWidget.Refresh()

}

func (w *Planet) CreateRenderer() fyne.WidgetRenderer {
data := container.NewVBox(
container.NewStack(
w.bg,
container.NewBorder(nil, nil, w.security, nil, w.location),
),
widget.NewForm(
widget.NewFormItem("Extracting", w.extracting),
widget.NewFormItem("Extraction due", w.post),
widget.NewFormItem("Producing", w.producing),
),
)
if fyne.CurrentDevice().IsMobile() {
return widget.NewSimpleRenderer(data)
}
c := container.NewBorder(
nil,
nil,
container.NewVBox(w.image),
nil,
container.NewVBox(
container.NewStack(canvas.NewRectangle(theme.Color(theme.ColorNameInputBackground)), container.NewHBox(w.security, w.title)),
widget.NewForm(
widget.NewFormItem("Extracting", container.NewHBox(w.extracting, w.post)),
widget.NewFormItem("Producing", w.producing),
),
),
data,
)
return widget.NewSimpleRenderer(c)
}

0 comments on commit 5268318

Please sign in to comment.