-
Notifications
You must be signed in to change notification settings - Fork 124
/
focus.go
41 lines (35 loc) · 939 Bytes
/
focus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"image/color"
"gioui.org/layout"
"gioui.org/unit"
"gioui.org/widget"
"gioui.org/widget/material"
)
// FocusBorderStyle implements a styling a focused widget.
type FocusBorderStyle struct {
Focused bool
BorderWidth unit.Dp
Color color.NRGBA
}
// FocusBorder creates a focus border for a focused widget.
func FocusBorder(th *material.Theme, focused bool) FocusBorderStyle {
return FocusBorderStyle{
Focused: focused,
BorderWidth: unit.Dp(2),
Color: th.ContrastBg,
}
}
// Layout adds a focus border and styling.
func (focus FocusBorderStyle) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
inset := layout.UniformInset(focus.BorderWidth)
if !focus.Focused {
return inset.Layout(gtx, w)
}
return widget.Border{
Color: focus.Color,
Width: focus.BorderWidth,
}.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return inset.Layout(gtx, w)
})
}