Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #23 by implementing Block.InnerBounds() and associated test. #24

Merged
merged 1 commit into from
Apr 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ func (d *Block) align() {

}

// InnerBounds returns the internal bounds of the block after aligning and
// calculating the padding and border, if any.
func (d *Block) InnerBounds() (x, y, width, height int) {
d.align()
return d.innerX, d.innerY, d.innerWidth, d.innerHeight
}

// Buffer implements Bufferer interface.
// Draw background and border (if any).
func (d *Block) Buffer() []Point {
Expand Down
46 changes: 46 additions & 0 deletions block_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package termui

import "testing"

func TestBlock_InnerBounds(t *testing.T) {
b := NewBlock()
b.X = 10
b.Y = 11
b.Width = 12
b.Height = 13

assert := func(name string, x, y, w, h int) {
t.Log(name)
cx, cy, cw, ch := b.InnerBounds()
if cx != x {
t.Errorf("expected x to be %d but got %d", x, cx)
}
if cy != y {
t.Errorf("expected y to be %d but got %d", y, cy)
}
if cw != w {
t.Errorf("expected width to be %d but got %d", w, cw)
}
if ch != h {
t.Errorf("expected height to be %d but got %d", h, ch)
}
}

b.HasBorder = false
assert("no border, no padding", 10, 11, 12, 13)

b.HasBorder = true
assert("border, no padding", 11, 12, 10, 11)

b.PaddingBottom = 2
assert("border, 2b padding", 11, 12, 10, 9)

b.PaddingTop = 3
assert("border, 2b 3t padding", 11, 15, 10, 6)

b.PaddingLeft = 4
assert("border, 2b 3t 4l padding", 15, 15, 6, 6)

b.PaddingRight = 5
assert("border, 2b 3t 4l 5r padding", 15, 15, 1, 6)
}