added a custom Theme using the fyne-theme-generator
This commit is contained in:
parent
4ecbbf4c83
commit
b0b04d23b1
|
@ -1,6 +1,8 @@
|
||||||
package game
|
package game
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"tictactoe/theme"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
|
@ -13,10 +15,12 @@ var TextLabel *widget.Label
|
||||||
// creates a window for the TicTacToe game application.
|
// creates a window for the TicTacToe game application.
|
||||||
func CreateWindow() fyne.Window {
|
func CreateWindow() fyne.Window {
|
||||||
// Create the app.
|
// Create the app.
|
||||||
myApp := app.New()
|
App := app.New()
|
||||||
|
|
||||||
|
// Adding a theme to my Window
|
||||||
|
App.Settings().SetTheme(theme.TicTacToeTheme{})
|
||||||
// Create a new window for the game application.
|
// Create a new window for the game application.
|
||||||
myWindow := myApp.NewWindow("TicTacToe")
|
Window := App.NewWindow("TicTacToe")
|
||||||
|
|
||||||
// Set the text of our TextLabel to TicTacToe
|
// Set the text of our TextLabel to TicTacToe
|
||||||
TextLabel = widget.NewLabel("TicTacToe")
|
TextLabel = widget.NewLabel("TicTacToe")
|
||||||
|
@ -34,9 +38,9 @@ func CreateWindow() fyne.Window {
|
||||||
content := container.New(layout.NewBorderLayout(topItems, nil, nil, nil), topItems, matchField)
|
content := container.New(layout.NewBorderLayout(topItems, nil, nil, nil), topItems, matchField)
|
||||||
|
|
||||||
// Set the content and size of the window.
|
// Set the content and size of the window.
|
||||||
myWindow.SetContent(content)
|
Window.SetContent(content)
|
||||||
myWindow.Resize(fyne.NewSize(300, 300))
|
Window.Resize(fyne.NewSize(300, 300))
|
||||||
|
|
||||||
// Return the created window.
|
// Return the created window.
|
||||||
return myWindow
|
return Window
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
// Code generated by fyne-theme-generator
|
||||||
|
|
||||||
|
package theme
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image/color"
|
||||||
|
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/theme"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TicTacToeTheme struct{}
|
||||||
|
|
||||||
|
func (TicTacToeTheme) Color(c fyne.ThemeColorName, v fyne.ThemeVariant) color.Color {
|
||||||
|
switch c {
|
||||||
|
case theme.ColorNameBackground:
|
||||||
|
return color.NRGBA{R: 0x13, G: 0x37, B: 0x73, A: 0xff}
|
||||||
|
case theme.ColorNameButton:
|
||||||
|
return color.NRGBA{R: 0x1e, G: 0x57, B: 0xba, A: 0xff}
|
||||||
|
case theme.ColorNameDisabledButton:
|
||||||
|
return color.NRGBA{R: 0x9, G: 0x19, B: 0x36, A: 0xff}
|
||||||
|
case theme.ColorNameDisabled:
|
||||||
|
return color.NRGBA{R: 0x54, G: 0x66, B: 0x87, A: 0xff}
|
||||||
|
case theme.ColorNameError:
|
||||||
|
return color.NRGBA{R: 0xf4, G: 0x43, B: 0x36, A: 0xff}
|
||||||
|
case theme.ColorNameFocus:
|
||||||
|
return color.NRGBA{R: 0x4a, G: 0x72, B: 0xbd, A: 0xff}
|
||||||
|
case theme.ColorNameForeground:
|
||||||
|
return color.NRGBA{R: 0xbd, G: 0xd5, B: 0xff, A: 0xff}
|
||||||
|
case theme.ColorNameHover:
|
||||||
|
return color.NRGBA{R: 0x56, G: 0x7a, B: 0xba, A: 0xff}
|
||||||
|
case theme.ColorNameInputBackground:
|
||||||
|
return color.NRGBA{R: 0xff, G: 0xff, B: 0xff, A: 0x19}
|
||||||
|
case theme.ColorNamePlaceHolder:
|
||||||
|
return color.NRGBA{R: 0xb2, G: 0xb2, B: 0xb2, A: 0xff}
|
||||||
|
case theme.ColorNamePressed:
|
||||||
|
return color.NRGBA{R: 0xff, G: 0xff, B: 0xff, A: 0x66}
|
||||||
|
case theme.ColorNamePrimary:
|
||||||
|
return color.NRGBA{R: 0x21, G: 0x96, B: 0xf3, A: 0xff}
|
||||||
|
case theme.ColorNameScrollBar:
|
||||||
|
return color.NRGBA{R: 0x0, G: 0x0, B: 0x0, A: 0x99}
|
||||||
|
case theme.ColorNameShadow:
|
||||||
|
return color.NRGBA{R: 0x0, G: 0x0, B: 0x0, A: 0x66}
|
||||||
|
default:
|
||||||
|
return theme.DefaultTheme().Color(c, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (TicTacToeTheme) Font(s fyne.TextStyle) fyne.Resource {
|
||||||
|
if s.Monospace {
|
||||||
|
return theme.DefaultTheme().Font(s)
|
||||||
|
}
|
||||||
|
if s.Bold {
|
||||||
|
if s.Italic {
|
||||||
|
return theme.DefaultTheme().Font(s)
|
||||||
|
}
|
||||||
|
return theme.DefaultTheme().Font(s)
|
||||||
|
}
|
||||||
|
if s.Italic {
|
||||||
|
return theme.DefaultTheme().Font(s)
|
||||||
|
}
|
||||||
|
return theme.DefaultTheme().Font(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (TicTacToeTheme) Icon(n fyne.ThemeIconName) fyne.Resource {
|
||||||
|
return theme.DefaultTheme().Icon(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (TicTacToeTheme) Size(s fyne.ThemeSizeName) float32 {
|
||||||
|
switch s {
|
||||||
|
case theme.SizeNameCaptionText:
|
||||||
|
return 11
|
||||||
|
case theme.SizeNameInlineIcon:
|
||||||
|
return 20
|
||||||
|
case theme.SizeNamePadding:
|
||||||
|
return 4
|
||||||
|
case theme.SizeNameScrollBar:
|
||||||
|
return 16
|
||||||
|
case theme.SizeNameScrollBarSmall:
|
||||||
|
return 3
|
||||||
|
case theme.SizeNameSeparatorThickness:
|
||||||
|
return 1
|
||||||
|
case theme.SizeNameText:
|
||||||
|
return 14
|
||||||
|
case theme.SizeNameInputBorder:
|
||||||
|
return 2
|
||||||
|
default:
|
||||||
|
return theme.DefaultTheme().Size(s)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue