Skip to content

Commit 9da6ce5

Browse files
committedJan 31, 2025
Merge branch 'master' of https://github.com/haxeui/haxeui-core
2 parents aae44f3 + 0fddeba commit 9da6ce5

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed
 

‎haxe/ui/components/NumberStepper.hx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class NumberStepper extends InteractiveComponent implements ICompositeInteractiv
5050
*/
5151
@:clonable @:behaviour(DefaultBehaviour, null) public var step:Null<Float>;
5252

53+
/**
54+
* If true, values that differ from the specified `step` will be marked as invalid.
55+
*/
56+
@:clonable @:behaviour(DefaultBehaviour, false) public var forceStep:Bool;
57+
5358
/**
5459
* The highest value this stepper can get to, even when set through code.
5560
*/
@@ -308,7 +313,7 @@ private class Events extends haxe.ui.events.Events {
308313
}
309314
var parsedValue = Std.parseFloat(value.text);
310315
parsedValue = MathUtil.clamp(parsedValue, _stepper.min, _stepper.max);
311-
if (_stepper.step != null && parsedValue % _stepper.step != 0) {
316+
if (_stepper.step != null && _stepper.forceStep && parsedValue % _stepper.step != 0) {
312317
parsedValue = MathUtil.roundToNearest(parsedValue, _stepper.step);
313318
}
314319

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

494-
if (step != null && MathUtil.fmodulo(parsedValue, step) != 0) {
499+
if (step != null && stepper.forceStep && MathUtil.fmodulo(parsedValue, step) != 0) {
495500
valid = false;
496501
parsedValue = MathUtil.roundToNearest(parsedValue, step);
497502
}
@@ -523,7 +528,9 @@ private class ValueHelper {
523528
}
524529
} else {
525530
newValue += step;
526-
newValue = MathUtil.roundToNearest(newValue, step);
531+
if (stepper.forceStep) {
532+
newValue = MathUtil.roundToNearest(newValue, step);
533+
}
527534
}
528535

529536
if (max != null && newValue > max) {
@@ -549,7 +556,9 @@ private class ValueHelper {
549556
}
550557
} else {
551558
newValue -= step;
552-
newValue = MathUtil.roundToNearest(newValue, step);
559+
if (stepper.forceStep) {
560+
newValue = MathUtil.roundToNearest(newValue, step);
561+
}
553562
}
554563

555564
if (min != null && newValue < min) {

‎haxe/ui/containers/properties/Property.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Property extends HBox implements IDataComponent {
1717
@:clonable @:behaviour(DefaultBehaviour, null) public var min:Null<Float>;
1818
@:clonable @:behaviour(DefaultBehaviour, null) public var max:Null<Float>;
1919
@:clonable @:behaviour(DefaultBehaviour, null) public var step:Null<Float>;
20+
@:clonable @:behaviour(DefaultBehaviour, null) public var forceStep:Null<Bool>;
2021
@:clonable @:behaviour(DefaultBehaviour, null) public var precision:Null<Int>;
2122
@:behaviour(DataSourceBehaviour) public var dataSource:DataSource<Dynamic>;
2223
}

‎haxe/ui/containers/properties/PropertyEditor.hx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ class PropertyEditorNumber extends PropertyEditor {
169169
if (property.step != null) {
170170
numberStepper.step = property.step;
171171
}
172+
if (property.forceStep != null) {
173+
numberStepper.forceStep = property.forceStep;
174+
}
172175
if (property.precision != null) {
173176
numberStepper.precision = property.precision;
174177
}

‎haxe/ui/containers/properties/PropertyGroup_OLD.hx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ private class Builder extends CompositeBuilder {
338338
if (property.step != null) {
339339
stepper.step = property.step;
340340
}
341+
if (property.forceStep != null) {
342+
stepper.forceStep = property.forceStep;
343+
}
341344
if (property.precision != null) {
342345
stepper.precision = property.precision;
343346
}

‎haxe/ui/containers/properties/Property_OLD.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Property_OLD extends HBox implements IDataComponent {
1818
@:behaviour(DataSourceBehaviour) public var dataSource:DataSource<Dynamic>;
1919
@:clonable @:behaviour(PropertyValueBehaviour) public var value:Dynamic;
2020
@:clonable @:behaviour(DefaultBehaviour) public var step:Null<Float>;
21+
@:clonable @:behaviour(DefaultBehaviour) public var forceStep:Null<Bool>;
2122
@:clonable @:behaviour(DefaultBehaviour) public var min:Null<Float>;
2223
@:clonable @:behaviour(DefaultBehaviour) public var max:Null<Float>;
2324
@:clonable @:behaviour(DefaultBehaviour) public var precision:Null<Int>;

0 commit comments

Comments
 (0)