haxeui / component-examples

27 stars 7 forks source link

Invalid Cast #2

Closed melMass closed 5 years ago

melMass commented 5 years ago

I'm getting:

Error : Invalid Cast

When trying to build the listviewsand demo samples. It seems to be related to the <itemrenderer> as a simple list work.

Using macOS | Haxe 4 | WxWidgets 3.1.3

ianharrigan commented 5 years ago

what versions of haxeui-*? Demo i think does have issues in native in the sense that some components dont have native counterparts yet (iirc)

melMass commented 5 years ago

I'm using haxeui-hxwidgets Version: 1.0.3

I've stripped down the sample and the culprit is itemRenderer is there an alternative for a list of images on native?

Also, where can I learn how to bind the UI to Haxe and things like that ? There seems to be many ways to do it.

ianharrigan commented 5 years ago

Ok, so this is exactly the thing ive been actively working on today. The issue is when you use native components, they dont really conform to the idea of "ItemRenderers" so, for the most part they simply wont work as you expect (for example, native listviews can have a single icon and a single label). However, you do have a few options:

The first, would be to just use a "ScrollView" and put all your images in there, this would work, but then you would have to maintain the items in there if you wanted to do anything remotely "interesting" with it.

The second would be to use the listview, but not native. This means it would still technically be native (in the sense everything, including the scrolls would be native windows) but the whole control, and its innner workings are no longer delegated to the host framework (wx in this case) and are managed internally by haxeui, as a so called "composite" component. This is, to me, the best option for your "list of images". However there are some issues that im currently working on for it.

  1. You'll need git version of haxeui-core and haxeui-hxwidgets (as i said, im currently actively working on this and dont want to make a release until im happy with it)
  2. Since the composite listview uses haxeui styles the result will look pretty crappy on dark mode, this is because haxeui default styles kick in now and things get "white & blue", there is a way to override that for now though, which is to simply remove them for the listview, so, something like:
<style>
    .listview, .listview .even, .listview .odd {
        background-color: none;
    }
</style>
  1. You'll have to manually set "native=false" on your listview:
    <listview native="false">
    ...
    </listview>

    or

    myList.native = false;

If you take a look at the listviews example (https://github.com/haxeui/component-examples/tree/master/listviews), and set the "virtual" attribute to false in the xml, or remove it, or change it to "native", and are using git version of the lib, and have that style above, then you should end up with something like:

image

Its not completely ideal, i would like the alternate rows to have a different colour and will get these from wx at some point (the facility is already there: .odd { background-color: platform-color(something); } )

I realise there is some hoops to jump through at the moment, but hopefully its not too bad and will become ALOT easier once ive got it all wired up correctly

Sheesh, that was a long answer!

Cheers, Ian

melMass commented 5 years ago

Thanks for the extensive report! Yes, it's kind of working doing the modification you suggested. I'll report back here once I have my basic layout done to be more precise!

ianharrigan commented 5 years ago

Cool - let me know if you hit any issues. FYI - most of the above is now in git (styles, etc). Below is the listview sample with virtual=true removed and native=true added:

image

melMass commented 5 years ago

For some reason this is how it looks like on my side doing the same modifications:

image

This is the trace when building:

Warning : Should be used in initialization macros only: haxe.macro.Compiler.define(source-header, GeneratedByHaxe)
/usr/local/lib/haxe/lib/haxeui-hxwidgets/git/haxe/ui/backend/DialogBase.hx:75: characters 19-26 : hx.widgets.StdDialogButtonSizer has no field realize
/usr/local/lib/haxe/lib/haxeui-hxwidgets/git/haxe/ui/backend/ComponentImpl.hx:88: lines 88-90 : Field get_isNativeScroller is declared 'override' but doesn't override any field
ianharrigan commented 5 years ago

Looks like you have a) updated hxWidgets (git version), haxeui-core (git version), haxeui-hxwidgets (gitversion)

Also, did you set "native=false" on <listview/> nodes?

melMass commented 5 years ago

Yes I've run:

haxelib git haxeui-core https://github.com/haxeui/haxeui-core.git
haxelib git haxeui-hxwidgets https://github.com/haxeui/haxeui-hxwidgets.git
haxelib git hxwidgets https://github.com/haxeui/hxwidgets.git

melMass commented 5 years ago

No error message during runtime, just the one I specified at build time

ianharrigan commented 5 years ago

I think case might be important? ie,

haxelib git **hxW**idgets https://github.com/haxeui/hxwidgets.git

And those are defo compiler errors, not runtime errors. Are you comfortable with "haxelib dev"? Maybe haxelib git has broken something? Maybe ill create a release, im pretty happy they work fine. Would be interesting to see why your install is broken though as using haxelib git / haxelib dev will be pretty important for "cutting edge" features

melMass commented 5 years ago

Unfortunately, that is not the culprit:

haxelib remove hxwidgets
haxelib git hxWidgets https://github.com/haxeui/hxwidgets

Building gives the same result. I'm not sure how to debug it myself.

ianharrigan commented 5 years ago

