Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ianharrigan committed Jan 31, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents aae44f3 + 0fddeba commit 9da6ce5
Showing 5 changed files with 21 additions and 4 deletions.
17 changes: 13 additions & 4 deletions haxe/ui/components/NumberStepper.hx
Original file line number Diff line number Diff line change
@@ -50,6 +50,11 @@ class NumberStepper extends InteractiveComponent implements ICompositeInteractiv
*/
@:clonable @:behaviour(DefaultBehaviour, null) public var step:Null<Float>;

/**
* If true, values that differ from the specified `step` will be marked as invalid.
*/
@:clonable @:behaviour(DefaultBehaviour, false) public var forceStep:Bool;

/**
* The highest value this stepper can get to, even when set through code.
*/
@@ -308,7 +313,7 @@ private class Events extends haxe.ui.events.Events {
}
var parsedValue = Std.parseFloat(value.text);
parsedValue = MathUtil.clamp(parsedValue, _stepper.min, _stepper.max);
if (_stepper.step != null && parsedValue % _stepper.step != 0) {
if (_stepper.step != null && _stepper.forceStep && parsedValue % _stepper.step != 0) {
parsedValue = MathUtil.roundToNearest(parsedValue, _stepper.step);
}

@@ -491,7 +496,7 @@ private class ValueHelper {
valid = false;
}

if (step != null && MathUtil.fmodulo(parsedValue, step) != 0) {
if (step != null && stepper.forceStep && MathUtil.fmodulo(parsedValue, step) != 0) {
valid = false;
parsedValue = MathUtil.roundToNearest(parsedValue, step);
}
@@ -523,7 +528,9 @@ private class ValueHelper {
}
} else {
newValue += step;
newValue = MathUtil.roundToNearest(newValue, step);
if (stepper.forceStep) {
newValue = MathUtil.roundToNearest(newValue, step);
}
}

if (max != null && newValue > max) {
@@ -549,7 +556,9 @@ private class ValueHelper {
}
} else {
newValue -= step;
newValue = MathUtil.roundToNearest(newValue, step);
if (stepper.forceStep) {
newValue = MathUtil.roundToNearest(newValue, step);
}
}

if (min != null && newValue < min) {
1 change: 1 addition & 0 deletions haxe/ui/containers/properties/Property.hx
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ class Property extends HBox implements IDataComponent {
@:clonable @:behaviour(DefaultBehaviour, null) public var min:Null<Float>;
@:clonable @:behaviour(DefaultBehaviour, null) public var max:Null<Float>;
@:clonable @:behaviour(DefaultBehaviour, null) public var step:Null<Float>;
@:clonable @:behaviour(DefaultBehaviour, null) public var forceStep:Null<Bool>;
@:clonable @:behaviour(DefaultBehaviour, null) public var precision:Null<Int>;
@:behaviour(DataSourceBehaviour) public var dataSource:DataSource<Dynamic>;
}
3 changes: 3 additions & 0 deletions haxe/ui/containers/properties/PropertyEditor.hx
Original file line number Diff line number Diff line change
@@ -169,6 +169,9 @@ class PropertyEditorNumber extends PropertyEditor {
if (property.step != null) {
numberStepper.step = property.step;
}
if (property.forceStep != null) {
numberStepper.forceStep = property.forceStep;
}
if (property.precision != null) {
numberStepper.precision = property.precision;
}
3 changes: 3 additions & 0 deletions haxe/ui/containers/properties/PropertyGroup_OLD.hx
Original file line number Diff line number Diff line change
@@ -338,6 +338,9 @@ private class Builder extends CompositeBuilder {
if (property.step != null) {
stepper.step = property.step;
}
if (property.forceStep != null) {
stepper.forceStep = property.forceStep;
}
if (property.precision != null) {
stepper.precision = property.precision;
}
1 change: 1 addition & 0 deletions haxe/ui/containers/properties/Property_OLD.hx
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ class Property_OLD extends HBox implements IDataComponent {
@:behaviour(DataSourceBehaviour) public var dataSource:DataSource<Dynamic>;
@:clonable @:behaviour(PropertyValueBehaviour) public var value:Dynamic;
@:clonable @:behaviour(DefaultBehaviour) public var step:Null<Float>;
@:clonable @:behaviour(DefaultBehaviour) public var forceStep:Null<Bool>;
@:clonable @:behaviour(DefaultBehaviour) public var min:Null<Float>;
@:clonable @:behaviour(DefaultBehaviour) public var max:Null<Float>;
@:clonable @:behaviour(DefaultBehaviour) public var precision:Null<Int>;

0 comments on commit 9da6ce5

Please sign in to comment.