thierrywtrmz

Villager
Member
Joined
Jan 30, 2020
Messages
23
Reaction score
3
First Language
French
Primarily Uses
RMMV
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.
 

Arctica

The Arbiter of Time
Veteran
Joined
Jul 19, 2021
Messages
85
Reaction score
108
First Language
English
Primarily Uses
RMMZ
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.
 

thierrywtrmz

Villager
Member
Joined
Jan 30, 2020
Messages
23
Reaction score
3
First Language
French
Primarily Uses
RMMV
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)?
 

Arctica

The Arbiter of Time
Veteran
Joined
Jul 19, 2021
Messages
85
Reaction score
108
First Language
English
Primarily Uses
RMMZ
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.
 

thierrywtrmz

Villager
Member
Joined
Jan 30, 2020
Messages
23
Reaction score
3
First Language
French
Primarily Uses
RMMV
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.
 

Attachments

  • Window_CustomBattleEnemy.js
    8.7 KB · Views: 0

Latest Threads

Latest Profile Posts

I'm gonna put my project on pause for a tiny bit so I can explore the engine outside of it... Winging it can only get you so far LMFAO
Have seen some of my favorite people here posting and helping others with questions today -- love to see it!
Haven't been on here actively in awhile, project is going strong my biggest issue is the STORY, i'm refining the plot and learning so much i decided to take a writers class to improve even more but the programming and functionality of the game is stepping up nicely!
Hi everyone! Here's what I'm working on today! It's one of the dorms on campus. I know I said I wouldn't use assets but I reused a few things from the cafeteria hehe.
FCuxBOMXMAICK5e
I added a little squish effect when characters change direction to try and make things a bit more lively. Though it's a bit hard to see on the fast moving guys.
2f4fiuy.gif

Forum statistics

Threads
116,123
Messages
1,095,957
Members
151,534
Latest member
clique
Top