Skip to content

Commit

Permalink
add missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberDex committed Nov 27, 2024
1 parent 9c5a799 commit 6369942
Show file tree
Hide file tree
Showing 13 changed files with 723 additions and 944 deletions.
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 4,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100
}
61 changes: 22 additions & 39 deletions src/CheckBox.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Container, Text } from 'pixi.js';
import { Text } from 'pixi.js';
import { Signal } from 'typed-signals';
import { Switcher } from './Switcher';
import { cleanup } from './utils/helpers/cleanup';
import { PixiText, PixiTextClass, PixiTextStyle } from './utils/helpers/text';
import { getView } from './utils/helpers/view';
import { getView, type GetViewSettings } from './utils/helpers/view';

type CheckBoxStyle = {
checked: Container | string;
unchecked: Container | string;
checked: GetViewSettings;
unchecked: GetViewSettings;
text?: PixiTextStyle;
textOffset?: {
x?: number;
Expand All @@ -32,8 +32,7 @@ export type CheckBoxOptions = {
* }
* });
*/
export class CheckBox extends Switcher
{
export class CheckBox extends Switcher {

Check warning on line 35 in src/CheckBox.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
//* Text label */
labelText!: PixiText;

Expand All @@ -43,8 +42,7 @@ export class CheckBox extends Switcher
protected _style: CheckBoxStyle;
protected _textClass: PixiTextClass;

constructor(options: CheckBoxOptions)
{
constructor(options: CheckBoxOptions) {

Check warning on line 45 in src/CheckBox.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
super();

this._textClass = options.TextClass ?? Text;
Expand All @@ -63,8 +61,7 @@ export class CheckBox extends Switcher
this.onChange.connect(() => this.onCheck.emit(this.checked));
}

protected addLabel(text?: string, style?: PixiTextStyle)
{
protected addLabel(text?: string, style?: PixiTextStyle) {

Check warning on line 64 in src/CheckBox.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
if (!text) return;

this.labelText = new this._textClass({
Expand All @@ -79,10 +76,8 @@ export class CheckBox extends Switcher
}

/** Setter, which sets a checkbox text. */
set text(text: string)
{
if (!text)
{
set text(text: string) {

Check warning on line 79 in src/CheckBox.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
if (!text) {

Check warning on line 80 in src/CheckBox.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
cleanup(this.labelText);

return;
Expand All @@ -92,14 +87,12 @@ export class CheckBox extends Switcher
}

/** Getter, which returns a checkbox text. */
get text(): string | ''
{
get text(): string | '' {

Check warning on line 90 in src/CheckBox.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
return this.labelText?.text ?? '';
}

/** Setter, which sets a checkbox style settings. */
set style(style: CheckBoxStyle)
{
set style(style: CheckBoxStyle) {

Check warning on line 95 in src/CheckBox.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
// Preserve checked state for the end of the method
const wasChecked = this.checked;

Expand All @@ -112,58 +105,48 @@ export class CheckBox extends Switcher

this.views = [uncheckedView, checkedView];

if (wasChecked)
{
if (wasChecked) {

Check warning on line 108 in src/CheckBox.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
checkedView.visible = true;
this.active = 1;
}
else
{
} else {

Check warning on line 111 in src/CheckBox.ts

View workflow job for this annotation

GitHub Actions / build

Closing curly brace appears on the same line as the subsequent block

Check warning on line 111 in src/CheckBox.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
uncheckedView.visible = true;
}

if (this.labelText)
{
if (this.labelText) {
checkedView.visible = true;
this.active = 1;
if (style.text)
{
if (style.text) {
this.labelText.style = style.text;
}

this.labelText.x = uncheckedView.width + 10 + (style.textOffset?.x ?? 0);
this.labelText.y = ((uncheckedView.height - this.labelText.height) / 2) + (style.textOffset?.y ?? 0);
}
else
{
this.labelText.y =
(uncheckedView.height - this.labelText.height) / 2 + (style.textOffset?.y ?? 0);
} else {
uncheckedView.visible = true;
}
}

/** Getter, which returns a checkbox style settings. */
get style(): CheckBoxStyle
{
get style(): CheckBoxStyle {
return this._style;
}

/** Getter, which returns a checkbox state. */
get checked(): boolean
{
get checked(): boolean {
return this.active === 1;
}

/** Setter, which sets a checkbox state. */
set checked(checked: boolean)
{
set checked(checked: boolean) {
this.switch(checked ? 1 : 0);
}

/**
* Setter, that sets a checkbox state without emitting a signal.
* @param checked
*/
forceCheck(checked: boolean)
{
forceCheck(checked: boolean) {
this.forceSwitch(checked ? 1 : 0);
}
}
Loading

0 comments on commit 6369942

Please sign in to comment.