Skip to content
⌘ NSIS Forum Archive

Vertical layout in .ini files

9 posts

Angus Leeming#

Vertical layout in .ini files

Is it possible to discover how much vertical space a Text object in a .ini file is really taking up? If I'm inserting translated strings (possibly multi-line), it would be nice to make the vertical layout look good as opposed to my current "leave lots of space just in case".

Angus
Afrow UK#
WriteINIStr will put in new lines for new key=value's if no more exist, so you don't need to leave any blank lines.

-Stu
Angus Leeming#
I think we misunderstand each other. I have a .ini file containing

widget1
text2
widget3

I was wondering if there was any way to find out how much vertical space text2 actually took up (how many lines) so that I could position widget3 correctly.

Angus

ps WriteINIStr doesn't work for me. I have to use MUI_INSTALLOPTIONS_WRITE.
A.
Afrow UK#
Right I see 🙂
MUI_INSTALLOPTIONS_WRITE is really a macro with WriteINIStr in it. With WriteINIStr you need to specify $PLUGINSDIR in the INI file path.

I'll have to write a Function to do this check (will use FileOpen and FileRead).
I'm wondering though that if you have an = sign on one of the other lines, it will stop there thinking that's another key=value... Will that cause any problems in your case?

-Stu
Afrow UK#
I just got round to writing the function. Now I'm going to submit it on the Wiki but I'm a bit lost at the system there.

-Stu
Angus Leeming#
Thanks, Stu. I've tried it but it doesn't do what I'm looking for.

StrCpy $0 "a really long line that wraps over several lines a really long line that wraps over several lines a really long line that wraps over several lines a really long line that wraps over several lines"
!insertmacro MUI_INSTALLOPTIONS_WRITE "myfile.ini" "Field 1" "Text" "$0"
${GetValueVertSpace} $1 "myfile.ini" "Field 1" "Text"
MessageBox MB_OK "Number of lines: $1"

This returns "1" rather than the "3" or "4" I was hoping for.

In turn, that's not surprising. The number of lines is a function of how the the string is displayed in the dialog, not how it's stored in the .ini file.

Anyway, many thanks for your time and effort.
Angus
Afrow UK#edited
If you want it to find out how many lines it takes up when placing the text in a label, then that's completely different. It won't work properly by counting the number of characters, because font sizes and types may vary from system to system, but it's a start.
You can also however chop a string down to a certian length using this function:


-Stu