How to implement "max-width" in a label.

I have a line container with a few label content elements inside. These are meant to be shown in a single line and I would like the first label to have a maximum width in case that string is too long. I don't want the width to be fixed as smaller strings won't show well.

Is this possible? how?


  • edited December 2015 Answer ✓

    Daniel -

    The KinomaJS Label object doesn't directly support the concept of a maximum width. Both the coordinates and style properties affect the width of the displayed string.

    To dynamically set the width of the first label based on the string width, I'd probably measure the contained string width to determine the width of the first label. Then instantiate a new Label object with the desired width and insert the label into the line. You can measure the width of a string using the measure function provided by Style:

    var size = style.measure("This is a longish string");
    var width = size.width;
    var height = size.height;

    Regards, Brian

Sign In or Register to comment.