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 {
ControlBase
Type ButtonType
Text string
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)
}
}

View File

@ -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)
}

View File

@ -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.,
}

View File

@ -35,7 +35,6 @@ type TextBox struct {
box BufferControl
blink time.Time
BorderWidth *Length
Focus bool
Text string
Selection TextSelection
@ -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()