fixed dimension point logic
This commit is contained in:
parent
542d5badbf
commit
67b65231fa
@ -137,7 +137,10 @@ func TestFlowLayout(t *testing.T) {
|
|||||||
textView := views.NewTextView("hello world!")
|
textView := views.NewTextView("hello world!")
|
||||||
textView.SetStyle(tui.StyleDefault.Background(tcell.ColorRed).Foreground(tcell.ColorBlack))
|
textView.SetStyle(tui.StyleDefault.Background(tcell.ColorRed).Foreground(tcell.ColorBlack))
|
||||||
|
|
||||||
marginView := views.NewMarginView(textView, 3, 1, 1, 0)
|
textView.MouseEvent = func(event *tui.MouseEvent) (consumed bool) {
|
||||||
|
textView.Text = "hi"
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
//borderView := views.NewBorderView(textView)
|
//borderView := views.NewBorderView(textView)
|
||||||
|
|
||||||
@ -151,27 +154,14 @@ func TestFlowLayout(t *testing.T) {
|
|||||||
growView2.SetStyle(tui.StyleDefault.Background(tcell.ColorYellow))
|
growView2.SetStyle(tui.StyleDefault.Background(tcell.ColorYellow))
|
||||||
|
|
||||||
flowLayout := views.NewFlowLayout(tui.Vertical)
|
flowLayout := views.NewFlowLayout(tui.Vertical)
|
||||||
flowLayout.AppendViews(marginView, growView, textView2)
|
flowLayout.AppendViews(textView, growView, textView2)
|
||||||
|
|
||||||
constrainView := views.NewConstrainView(flowLayout, -1, -1)
|
screen, err := tui.NewScreen(flowLayout)
|
||||||
constrainView.SetStyle(tui.StyleDefault.Background(tcell.ColorPurple))
|
|
||||||
|
|
||||||
screen, err := tui.NewScreen(constrainView)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
screen.KeyPressed = func(event *tui.KeyEvent) (consumed bool) {
|
|
||||||
textView.Text = event.When().String()
|
|
||||||
|
|
||||||
if event.Key() == tcell.KeyCtrlC {
|
|
||||||
screen.StopWithError(errors.New(fmt.Sprintf("key: %#v | rune: %s", event.Key(), string(event.Rune()))))
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
err = screen.Start()
|
err = screen.Start()
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
2
types.go
2
types.go
@ -23,7 +23,7 @@ func P(x, y int) Point {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p Point) In(d Dimension) bool {
|
func (p Point) In(d Dimension) bool {
|
||||||
return p.X > d.X && p.X < d.X+d.Width && p.Y > d.Y && p.Y < d.Y+d.Height
|
return p.X >= d.X && p.X < d.X+d.Width && p.Y >= d.Y && p.Y < d.Y+d.Height
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Point) String() string {
|
func (p Point) String() string {
|
||||||
|
Loading…
Reference in New Issue
Block a user