|
@@ -10,7 +10,7 @@ private class Fake extends Object {
|
|
override function getBoundsRec(relativeTo:Object, out:h2d.col.Bounds, forSize:Bool) {
|
|
override function getBoundsRec(relativeTo:Object, out:h2d.col.Bounds, forSize:Bool) {
|
|
super.getBoundsRec(relativeTo, out, forSize);
|
|
super.getBoundsRec(relativeTo, out, forSize);
|
|
if (dd.selectedItem >= 0) {
|
|
if (dd.selectedItem >= 0) {
|
|
- var item = @:privateAccess dd.items[dd.selectedItem];
|
|
|
|
|
|
+ var item = @:privateAccess dd.getItem(dd.selectedItem);
|
|
var size = item.getSize();
|
|
var size = item.getSize();
|
|
addBounds(relativeTo, out, 0, 0, size.width, size.height);
|
|
addBounds(relativeTo, out, 0, 0, size.width, size.height);
|
|
}
|
|
}
|
|
@@ -18,12 +18,14 @@ private class Fake extends Object {
|
|
|
|
|
|
override function draw(ctx) {
|
|
override function draw(ctx) {
|
|
if (dd.selectedItem >= 0) {
|
|
if (dd.selectedItem >= 0) {
|
|
- var item = @:privateAccess dd.items[dd.selectedItem];
|
|
|
|
|
|
+ var item = @:privateAccess dd.getItem(dd.selectedItem);
|
|
var oldX = item.absX;
|
|
var oldX = item.absX;
|
|
var oldY = item.absY;
|
|
var oldY = item.absY;
|
|
item.absX = absX;
|
|
item.absX = absX;
|
|
item.absY = absY;
|
|
item.absY = absY;
|
|
|
|
+ for( c in item ) c.posChanged = true;
|
|
item.drawRec(ctx);
|
|
item.drawRec(ctx);
|
|
|
|
+ for( c in item ) c.posChanged = true;
|
|
item.absX = oldX;
|
|
item.absX = oldX;
|
|
item.absY = oldY;
|
|
item.absY = oldY;
|
|
}
|
|
}
|
|
@@ -39,8 +41,8 @@ private class Fake extends Object {
|
|
|
|
|
|
Note that when `dropdownList` opens and closes, item objects will receive the `onHierarchyChanged` callback.
|
|
Note that when `dropdownList` opens and closes, item objects will receive the `onHierarchyChanged` callback.
|
|
**/
|
|
**/
|
|
|
|
+@:uiNoComponent
|
|
class Dropdown extends Flow {
|
|
class Dropdown extends Flow {
|
|
- var items : Array<h2d.Object>;
|
|
|
|
var fake : Fake;
|
|
var fake : Fake;
|
|
var cursor : h2d.Bitmap;
|
|
var cursor : h2d.Bitmap;
|
|
var arrow : h2d.Bitmap;
|
|
var arrow : h2d.Bitmap;
|
|
@@ -66,8 +68,6 @@ class Dropdown extends Flow {
|
|
public var canEdit(default,set) : Bool = true;
|
|
public var canEdit(default,set) : Bool = true;
|
|
/**
|
|
/**
|
|
A reference to the Flow that will contain the items.
|
|
A reference to the Flow that will contain the items.
|
|
-
|
|
|
|
- Adding objects to this Flow will not automatically add them to the item list, use `Dropdown.addItem` instead.
|
|
|
|
**/
|
|
**/
|
|
public var dropdownList : Flow;
|
|
public var dropdownList : Flow;
|
|
/**
|
|
/**
|
|
@@ -122,7 +122,6 @@ class Dropdown extends Flow {
|
|
|
|
|
|
//
|
|
//
|
|
fake = new Fake(this);
|
|
fake = new Fake(this);
|
|
- items = [];
|
|
|
|
enableInteractive = true;
|
|
enableInteractive = true;
|
|
interactive.onPush = function(e:hxd.Event) {
|
|
interactive.onPush = function(e:hxd.Event) {
|
|
if( e.button == 0 && canEdit )
|
|
if( e.button == 0 && canEdit )
|
|
@@ -154,6 +153,7 @@ class Dropdown extends Flow {
|
|
}
|
|
}
|
|
dropdownList.interactive.onMove = function(e : hxd.Event) {
|
|
dropdownList.interactive.onMove = function(e : hxd.Event) {
|
|
var clickPos = dropdownList.localToGlobal(new h2d.col.Point(e.relX, e.relY));
|
|
var clickPos = dropdownList.localToGlobal(new h2d.col.Point(e.relX, e.relY));
|
|
|
|
+ var items = getItems();
|
|
for (i in 0...items.length) {
|
|
for (i in 0...items.length) {
|
|
var item = items[i];
|
|
var item = items[i];
|
|
var bds = item.getBounds();
|
|
var bds = item.getBounds();
|
|
@@ -177,13 +177,21 @@ class Dropdown extends Flow {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
dropdownList.interactive.onOut = function(e : hxd.Event) {
|
|
dropdownList.interactive.onOut = function(e : hxd.Event) {
|
|
- onOutItem(items[highlightedItem]);
|
|
|
|
|
|
+ onOutItem(getItem(highlightedItem));
|
|
highlightedItem = -1;
|
|
highlightedItem = -1;
|
|
cursor.visible = false;
|
|
cursor.visible = false;
|
|
}
|
|
}
|
|
needReflow = true;
|
|
needReflow = true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ function getItems() : Array<h2d.Object> {
|
|
|
|
+ return [for( i => obj in dropdownList.children ) if( !dropdownList.properties[i].isAbsolute ) obj];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function getItem(index) {
|
|
|
|
+ return getItems()[index];
|
|
|
|
+ }
|
|
|
|
+
|
|
override function set_backgroundTile(t) {
|
|
override function set_backgroundTile(t) {
|
|
super.set_backgroundTile(t);
|
|
super.set_backgroundTile(t);
|
|
if(dropdownList != null) dropdownList.backgroundTile = t;
|
|
if(dropdownList != null) dropdownList.backgroundTile = t;
|
|
@@ -204,7 +212,6 @@ class Dropdown extends Flow {
|
|
Adds the Object `s` to the dropdown list. `s` is not restricted to be the same type across all items.
|
|
Adds the Object `s` to the dropdown list. `s` is not restricted to be the same type across all items.
|
|
**/
|
|
**/
|
|
public function addItem(s : Object) {
|
|
public function addItem(s : Object) {
|
|
- items.push(s);
|
|
|
|
dropdownList.addChild(s);
|
|
dropdownList.addChild(s);
|
|
var width = Std.int(dropdownList.getSize().width);
|
|
var width = Std.int(dropdownList.getSize().width);
|
|
if( maxWidth != null && width > maxWidth ) width = maxWidth;
|
|
if( maxWidth != null && width > maxWidth ) width = maxWidth;
|
|
@@ -218,6 +225,7 @@ class Dropdown extends Flow {
|
|
}
|
|
}
|
|
|
|
|
|
function set_selectedItem(s) {
|
|
function set_selectedItem(s) {
|
|
|
|
+ var items = getItems();
|
|
if( s < 0 )
|
|
if( s < 0 )
|
|
s = -1;
|
|
s = -1;
|
|
else if( s >= items.length )
|
|
else if( s >= items.length )
|