Skip to content

Commit

Permalink
throw exception when invalid enum value (should be applied to all enums)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed May 29, 2024
1 parent cf3be44 commit 7f7cacc
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions haxe/ui/constants/ScrollMode.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
package haxe.ui.constants;

enum abstract ScrollMode(String) from String to String {
var NORMAL = "normal";
var DRAG = "drag";
var INERTIAL = "inertial";
}
import haxe.ui.util.Variant;

enum abstract ScrollMode(String) to String {
var NORMAL = "normal";
var DRAG = "drag";
var INERTIAL = "inertial";
var HYBRID = "hybrid";

@:from public static function fromString(s:String):ScrollMode {
return switch (s.toLowerCase()) {
case "normal": NORMAL;
case "drag": DRAG;
case "inertial": INERTIAL;
case "hybrid": HYBRID;
case _: throw "invalid ScrollMode enum value '" + s + "'";
}
}

@:from public static function fromVariant(v:Variant):ScrollMode {
if (v == null || v.isNull) {
return null;
}
return fromString(v.toString());
}
}

0 comments on commit 7f7cacc

Please sign in to comment.