Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberDex committed Nov 27, 2024
1 parent 9ce9e96 commit 1e86f4a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 72 deletions.
52 changes: 23 additions & 29 deletions src/FancyButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,35 +411,32 @@ export class FancyButton extends ButtonContainer {
const { x: anchorX, y: anchorY } = this._defaultTextAnchor;

if (activeView) {
if (!this.options?.ignoreRefitting) {
if (activeView)
{
if (!this.options.ignoreRefitting)
{
if (!this.options.ignoreRefitting) {
this._views.textView.scale.set(this._defaultTextScale.x, this._defaultTextScale.y);
}

if (this.contentFittingMode === 'default')
{
if (this.contentFittingMode === 'default') {
fitToView(activeView, this._views.textView, this.padding, false);
}

if (this.contentFittingMode === 'fill')
{
if (this.contentFittingMode === 'fill') {
// reset to base dimensions for calculations
this._views.textView.scale.set(1);

const availableWidth = activeView.width - (this.padding * 2);
const availableHeight = activeView.height - (this.padding * 2);
const availableWidth = activeView.width - this.padding * 2;
const availableHeight = activeView.height - this.padding * 2;
const targetScaleX = availableWidth / this._views.textView.width;
const targetScaleY = availableHeight / this._views.textView.height;
const scale = Math.min(targetScaleX, targetScaleY);

this._views.textView.scale.set(scale * this._defaultTextScale.x, scale * this._defaultTextScale.y);
this._views.textView.scale.set(
scale * this._defaultTextScale.x,
scale * this._defaultTextScale.y,
);
}

this._views.textView.x = activeView.x + (activeView.width / 2);
this._views.textView.y = activeView.y + (activeView.height / 2);
this._views.textView.x = activeView.x + activeView.width / 2;
this._views.textView.y = activeView.y + activeView.height / 2;
}

this._views.textView.anchor.set(anchorX, anchorY);
Expand All @@ -462,34 +459,33 @@ export class FancyButton extends ButtonContainer {
return;
}

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

if (this.contentFittingMode === 'default')
{
if (this.contentFittingMode === 'default') {
fitToView(activeView, this._views.iconView, this.padding, false);
}

if (this.contentFittingMode === 'fill')
{
if (this.contentFittingMode === 'fill') {
// reset to base dimensions for calculations
this._views.iconView.scale.set(1);

const availableWidth = activeView.width - (this.padding * 2);
const availableHeight = activeView.height - (this.padding * 2);
const availableWidth = activeView.width - this.padding * 2;
const availableHeight = activeView.height - this.padding * 2;
const targetScaleX = availableWidth / this._views.iconView.width;
const targetScaleY = availableHeight / this._views.iconView.height;
const scale = Math.min(targetScaleX, targetScaleY);

this._views.iconView.scale.set(scale * this._defaultIconScale.x, scale * this._defaultIconScale.y);
this._views.iconView.scale.set(
scale * this._defaultIconScale.x,
scale * this._defaultIconScale.y,
);
}

const { x: anchorX, y: anchorY } = this._defaultIconAnchor;

if ('anchor' in this._views.iconView)
{
if ('anchor' in this._views.iconView) {
(this._views.iconView.anchor as ObservablePoint).set(anchorX, anchorY);
} else {
this._views.iconView.pivot.set(
Expand Down Expand Up @@ -545,14 +541,12 @@ export class FancyButton extends ButtonContainer {
* Sets the fitting mode for the button's content.
* @param {ContentFittingMode} mode - fitting mode type.
*/
set contentFittingMode(mode: ContentFittingMode)
{
set contentFittingMode(mode: ContentFittingMode) {
this.options.contentFittingMode = mode;
}

/** Returns the fitting mode for the button's content, defaulting to 'default'. */
get contentFittingMode(): ContentFittingMode
{
get contentFittingMode(): ContentFittingMode {
return this.options.contentFittingMode ?? 'default';
}

Expand Down
7 changes: 4 additions & 3 deletions src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ export class Input extends Container {
this.options.textStyle = options.textStyle ?? defaultTextStyle;
this.options.TextClass = options.TextClass ?? Text;
const textStyle = { ...defaultTextStyle, ...options.textStyle };
const colorSource = Color.isColorLike(this.options.textStyle.fill) ? this.options.textStyle.fill : 0x000000;
const colorSource = Color.isColorLike(this.options.textStyle.fill)
? this.options.textStyle.fill
: 0x000000;

this.inputField = new this.options.TextClass({
text: '',
Expand Down Expand Up @@ -464,8 +466,7 @@ export class Input extends Container {
this._value = text;
this.inputField.text = this.secure ? SECURE_CHARACTER.repeat(textLength) : text;

if (textLength !== 0)
{
if (textLength !== 0) {
this.placeholder.visible = false;
} else {
this.placeholder.visible = !this.editing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const args = {
onPress: action('button was pressed! (tap or click!)'),
};

export const UseNineSliceSprite: StoryFn<typeof args & { contentFittingMode: 'default' | 'fill' | 'none' }> = (
export const UseNineSliceSprite: StoryFn<
typeof args & { contentFittingMode: 'default' | 'fill' | 'none' }
> = (
{
text,
textColor,
Expand Down
49 changes: 26 additions & 23 deletions src/stories/input/InputGraphics.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,32 @@ const args = {
onChange: action('Change'),
};

export const UseGraphics: StoryFn<typeof args & { align: 'center' | 'left' | 'right' }> = ({
text,
amount,
border,
textColor,
fontSize,
backgroundColor,
borderColor,
width,
height,
radius,
maxLength,
align,
placeholder,
secure,
paddingTop,
paddingRight,
paddingBottom,
paddingLeft,
onChange,
cleanOnFocus,
addMask
}, context) =>
export const UseGraphics: StoryFn<typeof args & { align: 'center' | 'left' | 'right' }> = (
{
text,
amount,
border,
textColor,
fontSize,
backgroundColor,
borderColor,
width,
height,
radius,
maxLength,
align,
placeholder,
secure,
paddingTop,
paddingRight,
paddingBottom,
paddingLeft,
onChange,
cleanOnFocus,
addMask,
},
context,
) =>
new PixiStory<typeof args>({
context,
init: (view) => {
Expand Down
35 changes: 19 additions & 16 deletions src/stories/input/InputSprite.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,25 @@ const args = {
onChange: action('Input'),
};

export const UseSprite: StoryFn<typeof args & { align: 'center' | 'left' | 'right' }> = ({
text,
amount,
paddingTop,
paddingRight,
paddingBottom,
paddingLeft,
textColor,
fontSize,
maxLength,
align,
placeholder,
secure,
addMask,
onChange
}, context) =>
export const UseSprite: StoryFn<typeof args & { align: 'center' | 'left' | 'right' }> = (
{
text,
amount,
paddingTop,
paddingRight,
paddingBottom,
paddingLeft,
textColor,
fontSize,
maxLength,
align,
placeholder,
secure,
addMask,
onChange,
},
context,
) =>
new PixiStory({
context,
init: (view) => {
Expand Down

0 comments on commit 1e86f4a

Please sign in to comment.