Skip to content

Commit

Permalink
Merge branch 'master' into feature/component-consolidation
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Dec 26, 2023
2 parents 3d3ed85 + 1afb2a5 commit 5bf7682
Show file tree
Hide file tree
Showing 15 changed files with 183 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ var main = Toolkit.componentFromString('<vbox><button text="Button" /></vbox>',
Screen.instance.addComponent(main);
```

## Addtional resources
## Additional resources
* <a href="http://haxeui.org/explorer/">component-explorer</a> - Browse HaxeUI components
* <a href="http://haxeui.org/builder/">playground</a> - Write and test HaxeUI layouts in your browser
* <a href="https://github.com/haxeui/component-examples">component-examples</a> - Various componet examples
Expand Down
1 change: 1 addition & 0 deletions haxe/ui/_module/locale/en/form-strings.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
form.field.required=Field is required
4 changes: 4 additions & 0 deletions haxe/ui/_module/locale/en/messagebox-strings.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
messagebox.title.info=Info
messagebox.title.question=Question
messagebox.title.warning=Warning
messagebox.title.error=Error
1 change: 1 addition & 0 deletions haxe/ui/_module/locale/pt/form-strings.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
form.field.required=Campo obrigatório
4 changes: 4 additions & 0 deletions haxe/ui/_module/locale/pt/messagebox-strings.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
messagebox.title.info=Informação
messagebox.title.question=Pergunta
messagebox.title.warning=Aviso
messagebox.title.error=Erro
2 changes: 1 addition & 1 deletion haxe/ui/components/Button.hx
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private class IconBehaviour extends DataBehaviour {
private override function validateData() {
var icon:Image = _component.findComponent("button-icon", false);

if ((_value == null || _value.isNull) && icon != null) {
if ((_value == null || _value.isNull || _value == "") && icon != null) {
_component.customStyle.icon = null;
_component.removeComponent(icon);
return;
Expand Down
2 changes: 1 addition & 1 deletion haxe/ui/components/Image.hx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private class ResourceBehaviour extends DataBehaviour {
private var _canvasMap:Map<String, Canvas> = null; // we'll want to cache any canvases used so we dont cloneComponent over and ove again

private override function validateData() {
if (_value == null || _value.isNull) {
if (_value == null || _value.isNull || _value == "") {
_component.removeImageDisplay();
_component.invalidateComponent();
return;
Expand Down
50 changes: 39 additions & 11 deletions haxe/ui/components/Slider.hx
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,19 @@ private class MinBehaviour extends DataBehaviour {
if (range == null) {
return;
}
if (cast(_component, Slider).start == null) {
var slider = cast(_component, Slider);
if (slider.start == null) {
range.start = _value;
}
range.min = _value;
if (slider.minorTicks != null) {
--slider.minorTicks;
++slider.minorTicks;
}
if (slider.majorTicks != null) {
--slider.majorTicks;
++slider.majorTicks;
}
_component.invalidateComponentLayout();
}
}
Expand All @@ -231,7 +240,16 @@ private class MaxBehaviour extends DataBehaviour {
if (range == null) {
return;
}
var slider = cast(_component, Slider);
range.max = _value;
if (slider.minorTicks != null) {
--slider.minorTicks;
++slider.minorTicks;
}
if (slider.majorTicks != null) {
--slider.majorTicks;
++slider.majorTicks;
}
_component.invalidateComponentLayout();
}
}
Expand Down Expand Up @@ -288,17 +306,22 @@ private class MinorTicks extends DataBehaviour {
if (_value != null && _value.isNull == false) {
var slider:Slider = cast(_component, Slider);
var ticks = slider.findComponents("minor-tick", 1);
if (ticks == null || ticks.length == 0) {
var m:Float = slider.max - slider.min;
var v:Float = _value;
var n:Int = Std.int(m / v);
var v:Float = _value;
var m:Float = slider.max - slider.min;
var n:Int = Std.int(m / v) + 1;
if (ticks == null || ticks.length != n) {
var index = slider.getComponentIndex(slider.findComponent(Range));
for (_ in 0...n + 1) {
var addN = Std.int(n - ticks.length);
for (_ in 0...addN) {
var tick = new Component();
tick.addClass("minor-tick");
tick.scriptAccess = false;
slider.addComponentAt(tick, index + 1);
}
var removeN = Std.int(ticks.length - n);
for (_ in 0...removeN) {
slider.removeComponentAt(index + 1);
}
}
} else {
}
Expand All @@ -310,17 +333,22 @@ private class MajorTicks extends DataBehaviour {
if (_value != null && _value.isNull == false) {
var slider:Slider = cast(_component, Slider);
var ticks = slider.findComponents("major-tick", 1);
if (ticks == null || ticks.length == 0) {
var m:Float = slider.max - slider.min;
var v:Float = _value;
var n:Int = Std.int(m / v);
var v:Float = _value;
var m:Float = slider.max - slider.min;
var n:Int = Std.int(m / v) + 1;
if (ticks == null || ticks.length != n) {
var index = slider.getComponentIndex(slider.findComponent(Range));
for (_ in 0...n + 1) {
var addN = Std.int(n - ticks.length);
for (_ in 0...addN) {
var tick = new Component();
tick.addClass("major-tick");
tick.scriptAccess = false;
slider.addComponentAt(tick, index + 1);
}
var removeN = Std.int(ticks.length - n);
for (_ in 0...removeN) {
slider.removeComponentAt(index + 1);
}
}
} else {
}
Expand Down
91 changes: 81 additions & 10 deletions haxe/ui/containers/TableView.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package haxe.ui.containers;

import haxe.ui.actions.ActionType;
import haxe.ui.behaviours.Behaviour;
import haxe.ui.behaviours.DataBehaviour;
import haxe.ui.behaviours.DefaultBehaviour;
Expand All @@ -17,6 +18,7 @@ import haxe.ui.core.ItemRenderer;
import haxe.ui.data.ArrayDataSource;
import haxe.ui.data.DataSource;
import haxe.ui.data.transformation.NativeTypeTransformer;
import haxe.ui.events.ActionEvent;
import haxe.ui.events.ItemEvent;
import haxe.ui.events.MouseEvent;
import haxe.ui.events.ScrollEvent;
Expand Down Expand Up @@ -200,6 +202,7 @@ private class Events extends ScrollViewEvents {
}

private function onRendererMouseDown(e:MouseEvent) {
_tableview.focus = true;
switch (_tableview.selectionMode) {
case SelectionMode.MULTIPLE_LONG_PRESS:
if (_tableview.selectedIndices.length == 0) {
Expand Down Expand Up @@ -342,6 +345,42 @@ private class Events extends ScrollViewEvents {
private function selectRange(fromIndex:Int, toIndex:Int) {
_tableview.selectedIndices = [for (i in fromIndex...toIndex + 1) i];
}

private override function onActionStart(event:ActionEvent) {
switch (event.action) {
case ActionType.DOWN:
if (_tableview.selectedIndex < 0) {
_tableview.selectedIndex = 0;
} else {
var n:Int = _tableview.selectedIndex;
n++;
if (n > _tableview.dataSource.size - 1) {
n = 0;
}
_tableview.selectedIndex = n;
}
event.repeater = true;
case ActionType.UP:
if (_tableview.selectedIndex < 0) {
_tableview.selectedIndex = _tableview.dataSource.size - 1;
} else {
var n:Int = _tableview.selectedIndex;
n--;
if (n < 0) {
n = _tableview.selectedIndex = _tableview.dataSource.size - 1;
}
_tableview.selectedIndex = n;
}
event.repeater = true;
case ActionType.LEFT:
_scrollview.hscrollPos -= 10;
event.repeater = true;
case ActionType.RIGHT:
_scrollview.hscrollPos += 10;
event.repeater = true;
case _:
}
}
}

//***********************************************************************************************************
Expand Down Expand Up @@ -527,6 +566,8 @@ private class Builder extends ScrollViewBuilder {
i++;
}



/* NOT SURE WHAT THIS IS, OR WHY ITS HERE, IT SEEMS LIKE TEST CODE THAT
* HAS BEEN LEFT IN, COMMENTING FOR NOW, BUT LOOK TO REMOVE LATER IF
* NO USE HAS BEEN FOUND
Expand Down Expand Up @@ -587,6 +628,41 @@ private class Builder extends ScrollViewBuilder {
return true;
});
}

private function ensureVisible(itemToEnsure:ItemRenderer) {
if (itemToEnsure != null && _tableview.virtual == false) {
var vscroll:VerticalScroll = _tableview.findComponent(VerticalScroll);
if (vscroll != null) {
var vpos:Float = vscroll.pos;
var contents:Component = _tableview.findComponent("tableview-contents", "css");
if (itemToEnsure.top + itemToEnsure.height > vpos + contents.componentClipRect.height) {
vscroll.pos = ((itemToEnsure.top + itemToEnsure.height) - contents.componentClipRect.height);
} else if (itemToEnsure.top < vpos) {
vscroll.pos = itemToEnsure.top;
}
}
}
}


@:access(haxe.ui.layouts.VerticalVirtualLayout)
private function ensureVirtualItemVisible(index:Int) {
var vscroll:VerticalScroll = _tableview.findComponent(VerticalScroll);
if (vscroll != null) {
var layout = cast(_tableview.layout, VerticalVirtualLayout);
var itemHeight = layout.itemHeight;
var itemTop = index * itemHeight;
var vpos:Float = vscroll.pos;
var contents:Component = _tableview.findComponent("tableview-contents", "css");
if (itemTop + itemHeight > vpos + contents.componentClipRect.height) {
vscroll.pos = ((itemTop + itemHeight) - contents.componentClipRect.height);
} else if (itemTop < vpos) {
vscroll.pos = itemTop;
}
}
}


}

//***********************************************************************************************************
Expand Down Expand Up @@ -767,17 +843,12 @@ private class SelectedIndicesBehaviour extends DataBehaviour {
}
}

if (itemToEnsure != null && tableView.virtual == false) { // TODO: virtual scroll into view
var vscroll:VerticalScroll = tableView.findComponent(VerticalScroll);
if (vscroll != null) {
var vpos:Float = vscroll.pos;
var contents:Component = tableView.findComponent("tableview-contents", "css");
if (itemToEnsure.top + itemToEnsure.height > vpos + contents.componentClipRect.height) {
vscroll.pos = ((itemToEnsure.top + itemToEnsure.height) - contents.componentClipRect.height);
} else if (itemToEnsure.top < vpos) {
vscroll.pos = itemToEnsure.top;
}
if (tableView.virtual) {
for (i in selectedIndices) {
@:privateAccess builder.ensureVirtualItemVisible(i);
}
} else {
@:privateAccess builder.ensureVisible(itemToEnsure);
}

if (tableView.selectedIndex != -1 && tableView.selectedIndices.length != 0) {
Expand Down
10 changes: 5 additions & 5 deletions haxe/ui/containers/dialogs/MessageBox.hx
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class MessageBox extends MessageBoxBase {
if (title == "Message") {
switch (type) {
case MessageBoxType.TYPE_INFO:
title = "Info";
title = "{{messagebox.title.info}}";
case MessageBoxType.TYPE_QUESTION:
title = "Question";
title = "{{messagebox.title.question}}";
case MessageBoxType.TYPE_WARNING:
title = "Warning";
title = "{{messagebox.title.warning}}";
case MessageBoxType.TYPE_ERROR:
title = "Error";
title = "{{messagebox.title.error}}";
case MessageBoxType.TYPE_YESNO:
title = "Question";
title = "{{messagebox.title.question}}";
}
}
}
Expand Down
38 changes: 37 additions & 1 deletion haxe/ui/containers/menus/Menu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class MenuEvents extends haxe.ui.events.Events {
}
}

public var lastEventSubMenu:MouseEvent = null;

private function onItemMouseOver(event:MouseEvent) {
var builder:Builder = cast(_menu._compositeBuilder, Builder);
var subMenus:Map<MenuItem, Menu> = builder._subMenus;
Expand All @@ -139,9 +141,43 @@ class MenuEvents extends haxe.ui.events.Events {
if (subMenus.get(item) != null) {
_currentItem = item;
showSubMenu(cast(subMenus.get(item), Menu), item);
lastEventSubMenu = event;
} else {
hideCurrentSubMenu();
if (currentSubMenu != null) {
if (!isMouseAimingForSubMenu(event)) {
hideCurrentSubMenu();
lastEventSubMenu = null;
}
lastEventSubMenu = event;
}
}
}

private function isMouseAimingForSubMenu(event:MouseEvent) {
// We check if the mouse is moving towards the submenu
// by looking if it's inside the triangle formed by his last position
// and the top and bottom of the submenu
if (lastEventSubMenu == null) return true;
var vX = lastEventSubMenu.screenX;
var vY = lastEventSubMenu.screenY;
var v2X = currentSubMenu.screenLeft;
var v2Y = currentSubMenu.screenTop;
var v3X = v2X;
var v3Y = currentSubMenu.screenTop + currentSubMenu.height;

// https://stackoverflow.com/questions/2049582/how-to-determine-if-a-point-is-in-a-2d-triangle
inline function sign (px:Float, py:Float, p2x:Float, p2y:Float, p3x:Float, p3y:Float)
{
return (px - p3x) * (p2y - p3y) - (p2x - p3x) * (py - p3y);
}

var d1 = sign(event.screenX, event.screenY, vX, vY, v2X, v2Y);
var d2 = sign(event.screenX, event.screenY, v2X, v2Y, v3X, v3Y);
var d3 = sign(event.screenX, event.screenY, v3X, v3Y, vX, vY);

var hasNeg = (d1 < 0) || (d2 < 0) || (d3 < 0);
var hasPos = (d1 > 0) || (d2 > 0) || (d3 > 0);
return !(hasNeg && hasPos);
}

private function onItemMouseOut(event:MouseEvent) {
Expand Down
2 changes: 1 addition & 1 deletion haxe/ui/focus/FocusManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FocusManager extends FocusManagerImpl {
private function onScreenMouseDown(event:MouseEvent) {
var list = Screen.instance.findComponentsUnderPoint(event.screenX, event.screenY);
for (l in list) {
if (isOfType(l, IFocusable) && @:privateAccess !cast(l, Component).isScroller) {
if (isOfType(l, IFocusable)) {
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion haxe/ui/styles/Style.hx
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class Style {
case "icon":
switch (v.value) {
case Value.VNone:
icon = null;
icon = "";
case _:
icon = ValueTools.variant(v.value);
}
Expand Down
Loading

0 comments on commit 5bf7682

Please sign in to comment.