diff --git a/core/res.go b/core/res.go index 0cb9273..2b792a0 100644 --- a/core/res.go +++ b/core/res.go @@ -5,68 +5,145 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/theme" + _ "golang.org/x/image/webp" ) -//go:embed icon/login.svg -var loginRes []byte +// icons +var ( + //go:embed icon/login.svg + loginRes []byte -//go:embed icon/logout.svg -var logoutRes []byte + //go:embed icon/logout.svg + logoutRes []byte -//go:embed icon/person_add.svg -var useraddRes []byte + //go:embed icon/person_add.svg + useraddRes []byte -//go:embed icon/person_remove.svg -var userdelRes []byte + //go:embed icon/person_remove.svg + userdelRes []byte -//go:embed icon/account_balance_wallet.svg -var walletRes []byte + //go:embed icon/account_balance_wallet.svg + walletRes []byte -//go:embed icon/percent.svg -var percentRes []byte + //go:embed icon/percent.svg + percentRes []byte -//go:embed icon/key.svg -var accessRes []byte + //go:embed icon/key.svg + accessRes []byte -//go:embed icon/price_change.svg -var bankRes []byte + //go:embed icon/price_change.svg + bankRes []byte +) + +// underlays +var ( + //go:embed underlay/cards1.webp + underlay1Res []byte + + //go:embed underlay/cards2.webp + underlay2Res []byte + + //go:embed underlay/cards3.webp + underlay3Res []byte -var loginIconRes = theme.NewThemedResource(&fyne.StaticResource{ - StaticName: "login", - StaticContent: loginRes, -}) + //go:embed underlay/cards4.webp + underlay4Res []byte -var logoutIconRes = theme.NewThemedResource(&fyne.StaticResource{ - StaticName: "logout", - StaticContent: logoutRes, -}) + //go:embed underlay/cards5.webp + underlay5Res []byte -var useraddIconRes = theme.NewThemedResource(&fyne.StaticResource{ - StaticName: "useradd", - StaticContent: useraddRes, -}) + //go:embed underlay/cards6.webp + underlay6Res []byte -var userdelIconRes = theme.NewThemedResource(&fyne.StaticResource{ - StaticName: "userdel", - StaticContent: userdelRes, -}) + //go:embed underlay/castle.webp + underlay7Res []byte -var walletIconRes = theme.NewThemedResource(&fyne.StaticResource{ - StaticName: "wallet", - StaticContent: walletRes, -}) + //go:embed underlay/clever.webp + underlay8Res []byte -var percentIconRes = theme.NewThemedResource(&fyne.StaticResource{ - StaticName: "mrtp", - StaticContent: percentRes, -}) + //go:embed underlay/dices.webp + underlay9Res []byte -var accessIconRes = theme.NewThemedResource(&fyne.StaticResource{ - StaticName: "access", - StaticContent: accessRes, -}) + //go:embed underlay/dragon.webp + underlay10Res []byte +) + +// icon resources +var ( + loginIconRes = theme.NewThemedResource(&fyne.StaticResource{ + StaticName: "login", + StaticContent: loginRes, + }) + logoutIconRes = theme.NewThemedResource(&fyne.StaticResource{ + StaticName: "logout", + StaticContent: logoutRes, + }) + useraddIconRes = theme.NewThemedResource(&fyne.StaticResource{ + StaticName: "useradd", + StaticContent: useraddRes, + }) + userdelIconRes = theme.NewThemedResource(&fyne.StaticResource{ + StaticName: "userdel", + StaticContent: userdelRes, + }) + walletIconRes = theme.NewThemedResource(&fyne.StaticResource{ + StaticName: "wallet", + StaticContent: walletRes, + }) + percentIconRes = theme.NewThemedResource(&fyne.StaticResource{ + StaticName: "mrtp", + StaticContent: percentRes, + }) + accessIconRes = theme.NewThemedResource(&fyne.StaticResource{ + StaticName: "access", + StaticContent: accessRes, + }) + bankIconRes = theme.NewThemedResource(&fyne.StaticResource{ + StaticName: "bank", + StaticContent: bankRes, + }) +) -var bankIconRes = theme.NewThemedResource(&fyne.StaticResource{ - StaticName: "bank", - StaticContent: bankRes, -}) +// underlay resources +var ( + underlay1ImgRes = &fyne.StaticResource{ + StaticName: "cards1", + StaticContent: underlay1Res, + } + underlay2ImgRes = &fyne.StaticResource{ + StaticName: "cards2", + StaticContent: underlay2Res, + } + underlay3ImgRes = &fyne.StaticResource{ + StaticName: "cards3", + StaticContent: underlay3Res, + } + underlay4ImgRes = &fyne.StaticResource{ + StaticName: "cards4", + StaticContent: underlay4Res, + } + underlay5ImgRes = &fyne.StaticResource{ + StaticName: "cards5", + StaticContent: underlay5Res, + } + underlay6ImgRes = &fyne.StaticResource{ + StaticName: "cards6", + StaticContent: underlay6Res, + } + underlay7ImgRes = &fyne.StaticResource{ + StaticName: "castle", + StaticContent: underlay7Res, + } + underlay8ImgRes = &fyne.StaticResource{ + StaticName: "clever", + StaticContent: underlay8Res, + } + underlay9ImgRes = &fyne.StaticResource{ + StaticName: "dices", + StaticContent: underlay9Res, + } + underlay10ImgRes = &fyne.StaticResource{ + StaticName: "dragon", + StaticContent: underlay10Res, + } +) diff --git a/core/ui.go b/core/ui.go index 3a867b5..8634372 100644 --- a/core/ui.go +++ b/core/ui.go @@ -3,9 +3,11 @@ package core import ( "fmt" "log" + "math/rand/v2" "strconv" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/widget" cfg "github.com/slotopol/balance/config" @@ -42,7 +44,62 @@ func (tl *ToolbarLabel) ToolbarObject() fyne.CanvasObject { return tl } +// Layout that fits the images to whole space and cuts edges if it needs. +type FitLayout struct { +} + +func (l FitLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) { + var ratiofit = size.Width / size.Height + for _, child := range objects { + var newsize = size + var pos = fyne.NewPos(0, 0) + if img, ok := child.(*canvas.Image); ok { + var ratioimg = img.Aspect() + if ratiofit > ratioimg { + newsize.Height = size.Width / ratioimg + pos.Y = (size.Height - newsize.Height) / 2 + } else { + newsize.Width = size.Height * ratioimg + pos.Y = (size.Width - newsize.Width) / 2 + } + } + child.Resize(newsize) + child.Move(pos) + } +} + +func (l FitLayout) MinSize(objects []fyne.CanvasObject) fyne.Size { + var minSize = fyne.NewSize(0, 0) + for _, child := range objects { + if !child.Visible() { + continue + } + minSize = minSize.Max(child.MinSize()) + } + return minSize +} + +var underlays = []*fyne.StaticResource{ + underlay1ImgRes, + underlay2ImgRes, + underlay3ImgRes, + underlay4ImgRes, + underlay5ImgRes, + underlay6ImgRes, + underlay7ImgRes, + underlay8ImgRes, + underlay9ImgRes, + underlay10ImgRes, +} + var ( + // Backgroud image + underlay = &canvas.Image{ + Resource: underlays[rand.N(len(underlays))], + FillMode: canvas.ImageFillContain, + Translucency: 0.85, + } + // Toolbar buttons useraddBut = widget.NewToolbarAction(useraddIconRes, func() { fmt.Println("useradd") }) userdelBut = widget.NewToolbarAction(userdelIconRes, func() { fmt.Println("userdel") }) @@ -134,10 +191,13 @@ var ( } // Main page - mainPage = container.NewBorder( - container.NewVBox(toolbar, clubtabs), - nil, nil, nil, - userlist) + mainPage = container.NewStack( + container.New(FitLayout{}, underlay), + container.NewBorder( + container.NewVBox(toolbar, clubtabs), + nil, nil, nil, + userlist), + ) ) // Refreshes visible content of users list. Fetches data from server diff --git a/core/underlay/cards1.webp b/core/underlay/cards1.webp new file mode 100644 index 0000000..9c5d820 Binary files /dev/null and b/core/underlay/cards1.webp differ diff --git a/core/underlay/cards2.webp b/core/underlay/cards2.webp new file mode 100644 index 0000000..a92c484 Binary files /dev/null and b/core/underlay/cards2.webp differ diff --git a/core/underlay/cards3.webp b/core/underlay/cards3.webp new file mode 100644 index 0000000..eba15c6 Binary files /dev/null and b/core/underlay/cards3.webp differ diff --git a/core/underlay/cards4.webp b/core/underlay/cards4.webp new file mode 100644 index 0000000..7d29616 Binary files /dev/null and b/core/underlay/cards4.webp differ diff --git a/core/underlay/cards5.webp b/core/underlay/cards5.webp new file mode 100644 index 0000000..8bd678d Binary files /dev/null and b/core/underlay/cards5.webp differ diff --git a/core/underlay/cards6.webp b/core/underlay/cards6.webp new file mode 100644 index 0000000..69e23fe Binary files /dev/null and b/core/underlay/cards6.webp differ diff --git a/core/underlay/castle.webp b/core/underlay/castle.webp new file mode 100644 index 0000000..9b1d0e5 Binary files /dev/null and b/core/underlay/castle.webp differ diff --git a/core/underlay/clever.webp b/core/underlay/clever.webp new file mode 100644 index 0000000..d847adc Binary files /dev/null and b/core/underlay/clever.webp differ diff --git a/core/underlay/dices.webp b/core/underlay/dices.webp new file mode 100644 index 0000000..60edd9e Binary files /dev/null and b/core/underlay/dices.webp differ diff --git a/core/underlay/dragon.webp b/core/underlay/dragon.webp new file mode 100644 index 0000000..438631e Binary files /dev/null and b/core/underlay/dragon.webp differ diff --git a/go.mod b/go.mod index 5ce8a3b..8c80636 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.23 require ( fyne.io/fyne/v2 v2.5.2 github.com/spf13/viper v1.8.1 + golang.org/x/image v0.18.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -41,7 +42,6 @@ require ( github.com/stretchr/testify v1.8.4 // indirect github.com/subosito/gotenv v1.2.0 // indirect github.com/yuin/goldmark v1.7.1 // indirect - golang.org/x/image v0.18.0 // indirect golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a // indirect golang.org/x/net v0.25.0 // indirect golang.org/x/sys v0.20.0 // indirect