Skip to content

Commit

Permalink
add: add palette organizer in sprite tab
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelesaux committed Nov 17, 2024
1 parent 551bfcb commit f84c86c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ui/martine-ui/menu/sprite_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
w "github.com/jeromelesaux/fyne-io/widget"
"github.com/jeromelesaux/martine/config"
"github.com/jeromelesaux/martine/export/compression"
"github.com/jeromelesaux/martine/export/png"
"github.com/jeromelesaux/martine/log"
"github.com/jeromelesaux/martine/ui/martine-ui/directory"
)
Expand All @@ -41,6 +42,8 @@ type SpriteMenu struct {
func (s *SpriteMenu) SetPalette(p color.Palette) {
s.UsePalette = true
s.palette = p
s.paletteImage.Image = png.PalToImage(s.Palette())
s.paletteImage.Refresh()
}

func (s *SpriteMenu) Palette() color.Palette {
Expand Down Expand Up @@ -164,4 +167,5 @@ func (s *SpriteMenu) CmdLine() string {

func (s *SpriteMenu) SetOrderedPalette(p color.Palette) {
s.SetPalette(p)
s.UsePalette = true
}
13 changes: 12 additions & 1 deletion ui/martine-ui/sprite_tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fyne.io/fyne/v2/widget"
"github.com/disintegration/imaging"
wgt "github.com/jeromelesaux/fyne-io/widget"
"github.com/jeromelesaux/fyne-io/widget/palette/orderer"
"github.com/jeromelesaux/martine/config"
"github.com/jeromelesaux/martine/constants"
"github.com/jeromelesaux/martine/gfx"
Expand Down Expand Up @@ -213,6 +214,15 @@ func (m *MartineUI) newSpriteTab(s *menu.SpriteMenu) *fyne.Container {
importOpen := ImportSpriteBoard(m)
gifOpen := applySpriteBoardFromGif(s, m)

organizePalButton := widget.NewButtonWithIcon("Organize", theme.ContentPasteIcon(), func() {
organizePalette := orderer.NewOrderer(s.Palette(), s.SetOrderedPalette)
d := dialog.NewCustom("Edit Palette", "Cancel", organizePalette.NewOrderer(), m.window)
size := m.window.Content().Size()
size = fyne.Size{Width: size.Width, Height: size.Height}
d.Resize(size)
d.Show()
})

return container.New(
layout.NewGridLayoutWithColumns(2),
container.New(
Expand Down Expand Up @@ -267,7 +277,7 @@ func (m *MartineUI) newSpriteTab(s *menu.SpriteMenu) *fyne.Container {
),
),
container.New(
layout.NewGridLayoutWithRows(4),
layout.NewGridLayoutWithRows(5),
container.New(layout.NewGridLayoutWithColumns(2),
widget.NewCheck("Use this palette", func(b bool) {
s.UsePalette = b
Expand All @@ -283,6 +293,7 @@ func (m *MartineUI) newSpriteTab(s *menu.SpriteMenu) *fyne.Container {
layout.NewGridLayoutWithRows(2),
s.PaletteImage(),
),
organizePalButton,
),
container.New(
layout.NewVBoxLayout(),
Expand Down

0 comments on commit f84c86c

Please sign in to comment.