Skip to content

Commit 3f48279

Browse files
committed
Merge remote-tracking branch 'upstream/master' into mici-enter
2 parents 4fbb157 + 85b9f89 commit 3f48279

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

selfdrive/ui/mici/widgets/dialog.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def _render(self, _) -> DialogResult:
132132
class BigInputDialog(BigDialogBase):
133133
BACK_TOUCH_AREA_PERCENTAGE = 0.2
134134
BACKSPACE_RATE = 25 # hz
135+
TEXT_INPUT_SIZE = 35
135136

136137
def __init__(self,
137138
hint: str,
@@ -179,53 +180,44 @@ def _update_state(self):
179180
self._backspace_held_time = None
180181

181182
def _render(self, _):
182-
text_input_size = 35
183-
184183
# draw current text so far below everything. text floats left but always stays in view
185184
text = self._keyboard.text()
186185
candidate_char = self._keyboard.get_candidate_character()
187-
text_size = measure_text_cached(gui_app.font(FontWeight.ROMAN), text + candidate_char or self._hint_label.text, text_input_size)
188-
text_x = PADDING / 2 + self._enter_img.width
189-
190-
# text needs to move left if we're at the end where right button is
191-
text_rect = rl.Rectangle(text_x,
192-
int(self._rect.y + PADDING),
193-
# clip width to right button when in view
194-
int(self._rect.width - text_x - PADDING / 2 - self._enter_img.width + 5), # TODO: why 5?
195-
int(text_size.y))
186+
text_size = measure_text_cached(gui_app.font(FontWeight.ROMAN), text + candidate_char or self._hint_label.text, self.TEXT_INPUT_SIZE)
196187

197-
# draw rounded background for text input
198188
bg_block_margin = 5
199-
text_field_rect = rl.Rectangle(text_rect.x - bg_block_margin, text_rect.y - bg_block_margin,
200-
text_rect.width + bg_block_margin * 2, text_input_size + bg_block_margin * 2)
189+
text_x = PADDING * 2 + self._enter_img.width + bg_block_margin
190+
text_field_rect = rl.Rectangle(text_x, int(self._rect.y + PADDING) - bg_block_margin,
191+
int(self._rect.width - text_x - PADDING * 2 - self._enter_img.width) - bg_block_margin * 2,
192+
int(text_size.y))
201193

202194
# draw text input
203195
# push text left with a gradient on left side if too long
204-
if text_size.x > text_rect.width:
205-
text_x -= text_size.x - text_rect.width
196+
if text_size.x > text_field_rect.width:
197+
text_x -= text_size.x - text_field_rect.width
206198

207-
rl.begin_scissor_mode(int(text_rect.x), int(text_rect.y), int(text_rect.width), int(text_rect.height))
208-
rl.draw_text_ex(gui_app.font(FontWeight.ROMAN), text, rl.Vector2(text_x, text_rect.y), text_input_size, 0, rl.WHITE)
199+
rl.begin_scissor_mode(int(text_field_rect.x), int(text_field_rect.y), int(text_field_rect.width), int(text_field_rect.height))
200+
rl.draw_text_ex(gui_app.font(FontWeight.ROMAN), text, rl.Vector2(text_x, text_field_rect.y), self.TEXT_INPUT_SIZE, 0, rl.WHITE)
209201

210202
# draw grayed out character user is hovering over
211203
if candidate_char:
212-
candidate_char_size = measure_text_cached(gui_app.font(FontWeight.ROMAN), candidate_char, text_input_size)
204+
candidate_char_size = measure_text_cached(gui_app.font(FontWeight.ROMAN), candidate_char, self.TEXT_INPUT_SIZE)
213205
rl.draw_text_ex(gui_app.font(FontWeight.ROMAN), candidate_char,
214-
rl.Vector2(min(text_x + text_size.x, text_rect.x + text_rect.width) - candidate_char_size.x, text_rect.y),
215-
text_input_size, 0, rl.Color(255, 255, 255, 128))
206+
rl.Vector2(min(text_x + text_size.x, text_field_rect.x + text_field_rect.width) - candidate_char_size.x, text_field_rect.y),
207+
self.TEXT_INPUT_SIZE, 0, rl.Color(255, 255, 255, 128))
216208

217209
rl.end_scissor_mode()
218210

219211
# draw gradient on left side to indicate more text
220-
if text_size.x > text_rect.width:
221-
rl.draw_rectangle_gradient_h(int(text_rect.x), int(text_rect.y), 80, int(text_rect.height),
212+
if text_size.x > text_field_rect.width:
213+
rl.draw_rectangle_gradient_h(int(text_field_rect.x), int(text_field_rect.y), 80, int(text_field_rect.height),
222214
rl.BLACK, rl.BLANK)
223215

224216
# draw cursor
225217
if text:
226218
blink_alpha = (math.sin(rl.get_time() * 6) + 1) / 2
227-
cursor_x = min(text_x + text_size.x + 3, text_rect.x + text_rect.width)
228-
rl.draw_rectangle_rounded(rl.Rectangle(int(cursor_x), int(text_rect.y), 4, int(text_size.y)),
219+
cursor_x = min(text_x + text_size.x + 3, text_field_rect.x + text_field_rect.width)
220+
rl.draw_rectangle_rounded(rl.Rectangle(int(cursor_x), int(text_field_rect.y), 4, int(text_size.y)),
229221
1, 4, rl.Color(255, 255, 255, int(255 * blink_alpha)))
230222

231223
# draw backspace icon with nice fade
@@ -260,7 +252,6 @@ def _render(self, _):
260252
# draw debugging rect bounds
261253
if DEBUG:
262254
rl.draw_rectangle_lines_ex(text_field_rect, 1, rl.Color(100, 100, 100, 255))
263-
rl.draw_rectangle_lines_ex(text_rect, 1, rl.Color(0, 255, 0, 255))
264255
rl.draw_rectangle_lines_ex(self._top_right_button_rect, 1, rl.Color(0, 255, 0, 255))
265256
rl.draw_rectangle_lines_ex(self._top_left_button_rect, 1, rl.Color(0, 255, 0, 255))
266257

0 commit comments

Comments
 (0)