Giter Site home page Giter Site logo

How to properly position? about uitoolkit HOT 9 OPEN

oddgames avatar oddgames commented on June 25, 2024
How to properly position?

from uitoolkit.

Comments (9)

frarees avatar frarees commented on June 25, 2024

It seems to me that there's a size factor (2:1 in that case) I'm not applying (or UIToolkit is not applying), and it affects to pixel positioning. Am I right?

from uitoolkit.

FrittenKeeZ avatar FrittenKeeZ commented on June 25, 2024

First of all you should use the positioning methods (pixelsFromXxxYyy and positionFromXxxYyy) AFTER endUpdates and matchSizeToContentSize are called. When switching to HD all pixel positioning methods multiply the values with 2, so the positions stay relatively the same.

from uitoolkit.

frarees avatar frarees commented on June 25, 2024

After doing so, I'm still having the same problem. I'm doing:

        var layout2 = new UIVerticalLayout(spacingBetweenItems);
        layout2.beginUpdates();
        layout2.verticalAlignMode = UIAbsoluteLayout.UIContainerVerticalAlignMode.Top;
        layout2.addChild(but4, but5, but6);
        layout2.endUpdates();
        layout2.matchSizeToContentSize();
        layout2.pixelsFromTopLeft((int)(layout1.height + Mathf.Abs(layout1.position.y)) + spacingBetweenItems, spacingBetweenItems);

from uitoolkit.

FrittenKeeZ avatar FrittenKeeZ commented on June 25, 2024

Can you position the layouts without adding anything from layout1? I mean do they display correctly if you try to do, pixelsFromTopLeft, pixelsFromBottomLeft, pixelsFromTopRight and pixelsFromBottomRight?

from uitoolkit.

frarees avatar frarees commented on June 25, 2024

Yes, they do. As I said, And if I hardcode 118 instead of Mathf.Abs(layout1.position.y), things work great!, so:

        var spacingBetweenItems = 9;
        ...
        var layout2 = new UIVerticalLayout(spacingBetweenItems);
        layout2.beginUpdates();
        layout2.verticalAlignMode = UIAbsoluteLayout.UIContainerVerticalAlignMode.Top;
        layout2.addChild(but4, but5, but6);
        layout2.endUpdates();
        layout2.matchSizeToContentSize();
        layout2.pixelsFromTopLeft(109 + spacingBetweenItems, spacingBetweenItems); // 118, hardcoded instead of using his layout above

Works great in both SD & HD. However, I don't want to hardcode this, but get a relative to it's above layout distance.

from uitoolkit.

FrittenKeeZ avatar FrittenKeeZ commented on June 25, 2024

What does layout1.height report just before you begin your work on layout2? I don't think you should use the position.y value. Since the height will change whether it's in SD or HD mode, you probably need to do something like:

int factor = UI.instance.isHD ? 2 : 1;
layout2.pixelsFromTopLeft(layout1.height / factor + spacingBetweenItems, spacingBetweenItems);

from uitoolkit.

frarees avatar frarees commented on June 25, 2024

That's what I thought, that there's a factor needed to be applied if using UIObject's properties. So if you don't encourage using position.y, how can I get my desired behavior? (stacked horizontal layouts, just like horizontal layouts nested inside a vertical layout would work... something like a table, let's say)

from uitoolkit.

FrittenKeeZ avatar FrittenKeeZ commented on June 25, 2024

Thinking about you can use position.y, but you need to account for the HD factoring.

int factor = UI.instance.isHD ? 2 : 1;
layout2.pixelsFromTopLeft((int) ((Mathf.Abs(layout1.position.y) + layout1.height) / factor) + spacingBetweenItems, spacingBetweenItems);

from uitoolkit.

frarees avatar frarees commented on June 25, 2024

Great, let me give it a try.

from uitoolkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.