Changed tab style so the tabs are always visable
This commit is contained in:
@@ -1892,8 +1892,7 @@ func main() {
|
||||
exportSettingsBtn,
|
||||
importSettingsBtn,
|
||||
))
|
||||
// Create the main layout using a horizontal split
|
||||
tabs := container.NewAppTabs(
|
||||
tabItems := []*container.TabItem{
|
||||
imageTab,
|
||||
terrainTab,
|
||||
waterTab,
|
||||
@@ -1901,11 +1900,42 @@ func main() {
|
||||
fortificationsTab,
|
||||
textTab,
|
||||
buildingsTab,
|
||||
}
|
||||
tabContent := container.NewMax()
|
||||
tabButtons := make([]*tabButton, 0, len(tabItems))
|
||||
setActiveTab := func(name string) {
|
||||
for idx, item := range tabItems {
|
||||
if item.Text == name {
|
||||
tabContent.Objects = []fyne.CanvasObject{item.Content}
|
||||
tabContent.Refresh()
|
||||
for btnIdx, btn := range tabButtons {
|
||||
btn.setSelected(btnIdx == idx)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, item := range tabItems {
|
||||
tabName := item.Text
|
||||
btn := makeTabButton(tabName, func() {
|
||||
setActiveTab(tabName)
|
||||
})
|
||||
tabButtons = append(tabButtons, btn)
|
||||
}
|
||||
rowSplit := (len(tabButtons) + 1) / 2
|
||||
topRow := container.NewGridWithColumns(rowSplit, toTabCanvasObjects(tabButtons[:rowSplit])...)
|
||||
bottomRow := container.NewGridWithColumns(len(tabButtons)-rowSplit, toTabCanvasObjects(tabButtons[rowSplit:])...)
|
||||
tabHeader := container.NewVBox(
|
||||
topRow,
|
||||
bottomRow,
|
||||
widget.NewSeparator(),
|
||||
)
|
||||
setActiveTab(imageTab.Text)
|
||||
|
||||
left := container.NewVBox(
|
||||
widget.NewLabel("RPG City Maker Reborn"),
|
||||
tabs,
|
||||
tabHeader,
|
||||
tabContent,
|
||||
)
|
||||
|
||||
right := container.NewMax()
|
||||
@@ -2058,6 +2088,52 @@ func makeLegendItem(swatch color.Color, label string) fyne.CanvasObject {
|
||||
return container.NewHBox(container.NewStack(rect, outline), widget.NewLabel(label))
|
||||
}
|
||||
|
||||
type tabButton struct {
|
||||
widget *tappableImage
|
||||
bg *canvas.Rectangle
|
||||
label *canvas.Text
|
||||
selected bool
|
||||
}
|
||||
|
||||
func makeTabButton(title string, onTap func()) *tabButton {
|
||||
bg := canvas.NewRectangle(color.RGBA{R: 90, G: 90, B: 98, A: 255})
|
||||
bg.SetMinSize(fyne.NewSize(72, 30))
|
||||
label := canvas.NewText(title, color.RGBA{R: 255, G: 255, B: 255, A: 255})
|
||||
label.Alignment = fyne.TextAlignCenter
|
||||
label.TextStyle = fyne.TextStyle{Bold: true}
|
||||
content := container.NewStack(bg, container.NewCenter(label))
|
||||
button := newTappableImage(content, func(*fyne.PointEvent) {
|
||||
if onTap != nil {
|
||||
onTap()
|
||||
}
|
||||
})
|
||||
return &tabButton{
|
||||
widget: button,
|
||||
bg: bg,
|
||||
label: label,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *tabButton) setSelected(selected bool) {
|
||||
t.selected = selected
|
||||
if selected {
|
||||
t.bg.FillColor = color.RGBA{R: 44, G: 92, B: 148, A: 255}
|
||||
} else {
|
||||
t.bg.FillColor = color.RGBA{R: 90, G: 90, B: 98, A: 255}
|
||||
}
|
||||
t.bg.Refresh()
|
||||
t.label.Color = color.RGBA{R: 255, G: 255, B: 255, A: 255}
|
||||
t.label.Refresh()
|
||||
}
|
||||
|
||||
func toTabCanvasObjects(buttons []*tabButton) []fyne.CanvasObject {
|
||||
objects := make([]fyne.CanvasObject, 0, len(buttons))
|
||||
for _, btn := range buttons {
|
||||
objects = append(objects, btn.widget)
|
||||
}
|
||||
return objects
|
||||
}
|
||||
|
||||
func encodeImageToWriter(w io.Writer, img image.Image, format string) error {
|
||||
switch format {
|
||||
case "PNG":
|
||||
|
||||
Reference in New Issue
Block a user