So much work
This commit is contained in:
@@ -26,12 +26,15 @@ import "github.com/gdamore/tcell"
|
||||
type RelativeLayout struct {
|
||||
id string
|
||||
style tcell.Style
|
||||
widgetRelations map[Widget]widgetRelation
|
||||
widgetRelations map[Widget][]widgetRelation
|
||||
widgets []Widget
|
||||
|
||||
active bool
|
||||
visible bool
|
||||
x, y int
|
||||
w, h int
|
||||
active bool
|
||||
visible bool
|
||||
tabbable bool
|
||||
|
||||
x, y int
|
||||
w, h int
|
||||
}
|
||||
|
||||
var _ Widget = (*RelativeLayout)(nil)
|
||||
@@ -44,14 +47,19 @@ type widgetRelation struct {
|
||||
type RelativeRelation int
|
||||
|
||||
const (
|
||||
RRAbove = iota // Above Widget
|
||||
RRToRightOf // To Right of Widget
|
||||
RRBelow // Below Widget
|
||||
RRToLeftOf // To Left of Widget
|
||||
RATop // Anchored to parent Top
|
||||
RARight // Anchored to parent Right
|
||||
RABottom // Anchored to parent Bottom
|
||||
RALeft // Anchored to parent Left
|
||||
RelRelAbove = iota // Above Widget
|
||||
RelRelToRightOf // To Right of Widget
|
||||
RelRelBelow // Below Widget
|
||||
RelRelToLeftOf // To Left of Widget
|
||||
RelAncTL // Anchored to parent Top-Left
|
||||
RelAncT // Anchored to parent Top
|
||||
RelAncTR // Anchored to parent Top-Right
|
||||
RelAncL // Anchored to parent Left
|
||||
RelAncC // Anchored to parent Center
|
||||
RelAncR // Anchored to parent Right
|
||||
RelAncBL // Anchored to parent Bottom-Left
|
||||
RelAncB // Anchored to parent Bottom
|
||||
RelAncBR // Anchored to parent Bottom-Right
|
||||
)
|
||||
|
||||
func NewRelativeLayout(id string, s tcell.Style) *RelativeLayout {
|
||||
@@ -64,6 +72,7 @@ func (w *RelativeLayout) Init(id string, style tcell.Style) {
|
||||
w.id = id
|
||||
w.style = style
|
||||
w.visible = true
|
||||
w.tabbable = true
|
||||
}
|
||||
func (w *RelativeLayout) Id() string { return w.id }
|
||||
func (w *RelativeLayout) HandleResize(ev *tcell.EventResize) {}
|
||||
@@ -73,33 +82,62 @@ func (w *RelativeLayout) Draw(screen tcell.Screen) {
|
||||
if !w.visible {
|
||||
return
|
||||
}
|
||||
done := make(map[Widget]widgetRelation)
|
||||
rem := make(map[Widget]widgetRelation)
|
||||
for k, v := range w.widgetRelations {
|
||||
if v.relTo == w {
|
||||
done[k] = v
|
||||
} else {
|
||||
rem[k] = v
|
||||
// All widgets should have correct (relative) positions
|
||||
/*
|
||||
done := make(map[Widget]widgetRelation)
|
||||
rem := make(map[Widget]widgetRelation)
|
||||
for k, v := range w.widgetRelations {
|
||||
if v.relTo == w {
|
||||
done[k] = v
|
||||
} else {
|
||||
rem[k] = v
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
func (w *RelativeLayout) Active() bool { return w.active }
|
||||
func (w *RelativeLayout) SetActive(a bool) { w.active = a }
|
||||
func (w *RelativeLayout) Visible() bool { return w.visible }
|
||||
func (w *RelativeLayout) SetVisible(a bool) { w.visible = a }
|
||||
func (w *RelativeLayout) Focusable() bool { return true }
|
||||
func (w *RelativeLayout) SetTabbable(b bool) { w.tabbable = b }
|
||||
func (w *RelativeLayout) Tabbable() bool { return w.tabbable }
|
||||
func (w *RelativeLayout) SetX(x int) { w.x = x }
|
||||
func (w *RelativeLayout) SetY(y int) { w.y = y }
|
||||
func (w *RelativeLayout) GetX() int { return w.x }
|
||||
func (w *RelativeLayout) GetY() int { return w.y }
|
||||
func (w *RelativeLayout) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *RelativeLayout) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
|
||||
func (w *RelativeLayout) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
|
||||
func (w *RelativeLayout) SetW(wd int) { w.w = wd }
|
||||
func (w *RelativeLayout) SetH(h int) { w.h = h }
|
||||
func (w *RelativeLayout) GetW() int { return w.w }
|
||||
func (w *RelativeLayout) GetH() int { return w.h }
|
||||
func (w *RelativeLayout) WantW() int { return 1 }
|
||||
func (w *RelativeLayout) WantH() int { return 1 }
|
||||
func (w *RelativeLayout) MinW() int {
|
||||
// Find the highest value for x in all widgets GetX() + MinW()
|
||||
var minW int
|
||||
for _, wd := range w.widgets {
|
||||
wrk := wd.GetX() + wd.MinW()
|
||||
if wrk > minW {
|
||||
minW = wrk
|
||||
}
|
||||
}
|
||||
return minW
|
||||
}
|
||||
|
||||
func (w *RelativeLayout) MinH() int {
|
||||
// Find the highest value for y in all widgets GetY() + MinH()
|
||||
var minH int
|
||||
for _, wd := range w.widgets {
|
||||
wrk := wd.GetY() + wd.MinH()
|
||||
if wrk > minH {
|
||||
minH = wrk
|
||||
}
|
||||
}
|
||||
return minH
|
||||
}
|
||||
func (w *RelativeLayout) Active() bool { return w.active }
|
||||
func (w *RelativeLayout) SetActive(a bool) { w.active = a }
|
||||
func (w *RelativeLayout) Visible() bool { return w.visible }
|
||||
func (w *RelativeLayout) SetVisible(a bool) { w.visible = a }
|
||||
func (w *RelativeLayout) Focusable() bool { return true }
|
||||
func (w *RelativeLayout) SetX(x int) { w.x = x }
|
||||
func (w *RelativeLayout) SetY(y int) { w.y = y }
|
||||
func (w *RelativeLayout) GetX() int { return w.x }
|
||||
func (w *RelativeLayout) GetY() int { return w.y }
|
||||
func (w *RelativeLayout) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
|
||||
func (w *RelativeLayout) SetW(wd int) { w.w = wd }
|
||||
func (w *RelativeLayout) SetH(h int) { w.h = h }
|
||||
func (w *RelativeLayout) GetW() int { return w.w }
|
||||
func (w *RelativeLayout) GetH() int { return w.h }
|
||||
func (w *RelativeLayout) WantW() int { return 1 }
|
||||
func (w *RelativeLayout) WantH() int { return 1 }
|
||||
func (w *RelativeLayout) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
||||
|
||||
func (w *RelativeLayout) Add(n Widget, relTo Widget, relation RelativeRelation) {
|
||||
w.widgetRelations[n] = widgetRelation{
|
||||
@@ -107,3 +145,6 @@ func (w *RelativeLayout) Add(n Widget, relTo Widget, relation RelativeRelation)
|
||||
relTo: relTo,
|
||||
}
|
||||
}
|
||||
|
||||
func (w *RelativeLayout) AddRelation(n Widget, relation RelativeRelation, relTo Widget) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user