fixed dimension point logic

This commit is contained in:
Timon Ringwald 2022-05-04 15:17:26 +02:00
parent 542d5badbf
commit 67b65231fa
2 changed files with 7 additions and 17 deletions

View File

@ -137,7 +137,10 @@ func TestFlowLayout(t *testing.T) {
textView := views.NewTextView("hello world!")
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)
@ -151,27 +154,14 @@ func TestFlowLayout(t *testing.T) {
growView2.SetStyle(tui.StyleDefault.Background(tcell.ColorYellow))
flowLayout := views.NewFlowLayout(tui.Vertical)
flowLayout.AppendViews(marginView, growView, textView2)
flowLayout.AppendViews(textView, growView, textView2)
constrainView := views.NewConstrainView(flowLayout, -1, -1)
constrainView.SetStyle(tui.StyleDefault.Background(tcell.ColorPurple))
screen, err := tui.NewScreen(constrainView)
screen, err := tui.NewScreen(flowLayout)
if err != nil {
t.Error(err)
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()
fmt.Println(err)
}

View File

@ -23,7 +23,7 @@ func P(x, y int) Point {
}
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 {