Go to Page... |
|
Thread Tools | Display Modes |
|
06/08/24, 02:07 PM | #1 |
|
Perhaps the silliest question for this week?
Disclaimer: I'm in the weeds, I've looked high, low, and lower. This is an annoyance that has become a thing ...
The Goal: I'm trying to print info to the chat window in an aligned fashion. I think I am fighting a proportional font issue that prevents me from being able to line things up. At least, that's what I'm telling myself at the moment. Am I wrong? The code: Code:
d(string.format("Bottom test 1: Count (%2d): %10s = %-40s!", 1, 22, "Hello")); d(string.format("Bottom test 2: Count (%2d): %10s = %-40s!", 2, 32, "Hello There")); d(string.format("Bottom test 3: Count (%2d): %10s = %-40s!", 3, 42, " ii Well Hello There")); ![]() Notice that the end of each string (marked by the ! character) is staggered, roughly by the length of the string preceding it. The exclamation points should be lining up? The problem (as I understand it): sprintf should be left justifying the three varying length texts (Hello, Hello There, etc.) and the exclamation point at the end should be in alignment with the one above. But, and hopefully this is obvious in the post, the string in the %-40s section isn't behaving as expected. What is odd to me is that the second %10s strings (22,32,42) seem to be working okay though, granted, they are just numbers so maybe there isn't a lot of variance and this string definition is misbehaving like the 3rd, just not as obviously. Either way, the question: Is there a way to properly format/align this type of output? I've mined zo_strformat, lua's various controls, the wiki and source wherever I could find it - and am trying to avoid opening a whole new window layer where I can control the font ("avoid" is code for "I've tried 2 or 3 different examples/approaches, each resulting in a dismal failure and so I'm really hoping the solution isn't that complicated?") Last edited by Vilkasmanga : 06/08/24 at 02:54 PM. |
![]() |
06/08/24, 03:14 PM | #2 |
You are correct about that. Lua's string.format function is very low level and has no knowledge about fonts, typesetting and everything else that's going on in something as high level as the ESO UI. It simply outputs a number of whitespace characters, which works fine as long as you use a monospaced font.
Your best option is to make use of the padding markup provided by the game to align your text. That will work somewhat fine as long as the user doesn't use an addon to change what font the chat uses. Here's an example how I solved it in LibChatMessage: Lua Code:
Other than that, aligning text is an incredibly difficult problem to solve, especially if you want to make it work with different fonts, sizes, resolutions etc. |
|
![]() |
06/08/24, 04:41 PM | #3 |
|
sirinsidiator - Thank you!
![]() I am glad I wasn't missing something obvious but also greatly appreciate your suggestion - I'm off to work on that! -V |
![]() |
06/09/24, 01:47 PM | #4 | |
|
Update: Workaround in place, things look better - good enough for the next update in a week or two. Thanks go to sirinsidiator, et al.
This mostly works, enough for me to stop chasing the perfect solution (for now). Things typically line up (within a few pixels, typically < 3) and looks okay in chat which is good enough (for now). @sirinsidiator - Thanks again for your help. Formatting aligned output remains a painful endeavor but less so with your suggestions. -V Last edited by Vilkasmanga : 06/13/24 at 09:33 PM. |
|
![]() |
06/09/24, 03:15 PM | #5 | |
Maybe we can find a way to fix it (if it's not beaking any pChat functionality or invalidating the saved history in the SavedVars). |
||
![]() |
06/09/24, 04:59 PM | #6 |
|
Did you see how they handle markup here? maybe it could be of some use to you.
https://github.com/esoui/esoui/blob/...hared.lua#L433 |
![]() |
06/09/24, 07:39 PM | #7 | |
|
I also realized a flaw in my approach of using string length on a link, since the link looks like 10-15 characters but is in fact longer. So, the new approach calculates based on the number of characters in what appears (versus everything that is embedded in the link string which, when printed, may only show 10-15 characters). The new code handles that problem and opens up the door for the approaches here and in sirinsidiator's suggestions as well. Thanks for the suggestion ! -V |
|
![]() |
06/09/24, 07:30 PM | #8 |
|
Baertram - I didn't write anything down, just pivoted when I saw the behavior but I will try to retrace my steps and let you know how that goes. As memory serves, there was code similar to the following that wasn't spaced under one configuration, changing a single checkbox in PChat resolved it. I'll try and find that setting. I'm assuming it was a default but.... we shall see.
The code, which includes sirinsidiator's stuff from above, with variations: Code:
dft( zo_strformat("<time>|u129%:0: :|u[on/off]|u286%:0: :|uEnables or disables the time prefix" .. "\n")); dft( zo_strformat("<chat>|u125%:0: :|u[on/off]|u288%:0: :|uShow time prefix on regular chat" .. "\n")); dft( zo_strformat("Test 1: I am here and |cFF0000apple colored|r and you |u50:0::are here|r")); dft( zo_strformat("Test 2: I am here and |cFF0000apple colored|r and you |u50:0::are here|r")); dft( "Test 3: I am here and |cFF0000apple colored|r and you |u50:0::are here|r - via dft"); d ( "Test 4: I am here and |cFF0000apple colored|r and you |u50:0::are here|r - via d"); dft("Proof of concept"); local out = {} out[#out + 1] = "/chatmessage <command> [argument]" .. "\n"; out[#out + 1] = "<time>|u129%:0: :|u[on/off]|u286%:0: :|uEnables or disables the time prefix" .. "\n"; out[#out + 1] = "<chat>|u125%:0: :|u[on/off]|u288%:0: :|uShow time prefix on regular chat" .. "\n"; out[#out + 1] = "<format>|u62%:0: :|u[auto/12h/24h]|u68%:0: :|uChanges the time format used" .. "\n"; out[#out + 1] = "<tag>|u165%:0: :|u[off/short/long]|u50%:0::|uControls how a message is tagged" .. "\n"; out[#out + 1] = "<history>|u50%:0::|u[on/off]|u286%:0: :|uRestore old chat after login" .. "\n"; out[#out + 1] = "<age>|u147%:0: :|u[seconds]|u200%:0: :|uThe maximum age of restored chat" .. "\n"; out[#out + 1] = "Example: /chatmessage tag short" .. "\n"; d(table.concat(out,"\n")); Code:
local function dft(line) if ( ( FarmersToolkit.FTREP == 1 ) and (type(line) ~= nil) ) then d(FarmersToolkit.FTChat .. line); end end -- function dft |
![]() |
06/13/24, 09:45 PM | #9 | |
|
Since I'm unable to replicate, I've modified the original posting to clarify that PChat isn't a problem but will continue to check as time allows (which, looking at the next two months, won't be much). Sorry for the potential red herring. If I do find anything substantive, I'll let you know - with sufficient detail as to be useful. I've also updated the Farmers Toolkit addon so the original problem is more or less addressed. However, I folded in the test code I used to demonstrate the problem, in case others want to try from their setups. The command "/ft ptest" will produce the output described in the original post. TL;DR - If there are spaces between "you" and "are here", things are working fine. -V |
|
![]() |
06/09/24, 07:33 PM | #10 |
Hint: type(line) will never be nil, it will be "nil" (returns a string)
-> Learned that myself yesterday ![]() |
|
![]() |
06/09/24, 07:39 PM | #11 |
|
|
![]() |
06/10/24, 05:26 AM | #12 |
why check for type(line) ~= "nil" when you can just check for line ~= nil? there is only one value that can be of type nil, so it doesn't make much sense to call a function first to get the type (unless you store the result and check for multiple different types).
![]() |
|
![]() |
06/10/24, 06:24 AM | #13 | |
|
![]() ![]() I started this all less than 6 months ago, having never worked with lua so the learning curve started pretty low. With the help of folks like you, Baertram, Dolgubon and tons of documentation, pointers, suggestions, however, the learning curve has been steep but productive. But yeah, I still have "day one" code that probably needs a re-write. I'm in a kind of liminal space with respect to the addon: not completely lost yet far from being fluent so I'm definitely still in transition. I need to find the balance between "keep learning / trying new things" versus "go back and clean things up". Suggestions like yours show the right / more efficient ways of doing things and I try to fold those into new code (don't always succeed, I'll backslide with type() when the debugging is a slog) but in general, new code today is less cumbersome (though far from efficient or elegant) than last month's or the month before, etc. etc. It is a journey, to be sure, and I appreciate everyone's help along the way. There is a good chance I'll slow development down for a while. Having just posted the latest update, maybe this is a good time to take a break, go back and clean things up. Heck, I may even go crazy and try once more to break things into separate files - crazy talk, I know ![]() Thanks again for your help. -V |
|
![]() |
06/10/24, 07:02 AM | #14 |
You could even just skip the nil check if it's only about chat output for debugging:
Lua Code:
The tostring converts the nil to "nil" so you just see in your debug msg that something was wrong. Or if line usually contains a space at the beginning (not sure if the space is at the end of your FarmersToolkit.FTChat already) you could even do this to add the space if line is nil: Lua Code:
You are welcome to join us here for code questions, "best practices" about splitting up into multiple files et such: https://app.gitter.im/#/room/#esoui_esoui:gitter.im It's often easier to talk about actual code if you can drag&drop files, post blocks more easily and use links to the esoui sources without having to create forum threads and posts. Last edited by Baertram : 06/10/24 at 07:07 AM. |
|
![]() |
06/14/24, 06:52 AM | #15 |
Thanks for the update, if you find the problem again and can relate it to pChat send me a PM and we will try to work something out.
|
|
![]() |
ESOUI » Developer Discussions » General Authoring Discussion » Perhaps the silliest question for this week? |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
![]() |
![]() |
![]() |
|
|