Input preferences: Use BControlLook::ComposeIconSize().

And do some other cleanup while at it.

Fixes #17919.
This commit is contained in:
Augustin Cavalier 2022-09-27 18:57:31 -04:00
parent 6a287ced0b
commit d052479f68
4 changed files with 26 additions and 21 deletions

View File

@ -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);
}
}

View File

@ -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;

View File

@ -6,6 +6,7 @@
#include "InputIcons.h"
#include <Application.h>
#include <ControlLook.h>
#include <File.h>
#include <IconUtils.h>
#include <Resources.h>
@ -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<BRect*>(&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);

View File

@ -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(