Hey all.
I'm trying to change the size of a selectable item in a window.
I would like it fo fit the size of the content. As it is now, when an item name is short, the item rect has available space, and when the name is too long, the text is altered to fit the window.
I noticed the measuretextwidth function, but I can't figure out how to use it.
I'm pretty much sure I should use it in the rect.width or in the itemWidth function but all my attempts failed.
Please enlighten me.
So that there's no confusion, drawText(text, x, y, width, align) where width can be either the rectangle's width or any predefined width. In your case, text will have to conform to the window(get smushed) if it's longer than the window's width. If you want the text to fit into the window without any conformity, you'll have to adjust the width of the window to that of the width of the text.
That's what I'm asking, sorry if I wasn't many enough (any) sense.
So how can I use this measuretextwidth function with a variable (since I want to do this to an item in a selectable window)?
It will return the width of the text (in pixels) so you can assign it to that variable and then pass it to the width parameter for draw text.
You have the other option of changing the font size of the text(this.contents.fontSize). The font size will work for that window only, so you can reduce it as low as you can til it fits. Unlike width comformity, it wont be "smushed" but obviously it can get progressively hard to read the smaller you need to make it.
If you still have trouble, tell me what your text says, and I'll need the width and height of your rectangle.
Hey,
sorry for the late answer, I've been unable to work on the project last month.
And I'm sorry to say I still can't make it work, so I will try to explain more precisely.
I'm working on a custom enemy window (Window_BattleEnemy).
The text is the name of the currently selected enemy.
The height of the rectangle is the default height of an itemrect, and I'm ok with it.
The width of the rectangle is currently the width of the enemy window (maxcols is 1), defined by a function. I'd like it to fit the width of the enemy name (long window for long name, short window for short name).
I'm completely lost...
I'll attach my script, in case someone is willing to take a look.
Moved to: Learning Javascript
It's been some time already but I got what I wanted doing a custom itemrect function with :
rect.width = this.textWidth($gameParty.battleMembers()[index].name())
Thanks for all the replies