Simplify lifecycle and section UI
This commit is contained in:
+78
-5
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gioui.org/layout"
|
||||
@@ -17,11 +18,11 @@ func (u *ui) lifecycleControls(gtx layout.Context) layout.Dimensions {
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return layout.Flex{Spacing: layout.SpaceStart}.Layout(gtx,
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return tonedButton(gtx, u.theme, &u.showLocalLifecycle, "Local Vault")
|
||||
return sectionTabButton(gtx, u.theme, &u.showLocalLifecycle, "Local Vault", u.lifecycleMode == "local")
|
||||
}),
|
||||
layout.Rigid(layout.Spacer{Width: unit.Dp(6)}.Layout),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return tonedButton(gtx, u.theme, &u.showRemoteLifecycle, "Remote Vault")
|
||||
return sectionTabButton(gtx, u.theme, &u.showRemoteLifecycle, "Remote Vault", u.lifecycleMode == "remote")
|
||||
}),
|
||||
)
|
||||
}),
|
||||
@@ -61,9 +62,18 @@ func (u *ui) lifecycleControls(gtx layout.Context) layout.Dimensions {
|
||||
)
|
||||
}),
|
||||
layout.Rigid(layout.Spacer{Height: unit.Dp(8)}.Layout),
|
||||
layout.Rigid(labeledEditorHelp(u.theme, "Cipher", "Supported values: aes256, chacha20", &u.securityCipher, false)),
|
||||
layout.Rigid(u.lifecycleAdvancedDisclosure),
|
||||
layout.Rigid(layout.Spacer{Height: unit.Dp(6)}.Layout),
|
||||
layout.Rigid(labeledEditorHelp(u.theme, "KDF", "Supported values: aes-kdf, argon2", &u.securityKDF, false)),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
if u.lifecycleAdvancedHidden {
|
||||
return layout.Dimensions{}
|
||||
}
|
||||
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
|
||||
layout.Rigid(labeledEditorHelp(u.theme, "Cipher", "Used for new vaults and future saves. Supported values: aes256, chacha20.", &u.securityCipher, false)),
|
||||
layout.Rigid(layout.Spacer{Height: unit.Dp(6)}.Layout),
|
||||
layout.Rigid(labeledEditorHelp(u.theme, "KDF", "Used for new vaults and future saves. Supported values: aes-kdf, argon2.", &u.securityKDF, false)),
|
||||
)
|
||||
}),
|
||||
layout.Rigid(layout.Spacer{Height: unit.Dp(8)}.Layout),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
if u.lifecycleMode == "remote" {
|
||||
@@ -82,6 +92,36 @@ func (u *ui) lifecycleControls(gtx layout.Context) layout.Dimensions {
|
||||
)
|
||||
}
|
||||
|
||||
func (u *ui) lifecycleAdvancedDisclosure(gtx layout.Context) layout.Dimensions {
|
||||
return u.toggleLifecycleAdvanced.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||
return layout.UniformInset(unit.Dp(2)).Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||
return layout.Flex{Alignment: layout.Middle}.Layout(gtx,
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
icon := u.expandLessIcon
|
||||
if u.lifecycleAdvancedHidden {
|
||||
icon = u.expandMoreIcon
|
||||
}
|
||||
if icon != nil {
|
||||
return icon.Layout(gtx, accentColor)
|
||||
}
|
||||
lbl := material.Label(u.theme, unit.Sp(16), ">")
|
||||
if !u.lifecycleAdvancedHidden {
|
||||
lbl.Text = "v"
|
||||
}
|
||||
lbl.Color = accentColor
|
||||
return lbl.Layout(gtx)
|
||||
}),
|
||||
layout.Rigid(layout.Spacer{Width: unit.Dp(4)}.Layout),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
lbl := material.Label(u.theme, unit.Sp(12), "Advanced Vault Settings")
|
||||
lbl.Color = mutedColor
|
||||
return lbl.Layout(gtx)
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (u *ui) recentVaultList(gtx layout.Context) layout.Dimensions {
|
||||
if len(u.recentVaults) == 0 {
|
||||
return layout.Dimensions{}
|
||||
@@ -102,6 +142,9 @@ func (u *ui) recentVaultList(gtx layout.Context) layout.Dimensions {
|
||||
for i, path := range u.recentVaults {
|
||||
index := i
|
||||
label := path
|
||||
if friendly := friendlyRecentVaultLabel(path); friendly != "" {
|
||||
label = friendly
|
||||
}
|
||||
children = append(children, layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return tonedButton(gtx, u.theme, &u.recentVaultClicks[index], label)
|
||||
}))
|
||||
@@ -134,7 +177,7 @@ func (u *ui) recentRemoteList(gtx layout.Context) layout.Dimensions {
|
||||
children := make([]layout.FlexChild, 0, len(u.recentRemotes)*2)
|
||||
for i, record := range u.recentRemotes {
|
||||
index := i
|
||||
label := record.BaseURL + " / " + record.Path
|
||||
label := friendlyRecentRemoteLabel(record)
|
||||
children = append(children, layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return tonedButton(gtx, u.theme, &u.recentRemoteClicks[index], label)
|
||||
}))
|
||||
@@ -148,6 +191,36 @@ func (u *ui) recentRemoteList(gtx layout.Context) layout.Dimensions {
|
||||
)
|
||||
}
|
||||
|
||||
func friendlyRecentVaultLabel(path string) string {
|
||||
value := strings.TrimSpace(path)
|
||||
if value == "" {
|
||||
return ""
|
||||
}
|
||||
base := filepath.Base(value)
|
||||
if base == "." || base == string(filepath.Separator) || base == "" {
|
||||
return value
|
||||
}
|
||||
return base
|
||||
}
|
||||
|
||||
func friendlyRecentRemoteLabel(record recentRemoteRecord) string {
|
||||
baseURL := strings.TrimSpace(record.BaseURL)
|
||||
path := strings.TrimSpace(record.Path)
|
||||
if baseURL == "" && path == "" {
|
||||
return ""
|
||||
}
|
||||
host := strings.TrimSpace(strings.TrimPrefix(strings.TrimPrefix(baseURL, "https://"), "http://"))
|
||||
host = strings.TrimSuffix(host, "/")
|
||||
switch {
|
||||
case host == "":
|
||||
return path
|
||||
case path == "":
|
||||
return host
|
||||
default:
|
||||
return host + " · " + path
|
||||
}
|
||||
}
|
||||
|
||||
func (u *ui) attachmentList(gtx layout.Context) layout.Dimensions {
|
||||
items := u.selectedAttachmentItems()
|
||||
if len(items) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user