Created
March 7, 2013 18:41
-
-
Save pec1985/5110597 to your computer and use it in GitHub Desktop.
This is a simple slider with two knobs created with the help of the TiDraggable module. Tested on Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Ti.UI.createWindow({ | |
backgroundColor: '#DDD' | |
}); | |
var knobRight = TiDraggable.createView({ | |
center: { x: 30, y: 105 }, | |
width: 20, height: 20, | |
minLeft: 20, | |
maxLeft: 200, | |
backgroundColor: 'blue', | |
axis: 'x', | |
knob: 'right' | |
}); | |
var knobLeft = TiDraggable.createView({ | |
center: { x: 30, y: 105 }, | |
width: 20, height: 20, | |
minLeft: 20, | |
maxLeft: 200, | |
backgroundColor: 'red', | |
axis: 'x', | |
knob: 'left' | |
}); | |
var barView = Ti.UI.createView({ | |
left: 30, | |
right: 30, | |
height: 10, | |
top: 100, | |
borderColor: 'black', | |
borderWidth: 1 | |
}); | |
var fillView = Ti.UI.createView({ | |
left: 31, | |
// right: 31, | |
height: 8, | |
top: 101, | |
backgroundColor: 'green' | |
}); | |
win.add(barView); | |
win.add(fillView); | |
win.add(knobRight); | |
win.add(knobLeft); | |
function barViewPostLayout(_event) { | |
barView.removeEventListener('postlayout', barViewPostLayout); | |
var rect = _event.source.rect; | |
var x = rect.x + rect.width; | |
knobRight.center = { x: x, y: 105} ; | |
knobRight.maxLeft = x - (knobRight.width / 2); | |
fillView.left = knobLeft.center.x; | |
fillView.width = knobRight.center.x - knobLeft.center.x; | |
} | |
function onKnobMove(e) { | |
e.source.center = e.center; | |
knobRight.minLeft = knobLeft.center.x + (knobLeft.width / 2); | |
knobLeft.maxLeft = knobRight.center.x - knobRight.width - (knobRight.width / 2); | |
fillView.left = knobLeft.center.x; | |
fillView.width = knobRight.center.x - knobLeft.center.x; | |
} | |
knobLeft.addEventListener('move', onKnobMove); | |
knobRight.addEventListener('move', onKnobMove); | |
barView.addEventListener('postlayout', barViewPostLayout) | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment