From 6ba6b8ed13c6d98e5491e39777f61c86fd26bf3d Mon Sep 17 00:00:00 2001 From: elnabo Date: Tue, 23 May 2017 21:47:14 +0200 Subject: [PATCH 1/3] adding support for wordwrap and readonly change --- haxe/ui/backend/ComponentBase.hx | 55 +++++++++++++++- haxe/ui/backend/TextInputBase.hx | 1 + haxe/ui/backend/hxwidgets/StyleParser.hx | 3 +- .../hxwidgets/behaviours/ControlReadOnly.hx | 63 +++++++++++++++++++ .../hxwidgets/behaviours/ControlWrap.hx | 63 +++++++++++++++++++ haxe/ui/backend/native.xml | 2 + 6 files changed, 184 insertions(+), 3 deletions(-) create mode 100644 haxe/ui/backend/hxwidgets/behaviours/ControlReadOnly.hx create mode 100644 haxe/ui/backend/hxwidgets/behaviours/ControlWrap.hx diff --git a/haxe/ui/backend/ComponentBase.hx b/haxe/ui/backend/ComponentBase.hx index a15653b..093f46d 100644 --- a/haxe/ui/backend/ComponentBase.hx +++ b/haxe/ui/backend/ComponentBase.hx @@ -232,7 +232,58 @@ class ComponentBase { window.bind(EventType.ERASE_BACKGROUND, function(e) { }); - } + } + } + + private function replaceWindow(replacement:Window) { + if (replacement == null) { + return; + } + __children = []; + + cast(this, Component).invalidateStyle(false); + window.destroy(); + window = replacement; + + var platform:PlatformInfo = new PlatformInfo(); + if (Std.is(window, Notebook)) { + if (platform.isWindows) { + var n:Notebook = cast window; + n.padding = new hx.widgets.Size(6, 6); + //n.backgroundColour = 0xF0F0F0; + //n.refresh(); + } + } + + if (Std.is(window, ScrollBar)) { + var scrollbar:ScrollBar = cast window; + scrollbar.setScrollbar(0, 5, 100, 5); + } + + if (Std.is(__parent, haxe.ui.containers.TabView)) { + var n:Notebook = cast __parent.window; + var pageTitle:String = cast(this, Component).text; + var pageIcon:String = cast(this, Box).icon; + var iconIndex:Int = TabViewIcons.getImageIndex(cast __parent, pageIcon); + n.addPage(window, pageTitle, iconIndex); + } + + if (Std.parseInt(cast(this, Component).id) != null) { + window.id = Std.parseInt(cast(this, Component).id); + } + + if (__eventsToMap != null) { + for (type in __eventsToMap.keys()) { + mapEvent(type, __eventsToMap.get(type)); + } + __eventsToMap = null; + } + + if (Std.is(window, Button) || Std.is(window, StaticText)) { + window.bind(EventType.ERASE_BACKGROUND, function(e) { + + }); + } } private var _paintStyle:Style = null; @@ -741,4 +792,4 @@ class ComponentBase { } } } -} \ No newline at end of file +} diff --git a/haxe/ui/backend/TextInputBase.hx b/haxe/ui/backend/TextInputBase.hx index 7773a82..bbde1c6 100644 --- a/haxe/ui/backend/TextInputBase.hx +++ b/haxe/ui/backend/TextInputBase.hx @@ -10,4 +10,5 @@ class TextInputBase extends TextDisplayBase { public var multiline:Bool; public var password:Bool; public var wordWrap:Bool; + public var readOnly:Bool; } diff --git a/haxe/ui/backend/hxwidgets/StyleParser.hx b/haxe/ui/backend/hxwidgets/StyleParser.hx index d59fd9d..b48a318 100644 --- a/haxe/ui/backend/hxwidgets/StyleParser.hx +++ b/haxe/ui/backend/hxwidgets/StyleParser.hx @@ -31,10 +31,11 @@ class StyleParser { case "ScrollBarStyle.VERTICAL": return ScrollBarStyle.VERTICAL; case "TextCtrlStyle.MULTILINE": return TextCtrlStyle.MULTILINE; case "TextCtrlStyle.HSCROLL": return TextCtrlStyle.HSCROLL; + case "TextCtrlStyle.READONLY": return TextCtrlStyle.READONLY; default: trace('WARNING: hxWidgets style "${style}" not recognised'); } return 0; } -} \ No newline at end of file +} diff --git a/haxe/ui/backend/hxwidgets/behaviours/ControlReadOnly.hx b/haxe/ui/backend/hxwidgets/behaviours/ControlReadOnly.hx new file mode 100644 index 0000000..0b8f889 --- /dev/null +++ b/haxe/ui/backend/hxwidgets/behaviours/ControlReadOnly.hx @@ -0,0 +1,63 @@ +package haxe.ui.backend.hxwidgets.behaviours; + +import haxe.ui.util.Variant; +import haxe.ui.components.TextArea; +import hx.widgets.Bitmap; +import hx.widgets.Control; +import hx.widgets.Button; +import hx.widgets.StaticText; +import hx.widgets.TextCtrl; +import hx.widgets.styles.TextCtrlStyle; + +@:keep +@:access(haxe.ui.core.Component) +class ControlReadOnly extends HxWidgetsBehaviour { + public override function set(value:Variant) { + super.set(value); + if (_component.window == null) { + return; + } + + var ctrl:Control = cast _component.window; + if (value.isNull == false) { + if (Std.is(_component.window, TextCtrl)) { + var textctrl:TextCtrl = cast _component.window; + var style = textctrl.windowStyle; + + if (value == false && (style & TextCtrlStyle.READONLY > 0)) { + style -= TextCtrlStyle.READONLY; + } + if (value == true) { + style |= TextCtrlStyle.READONLY; + } + + var text = textctrl.value; + var parent = textctrl.parent; + var id = textctrl.id; + + var replacement = new TextCtrl(parent, text, style, id); + replacement.size = textctrl.size; + replacement.position = textctrl.position; + _component.replaceWindow(replacement); + } + _component.invalidateLayout(); + } + + + var textArea:TextArea = cast _component; + textArea.getTextInput().readOnly = value; + } + + public override function get():Variant { + if (_component.window == null) { + return null; + } + + if (Std.is(_component.window, TextCtrl)) { + var textctrl:TextCtrl = cast _component.window; + return !(textctrl.windowStyle & TextCtrlStyle.DONTWRAP > 0); + } + + return null; + } +} diff --git a/haxe/ui/backend/hxwidgets/behaviours/ControlWrap.hx b/haxe/ui/backend/hxwidgets/behaviours/ControlWrap.hx new file mode 100644 index 0000000..92639b3 --- /dev/null +++ b/haxe/ui/backend/hxwidgets/behaviours/ControlWrap.hx @@ -0,0 +1,63 @@ +package haxe.ui.backend.hxwidgets.behaviours; + +import haxe.ui.util.Variant; +import haxe.ui.components.TextArea; +import hx.widgets.Bitmap; +import hx.widgets.Control; +import hx.widgets.Button; +import hx.widgets.StaticText; +import hx.widgets.TextCtrl; +import hx.widgets.styles.TextCtrlStyle; + +@:keep +@:access(haxe.ui.core.Component) +class ControlWrap extends HxWidgetsBehaviour { + public override function set(value:Variant) { + super.set(value); + if (_component.window == null) { + return; + } + + var ctrl:Control = cast _component.window; + if (value.isNull == false) { + if (Std.is(_component.window, TextCtrl)) { + var textctrl:TextCtrl = cast _component.window; + var style = textctrl.windowStyle; + if (value == true && (style & TextCtrlStyle.DONTWRAP > 0)) { + style -= TextCtrlStyle.DONTWRAP; + } + else if (value == false && (style & TextCtrlStyle.BESTWRAP > 0)) { + style -= TextCtrlStyle.BESTWRAP; + } + style |= (value == true) ? TextCtrlStyle.BESTWRAP : TextCtrlStyle.DONTWRAP; + var text = textctrl.value; + var parent = textctrl.parent; + var id = textctrl.id; + + var replacement = new TextCtrl(parent, text, style, id); + replacement.size = textctrl.size; + replacement.position = textctrl.position; + _component.replaceWindow(replacement); + } + _component.invalidateLayout(); + } + + + var textArea:TextArea = cast _component; + textArea.getTextInput().wordWrap = value; + textArea.checkScrolls(); + } + + public override function get():Variant { + if (_component.window == null) { + return null; + } + + if (Std.is(_component.window, TextCtrl)) { + var textctrl:TextCtrl = cast _component.window; + return !(textctrl.windowStyle & TextCtrlStyle.DONTWRAP > 0); + } + + return null; + } +} diff --git a/haxe/ui/backend/native.xml b/haxe/ui/backend/native.xml index 0e38527..43990c3 100644 --- a/haxe/ui/backend/native.xml +++ b/haxe/ui/backend/native.xml @@ -33,6 +33,8 @@ + + From b81e7fc109d0e9d7f0ce469ad3f1e35b5de8ffd1 Mon Sep 17 00:00:00 2001 From: elnabo Date: Tue, 23 May 2017 22:03:56 +0200 Subject: [PATCH 2/3] typo & parenthesis --- haxe/ui/backend/hxwidgets/behaviours/ControlReadOnly.hx | 2 +- haxe/ui/backend/hxwidgets/behaviours/ControlWrap.hx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/haxe/ui/backend/hxwidgets/behaviours/ControlReadOnly.hx b/haxe/ui/backend/hxwidgets/behaviours/ControlReadOnly.hx index 0b8f889..a8ae8eb 100644 --- a/haxe/ui/backend/hxwidgets/behaviours/ControlReadOnly.hx +++ b/haxe/ui/backend/hxwidgets/behaviours/ControlReadOnly.hx @@ -55,7 +55,7 @@ class ControlReadOnly extends HxWidgetsBehaviour { if (Std.is(_component.window, TextCtrl)) { var textctrl:TextCtrl = cast _component.window; - return !(textctrl.windowStyle & TextCtrlStyle.DONTWRAP > 0); + return (textctrl.windowStyle & TextCtrlStyle.READONLY) > 0; } return null; diff --git a/haxe/ui/backend/hxwidgets/behaviours/ControlWrap.hx b/haxe/ui/backend/hxwidgets/behaviours/ControlWrap.hx index 92639b3..b9507c1 100644 --- a/haxe/ui/backend/hxwidgets/behaviours/ControlWrap.hx +++ b/haxe/ui/backend/hxwidgets/behaviours/ControlWrap.hx @@ -55,7 +55,7 @@ class ControlWrap extends HxWidgetsBehaviour { if (Std.is(_component.window, TextCtrl)) { var textctrl:TextCtrl = cast _component.window; - return !(textctrl.windowStyle & TextCtrlStyle.DONTWRAP > 0); + return !((textctrl.windowStyle & TextCtrlStyle.DONTWRAP) > 0); } return null; From 6cbd8b689d6df44e66aa815e35d2cc4a95e4589e Mon Sep 17 00:00:00 2001 From: elnabo Date: Tue, 23 May 2017 22:17:11 +0200 Subject: [PATCH 3/3] factoring --- haxe/ui/backend/ComponentBase.hx | 34 +++++--------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/haxe/ui/backend/ComponentBase.hx b/haxe/ui/backend/ComponentBase.hx index 093f46d..cd3a662 100644 --- a/haxe/ui/backend/ComponentBase.hx +++ b/haxe/ui/backend/ComponentBase.hx @@ -204,35 +204,7 @@ class ComponentBase { } } - if (Std.is(window, ScrollBar)) { - var scrollbar:ScrollBar = cast window; - scrollbar.setScrollbar(0, 5, 100, 5); - } - - if (Std.is(__parent, haxe.ui.containers.TabView)) { - var n:Notebook = cast __parent.window; - var pageTitle:String = cast(this, Component).text; - var pageIcon:String = cast(this, Box).icon; - var iconIndex:Int = TabViewIcons.getImageIndex(cast __parent, pageIcon); - n.addPage(window, pageTitle, iconIndex); - } - - if (Std.parseInt(cast(this, Component).id) != null) { - window.id = Std.parseInt(cast(this, Component).id); - } - - if (__eventsToMap != null) { - for (type in __eventsToMap.keys()) { - mapEvent(type, __eventsToMap.get(type)); - } - __eventsToMap = null; - } - - if (Std.is(window, Button) || Std.is(window, StaticText)) { - window.bind(EventType.ERASE_BACKGROUND, function(e) { - - }); - } + setupWindow(); } private function replaceWindow(replacement:Window) { @@ -245,6 +217,10 @@ class ComponentBase { window.destroy(); window = replacement; + setupWindow(); + } + + private function setupWindow() { var platform:PlatformInfo = new PlatformInfo(); if (Std.is(window, Notebook)) { if (platform.isWindows) {