Skip to content

Commit

Permalink
fix input mask
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberDex authored and CatchABus committed Dec 1, 2024
1 parent 03014ef commit a63da37
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 43 deletions.
89 changes: 48 additions & 41 deletions src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,37 +254,7 @@ export class Input extends Container
this.init();
}

if (this.inputMask)
{
this.inputField.mask = null;
this._cursor.mask = null;
this.inputMask.destroy();
}

if (this.options?.nineSlicePlane && typeof bg === 'string')
{
this.inputMask = new NineSlicePlane(Texture.from(bg), ...this.options.nineSlicePlane);
}
else
if (bg instanceof Sprite)
{
this.inputMask = new Sprite(bg.texture);
}
else
if (bg instanceof Graphics)
{
this.inputMask = bg.clone();
}
else
{
this.inputMask = getView(bg);
}

this.inputField.mask = this.inputMask;

this._cursor.mask = this.inputMask;

this.addChildAt(this.inputMask, 0);
this.createInputMask(bg);
}

get bg(): Container | string
Expand Down Expand Up @@ -612,11 +582,7 @@ export class Input extends Container
this._bg.width = width;
}

if (this.inputMask)
{
this.inputMask.width = width - this.paddingLeft - this.paddingRight;
this.inputMask.x = this.paddingLeft;
}
this.updateInputMaskSize();

this.align();
}
Expand Down Expand Up @@ -647,11 +613,7 @@ export class Input extends Container
this._bg.height = height;
}

if (this.inputMask)
{
this.inputMask.height = height - this.paddingTop - this.paddingBottom;
this.inputMask.y = this.paddingTop;
}
this.updateInputMaskSize();

this.align();
}
Expand All @@ -666,4 +628,49 @@ export class Input extends Container
{
return super.height;
}

protected createInputMask(bg: ViewType)
{
if (this.inputMask)
{
this.inputField.mask = null;
this._cursor.mask = null;
this.inputMask.destroy();
}

if (this.options?.nineSlicePlane && typeof bg === 'string')
{
this.inputMask = new NineSlicePlane(Texture.from(bg), ...this.options.nineSlicePlane);
}
else if (bg instanceof Sprite)
{
this.inputMask = new Sprite(bg.texture);
}
else if (bg instanceof Graphics)
{
this.inputMask = bg.clone();
}
else
{
this.inputMask = getView(bg);
}

this.inputField.mask = this.inputMask;

this._cursor.mask = this.inputMask;

this.updateInputMaskSize();

this.addChildAt(this.inputMask, 0);
}

protected updateInputMaskSize()
{
if (!this.inputMask || !this._bg) return;

this.inputMask.width = this._bg.width - this.paddingLeft - this.paddingRight;
this.inputMask.height = this._bg.height - this.paddingTop - this.paddingBottom;

this.inputMask.position.set(this.paddingLeft, this.paddingTop);
}
}
4 changes: 2 additions & 2 deletions src/stories/input/InputGraphics.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const args = {
radius: 11,
amount: 1,
paddingTop: 0,
paddingRight: 0,
paddingRight: 7,
paddingBottom: 0,
paddingLeft: 0,
paddingLeft: 7,
cleanOnFocus: true,
onChange: action('Change')
};
Expand Down

0 comments on commit a63da37

Please sign in to comment.