153 lines
4.1 KiB
Go
153 lines
4.1 KiB
Go
package gio
|
|
|
|
import (
|
|
"gioui.org/layout"
|
|
"gioui.org/unit"
|
|
"gioui.org/widget"
|
|
"gioui.org/widget/material"
|
|
|
|
"softbox.local/core/application"
|
|
)
|
|
|
|
func (shell *AppShell) layoutHeader(
|
|
gtx layout.Context,
|
|
theme *material.Theme,
|
|
) layout.Dimensions {
|
|
return layout.Flex{Axis: layout.Vertical}.Layout(
|
|
gtx,
|
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
|
return layout.Flex{Alignment: layout.Middle}.Layout(
|
|
gtx,
|
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
|
return layout.Flex{Axis: layout.Vertical}.Layout(
|
|
gtx,
|
|
layout.Rigid(material.H4(theme, "SoftBox").Layout),
|
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
|
label := material.Body2(theme, "发现、安装并更新可信软件")
|
|
label.Color = shellColors.secondary
|
|
return label.Layout(gtx)
|
|
}),
|
|
)
|
|
}),
|
|
layout.Rigid(layout.Spacer{Width: unit.Dp(48)}.Layout),
|
|
layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
|
|
border := shellColors.border
|
|
if gtx.Focused(&shell.search) {
|
|
border = shellColors.primary
|
|
}
|
|
return outlinedPanel(
|
|
gtx,
|
|
border,
|
|
shellColors.surface,
|
|
unit.Dp(8),
|
|
layout.Inset{
|
|
Top: unit.Dp(10), Bottom: unit.Dp(10),
|
|
Left: unit.Dp(14), Right: unit.Dp(14),
|
|
},
|
|
func(gtx layout.Context) layout.Dimensions {
|
|
gtx.Constraints.Min.Y = gtx.Dp(unit.Dp(24))
|
|
editor := material.Editor(theme, &shell.search, "搜索名称、软件 ID 或标签")
|
|
editor.TextSize = unit.Sp(15)
|
|
return editor.Layout(gtx)
|
|
},
|
|
)
|
|
}),
|
|
)
|
|
}),
|
|
layout.Rigid(layout.Spacer{Height: unit.Dp(12)}.Layout),
|
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
|
return shell.layoutCategories(gtx, theme)
|
|
}),
|
|
)
|
|
}
|
|
|
|
func (shell *AppShell) layoutCategories(
|
|
gtx layout.Context,
|
|
theme *material.Theme,
|
|
) layout.Dimensions {
|
|
categories := append([]string{""}, shell.model.Categories()...)
|
|
height := gtx.Dp(unit.Dp(44))
|
|
gtx.Constraints.Min.Y = height
|
|
gtx.Constraints.Max.Y = height
|
|
return shell.categoryList.Layout(gtx, len(categories), func(
|
|
gtx layout.Context,
|
|
index int,
|
|
) layout.Dimensions {
|
|
category := categories[index]
|
|
label := category
|
|
if label == "" {
|
|
label = "全部分类"
|
|
}
|
|
return layout.Inset{Right: unit.Dp(8)}.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
|
return shell.layoutFilterButton(
|
|
gtx,
|
|
theme,
|
|
shell.categoryControls[category],
|
|
label,
|
|
shell.model.Category() == category,
|
|
)
|
|
})
|
|
})
|
|
}
|
|
|
|
func (shell *AppShell) layoutViewButton(
|
|
gtx layout.Context,
|
|
theme *material.Theme,
|
|
clickable *widget.Clickable,
|
|
label string,
|
|
view application.CatalogView,
|
|
) layout.Dimensions {
|
|
gtx.Constraints.Min.X = gtx.Constraints.Max.X
|
|
return shell.layoutFilterButton(
|
|
gtx,
|
|
theme,
|
|
clickable,
|
|
label,
|
|
shell.model.View() == view,
|
|
)
|
|
}
|
|
|
|
func (shell *AppShell) layoutFilterButton(
|
|
gtx layout.Context,
|
|
theme *material.Theme,
|
|
clickable *widget.Clickable,
|
|
label string,
|
|
active bool,
|
|
) layout.Dimensions {
|
|
gtx.Constraints.Min.Y = gtx.Dp(unit.Dp(44))
|
|
button := material.Button(theme, clickable, label)
|
|
button.CornerRadius = unit.Dp(8)
|
|
button.Inset = layout.Inset{
|
|
Top: unit.Dp(10), Bottom: unit.Dp(10),
|
|
Left: unit.Dp(14), Right: unit.Dp(14),
|
|
}
|
|
if active {
|
|
button.Background = shellColors.primary
|
|
button.Color = shellColors.onPrimary
|
|
} else {
|
|
button.Background = shellColors.muted
|
|
button.Color = shellColors.foreground
|
|
}
|
|
return button.Layout(gtx)
|
|
}
|
|
|
|
func (shell *AppShell) layoutFooter(
|
|
gtx layout.Context,
|
|
theme *material.Theme,
|
|
) layout.Dimensions {
|
|
return layout.Flex{Alignment: layout.Middle}.Layout(
|
|
gtx,
|
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
|
label := material.Caption(theme, "目录状态:等待已验证 Catalog")
|
|
label.Color = shellColors.secondary
|
|
return label.Layout(gtx)
|
|
}),
|
|
layout.Flexed(1, layout.Spacer{}.Layout),
|
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
|
label := material.Caption(theme, shell.edition+" · Windows 10/11 x64")
|
|
label.Color = shellColors.secondary
|
|
return label.Layout(gtx)
|
|
}),
|
|
)
|
|
}
|