Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc fixes #460

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions haxe/ui/components/Label.hx
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ private class LabelLayout extends DefaultLayout {
component.getTextDisplay().width = component.getTextDisplay().textWidth;
}

//Extra space is needed to ensure the last line in multiline labels is visible.
var extraSpace:Int=(component.getTextDisplay().textField.numLines>1)?5:0;
if (component.autoHeight == true) {
component.getTextDisplay().height = component.getTextDisplay().textHeight;
component.getTextDisplay().height = component.getTextDisplay().textHeight+extraSpace;
} else {
component.getTextDisplay().height = component.height;
component.getTextDisplay().height = component.height+extraSpace;
}
}

Expand All @@ -103,7 +105,9 @@ private class LabelLayout extends DefaultLayout {
var size:Size = super.calcAutoSize(exclusions);
if (component.hasTextDisplay() == true) {
size.width += component.getTextDisplay().textWidth;
size.height += component.getTextDisplay().textHeight;
//Extra space is needed to ensure the last line in multiline labels is visible.
var extraSpace:Int=(component.getTextDisplay().textField.numLines>1)?5:0;
size.height += component.getTextDisplay().textHeight+extraSpace;
}
return size;
}
Expand Down
64 changes: 33 additions & 31 deletions haxe/ui/components/NumberStepper.hx
Original file line number Diff line number Diff line change
Expand Up @@ -79,39 +79,41 @@ class NumberStepper extends InteractiveComponent {
@:dox(hide) @:noCompletion
private class PosBehaviour extends DataBehaviour {
public override function validateData() {
var stepper = cast(_component, NumberStepper);
var preciseValue:Null<Float> = _value;
if (preciseValue == null) {
preciseValue = stepper.min;
}

preciseValue = MathUtil.clamp(preciseValue, stepper.min, stepper.max);
var wasRounded = false;
if (stepper.precision != null) {
var newPreciseValue = MathUtil.round(preciseValue, stepper.precision);
if (newPreciseValue != preciseValue) {
preciseValue = newPreciseValue;
wasRounded = true;
if (_value!=null) {
var stepper = cast(_component, NumberStepper);
var preciseValue:Null<Float> = _value;
if (preciseValue == null) {
preciseValue = stepper.min;
}

preciseValue = MathUtil.clamp(preciseValue, stepper.min, stepper.max);
var wasRounded = false;
if (stepper.precision != null) {
var newPreciseValue = MathUtil.round(preciseValue, stepper.precision);
if (newPreciseValue != preciseValue) {
preciseValue = newPreciseValue;
wasRounded = true;
}
}
_value = preciseValue;

var stringValue = StringUtil.padDecimal(preciseValue, stepper.precision);
var value:TextField = stepper.findComponent("value", TextField);
var carentIndex = value.caretIndex;
stringValue = StringTools.replace(stringValue, ",", ".");
stringValue = StringTools.replace(stringValue, ".", stepper.decimalSeparator);
value.text = stringValue;
if (wasRounded) {
value.caretIndex = stringValue.length;
} else {
value.caretIndex = carentIndex;
}

var event = new UIEvent(UIEvent.CHANGE);
event.previousValue = _previousValue;
event.value = _value;
_component.dispatch(event);
}
_value = preciseValue;

var stringValue = StringUtil.padDecimal(preciseValue, stepper.precision);
var value:TextField = stepper.findComponent("value", TextField);
var carentIndex = value.caretIndex;
stringValue = StringTools.replace(stringValue, ",", ".");
stringValue = StringTools.replace(stringValue, ".", stepper.decimalSeparator);
value.text = stringValue;
if (wasRounded) {
value.caretIndex = stringValue.length;
} else {
value.caretIndex = carentIndex;
}

var event = new UIEvent(UIEvent.CHANGE);
event.previousValue = _previousValue;
event.value = _value;
_component.dispatch(event);
}
}

Expand Down
14 changes: 8 additions & 6 deletions haxe/ui/components/Stepper.hx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ class Stepper extends VBox implements IValueComponent {
@:dox(hide) @:noCompletion
private class PosBehaviour extends DataBehaviour {
public override function validateData() {
var stepper:Stepper = cast(_component, Stepper);
var v:Float = MathUtil.clamp(_value, stepper.min, stepper.max);
stepper.pos = v;
_value = v;
var event = new UIEvent(UIEvent.CHANGE);
_component.dispatch(event);
if (_value!=null) {
var stepper:Stepper = cast(_component, Stepper);
var v:Float = MathUtil.clamp(_value, stepper.min, stepper.max);
stepper.pos = v;
_value = v;
var event = new UIEvent(UIEvent.CHANGE);
_component.dispatch(event);
}
}
}

Expand Down
22 changes: 12 additions & 10 deletions haxe/ui/containers/ScrollView.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1038,11 +1038,10 @@ class ScrollViewBuilder extends CompositeBuilder {
if (hscroll == null) {
hscroll = createHScroll();
}

hscroll.max = vcw - usableSize.width;
hscroll.pageSize = (usableSize.width / vcw) * hscroll.max;

hscroll.syncComponentValidation(); //avoid another pass
//Any action might cause a resize->might cause the child to modify size->might cause the hscroll to disappear
if (hscroll != null) hscroll.max = vcw - usableSize.width;
if (hscroll != null) hscroll.pageSize = (usableSize.width / vcw) * hscroll.max;
if (hscroll != null) hscroll.syncComponentValidation(); //avoid another pass
} else {
if (hscroll != null) {
destroyHScroll();
Expand All @@ -1054,15 +1053,18 @@ class ScrollViewBuilder extends CompositeBuilder {
var verticalConstraint = _contents;
var vscroll:VerticalScroll = _component.findComponent(VerticalScroll, false);
var vch:Float = verticalConstraint.height + verticalConstraintModifier();
//account for height of hscroll in case there is one
var hscroll:HorizontalScroll = _component.findComponent(HorizontalScroll, false);
if (hscroll!=null) vch-=hscroll.height;

if (vch > usableSize.height) {
if (vscroll == null) {
vscroll = createVScroll();
}

vscroll.max = vch - usableSize.height;
vscroll.pageSize = (usableSize.height / vch) * vscroll.max;

vscroll.syncComponentValidation(); //avoid another pass
//any action might cause a resize->might cause the child to modify size->might cause the vscroll to disappear
if (vscroll != null) vscroll.max = vch - usableSize.height;
if (vscroll != null) vscroll.pageSize = (usableSize.height / vch) * vscroll.max;
if (vscroll != null) vscroll.syncComponentValidation(); //avoid another pass
} else {
if (vscroll != null) {
destroyVScroll();
Expand Down
4 changes: 2 additions & 2 deletions haxe/ui/core/TextDisplay.hx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ class TextDisplay extends TextDisplayImpl implements IValidating {
if (_htmlText != null && _htmlText.length == 0) {
return 0;
}

if (isComponentInvalid() == true) {
validateComponent();
}
Expand All @@ -180,6 +179,7 @@ class TextDisplay extends TextDisplayImpl implements IValidating {

public var textHeight(get, null):Float;
private function get_textHeight():Float {
/* //empty labels should have same height as labels with text.
if (_text == null && _htmlText == null) {
return 0;
}
Expand All @@ -190,7 +190,7 @@ class TextDisplay extends TextDisplayImpl implements IValidating {

if (_htmlText != null && _htmlText.length == 0) {
return 0;
}
}*/

if (isComponentInvalid() == true) {
validateComponent();
Expand Down