Tweaks from concurrent project
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
import { Component } from /**/"./Component.js";
|
||||
let Toolkit;
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// DropDown //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Text entry field
|
||||
class DropDown extends Component {
|
||||
static Component = Component;
|
||||
|
||||
///////////////////////// Initialization Methods //////////////////////////
|
||||
|
||||
constructor(gui, options) {
|
||||
super(gui, options, {
|
||||
className: "tk tk-dropdown",
|
||||
tagName : "select"
|
||||
});
|
||||
|
||||
// Configure instance fields
|
||||
this.isEnabled = null;
|
||||
this.options = [];
|
||||
|
||||
// Configure component
|
||||
options = options || {};
|
||||
this.setEnabled(!("enabled" in options) || options.enabled);
|
||||
if ("options" in options)
|
||||
this.setOptions(options.options);
|
||||
this.setSelectedIndex(
|
||||
("selectedIndex" in options ? options : this).selectedIndex);
|
||||
|
||||
// Configure event handlers
|
||||
this.addEventListener("keydown" , e=>e.stopPropagation());
|
||||
this.addEventListener("pointerdown", e=>e.stopPropagation());
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////// Public Methods //////////////////////////////
|
||||
|
||||
// Programmatically change the selection
|
||||
change() {
|
||||
this.element.dispatchEvent(this.event("input"));
|
||||
}
|
||||
|
||||
// Retrieve the current selection index
|
||||
getSelectedIndex() {
|
||||
return this.element.selectedIndex;
|
||||
}
|
||||
|
||||
// Specify whether the button can be activated
|
||||
setEnabled(enabled) {
|
||||
this.isEnabled = enabled = !!enabled;
|
||||
this.setAttribute("disabled", enabled ? null : "true");
|
||||
}
|
||||
|
||||
// Specify the list contents
|
||||
setOptions(options) {
|
||||
|
||||
// Error checking
|
||||
if (!Array.isArray(options))
|
||||
return;
|
||||
|
||||
// Erase the list of options
|
||||
this.options.splice(0);
|
||||
this.element.replaceChildren();
|
||||
|
||||
// Add options from the input
|
||||
for (let option of options) {
|
||||
if (typeof option != "string")
|
||||
continue;
|
||||
this.options.push(option);
|
||||
this.element.add(document.createElement("option"));
|
||||
}
|
||||
|
||||
// Update the display text
|
||||
this.translate();
|
||||
}
|
||||
|
||||
// Specify the current selection
|
||||
setSelectedIndex(index) {
|
||||
|
||||
// Error checking
|
||||
if (typeof index != "number" || isNaN(index))
|
||||
return this.element.selectedIndex;
|
||||
index = Math.round(index);
|
||||
if (index < -1 || index >= this.options.length)
|
||||
return this.element.selectedIndex;
|
||||
|
||||
// Configure element and instance fields
|
||||
return this.element.selectedIndex = index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////// Package Methods /////////////////////////////
|
||||
|
||||
// Update the global Toolkit object
|
||||
static setToolkit(toolkit) {
|
||||
Toolkit = toolkit;
|
||||
}
|
||||
|
||||
// Regenerate localized display text
|
||||
translate() {
|
||||
super.translate();
|
||||
|
||||
// Error checking
|
||||
if (!this.options)
|
||||
return;
|
||||
|
||||
// Update the list items
|
||||
for (let x = 0; x < this.options.length; x++) {
|
||||
this.element.item(x).innerText =
|
||||
this.gui.translate(this.options[x], this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
export { DropDown };
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Component } from /**/"./Component.js";
|
||||
import { Button, CheckBox, Group, Radio } from /**/"./Button.js" ;
|
||||
import { DropDown } from /**/"./DropDown.js" ;
|
||||
import { Menu, MenuBar, MenuItem, MenuSeparator } from /**/"./MenuBar.js" ;
|
||||
import { ScrollBar, ScrollPane, SplitPane } from /**/"./ScrollBar.js";
|
||||
import { TextBox } from /**/"./TextBox.js" ;
|
||||
@@ -26,6 +27,7 @@ let Toolkit = globalThis.Toolkit = (class GUI extends Component {
|
||||
this.components = [];
|
||||
Button .setToolkit(this); this.components.push(Button .Component);
|
||||
Component.setToolkit(this); this.components.push( Component);
|
||||
DropDown .setToolkit(this); this.components.push(DropDown .Component);
|
||||
MenuBar .setToolkit(this); this.components.push(MenuBar .Component);
|
||||
ScrollBar.setToolkit(this); this.components.push(ScrollBar.Component);
|
||||
TextBox .setToolkit(this); this.components.push(TextBox .Component);
|
||||
@@ -34,6 +36,7 @@ let Toolkit = globalThis.Toolkit = (class GUI extends Component {
|
||||
this.CheckBox = CheckBox;
|
||||
this.Component = Component;
|
||||
this.Desktop = Desktop;
|
||||
this.DropDown = DropDown;
|
||||
this.Group = Group;
|
||||
this.Menu = Menu;
|
||||
this.MenuBar = MenuBar;
|
||||
|
||||
Reference in New Issue
Block a user