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()}
|
||||
}
|
||||
|
||||
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]
|
||||
if f == nil {
|
||||
return
|
||||
}
|
||||
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
|
||||
|
@ -28,8 +28,9 @@ type ControlBase struct {
|
||||
onDragMove DragMoveFn
|
||||
onDragStart DragStartFn
|
||||
|
||||
Background color.Color
|
||||
Font FontStyle
|
||||
Background color.Color
|
||||
Font FontStyle
|
||||
TextAlignment HorizontalAlignment
|
||||
}
|
||||
|
||||
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 f = l.FontName(ctx)
|
||||
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
|
||||
Target() Image
|
||||
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