Skip to content

Commit

Permalink
tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-swf committed Dec 8, 2021
1 parent 7b015cd commit bd7adbf
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/component-tags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class ComponentTags {
// TODO remove the ones that doesn't need to be here
public static readonly EditorView = 'phred-editor-view';
public static readonly GameContainer = 'phred-game-container';
public static readonly ActionsToolbar = 'phred-actions-toolbar';
Expand Down
1 change: 0 additions & 1 deletion src/core/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ class EditorClass {
id: Actions.TOGGLE_ENABLED,
label: 'edit',
icon: 'fa-edit',
shortcuts: ['ctrl+F2'],
},

{
Expand Down
41 changes: 41 additions & 0 deletions src/editor-view/actions/button/action-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ phred-action-button.button {
min-width: 35px;
padding: 0;
box-shadow: none;
position: relative;

&:hover {
background-color: $primary-color;
Expand All @@ -27,4 +28,44 @@ phred-action-button.button {
background-color: lighten($primary-color, 10%);
}
}

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

.tooltip {
position: absolute;
top: 46px;
background-color: lighten($background-color, 2%);
color: $on-background;
padding: 4px 10px;
border-radius: 6px;
font-size: 14px;
text-align: center;
user-select: none;
pointer-events: none;
opacity: 0;
max-width: 150px;
box-sizing: border-box;
white-space: nowrap;
box-shadow: 0 2px 2px 2px $light-shadow-color;
transition: opacity 200ms 100ms;
z-index: 1;

&:before {
content: '';
position: absolute;
top: -4px;
left: 50%;
display: block;
width: 8px;
height: 8px;
background-color: lighten($background-color, 2%);
transform-origin: 4px 4px;
margin-left: -4px;
transform: rotateZ(45deg);
z-index: -1;
}
}
}
13 changes: 13 additions & 0 deletions src/editor-view/actions/button/action-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export class ActionButton extends HTMLElement {
public setAction(action: Action) {
this.classList.add('button');
this.action = action;
this.createTooltip(action);

if (action.icon) {
const icon = this.appendChild(document.createElement('i'));
icon.classList.add('fas', action.icon);
Expand All @@ -21,10 +23,21 @@ export class ActionButton extends HTMLElement {
this.onclick = () => action.command();
return;
}

this.onclick = this.toggleSelected.bind(this);
this.updateState();
}

private createTooltip(action: Action) {
const tooltip = this.appendChild(document.createElement('div'));
tooltip.classList.add('tooltip');
let text = action.label;
if (action.shortcuts?.length) {
text += ` (${action.shortcuts[0].replace('+Shift', '')})`;
}
tooltip.innerText = text;
}

private toggleSelected() {
this.action.command();
this.updateState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ phred-object-tree-inspector.phred-inspector {
&.filtering {
.content .node-children {
margin-left: 0;
display: flex;
}
.collapse-icon {
display: none;
Expand Down
1 change: 1 addition & 0 deletions src/editor-view/object-tree/model/object-tree-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class ObjectTreeModel {
filter = filter ? filter.toLowerCase() : '';
Object.keys(objects).forEach(k => {
const o = objects[k] as ObjectTreeNodeModel;
console.log(o.node?.title);
if (!o.node) return;
if (o.node.title.toLowerCase().indexOf(filter) >= 0) {
o.node.classList.remove('invisible');
Expand Down

0 comments on commit bd7adbf

Please sign in to comment.