Fix crash on TAB

This commit is contained in:
Vladimir Markelov 2015-10-17 01:16:19 -07:00
parent 4b95d078c9
commit 189788fcd6
6 changed files with 16 additions and 3 deletions

View File

@ -203,7 +203,6 @@ func (c *Composer) resizeTopView(ev termbox.Event) bool {
}
w, h := view.Size()
wm, hm := view.Constraints()
w1, h1 := w, h
minW, minH := view.Constraints()
if ev.Key == termbox.KeyArrowUp && minH < h {

View File

@ -171,6 +171,9 @@ func (c *ControlBase) Parent() Control {
return c.parent
}
func (c *ControlBase) RecalculateConstraints() {
}
//---------- debug ----------------
func (c *ControlBase) Logger() *log.Logger {
if c.parent == nil {

View File

@ -95,6 +95,12 @@ func (f *Frame) RecalculateConstraints() {
if newW != width || newH != height {
f.SetConstraints(newW, newH)
}
if f.parent != nil {
f.parent.RecalculateConstraints()
} else if f.view != nil {
f.view.RecalculateConstraints()
}
}
func (f *Frame) AddChild(c Control, scale int) {

View File

@ -59,6 +59,7 @@ type View interface {
SetScale(int)
TabStop() bool
Colors() (term.Attribute, term.Attribute)
RecalculateConstraints()
Logger() *log.Logger
}
@ -86,5 +87,7 @@ type Control interface {
Parent() Control
Colors() (term.Attribute, term.Attribute)
RecalculateConstraints()
Logger() *log.Logger
}

View File

@ -23,7 +23,7 @@ func NewLabel(view View, parent Control, w, h int, title string, scale int) *Lab
c.tabSkip = true
c.fg = ColorWhite
c.bg = ColorBlack
c.bg = ColorBlackBold
if parent != nil {
parent.AddChild(c, scale)

View File

@ -276,7 +276,9 @@ func (w *Window) ProcessEvent(ev Event) bool {
if ev.Type == EventKey && (ev.Key == term.KeyTab || (ev.Mod&term.ModAlt != 0 && (ev.Key == term.KeyPgup || ev.Key == term.KeyPgdn))) {
forward := ev.Key != term.KeyPgup
ctrl := w.ActiveControl()
ctrl.ProcessEvent(Event{Type: EventActivate, X: 0})
if ctrl != nil {
ctrl.ProcessEvent(Event{Type: EventActivate, X: 0})
}
ctrl = w.NextControl(ctrl, forward)
if ctrl != nil {
// w.Logger().Printf("Activate control: %v", ctrl)