From 03fbdb7cc68114d9e6b105fc0951ccb4716a9adb Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Wed, 7 Jun 2017 20:42:45 -0500 Subject: [PATCH 1/2] Find non-children Maybe fixed findAncestor? --- haxe/ui/containers/TabView.hx | 6 ++- haxe/ui/core/Component.hx | 79 +++++++++++++++++++---------------- 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/haxe/ui/containers/TabView.hx b/haxe/ui/containers/TabView.hx index 0f4772518..c5f3ee876 100644 --- a/haxe/ui/containers/TabView.hx +++ b/haxe/ui/containers/TabView.hx @@ -92,7 +92,11 @@ class TabView extends Component { var match = super.findComponent(criteria, type, recursive, searchType); if (match == null) { for (view in _views) { - match = view.findComponent(criteria, type, recursive, searchType); + if (view.matchesSearch(criteria, type, searchType)) { + return cast view; + } else { + match = view.findComponent(criteria, type, recursive, searchType); + } if (match != null) { break; } diff --git a/haxe/ui/core/Component.hx b/haxe/ui/core/Component.hx index b2afa73b3..1bcf9155f 100644 --- a/haxe/ui/core/Component.hx +++ b/haxe/ui/core/Component.hx @@ -583,6 +583,29 @@ class Component extends ComponentBase implements IComponentBase implements IClon return _children; } + /** + Checks if this component meets the search criteria + + - `criteria` - The criteria by which to search, the interpretation of this is defined using `searchType` (the default search type is _id_) + + - `type` - The component class you wish to cast the result to (defaults to _null_) + + - `searchType` - Allows you specify how to consider a parent a match (defaults to _id_), can be either: + + - `id` - The first component that has the id specified in `criteria` will be considered a match + + - `css` - The first component that contains a style name specified by `criteria` will be considered a match + **/ + @:dox(group = "Display tree related properties and methods") + public function matchesSearch(criteria:String = null, type:Class = null, searchType:String = "id"):Bool { + if (criteria != null) { + return searchType == "id" && id == criteria || searchType == "css" && hasClass(criteria) == true; + } else if (type != null) { + return Std.is(this, type) == true; + } + return false; + } + /** Finds a specific child in this components display tree (recusively if desired) and can optionally cast the result @@ -606,19 +629,9 @@ class Component extends ComponentBase implements IComponentBase implements IClon var match:Component = null; for (child in childComponents) { - if (criteria != null) { - if (searchType == "id" && child.id == criteria) { - match = cast child; - break; - } else if (searchType == "css" && child.hasClass(criteria) == true) { - match = cast child; - break; - } - } else if (type != null) { - if (Std.is(child, type) == true) { - match = cast child; - break; - } + if (child.matchesSearch(criteria, type, searchType)) { + match = child; + break; } } if (match == null && recursive == true) { @@ -652,19 +665,11 @@ class Component extends ComponentBase implements IComponentBase implements IClon var match:Component = null; var p = this.parentComponent; while (p != null) { - if (criteria != null) { - if (searchType == "id" && p.id == criteria) { - match = cast p; - break; - } else if (searchType == "css" && p.hasClass(criteria) == true) { - match = cast p; - break; - } - } else if (type != null) { - if (Std.is(p, type) == true) { - match = cast p; - break; - } + if (p.matchesSearch(criteria, type, searchType)) { + match = p; + break; + } else { + p = p.parentComponent; } } return cast match; @@ -803,12 +808,12 @@ class Component extends ComponentBase implements IComponentBase implements IClon invalidateStyle(); } } - - if (recursive == true) { - for (child in childComponents) { - child.addClass(name, invalidate, recursive); - } - } + + if (recursive == true) { + for (child in childComponents) { + child.addClass(name, invalidate, recursive); + } + } } /** @@ -823,11 +828,11 @@ class Component extends ComponentBase implements IComponentBase implements IClon } } - if (recursive == true) { - for (child in childComponents) { - child.removeClass(name, invalidate, recursive); - } - } + if (recursive == true) { + for (child in childComponents) { + child.removeClass(name, invalidate, recursive); + } + } } /** From d217dc48ec937794f8977077cfeb579fb8788430 Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Wed, 7 Jun 2017 21:10:18 -0500 Subject: [PATCH 2/2] CI tab fix --- haxe/ui/containers/TabView.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/haxe/ui/containers/TabView.hx b/haxe/ui/containers/TabView.hx index c5f3ee876..40ddef942 100644 --- a/haxe/ui/containers/TabView.hx +++ b/haxe/ui/containers/TabView.hx @@ -94,7 +94,7 @@ class TabView extends Component { for (view in _views) { if (view.matchesSearch(criteria, type, searchType)) { return cast view; - } else { + } else { match = view.findComponent(criteria, type, recursive, searchType); } if (match != null) {