Added RenderOutline to ControlBase.

Added HoverColor to Button.
This commit is contained in:
Sander Schobers 2019-04-11 23:27:25 +02:00
parent 8d78083583
commit 99c76545ef
4 changed files with 30 additions and 21 deletions

View File

@ -9,11 +9,11 @@ import (
type Button struct { type Button struct {
ControlBase ControlBase
Type ButtonType HoverColor color.Color
Text string Icon Image
Icon Image IconScale float32
Text string
IconScale float32 Type ButtonType
} }
type ButtonType int type ButtonType int
@ -65,9 +65,15 @@ func (b *Button) Handle(ctx Context, e Event) {
func (b *Button) fillColor(p *Palette) color.Color { func (b *Button) fillColor(p *Palette) color.Color {
if b.Background != nil { if b.Background != nil {
if b.over && b.HoverColor != nil {
return b.HoverColor
}
return b.Background return b.Background
} }
if b.over { if b.over {
if b.HoverColor != nil {
return b.HoverColor
}
switch b.Type { switch b.Type {
case ButtonTypeContained: case ButtonTypeContained:
return p.PrimaryLight return p.PrimaryLight
@ -138,7 +144,8 @@ func (b *Button) Render(ctx Context) {
var font = ctx.Renderer().Font(fontName) var font = ctx.Renderer().Font(fontName)
ctx.Renderer().Text(geom.PtF32(pos.X, pos.Y+.5*(bounds.Dy()-font.Height())), fontName, textColor, b.Text) ctx.Renderer().Text(geom.PtF32(pos.X, pos.Y+.5*(bounds.Dy()-font.Height())), fontName, textColor, b.Text)
} }
if b.Type == ButtonTypeOutlined { if b.Type == ButtonTypeOutlined {
ctx.Renderer().Rectangle(b.bounds, palette.TextDisabled, 1) b.RenderOutline(ctx)
} }
} }

View File

@ -129,9 +129,7 @@ func (c *ControlBase) OnDragMove(fn DragMoveFn) {
c.onDragMove = fn c.onDragMove = fn
} }
func (c *ControlBase) OnDragEnd(fn DragEndFn) { func (c *ControlBase) Render(Context) {}
c.onDragEnd = fn
}
func (c *ControlBase) RenderBackground(ctx Context) { func (c *ControlBase) RenderBackground(ctx Context) {
if c.Background != nil { 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)
} }

View File

@ -8,6 +8,7 @@ var defaultPalette *Palette
var defaultStyle *Style var defaultStyle *Style
type Dimensions struct { type Dimensions struct {
OutlineWidth float32
ScrollbarWidth float32 ScrollbarWidth float32
TextPadding float32 TextPadding float32
} }
@ -46,6 +47,7 @@ type Style struct {
func DefaultDimensions() *Dimensions { func DefaultDimensions() *Dimensions {
if defaultDimensions == nil { if defaultDimensions == nil {
defaultDimensions = &Dimensions{ defaultDimensions = &Dimensions{
OutlineWidth: 2.,
ScrollbarWidth: 16., ScrollbarWidth: 16.,
TextPadding: 8., TextPadding: 8.,
} }

View File

@ -35,10 +35,9 @@ type TextBox struct {
box BufferControl box BufferControl
blink time.Time blink time.Time
BorderWidth *Length Focus bool
Focus bool Text string
Text string Selection TextSelection
Selection TextSelection
} }
func BuildTextBox(fn func(*TextBox)) *TextBox { func BuildTextBox(fn func(*TextBox)) *TextBox {
@ -49,12 +48,8 @@ func BuildTextBox(fn func(*TextBox)) *TextBox {
return b return b
} }
func (b *TextBox) borderWidth() float32 {
return b.BorderWidth.Zero(2)
}
func (b *TextBox) pad(ctx Context) float32 { 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) { 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) { func (b *TextBox) Render(ctx Context) {
b.RenderBackground(ctx) b.RenderBackground(ctx)
b.RenderOutline(ctx)
c := b.FontColor(ctx) c := b.FontColor(ctx)
f := b.FontName(ctx) f := b.FontName(ctx)
style := ctx.Style() style := ctx.Style()
borderWidth := b.borderWidth()
ctx.Renderer().Rectangle(b.bounds.Inset(.5*borderWidth), style.Palette.Primary, borderWidth)
var caretWidth float32 = 1 var caretWidth float32 = 1
b.box.RenderFn(ctx, func(_ Context, size geom.PointF32) { b.box.RenderFn(ctx, func(_ Context, size geom.PointF32) {
var renderer = ctx.Renderer() var renderer = ctx.Renderer()