haxeui / haxeui-openfl

The OpenFL backend of the HaxeUI framework -
http://haxeui.org
MIT License
42 stars 14 forks source link

Stepper max value ( With correction) #54

Open Shallowmallow opened 3 years ago

Shallowmallow commented 3 years ago

On Haxe-ui openfl linux target

If you don't put a max value

The max is considered a 0.

Expected Behavior

If you don't put a max value <number-stepper pos="30" step="10" width ="30%" /> The max should be considered an infinite

Current Behavior

If you don't put a max value <number-stepper pos="30" step="10" width ="30%" /> The max is considered a 0.

It's the same problem with minimums

Possible Solution

I haven't checked in detail yet, maybe I'll try in the next few days. But I suppose the problem is the null value public var min:Null; public var max:Null;

Maybe it is considered 0 in MathUtil.clamp https://github.com/haxeui/haxeui-core/blob/35db371129336a9b592c12997db55b2e4cbd333b/haxe/ui/util/MathUtil.hx#L15-L27

Shallowmallow commented 3 years ago

Ok found it.

For some reason, in this function _stepper.max is equal to 0.

https://github.com/haxeui/haxeui-core/blob/35db371129336a9b592c12997db55b2e4cbd333b/haxe/ui/components/NumberStepper.hx#L265-L274

instead use var step:Stepper = _component.findComponent("stepper-step", Stepper); and replace _stepper.min and _stepper.max with step.min and steo.max


    private function onTextFieldFocusOut(event:FocusEvent) {
        _stepper.removeClass(":active");
        var textfield:TextField = _stepper.findComponent("stepper-textfield", TextField);
    var step:Stepper = _stepper.findComponent("stepper-step", Stepper);
        if (textfield != null) {
            _stepper.pos = MathUtil.clamp(Std.parseFloat(textfield.text), step.min, step.max);
            textfield.text = Std.string(_stepper.pos);
        } else {
            event.cancel();
        }
    }