From d052479f681fde01d915af24b8d82d8999ee9403 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 27 Sep 2022 18:57:31 -0400 Subject: [PATCH] Input preferences: Use BControlLook::ComposeIconSize(). And do some other cleanup while at it. Fixes #17919. --- src/preferences/input/InputDeviceView.cpp | 23 ++++++++++++----------- src/preferences/input/InputDeviceView.h | 5 ++--- src/preferences/input/InputIcons.cpp | 16 ++++++++++------ src/preferences/input/InputWindow.cpp | 3 ++- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/preferences/input/InputDeviceView.cpp b/src/preferences/input/InputDeviceView.cpp index 4d701f4834..a2ee5429aa 100644 --- a/src/preferences/input/InputDeviceView.cpp +++ b/src/preferences/input/InputDeviceView.cpp @@ -103,7 +103,8 @@ struct DeviceListItemView::Renderer { float ItemWidth() { float width = 4.0f; - width += be_plain_font->StringWidth(fTitle) + 16.0f; + width += be_plain_font->StringWidth(fTitle) + + (fPrimaryIcon != NULL ? fPrimaryIcon->Bounds().Width() : 16.0f); return width; } @@ -129,7 +130,7 @@ DeviceListItemView::Update(BView* owner, const BFont* font) renderer.SetTitle(fTitle); SetRenderParameters(renderer); SetWidth(renderer.ItemWidth()); -}; +} void @@ -140,18 +141,18 @@ DeviceListItemView::DrawItem(BView* owner, BRect frame, bool complete) renderer.SetTitle(Label()); SetRenderParameters(renderer); renderer.Render(owner, frame, complete); -}; +} void DeviceListItemView::SetRenderParameters(Renderer& renderer) { - if (fInputType == MOUSE_TYPE) - renderer.AddIcon(&Icons()->mouseIcon); - - else if (fInputType == TOUCHPAD_TYPE) - renderer.AddIcon(&Icons()->touchpadIcon); - - else if (fInputType == KEYBOARD_TYPE) - renderer.AddIcon(&Icons()->keyboardIcon); + if (Icons() != NULL) { + if (fInputType == MOUSE_TYPE) + renderer.AddIcon(&Icons()->mouseIcon); + else if (fInputType == TOUCHPAD_TYPE) + renderer.AddIcon(&Icons()->touchpadIcon); + else if (fInputType == KEYBOARD_TYPE) + renderer.AddIcon(&Icons()->keyboardIcon); + } } diff --git a/src/preferences/input/InputDeviceView.h b/src/preferences/input/InputDeviceView.h index 4511a86489..2395caab0b 100644 --- a/src/preferences/input/InputDeviceView.h +++ b/src/preferences/input/InputDeviceView.h @@ -52,8 +52,8 @@ public: const char* Label() { return fTitle.String();} - static InputIcons* Icons() {return sIcons;} - static void SetIcons(InputIcons* icons) {sIcons = icons;} + static InputIcons* Icons() { return sIcons; } + static void SetIcons(InputIcons* icons) { sIcons = icons; } protected: struct Renderer; @@ -61,7 +61,6 @@ protected: void SetRenderParameters(Renderer& renderer); private: - static InputIcons* sIcons; BString fTitle; input_type fInputType; diff --git a/src/preferences/input/InputIcons.cpp b/src/preferences/input/InputIcons.cpp index b995060f48..027d02a6e7 100644 --- a/src/preferences/input/InputIcons.cpp +++ b/src/preferences/input/InputIcons.cpp @@ -6,6 +6,7 @@ #include "InputIcons.h" #include +#include #include #include #include @@ -14,17 +15,20 @@ #include "IconHandles.h" -#define ICON_SIZE 15 - -const BRect InputIcons::sBounds(0, 0, ICON_SIZE, ICON_SIZE); +const BRect InputIcons::sBounds; InputIcons::InputIcons() : - mouseIcon(sBounds, B_CMAP8), - touchpadIcon(sBounds, B_CMAP8), - keyboardIcon(sBounds, B_CMAP8) + mouseIcon(NULL, false), + touchpadIcon(NULL, false), + keyboardIcon(NULL, false) { + if (!sBounds.IsValid()) { + *const_cast(&sBounds) = BRect(BPoint(0, 0), + be_control_look->ComposeIconSize(B_MINI_ICON)); + } + app_info info; be_app->GetAppInfo(&info); BFile executableFile(&info.ref, B_READ_ONLY); diff --git a/src/preferences/input/InputWindow.cpp b/src/preferences/input/InputWindow.cpp index 8689288ac1..90d6d8e6d5 100644 --- a/src/preferences/input/InputWindow.cpp +++ b/src/preferences/input/InputWindow.cpp @@ -44,7 +44,8 @@ InputWindow::InputWindow(BRect rect) fDeviceListView = new BListView(B_TRANSLATE("Device List")); fDeviceListView->SetSelectionMessage(new BMessage(ITEM_SELECTED)); fDeviceListView->SetExplicitMinSize( - BSize(32 + fDeviceListView->StringWidth("Extended PS/2 Mouse 1"), + BSize(be_control_look->ComposeIconSize(32).Width() + + fDeviceListView->StringWidth("Extended PS/2 Mouse 1"), B_SIZE_UNSET)); BScrollView* scrollView = new BScrollView(