Wrong element sizing when using separator in TMConstrainedHorizontalBarLayout
New Issue Checklist
- [x] Updated Tabman to the latest version
- [x] I took a look at the Troubleshooting Guide
- [x] I searched for existing GitHub issues
Issue Description
With #564 I've corrected a bug in separators (#563) in bars where separators itself were constrained to a width equal to every button item.
To correct this, I've applied a constant negative value to the proportional width constraint of every button to take into account the separator width: example: 5 elements in a bar would have a 20% parent width constraint minus the separator width.
This calculation is not 100% right, since we always have n - 1 separators in a bar, where n is the total amount of buttons. Therefore, the offset applied to the constant should be (separatorWidth * (n - 1)) / n
It's something really not noticeable when using normal buttons: usually, separators are narrow and the practical result is having the last item wider than the others (by a pixel or two).
In my case, however, I'm applying a background color to the currently selected item: if this item is the last one, with a 1px separator, I'm seeing a small gap between the last button (with tinted background) and the bar. I'm using purple over white, so this is really noticeable and annoying.
I'll try to take care of this personally.
Cheers :)
Hi! How you change bg color for active button?
@Alphacentaura by overriding the Button class used in the pager with something like this:
class TabPagerButton: Tabman.TMBarButton {
override func update(for selectionState: TMBarButton.SelectionState) {
switch selectionState {
case .selected:
backgroundColor = .red
default:
backgroundColor = .clear
}
super.update(for: selectionState)
}
}
Thanks! Tried to do this in tab button discription, but it is a bit dirty )