1/*
2 * Copyright 2021, Pascal R. G. Abresch, nep@packageloss.eu.
3 * Distributed under the terms of the MIT License.
4 */
5
6#include <ControlLook.h>
7#include <View.h>
8
9
10namespace BPrivate {
11
12
13void
14AdoptScrollBarFontSize(BView* view)
15{
16	float maxSize = be_control_look->GetScrollBarWidth();
17	BFont testFont = be_plain_font;
18	float currentSize;
19	font_height fontHeight;
20
21	float minFontSize = 0.0f;
22	float maxFontSize = 48.0f;
23
24	while (maxFontSize - minFontSize > 1.0f) {
25		float midFontSize = (maxFontSize + minFontSize) / 2.0f;
26
27		testFont.SetSize(midFontSize);
28		testFont.GetHeight(&fontHeight);
29		currentSize = fontHeight.ascent + fontHeight.descent;
30
31		if (currentSize > maxSize)
32			maxFontSize = midFontSize;
33		else
34			minFontSize = midFontSize;
35	}
36
37	view->SetFontSize(minFontSize);
38}
39
40
41} // namespace BPrivate
42