Просмотр исходного кода

ignore gui.Panel events over the panel's margins

leonsal 8 лет назад
Родитель
Сommit
4d8b389833
3 измененных файлов с 17 добавлено и 3 удалено
  1. 2 2
      gui/dropdown.go
  2. 14 0
      gui/panel.go
  3. 1 1
      gui/root.go

+ 2 - 2
gui/dropdown.go

@@ -175,7 +175,7 @@ func (dd *DropDown) onListMouse(evname string, ev interface{}) {
 	if evname == OnMouseDown {
 		// If click occurred inside the list scrollbar ignore it
 		if dd.list.vscroll != nil {
-			if dd.list.vscroll.ContainsPosition(mev.Xpos, mev.Ypos) {
+			if dd.list.vscroll.InsideBorders(mev.Xpos, mev.Ypos) {
 				return
 			}
 		}
@@ -193,7 +193,7 @@ func (dd *DropDown) onListMouse(evname string, ev interface{}) {
 		}
 		// If list clickout occurred inside the dropdown, set 'clickOut' to
 		// indicate that the list was already closed
-		if dd.Panel.ContainsPosition(mev.Xpos, mev.Ypos) {
+		if dd.Panel.InsideBorders(mev.Xpos, mev.Ypos) {
 			dd.clickOut = true
 		}
 	}

+ 14 - 0
gui/panel.go

@@ -547,6 +547,20 @@ func (p *Panel) ContainsPosition(x, y float32) bool {
 	return true
 }
 
+// InsideBorders returns indication if the specified screen
+// position in pixels is inside the panel borders, including the borders width.
+// Unlike "ContainsPosition" is does not consider the panel margins.
+func (p *Panel) InsideBorders(x, y float32) bool {
+
+	if x < (p.pospix.X+p.marginSizes.Left) || x >= (p.pospix.X+p.width-p.marginSizes.Right) {
+		return false
+	}
+	if y < (p.pospix.Y+p.marginSizes.Top) || y >= (p.pospix.Y+p.height-p.marginSizes.Bottom) {
+		return false
+	}
+	return true
+}
+
 // SetEnabled sets the panel enabled state
 // A disabled panel do not process key or mouse events.
 func (p *Panel) SetEnabled(state bool) {

+ 1 - 1
gui/root.go

@@ -242,7 +242,7 @@ func (r *Root) sendPanels(x, y float32, evname string, ev interface{}) {
 			return
 		}
 		// Checks if this panel contains the mouse position
-		found := pan.ContainsPosition(x, y)
+		found := pan.InsideBorders(x, y)
 		if found {
 			r.targets = append(r.targets, ipan)
 		} else {