Move UI logic to Stimulus: toolbar only
This commit is contained in:
50
js/controllers/toolbar_controller.js
Normal file
50
js/controllers/toolbar_controller.js
Normal file
@@ -0,0 +1,50 @@
|
||||
// Global ATON
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
import AppState from "../state.js";
|
||||
import { createLightSlider } from "../utils/environment.js";
|
||||
|
||||
const html = String.raw;
|
||||
const panelHeader = html`
|
||||
<i class="bi bi-gear-fill me-1"></i> Impostazioni
|
||||
`;
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ['settings'];
|
||||
|
||||
connect() {
|
||||
console.log('#toolbar controller connected');
|
||||
}
|
||||
/**
|
||||
* Open settings panel
|
||||
* @param {Event} event
|
||||
*/
|
||||
toggleSettings(event) {
|
||||
ATON.UI.setSidePanelLeft();
|
||||
ATON.UI.showSidePanel({header: panelHeader});
|
||||
this.#buildSettingsPanel(ATON.UI.elSidePanel);
|
||||
}
|
||||
/**
|
||||
* Clone a <template> by id
|
||||
* @param {String} id
|
||||
* @returns {DocumentFragment}
|
||||
*/
|
||||
#cloneTemplate(id) {
|
||||
return document.getElementById(id).content.cloneNode(true);
|
||||
}
|
||||
/**
|
||||
* Create the left-side settings panel
|
||||
* content
|
||||
* @param {Element} panel
|
||||
*/
|
||||
#buildSettingsPanel(panel) {
|
||||
const fragment = this.#cloneTemplate('tmpl-settings');
|
||||
let sliderContainer = fragment.querySelector('[data-sliders-container]');
|
||||
|
||||
['x', 'y', 'z'].forEach((axis, i) => {
|
||||
const label = ['Asse X', 'Asse Y', 'Asse Z'][i];
|
||||
sliderContainer.appendChild(createLightSlider(axis, label, [-2, 2], 0.1));
|
||||
})
|
||||
|
||||
panel.appendChild(fragment);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user