feature/ui - zatim ne uplne uhlazena ale celkem pouzitelna appka #1
65
ui.go
65
ui.go
@ -63,40 +63,21 @@ func (p *uiParts) showToast(msg string) {
|
||||
})
|
||||
}
|
||||
|
||||
// theme toggle
|
||||
// Simple theme variants using built-in with preference respecting variant
|
||||
// lightOverride & darkOverride implement fyne.Theme with adjusted primary/background colors.
|
||||
// minimal two themes (light/dark) customizing a couple of colors
|
||||
type simpleTheme struct{ dark bool }
|
||||
// custom fixed dark theme
|
||||
type simpleTheme struct{}
|
||||
|
||||
func (s simpleTheme) Color(n fyne.ThemeColorName, v fyne.ThemeVariant) color.Color {
|
||||
func (simpleTheme) Color(n fyne.ThemeColorName, v fyne.ThemeVariant) color.Color {
|
||||
base := theme.DefaultTheme().Color(n, v)
|
||||
if !s.dark {
|
||||
return base
|
||||
}
|
||||
// dark tweak: slightly desaturate backgrounds
|
||||
if n == theme.ColorNameBackground || n == theme.ColorNameButton {
|
||||
return color.NRGBA{R: 30, G: 34, B: 39, A: 255}
|
||||
}
|
||||
return base
|
||||
}
|
||||
func (s simpleTheme) Font(st fyne.TextStyle) fyne.Resource { return theme.DefaultTheme().Font(st) }
|
||||
func (s simpleTheme) Icon(n fyne.ThemeIconName) fyne.Resource { return theme.DefaultTheme().Icon(n) }
|
||||
func (s simpleTheme) Size(n fyne.ThemeSizeName) float32 { return theme.DefaultTheme().Size(n) }
|
||||
func (simpleTheme) Font(st fyne.TextStyle) fyne.Resource { return theme.DefaultTheme().Font(st) }
|
||||
func (simpleTheme) Icon(n fyne.ThemeIconName) fyne.Resource { return theme.DefaultTheme().Icon(n) }
|
||||
func (simpleTheme) Size(n fyne.ThemeSizeName) float32 { return theme.DefaultTheme().Size(n) }
|
||||
|
||||
var currentDark bool
|
||||
|
||||
func newThemeToggle(app fyne.App, parts *uiParts) *widget.Button {
|
||||
return widget.NewButton("🌗 Motiv", func() {
|
||||
currentDark = !currentDark
|
||||
app.Settings().SetTheme(simpleTheme{dark: currentDark})
|
||||
if currentDark {
|
||||
parts.showToast("Dark")
|
||||
} else {
|
||||
parts.showToast("Light")
|
||||
}
|
||||
})
|
||||
}
|
||||
var forceDark = true
|
||||
|
||||
// Build key section
|
||||
func buildIdentityTab(parts *uiParts, svc ServiceFacade) fyne.CanvasObject {
|
||||
@ -158,15 +139,16 @@ func buildEncryptTab(parts *uiParts, svc ServiceFacade) fyne.CanvasObject {
|
||||
}(m, p)
|
||||
}
|
||||
msgBtns := buttonTile(
|
||||
widget.NewButton("Clear+Paste", func() { parts.msg.SetText(""); parts.msg.SetText(fyne.CurrentApp().Clipboard().Content()) }),
|
||||
widget.NewButton("Encrypt", encAction),
|
||||
widget.NewButton("Copy", func() { copyClip(parts.cipherOut.Text, parts) }),
|
||||
widget.NewButton("Copy encrypted", func() { copyClip(parts.cipherOut.Text, parts) }),
|
||||
)
|
||||
resultBtns := buttonTile(widget.NewButton("Copy", func() { copyClip(parts.cipherOut.Text, parts) }))
|
||||
|
||||
group := container.NewVBox(
|
||||
widget.NewLabelWithStyle("Šifrování", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
|
||||
widget.NewLabel("Veřejný klíč příjemce"), peerBtns, parts.peer,
|
||||
widget.NewLabel("Zpráva"), msgBtns, parts.msg,
|
||||
widget.NewLabel("Výsledek"), resultBtns, parts.cipherOut,
|
||||
widget.NewLabel("Výsledek"), parts.cipherOut,
|
||||
)
|
||||
return container.NewVScroll(group)
|
||||
}
|
||||
@ -196,7 +178,7 @@ func buildDecryptTab(parts *uiParts, svc ServiceFacade) fyne.CanvasObject {
|
||||
decryptAction()
|
||||
}),
|
||||
// widget.NewButton("Decrypt", decryptAction),
|
||||
widget.NewButton("Clear", func() { parts.payload.SetText("") }),
|
||||
widget.NewButton("Clear", func() { parts.payload.SetText(""); parts.plainOut.SetText("") }),
|
||||
)
|
||||
plainBtns := buttonTile(widget.NewButton("Copy", func() { copyClip(parts.plainOut.Text, parts) }))
|
||||
group := container.NewVBox(
|
||||
@ -214,35 +196,22 @@ func buildTabbedUI(parts *uiParts, svc ServiceFacade) fyne.CanvasObject {
|
||||
tabs := container.NewAppTabs(idTab, encTab, decTab)
|
||||
tabs.SetTabLocation(container.TabLocationTop)
|
||||
|
||||
// top bar with theme toggle
|
||||
themeBtn := newThemeToggle(fyne.CurrentApp(), parts)
|
||||
// load preferences
|
||||
// apply fixed dark theme once
|
||||
fyne.CurrentApp().Settings().SetTheme(simpleTheme{})
|
||||
prefs := fyne.CurrentApp().Preferences()
|
||||
if prefs != nil {
|
||||
idx := prefs.IntWithFallback("lastTab", 0)
|
||||
if idx >= 0 && idx < len(tabs.Items) {
|
||||
tabs.SelectIndex(idx)
|
||||
}
|
||||
if prefs.Bool("darkTheme") {
|
||||
currentDark = true
|
||||
fyne.CurrentApp().Settings().SetTheme(simpleTheme{dark: true})
|
||||
}
|
||||
// only persist lastTab now
|
||||
}
|
||||
tabs.OnSelected = func(ti *container.TabItem) {
|
||||
if prefs != nil {
|
||||
prefs.SetInt("lastTab", tabs.SelectedIndex())
|
||||
}
|
||||
}
|
||||
// wrap toggle to persist theme choice
|
||||
oldAction := themeBtn.OnTapped
|
||||
themeBtn.OnTapped = func() {
|
||||
oldAction()
|
||||
if prefs != nil {
|
||||
prefs.SetBool("darkTheme", currentDark)
|
||||
}
|
||||
}
|
||||
topBar := container.NewBorder(nil, nil, nil, themeBtn, tabs)
|
||||
return container.NewBorder(nil, parts.toastLabel, nil, nil, topBar)
|
||||
return container.NewBorder(nil, parts.toastLabel, nil, nil, tabs)
|
||||
}
|
||||
|
||||
// buttonTile renders buttons above a related entry with a colored background spanning full width
|
||||
@ -256,7 +225,7 @@ func buttonTile(btns ...fyne.CanvasObject) fyne.CanvasObject {
|
||||
} // wrap into multiple rows if many
|
||||
grid := container.NewGridWithColumns(cols, btns...)
|
||||
bgColor := color.NRGBA{R: 240, G: 240, B: 245, A: 255}
|
||||
if currentDark {
|
||||
if forceDark {
|
||||
bgColor = color.NRGBA{R: 50, G: 54, B: 60, A: 255}
|
||||
}
|
||||
rect := canvas.NewRectangle(bgColor)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user