From 8672fc2739b8601218f6d0f83a4fe492b7ffb5ae Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 28 Sep 2022 20:03:59 -0400 Subject: [PATCH] InterfaceDefs: Adjust and introduce new spacing/insets constants. * Nothing in the tree and few things outside it used BIG_{SPACING|INSETS}; it seems a value of 15px (at default font size) is not that useful. There are, however, a lot of things around the tree that use multiples of 20px. So, make BIG be that, with the intent to replace those with BIG directly. * Introduce CORNER_{SPACING|INSETS}. There are a lot of applications (e.g. Tracker, Terminal, Debugger etc.) which use scroll bar width/height to metrically align controls with the window frame or with some other control which contains scroll bars. Rather than have to invoke BScrollBar or BControlLook directly to get the value, we should just derive the size of scrollbars from a spacing constant instead and get rid of the custom function. (For now it is just replaced.) This reuses the old values for BIG, as it is equal to 14px at default. * Introduce BORDER_{SPACING|INSETS}. This is equal to the typical border size of 1px at default font size (or lower) and uses floor() instead of ciel() to compute what the size should be (i.e. it will remain 1px at 150%/18pt and only go up at 200%/24pt.) This will allow a lot of the hardcoded border sizes around the tree and elsewhere to use ComposeSpacing() instead. Change-Id: Iaea3fa30364859888e816a9d61ac156268d70758 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5702 Reviewed-by: waddlesplash Reviewed-by: nephele Tested-by: Commit checker robot --- headers/os/interface/InterfaceDefs.h | 6 +++++- headers/private/interface/HaikuControlLook.h | 2 -- src/kits/interface/ControlLook.cpp | 14 ++++++++------ src/kits/interface/HaikuControlLook.cpp | 11 ----------- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/headers/os/interface/InterfaceDefs.h b/headers/os/interface/InterfaceDefs.h index d692a0127a..c5a59b8a80 100644 --- a/headers/os/interface/InterfaceDefs.h +++ b/headers/os/interface/InterfaceDefs.h @@ -239,8 +239,12 @@ enum { B_USE_WINDOW_INSETS = B_USE_WINDOW_SPACING, B_USE_SMALL_SPACING = -1006, B_USE_SMALL_INSETS = B_USE_SMALL_SPACING, - B_USE_BIG_SPACING = -1007, + B_USE_CORNER_SPACING = -1007, + B_USE_CORNER_INSETS = B_USE_CORNER_SPACING, + B_USE_BIG_SPACING = -1008, B_USE_BIG_INSETS = B_USE_BIG_SPACING, + B_USE_BORDER_SPACING = -1009, + B_USE_BORDER_INSETS = B_USE_BORDER_SPACING, }; diff --git a/headers/private/interface/HaikuControlLook.h b/headers/private/interface/HaikuControlLook.h index b8edf7f152..be6f9c624d 100644 --- a/headers/private/interface/HaikuControlLook.h +++ b/headers/private/interface/HaikuControlLook.h @@ -337,8 +337,6 @@ public: uint32 flags = 0, uint32 borders = B_ALL_BORDERS, orientation orientation = B_HORIZONTAL); - virtual float GetScrollBarWidth( - orientation orientation = B_VERTICAL); protected: void _DrawButtonFrame(BView* view, BRect& rect, diff --git a/src/kits/interface/ControlLook.cpp b/src/kits/interface/ControlLook.cpp index 6081cffded..85f882048b 100644 --- a/src/kits/interface/ControlLook.cpp +++ b/src/kits/interface/ControlLook.cpp @@ -3,9 +3,9 @@ * Distributed under the terms of the MIT License. */ - #include +#include #include @@ -37,8 +37,13 @@ BControlLook::ComposeSpacing(float spacing) return be_control_look->DefaultItemSpacing(); case B_USE_SMALL_SPACING: return ceilf(be_control_look->DefaultItemSpacing() * 0.7f); + case B_USE_CORNER_SPACING: + return ceilf(be_control_look->DefaultItemSpacing() * 1.273f); case B_USE_BIG_SPACING: - return ceilf(be_control_look->DefaultItemSpacing() * 1.3f); + return ceilf(be_control_look->DefaultItemSpacing() * 1.8f); + + case B_USE_BORDER_SPACING: + return std::max(1.0f, floorf(be_control_look->DefaultItemSpacing() / 11.0f)); } return spacing; @@ -86,10 +91,7 @@ BControlLook::GetInsets(frame_type frameType, background_type backgroundType, float BControlLook::GetScrollBarWidth(orientation orientation) { - // this matches HaikuControlLook.cpp currently - if (be_plain_font->Size() <= 12.0f) - return 14.0f; - return be_plain_font->Size() / 12.0f * 14.0f; + return ComposeSpacing(B_USE_CORNER_SPACING); } diff --git a/src/kits/interface/HaikuControlLook.cpp b/src/kits/interface/HaikuControlLook.cpp index edd31589d1..ab2ef31d8f 100644 --- a/src/kits/interface/HaikuControlLook.cpp +++ b/src/kits/interface/HaikuControlLook.cpp @@ -3840,17 +3840,6 @@ HaikuControlLook::_FillGlossyGradient(BView* view, const BRect& rect, } -float -HaikuControlLook::GetScrollBarWidth(orientation orientation) -{ - // HaikuControlLook does not make a distinction between the - // width and height of the scrollbar, but other controllooks may - if (be_plain_font->Size() <= 12.0f) - return 14.0f; - return be_plain_font->Size() / 12.0f * 14.0f; -} - - void HaikuControlLook::_MakeGradient(BGradientLinear& gradient, const BRect& rect, const rgb_color& base, float topTint, float bottomTint,