-
-
Notifications
You must be signed in to change notification settings - Fork 786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for stretching tab bar to fill width of tab bar #4403
Conversation
3e3f2dc
to
81ace83
Compare
I have modified the implementation to implement fill directly in the box model. We recompute the width of the fill items as a group, after calculating the available non-static space. The effect is much nicer - tab titles grow to the size needed, up to <width/number of tabs> size. This also lets us avoid trying to pre-calculate the layout max width in the fancy tab bar code itself. It's still possible to overrun the status item if you try real hard. I think it is becuase of the order of computation and floating order. Honestly, i'm likely to take a whack at converting the box model to use cassowary constraints after this patch. I suspect it would be easier to get correct, and faster (because it can incrementally update very quickly for things like window resizes, single item changes, etc) |
I fixed having it run into the right status by doing the following:
I have a branch that converts this into constraints that i'm using to test against. |
This looks good from my build! |
If you want to see a complicated tab formatting setup so you can see how it fills or doesn't, here's one: |
Hi, I discovered this after partially implementing a similar feature, but this is quite a bit better than what I'd gotten done. I wonder, though, if it would be possible to tweak this so that instead of forcing the tabs to fill the bar, it would instead allow them to individually expand up to |
Short answer: It's possible, but it's not super-easy and I don't plan on doing it myself, but you are welcome to. Long answer: However, for something like tab fill, it's like trying to make something work in CSS, which is hard enough, but then it's like trying to make it work in CSS when the underlying CSS engine works only right 80% of the time ;) Originally, early versions of the patch did what you ask, mostly . But because of interesting box model bugs, it would run into/overwrite the right status icon, because of how filling is implemented. across two different children of the same parent. I also believe it would never have worked with bottom tab-bar. You are basically asking for it to float left instead of float right. But if you implement float left, you will also discover it wil not draw the X/etc next to tabs properly in all cases. Fixing this is not easy with the way the layout algorithm works right now. Which is why it now puts them in the same tree and floats them all right. The algorithm used to do layout here only works in the degenerate case that they are all float right. It would not work if they are a mix. To be fair - it didn't work right in this case before i did this either :) Fixing all ofthis is possible, and the algorithms are not theoretically hard, but you will probably spend a lot of time debugging lots of edge cases that exist and trying to figure out why they aren't doing what they are supposed to. Quite honestly, my suggestion is that as this becomes more complicated, time would be better spent moving the box model to use something like taffy, which does exactly what all the box model code is trying to do, but is complete, well tested, and very fast at it. It is almost a mechanical port. I have a port of wezterm to taffy somewhere, that does layout properly in all cases, and enables what you are talking about. It is faster than the current layout engine (even with 100 tabs that can't possibly fit it takes <1ms to do layout), and enables what you are asking for to just work by setting the right layout attributes. In also lets you remove hundreds of lines of complicated layout code. The only slightly difficult part was handling the glyph bounding boxes, which taffy now easily supports with it's measurement function. But i would not go down this path without the overall maintainer being willing to see it happen - i would instead live with always-expanding tabs ;) |
9af8a2b
to
edf389c
Compare
19d8ac0
to
e6387b6
Compare
7cf7c8c
to
e7912bd
Compare
Closing this because i use the branch in my repo a lot and it's going to generate noise here. If we decide we want to look at this, happy to reopen a cleaner version. |
I didn't get a chance to fully review this, but this comment about taffy caught my eye. |
Sounds reasonable to me. This particular PR became complicated/noisy in part because
So it was either "accept some limitations will likely last for a long time" or "see if i could outsource box model solving". The latter turned out to be easier than expected - the representation we use and they use are very close already because everyone seems to have tried to hew to the naming/semantics of CSS. |
This PR is meant to resolve issue #1914
It implements support for filling letting tabs expand to fill the title bar.
At least, about as well as was obvious to me how to do :)
The main issues with the current implementation are:
When computing layout, most people would expect (IMHO) the real tabs to take up all available space except for the width of the left and right status items.Unfortunately, it was not obvious to me how to do this without computing layout twice.
This is exacerbated by the fact that we give the max width to all of the computation functions, and they often try to do reasonable truncation (see #2).Additionally, as far as the window is current, a right status item always exists (AFAICT), so the max title fill of a single tab is really half the space.The best i think makes sense at the moment (not implemented), unless i'm missing something, would be to add options for max width of left/right status items,and use them to account for the items without wasting a full tab width on them.
If there is a way to compute the layout of the right/left status items first, you could get it exactly right.(This was fixed later)
On the second pass, the (previous to this patch) semantic was to pass in first_pass_title_len.min(max_tab_width)
The problem is that this semantic is, IMHO, broken.
Lots of format-tab-title functions truncate, especially if they involve the current working directory.
They then also leave a little space at the end.
Or left truncate and then right truncate.
So something like
When the title runs over during the first pass, we will return a title that is smaller than it needs to be (the - 8).
The second pass will now hand us the old title width instead of the actual max amount we could expand to, because that's the min of (first_pass_title_len, max_tab_width)
We will now truncate even further, despite having plenty of space left in our tab title.
I have changed this second pass to instead use max(title_len, max_tab_width). This will allow functions like the above to work.
Looking at github, most functions act like the above.
On top of this, if you don't do this, there is no way to truncate to anything <= max_width without it giving you a smaller size during pass 2.
This change seemed the better option.