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

Add boolean invertDirection to allow inverting the scrollbar navigati… #12867

Merged
merged 2 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion packages/dev/gui/src/2D/controls/sliders/imageScrollBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,22 @@ export class ImageScrollBar extends BaseSlider {
private _thumbHeight: number = 1;
private _barImageHeight: number = 1;
private _tempMeasure = new Measure(0, 0, 0, 0);
private _invertDirection = false;

/** Number of 90° rotation to apply on the images when in vertical mode */
@serialize()
public num90RotationInVerticalMode = 1;

/** Inverts the scrolling direction (default: false) */
@serialize()
public get invertDirection() {
return this._invertDirection;
}

public set invertDirection(invert: boolean) {
this._invertDirection = invert;
}

/**
* Gets or sets the image used to render the background for horizontal bar
*/
Expand Down Expand Up @@ -249,6 +260,8 @@ export class ImageScrollBar extends BaseSlider {
y = this._transformedPosition.y;
}

const sign = this._invertDirection ? -1 : 1;

if (this._first) {
this._first = false;
this._originX = x;
Expand Down Expand Up @@ -277,7 +290,7 @@ export class ImageScrollBar extends BaseSlider {
delta = (x - this._originX) / (this._currentMeasure.width - this._effectiveThumbThickness);
}

this.value += delta * (this.maximum - this.minimum);
this.value += sign * delta * (this.maximum - this.minimum);

this._originX = x;
this._originY = y;
Expand Down
15 changes: 14 additions & 1 deletion packages/dev/gui/src/2D/controls/sliders/scrollBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class ScrollBar extends BaseSlider {
private _background = "black";
private _borderColor = "white";
private _tempMeasure = new Measure(0, 0, 0, 0);
private _invertDirection = false;

/** Gets or sets border color */
@serialize()
Expand Down Expand Up @@ -44,6 +45,16 @@ export class ScrollBar extends BaseSlider {
this._markAsDirty();
}

/** Inverts the scrolling direction (default: false) */
@serialize()
public get invertDirection() {
return this._invertDirection;
}

public set invertDirection(invert: boolean) {
this._invertDirection = invert;
}

/**
* Creates a new Slider
* @param name defines the control name
Expand Down Expand Up @@ -115,6 +126,8 @@ export class ScrollBar extends BaseSlider {
y = this._transformedPosition.y;
}

const sign = this._invertDirection ? -1 : 1;

if (this._first) {
this._first = false;
this._originX = x;
Expand Down Expand Up @@ -143,7 +156,7 @@ export class ScrollBar extends BaseSlider {
delta = (x - this._originX) / (this._currentMeasure.width - this._effectiveThumbThickness);
}

this.value += delta * (this.maximum - this.minimum);
this.value += sign * delta * (this.maximum - this.minimum);

this._originX = x;
this._originY = y;
Expand Down