[hw] rename haxework package to hw
This commit is contained in:
74
src/main/hw/view/geometry/SizeValue.hx
Normal file
74
src/main/hw/view/geometry/SizeValue.hx
Normal file
@@ -0,0 +1,74 @@
|
||||
package hw.view.geometry;
|
||||
|
||||
enum SizeType {
|
||||
FIXED;
|
||||
PERCENT;
|
||||
}
|
||||
|
||||
abstract SizeValue({type:SizeType, value:Float}) {
|
||||
public var type(get, set):SizeType;
|
||||
public var value(get, set):Float;
|
||||
|
||||
public var fixed(get, set):Float;
|
||||
public var percent(get, set):Float;
|
||||
|
||||
public function new(type:SizeType, value:Float) {
|
||||
this = {type: type, value: value};
|
||||
}
|
||||
|
||||
private inline function get_type():SizeType {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
private inline function set_type(value:SizeType):SizeType {
|
||||
return this.type = value;
|
||||
}
|
||||
|
||||
private inline function get_value():Float {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
private inline function set_value(value:Float):Float {
|
||||
return this.value = value;
|
||||
}
|
||||
|
||||
private inline function get_fixed():Float {
|
||||
return switch type {
|
||||
case FIXED: value;
|
||||
case _: 0;
|
||||
}
|
||||
}
|
||||
|
||||
private inline function set_fixed(value:Float):Float {
|
||||
this.type = FIXED;
|
||||
return this.value = value;
|
||||
}
|
||||
|
||||
private inline function get_percent():Float {
|
||||
return switch type {
|
||||
case PERCENT: value;
|
||||
case _: 0;
|
||||
}
|
||||
}
|
||||
|
||||
private inline function set_percent(value:Float):Float {
|
||||
this.type = PERCENT;
|
||||
return this.value = value;
|
||||
}
|
||||
|
||||
@:from static public inline function fromInt(value:Int):SizeValue {
|
||||
return new SizeValue(FIXED, value);
|
||||
}
|
||||
|
||||
@:from static public inline function fromFloat(value:Float):SizeValue {
|
||||
return new SizeValue(FIXED, value);
|
||||
}
|
||||
|
||||
@:from static public inline function fromString(value:String):SizeValue {
|
||||
if (value.substr(value.length - 1) == "%") {
|
||||
return new SizeValue(PERCENT, Std.parseFloat(value));
|
||||
} else {
|
||||
return new SizeValue(FIXED, Std.parseFloat(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user