From 67b65231fa0ea3f5c671e3a794fbf3bb98ac8059 Mon Sep 17 00:00:00 2001 From: Timon Ringwald Date: Wed, 4 May 2022 15:17:26 +0200 Subject: [PATCH] fixed dimension point logic --- tests/screen_test.go | 22 ++++++---------------- types.go | 2 +- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/tests/screen_test.go b/tests/screen_test.go index b28f476..67a2c22 100644 --- a/tests/screen_test.go +++ b/tests/screen_test.go @@ -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) } diff --git a/types.go b/types.go index 10c7fd7..254af93 100644 --- a/types.go +++ b/types.go @@ -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 {