diff --git a/ui/button.go b/ui/button.go index 546c43a..d720357 100644 --- a/ui/button.go +++ b/ui/button.go @@ -9,11 +9,11 @@ import ( type Button struct { ControlBase - Type ButtonType - Text string - Icon Image - - IconScale float32 + HoverColor color.Color + Icon Image + IconScale float32 + Text string + Type ButtonType } type ButtonType int @@ -65,9 +65,15 @@ func (b *Button) Handle(ctx Context, e Event) { func (b *Button) fillColor(p *Palette) color.Color { if b.Background != nil { + if b.over && b.HoverColor != nil { + return b.HoverColor + } return b.Background } if b.over { + if b.HoverColor != nil { + return b.HoverColor + } switch b.Type { case ButtonTypeContained: return p.PrimaryLight @@ -138,7 +144,8 @@ func (b *Button) Render(ctx Context) { var font = ctx.Renderer().Font(fontName) ctx.Renderer().Text(geom.PtF32(pos.X, pos.Y+.5*(bounds.Dy()-font.Height())), fontName, textColor, b.Text) } + if b.Type == ButtonTypeOutlined { - ctx.Renderer().Rectangle(b.bounds, palette.TextDisabled, 1) + b.RenderOutline(ctx) } } diff --git a/ui/controlbase.go b/ui/controlbase.go index 55b4d16..4cd7f76 100644 --- a/ui/controlbase.go +++ b/ui/controlbase.go @@ -129,9 +129,7 @@ func (c *ControlBase) OnDragMove(fn DragMoveFn) { c.onDragMove = fn } -func (c *ControlBase) OnDragEnd(fn DragEndFn) { - c.onDragEnd = fn -} +func (c *ControlBase) Render(Context) {} func (c *ControlBase) RenderBackground(ctx Context) { if c.Background != nil { @@ -139,5 +137,12 @@ func (c *ControlBase) RenderBackground(ctx Context) { } } -func (c *ControlBase) Render(Context) { +func (c *ControlBase) RenderOutline(ctx Context) { + style := ctx.Style() + width := style.Dimensions.OutlineWidth + color := style.Palette.Primary + if c.Font.Color != nil { + color = c.Font.Color + } + ctx.Renderer().Rectangle(c.bounds.Inset(.5*width), color, width) } diff --git a/ui/style.go b/ui/style.go index a861670..7e318db 100644 --- a/ui/style.go +++ b/ui/style.go @@ -8,6 +8,7 @@ var defaultPalette *Palette var defaultStyle *Style type Dimensions struct { + OutlineWidth float32 ScrollbarWidth float32 TextPadding float32 } @@ -46,6 +47,7 @@ type Style struct { func DefaultDimensions() *Dimensions { if defaultDimensions == nil { defaultDimensions = &Dimensions{ + OutlineWidth: 2., ScrollbarWidth: 16., TextPadding: 8., } diff --git a/ui/textbox.go b/ui/textbox.go index 935fa61..e945585 100644 --- a/ui/textbox.go +++ b/ui/textbox.go @@ -35,10 +35,9 @@ type TextBox struct { box BufferControl blink time.Time - BorderWidth *Length - Focus bool - Text string - Selection TextSelection + Focus bool + Text string + Selection TextSelection } func BuildTextBox(fn func(*TextBox)) *TextBox { @@ -49,12 +48,8 @@ func BuildTextBox(fn func(*TextBox)) *TextBox { return b } -func (b *TextBox) borderWidth() float32 { - return b.BorderWidth.Zero(2) -} - func (b *TextBox) pad(ctx Context) float32 { - return ctx.Style().Dimensions.TextPadding + b.borderWidth() + return ctx.Style().Dimensions.TextPadding } func (b *TextBox) Arrange(ctx Context, bounds geom.RectangleF32, offset geom.PointF32) { @@ -239,11 +234,11 @@ func (b *TextBox) Handle(ctx Context, e Event) { func (b *TextBox) Render(ctx Context) { b.RenderBackground(ctx) + b.RenderOutline(ctx) + c := b.FontColor(ctx) f := b.FontName(ctx) style := ctx.Style() - borderWidth := b.borderWidth() - ctx.Renderer().Rectangle(b.bounds.Inset(.5*borderWidth), style.Palette.Primary, borderWidth) var caretWidth float32 = 1 b.box.RenderFn(ctx, func(_ Context, size geom.PointF32) { var renderer = ctx.Renderer()