From 73ea36decace616f1da0e154de9544dc758e6124 Mon Sep 17 00:00:00 2001
From: Laurent Chea <contact@laurentchea.com>
Date: Thu, 4 Dec 2014 22:44:25 +0100
Subject: [PATCH] Fix alignment in TextControl widgets (fixes #8391)
---
src/kits/interface/TextInput.cpp | 33 +++++++++++++++++++++++++++------
1 file changed, 27 insertions(+), 6 deletions(-)
diff --git a/src/kits/interface/TextInput.cpp b/src/kits/interface/TextInput.cpp
index 9b1b570..d9e4a96 100644
a
|
b
|
_BTextInput_::KeyDown(const char* bytes, int32 numBytes)
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
| 121 | |
121 | 122 | void |
122 | 123 | _BTextInput_::MakeFocus(bool state) |
123 | 124 | { |
… |
… |
_BTextInput_::MinSize()
|
155 | 156 | { |
156 | 157 | BSize min; |
157 | 158 | min.height = ceilf(LineHeight(0) + 2.0); |
158 | | // we always add at least one pixel vertical inset top/bottom for |
159 | | // the text rect. |
| 159 | // we always add at least one pixel vertical inset top/bottom for |
| 160 | // the text rect. |
160 | 161 | min.width = min.height * 3; |
161 | 162 | return BLayoutUtils::ComposeSize(ExplicitMinSize(), min); |
162 | 163 | } |
… |
… |
_BTextInput_::AlignTextRect()
|
170 | 171 | // the text rect to be in the middle, normally this means there |
171 | 172 | // is one pixel spacing on each side |
172 | 173 | BRect textRect(Bounds()); |
173 | | textRect.left = 0.0; |
174 | | float vInset = max_c(1, floorf((textRect.Height() - LineHeight(0)) / 2.0)); |
| 174 | float vInset = max_c(1, |
| 175 | floorf((textRect.Height() - LineHeight(0)) / 2.0)); |
175 | 176 | float hInset = 2; |
| 177 | float textFontWidth = TextRect().right; |
| 178 | |
| 179 | if (be_control_look != NULL) |
| 180 | { |
| 181 | switch(Alignment()) |
| 182 | { |
| 183 | case B_ALIGN_LEFT: |
| 184 | hInset = be_control_look->DefaultLabelSpacing(); |
| 185 | break; |
| 186 | |
| 187 | case B_ALIGN_RIGHT: |
| 188 | hInset = textRect.right - textFontWidth; |
| 189 | hInset -= be_control_look->DefaultLabelSpacing(); |
| 190 | break; |
176 | 191 | |
177 | | if (be_control_look != NULL) |
178 | | hInset = be_control_look->DefaultLabelSpacing(); |
| 192 | case B_ALIGN_CENTER: |
| 193 | hInset = (textRect.right - textFontWidth)/ 2.0; |
| 194 | break; |
| 195 | |
| 196 | default: |
| 197 | break; |
| 198 | } |
| 199 | } |
179 | 200 | |
180 | 201 | textRect.InsetBy(hInset, vInset); |
181 | 202 | SetTextRect(textRect); |