Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented a TreeViewEvent for when nodes get collapsed or expanded and fixed Null Object Reference Error. #586

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion haxe/ui/components/Image.hx
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ private class ResourceBehaviour extends DataBehaviour {
_component.invalidateComponent();
return;
}
var subImage = null;

if(_component != null && _component.findComponent(Image) != null) subImage = _component.findComponent(Image);

var subImage = _component.findComponent(Image);
if (subImage != null) {
_component.removeComponent(subImage, false, false);
}
Expand Down
25 changes: 25 additions & 0 deletions haxe/ui/containers/TreeView.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import haxe.ui.data.ArrayDataSource;
import haxe.ui.data.DataSource;
import haxe.ui.events.UIEvent;
import haxe.ui.util.Variant;
import haxe.ui.events.EventType;


@:access(haxe.ui.containers.TreeViewNode)
@:composite(TreeViewEvents, TreeViewBuilder)
Expand All @@ -34,6 +36,8 @@ class TreeView extends ScrollView implements IDataComponent {
@:call(ClearNodes) public function clearNodes():Void;
@:call(GetNodesInternal) private function getNodesInternal():Array<Component>;

@:event(TreeViewEvent.NODE_COLLAPSE_EXPAND) public var onCollapseExpand:TreeViewEvent->Void;

private var _dataSource:DataSource<Dynamic> = null;
public var dataSource(get, set):DataSource<Dynamic>;
private function get_dataSource():DataSource<Dynamic> {
Expand Down Expand Up @@ -238,7 +242,28 @@ private class TreeViewBuilder extends ScrollViewBuilder {
}
}

class TreeViewEvent extends UIEvent{
public static final NODE_COLLAPSE_EXPAND:EventType<TreeViewEvent> = EventType.name("nodecollapseexpand");

public var expand:Bool = false;
public var affected_node:TreeViewNode;
public function new(type:EventType<TreeViewEvent>, expand:Bool = false, bubble:Null<Bool> = false, data:Dynamic = null){
super(type, bubble, data);
this.expand = expand;
}
public override function clone():TreeViewEvent {
var c:TreeViewEvent = new TreeViewEvent(this.type);
c.expand = this.expand;
c.affected_node = this.affected_node;
c.type = this.type;
c.bubble = this.bubble;
c.target = this.target;
c.data = this.data;
c.canceled = this.canceled;
postClone(c);
return c;
}
}


/***************************************************************************************************
Expand Down
6 changes: 6 additions & 0 deletions haxe/ui/containers/TreeViewNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import haxe.ui.core.InteractiveComponent;
import haxe.ui.core.ItemRenderer;
import haxe.ui.events.MouseEvent;
import haxe.ui.util.Variant;
import haxe.ui.containers.TreeView.TreeViewEvent;

#if (haxe_ver >= 4.2)
import Std.isOfType;
Expand Down Expand Up @@ -294,8 +295,13 @@ private class TreeViewNodeBuilder extends CompositeBuilder {

private function onExpandCollapseClicked(event:MouseEvent) {
event.cancel();
var treeview = _node.findAncestor(TreeView);
_node.expanded = !_node.expanded;
updateIconClass();
var event = new TreeViewEvent(TreeViewEvent.NODE_COLLAPSE_EXPAND);
event.expand = _node.expanded;
event.affected_node = _node;
treeview.dispatch(event);
}

public function updateIconClass() {
Expand Down