i guess the first thing to check is hx.widgets.StdDialogButtonSizer` (which is part of hxWidgets) - that should have the "realise" function as defined here: https://github.com/haxeui/hxWidgets/blob/master/src/hx/widgets/StdDialogButtonSizer.hx#L20-L22

ianharrigan commented 5 years ago

One thing ive just noticed is this file here: https://github.com/haxeui/hxWidgets/blob/master/src/StdDialogButtonSizer.hx is in the wrong place and is duplicated in src/wx/widgets/... i wonder how that got there... ill get rid of it

ianharrigan commented 5 years ago

Another thing might be manually delete the haxelibs yourself, ive had issues in the past where haxelib git never updated - might be fixed now, but ive certainly had to do it previously

melMass commented 5 years ago

It tried different approaches (reinstalling Haxelibs by first deleting them manually) but I'm still getting the same result

melMass commented 5 years ago

Just after answering this thread I tried to update and I had an issue about App Implementation, looking at the commits I realized this was added after I last updated.

About the issue of updating git haxelibs you are right! I think haxelib won't update the lib if the version number is the same (even if the sources changed). And your new App Implementation made it work !!

But now I have a little issue, some list items can't be clicked and trying to Remove 100 crashes the app, here is a video:

https://imgur.com/a/X6c569h

You told me you are actively working on it, so tell me if my reports are useful or not at that stage?

I really love what you have done with Haxe-UI

ianharrigan commented 5 years ago

You reports are certainly useful - for sure! Im still not convinced you have the latest version of haxeui-hxwidgets, or haxeui-core... you dont have any alternating colours in the lists, which you should have now... Do you still have the css i suggested above? Basically, revert the listview demo to its original, but remember to add "native=false" on the xml

melMass commented 5 years ago

Hm that's strange here are the exact steps I'm doing:

# Remove existing
RM -rf /usr/local/lib/haxe/lib/hxwidgets
RM -rf /usr/local/lib/haxe/lib/haxeui-*

# Install Libs from Git
haxelib git haxeui-core https://github.com/haxeui/haxeui-core.git
haxelib git hxWidgets https://github.com/haxeui/hxwidgets.git
haxelib git haxeui-hxwidgets https://github.com/haxeui/haxeui-hxwidgets.git
melMass commented 5 years ago

I'm starting over from the sample repo and I'll report if it solves it

melMass commented 5 years ago

I'm not getting how this can happen but I replaced virtual="false" with native="true"

And now i'm getting a weird error:

Warning : Should be used in initialization macros only: haxe.macro.Compiler.define(source-header, GeneratedByHaxe)
src/Main.hx:11: characters 34-83 : Uncaught exception Null Access
/usr/local/lib/haxe/lib/haxeui-core/git/haxe/ui/core/ComponentClassMap.hx:14: characters 17-52 : Called from here
/usr/local/lib/haxe/lib/haxeui-core/git/haxe/ui/macros/ComponentMacros.hx:145: characters 32-61 : Called from here
/usr/local/lib/haxe/lib/haxeui-core/git/haxe/ui/macros/ComponentMacros.hx:126: characters 9-63 : Called from here
/usr/local/lib/haxe/lib/haxeui-core/git/haxe/ui/macros/ComponentMacros.hx:106: characters 9-68 : Called from here
/usr/local/lib/haxe/lib/haxeui-core/git/haxe/ui/macros/ComponentMacros.hx:77: characters 9-88 : Called from here
src/Main.hx:11: characters 34-83 : Called from here
src/Main.hx:7: lines 7-17 : Defined in this class

I'll continue to find the cause, but posting just in case that sound familiar to you

ianharrigan commented 5 years ago

hmmm, any chance you can zip you project? Is the xml "well formed"?

melMass commented 5 years ago

It's a copy of the repo I just cloned. I have a meeting but I'll be back in a few hours and will report properly.

ianharrigan commented 5 years ago

cool - well, if you get a moment, send the zip over anyway, there maybe be some subtle difference, and that error isnt very useful, so if possibly id like to fix that and give a better error back.

Cheers, Ian

ianharrigan commented 5 years ago

empty .zip it seems :)

melMass commented 5 years ago

listviews+.zip

Sorry here it is

ianharrigan commented 5 years ago

OK, the xml isnt valid:

<style>
    .listview, .listview .even, .listview .odd {
        background-color: none;
    }
</style>
<vbox style="padding: 5px;">
...
</vbox>

thats not valid xml, your <style> element needs to be under another node, ie, you can only have one root node

In this case its the fix i mentioned above, which is no longer needed so you can just remove it entirely.

melMass commented 5 years ago

🤦‍♂ ... Dumb one sorry.. It now builds ( I still needed to add -D disable-unicode-strings on macOS Mojave)

melMass commented 5 years ago

The list now behaves correctly! (Selectable etc..) but segfaults on Remove 10 or Remove 100. Thought those issues and your answers I managed to solve the things that blocked me from really taking the time to discover haxe-ui. I will do now. The error must be some kind of memory leak

melMass commented 5 years ago

Here is how it now behaves|look on my end: https://imgur.com/a/rmqXld2

ianharrigan commented 5 years ago

Perfect! Glad its working! Ill check out the remove, it will either be an issue with the demo application or the framework, either way, it shouldnt be too hard.

:)

melMass commented 5 years ago

Thanks again

ianharrigan commented 5 years ago

No problem! Thanks for taking the time to work through the issue(s). :)

ianharrigan commented 5 years ago

FYI: that crash when you try and remove an item is fixed now :)

melMass commented 5 years ago

Just tested I can confirm that !