How do I implement an expanding textbox?

  • Is there a way to make the word wrap in a textbox AND text object increase the height of the textbox and text object?

    I'm basically hiding the textbox object when you're not editing and instead displaying a text object with the same content (due to the annoying visibility properties on html objects). I want the user to control the height of the textbox (and text object) based on the amount of text in there.

    Hopefully this makes sense?

  • You can change the size of your TextBox, but as for the word wrap - not sure if it's possible. Maybe with CSS?

    Use TextHeight and TextWidth expressions of the Text object to get actual text dimensions and resize the Text object accordingly. The only problem is that the system needs at least 1 tick (or longer for web fonts) to render the text before TextHeight and TextWidth become available.

    So it works like this:

    TextObject set Text to "Hello world!"

    Wait 0

    TextObject set Width to (Self.TextWidth+5)

    TextObject set Height to (Self.TextHeight+5)

  • dop2000 - yeah the textbox not being able to word wrap is pretty game breaking. Although, the text height worked! Previously, I was thinking it wasn't wrapping so I checked to see if the textwidth > text.width (and obviously wasn't working).

    Anyone else have any clue to make the textbox more malleable?

  • UPDATE - okay so I've figured out to use the textarea for the texbox...that'll make it word wrap. But now the only issue im having is the textbox doesn't line up exactly with the text object, even though its the same font, size, etc.

    So when I update the text size based on text height, it's updating the textbox too, but incorrectly (since the text size is "technically" different).

  • I don't like TextBox, it's ugly (for games), impractical, hard to customize.

    If I needed a simple text input for my game, I would probably make my own custom "textbox" using Text or SpriteFont object.

    Shouldn't be too hard - read keyboard input to add or remove characters. Use symbol "|" for cursor, blink it every second (replace with " "), move cursor with arrow keys.

    Setting cursor to mouse position could be tricky, but still possible with SpriteFont as you can get the exact size of each character.

    Of course if you need text selection, copy-paste functions - this will require more effort.

  • dop2000 - well that's the thing...it's TECHNICALLY not a game, it's software. So the textbox is useful in it's own right due to the text selection, copy paste functions, right click menu, etc. I agree with you - I absolutely loathe using it, but with what I'm trying to do, it's my only option.

  • There are a couple of plugins that extend textbox capabilities, you may find them useful:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • dop2000 - Interesting; I'll certainly give this a shot. Thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)