Skip to content

Commit

Permalink
Add toggle-fullscreen control with temp icons.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocaccamo committed Aug 30, 2023
1 parent 066ab41 commit 148605b
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/fontra/client/images/fullscreen-enter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/fontra/client/images/fullscreen-exit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/fontra/views/editor/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ body {
transform: scale(1.1, 1.1);
}

.tool-icon--hidden {
display: none;
}

.tool-button:hover {
background-color: var(--editor-tool-button-hover-background-color);
}
Expand Down
10 changes: 10 additions & 0 deletions src/fontra/views/editor/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
<div class="tool-button" data-tool="zoom-fit-selection">
<inline-svg class="tool-icon" src="/images/bullseye.svg"></inline-svg>
</div>
<div class="tool-button" data-tool="toggle-fullscreen">
<inline-svg
class="tool-icon tool-icon--fullscreen-enter tool-icon--hidden"
src="/images/fullscreen-enter.svg"
></inline-svg>
<inline-svg
class="tool-icon tool-icon--fullscreen-exit tool-icon--hidden"
src="/images/fullscreen-exit.svg"
></inline-svg>
</div>
</div>
</div>
</div>
Expand Down
49 changes: 49 additions & 0 deletions src/fontra/views/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,19 @@ export class EditorController {
case "zoom-fit-selection":
this.zoomFit();
break;
case "toggle-fullscreen":
this.toggleFullscreen();
break;
}
this.canvasController.canvas.focus();
};
}

// init fullscreen button
this.updateFullscreenButton();
document.addEventListener("fullscreenchange", () => {
this.updateFullscreenButton();
});
}

addEditTool(tool) {
Expand Down Expand Up @@ -1574,6 +1583,46 @@ export class EditorController {
this.sceneController.autoViewBox = false;
}

toggleFullscreen() {
if (document.fullscreenElement) {
if (document.exitFullscreen) {
document.exitFullscreen();
}
} else {
const element = document.documentElement;
if (element.requestFullscreen) {
element.requestFullscreen();
}
}
}

updateFullscreenButton() {
// hide button in case fullscreen is not enabled on device
const fullscreenButtonEl = document.querySelector(
".tool-button[data-tool='toggle-fullscreen']"
);
if (!document.fullscreenEnabled) {
fullscreenButtonEl.style.display = "none";
return;
}
// fullscreen is enabled, show the right icon depending on the fullscreen state
const fullscreenEnterIconEl = fullscreenButtonEl.querySelector(
".tool-icon--fullscreen-enter"
);
const fullscreenExitIconEl = fullscreenButtonEl.querySelector(
".tool-icon--fullscreen-exit"
);
if (document.fullscreenElement) {
// fullscreen state is on, display exit-fullscreen button icon
fullscreenEnterIconEl.classList.add("tool-icon--hidden");
fullscreenExitIconEl.classList.remove("tool-icon--hidden");
} else {
// fullscreen state is off, display enter-fullscreen button icon
fullscreenEnterIconEl.classList.remove("tool-icon--hidden");
fullscreenExitIconEl.classList.add("tool-icon--hidden");
}
}

animateToViewBox(viewBox) {
const startViewBox = this.sceneSettings.viewBox;
const deltaViewBox = subItemwise(viewBox, startViewBox);
Expand Down

0 comments on commit 148605b

Please sign in to comment.