Good day!
I can’t find the option to set design Width, Height and Anchors from the file at loading.
For example, I create window with 800x600 sizes and with middle position. But, when I call it from the code, it always have 100x100 size and left-bottom position. And I use this construction again and again and again:
There’s nothing special you need to do to center the TCastleDesign – the code you show looks OK (except Exists := False;, but I assume this is just from experiments ).
You should be able to center TCastleDesign, or really any other TCastleUserInterface, with this. Note that you can also use Anchor(hpMiddle) to set both HorizontalAnchorParent and HorizontalAnchorSelf and Translation.X (to zero by default) in one go. So you can as well write
So, the simple test works for me Please submit a testcase to reproduce the problem – full code and data. You can test can you modify my attached testcase to make it broken.
Your example my-new-project-test-designs-2.zip works for me OK – if I add the code centering the design, mentioned above in this thread This is the result:
Your example does it in Update. Don’t do this in Update in the real application, as you’re adding ~60 rectangles every second Do it e.g. in Start if you only want to do it once.
You can use CGE functionality “package sources” to send smaller ZIP files. From the editor, choose menu item “Run → Package Source”. From the command-line, use castle-engine package-source ( Build Tool | Manual | Castle Game Engine ). This avoids packing to ZIP output files (like castle-engine-output).
Sorry, I don’t understand this question I’m not sure what is “target component” and “root” in this context.
To be clear, things you load from designs (either by setting TCastleDesign.Url or UserInterfaceLoad) are regular component instances.
TCastleDesign itself is TCastleUserInterface descendant.
The result of UserInterfaceLoad (you don’t use it, but I mention it for completeness) is also TCastleUserInterface descendant.
And you insert it into a view (TCastleView) that is also TCastleUserInterface descendant.
You could also insert it into RootGroup component in the view, or any other component there.
Everything can used with everything, in principle :), i.e. any TCastleUserInterface can be parent of any TCastleUserInterface.
I hope this is helpful. I’m sorry for failing to understand the question If you still experience issues, please submit another testcase and/or clarify your question, I’ll be happy to help more.
Yes, it helps.
I meant, design in the data folder already have Middle anchors and Width and Height 800x600. When I opens it on API I see it… But, when I add this Design to somewhere, it uses default anchors and sizes.
So, for fix this, I need to use this code:
I have few those designs. And I thinked about the way to load them with some parameters automatically. To not always write few additional strings in the constructor. But it is not big problem to change them from code in the creating process.
P.S. when I told about the target component, I meand directly our blue rectangle. And root is TCastleUserInterface in design.
That is how it is supposed to work – TCastleDesign has it’s own sizes and anchors, and TCastleDesign is a parent of the loaded content. The idea is that this way, size and anchors of every instance of the loaded component are independent.
As you say, you can just use these lines (to adjust size and position) every time you instantiate it.
You can also change the TCastleDesign.Stretch to false (by default it is true) to use the designed sizes. But you will still then have to make sure the anchors of the design are good, and also you should make sure the TCastleDesign effective size is what the children say. So instead of
Hm, I realize this is the same amount of lines But at least you don’t hardcode the numbers (800 / 600) in this case.
You can also use UserInterfaceLoad. It’s a bit less comfortable, so we don’t really recommend using it (TCastleDesign is my recommendation), but in this case → it will avoid the issue. UserInterfaceLoad doesn’t “wrap” the component in any parent, so it will have anchors and sizes as you did. For this, replace the whole
So it’s shorter, and LoadedTestRect has anchors / sizes as you designed. But you don’t have then the DesignTestRect.DesignedComponent utility (which you could have used above like AccessSomethingInsideBlueRect := DesignTestRect.DesignedComponent('SomethingInsideBlueRect');. To access loaded components you need to introduce another component – I show an example below, but it looks more complicated, which is why I don’t generally recommend it:
Understood how it works for now, thanks
Actually, set windows sizes from the code not to bad - maybe sometime I will make them defend from the screen resolution.
As for screen resolution: we have UI scaling and I recommend to use it See Customize look by CastleSettings.xml | Manual | Castle Game Engine . This basically means it is OK to use hardcoded sizes, like width=800, height=600. They will be adjusted to the actual window size (or screen size, when window is fullscreen). So when UI scaling is used, it’s actually fully OK to just set