mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
widget/material: add disabled state support to all widgets
This commit configures all remaining widgets to draw themselves in a disabled state when their layout.Context is disabled. A description of the strategy employed by each follows: - Checkbox and RadioButton: Draws the icon component in a lighter color. Currently the label text is left in its default color. - ProgressBar: The "progress" color is lightened, but not as much as the background color. This makes the current progress value still readable. - Editor: The cursor is no longer drawn and the text is lightened. - Switch: The track is unchanged, but the circular "thumb" component is lightened. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -41,6 +41,9 @@ func (c *checkable) layout(gtx layout.Context, checked bool) layout.Dimensions {
|
|||||||
return layout.UniformInset(unit.Dp(2)).Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
return layout.UniformInset(unit.Dp(2)).Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||||
size := gtx.Px(c.Size)
|
size := gtx.Px(c.Size)
|
||||||
icon.Color = c.IconColor
|
icon.Color = c.IconColor
|
||||||
|
if gtx.Queue == nil {
|
||||||
|
icon.Color = mulAlpha(icon.Color, 150)
|
||||||
|
}
|
||||||
icon.Layout(gtx, unit.Px(float32(size)))
|
icon.Layout(gtx, unit.Px(float32(size)))
|
||||||
return layout.Dimensions{
|
return layout.Dimensions{
|
||||||
Size: image.Point{X: size, Y: size},
|
Size: image.Point{X: size, Y: size},
|
||||||
|
|||||||
@@ -52,13 +52,20 @@ func (e EditorStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|||||||
gtx.Constraints.Min.Y = h
|
gtx.Constraints.Min.Y = h
|
||||||
}
|
}
|
||||||
dims = e.Editor.Layout(gtx, e.shaper, e.Font, e.TextSize)
|
dims = e.Editor.Layout(gtx, e.shaper, e.Font, e.TextSize)
|
||||||
|
disabled := gtx.Queue == nil
|
||||||
if e.Editor.Len() > 0 {
|
if e.Editor.Len() > 0 {
|
||||||
paint.ColorOp{Color: e.Color}.Add(gtx.Ops)
|
textColor := e.Color
|
||||||
|
if disabled {
|
||||||
|
textColor = mulAlpha(textColor, 150)
|
||||||
|
}
|
||||||
|
paint.ColorOp{Color: textColor}.Add(gtx.Ops)
|
||||||
e.Editor.PaintText(gtx)
|
e.Editor.PaintText(gtx)
|
||||||
} else {
|
} else {
|
||||||
call.Add(gtx.Ops)
|
call.Add(gtx.Ops)
|
||||||
}
|
}
|
||||||
paint.ColorOp{Color: e.Color}.Add(gtx.Ops)
|
if !disabled {
|
||||||
e.Editor.PaintCaret(gtx)
|
paint.ColorOp{Color: e.Color}.Add(gtx.Ops)
|
||||||
|
e.Editor.PaintCaret(gtx)
|
||||||
|
}
|
||||||
return dims
|
return dims
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,11 @@ func (p ProgressBarStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|||||||
}),
|
}),
|
||||||
layout.Stacked(func(gtx layout.Context) layout.Dimensions {
|
layout.Stacked(func(gtx layout.Context) layout.Dimensions {
|
||||||
fillWidth := (progressBarWidth / 100) * float32(progress)
|
fillWidth := (progressBarWidth / 100) * float32(progress)
|
||||||
return shader(fillWidth, p.Color)
|
fillColor := p.Color
|
||||||
|
if gtx.Queue == nil {
|
||||||
|
fillColor = mulAlpha(fillColor, 200)
|
||||||
|
}
|
||||||
|
return shader(fillWidth, fillColor)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,12 +47,20 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|||||||
X: float32(trackWidth),
|
X: float32(trackWidth),
|
||||||
Y: float32(trackHeight),
|
Y: float32(trackHeight),
|
||||||
}}
|
}}
|
||||||
|
col := s.Color.Disabled
|
||||||
|
if s.Switch.Value {
|
||||||
|
col = s.Color.Enabled
|
||||||
|
}
|
||||||
|
if gtx.Queue == nil {
|
||||||
|
col = mulAlpha(col, 150)
|
||||||
|
}
|
||||||
|
trackColor := mulAlpha(col, 150)
|
||||||
op.TransformOp{}.Offset(f32.Point{Y: trackOff}).Add(gtx.Ops)
|
op.TransformOp{}.Offset(f32.Point{Y: trackOff}).Add(gtx.Ops)
|
||||||
clip.Rect{
|
clip.Rect{
|
||||||
Rect: trackRect,
|
Rect: trackRect,
|
||||||
NE: trackCorner, NW: trackCorner, SE: trackCorner, SW: trackCorner,
|
NE: trackCorner, NW: trackCorner, SE: trackCorner, SW: trackCorner,
|
||||||
}.Op(gtx.Ops).Add(gtx.Ops)
|
}.Op(gtx.Ops).Add(gtx.Ops)
|
||||||
paint.ColorOp{Color: rgb(0x9b9b9b)}.Add(gtx.Ops)
|
paint.ColorOp{Color: trackColor}.Add(gtx.Ops)
|
||||||
paint.PaintOp{Rect: trackRect}.Add(gtx.Ops)
|
paint.PaintOp{Rect: trackRect}.Add(gtx.Ops)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
|
|
||||||
@@ -79,11 +87,9 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|||||||
|
|
||||||
// Compute thumb offset and color.
|
// Compute thumb offset and color.
|
||||||
stack = op.Push(gtx.Ops)
|
stack = op.Push(gtx.Ops)
|
||||||
col := s.Color.Disabled
|
|
||||||
if s.Switch.Value {
|
if s.Switch.Value {
|
||||||
off := trackWidth - thumbSize
|
off := trackWidth - thumbSize
|
||||||
op.TransformOp{}.Offset(f32.Point{X: float32(off)}).Add(gtx.Ops)
|
op.TransformOp{}.Offset(f32.Point{X: float32(off)}).Add(gtx.Ops)
|
||||||
col = s.Color.Enabled
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw thumb shadow, a translucent disc slightly larger than the
|
// Draw thumb shadow, a translucent disc slightly larger than the
|
||||||
|
|||||||
Reference in New Issue
Block a user