소스 검색

Add over and out events on HtmlText <a> nodes

Leonardo Jeanteur 1 년 전
부모
커밋
11f8a8a612
2개의 변경된 파일40개의 추가작업 그리고 0개의 파일을 삭제
  1. 31 0
      h2d/HtmlText.hx
  2. 9 0
      h2d/domkit/BaseComponents.hx

+ 31 - 0
h2d/HtmlText.hx

@@ -71,6 +71,12 @@ class HtmlText extends Text {
 		If not set, uncondensed whitespace is left as is, as well as line-breaks.
 	**/
 	public var condenseWhite(default,set) : Bool = true;
+
+	/**
+		When enabled, nodes that create interactives will propagate events
+	**/
+	public var propagateInteractiveNode(default,set) : Bool = false;
+
 	/**
 		The spacing after `<img>` tags in pixels.
 	**/
@@ -169,6 +175,16 @@ class HtmlText extends Text {
 	**/
 	public dynamic function onHyperlink(url:String) : Void {
 	}
+	/**
+		Called on a <a> tag over
+	**/
+	public dynamic function onOverHyperlink(url:String) : Void {
+	}
+	/**
+		Called on a <a> tag out
+	**/
+	public dynamic function onOutHyperlink(url:String) : Void {
+	}
 
 	/**
 		Called when text is assigned, allowing to process arbitrary text to a valid XHTML.
@@ -592,10 +608,17 @@ class HtmlText extends Text {
 			if(aHrefs == null || aHrefs.length == 0)
 				return;
 			aInteractive = new Interactive(0, metrics[sizePos].height, this);
+			aInteractive.propagateEvents = propagateInteractiveNode;
 			var href = aHrefs[aHrefs.length-1];
 			aInteractive.onClick = function(event) {
 				onHyperlink(href);
 			}
+			aInteractive.onOver = function(event) {
+				onOverHyperlink(href);
+			}
+			aInteractive.onOut = function(event) {
+				onOutHyperlink(href);
+			}
 			aInteractive.x = xPos;
 			aInteractive.y = yPos;
 			elements.push(aInteractive);
@@ -801,6 +824,14 @@ class HtmlText extends Text {
 		return value;
 	}
 
+	function set_propagateInteractiveNode(value: Bool) {
+		if ( this.propagateInteractiveNode != value ) {
+			this.propagateInteractiveNode = value;
+			rebuild();
+		}
+		return value;
+	}
+
 	function set_imageVerticalAlign(align) {
 		if ( this.imageVerticalAlign != align ) {
 			this.imageVerticalAlign = align;

+ 9 - 0
h2d/domkit/BaseComponents.hx

@@ -720,10 +720,19 @@ class TextComp extends DrawableComp implements domkit.Component.ComponentDecl<h2
 @:uiComp("html-text") @:domkitDecl
 class HtmlTextComp extends TextComp implements domkit.Component.ComponentDecl<h2d.HtmlText> {
 	@:p var condenseWhite : Bool;
+	@:p var propagateInteractiveNode: Bool;
 
 	static function create( parent : h2d.Object ) {
 		return new h2d.HtmlText(hxd.res.DefaultFont.get(),parent);
 	}
+
+	static function set_condenseWhite(o : h2d.HtmlText, v) {
+		o.condenseWhite = v;
+	}
+
+	static function set_propagateInteractiveNode(o : h2d.HtmlText, v) {
+		o.propagateInteractiveNode = v;
+	}
 }
 
 @:uiComp("scale-grid") @:domkitDecl