RealyUniqueName / StablexUI

UI engine for Haxe OpenFL designed to give as much freedom as possible in customizing UI
http://ui.stablex.ru/doc
Other
337 stars 80 forks source link

how to invalidate size manually? #251

Closed hopewise closed 7 years ago

hopewise commented 8 years ago

on-resize works well when window of browser get resized. but, I have other scenario, where user changes the canvas size.

I tried:

var root:Floating = UIBuilder.get('root').as(Floating);
root.resize(w, root.h);
root.refresh();

where w is the new width of the openfl canvas, but, nothing happened. I want to achieve the same result I get when the whole window resized, but when resizing the Canvas instead.

What I expect, that all children sizes of the root get re-validated again.

Please advice.

RealyUniqueName commented 8 years ago

Floating widget relies on stage resize event. So maybe openfl does not emit this event if canvas size changed manually? You can try to dispatch it manually:

Lib.current.stage.dispatchEvent(new Event(Event.RESIZE));
hopewise commented 8 years ago

I tried to resize the Canvas, using jQuery:

$("#openfl_canvas_id").attr("width", new_width);

Then I did:

haxe.Timer.delay(function(){
openfl.Lib.current.stage.dispatchEvent(new Event(Event.RESIZE));    
}, 100);

I had to pass the new width to root Floating manually, I did:

var root:Floating = UIBuilder.get('root').as(Floating);
root.resize(new_width, root.h);
root.refresh();

but I've noticed that children of root Floating was not invalidated, the expected behavior is that children of resized Floating, should be invalidated once I refresh their parent size, but that did not happen.

Please advice.

RealyUniqueName commented 8 years ago

How do you define size of children? Do you use widthPt/heightPt?

hopewise commented 8 years ago

yes

RealyUniqueName commented 8 years ago

Can you provide a minimal example?

hopewise commented 8 years ago

I am checking with openFL it self, I am not sure .. I will let you know though

hopewise commented 8 years ago

ok, I found the solution, the problem is not with stablexUI. The solution was, I had to revalidate the window itself right after resizing the Canvas as:

var evt = document.createEvent('UIEvents'); evt.initUIEvent('resize', true, false,window,0); window.dispatchEvent(evt);

Thank you