Possible bug in FlTabs::tabs_position()

Skip to first unread message


Apr 11, 2023, 5:18:49 PMApr 11
to fltk.general

I have inherited Fl_Tabs for my own tabs widget. When I display it I occasionally get one of the tabs not displayed. I tried to understand the algorithm in tabs_position() that adjusts the tab widths if they are larger than the Fl_Tabs width but failed. I overrode tabs_position() to implement a different algorithm.

Keep the selected tab width as calculated and then shrink the other tab widths by the same ratio.

I replaced the correction code with the following.

// Change the algorithm if they are too big
// Reduce all deselected widths by the apportioned oversize
// Use fixed point arithmetic (x2^10) to reduce rounding error
int delta = 1024 * (r - tab_width[selected]) / (tab_pos[i] - tab_width[selected]);
for (i = 0; i < nc; i++) {
if (i != selected) {
tab_width[i] = tab_width[i] * delta / 1024;
tab_pos[i + 1] = tab_pos[i] + tab_width[i] + BORDER;
// If we haven't used the full width, increase the size of the last tab to compensate
if (tab_pos[i] < r) {
tab_width[i - 1] = r - tab_pos[i];
tab_pos[i] = r;
return selected;

I am using a fairly old version of fLTK 1.4. It doesn't yet have the change that introduced the when(FL_WHEN_CLOSED) feature for Fl_Tabs.

Regards Phil.

Matthias Melcher

Apr 11, 2023, 7:31:40 PMApr 11
to fltk.general
Made into a Bug Report on GitHub. https://github.com/fltk/fltk/issues/718 . Please answer over there if this behaviour is still observable in the current version. I rewrote a lot of code. Also, Iis there a way to trigger the bug that you observed, so I can repeat it? Thanks.

Reply all
Reply to author
0 new messages