mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 16: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:
@@ -47,12 +47,20 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||
X: float32(trackWidth),
|
||||
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)
|
||||
clip.Rect{
|
||||
Rect: trackRect,
|
||||
NE: trackCorner, NW: trackCorner, SE: trackCorner, SW: trackCorner,
|
||||
}.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)
|
||||
stack.Pop()
|
||||
|
||||
@@ -79,11 +87,9 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||
|
||||
// Compute thumb offset and color.
|
||||
stack = op.Push(gtx.Ops)
|
||||
col := s.Color.Disabled
|
||||
if s.Switch.Value {
|
||||
off := trackWidth - thumbSize
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user