Added (horizontal) text alignment.
This commit is contained in:
parent
ff064bbf1f
commit
e867925de8
@ -237,13 +237,28 @@ func (r *Renderer) Target() ui.Image {
|
|||||||
return &uiImage{allg5.CurrentTarget()}
|
return &uiImage{allg5.CurrentTarget()}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Renderer) Text(p geom.PointF32, font string, c color.Color, t string) {
|
func (r *Renderer) text(p geom.PointF32, font string, c color.Color, t string, align allg5.HorizontalAlignment) {
|
||||||
var f = r.ft[font]
|
var f = r.ft[font]
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
x, y := snap(p)
|
x, y := snap(p)
|
||||||
f.f.Draw(x, y, newColor(c), allg5.AlignLeft, t)
|
f.f.Draw(x, y, newColor(c), align, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Renderer) Text(p geom.PointF32, font string, c color.Color, t string) {
|
||||||
|
r.text(p, font, c, t, allg5.AlignLeft)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Renderer) TextAlign(p geom.PointF32, font string, c color.Color, t string, align ui.HorizontalAlignment) {
|
||||||
|
var alignment = allg5.AlignLeft
|
||||||
|
switch align {
|
||||||
|
case ui.AlignCenter:
|
||||||
|
alignment = allg5.AlignCenter
|
||||||
|
case ui.AlignRight:
|
||||||
|
alignment = allg5.AlignRight
|
||||||
|
}
|
||||||
|
r.text(p, font, c, t, alignment)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utility functions
|
// Utility functions
|
||||||
|
@ -30,6 +30,7 @@ type ControlBase struct {
|
|||||||
|
|
||||||
Background color.Color
|
Background color.Color
|
||||||
Font FontStyle
|
Font FontStyle
|
||||||
|
TextAlignment HorizontalAlignment
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ControlBase) Arrange(ctx Context, bounds geom.RectangleF32, offset geom.PointF32, parent Control) {
|
func (c *ControlBase) Arrange(ctx Context, bounds geom.RectangleF32, offset geom.PointF32, parent Control) {
|
||||||
|
@ -32,5 +32,5 @@ func (l *Label) Render(ctx Context) {
|
|||||||
var c = l.FontColor(ctx)
|
var c = l.FontColor(ctx)
|
||||||
var f = l.FontName(ctx)
|
var f = l.FontName(ctx)
|
||||||
var pad = ctx.Style().Dimensions.TextPadding
|
var pad = ctx.Style().Dimensions.TextPadding
|
||||||
ctx.Renderer().Text(l.bounds.Min.Add(geom.PtF32(pad, pad)), f, c, l.Text)
|
ctx.Renderer().TextAlign(l.bounds.Min.Add(geom.PtF32(pad, pad)), f, c, l.Text, l.TextAlignment)
|
||||||
}
|
}
|
||||||
|
@ -32,4 +32,5 @@ type Renderer interface {
|
|||||||
Size() geom.PointF32
|
Size() geom.PointF32
|
||||||
Target() Image
|
Target() Image
|
||||||
Text(p geom.PointF32, font string, color color.Color, text string)
|
Text(p geom.PointF32, font string, color color.Color, text string)
|
||||||
|
TextAlign(p geom.PointF32, font string, color color.Color, text string, align HorizontalAlignment)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user