|
@@ -27,6 +27,23 @@ type Panel struct {
|
|
|
TitleOffset int
|
|
|
}
|
|
|
|
|
|
+func (p *Panel) Range(withBorder bool) (sx, sy, ex, ey int) {
|
|
|
+ sx = p.X
|
|
|
+ sy = p.Y
|
|
|
+ ex = p.X + p.Width
|
|
|
+ ey = p.Y + len(p.Lines)
|
|
|
+ if p.Style > 0 {
|
|
|
+ if withBorder {
|
|
|
+ ex += 2
|
|
|
+ ey += 2
|
|
|
+ } else {
|
|
|
+ sx += 1
|
|
|
+ sy += 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// Output the panel
|
|
|
func (p *Panel) Output() string {
|
|
|
var style int = int(p.Style)
|
|
@@ -130,7 +147,7 @@ func (p *Panel) UpdateLine(index int) string {
|
|
|
return output
|
|
|
}
|
|
|
|
|
|
-// Goto the end
|
|
|
+// Position Cursor at the "end" of the panel
|
|
|
func (p *Panel) GotoEnd() string {
|
|
|
var row, col int
|
|
|
row = p.Y
|
|
@@ -183,34 +200,25 @@ func (p *Panel) CenterY() {
|
|
|
p.Y = (Height - len(p.Lines)) / 2
|
|
|
}
|
|
|
|
|
|
-func (p *Panel) Clicked(m Mouse) (line int, clicked bool) {
|
|
|
- mX := int(m.X)
|
|
|
- mY := int(m.Y)
|
|
|
-
|
|
|
- if p.Style == NONE {
|
|
|
- if mY >= p.Y && mY < p.Y+len(p.Lines) &&
|
|
|
- mX >= p.X && mX < p.X+p.Width {
|
|
|
- return p.Y - mY + 1, true
|
|
|
- }
|
|
|
- return 0, false
|
|
|
- } else {
|
|
|
- if mY == p.Y || mY == p.Y+len(p.Lines)+1 {
|
|
|
- if mX >= p.X && mX <= p.X+p.Width+1 {
|
|
|
- // Top/Bottom border clicked
|
|
|
- return 0, true
|
|
|
- }
|
|
|
- }
|
|
|
- if mY > p.Y && mY < p.Y+len(p.Lines)+1 {
|
|
|
- if mX == p.X || mX == p.X+p.Width+1 {
|
|
|
- // Left/Right border clicked
|
|
|
- return 0, true
|
|
|
- }
|
|
|
- }
|
|
|
- if mY > p.Y && mY < p.Y+len(p.Lines)+1 {
|
|
|
- if mY > p.X && mY <= p.X+p.Width+1 {
|
|
|
- return p.Y - mY, true
|
|
|
+// Panel Clicked?
|
|
|
+// If onBorder == true, returns true, 0 for border click.
|
|
|
+// Otherwise true, line clicked on (starting with 1)/
|
|
|
+func (p *Panel) Clicked(m Mouse, onBorder bool) (bool, int) {
|
|
|
+ var sx, sy, ex, ey = p.Range(onBorder)
|
|
|
+ var mx = int(m.X)
|
|
|
+ var my = int(m.Y)
|
|
|
+
|
|
|
+ if (mx >= sx) && (mx <= ex) {
|
|
|
+ if (my >= sy) && (my <= ey) {
|
|
|
+ if onBorder {
|
|
|
+ if my == sy || my == ey {
|
|
|
+ return true, 0
|
|
|
+ }
|
|
|
+ return true, my - sy
|
|
|
+ } else {
|
|
|
+ return true, (my - sy) + 1
|
|
|
}
|
|
|
}
|
|
|
- return 0, false
|
|
|
}
|
|
|
+ return false, 0
|
|
|
}
|