RonenNess / GeonBit.UI

UI system for MonoGame projects.
MIT License
467 stars 63 forks source link

Absolute -> relative positioning #143

Closed Kubrix closed 3 months ago

Kubrix commented 4 months ago

How do I start adapting UI elements from Absolute to relative positioning (as GeonBit 4.3.0.0 does not offer the former)

Current main menu image

5 boxes are centered Horizontally but not vertically - they are positioned by Top/Left coordinates

Do i make 3 rectanged areas? Top Medium and bottom?

RonenNess commented 4 months ago

Hi not sure what you mean about not offering relative positioning, I never removed any compatibility related to positioning.

Relative positions and sizes are 0.0 - 1.0 values. 0.5 will be 50% of parent size.

Or did you mean relative to each other? In which case there's an anchor type for that.

Kubrix commented 4 months ago

I create a label GeonBit.UI.Entities.Label lbl = new GeonBit.UI.Entities.Label("Level", Anchor.Auto, new Vector2(0,0));

But I cant find the width or height properties so I have to specify size relative to outsie container

Or take those 5 colored rectrangles - I have to put them into some container to set their width 100 of container`s width. But what will that container width will be if it as to be placed on the center of screen

RonenNess commented 4 months ago

It will be whatever width you set it to be. Anchor does not affect size, only placement. Please read the docs about sizing elements, all the rules are explained there:

https://github.com/RonenNess/GeonBit.UI?tab=readme-ov-file#size

An element placed directly under root will use renderer size as "parent" size.

Kubrix commented 4 months ago

It will be whatever width you set it to be.

No? I want the label to be 800px width

This does not work as I dont have parent for label https://github.com/RonenNess/GeonBit.UI?tab=readme-ov-file#size

MinSize/MaxSize is vector2?

RonenNess commented 4 months ago

If you set its width to 800 pixels the element width will be 800 pixels. That doesn't mean the label text itself will be stretch to fit that width though, if thats what you want.

I really don't understand what's your issue with elements with no parent. Just imagine it as if their parent is an imaginary container the size of the screen, which is actually sort of what's happening internally.

Kubrix commented 4 months ago

That doesn't mean the label text itself will be stretch to fit that width though, if thats what you want. :(

I want a 800*25 px label with all of its backround colored

    GLabel = new  GeonBit.UI.Entities.Label("Level", Anchor.Auto, new Vector2(800, 25) , new Vector2(0, 5)  ); 

Only the text part is colored

RonenNess commented 4 months ago

Ah I see you're talking about background color. Use this:

https://github.com/RonenNess/GeonBit.UI/blob/master/GeonBit.UI/Source/Entities/Paragraph.cs#L91

Kubrix commented 3 months ago

Tnank you