Added shorthand method for retrieving default font for the control.
This commit is contained in:
parent
5babda0ca9
commit
11e37af9c2
@ -41,7 +41,7 @@ func BuildIconButton(icon, text string, fn func(b *Button)) *Button {
|
|||||||
|
|
||||||
func (b *Button) desiredSize(ctx Context) geom.PointF32 {
|
func (b *Button) desiredSize(ctx Context) geom.PointF32 {
|
||||||
var pad = ctx.Style().Dimensions.TextPadding
|
var pad = ctx.Style().Dimensions.TextPadding
|
||||||
var font = ctx.Fonts().Font(b.FontName(ctx))
|
var font = b.Font_(ctx)
|
||||||
var w, h float32 = 0, font.Height()
|
var w, h float32 = 0, font.Height()
|
||||||
|
|
||||||
icon, iconW, iconH := b.icon(ctx)
|
icon, iconW, iconH := b.icon(ctx)
|
||||||
@ -225,8 +225,7 @@ func (b *Button) Render(ctx Context) {
|
|||||||
pos.X += iconW + pad
|
pos.X += iconW + pad
|
||||||
}
|
}
|
||||||
if len(b.Text) != 0 {
|
if len(b.Text) != 0 {
|
||||||
fontName := b.FontName(ctx)
|
font := b.Font_(ctx)
|
||||||
font := ctx.Fonts().Font(fontName)
|
|
||||||
ctx.Renderer().Text(font, geom.PtF32(pos.X, pos.Y+.5*(boundsH-font.Height())), textColor, b.Text)
|
ctx.Renderer().Text(font, geom.PtF32(pos.X, pos.Y+.5*(boundsH-font.Height())), textColor, b.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ func BuildCheckbox(text string, fn func(c *Checkbox)) *Checkbox {
|
|||||||
|
|
||||||
func (c *Checkbox) desiredSize(ctx Context) geom.PointF32 {
|
func (c *Checkbox) desiredSize(ctx Context) geom.PointF32 {
|
||||||
var pad = ctx.Style().Dimensions.TextPadding
|
var pad = ctx.Style().Dimensions.TextPadding
|
||||||
var font = ctx.Fonts().Font(c.FontName(ctx))
|
font := c.Font_(ctx)
|
||||||
var w, h float32 = 0, font.Height()
|
var w, h float32 = 0, font.Height()
|
||||||
if len(c.Text) != 0 {
|
if len(c.Text) != 0 {
|
||||||
w += pad + font.WidthOf(c.Text)
|
w += pad + font.WidthOf(c.Text)
|
||||||
@ -128,8 +128,7 @@ func (c *Checkbox) Render(ctx Context) {
|
|||||||
pos.X += iconWidth + pad
|
pos.X += iconWidth + pad
|
||||||
}
|
}
|
||||||
if len(c.Text) != 0 {
|
if len(c.Text) != 0 {
|
||||||
var fontName = c.FontName(ctx)
|
font := c.Font_(ctx)
|
||||||
var font = ctx.Fonts().Font(fontName)
|
|
||||||
ctx.Renderer().Text(font, geom.PtF32(pos.X, pos.Y+.5*(boundsH-font.Height())), fore, c.Text)
|
ctx.Renderer().Text(font, geom.PtF32(pos.X, pos.Y+.5*(boundsH-font.Height())), fore, c.Text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,11 @@ func (c *ControlBase) HandleNotify(ctx Context, e Event, notifier Notifier) bool
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ControlBase) Font_(ctx Context) Font {
|
||||||
|
name := c.FontName(ctx)
|
||||||
|
return ctx.Fonts().Font(name)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ControlBase) FontColor(ctx Context, color color.Color) color.Color {
|
func (c *ControlBase) FontColor(ctx Context, color color.Color) color.Color {
|
||||||
if c.Disabled {
|
if c.Disabled {
|
||||||
return ctx.Style().Palette.TextOnDisabled
|
return ctx.Style().Palette.TextOnDisabled
|
||||||
|
@ -28,8 +28,7 @@ func (l *Label) hashDesiredSize(ctx Context) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *Label) desiredSize(ctx Context) interface{} {
|
func (l *Label) desiredSize(ctx Context) interface{} {
|
||||||
fontName := l.FontName(ctx)
|
font := l.Font_(ctx)
|
||||||
font := ctx.Fonts().Font(fontName)
|
|
||||||
width := font.WidthOf(l.Text)
|
width := font.WidthOf(l.Text)
|
||||||
height := font.Height()
|
height := font.Height()
|
||||||
pad := ctx.Style().Dimensions.TextPadding
|
pad := ctx.Style().Dimensions.TextPadding
|
||||||
|
@ -26,8 +26,7 @@ func BuildParagraph(text string, fn func(*Paragraph)) *Paragraph {
|
|||||||
func fastFormatFloat32(f float32) string { return strconv.FormatFloat(float64(f), 'b', 32, 32) }
|
func fastFormatFloat32(f float32) string { return strconv.FormatFloat(float64(f), 'b', 32, 32) }
|
||||||
|
|
||||||
func (p *Paragraph) desiredSize(ctx Context) interface{} {
|
func (p *Paragraph) desiredSize(ctx Context) interface{} {
|
||||||
fontName := p.FontName(ctx)
|
font := p.Font_(ctx)
|
||||||
font := ctx.Fonts().Font(fontName)
|
|
||||||
|
|
||||||
pad := ctx.Style().Dimensions.TextPadding
|
pad := ctx.Style().Dimensions.TextPadding
|
||||||
lines := p.splitInLines(ctx, p.width-2*pad)
|
lines := p.splitInLines(ctx, p.width-2*pad)
|
||||||
@ -43,8 +42,7 @@ func (p *Paragraph) hashTextDesired(ctx Context) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Paragraph) splitInLines(ctx Context, width float32) []string {
|
func (p *Paragraph) splitInLines(ctx Context, width float32) []string {
|
||||||
fontName := p.FontName(ctx)
|
font := p.Font_(ctx)
|
||||||
font := ctx.Fonts().Font(fontName)
|
|
||||||
|
|
||||||
spaces := func(s string) []int { // creates a slice with indices where spaces can be found in string s
|
spaces := func(s string) []int { // creates a slice with indices where spaces can be found in string s
|
||||||
var spaces []int
|
var spaces []int
|
||||||
|
@ -57,8 +57,7 @@ func (b *TextBox) Arrange(ctx Context, bounds geom.RectangleF32, offset geom.Poi
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *TextBox) DesiredSize(ctx Context, _ geom.PointF32) geom.PointF32 {
|
func (b *TextBox) DesiredSize(ctx Context, _ geom.PointF32) geom.PointF32 {
|
||||||
var fontName = b.FontName(ctx)
|
font := b.Font_(ctx)
|
||||||
var font = ctx.Fonts().Font(fontName)
|
|
||||||
var width = font.WidthOf(b.Text)
|
var width = font.WidthOf(b.Text)
|
||||||
var height = font.Height()
|
var height = font.Height()
|
||||||
var pad = b.pad(ctx)
|
var pad = b.pad(ctx)
|
||||||
@ -68,7 +67,7 @@ func (b *TextBox) DesiredSize(ctx Context, _ geom.PointF32) geom.PointF32 {
|
|||||||
func (b *TextBox) mousePosToCaretPos(ctx Context, e MouseEvent) int {
|
func (b *TextBox) mousePosToCaretPos(ctx Context, e MouseEvent) int {
|
||||||
p := b.ToControlPosition(e.Pos())
|
p := b.ToControlPosition(e.Pos())
|
||||||
offset := p.X - b.box.bounds.Min.X
|
offset := p.X - b.box.bounds.Min.X
|
||||||
f := ctx.Fonts().Font(b.FontName(ctx))
|
f := b.Font_(ctx)
|
||||||
var carets = [3]int{0, 0, len(b.Text)}
|
var carets = [3]int{0, 0, len(b.Text)}
|
||||||
var offsets = [3]float32{0, 0, f.WidthOf(b.Text)}
|
var offsets = [3]float32{0, 0, f.WidthOf(b.Text)}
|
||||||
var updateCenter = func() {
|
var updateCenter = func() {
|
||||||
@ -259,8 +258,7 @@ func (b *TextBox) Render(ctx Context) {
|
|||||||
back = ctx.Style().Palette.Background
|
back = ctx.Style().Palette.Background
|
||||||
}
|
}
|
||||||
renderer.Clear(back)
|
renderer.Clear(back)
|
||||||
fontName := b.FontName(ctx)
|
font := b.Font_(ctx)
|
||||||
font := ctx.Fonts().Font(fontName)
|
|
||||||
if b.Selection.Start != b.Selection.End {
|
if b.Selection.Start != b.Selection.End {
|
||||||
left, right := font.WidthOf(b.Text[:b.Selection.Start]), font.WidthOf(b.Text[:b.Selection.End])
|
left, right := font.WidthOf(b.Text[:b.Selection.Start]), font.WidthOf(b.Text[:b.Selection.End])
|
||||||
renderer.FillRectangle(geom.RectF32(left, 0, right, size.Y), style.Palette.PrimaryHighlight)
|
renderer.FillRectangle(geom.RectF32(left, 0, right, size.Y), style.Palette.PrimaryHighlight)
|
||||||
|
Loading…
Reference in New Issue
Block a user