fixed FlowLayout.RemoveViews
This commit is contained in:
parent
a20d361871
commit
9f3213e45c
@ -62,8 +62,8 @@ func TestScrollView(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
screen.MouseClicked = func(event *tui.MouseEvent) (consumed bool) {
|
screen.MouseClicked = func(event *tui.MouseEvent) (consumed bool) {
|
||||||
//textViews[0].(*views.TextView).Text = fmt.Sprintf("mouse position: %d | %d", event.X, event.Y)
|
textViews[0].(*views.TextView).Text = fmt.Sprintf("mouse position: %d | %d", event.X, event.Y)
|
||||||
//textViews[1].(*views.TextView).Text = fmt.Sprintf("mouse button: %d", event.Button)
|
textViews[1].(*views.TextView).Text = fmt.Sprintf("mouse button: %d", event.Button)
|
||||||
|
|
||||||
if event.Button == tui.MouseWheelUp {
|
if event.Button == tui.MouseWheelUp {
|
||||||
scrollView.Scroll(-1, 0)
|
scrollView.Scroll(-1, 0)
|
||||||
|
@ -29,6 +29,7 @@ func (g *CoordLayout) Views() []tui.View {
|
|||||||
func (g *CoordLayout) SetView(v tui.View, x, y, width, height int) {
|
func (g *CoordLayout) SetView(v tui.View, x, y, width, height int) {
|
||||||
g.views[v] = tui.Dimension{Point: tui.Point{X: x, Y: y}, Size: tui.Size{Width: width, Height: height}}
|
g.views[v] = tui.Dimension{Point: tui.Point{X: x, Y: y}, Size: tui.Size{Width: width, Height: height}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *CoordLayout) Draw(buf *tui.ViewBuffer) {
|
func (g *CoordLayout) Draw(buf *tui.ViewBuffer) {
|
||||||
for v, d := range g.views {
|
for v, d := range g.views {
|
||||||
v.Draw(buf.Sub(d.X, d.Y, d.Width, d.Height))
|
v.Draw(buf.Sub(d.X, d.Y, d.Width, d.Height))
|
||||||
|
@ -39,15 +39,21 @@ func (g *FlowLayout) InsertView(v tui.View, index int) {
|
|||||||
g.views = append(g.views[:index], append([]tui.View{v}, g.views[index:]...)...)
|
g.views = append(g.views[:index], append([]tui.View{v}, g.views[index:]...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *FlowLayout) RemoveView(v tui.View) {
|
func (g *FlowLayout) removeView(v tui.View) {
|
||||||
for index, view := range g.Views() {
|
for index, view := range g.Views() {
|
||||||
if view == v {
|
if v == view {
|
||||||
g.views = append(g.views[:index], g.views[index:]...)
|
g.views = append(g.views[:index], g.views[index+1:]...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *FlowLayout) RemoveViews(v ...tui.View) {
|
||||||
|
for _, view := range v {
|
||||||
|
g.removeView(view)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (g *FlowLayout) Draw(buf *tui.ViewBuffer) {
|
func (g *FlowLayout) Draw(buf *tui.ViewBuffer) {
|
||||||
g.ViewTmpl.Draw(buf)
|
g.ViewTmpl.Draw(buf)
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ func NewScrollView(view tui.View) *ScrollView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *ScrollView) Draw(buf *tui.ViewBuffer) {
|
func (v *ScrollView) Draw(buf *tui.ViewBuffer) {
|
||||||
|
v.ViewTmpl.Draw(buf)
|
||||||
|
|
||||||
w, h := v.View().Layout()
|
w, h := v.View().Layout()
|
||||||
|
|
||||||
if v.buf == nil || v.buf.Width() != w || v.buf.Height() != h {
|
if v.buf == nil || v.buf.Width() != w || v.buf.Height() != h {
|
||||||
|
Loading…
Reference in New Issue
Block a user