closes #3 - label text alignment and direction
This commit is contained in:
parent
6addbfe158
commit
dcf1c50b5c
23
canvas.go
23
canvas.go
|
@ -128,6 +128,29 @@ func (fb *FrameBuffer) PutText(x, y int, text string, fg, bg term.Attribute) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draws vertical text line on buffer
|
||||||
|
func (fb *FrameBuffer) PutVerticalText(x, y int, text string, fg, bg term.Attribute) {
|
||||||
|
height := fb.h
|
||||||
|
|
||||||
|
if (y < 0 && xs.Len(text) <= -y) || x < 0 || y < 0 || x >= fb.w {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if y < 0 {
|
||||||
|
yy := -y
|
||||||
|
y = 0
|
||||||
|
text = xs.Slice(text, yy, -1)
|
||||||
|
}
|
||||||
|
text = CutText(text, height)
|
||||||
|
|
||||||
|
dy := 0
|
||||||
|
for _, char := range text {
|
||||||
|
s := term.Cell{Ch: char, Fg: fg, Bg: bg}
|
||||||
|
fb.buffer[y+dy][x] = s
|
||||||
|
dy++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Draws vertical text line on buffer
|
// Draws vertical text line on buffer
|
||||||
func (fb *FrameBuffer) PutTextVertical(x, y int, text string, fg, bg term.Attribute) {
|
func (fb *FrameBuffer) PutTextVertical(x, y int, text string, fg, bg term.Attribute) {
|
||||||
height := fb.h
|
height := fb.h
|
||||||
|
|
|
@ -17,6 +17,7 @@ type Canvas interface {
|
||||||
Size() (int, int)
|
Size() (int, int)
|
||||||
PutSymbol(int, int, term.Cell) bool
|
PutSymbol(int, int, term.Cell) bool
|
||||||
PutText(int, int, string, term.Attribute, term.Attribute)
|
PutText(int, int, string, term.Attribute, term.Attribute)
|
||||||
|
PutVerticalText(int, int, string, term.Attribute, term.Attribute)
|
||||||
Symbol(int, int) (term.Cell, bool)
|
Symbol(int, int) (term.Cell, bool)
|
||||||
Clear(term.Attribute)
|
Clear(term.Attribute)
|
||||||
FillRect(int, int, int, int, term.Cell)
|
FillRect(int, int, int, int, term.Cell)
|
||||||
|
@ -50,6 +51,7 @@ type View interface {
|
||||||
HitTest(int, int) HitResult
|
HitTest(int, int) HitResult
|
||||||
|
|
||||||
Paddings() (int, int, int, int)
|
Paddings() (int, int, int, int)
|
||||||
|
SetPaddings(int, int, int, int)
|
||||||
AddChild(Control, int)
|
AddChild(Control, int)
|
||||||
SetPack(PackType)
|
SetPack(PackType)
|
||||||
Pack() PackType
|
Pack() PackType
|
||||||
|
@ -80,6 +82,7 @@ type Control interface {
|
||||||
SetScale(int)
|
SetScale(int)
|
||||||
Constraints() (int, int)
|
Constraints() (int, int)
|
||||||
Paddings() (int, int, int, int)
|
Paddings() (int, int, int, int)
|
||||||
|
SetPaddings(int, int, int, int)
|
||||||
Repaint()
|
Repaint()
|
||||||
AddChild(Control, int)
|
AddChild(Control, int)
|
||||||
SetPack(PackType)
|
SetPack(PackType)
|
||||||
|
|
17
label.go
17
label.go
|
@ -29,6 +29,14 @@ func NewLabel(view View, parent Control, w, h int, title string, scale int) *Lab
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *Label) Direction() Direction {
|
||||||
|
return l.direction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Label) SetDirection(dir Direction) {
|
||||||
|
l.direction = dir
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Label) Repaint() {
|
func (l *Label) Repaint() {
|
||||||
canvas := l.view.Canvas()
|
canvas := l.view.Canvas()
|
||||||
tm := l.view.Screen().Theme()
|
tm := l.view.Screen().Theme()
|
||||||
|
@ -40,6 +48,11 @@ func (l *Label) Repaint() {
|
||||||
|
|
||||||
canvas.FillRect(l.x, l.y, l.width, l.height, term.Cell{Ch: ' ', Fg: fg, Bg: bg})
|
canvas.FillRect(l.x, l.y, l.width, l.height, term.Cell{Ch: ' ', Fg: fg, Bg: bg})
|
||||||
|
|
||||||
shift, text := AlignText(l.title, l.width, l.align)
|
if l.direction == Horizontal {
|
||||||
canvas.PutText(l.x+shift, l.y, text, fg, bg)
|
shift, text := AlignText(l.title, l.width, l.align)
|
||||||
|
canvas.PutText(l.x+shift, l.y, text, fg, bg)
|
||||||
|
} else {
|
||||||
|
shift, text := AlignText(l.title, l.height, l.align)
|
||||||
|
canvas.PutVerticalText(l.x, l.y+shift, text, fg, bg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,6 +185,10 @@ func (w *Window) Paddings() (int, int, int, int) {
|
||||||
return w.padSide, w.padTop, w.padX, w.padY
|
return w.padSide, w.padTop, w.padX, w.padY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Window) SetPaddings(side, top, dx, dy int) {
|
||||||
|
w.padSide, w.padTop, w.padX, w.padY = side, top, dx, dy
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Window) Canvas() Canvas {
|
func (w *Window) Canvas() Canvas {
|
||||||
return w.canvas
|
return w.canvas
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue