Tabman icon indicating copy to clipboard operation
Tabman copied to clipboard

Wrong element sizing when using separator in TMConstrainedHorizontalBarLayout

Open stefanomondino opened this issue 5 years ago • 3 comments

New Issue Checklist

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 :)

stefanomondino avatar Apr 06 '21 14:04 stefanomondino

Hi! How you change bg color for active button?

Alphacentaura avatar Apr 30 '21 16:04 Alphacentaura

@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)
    }
}

stefanomondino avatar May 01 '21 14:05 stefanomondino

Thanks! Tried to do this in tab button discription, but it is a bit dirty )

Alphacentaura avatar May 03 '21 09:05 Alphacentaura