Changed appearance of tooltips a bit.
- Bit smaller text, background half transparent.
This commit is contained in:
parent
7150d03d16
commit
ad7c149baf
@ -45,7 +45,7 @@ func (c *ControlBase) ActualFont(ctx *Context) *Font {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ControlBase) ActualFontName() string {
|
func (c *ControlBase) ActualFontName() string {
|
||||||
if len(c.FontName) == 0 {
|
if c.FontName == "" {
|
||||||
return "default"
|
return "default"
|
||||||
}
|
}
|
||||||
return c.FontName
|
return c.FontName
|
||||||
|
25
tooltip.go
25
tooltip.go
@ -9,15 +9,26 @@ type Tooltip struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const tooltipBorderThickness = 1
|
const tooltipBorderThickness = 1
|
||||||
const tooltipHorizontalPadding = 4
|
const tooltipHorizontalPadding = 6
|
||||||
|
const tooltipVerticalPadding = 2
|
||||||
const tooltipMouseDistance = 12
|
const tooltipMouseDistance = 12
|
||||||
|
|
||||||
|
func (t *Tooltip) ActualFontName() string {
|
||||||
|
if t.FontName == "" {
|
||||||
|
return "small"
|
||||||
|
}
|
||||||
|
return t.FontName
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Tooltip) Handle(ctx *Context, event sdl.Event) bool {
|
func (t *Tooltip) Handle(ctx *Context, event sdl.Event) bool {
|
||||||
if len(t.Text) == 0 {
|
if len(t.Text) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
font := ctx.Fonts.Font(t.ActualFontName())
|
font := ctx.Fonts.Font(t.ActualFontName())
|
||||||
|
if font == nil {
|
||||||
|
font = ctx.Fonts.Font("default")
|
||||||
|
}
|
||||||
windowW, windowH, err := ctx.Renderer.GetOutputSize()
|
windowW, windowH, err := ctx.Renderer.GetOutputSize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
@ -30,7 +41,7 @@ func (t *Tooltip) Handle(ctx *Context, event sdl.Event) bool {
|
|||||||
|
|
||||||
mouse := ctx.MousePosition
|
mouse := ctx.MousePosition
|
||||||
width := int32(labelW) + 2*tooltipBorderThickness + 2*tooltipHorizontalPadding
|
width := int32(labelW) + 2*tooltipBorderThickness + 2*tooltipHorizontalPadding
|
||||||
height := int32(labelH) + 2*tooltipBorderThickness
|
height := int32(labelH) + 2*tooltipBorderThickness + 2*tooltipVerticalPadding
|
||||||
|
|
||||||
left := mouse.X + tooltipMouseDistance
|
left := mouse.X + tooltipMouseDistance
|
||||||
top := mouse.Y + tooltipMouseDistance
|
top := mouse.Y + tooltipMouseDistance
|
||||||
@ -46,14 +57,16 @@ func (t *Tooltip) Handle(ctx *Context, event sdl.Event) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tooltip) Render(ctx *Context) {
|
func (t *Tooltip) Render(ctx *Context) {
|
||||||
SetDrawColor(ctx.Renderer, Black)
|
almostBlack := MustHexColor("#0000007f")
|
||||||
|
SetDrawColor(ctx.Renderer, almostBlack)
|
||||||
ctx.Renderer.FillRect(t.Bounds.SDLPtr())
|
ctx.Renderer.FillRect(t.Bounds.SDLPtr())
|
||||||
|
|
||||||
SetDrawColor(ctx.Renderer, White)
|
almostWhite := MustHexColor("ffffff7f")
|
||||||
|
SetDrawColor(ctx.Renderer, almostWhite)
|
||||||
ctx.Renderer.DrawRect(t.Bounds.SDLPtr())
|
ctx.Renderer.DrawRect(t.Bounds.SDLPtr())
|
||||||
|
|
||||||
font := t.ActualFont(ctx)
|
font := ctx.Fonts.Font(t.ActualFontName())
|
||||||
|
|
||||||
bottomLeft := Pt(t.Bounds.X+tooltipBorderThickness+tooltipHorizontalPadding, t.Bounds.Y+t.Bounds.H-tooltipBorderThickness)
|
bottomLeft := Pt(t.Bounds.X+tooltipBorderThickness+tooltipHorizontalPadding, t.Bounds.Y+t.Bounds.H-tooltipBorderThickness-tooltipVerticalPadding)
|
||||||
font.RenderCopy(ctx.Renderer, t.Text, bottomLeft, White)
|
font.RenderCopy(ctx.Renderer, t.Text, bottomLeft, White)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user