Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggling line wrap and readonly #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions haxe/ui/backend/ComponentBase.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be better to factor out the common parts between replaceWindow and createWindow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is this the correct way to go about it, you cant change wordwrap or readonly in wx at runtime on the same control?

Copy link
Contributor Author

@elnabo elnabo May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on the plateform. According to the documentation it is possible to update the widget at runtime with wxGTK but not wxMSW. But even then, it still behave strangely.

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;
Expand Down Expand Up @@ -741,4 +792,4 @@ class ComponentBase {
}
}
}
}
}
1 change: 1 addition & 0 deletions haxe/ui/backend/TextInputBase.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ class TextInputBase extends TextDisplayBase {
public var multiline:Bool;
public var password:Bool;
public var wordWrap:Bool;
public var readOnly:Bool;
}
3 changes: 2 additions & 1 deletion haxe/ui/backend/hxwidgets/StyleParser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
63 changes: 63 additions & 0 deletions haxe/ui/backend/hxwidgets/behaviours/ControlReadOnly.hx
Original file line number Diff line number Diff line change
@@ -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.READONLY) > 0;
}

return null;
}
}
63 changes: 63 additions & 0 deletions haxe/ui/backend/hxwidgets/behaviours/ControlWrap.hx
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions haxe/ui/backend/native.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<component id="haxe.ui.components.TextArea" class="hx.widgets.TextCtrl" constructor="null, $style" allowChildren="false" style="TextCtrlStyle.MULTILINE, TextCtrlStyle.HSCROLL">
<behaviour id="text" class="haxe.ui.backend.hxwidgets.behaviours.ControlLabel" />
<behaviour id="disabled" class="haxe.ui.backend.hxwidgets.behaviours.ControlDisable" />
<behaviour id="wrap" class="haxe.ui.backend.hxwidgets.behaviours.ControlWrap" />
<behaviour id="readOnly" class="haxe.ui.backend.hxwidgets.behaviours.ControlReadOnly" />
<size class="haxe.ui.backend.hxwidgets.size.BestSize" includePadding="false" />
</component>
<component id="haxe.ui.components.HProgress" class="hx.widgets.Gauge" constructor="100, $style" allowChildren="false">
Expand Down