Skip to content

Commit

Permalink
feature(Widgets): add show and hide methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mgermerie authored and gchoqueux committed Mar 16, 2022
1 parent 9bd81ce commit 59ac32c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/config.json
Expand Up @@ -128,6 +128,7 @@
],

"Widgets": [
"Widget",
"Navigation",
"Minimap",
"Scale",
Expand Down
2 changes: 2 additions & 0 deletions utils/gui/Minimap.js
Expand Up @@ -18,6 +18,8 @@ const DEFAULT_OPTIONS = {
/**
* A widget for minimap
*
* @extends Widget
*
* @property {HTMLElement} domElement An html div containing the minimap.
* @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
*/
Expand Down
2 changes: 2 additions & 0 deletions utils/gui/Navigation.js
Expand Up @@ -16,6 +16,8 @@ const DEFAULT_OPTIONS = {
/**
* A widget menu manager for navigation.
*
* @extends Widget
*
* @property {HTMLElement} domElement An html div containing all navigation widgets.
* @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
* @property {Object} onClick An object containing methods which are executed when clicking one of the
Expand Down
2 changes: 2 additions & 0 deletions utils/gui/Scale.js
Expand Up @@ -15,6 +15,8 @@ const DEFAULT_OPTIONS = {
/**
* A widget for scale
*
* @extends Widget
*
* @property {HTMLElement} domElement An html div containing the scale.
* @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
*/
Expand Down
2 changes: 2 additions & 0 deletions utils/gui/Searchbar.js
Expand Up @@ -45,6 +45,8 @@ function eraseSuggestionList(form) {
/**
* A widget for searchbar
*
* @extends Widget
*
* @property {HTMLElement} domElement An html div containing the searchbar.
* @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
*/
Expand Down
22 changes: 22 additions & 0 deletions utils/gui/Widget.js
@@ -1,4 +1,11 @@
/**
* An interface that stores common methods for all specific widgets.
*
* @hideconstructor
*/
class Widget {
#_display;

constructor(view, options = {}, defaultOptions) {
this.parentElement = options.parentElement || view.domElement;

Expand Down Expand Up @@ -58,6 +65,21 @@ class Widget {
this.domElement.addEventListener('pointerdown', (e) => { e.stopPropagation(); });
this.domElement.addEventListener('mousedown', (e) => { e.stopPropagation(); });
}

/**
* Change the widget style `display` property so that the widget becomes visible.
*/
show() {
this.domElement.style.display = this.#_display;
}

/**
* Change the widget style `display` property so that the widget becomes invisible.
*/
hide() {
this.#_display = window.getComputedStyle(this.domElement).display;
this.domElement.style.display = 'none';
}
}


Expand Down

0 comments on commit 59ac32c

Please sign in to comment.