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

Fixes to Input and CheckBox when updating styles #101

Merged
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
7 changes: 7 additions & 0 deletions src/CheckBox.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Container } from '@pixi/display';

Check failure on line 1 in src/CheckBox.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type 'Text' is not assignable to parameter of type 'DisplayObject'.
import { TextStyle, ITextStyle, Text } from '@pixi/text';
import { Signal } from 'typed-signals';
import { Switcher } from './Switcher';
Expand Down Expand Up @@ -95,6 +95,9 @@
/** Setter, which sets a checkbox style settings. */
set style(style: CheckBoxStyle)
{
// Preserve checked state for the end of the method
const wasChecked = this.checked;

this._style = style;

const { unchecked, checked } = style;
Expand All @@ -110,6 +113,10 @@
this.label.x = uncheckedView.width + 10 + (style.textOffset?.x ?? 0);
this.label.y = ((uncheckedView.height - this.label.height) / 2) + (style.textOffset?.y ?? 0);
}

// Reset checked state
delete this._active;
this.checked = wasChecked;
}

/** Getter, which returns a checkbox style settings. */
Expand Down
40 changes: 32 additions & 8 deletions src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@

const defaultTextStyle = {
fill: 0x000000,
align: 'center'
align: 'center',
} as TextStyle;

this.options.textStyle = options.textStyle ?? defaultTextStyle;
Expand All @@ -147,7 +147,10 @@
this._cursor.height = this.inputField.height * 0.8;
this._cursor.alpha = 0;

this.placeholder = new Text(options.placeholder, textStyle ?? defaultTextStyle);
this.placeholder = new Text(
options.placeholder,
textStyle ?? defaultTextStyle
);
this.placeholder.visible = !!options.placeholder;

this.addChild(this.inputField, this.placeholder, this._cursor);
Expand All @@ -169,7 +172,10 @@
this._bg.cursor = 'text';
this._bg.interactive = true;

this.addChildAt(this._bg, 0);
if (!this._bg.parent)
{
this.addChildAt(this._bg, 0);
}

if (!this.inputField)
{
Expand Down Expand Up @@ -212,7 +218,10 @@
return;
}

if (this.options.maxLength && this.value.length >= this.options.maxLength)
if (
this.options.maxLength
&& this.value.length >= this.options.maxLength
)
{
return;
}
Expand Down Expand Up @@ -260,6 +269,11 @@
this.input.removeEventListener('blur', this.stopEditingBinding);
this.input.removeEventListener('keyup', this.onKeyUpBinding);

this._keyboard.oninput = (event) =>

Check warning on line 272 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

'event' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 272 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

'event' is defined but never used. Allowed unused args must match /^_/u
{
let value = this._keyboard.value;

Check warning on line 274 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 16 spaces but found 14

Check warning on line 274 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

'value' is assigned a value but never used

Check failure on line 274 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

'value' is never reassigned. Use 'const' instead

Check warning on line 274 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 16 spaces but found 14

Check warning on line 274 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

'value' is assigned a value but never used

Check failure on line 274 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

'value' is never reassigned. Use 'const' instead
}

Check warning on line 275 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

Missing semicolon

Check warning on line 275 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

Missing semicolon

Check warning on line 276 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed

Check warning on line 276 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
this.input?.blur();
this.input?.remove();
this.input = null;
Expand Down Expand Up @@ -356,11 +370,16 @@
const align = this.getAlign();

this.inputField.anchor.set(align, 0.5);
this.inputField.x = (this._bg.width * align) + (align === 1 ? -this.paddingRight : this.paddingLeft);
this.inputField.y = (this._bg.height / 2) + this.paddingTop - this.paddingBottom;
this.inputField.x
= (this._bg.width * align)
+ (align === 1 ? -this.paddingRight : this.paddingLeft);
this.inputField.y
= (this._bg.height / 2) + this.paddingTop - this.paddingBottom;

this.placeholder.anchor.set(align, 0.5);
this.placeholder.x = (this._bg.width * align) + (align === 1 ? -this.paddingRight : this.paddingLeft);
this.placeholder.x
= (this._bg.width * align)
+ (align === 1 ? -this.paddingRight : this.paddingLeft);
this.placeholder.y = this._bg.height / 2;

this._cursor.x = this.getCursorPosX();
Expand Down Expand Up @@ -471,7 +490,12 @@
// Return array of paddings [top, right, bottom, left]
get padding(): [number, number, number, number]
{
return [this.paddingTop, this.paddingRight, this.paddingBottom, this.paddingLeft];
return [
this.paddingTop,
this.paddingRight,
this.paddingBottom,
this.paddingLeft,
];
}

override destroy(options?: IDestroyOptions | boolean)
Expand Down
Loading