[view] fixes
This commit is contained in:
@@ -114,13 +114,6 @@ import haxework.view.theme.ITheme;
|
|||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToDo:
|
|
||||||
/*private function set_skin(value:ISkin<Dynamic>):ISkin<Dynamic> {
|
|
||||||
this.skin = value;
|
|
||||||
toRedraw();
|
|
||||||
return this.skin;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
private function set_visible(value:Bool):Bool {
|
private function set_visible(value:Bool):Bool {
|
||||||
if (visible != value) {
|
if (visible != value) {
|
||||||
visible = value;
|
visible = value;
|
||||||
@@ -150,11 +143,10 @@ import haxework.view.theme.ITheme;
|
|||||||
private function get_rect():Rectangle {
|
private function get_rect():Rectangle {
|
||||||
var x = this.x;
|
var x = this.x;
|
||||||
var y = this.y;
|
var y = this.y;
|
||||||
var parent = this.parent;
|
if (parent != null) {
|
||||||
while (parent != null) {
|
var rect = parent.rect;
|
||||||
x += parent.x;
|
x += rect.x;
|
||||||
y += parent.y;
|
y += rect.y;
|
||||||
parent = parent.parent;
|
|
||||||
}
|
}
|
||||||
return new Rectangle(x, y, width, height);
|
return new Rectangle(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,13 @@ class DataView<D, V:IView<Dynamic>> extends GroupView {
|
|||||||
public var factory(default, set):Factory<D, V>;
|
public var factory(default, set):Factory<D, V>;
|
||||||
public var onItemSelect(default, null):Signal3<Int, D, V> = new Signal3();
|
public var onItemSelect(default, null):Signal3<Int, D, V> = new Signal3();
|
||||||
public var onDataSelect(default, null):Signal<D> = new Signal();
|
public var onDataSelect(default, null):Signal<D> = new Signal();
|
||||||
public var dataViews(get, null):Array<V>;
|
public var dataViews(default, null):Array<V>;
|
||||||
|
|
||||||
private var objectIndexes:Map<DisplayObject, Int> = new Map();
|
private var objectIndexes:Map<DisplayObject, Int> = new Map();
|
||||||
|
|
||||||
public function new(?layout:ILayout) {
|
public function new(?layout:ILayout) {
|
||||||
super(layout != null ? layout : new VerticalLayout());
|
super(layout != null ? layout : new VerticalLayout());
|
||||||
|
dataViews = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_data(value:Array<D>):Array<D> {
|
private function set_data(value:Array<D>):Array<D> {
|
||||||
@@ -35,25 +36,22 @@ class DataView<D, V:IView<Dynamic>> extends GroupView {
|
|||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_dataViews():Array<V> {
|
|
||||||
return cast views;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function rebuild():Void {
|
private function rebuild():Void {
|
||||||
for (view in views) {
|
for (view in dataViews) {
|
||||||
view.content.removeEventListener(MouseEvent.CLICK, onItemClick);
|
view.content.removeEventListener(MouseEvent.CLICK, onItemClick);
|
||||||
}
|
}
|
||||||
objectIndexes = new Map();
|
objectIndexes = new Map();
|
||||||
views = cast Lambda.array(Lambda.mapi(data, factory));
|
dataViews = Lambda.array(Lambda.mapi(data, factory));
|
||||||
for (i in 0...views.length) {
|
views = cast dataViews;
|
||||||
objectIndexes[views[i].content] = i;
|
for (i in 0...dataViews.length) {
|
||||||
views[i].content.addEventListener(MouseEvent.CLICK, onItemClick);
|
objectIndexes[dataViews[i].content] = i;
|
||||||
|
dataViews[i].content.addEventListener(MouseEvent.CLICK, onItemClick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onItemClick(event:MouseEvent):Void {
|
private function onItemClick(event:MouseEvent):Void {
|
||||||
var index = objectIndexes[event.currentTarget];
|
var index = objectIndexes[event.currentTarget];
|
||||||
onDataSelect.emit(data[index]);
|
onDataSelect.emit(data[index]);
|
||||||
onItemSelect.emit(index, data[index], cast views[index]);
|
onItemSelect.emit(index, data[index], dataViews[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package haxework.view.group;
|
package haxework.view.group;
|
||||||
|
|
||||||
|
import flash.geom.Point;
|
||||||
|
import flash.events.TouchEvent;
|
||||||
|
import flash.geom.Rectangle;
|
||||||
import flash.display.DisplayObjectContainer;
|
import flash.display.DisplayObjectContainer;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import flash.events.MouseEvent;
|
import flash.events.MouseEvent;
|
||||||
@@ -94,7 +97,41 @@ class OverflowControl {
|
|||||||
overflowControlX.offsetSignal.connect(function(value) container.x = value);
|
overflowControlX.offsetSignal.connect(function(value) container.x = value);
|
||||||
overflowControlY = new OverflowControl(function() return scrollY);
|
overflowControlY = new OverflowControl(function() return scrollY);
|
||||||
overflowControlY.offsetSignal.connect(function(value) container.y = value);
|
overflowControlY.offsetSignal.connect(function(value) container.y = value);
|
||||||
content.addEventListener(MouseEvent.MOUSE_WHEEL, _onMouseWheelEvent);
|
content.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheelEvent);
|
||||||
|
content.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onMouseWheelEvent(event:MouseEvent):Void {
|
||||||
|
if (overflowY > 1) {
|
||||||
|
#if flash event.preventDefault(); #end
|
||||||
|
overflowControlY.offset += event.delta * 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var touchPoint:Point;
|
||||||
|
|
||||||
|
private function onTouchBegin(event:TouchEvent):Void {
|
||||||
|
if (overflowY > 1) {
|
||||||
|
touchPoint = new Point(event.stageX, event.stageY);
|
||||||
|
content.stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
||||||
|
content.stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onTouchMove(event:TouchEvent):Void {
|
||||||
|
if (overflowY > 1) {
|
||||||
|
overflowControlY.offset -= touchPoint.y - event.stageY;
|
||||||
|
}
|
||||||
|
if (overflowX > 1) {
|
||||||
|
overflowControlX.offset -= touchPoint.x - event.stageX;
|
||||||
|
}
|
||||||
|
touchPoint = new Point(event.stageX, event.stageY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onTouchEnd(event:TouchEvent):Void {
|
||||||
|
event.preventDefault();
|
||||||
|
content.stage.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
||||||
|
content.stage.removeEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_scrollX():HScrollBarView {
|
private function get_scrollX():HScrollBarView {
|
||||||
@@ -119,13 +156,6 @@ class OverflowControl {
|
|||||||
return scrollY;
|
return scrollY;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _onMouseWheelEvent(event:MouseEvent):Void {
|
|
||||||
if (overflowY > 1) {
|
|
||||||
#if flash event.preventDefault(); #end
|
|
||||||
overflowControlY.offset += event.delta * 15;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_overflowX(value:Float):Float {
|
public function set_overflowX(value:Float):Float {
|
||||||
return overflowX = overflowControlX.overflow = value;
|
return overflowX = overflowControlX.overflow = value;
|
||||||
}
|
}
|
||||||
@@ -196,16 +226,19 @@ class OverflowControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function removeAllViews():Void {
|
public function removeAllViews():Void {
|
||||||
/*if (views != null) while (views.length > 0) {
|
|
||||||
removeView(views[0]);
|
|
||||||
}*/
|
|
||||||
if (views != null) {
|
if (views != null) {
|
||||||
for (i in 0...views.length) {
|
for (view in views.slice(0)) {
|
||||||
var view = views[i];
|
|
||||||
if (view != scrollX && view != scrollY) {
|
if (view != scrollX && view != scrollY) {
|
||||||
removeView(view);
|
removeView(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override private function get_rect():Rectangle {
|
||||||
|
var result = super.get_rect();
|
||||||
|
result.x += overflowControlX.offset;
|
||||||
|
result.y += overflowControlY.offset;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,12 +37,12 @@ class DefaultLayout extends Layout {
|
|||||||
);
|
);
|
||||||
switch group.overflow.x {
|
switch group.overflow.x {
|
||||||
case SCROLL:
|
case SCROLL:
|
||||||
group.overflowX = width / group.width;
|
group.overflowX = width / (group.width - group.geometry.padding.horizontal);
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
switch group.overflow.y {
|
switch group.overflow.y {
|
||||||
case SCROLL:
|
case SCROLL:
|
||||||
group.overflowY = height / group.height;
|
group.overflowY = height / (group.height - group.geometry.padding.vertical);
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class TailLayout extends DefaultLayout {
|
|||||||
}
|
}
|
||||||
var w:Float = 0;
|
var w:Float = 0;
|
||||||
var size = group.size.toSize("group");
|
var size = group.size.toSize("group");
|
||||||
for (view in views) {
|
for (view in filterViews(group, views)) {
|
||||||
setViewWidth(group, view);
|
setViewWidth(group, view);
|
||||||
setViewHeight(group, view);
|
setViewHeight(group, view);
|
||||||
if (
|
if (
|
||||||
@@ -74,6 +74,6 @@ class TailLayout extends DefaultLayout {
|
|||||||
y += row.height + margin;
|
y += row.height + margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
group.setSize(w, h, "group");
|
setGroupSize(group, w, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class ListView<D> extends GroupView {
|
|||||||
items = [];
|
items = [];
|
||||||
itemsListeners = new Map<IListItemView<D>, MouseEvent -> Void>();
|
itemsListeners = new Map<IListItemView<D>, MouseEvent -> Void>();
|
||||||
selected = [];
|
selected = [];
|
||||||
content.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheelEvent);
|
content.addEventListener(MouseEvent.MOUSE_WHEEL, _onMouseWheelEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_scroll(value:ScrollBarView):ScrollBarView {
|
private function set_scroll(value:ScrollBarView):ScrollBarView {
|
||||||
@@ -121,7 +121,7 @@ class ListView<D> extends GroupView {
|
|||||||
offset = o;
|
offset = o;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onMouseWheelEvent(event:MouseEvent):Void {
|
private function _onMouseWheelEvent(event:MouseEvent):Void {
|
||||||
#if flash event.preventDefault(); #end
|
#if flash event.preventDefault(); #end
|
||||||
onMouseWheel(event.delta);
|
onMouseWheel(event.delta);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ import flash.display.Graphics;
|
|||||||
} else {
|
} else {
|
||||||
graphics.beginFill(0, 0);
|
graphics.beginFill(0, 0);
|
||||||
}
|
}
|
||||||
graphics.drawRect(0, 0, view.width, view.height);
|
var o = border.color != null ? border.thickness / 2 : 0;
|
||||||
|
graphics.drawRect(o, o, view.width - o * 2, view.height - o * 2);
|
||||||
graphics.lineStyle();
|
graphics.lineStyle();
|
||||||
graphics.endFill();
|
graphics.endFill();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,12 +127,14 @@ class Theme implements ITheme {
|
|||||||
"geometry.width" => SizeValue.fromFloat(10),
|
"geometry.width" => SizeValue.fromFloat(10),
|
||||||
"geometry.height" => SizeValue.fromString("100%"),
|
"geometry.height" => SizeValue.fromString("100%"),
|
||||||
"geometry.hAlign" => HAlign.RIGHT,
|
"geometry.hAlign" => HAlign.RIGHT,
|
||||||
|
"geometry.vAlign" => VAlign.TOP,
|
||||||
]));
|
]));
|
||||||
register(new Style("scroll.horizontal", [
|
register(new Style("scroll.horizontal", [
|
||||||
"skin.foreColor" => colors.light,
|
"skin.foreColor" => colors.light,
|
||||||
"skin.backColor" => colors.dark,
|
"skin.backColor" => colors.dark,
|
||||||
"geometry.width" => SizeValue.fromString("100%"),
|
"geometry.width" => SizeValue.fromString("100%"),
|
||||||
"geometry.height" => SizeValue.fromFloat(10),
|
"geometry.height" => SizeValue.fromFloat(10),
|
||||||
|
"geometry.hAlign" => HAlign.LEFT,
|
||||||
"geometry.vAlign" => VAlign.BOTTOM,
|
"geometry.vAlign" => VAlign.BOTTOM,
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user