picker implemented

This commit is contained in:
Luis Fernando Molina committed 2020-04-27 15:13:48 +02:00
1 parent 76ae07e3ab
commit 5e51a49468
2 files changed
+62 -11

No files matched your search

+14 -7
View File
@@ -49,6 +49,8 @@ function newConditionEditor () {
}
function deactivate () {
finalizePickers()
if (thisObject.visible === true) {
thisObject.visible = false
}
@@ -64,7 +66,7 @@ function newConditionEditor () {
thisObject.payload.uiObject.setErrorMessage('', 0)
scanDataMines()
setUpPickers()
initializePickers()
EDITOR_ON_FOCUS = true
}
@@ -121,7 +123,7 @@ function newConditionEditor () {
operatorB.selector = JSON.parse(JSON.stringify(selector))
}
function setUpPickers () {
function initializePickers () {
operatorA.dataMinePicker = newPicker()
operatorA.dataMinePicker.container.connectToParent(thisObject.container)
operatorA.dataMinePicker.container.frame.position.x = 0 - operatorA.dataMinePicker.container.frame.width / 2
@@ -129,14 +131,19 @@ function newConditionEditor () {
operatorA.dataMinePicker.initialize(Object.keys(operatorA.selector))
}
function finalizePickers () {
if (operatorA.dataMinePicker !== undefined) {
operatorA.dataMinePicker.finalize()
operatorA.dataMinePicker = undefined
}
}
function getContainer (point) {
let container
if (thisObject.visible === true) {
if (point.x === VERY_LARGE_NUMBER) {
/* The the mouse leaves the canvas, and event of mouse over with a ridiculous coordinate is triggered so that
anyone can react. In our case, the code editor has a text area that is not part of the canvas, so the event is
triggered. We compensate recognizing this coordinate and returning our container. */
return thisObject.container
if (operatorA.dataMinePicker !== undefined) {
container = operatorA.dataMinePicker.getContainer(point)
if (container !== undefined) { return container }
}
if (thisObject.container.frame.isThisPointHere(point, true, false) === true) {
+48 -4
View File
@@ -17,16 +17,21 @@ function newPicker () {
thisObject.container.initialize(MODULE_NAME)
thisObject.container.isClickeable = false
thisObject.container.isDraggeable = false
thisObject.container.isWheelable = true
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.height = 100
thisObject.container.frame.height = 200
let optionsList
let selected = 0
let onMouseWheelEventSubscriptionId
return thisObject
function finalize () {
thisObject.container.eventHandler.stopListening(onMouseWheelEventSubscriptionId)
thisObject.container.finalize()
thisObject.container = undefined
optionsList = undefined
@@ -34,6 +39,7 @@ function newPicker () {
function initialize (pOptionsList) {
optionsList = pOptionsList
onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel)
}
function getContainer (point) {
@@ -44,6 +50,21 @@ function newPicker () {
}
}
function onMouseWheel () {
delta = event.wheelDelta
if (delta > 0) {
delta = -1
} else {
delta = 1
}
selected = selected + delta
if (selected < 0) { selected = 0 }
if (selected > optionsList.length - 1) {
selected = optionsList.length - 1
}
}
function physics () {
}
@@ -53,10 +74,33 @@ function newPicker () {
}
function drawForeground () {
const FONT_SIZE = 15
const FONT_SIZE = 25
const VISIBLE_LABELS = 5
let fontSize
let fontColor
for (let i = 0; i < optionsList.length; i++) {
drawLabel(optionsList[i], 1 / 2, i / optionsList.length, 0, 0, FONT_SIZE, thisObject.container, UI_COLOR.WHITE, undefined, undefined)
for (let i = 0; i < VISIBLE_LABELS; i++) {
let index = i - 2 + selected
let label = ''
if (index >= 0 && index < VISIBLE_LABELS) {
label = optionsList[index]
}
fontColor = UI_COLOR.WHITE
switch (i) {
case 0: fontSize = FONT_SIZE - 15
break
case 1: fontSize = FONT_SIZE - 8
break
case 2: fontSize = FONT_SIZE - 0
fontColor = UI_COLOR.BLACK
break
case 3: fontSize = FONT_SIZE - 8
break
case 4: fontSize = FONT_SIZE - 15
break
}
drawLabel(label, 1 / 2, i / VISIBLE_LABELS, 0, 0, fontSize, thisObject.container, fontColor, undefined, undefined)
}
}
}