Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Minor ui enhancements.

  • Loading branch information...
commit ddc8e4a710701d2c2749f10d38644474fb434045 1 parent 2b03ddc
@back2dos authored
View
46 src/tink/ui/controls/Button.hx
@@ -73,8 +73,8 @@ class ButtonStyle implements Style, implements Cls {
this.container = container;
this.label = label;
container.paddingLeft = container.paddingRight = container.paddingTop = container.paddingBottom = 5;
- normal.up = Skin.Draw(Plain(0xE8E8E8, 1), Plain(0, .25));
- normal.over = Skin.Draw(Plain(0xF0F0F0, 1), Plain(0, .25));
+ normal.up = Skin.Draw(Plain(0xE0E0E0, 1), Plain(0, .25));
+ normal.over = Skin.Draw(Plain(0xE8E8E8, 1), Plain(0, .25));
normal.down = Skin.Draw(Plain(0xF0F0F0, 1), Plain(0, .25));
normal.disabled = Skin.Draw(Plain(0xE8E8E8, 1), Plain(0, .5));
//function rect(index) return new Rectangle(0, 22 * index, 100, 22);
@@ -90,24 +90,56 @@ class ButtonStyle implements Style, implements Cls {
}
//static var TEXTURE = new MyFile();
}
-
+class FlashBehavior {
+ static public function wire(s:Sprite, click, down, drag, up, setState) {
+ s.addEventListener(MouseEvent.CLICK, function (e:MouseEvent) click.fire( { x:s.mouseX, y:s.mouseY } ));
+ s.addEventListener(MouseEvent.ROLL_OVER, function (e:MouseEvent) if (!e.buttonDown) setState(Over));
+ s.addEventListener(MouseEvent.ROLL_OUT, function (e:MouseEvent) if (!e.buttonDown) setState(Up));
+ s.addEventListener(MouseEvent.MOUSE_DOWN, function (e:MouseEvent) {
+ var stage = s.stage;
+ var x0 = stage.mouseX,
+ y0 = stage.mouseY;
+ function handleDrag(_) {
+ drag.fire( { dx: stage.mouseX - x0, dy: stage.mouseY - y0 } );
+ x0 = stage.mouseX;
+ y0 = stage.mouseY;
+ }
+ down.fire( { x:s.mouseX, y:s.mouseY } );
+ stage.addEventListener(MouseEvent.MOUSE_MOVE, handleDrag);
+ function handleUp(e) {
+ stage.removeEventListener(MouseEvent.MOUSE_MOVE, handleDrag);
+ stage.removeEventListener(MouseEvent.MOUSE_UP, handleUp);
+ var inside = s.hitTestPoint(stage.mouseX, stage.mouseY);
+ setState(inside ? Over : Up);
+ up.fire( { x:s.mouseX, y:s.mouseY, inside: inside } );
+ }
+ stage.addEventListener(MouseEvent.MOUSE_UP, handleUp);
+ setState(Down);
+ });
+ s.buttonMode = true;
+ s.mouseChildren = false;
+ }
+}
class Button extends UIComponent<Sprite, ButtonStyle>, implements Cls {
var label = new Label();
var container = new UIContainer();
@:prop(updateCaption(param)) var caption:String;
+
@:bindable var enabled = true;
@:bindable var selected = false;
@:bindable private var state = Up;
+ @:signal var click:{ x:Float, y:Float };
+ @:signal var down:{ x:Float, y:Float };
+ @:signal var drag:{ dx:Float, dy:Float };
+ @:signal var up:{ x:Float, y:Float, inside:Bool };
+
public function new() {
var s = cast(container.getView(), Sprite);
super(s, new ButtonStyle(container.style, label.style));
- s.addEventListener(MouseEvent.ROLL_OVER, function (e) state = e.buttonDown ? Down : Over);
- s.addEventListener(MouseEvent.ROLL_OUT, function (_) state = Up);
- s.addEventListener(MouseEvent.MOUSE_DOWN, function (_) state = Down);
- s.addEventListener(MouseEvent.MOUSE_UP, function (_) state = Over);
+ FlashBehavior.wire(s, _click, _down, _drag, _up, set_state);
bindSkin();
}
View
17 src/tink/ui/controls/ScrollBar.hx
@@ -85,6 +85,8 @@ class ScrollBar extends UIComponent<Sprite, ScrollBarStyle>, implements Cls {
style.track.down = Skin.Draw(Plain(0xB8B8B8, 1), Plain(0, .25));
style.track.disabled = Skin.Draw(Plain(0xB0B0B0, 1), Empty);
+ wireSignals();
+
var thumbStyle = thumb.style;
var self = this;
@@ -93,6 +95,21 @@ class ScrollBar extends UIComponent<Sprite, ScrollBarStyle>, implements Cls {
thumbStyle.hAlign.bindExpr(self.position);
thumbStyle.vAlign.bindExpr(self.position);
}
+ function wireSignals() {
+ function normalize(x:Float, y:Float)
+ return
+ if (style.horizontal) x / (track.getView().width - thumb.getView().width);
+ else y / (track.getView().height - thumb.getView().height);
+ function sign(x:Float)
+ return x > 0 ? 1 : -1;
+
+ thumb.drag.watch(function (p) {
+ position += normalize(p.dx, p.dy);
+ });
+ track.down.watch(function (p) {
+ position += percentage * sign(normalize(p.x, p.y) - position);
+ });
+ }
override function getMetrics()
return container.getMetrics()
View
2  src/tink/ui/text/Input.hx
@@ -48,10 +48,8 @@ class Input extends UIComponent<Sprite, InputStyle> {
public function new() {
super(new Sprite(), new InputStyle());
view.addChild(tf);
- //tf.background = true;
tf.multiline = false;
tf.type = TextFieldType.INPUT;
- //tf.defaultTextFormat = new TextFormat('_sans', 12);
tf.addEventListener(Event.CHANGE, function (_) {
bindings.fire('text');
});
Please sign in to comment.
Something went wrong with that request. Please try again.