Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Mar 30, 2019
1 parent 4614cdc commit e024586
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 285 deletions.
17 changes: 6 additions & 11 deletions haxe/ui/backend/AppBase.hx → haxe/ui/backend/AppImpl.hx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package haxe.ui.backend;

import cs.system.drawing.Size;
import cs.system.windows.forms.Application;
import cs.system.windows.forms.Form;
import haxe.ui.Preloader.PreloadItem;
import cs.system.drawing.Size;

class AppBase {
class AppImpl extends AppBase {
private var _form:Form;
private var _onEnd:Void->Void;

Expand All @@ -14,12 +13,12 @@ class AppBase {
Application.SetCompatibleTextRenderingDefault(false);
}

private function build() {
private override function build() {
_form = new Form();
_form.Text = Toolkit.backendProperties.getProp("haxe.ui.winforms.form.title", "");
}

private function init(onReady:Void->Void, onEnd:Void->Void = null) {
private override function init(onReady:Void->Void, onEnd:Void->Void = null) {
_onEnd = onEnd;

var formAutoSize = Toolkit.backendProperties.getPropBool("haxe.ui.winforms.form.autosize", true);
Expand All @@ -37,20 +36,16 @@ class AppBase {
onReady();
}

private function getToolkitInit():ToolkitOptions {
private override function getToolkitInit():ToolkitOptions {
return {
form: _form
};
}

public function start() {
public override function start() {
Application.Run(_form);
if (_onEnd != null) {
_onEnd();
}
}

private function buildPreloadList():Array<PreloadItem> {
return null;
}
}
29 changes: 6 additions & 23 deletions haxe/ui/backend/AssetsBase.hx → haxe/ui/backend/AssetsImpl.hx
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
package haxe.ui.backend;

import haxe.io.Bytes;
import haxe.ui.assets.ImageInfo;
import haxe.ui.assets.FontInfo;
import cs.system.drawing.Image;
import cs.system.io.MemoryStream;
import haxe.io.Bytes;
import haxe.ui.assets.ImageInfo;

class AssetsBase {
public function new() {

}

private function getTextDelegate(resourceId:String):String {
return null;
}

private function getImageInternal(resourceId:String, callback:ImageInfo->Void) {
class AssetsImpl extends AssetsBase {
private override function getImageInternal(resourceId:String, callback:ImageInfo->Void) {
imageFromBytes(Resource.getBytes(resourceId), callback);
}

private function getImageFromHaxeResource(resourceId:String, callback:String->ImageInfo->Void) {
private override function getImageFromHaxeResource(resourceId:String, callback:String->ImageInfo->Void) {
imageFromBytes(Resource.getBytes(resourceId), function(imageInfo) {
callback(resourceId, imageInfo);
});
}

public function imageFromBytes(bytes:Bytes, callback:ImageInfo->Void) {
public override function imageFromBytes(bytes:Bytes, callback:ImageInfo->Void) {
if (bytes == null) {
callback(null);
}
Expand All @@ -39,12 +30,4 @@ class AssetsBase {
}
callback(imageInfo);
}

private function getFontInternal(resourceId:String, callback:FontInfo->Void) {
callback(null);
}

private function getFontFromHaxeResource(resourceId:String, callback:String->FontInfo->Void) {
callback(resourceId, null);
}
}
5 changes: 0 additions & 5 deletions haxe/ui/backend/BackendBase.hx

This file was deleted.

5 changes: 5 additions & 0 deletions haxe/ui/backend/BackendImpl.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package haxe.ui.backend;

class BackendImpl {
public static var id:String = "winforms";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package haxe.ui.backend;

class CallLaterBase {
class CallLaterImpl {
public function new(fn:Void->Void) {
fn();
}
Expand Down
108 changes: 15 additions & 93 deletions haxe/ui/backend/ComponentBase.hx → haxe/ui/backend/ComponentImpl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@ import cs.system.windows.forms.Panel;
import haxe.ui.backend.winforms.StyleHelper;
import haxe.ui.containers.Box;
import haxe.ui.core.Component;
import haxe.ui.core.ImageDisplay;
import haxe.ui.core.TextDisplay;
import haxe.ui.core.TextInput;
import haxe.ui.events.MouseEvent;
import haxe.ui.events.UIEvent;
import haxe.ui.styles.Style;
import haxe.ui.geom.Rectangle;

class ComponentBase {
class ComponentImpl extends ComponentBase {
private var _eventMap:Map<String, UIEvent->Void> = new Map<String, UIEvent->Void>();

public var control:Control;

public function new() {
super();
}

public function handleCreate(native:Bool) {
public override function handleCreate(native:Bool) {
var className:String = Type.getClassName(Type.getClass(this));
var nativeComponentClass:String = Toolkit.nativeConfig.query('component[id=${className}].@class', 'System.Windows.Forms.Panel', null);

Expand All @@ -44,15 +41,15 @@ class ComponentBase {
}
}

private function handlePosition(left:Null<Float>, top:Null<Float>, style:Style) {
private override function handlePosition(left:Null<Float>, top:Null<Float>, style:Style) {
if (control == null) {
return;
}

control.Location = new Point(Std.int(left), Std.int(top));
}

private function handleSize(width:Null<Float>, height:Null<Float>, style:Style) {
private override function handleSize(width:Null<Float>, height:Null<Float>, style:Style) {
if (control == null) {
return;
}
Expand All @@ -66,7 +63,7 @@ class ComponentBase {
control.Size = new Size(Std.int(width), Std.int(height));
}

private function handleReady() {
private override function handleReady() {
if (Std.is(control, cs.system.windows.forms.TrackBar)) { // super crappy hack, trackbars _always_ have a grey background... if you can believe that!
var parent = findParent(cs.system.windows.forms.TabControl);
if (parent != null) {
Expand All @@ -75,92 +72,17 @@ class ComponentBase {
}
}

private function handleClipRect(value:Rectangle) {
}

public function handlePreReposition() {
}

public function handlePostReposition() {
}

private function handleVisibility(show:Bool) {
}

//***********************************************************************************************************
// Text related
//***********************************************************************************************************
private var _textDisplay:TextDisplay;
public function createTextDisplay(text:String = null):TextDisplay {
if (_textDisplay == null) {
_textDisplay = new TextDisplay();
}
if (text != null) {
_textDisplay.text = text;
}
return _textDisplay;
}

public function getTextDisplay():TextDisplay {
return createTextDisplay();
}

public function hasTextDisplay():Bool {
return (_textDisplay != null);
}

private var _textInput:TextInput;
public function createTextInput(text:String = null):TextInput {
if (_textInput == null) {
_textInput = new TextInput();
}
if (text != null) {
_textInput.text = text;
}
return _textInput;
}

public function getTextInput():TextInput {
return createTextInput();
}

public function hasTextInput():Bool {
return (_textInput != null);
}

//***********************************************************************************************************
// Image related
//***********************************************************************************************************
private var _imageDisplay:ImageDisplay;
public function createImageDisplay():ImageDisplay {
if (_imageDisplay == null) {
_imageDisplay = new ImageDisplay();
}
return _imageDisplay;
}

public function getImageDisplay():ImageDisplay {
return createImageDisplay();
}

public function hasImageDisplay():Bool {
return (_imageDisplay != null);
}

public function removeImageDisplay() {
if (_imageDisplay != null) {
_imageDisplay = null;
}
private override function handleVisibility(show:Bool) {
}

//***********************************************************************************************************
// Display tree
//***********************************************************************************************************
private function handleSetComponentIndex(child:Component, index:Int) {
private override function handleSetComponentIndex(child:Component, index:Int) {

}

private function handleAddComponent(child:Component):Component {
private override function handleAddComponent(child:Component):Component {
if (Std.is(this.control, cs.system.windows.forms.TabControl)) {
var tabControl = cast(this.control, cs.system.windows.forms.TabControl);

Expand Down Expand Up @@ -191,20 +113,20 @@ class ComponentBase {
return child;
}

private function handleAddComponentAt(child:Component, index:Int):Component {
private override function handleAddComponentAt(child:Component, index:Int):Component {
return child;
}

private function handleRemoveComponent(child:Component, dispose:Bool = true):Component {
private override function handleRemoveComponent(child:Component, dispose:Bool = true):Component {
control.Controls.Remove(child.control);
return child;
}

private function handleRemoveComponentAt(index:Int, dispose:Bool = true):Component {
private override function handleRemoveComponentAt(index:Int, dispose:Bool = true):Component {
return null;
}

private function applyStyle(style:Style) {
private override function applyStyle(style:Style) {
if (control == null) {
return;
}
Expand Down Expand Up @@ -249,7 +171,7 @@ class ComponentBase {
//***********************************************************************************************************
// Events
//***********************************************************************************************************
private function mapEvent(type:String, listener:UIEvent->Void) {
private override function mapEvent(type:String, listener:UIEvent->Void) {
switch (type) {
case MouseEvent.CLICK:
if (_eventMap.exists(type) == false) {
Expand All @@ -270,7 +192,7 @@ class ComponentBase {
}
}

private function unmapEvent(type:String, listener:UIEvent->Void) {
private override function unmapEvent(type:String, listener:UIEvent->Void) {
switch (type) {
case MouseEvent.CLICK:
_eventMap.remove(type);
Expand Down
6 changes: 6 additions & 0 deletions haxe/ui/backend/ComponentSurface.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package haxe.ui.backend;

class ComponentSurface {
public function new() {
}
}
13 changes: 0 additions & 13 deletions haxe/ui/backend/EventBase.hx

This file was deleted.

4 changes: 4 additions & 0 deletions haxe/ui/backend/EventImpl.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package haxe.ui.backend;

class EventImpl extends EventBase {
}
35 changes: 0 additions & 35 deletions haxe/ui/backend/ImageDisplayBase.hx

This file was deleted.

4 changes: 4 additions & 0 deletions haxe/ui/backend/ImageDisplayImpl.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package haxe.ui.backend;

class ImageDisplayImpl extends ImageBase {
}
6 changes: 6 additions & 0 deletions haxe/ui/backend/ImageSurface.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package haxe.ui.backend;

class ImageSurface {
public function new() {
}
}
Loading

0 comments on commit e024586

Please sign in to comment.