Skip to content

Commit

Permalink
EditableTextField: allow cycling through Enum values
Browse files Browse the repository at this point in the history
see #1924
  • Loading branch information
Gama11 committed Sep 19, 2016
1 parent c0fa47d commit 5702c92
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions flixel/system/debug/watch/EditableTextField.hx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class EditableTextField extends TextField implements IFlxDestroyable
case TBool:
text = if (text == "true") "false" else "true";
selectEnd();
case TEnum(e):
cycleEnumValue(e, FlxMath.signOf(modifier));
selectEnd();
case _:
setSelection(selection, selection);
}
Expand All @@ -114,6 +117,21 @@ class EditableTextField extends TextField implements IFlxDestroyable
text = Std.string(value);
}

private function cycleEnumValue(e:Enum<Dynamic>, modifier:Int):Void
{
var values = e.getConstructors();
var index = values.indexOf(text);
if (index == -1)
index = 0;
else
{
index += modifier;
if (index > values.length)
index = 0;
}

This comment has been minimized.

Copy link
@MSGhero

MSGhero Sep 19, 2016

Member

else if (index < 0) index = values.length - 1;?

This comment has been minimized.

Copy link
@Gama11

Gama11 Sep 19, 2016

Author Member

Damnit.. Should really just use FlxMath.bound().

This comment has been minimized.

Copy link
@Gama11

Gama11 Sep 19, 2016

Author Member

wrap() I mean.

text = Std.string(values[index]);
}

private function onFocusLost(_)
{
setIsEditing(false);
Expand All @@ -129,6 +147,9 @@ class EditableTextField extends TextField implements IFlxDestroyable
#end
case TBool if (text == "true"): true;
case TBool if (text == "false"): false;
case TEnum(e):
try Type.createEnum(e, text)
catch (_:Dynamic) null;
case _: text;
}

Expand Down

0 comments on commit 5702c92

Please sign in to comment.