pikers interconnected

This commit is contained in:
Luis Fernando Molina committed 2020-04-27 22:27:57 +02:00
1 parent 5e51a49468
commit 91c39b30ae
3 files changed
+155 -11

No files matched your search

+37 -4
View File
@@ -5,6 +5,8 @@ function newPicker () {
let thisObject = {
container: undefined,
selectedItem: 0,
onParentChanged: onParentChanged,
getSelected: getSelected,
physics: physics,
drawBackground: drawBackground,
drawForeground: drawForeground,
@@ -21,11 +23,13 @@ function newPicker () {
thisObject.container.frame.radius = 0
thisObject.container.frame.position.x = 0
thisObject.container.frame.position.y = 0
thisObject.container.frame.width = 50
thisObject.container.frame.width = 250
thisObject.container.frame.height = 200
let optionsList
let parent
let selected = 0
let lastSelected = 0
let onMouseWheelEventSubscriptionId
return thisObject
@@ -35,13 +39,31 @@ function newPicker () {
thisObject.container.finalize()
thisObject.container = undefined
optionsList = undefined
parent = undefined
}
function initialize (pOptionsList) {
function initialize (pOptionsList, pParent) {
optionsList = pOptionsList
parent = pParent
onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel)
}
function onParentChanged (event) {
if (event.parent !== undefined) {
parent = event.parent
}
selected = 0
let parentKeys = Object.keys(parent)
optionsList = Object.keys(parent[parentKeys[event.selected]])
event = {
selected: selected,
parent: parent[parentKeys[event.selected]]
}
thisObject.container.eventHandler.raiseEvent('onParentChanged', event)
}
function getContainer (point) {
let container
@@ -50,6 +72,10 @@ function newPicker () {
}
}
function getSelected () {
return optionsList[selected]
}
function onMouseWheel () {
delta = event.wheelDelta
if (delta > 0) {
@@ -63,6 +89,14 @@ function newPicker () {
if (selected > optionsList.length - 1) {
selected = optionsList.length - 1
}
if (selected !== lastSelected) {
let event = {
selected: selected
}
thisObject.container.eventHandler.raiseEvent('onParentChanged', event)
lastSelected = selected
}
}
function physics () {
@@ -82,7 +116,7 @@ function newPicker () {
for (let i = 0; i < VISIBLE_LABELS; i++) {
let index = i - 2 + selected
let label = ''
if (index >= 0 && index < VISIBLE_LABELS) {
if (index >= 0 && index < optionsList.length) {
label = optionsList[index]
}
fontColor = UI_COLOR.WHITE
@@ -103,4 +137,3 @@ function newPicker () {
}
}
}