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

Center Widget On Resize #217

Closed dresch86 closed 9 years ago

dresch86 commented 9 years ago

I am working on making a login portal and would like for it to be centered on the screen even if the window is resized. What is the best way to accomplish this? I've tried setting the .h and .w using the on-resize event but the column layout does not resize.

RealyUniqueName commented 9 years ago

You can create Floating widget and attach your login window to it. Something like this:

var floating = UIBuilder.create(Floating, {/* setup properties */});
var login = /* create login window */
floating.addChild(login);
floating.show()

By default Floating is added directly to Lib.current.stage and resized on each stage resize.

dresch86 commented 9 years ago

I'm using the XML route and have the following from the samples section:

<?xml version="1.0" encoding="UTF-8"?>

<Floating name="'popup'" widthPt="100" heightPt="100" skin:Paint-color="0x333333">
    <VBox widthPt="90" childPadding="10" padding="10" skin:Paint-color="0x333333" skin:Paint-corners="[10]">
        <Text widthPt="90" label-wordWrap="true" text="'pop'" />
        <Button text="'OK'" on-click="$this.getParent('popup').free();"/>
    </VBox>
</Floating>

The only different from the samples section is I don't have a skin named "popup." The only thing I see is a blank white screen. There are no text boxes or buttons. Any ideas?

RealyUniqueName commented 9 years ago

Your xml seems ok. Can you show the code you use to display it?

dresch86 commented 9 years ago
package;

import openfl.Lib;
import openfl.Assets;
import openfl.text.TextFieldAutoSize;

import openfl.display.Stage;
import openfl.display.Sprite;

import openfl.text.TextField;
import openfl.text.TextFieldType;

import ru.stablex.ui.UIBuilder;

class Main extends Sprite
{
    private var spLoginForm:Sprite;

    public function new() 
    {
        super();
        Lib.current.stage.addChild(this);
        UIBuilder.init();

                addChild( UIBuilder.buildFn('ui.xml')() );
    }
}
RealyUniqueName commented 9 years ago

For Floating widgets instead of addChild( UIBuilder.buildFn('ui.xml')() ) you need to UIBuilder.buildFn('ui.xml')().show()

dresch86 commented 9 years ago

Awesome! Got it working now! Thanks!