Skip to content

Commit

Permalink
toggle orientation button
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-swf committed Dec 8, 2021
1 parent 3790c0d commit e15cfff
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/core/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class Actions {
public static readonly TOGGLE_GUIDES = 'TOGGLE_GUIDES';
public static readonly TOGGLE_HIT_AREA = 'TOGGLE_HIT_AREA';
public static readonly TOGGLE_RESPONSIVE = 'TOGGLE_RESPONSIVE';
public static readonly TOGGLE_ORIENTATION = 'TOGGLE_ORIENTATION';
public static readonly TOGGLE_REF_IMAGE = 'TOGGLE_REF_IMAGE';
public static readonly TOGGLE_ALL_HIT_AREAS_SNAPSHOT = 'TOGGLE_ALL_HIT_AREAS_SNAPSHOT';
public static readonly TOGGLE_ENABLED = 'TOGGLE_ENABLED';
Expand Down
7 changes: 6 additions & 1 deletion src/core/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ class EditorClass {
id: Actions.TOGGLE_RESPONSIVE,
toggle: true,
label: 'responsive',
icon: 'fa-expand-arrows-alt',
icon: 'fa-tablet-alt',
},
{
id: Actions.TOGGLE_ORIENTATION,
label: 'orientation',
icon: 'fa-retweet',
},
{
id: Actions.TOGGLE_REF_IMAGE,
Expand Down
17 changes: 17 additions & 0 deletions src/core/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ export class Preferences {
this.save('responsive', value);
}

private _responsiveSize = { width: 450, height: 800 };

public get responsiveSize() { return this._responsiveSize; }

public set responsiveSize(value: { width: number, height: number }) {
value = value ?? { width: 450, height: 800 };
value.width = value.width > 0 ? value.width : 450;
value.height = value.height > 0 ? value.height : 800;
this._responsiveSize = value;
this.notifyListeners('responsiveSize', value);
this.save('responsiveSize', value);
}

// #endregion

public readonly onPreferenceChanged = new Phaser.Signal();
Expand All @@ -119,6 +132,10 @@ export class Preferences {
actions.setActionCommand(Actions.TOGGLE_GUIDES, () => this.guides = !this._guides, () => this._guides);
actions.setActionCommand(Actions.TOGGLE_HIT_AREA, () => this.hitArea = !this._hitArea, () => this._hitArea);
actions.setActionCommand(Actions.TOGGLE_RESPONSIVE, () => this.responsive = !this._responsive, () => this._responsive);
actions.setActionCommand(Actions.TOGGLE_ORIENTATION, () => {
const size = this._responsiveSize;
this.responsiveSize = { width: size.height, height: size.width };
});
actions.setActionCommand(
Actions.TOGGLE_ALL_HIT_AREAS_SNAPSHOT,
() => this.allHitAreasSnapshot = !this._allHitAreasSnapshot,
Expand Down
22 changes: 18 additions & 4 deletions src/editor-view/actions/actions-toolbar.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { ComponentTags } from 'component-tags';
import { Action, ActionHandler } from 'core/action-handler';
import { Actions } from 'core/actions';
import { Editor } from 'core/editor';
import { PreferenceKey } from 'core/preferences';
import { Widget } from 'editor-view/widget/widget';
import './actions-toolbar.scss';
import { ActionButton } from './button/action-button';

export class ActionsToolbar extends Widget {
private readonly _buttons: ActionButton[] = [];
private readonly buttons: ActionButton[] = [];
private orientationBtn: ActionButton;

public setupActions(actions: ActionHandler) {
this.createButton(actions.getAction(Actions.TOGGLE_ENABLED));
Expand All @@ -18,6 +21,8 @@ export class ActionsToolbar extends Widget {
this.createButton(actions.getAction(Actions.TOGGLE_ALL_HIT_AREAS_SNAPSHOT));
this.createSeparator();
this.createButton(actions.getAction(Actions.TOGGLE_RESPONSIVE));
this.orientationBtn = this.createButton(actions.getAction(Actions.TOGGLE_ORIENTATION));
this.createSeparator();
this.createButton(actions.getAction(Actions.ZOOM_OUT));
this.createButton(actions.getAction(Actions.ZOOM_IN));
this.createSeparator();
Expand All @@ -26,18 +31,27 @@ export class ActionsToolbar extends Widget {
this.createButton(actions.getAction(Actions.UNDO));
this.createSeparator();
this.createSpacer();

Editor.prefs.onPreferenceChanged.add(this.onPreferencesChanged, this);
this.onPreferencesChanged('responsive', Editor.prefs.responsive);
}

private onPreferencesChanged(key: PreferenceKey, value: any) {
if (key !== 'responsive') return;
this.orientationBtn.interactable = value === true;
}

public enable() { this._buttons.forEach(e => e.updateState()); }
public enable() { this.buttons.forEach(e => e.updateState()); }

public disable() { }

private createButton(action: Action) {
if (!action) return;
if (!action) return null;
const btn = document.createElement(ComponentTags.ActionButton) as ActionButton;
btn.setAction(action);
this.appendChild(btn);
this._buttons.push(btn);
this.buttons.push(btn);
return btn;
}

private createSeparator() {
Expand Down
11 changes: 8 additions & 3 deletions src/editor-view/actions/button/action-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ phred-action-button.button {
}
}

&:hover .tooltip {
opacity: 1;
transition: opacity 200ms 800ms;
}

&.selected {
background-color: lighten($primary-color, 10%);
color: $on-primary;
Expand All @@ -29,9 +34,9 @@ phred-action-button.button {
}
}

&:hover .tooltip {
opacity: 1;
transition: opacity 200ms 800ms;
&.disabled {
pointer-events: none;
opacity: 0.5;
}

.tooltip {
Expand Down
10 changes: 10 additions & 0 deletions src/editor-view/actions/button/action-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import './action-button.scss';
export class ActionButton extends HTMLElement {
private action: Action;

public set interactable(value: boolean) {
if (value) {
this.classList.remove('disabled');
return;
}
if (!this.classList.contains('disabled')) {
this.classList.add('disabled');
}
}

public setAction(action: Action) {
this.classList.add('button');
this.action = action;
Expand Down

0 comments on commit e15cfff

Please sign in to comment.