Split Gio shell responsibilities (T-610)
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
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.H5(theme, "SoftBox Legacy").Layout),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
label := material.Caption(theme, "兼容 Windows 7 SP1 的可信软件目录")
|
||||
label.Color = shellColors.secondary
|
||||
return label.Layout(gtx)
|
||||
}),
|
||||
)
|
||||
}),
|
||||
layout.Rigid(layout.Spacer{Width: unit.Dp(32)}.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(6),
|
||||
layout.Inset{
|
||||
Top: unit.Dp(9), Bottom: unit.Dp(9),
|
||||
Left: unit.Dp(12), Right: unit.Dp(12),
|
||||
},
|
||||
func(gtx layout.Context) layout.Dimensions {
|
||||
editor := material.Editor(theme, &shell.search, "搜索名称、ID 或标签")
|
||||
editor.TextSize = unit.Sp(14)
|
||||
return editor.Layout(gtx)
|
||||
},
|
||||
)
|
||||
}),
|
||||
)
|
||||
}),
|
||||
layout.Rigid(layout.Spacer{Height: unit.Dp(8)}.Layout),
|
||||
layout.Rigid(func(gtx layout.Context) 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(6)}.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(5)
|
||||
button.Inset = layout.Inset{
|
||||
Top: unit.Dp(10), Bottom: unit.Dp(10),
|
||||
Left: unit.Dp(12), Right: unit.Dp(12),
|
||||
}
|
||||
if active {
|
||||
button.Background = shellColors.primary
|
||||
button.Color = shellColors.onPrimary
|
||||
} else {
|
||||
button.Background = shellColors.muted
|
||||
button.Color = shellColors.foreground
|
||||
}
|
||||
return button.Layout(gtx)
|
||||
}
|
||||
Reference in New Issue
Block a user