feat: define theme, might not need this but oh well

This commit is contained in:
2024-07-23 08:55:10 -05:00
parent 920f61d3a2
commit fa897496a2
2 changed files with 66 additions and 8 deletions

15
main.go
View File

@@ -4,19 +4,18 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"github.com/ryanehamil/computerinfo/src/computerinfo"
"github.com/ryanehamil/computerinfo/src/utils"
)
func main() {
a := app.New()
App := app.New()
App.Settings().SetTheme(&utils.Theme{})
// create fyne resource for icon.png
// a.SetIcon(resourceIconPng)
Window := App.NewWindow("Computer Info")
w := a.NewWindow("Computer Info")
Window.Resize(fyne.NewSize(800, 200))
w.Resize(fyne.NewSize(800, 200))
Window.SetContent(computerinfo.Container())
w.SetContent(computerinfo.Container())
w.ShowAndRun()
Window.ShowAndRun()
}

59
src/utils/theme.go Normal file
View File

@@ -0,0 +1,59 @@
package utils
import (
"image/color"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
)
type Theme struct{}
var _ fyne.Theme = (*Theme)(nil)
// The color package has to be imported from "image/color".
func (m Theme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
if name == theme.ColorNameBackground {
if variant == theme.VariantLight {
// return color #eeeeee
return color.RGBA{238, 238, 238, 255}
}
// return color #222222
return color.RGBA{34, 34, 34, 255}
}
if name == theme.ColorNameForeground {
if variant == theme.VariantLight {
// return color #222222
return color.RGBA{34, 34, 34, 255}
}
// return color #eeeeee
return color.RGBA{238, 238, 238, 255}
}
if name == theme.ColorNameButton {
if variant == theme.VariantLight {
// return color #eeeeee
return color.RGBA{238, 238, 238, 255}
}
// return color #222222
return color.RGBA{34, 34, 34, 255}
}
return theme.DefaultTheme().Color(name, variant)
}
func (m Theme) Icon(name fyne.ThemeIconName) fyne.Resource {
// if name == theme.IconNameHome {
// return fyne.NewStaticResource("myHome", homeBytes)
// }
return theme.DefaultTheme().Icon(name)
}
func (m Theme) Font(style fyne.TextStyle) fyne.Resource {
return theme.DefaultTheme().Font(style)
}
func (m Theme) Size(name fyne.ThemeSizeName) float32 {
return theme.DefaultTheme().Size(name)
}