Skip to content

Commit

Permalink
convert for variant properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Nov 16, 2023
1 parent cd89285 commit 65a756e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions haxe/ui/RuntimeComponentBuilder.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package haxe.ui;

import haxe.ui.util.RTTI;
#if !macro
import haxe.ui.Toolkit;
import haxe.ui.components.Button;
Expand Down Expand Up @@ -164,12 +165,13 @@ class RuntimeComponentBuilder {
if (StringTools.startsWith(propName, "on")) {
//component.addScriptEvent(propName, propValue);
} else {
// TODO: weirdly, for Images (also icons) setProperty doesnt work correctly - or the behaviour...... misbehaves
if (propName == "resource" && (component is Image)) {
cast(component, Image).resource = Variant.fromDynamic(propValue);
} else if (propName == "icon" && (component is Button)) {
cast(component, Button).icon = Variant.fromDynamic(propValue);
} else {
var propInfo = RTTI.getClassProperty(Type.getClassName(Type.getClass(component)), propName);
// if the property is a variant, we'll need to make sure (explicity) that it is a converted
// since the abstract wont exist at runtime, so it wont have the from, to, etc
if (propInfo != null && propInfo.propertyType == "variant") {
propValue = Variant.fromDynamic(propValue);
Reflect.setProperty(component, propName, propValue);
} else {
propValue = TypeConverter.convertFrom(propValue);
Reflect.setProperty(component, propName, propValue);
}
Expand Down

0 comments on commit 65a756e

Please sign in to comment.