mirror of https://github.com/buggins/dlangui.git
fix hover tracking
This commit is contained in:
parent
01fcb4ba8c
commit
cb9b46719c
|
@ -2,24 +2,24 @@
|
||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
|
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
<item
|
<item
|
||||||
android:drawable="btn_default_small_normal_disable_focused"
|
android:drawable="btn_default_small_normal_disable_focused"
|
||||||
color_transform_add1="100,0,0,0"
|
color_transform_add1="0,0,0,0"
|
||||||
android:state_enabled="false"
|
android:state_enabled="false"
|
||||||
android:state_focused="true" />
|
android:state_focused="true" />
|
||||||
<item
|
<item
|
||||||
android:drawable="btn_default_small_normal_disable"
|
android:drawable="btn_default_small_normal_disable"
|
||||||
color_transform_add1="100,0,0,0"
|
color_transform_add1="0,0,0,0"
|
||||||
android:state_focused="true" />
|
android:state_focused="true" />
|
||||||
<item
|
<item
|
||||||
android:drawable="btn_default_small_pressed"
|
android:drawable="btn_default_small_pressed"
|
||||||
color_transform_add1="100,0,0,0"
|
color_transform_add1="0,0,0,0"
|
||||||
android:state_pressed="true" />
|
android:state_pressed="true" />
|
||||||
<item
|
<item
|
||||||
android:drawable="btn_default_small_selected"
|
android:drawable="btn_default_small_selected"
|
||||||
color_transform_add1="100,0,0,0"
|
color_transform_add1="0,0,0,0"
|
||||||
android:state_selected="true" />
|
android:state_selected="true" />
|
||||||
<item
|
<item
|
||||||
android:drawable="btn_default_small_normal_hover"
|
android:drawable="btn_default_small_normal_hover"
|
||||||
color_transform_add1="100,0,0,0"
|
color_transform_add1="0,0,0,0"
|
||||||
android:state_hovered="true" />
|
android:state_hovered="true" />
|
||||||
<item
|
<item
|
||||||
android:drawable="@null" />
|
android:drawable="@null" />
|
||||||
|
|
|
@ -123,7 +123,6 @@ class Window {
|
||||||
_mouseCaptureWidget = root;
|
_mouseCaptureWidget = root;
|
||||||
_mouseCaptureButtons = event.flags & (MouseFlag.LButton|MouseFlag.RButton|MouseFlag.MButton);
|
_mouseCaptureButtons = event.flags & (MouseFlag.LButton|MouseFlag.RButton|MouseFlag.MButton);
|
||||||
} else if (event.action == MouseAction.Move) {
|
} else if (event.action == MouseAction.Move) {
|
||||||
Log.d("Setting tracking widget");
|
|
||||||
addTracking(root);
|
addTracking(root);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -135,10 +134,15 @@ class Window {
|
||||||
//protected Widget _mouseTrackingWidget;
|
//protected Widget _mouseTrackingWidget;
|
||||||
protected Widget[] _mouseTrackingWidgets;
|
protected Widget[] _mouseTrackingWidgets;
|
||||||
private void addTracking(Widget w) {
|
private void addTracking(Widget w) {
|
||||||
foreach(widget; _mouseTrackingWidgets)
|
for(int i = 0; i < _mouseTrackingWidgets.length; i++)
|
||||||
if (widget is w)
|
if (w is _mouseTrackingWidgets[i])
|
||||||
return;
|
return;
|
||||||
|
//foreach(widget; _mouseTrackingWidgets)
|
||||||
|
// if (widget is w)
|
||||||
|
// return;
|
||||||
|
//Log.d("addTracking ", w.id, " items before: ", _mouseTrackingWidgets.length);
|
||||||
_mouseTrackingWidgets ~= w;
|
_mouseTrackingWidgets ~= w;
|
||||||
|
//Log.d("addTracking ", w.id, " items after: ", _mouseTrackingWidgets.length);
|
||||||
}
|
}
|
||||||
private bool checkRemoveTracking(MouseEvent event) {
|
private bool checkRemoveTracking(MouseEvent event) {
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
|
@ -146,7 +150,11 @@ class Window {
|
||||||
for(int i = _mouseTrackingWidgets.length - 1; i >=0; i--) {
|
for(int i = _mouseTrackingWidgets.length - 1; i >=0; i--) {
|
||||||
Widget w = _mouseTrackingWidgets[i];
|
Widget w = _mouseTrackingWidgets[i];
|
||||||
if (!_mainWidget.isChild(w)) {
|
if (!_mainWidget.isChild(w)) {
|
||||||
_mouseTrackingWidgets.remove(i);
|
// std.algorithm.remove does not work for me
|
||||||
|
//_mouseTrackingWidgets.remove(i);
|
||||||
|
for (int j = i; j < _mouseTrackingWidgets.length - 1; j++)
|
||||||
|
_mouseTrackingWidgets[j] = _mouseTrackingWidgets[j + 1];
|
||||||
|
_mouseTrackingWidgets.length--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!w.isPointInside(event.x, event.y)) {
|
if (!w.isPointInside(event.x, event.y)) {
|
||||||
|
@ -154,7 +162,14 @@ class Window {
|
||||||
MouseEvent leaveEvent = new MouseEvent(event);
|
MouseEvent leaveEvent = new MouseEvent(event);
|
||||||
leaveEvent.changeAction(MouseAction.Leave);
|
leaveEvent.changeAction(MouseAction.Leave);
|
||||||
res = w.onMouseEvent(leaveEvent) || res;
|
res = w.onMouseEvent(leaveEvent) || res;
|
||||||
_mouseTrackingWidgets.remove(i);
|
// std.algorithm.remove does not work for me
|
||||||
|
//Log.d("removeTracking ", w.id, " items before: ", _mouseTrackingWidgets.length);
|
||||||
|
//_mouseTrackingWidgets.remove(i);
|
||||||
|
//_mouseTrackingWidgets.length--;
|
||||||
|
for (int j = i; j < _mouseTrackingWidgets.length - 1; j++)
|
||||||
|
_mouseTrackingWidgets[j] = _mouseTrackingWidgets[j + 1];
|
||||||
|
_mouseTrackingWidgets.length--;
|
||||||
|
//Log.d("removeTracking ", w.id, " items after: ", _mouseTrackingWidgets.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -48,6 +48,7 @@ class MenuItemWidget : HorizontalLayout {
|
||||||
protected MenuItem _item;
|
protected MenuItem _item;
|
||||||
protected TextWidget _label;
|
protected TextWidget _label;
|
||||||
this(MenuItem item) {
|
this(MenuItem item) {
|
||||||
|
id="menuitem";
|
||||||
_item = item;
|
_item = item;
|
||||||
styleId = "MENU_ITEM";
|
styleId = "MENU_ITEM";
|
||||||
_label = new TextWidget("MENU_LABEL");
|
_label = new TextWidget("MENU_LABEL");
|
||||||
|
@ -65,10 +66,6 @@ class MainMenu : HorizontalLayout {
|
||||||
_item = item;
|
_item = item;
|
||||||
for (int i = 0; i < item.subitemCount; i++) {
|
for (int i = 0; i < item.subitemCount; i++) {
|
||||||
MenuItemWidget subitem = new MenuItemWidget(item.subitem(i));
|
MenuItemWidget subitem = new MenuItemWidget(item.subitem(i));
|
||||||
if (i == 1)
|
|
||||||
subitem.setState(State.Focused);
|
|
||||||
else if (i == 2)
|
|
||||||
subitem.setState(State.Pressed);
|
|
||||||
addChild(subitem);
|
addChild(subitem);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -665,10 +665,10 @@ Theme createDefaultTheme() {
|
||||||
//res.dumpStats();
|
//res.dumpStats();
|
||||||
|
|
||||||
Style mainMenu = res.createSubstyle("MAIN_MENU").backgroundColor(0xE0E0E0).layoutWidth(FILL_PARENT);
|
Style mainMenu = res.createSubstyle("MAIN_MENU").backgroundColor(0xE0E0E0).layoutWidth(FILL_PARENT);
|
||||||
Style menuItem = res.createSubstyle("MENU_ITEM").padding(Rect(4,2,4,2)).backgroundColor(0xE0E080) ;
|
Style menuItem = res.createSubstyle("MENU_ITEM").padding(Rect(4,2,4,2)); //.backgroundColor(0xE0E080) ;
|
||||||
menuItem.createState(State.Focused, State.Focused).backgroundColor(0x40C0C000);
|
menuItem.createState(State.Focused, State.Focused).backgroundColor(0x40C0C000);
|
||||||
menuItem.createState(State.Pressed, State.Pressed).backgroundColor(0x4080C000);
|
menuItem.createState(State.Pressed, State.Pressed).backgroundColor(0x4080C000);
|
||||||
menuItem.createState(State.Hovered, State.Hovered).backgroundColor(0x80E0E000);
|
menuItem.createState(State.Hovered, State.Hovered).backgroundColor(0x80FFFF00);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,7 +306,7 @@ class Widget {
|
||||||
|
|
||||||
/// process mouse event; return true if event is processed by widget.
|
/// process mouse event; return true if event is processed by widget.
|
||||||
bool onMouseEvent(MouseEvent event) {
|
bool onMouseEvent(MouseEvent event) {
|
||||||
//Log.d("onMouseEvent ", id, " ", event.action, " (", event.x, ",", event.y, ")");
|
Log.d("onMouseEvent ", id, " ", event.action, " (", event.x, ",", event.y, ")");
|
||||||
// support onClick
|
// support onClick
|
||||||
if (_onClickListener !is null) {
|
if (_onClickListener !is null) {
|
||||||
if (event.action == MouseAction.ButtonDown && event.button == MouseButton.Left) {
|
if (event.action == MouseAction.ButtonDown && event.button == MouseButton.Left) {
|
||||||
|
|
Loading…
Reference in New Issue