Skip to content

Commit

Permalink
underlays added.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwarzlichtbezirk committed Nov 17, 2024
1 parent 2df504d commit 5cfaafe
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 53 deletions.
173 changes: 125 additions & 48 deletions core/res.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
)
68 changes: 64 additions & 4 deletions core/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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") })
Expand Down Expand Up @@ -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
Expand Down
Binary file added core/underlay/cards1.webp
Binary file not shown.
Binary file added core/underlay/cards2.webp
Binary file not shown.
Binary file added core/underlay/cards3.webp
Binary file not shown.
Binary file added core/underlay/cards4.webp
Binary file not shown.
Binary file added core/underlay/cards5.webp
Binary file not shown.
Binary file added core/underlay/cards6.webp
Binary file not shown.
Binary file added core/underlay/castle.webp
Binary file not shown.
Binary file added core/underlay/clever.webp
Binary file not shown.
Binary file added core/underlay/dices.webp
Binary file not shown.
Binary file added core/underlay/dragon.webp
Binary file not shown.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5cfaafe

Please sign in to comment.