fix: tighten instance list action layout
This commit is contained in:
+36
-16
@@ -20,6 +20,14 @@ const (
|
|||||||
pageCreate
|
pageCreate
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
instanceNameColumnWeight = 25
|
||||||
|
instanceBrowserColumnWeight = 12
|
||||||
|
instanceDirectoryColumnWeight = 39
|
||||||
|
instanceStatusColumnWeight = 14
|
||||||
|
instanceStartColumnWeight = 10
|
||||||
|
)
|
||||||
|
|
||||||
type PathField string
|
type PathField string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -265,15 +273,13 @@ func (s *Shell) instances(gtx layout.Context) layout.Dimensions {
|
|||||||
layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
|
layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
|
||||||
return material.List(s.theme, &s.list).Layout(gtx, len(s.rows), func(gtx layout.Context, i int) layout.Dimensions {
|
return material.List(s.theme, &s.list).Layout(gtx, len(s.rows), func(gtx layout.Context, i int) layout.Dimensions {
|
||||||
row := s.rows[i]
|
row := s.rows[i]
|
||||||
return layout.Inset{Bottom: unit.Dp(10)}.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
return layout.Inset{Right: unit.Dp(4), Bottom: unit.Dp(10)}.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||||
return layout.Flex{Alignment: layout.Middle}.Layout(gtx,
|
return layout.Flex{Alignment: layout.Middle}.Layout(gtx,
|
||||||
layout.Flexed(30, material.Body1(s.theme, row.Name).Layout),
|
layout.Flexed(instanceNameColumnWeight, material.Body1(s.theme, row.Name).Layout),
|
||||||
layout.Flexed(14, material.Body2(s.theme, row.Browser).Layout),
|
layout.Flexed(instanceBrowserColumnWeight, material.Body2(s.theme, row.Browser).Layout),
|
||||||
layout.Flexed(26, pathCell(s.theme, row.UserDataDir)),
|
layout.Flexed(instanceDirectoryColumnWeight, pathCell(s.theme, row.UserDataDir)),
|
||||||
layout.Flexed(16, statusLabel(s.theme, row.Status)),
|
layout.Flexed(instanceStatusColumnWeight, statusLabel(s.theme, row.Status)),
|
||||||
layout.Flexed(14, func(gtx layout.Context) layout.Dimensions {
|
layout.Flexed(instanceStartColumnWeight, s.instanceStartButton(s.startClickFor(row.ID))),
|
||||||
return material.Button(s.theme, s.startClickFor(row.ID), "启动").Layout(gtx)
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -284,21 +290,35 @@ func (s *Shell) instances(gtx layout.Context) layout.Dimensions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Shell) instanceHeader(gtx layout.Context) layout.Dimensions {
|
func (s *Shell) instanceHeader(gtx layout.Context) layout.Dimensions {
|
||||||
return layout.Flex{Alignment: layout.Middle}.Layout(gtx,
|
return layout.Inset{Right: unit.Dp(4)}.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||||
layout.Flexed(30, material.Caption(s.theme, "实例名称").Layout),
|
return layout.Flex{Alignment: layout.Middle}.Layout(gtx,
|
||||||
layout.Flexed(14, material.Caption(s.theme, "浏览器类型").Layout),
|
layout.Flexed(instanceNameColumnWeight, material.Caption(s.theme, "实例名称").Layout),
|
||||||
layout.Flexed(26, material.Caption(s.theme, "用户数据目录").Layout),
|
layout.Flexed(instanceBrowserColumnWeight, material.Caption(s.theme, "浏览器类型").Layout),
|
||||||
layout.Flexed(16, material.Caption(s.theme, "状态").Layout),
|
layout.Flexed(instanceDirectoryColumnWeight, material.Caption(s.theme, "用户数据目录").Layout),
|
||||||
layout.Flexed(14, material.Caption(s.theme, "启动").Layout),
|
layout.Flexed(instanceStatusColumnWeight, material.Caption(s.theme, "状态").Layout),
|
||||||
)
|
layout.Flexed(instanceStartColumnWeight, func(gtx layout.Context) layout.Dimensions {
|
||||||
|
return layout.E.Layout(gtx, material.Caption(s.theme, "启动").Layout)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func pathCell(theme *material.Theme, path string) layout.Widget {
|
func pathCell(theme *material.Theme, path string) layout.Widget {
|
||||||
style := material.Body2(theme, path)
|
style := material.Body2(theme, path)
|
||||||
style.MaxLines = 2
|
style.MaxLines = 1
|
||||||
return style.Layout
|
return style.Layout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Shell) instanceStartButton(click *widget.Clickable) layout.Widget {
|
||||||
|
return func(gtx layout.Context) layout.Dimensions {
|
||||||
|
return layout.E.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||||
|
style := material.Button(s.theme, click, "启动")
|
||||||
|
style.Inset = layout.Inset{Top: unit.Dp(6), Right: unit.Dp(10), Bottom: unit.Dp(6), Left: unit.Dp(10)}
|
||||||
|
return style.Layout(gtx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func statusLabel(theme *material.Theme, status string) layout.Widget {
|
func statusLabel(theme *material.Theme, status string) layout.Widget {
|
||||||
style := material.Label(theme, unit.Sp(13), status)
|
style := material.Label(theme, unit.Sp(13), status)
|
||||||
style.Color = map[string]color.NRGBA{
|
style.Color = map[string]color.NRGBA{
|
||||||
|
|||||||
@@ -38,6 +38,19 @@ func TestShellInstanceRowsContainRequiredColumnsAndIndependentStartControls(t *t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInstanceListColumnWeightsPrioritizeDirectoryAndCompactAction(t *testing.T) {
|
||||||
|
got := instanceNameColumnWeight + instanceBrowserColumnWeight + instanceDirectoryColumnWeight + instanceStatusColumnWeight + instanceStartColumnWeight
|
||||||
|
if got != 100 {
|
||||||
|
t.Fatalf("instance column weights = %d, want 100", got)
|
||||||
|
}
|
||||||
|
if instanceDirectoryColumnWeight <= instanceNameColumnWeight {
|
||||||
|
t.Fatal("user data directory must have the widest instance-list column")
|
||||||
|
}
|
||||||
|
if instanceStartColumnWeight >= instanceStatusColumnWeight {
|
||||||
|
t.Fatal("start action column must remain compact")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestShellCancelsOnlyTheActivePathSearch(t *testing.T) {
|
func TestShellCancelsOnlyTheActivePathSearch(t *testing.T) {
|
||||||
shell := NewShell(material.NewTheme())
|
shell := NewShell(material.NewTheme())
|
||||||
started := make(chan struct{}, 1)
|
started := make(chan struct{}, 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user