|
@@ -27,6 +27,7 @@ type Panel struct {
|
|
|
TitleOffset int
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
func (p *Panel) Range(withBorder bool) (sx, sy, ex, ey int) {
|
|
|
sx = p.X
|
|
|
sy = p.Y
|
|
@@ -43,6 +44,65 @@ func (p *Panel) Range(withBorder bool) (sx, sy, ex, ey int) {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+*/
|
|
|
+
|
|
|
+func (p *Panel) Length() int {
|
|
|
+ return len(p.Lines)
|
|
|
+}
|
|
|
+
|
|
|
+func (p *Panel) RightBottomPos() (rx, by int) {
|
|
|
+ rx = p.X + p.Width
|
|
|
+ by = p.Y + len(p.Lines)
|
|
|
+ if p.HasBorder() {
|
|
|
+ rx += 2
|
|
|
+ by += 2
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (p *Panel) HasBorder() bool {
|
|
|
+ return int(p.Style) > 0
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+Is X,Y within the Panel?
|
|
|
+*/
|
|
|
+func (p *Panel) Within(x, y int) (bool, int, int) {
|
|
|
+ if x < p.X || y < p.Y {
|
|
|
+ return false, 0, 0
|
|
|
+ }
|
|
|
+ mx, my := p.RightBottomPos()
|
|
|
+ if x > mx || y > my {
|
|
|
+ return false, 0, 0
|
|
|
+ }
|
|
|
+ // Ok, it must be within:
|
|
|
+ return true, x - p.X, y - p.Y
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+// 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 false, 0
|
|
|
+}
|
|
|
+*/
|
|
|
|
|
|
// Clear out the panel
|
|
|
func (p *Panel) Clear() string {
|
|
@@ -225,26 +285,3 @@ func (p *Panel) CenterX() {
|
|
|
func (p *Panel) CenterY() {
|
|
|
p.Y = (Height - len(p.Lines)) / 2
|
|
|
}
|
|
|
-
|
|
|
-// 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 false, 0
|
|
|
-}
|