Open connermcd opened 12 years ago
I think something like this is a good idea. I think I would prefer to incorporate it into the format string directly though, but I will see what I can do. Thanks for the suggestions!
This could be solved similar to how multi-line equations can be aligned in LaTeX, where one may insert a &
to mark a place that should be aligned with the corresponding ampersand on the other lines.
To elaborate a bit, I think specifying an alignment string is a) limiting the possibilities for layout (imagine just aligning things with just a space in between) and b) prone to errors (" - " seems like it could be a common divider, but also occurs in song titles).
Wheee, I was just searching for some functionality like this.
I really like the approach of having some sort of explicit marker in the songformat string, that says what should be aligned.
But I would also suggest a slightly different approach: Have a marker that says: Up to here should fill up
It looks better. Consider the case where there are only songs with short artist names in the list. Now I insert one song with a long artist name. To keep alignment, the tab stop where all lines are aligned would need to move to accomodate the long artist name. So the screen has to be redrawn and the song titles move to the right. Now, I add the next song...
Difficulty of implementation. 1.) Possibility: Alignment is kept only for the songs currently visible on screen. When scrolling, we would need to re-check, if the tab stop till provides enough space for all artist names. So we would need to re-iterate the visible lines looing for the longes tab stop for each line that the user scrolles. Inefficient and it would lead to the same ugly moving effect described before. 2.) Alignment could be done globally, fitting all items in the list. It looks good, at least when scrolling, and does not complicate scrolling very much. However, obtaining the longes tab stop is a problem. Or, to be more exact, keeping it. Assume the user adds songs to the list. We can simply compare that songs tab stop requirement (artist name length) and if it is bigger than the current tab stop, update it. But when the user deletes songs, there will be the moment, when the song with the longes tab stop is removed. We would now need to re-scan all remaining songs in the list to find the new longes tab stop. This would turn list removal from O(1) to O(n) complexity. Probably no good idea.
Instead we could add two new tokens to the format string:
Pros:
Btw: I like the coding style. Not many comments, but well readable :)
Update: That means, only the parsing function void ScrollWindow::Print(uint32_t line) const needs an update.
Side note: I noticed, that using the $A to mean align really was the most intuitive "name" and since I don't really see why one would need absolute alignment, I used that name. However, really any letter can be chosen by changing 'A' to another letter in two places.
@mox-mox Thanks! On initial testing this appears to work as stated. It fails hard when the specified percentage is <= 9 as stated in the code. Also, when the playlist only contains a few songs with short titles this approach spaces them out quite a bit, but it's definitely a useful contribution.
About the numbers: Numbers smaller than 10 work fine for me, if stated as e.g. $A05. I wrote a check to allow a variable number of digits from 0 to 3 but I think this is not really sensible. It adds quite a bit of conditional code at runtime while providing relatively little improvement. Aligning to 100% is not sensible as there would be no space left to put the aligned text and for all other percentages, the two-digit style of writing the numbers is sufficient.
About the spacing: The spacing is admittedly not so nice and makes it a tad hard to find the remaining part of the line. For testing, I used an underscore as fill character which made it easier to follow the line. Maybe having the fill character as a setting would help here? Edit: I tested that, and I find it help full :) See the updated pull request.
I love the new custom format options! I do feel like it's lacking some alignment though. It would be great if you could specify a character to align on so that this:
would look like this:
if I set my alignment string to / - / (notice the spaces so The Pick-Up doesn't get aligned). Would be a great enhancement!