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

Modified listener in order to avoid CHANGE event to be fired twice when "sliding" #120

Open
wants to merge 2 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
44 changes: 26 additions & 18 deletions src/ru/stablex/ui/widgets/InputText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,32 @@ class InputText extends Text{
* Constructor
*
*/
public var disabled :Bool = false;

public function new () : Void {
super();

#if !html5
this.label.type = flash.text.TextFieldType.INPUT;
#else
//due to strange bug we need this hack
this.addEventListener(Event.ADDED_TO_STAGE, function(e:Event){
if (!disabled){
#if !html5
this.label.type = flash.text.TextFieldType.INPUT;
Reflect.field(this.label, '__graphics').__surface.style.width = this.w + "px";
Reflect.field(this.label, '__graphics').__surface.style.height = this.h + "px";
Reflect.field(this.label, '__graphics').__surface.style.overflow = "hidden";
if( this.label.wordWrap ){
Reflect.field(this.label, '__graphics').__surface.style.whiteSpace = "normal";
}else{
Reflect.field(this.label, '__graphics').__surface.style.whiteSpace = "nowrap";
}
});
#end
#else
//due to strange bug we need this hack
this.addEventListener(Event.ADDED_TO_STAGE, function(e:Event){
this.label.type = flash.text.TextFieldType.INPUT;
Reflect.field(this.label, '__graphics').__surface.style.width = this.w + "px";
Reflect.field(this.label, '__graphics').__surface.style.height = this.h + "px";
Reflect.field(this.label, '__graphics').__surface.style.overflow = "hidden";
if( this.label.wordWrap ){
Reflect.field(this.label, '__graphics').__surface.style.whiteSpace = "normal";
}else{
Reflect.field(this.label, '__graphics').__surface.style.whiteSpace = "nowrap";
}
});
#end

this.label.autoSize = flash.text.TextFieldAutoSize.NONE;
this.format.align = flash.text.TextFormatAlign.LEFT;
this.label.autoSize = flash.text.TextFieldAutoSize.NONE;
this.format.align = flash.text.TextFormatAlign.LEFT;
}
}//function new()


Expand All @@ -59,6 +63,10 @@ class InputText extends Text{
Reflect.field(this.label, '__graphics').__surface.style.whiteSpace = "nowrap";
}
#end
if (disabled)
{this.label.type = null;}
else {this.label.type = flash.text.TextFieldType.INPUT;}

}//function refresh()

#if html5
Expand All @@ -85,4 +93,4 @@ class InputText extends Text{
return super.set_text(txt);
}//function set_text()
#end
}//class InputText
}//class InputText
7 changes: 6 additions & 1 deletion src/ru/stablex/ui/widgets/Switch.hx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ class Switch extends Widget{
private inline function _slide (e:MouseEvent) : Void {
var dx : Float = this.mouseX - this.slider.left;
var startX : Float = this.mouseX;
// Remove the Mouseup event for parent widget
this.removeEventListener(MouseEvent.MOUSE_UP, this._onRelease); // added row

//indicate user is actually moving slider
var slided : Bool = false;

Expand Down Expand Up @@ -174,9 +177,11 @@ class Switch extends Widget{
//remove listeners
this.removeEventListener(Event.ENTER_FRAME, fn);
Lib.current.stage.removeEventListener(MouseEvent.MOUSE_UP, fnRelease);
// Add the Mouseup event for parent widget
this.addEventListener(MouseEvent.MOUSE_UP, this._onRelease); // added row
};

//listen for MOUSE_UP
Lib.current.stage.addEventListener(MouseEvent.MOUSE_UP, fnRelease);
}//function _slide()
}//class Switch
}//class Switch