Browse Source

added onChange

Nicolas Cannasse 4 năm trước cách đây
mục cha
commit
6efc9e0a04
1 tập tin đã thay đổi với 16 bổ sung2 xóa
  1. 16 2
      h2d/Dropdown.hx

+ 16 - 2
h2d/Dropdown.hx

@@ -120,6 +120,13 @@ class Dropdown extends Flow {
 		p.horizontalAlign = Right;
 		p.horizontalAlign = Right;
 		p.verticalAlign = Top;
 		p.verticalAlign = Top;
 
 
+		inline function setItem(i) {
+			if( selectedItem != i ) {
+				selectedItem = i;
+				onChange(getItem(i));
+			}
+		}
+
 		//
 		//
 		fake = new Fake(this);
 		fake = new Fake(this);
 		enableInteractive = true;
 		enableInteractive = true;
@@ -141,14 +148,14 @@ class Dropdown extends Flow {
 
 
 		interactive.onFocusLost = function(e) {
 		interactive.onFocusLost = function(e) {
 			if (highlightedItem >= 0 && canEdit) {
 			if (highlightedItem >= 0 && canEdit) {
-				selectedItem = highlightedItem;
+				setItem(highlightedItem);
 			}
 			}
 			close();
 			close();
 		}
 		}
 
 
 		dropdownList.enableInteractive = true;
 		dropdownList.enableInteractive = true;
 		dropdownList.interactive.onClick = function(e) {
 		dropdownList.interactive.onClick = function(e) {
-			if( canEdit ) selectedItem = highlightedItem;
+			if( canEdit ) setItem(highlightedItem);
 			close();
 			close();
 		}
 		}
 		dropdownList.interactive.onMove = function(e : hxd.Event) {
 		dropdownList.interactive.onMove = function(e : hxd.Event) {
@@ -279,6 +286,13 @@ class Dropdown extends Flow {
 	public dynamic function onClose() {
 	public dynamic function onClose() {
 	}
 	}
 
 
+	/**
+		Sent when user change the item in the list.
+		@param item An object that was hovered.
+	**/
+	public dynamic function onChange(item : Object) {
+	}
+
 	/**
 	/**
 		Sent when user hovers over an item in the dropdown list.
 		Sent when user hovers over an item in the dropdown list.
 		@param item An object that was hovered.
 		@param item An object that was hovered.