Skip to content

Commit

Permalink
fix button
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberDex committed Oct 6, 2023
1 parent 05d0dfc commit 7a5f1a1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Button.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Sprite, Graphic } from "pixi.js";
import { Container } from 'pixi.js';
import { ButtonEvents } from './ButtonEvents';
import { Mixin } from 'ts-mixer';

Expand Down Expand Up @@ -105,7 +105,7 @@ export class ButtonContainer extends Mixin(Container, Button)
{
super();

this.view = this;
this._view = this;
this.enabled = true;

if (view)
Expand Down
8 changes: 3 additions & 5 deletions src/ButtonEvents.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { FederatedPointerEvent } from '@pixi/events';
import { isMobile, utils } from '@pixi/core';
import { FederatedPointerEvent, isMobile, Container } from 'pixi.js';
import { Signal } from 'typed-signals';
import { Container } from '@pixi/display';

/** Events controller used for {@link Button}. */
export class ButtonEvents
Expand Down Expand Up @@ -40,7 +38,7 @@ export class ButtonEvents

protected connectEvents(view: Container)
{
if (utils.isMobile.any)
if (isMobile.any)
{
view.on('pointerdown', this.processDown, this);
view.on('pointerup', this.processUp, this);
Expand All @@ -62,7 +60,7 @@ export class ButtonEvents

protected disconnectEvents(view: Container)
{
if (utils.isMobile.any)
if (isMobile.any)
{
view.off('pointerdown', this.processDown, this);
view.off('pointerup', this.processUp, this);
Expand Down
27 changes: 24 additions & 3 deletions src/tests/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Container, Text } from 'pixi.js';
import { Container, Graphics, Text } from 'pixi.js';
import { initPixi } from './utils/pixi';
import { Button } from '../Button';

// eslint-disable-next-line no-new
new class App
Expand Down Expand Up @@ -27,11 +28,18 @@ new class App
private addSubscriptions()
{
window.addEventListener('resize', () => this.resize());
window.addEventListener('deviceorientation', () => this.resize());
window.addEventListener('deviceorientation', () => this.resize(), true);
this.resize();
}

private createElements()
{
const button = this.createButton();

button.onPress.connect(() => console.log('onPress'));
}

private createButton(): Button
{
const text = new Text({ text: 'Pixi 8' });

Expand All @@ -41,7 +49,20 @@ new class App
fill: 0xffffff
};

this.view.addChild(text);
const graphics = new Graphics()
.roundRect(0, 0, text.width + 100, text.height + 20, 25)
.fill(0xde3249);

graphics.x = -graphics.width / 2;
graphics.y = -graphics.height / 2;

const buttonContainer = new Container();

buttonContainer.addChild(graphics, text);

this.view.addChild(buttonContainer);

return new Button(this.view);
}

private resize(width = window.innerWidth, height = window.innerHeight)
Expand Down
1 change: 1 addition & 0 deletions src/tests/utils/pixi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export async function initPixi(options?: Partial<ApplicationOptions>): Promise<A
await app.init({
resizeTo: window,
background: 0x000000,
antialias: true,
...options
});

Expand Down

0 comments on commit 7a5f1a1

Please sign in to comment.