Skip to content

Commit

Permalink
fix: setSize not being overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed Aug 16, 2024
1 parent f71bf3c commit 2e862c7
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/DoubleSlider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Container, FederatedPointerEvent } from 'pixi.js';
import { Container, FederatedPointerEvent, Optional, Size } from 'pixi.js';
import { Signal } from 'typed-signals';
import { DoubleSliderOptions, SliderBase } from './SliderBase';

Expand Down Expand Up @@ -307,4 +307,12 @@ export class DoubleSlider extends SliderBase
{
return super.height;
}

override setSize(value: number | Optional<Size, 'height'>, height?: number): void
{
super.setSize(value, height);

this.updateSlider1();
this.updateSlider2();
}
}
33 changes: 32 additions & 1 deletion src/FancyButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fitToView } from './utils/helpers/fit';
import { AnyText, getTextView, PixiText } from './utils/helpers/text';
import { getView } from './utils/helpers/view';

import type { Sprite } from 'pixi.js';
import type { Optional, Size, Sprite } from 'pixi.js';

type State = 'default' | 'hover' | 'pressed' | 'disabled';
type Pos = { x?: number; y?: number };
Expand Down Expand Up @@ -1044,4 +1044,35 @@ export class FancyButton extends ButtonContainer
{
return super.height;
}

override setSize(value: number | Optional<Size, 'height'>, height?: number): void
{
if (this.options?.nineSliceSprite)
{
if (this._views.defaultView)
{
this._views.defaultView.setSize(value, height);
}
if (this._views.hoverView)
{
this._views.hoverView.setSize(value, height);
}
if (this._views.pressedView)
{
this._views.pressedView.setSize(value, height);
}
if (this._views.disabledView)
{
this._views.disabledView.setSize(value, height);
}

this.adjustTextView(this.state);
this.adjustIconView(this.state);
this.updateAnchor();
}
else
{
super.setSize(value, height);
}
}
}
38 changes: 38 additions & 0 deletions src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
Graphics,
isMobile,
NineSliceSprite,
Optional,
Size,
Sprite,
Text,
TextStyleOptions,
Expand Down Expand Up @@ -652,4 +654,40 @@ export class Input extends Container
{
return super.height;
}

override setSize(value: number | Optional<Size, 'height'>, height?: number): void
{
if (this.options?.nineSliceSprite)
{
if (this._bg)
{
this._bg.setSize(value, height);
}

if (this.inputMask)
{
if (typeof value === 'object')
{
height = value.height ?? value.width;
value = value.width;
}
else
{
height = height ?? value;
}

this.inputMask.setSize(
value - this.paddingLeft - this.paddingRight,
height - this.paddingTop - this.paddingBottom
);
this.inputMask.position.set(this.paddingLeft, this.paddingTop);
}

this.align();
}
else
{
super.setSize(value, height);
}
}
}
40 changes: 39 additions & 1 deletion src/ProgressBar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Container, Graphics, NineSliceSprite as PixiNineSliceSprite, Sprite, Texture } from 'pixi.js';
import { Container, Graphics, NineSliceSprite as PixiNineSliceSprite, Optional, Size, Sprite, Texture } from 'pixi.js';
import { getSpriteView } from './utils/helpers/view';

type FillPaddings = {
Expand Down Expand Up @@ -334,4 +334,42 @@ export class ProgressBar extends Container
{
return super.height;
}

override setSize(value: number | Optional<Size, 'height'>, height?: number): void
{
if (this.options?.nineSliceSprite)
{
if (this.bg)
{
this.bg.setSize(value, height);
}

if (this.fill)
{
if (typeof value === 'object')
{
height = value.height ?? value.width;
value = value.width;
}
else
{
height = height ?? value;
}

const topPadding = this.options.fillPaddings?.top ?? 0;
const bottomPadding = this.options.fillPaddings?.bottom ?? 0;
const leftPadding = this.options.fillPaddings?.left ?? 0;
const rightPadding = this.options.fillPaddings?.right ?? 0;

this.fill.setSize(value - leftPadding - rightPadding, height - topPadding - bottomPadding);
this.fillMask.setSize(value - leftPadding - rightPadding, height - topPadding - bottomPadding);
}

this.progress = this._progress;
}
else
{
super.setSize(value, height);
}
}
}
30 changes: 30 additions & 0 deletions src/ScrollBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {
FederatedPointerEvent,
Graphics,
isMobile,
Optional,
Point,
PointData,
Size,
Ticker,
} from 'pixi.js';
import { Signal } from 'typed-signals';
Expand Down Expand Up @@ -772,6 +774,34 @@ export class ScrollBox extends Container
this.scrollTop();
}

override setSize(value: number | Optional<Size, 'height'>, height?: number): void
{
if (typeof value === 'object')
{
height = value.height ?? value.width;
value = value.width;
}
else
{
height = height ?? value;
}

this.__width = value;
this.__height = height;
this._dimensionChanged = true;
this.resize();
this.scrollTop();
}

override getSize(out?: Size): Size
{
out = out || { width: 0, height: 0 };
out.width = this.__width;
out.height = this.__height;

return out;
}

/** Gets the current raw scroll position on the x-axis (Negated Value). */
get scrollX(): number
{
Expand Down
8 changes: 7 additions & 1 deletion src/Slider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Container, FederatedPointerEvent } from 'pixi.js';
import { Container, FederatedPointerEvent, Optional, Size } from 'pixi.js';
import { Signal } from 'typed-signals';
import { BaseSliderOptions, SliderBase } from './SliderBase';

Expand Down Expand Up @@ -191,4 +191,10 @@ export class Slider extends SliderBase
{
return super.height;
}

override setSize(value: number | Optional<Size, 'height'>, height?: number): void
{
super.setSize(value, height);
this.updateSlider();
}
}

0 comments on commit 2e862c7

Please sign in to comment.