shithub: mycel

Download patch

ref: d5a4d882a221f32721bc9608d14bfbad0583c50b
parent: 32d6b0b328ef5a5e6a000211bf39e66184adf67f
author: Philip Silva <philip.silva@protonmail.com>
date: Thu Dec 2 23:13:18 EST 2021

check click instead of mousedown for links

--- a/browser/browser.go
+++ b/browser/browser.go
@@ -311,10 +311,12 @@
 	duit.UI
 	n       *nodes.Node
 	orig    image.Point
-	rect    image.Rectangle
 	IsLink  bool
 	Click   func() duit.Event
 	Changed func(*Element)
+
+	m    draw.Mouse
+	rect image.Rectangle
 }
 
 func NewElement(ui duit.UI, n *nodes.Node) *Element {
@@ -676,18 +678,18 @@
 		return
 	}
 
-	if m.Buttons == 1 {
-		if el.click() {
-			return duit.Result{
-				Consumed: true,
-			}
-		}
-	}
-	/*x := m.Point.X
+	x := m.Point.X
 	y := m.Point.Y
 	maxX := self.R.Dx()
 	maxY := self.R.Dy()
-	if 5 <= x && x <= (maxX-5) && 5 <= y && y <= (maxY-5) && el.IsLink {
+	border := 5 > x || x > (maxX-5) || 5 > y || y > (maxY-5)
+	hover := m.In(el.rect)
+	if hover && el.m.Buttons&duit.Button1 == duit.Button1 && m.Buttons&duit.Button1 == 0 && el.click() {
+		return duit.Result{
+			Consumed: true,
+		}
+	}
+	/*if !border && el.IsLink {
 		dui.Display.SwitchCursor(&draw.Cursor{
 			Black: cursor,
 		})
@@ -698,7 +700,11 @@
 	} else {
 		dui.Display.SwitchCursor(nil)
 	}*/
-
+	if border {
+		el.m = draw.Mouse{}
+	} else {
+		el.m = m
+	}
 	return el.UI.Mouse(dui, self, m, origM, orig)
 }