GuiLabel sizes

  • 1) I am finding it would be very useful to have a way to get the vertical and, above all, horizontal size of a GuiLabel (as also stated somewhere in the documentation, GuiElement.getWidth/Height() do not work with GuiLabels and always returns 0).


    Is there any plan to implement those methods for GuiLabels too?


    2) It would also be very useful to be able to retrieve the sizes both as relative and as absolute, regardless of the way they have been defined;
    OR at lest
    to be able to retrieve their absolute values even if defined in relative terms (ultimately, any GuiElement takes an absolute amount of pixel on screen; the opposite, retrieving the relative value of a size defined as absolute seems less frequent).


    My use case is adapting the size of a container GuiElement (say, a GuiPanel) to the size of the contained elements.

  • Tbh I would like to also see the equivalent setWidth, and setHeight methods for labels as well as setTextAllignment methods wich will be then needed to control where the text will appear on the label.


    Currently the only way I can see to create a button of set size but with text on it is to first create a GuiImage to have the button border at a set size and then create a GuiLabel on that GuiImage to have the text label in the middle of the button. Then in my GuiListener have an if loop on the GuiClickEvent for either the label or the image being clicked to do the action my button needs to do.


    If I could set the label to the size I wanted then there would be no need for the extra GuiImage to create the border. I think that having the labels take the size of the text they hold by default without the ability to change it is a huge limitation in the current java API

  • 1) I am finding it would be very useful to have a way to get the vertical and, above all, horizontal size of a GuiLabel

    These methods will be added in the near future :) The current GUI anyway needs an overhaul...


    2) It would also be very useful to be able to retrieve the sizes both as relative and as absolute, regardless of the way they have been defined;

    Methods like "getRelativeWidth()" or "getAbsoluteHeight()" etc. will be added accordingly^^


    Tbh I would like to also see the equivalent setWidth, and setHeight methods for labels as well as setTextAllignment methods wich will be then needed to control where the text will appear on the label.

    Hmm... I'm afraid that will be a little bit complicated. The underlying framework is designed to adapt the element size to the font size (and text width), and the alignment is automatically determined by the pivot... maybe this changes in the future, since we want to rework the underlying framework anyway (to support ttf fonts), but unfortunately I can't say much about that yet :(


    Currently the only way I can see to create a button of set size but with text on it is to first create a GuiImage to have the button border at a set size and then create a GuiLabel on that GuiImage to have the text label in the middle of the button. Then in my GuiListener have an if loop on the GuiClickEvent for either the label or the image being clicked to do the action my button needs to do.

    Maybe it would work if we implement a flag that certain GUI elements should be ignored when it comes to mouse clicks, then the click event will be forwarded to the parent. Basically that's how the game handles it own GUI elements. However, button elements are planned for the API GUI anyway :)

  • Maybe it would work if we implement a flag that certain GUI elements should be ignored when it comes to mouse clicks, then the click event will be forwarded to the parent. Basically that's how the game handles it own GUI elements. However, button elements are planned for the API GUI anyway

    perfect because my current solution needs 2 elements for each button and I will soon get lost in label and image names :D (i.e. only the borders without an actual image in them)

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!