Skip to content

Commit

Permalink
update names
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed Apr 4, 2024
1 parent 5137057 commit c84a6e2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
54 changes: 28 additions & 26 deletions src/FancyButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export type ButtonOptions = ViewsInput & {
offset?: Offset;
textOffset?: Offset;
iconOffset?: Offset;
textScale?: Pos | number;
iconScale?: Pos | number;
defaultTextScale?: Pos | number;
defaultIconScale?: Pos | number;
animations?: StateAnimations;
nineSlicePlane?: [number, number, number, number];
ignoreRefitting?: boolean;
Expand Down Expand Up @@ -140,10 +140,10 @@ export class FancyButton extends ButtonContainer
anchor: ObservablePoint;

/** Base text scaling to take into account when fitting inside the button */
protected _textBaseScale: Pos = { x: 1, y: 1 };
protected _defaultTextScale: Pos = { x: 1, y: 1 };

/** Base icon scaling to take into account when fitting inside the button */
protected _iconBaseScale: Pos = { x: 1, y: 1 };
protected _defaultIconScale: Pos = { x: 1, y: 1 };

/**
* Creates a button with a lot of tweaks.
Expand All @@ -161,6 +161,8 @@ export class FancyButton extends ButtonContainer
* @param {Point} options.iconOffset - Offset of the icon view.
* @param {number} options.scale - Scale of the button. Scale will be applied to a main container,
* when all animations scales will be applied to the inner view.
* @param {number} options.defaultTextScale - Base text scaling to take into account when fitting inside the button.
* @param {number} options.defaultIconScale - Base icon scaling to take into account when fitting inside the button.
* @param {number} options.anchor - Anchor point of the button.
* @param {number} options.anchorX - Horizontal anchor point of the button.
* @param {number} options.anchorY - Vertical anchor point of the button.
Expand All @@ -182,8 +184,8 @@ export class FancyButton extends ButtonContainer
offset,
textOffset,
iconOffset,
textScale,
iconScale,
defaultTextScale: textScale,
defaultIconScale: iconScale,
scale,
anchor,
anchorX,
Expand All @@ -201,8 +203,8 @@ export class FancyButton extends ButtonContainer
this.offset = offset;
this.textOffset = textOffset;
this.iconOffset = iconOffset;
this.textBaseScale = textScale;
this.iconBaseScale = iconScale;
this.defaultTextScale = textScale;
this.defaultIconScale = iconScale;
this.scale.set(scale ?? 1);

if (animations)
Expand Down Expand Up @@ -313,11 +315,11 @@ export class FancyButton extends ButtonContainer
this._views.textView = getTextView(text);

// If text scale has not manually been set, we will overwrite the base scale with the new text view scale.
if (this.options?.textScale === undefined)
if (this.options?.defaultTextScale === undefined)
{
const { x, y } = this._views.textView.scale;

this._textBaseScale = { x, y };
this._defaultTextScale = { x, y };
}

this._views.textView.anchor.set(0);
Expand Down Expand Up @@ -397,7 +399,7 @@ export class FancyButton extends ButtonContainer
{
if (!this.options?.ignoreRefitting)
{
this._views.textView.scale.set(this._textBaseScale.x, this._textBaseScale.y);
this._views.textView.scale.set(this._defaultTextScale.x, this._defaultTextScale.y);
}

fitToView(activeView, this._views.textView, this.padding, false);
Expand Down Expand Up @@ -431,7 +433,7 @@ export class FancyButton extends ButtonContainer

if (!this.options?.ignoreRefitting)
{
this._views.iconView.scale.set(this._iconBaseScale.x, this._iconBaseScale.y);
this._views.iconView.scale.set(this._defaultIconScale.x, this._defaultIconScale.y);
}

fitToView(activeView, this._views.iconView, this.padding, false);
Expand Down Expand Up @@ -660,11 +662,11 @@ export class FancyButton extends ButtonContainer
this._views.iconView = getView(view);

// If icon scale has not manually been set, we will overwrite the base scale with the new icon view scale.
if (this.options?.iconScale === undefined)
if (this.options?.defaultIconScale === undefined)
{
const { x, y } = this._views.iconView.scale;

this._iconBaseScale = { x, y };
this._defaultIconScale = { x, y };
}

if (!this._views.iconView.parent)
Expand Down Expand Up @@ -839,44 +841,44 @@ export class FancyButton extends ButtonContainer
* Sets the base scale for the text view to take into account when fitting inside the button.
* @param {Pos | number} scale - base scale of the text view.
*/
set textBaseScale(scale: Pos | number)
set defaultTextScale(scale: Pos | number)
{
if (scale === undefined) return;
// Apply to the options so that the manual scale is prioritized.
this.options.textScale = scale;
this.options.defaultTextScale = scale;
const isNumber = typeof scale === 'number';

this._textBaseScale.x = isNumber ? scale : scale.x ?? 1;
this._textBaseScale.y = isNumber ? scale : scale.y ?? 1;
this._defaultTextScale.x = isNumber ? scale : scale.x ?? 1;
this._defaultTextScale.y = isNumber ? scale : scale.y ?? 1;
this.adjustTextView(this.state);
}

/** Returns the text view base scale. */
get textBaseScale(): Pos
get defaultTextScale(): Pos
{
return this.textBaseScale;
return this.defaultTextScale;
}

/**
* Sets the base scale for the icon view to take into account when fitting inside the button.
* @param {Pos | number} scale - base scale of the icon view.
*/
set iconBaseScale(scale: Pos | number)
set defaultIconScale(scale: Pos | number)
{
if (scale === undefined) return;
// Apply to the options so that the manual scale is prioritized.
this.options.iconScale = scale;
this.options.defaultIconScale = scale;
const isNumber = typeof scale === 'number';

this._iconBaseScale.x = isNumber ? scale : scale.x ?? 1;
this._iconBaseScale.y = isNumber ? scale : scale.y ?? 1;
this._defaultIconScale.x = isNumber ? scale : scale.x ?? 1;
this._defaultIconScale.y = isNumber ? scale : scale.y ?? 1;
this.adjustIconView(this.state);
}

/** Returns the icon view base scale. */
get iconBaseScale(): Pos
get defaultIconScale(): Pos
{
return this.iconBaseScale;
return this.defaultIconScale;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const DynamicUpdate = ({
let icon = avatars[0];

button.iconView = Sprite.from(icon);
button.iconBaseScale = 0.2;
button.defaultIconScale = 0.2;
button.iconOffset = { x: -100, y: -7 };

button.textView = new Text(text, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const UseNineSlicePlane = ({
padding,
textOffset: { x: 30, y: -5 },
iconOffset: { x: -100, y: -7 },
iconScale: 0.2,
defaultIconScale: 0.2,
animations: {
hover: {
props: {
Expand Down

0 comments on commit c84a6e2

Please sign in to comment.