Buffers ?!
This commit is contained in:
@@ -22,6 +22,7 @@ THE SOFTWARE.
|
||||
package widgets
|
||||
|
||||
import (
|
||||
wh "git.bullercodeworks.com/brian/tcell-widgets/helpers"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
@@ -31,6 +32,7 @@ type AbsoluteLayout struct {
|
||||
|
||||
x, y int
|
||||
w, h int
|
||||
bordered bool
|
||||
widgets []Widget
|
||||
wCoords map[Widget]Coord
|
||||
wAnchor map[Widget]AbsoluteAnchor
|
||||
@@ -151,6 +153,9 @@ func (w *AbsoluteLayout) Draw(screen tcell.Screen) {
|
||||
return
|
||||
}
|
||||
p := w.GetPos()
|
||||
if w.bordered {
|
||||
wh.Border(p.X, p.Y, p.X+w.w, p.Y+w.h, wh.BRD_CSIMPLE, w.style, screen)
|
||||
}
|
||||
for _, wd := range w.widgets {
|
||||
p.DrawOffset(wd, screen)
|
||||
}
|
||||
@@ -229,6 +234,8 @@ func (w *AbsoluteLayout) Log(txt string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (w *AbsoluteLayout) SetBordered(b bool) { w.bordered = b }
|
||||
|
||||
func (w *AbsoluteLayout) updateWidgetLayouts() {
|
||||
// In an Absolute Layout, widgets are given a definite position and anchor.
|
||||
// The anchor is a side of the layout (see AbsoluteAnchor type)
|
||||
@@ -268,7 +275,9 @@ func (w *AbsoluteLayout) updateWidgetSize(wd Widget) {
|
||||
}
|
||||
|
||||
// Set a widgets position relative to the layout
|
||||
func (w *AbsoluteLayout) updateWidgetPos(wd Widget) { wd.SetPos(w.getRelPos(wd)) }
|
||||
func (w *AbsoluteLayout) updateWidgetPos(wd Widget) {
|
||||
wd.SetPos(w.getRelPos(wd))
|
||||
}
|
||||
|
||||
// Manually set the size of a widget, the Layout won't override it
|
||||
func (w *AbsoluteLayout) SetWidgetSize(wd Widget, sz Coord) { w.wManualSizes[wd] = sz }
|
||||
@@ -288,34 +297,41 @@ func (w *AbsoluteLayout) getRelPos(wd Widget) Coord {
|
||||
if a, ok = w.wAnchor[wd]; !ok {
|
||||
a = w.defAnchor
|
||||
}
|
||||
leftX, topY, rightX, bottomY := 0, 0, w.w, w.h
|
||||
if w.bordered {
|
||||
leftX += 1
|
||||
topY += 1
|
||||
rightX -= 1
|
||||
bottomY -= 1
|
||||
}
|
||||
midX, midY := (w.w / 2), (w.h / 2)
|
||||
switch a {
|
||||
case AnchorTL:
|
||||
return p
|
||||
return p.Add(Coord{X: leftX, Y: topY})
|
||||
|
||||
case AnchorT:
|
||||
return p.Add(Coord{X: midX - (wd.GetW() / 2), Y: 0})
|
||||
return p.Add(Coord{X: midX - (wd.GetW() / 2), Y: topY})
|
||||
|
||||
case AnchorTR:
|
||||
return p.Add(Coord{X: w.w - wd.GetW(), Y: 0})
|
||||
return p.Add(Coord{X: rightX - wd.GetW(), Y: topY})
|
||||
|
||||
case AnchorL:
|
||||
return p.Add(Coord{X: 0, Y: midY - (wd.GetH() / 2)})
|
||||
return p.Add(Coord{X: leftX, Y: midY - (wd.GetH() / 2)})
|
||||
|
||||
case AnchorC:
|
||||
return p.Add(Coord{X: midX - (wd.GetW() / 2), Y: midY - (wd.GetH() / 2)})
|
||||
|
||||
case AnchorR:
|
||||
return p.Add(Coord{X: w.w - wd.GetW(), Y: midY - (wd.GetH() / 2)})
|
||||
return p.Add(Coord{X: rightX - wd.GetW(), Y: midY - (wd.GetH() / 2)})
|
||||
|
||||
case AnchorBR:
|
||||
return p.Add(Coord{X: w.w - wd.GetW(), Y: w.h - wd.GetH()})
|
||||
return p.Add(Coord{X: rightX - wd.GetW(), Y: bottomY - wd.GetH()})
|
||||
|
||||
case AnchorB:
|
||||
return p.Add(Coord{X: midX - (wd.GetW() / 2), Y: w.h - wd.GetH()})
|
||||
return p.Add(Coord{X: midX - (wd.GetW() / 2), Y: bottomY - wd.GetH()})
|
||||
|
||||
case AnchorBL:
|
||||
return p.Add(Coord{X: 0, Y: w.h - wd.GetH()})
|
||||
return p.Add(Coord{X: leftX, Y: bottomY - wd.GetH()})
|
||||
|
||||
}
|
||||
return p
|
||||
|
||||
Reference in New Issue
Block a user