Skip to content

Excess vertical space allocated to toolbar as more trackbars are added in WinAPI HighGUI backend #22769

@dan-masek

Description

@dan-masek

Windows 10 (and likely others)
OpenCV 4.6.0 (and likely going way back)

Related to #22766

C++ code to reproduce:

#include "opencv2/highgui.hpp"

int main()
{
    std::string const window_name{ "TrackBars" };
    cv::namedWindow(window_name, cv::WINDOW_AUTOSIZE);
    cv::resizeWindow(window_name, {500, 600 });
    cv::createTrackbar("Slider 1", window_name, nullptr, 255);
    cv::waitKey();
    cv::createTrackbar("Slider 2", window_name, nullptr, 255);
    cv::waitKey();
    cv::createTrackbar("Slider 3", window_name, nullptr, 255);
    cv::waitKey();
    cv::createTrackbar("Slider 4", window_name, nullptr, 255);
    cv::waitKey();
    return 0;
}

Observe the growing blank area at the bottom of the toolbar, as controls are added:
image
image
image
image


Problem is a combination of two factors. First of all, separators are added between the trackbar placeholders, and those end up each taking up a separate row as well:

if (bcount > 1)
{
/* If this is not the first button then we need to
separate it from the previous one */
tbs.iBitmap = 0;
tbs.idCommand = bcount; // Set button id to it's number
tbs.iString = 0;
tbs.fsStyle = TBSTYLE_SEP;
tbs.fsState = TBSTATE_ENABLED;
SendMessage(window.toolbar.toolbar, TB_ADDBUTTONS, 1, (LPARAM)&tbs);
// Retrieve current buttons count
bcount = (int)SendMessage(window.toolbar.toolbar, TB_BUTTONCOUNT, 0, 0);
}

However, to set the height of the toolbar area, we simply multiply the number of rows by the height of a single trackbar:

minmax->ptMinTrackSize.y += window.toolbar.rows*(rect.bottom - rect.top);

Since every second row is a separator, which is much less tall than the actual trackbar, we end up overestimating the space needed.


Unless there is some variant of windows which requires those separators, it may be the best to just get rid of them. This is what it looks like with no separators (and with resized window):

image
image

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions