mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
widget/material: add hover to Button
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
@@ -172,6 +172,17 @@ func Disabled(c color.NRGBA) (d color.NRGBA) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hovered blends color towards a brighter color.
|
||||||
|
func Hovered(c color.NRGBA) (d color.NRGBA) {
|
||||||
|
const r = 0x20 // lighten ratio
|
||||||
|
return color.NRGBA{
|
||||||
|
R: byte(255 - int(255-c.R)*(255-r)/256),
|
||||||
|
G: byte(255 - int(255-c.G)*(255-r)/256),
|
||||||
|
B: byte(255 - int(255-c.B)*(255-r)/256),
|
||||||
|
A: c.A,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// approxLuminance is a fast approximate version of RGBA.Luminance.
|
// approxLuminance is a fast approximate version of RGBA.Luminance.
|
||||||
func approxLuminance(c color.NRGBA) byte {
|
func approxLuminance(c color.NRGBA) byte {
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -128,8 +128,11 @@ func (b ButtonLayoutStyle) Layout(gtx layout.Context, w layout.Widget) layout.Di
|
|||||||
Y: float32(gtx.Constraints.Min.Y),
|
Y: float32(gtx.Constraints.Min.Y),
|
||||||
}}, rr).Add(gtx.Ops)
|
}}, rr).Add(gtx.Ops)
|
||||||
background := b.Background
|
background := b.Background
|
||||||
if gtx.Queue == nil {
|
switch {
|
||||||
|
case gtx.Queue == nil:
|
||||||
background = f32color.Disabled(b.Background)
|
background = f32color.Disabled(b.Background)
|
||||||
|
case b.Button.Hovered():
|
||||||
|
background = f32color.Hovered(b.Background)
|
||||||
}
|
}
|
||||||
paint.Fill(gtx.Ops, background)
|
paint.Fill(gtx.Ops, background)
|
||||||
for _, c := range b.Button.History() {
|
for _, c := range b.Button.History() {
|
||||||
@@ -155,8 +158,11 @@ func (b IconButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|||||||
Max: f32.Point{X: sizexf, Y: sizeyf},
|
Max: f32.Point{X: sizexf, Y: sizeyf},
|
||||||
}, rr).Add(gtx.Ops)
|
}, rr).Add(gtx.Ops)
|
||||||
background := b.Background
|
background := b.Background
|
||||||
if gtx.Queue == nil {
|
switch {
|
||||||
|
case gtx.Queue == nil:
|
||||||
background = f32color.Disabled(b.Background)
|
background = f32color.Disabled(b.Background)
|
||||||
|
case b.Button.Hovered():
|
||||||
|
background = f32color.Hovered(b.Background)
|
||||||
}
|
}
|
||||||
paint.Fill(gtx.Ops, background)
|
paint.Fill(gtx.Ops, background)
|
||||||
for _, c := range b.Button.History() {
|
for _, c := range b.Button.History() {
|
||||||
|
|||||||
Reference in New Issue
Block a user