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

fix input mask #210

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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