ui: keyboard improvements (#35906)

* better

* miss this one
pull/35907/head
Maxime Desroches 5 days ago committed by GitHub
parent 0b855a93d7
commit 8cce8cf3f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      system/ui/widgets/button.py
  2. 20
      system/ui/widgets/keyboard.py

@ -16,6 +16,7 @@ class ButtonStyle(IntEnum):
ACTION = 4
LIST_ACTION = 5 # For list items with action buttons
NO_EFFECT = 6
KEYBOARD = 7
class TextAlignment(IntEnum):
@ -38,6 +39,7 @@ BUTTON_TEXT_COLOR = {
ButtonStyle.ACTION: rl.Color(0, 0, 0, 255),
ButtonStyle.LIST_ACTION: rl.Color(228, 228, 228, 255),
ButtonStyle.NO_EFFECT: rl.Color(228, 228, 228, 255),
ButtonStyle.KEYBOARD: rl.Color(221, 221, 221, 255),
}
BUTTON_BACKGROUND_COLORS = {
@ -48,6 +50,7 @@ BUTTON_BACKGROUND_COLORS = {
ButtonStyle.ACTION: rl.Color(189, 189, 189, 255),
ButtonStyle.LIST_ACTION: rl.Color(57, 57, 57, 255),
ButtonStyle.NO_EFFECT: rl.Color(51, 51, 51, 255),
ButtonStyle.KEYBOARD: rl.Color(68, 68, 68, 255),
}
BUTTON_PRESSED_BACKGROUND_COLORS = {
@ -58,6 +61,7 @@ BUTTON_PRESSED_BACKGROUND_COLORS = {
ButtonStyle.ACTION: rl.Color(130, 130, 130, 255),
ButtonStyle.LIST_ACTION: rl.Color(74, 74, 74, 74),
ButtonStyle.NO_EFFECT: rl.Color(51, 51, 51, 255),
ButtonStyle.KEYBOARD: rl.Color(51, 51, 51, 255),
}
_pressed_buttons: set[str] = set() # Track mouse press state globally

@ -79,6 +79,8 @@ class Keyboard(Widget):
self._render_return_status = -1
self._cancel_button = Button("Cancel", self._cancel_button_callback)
self._eye_button = Button("", self._eye_button_callback, button_style=ButtonStyle.TRANSPARENT)
self._eye_open_texture = gui_app.texture("icons/eye_open.png", 81, 54)
self._eye_closed_texture = gui_app.texture("icons/eye_closed.png", 81, 54)
self._key_icons = {
@ -96,10 +98,11 @@ class Keyboard(Widget):
if key in self._key_icons:
texture = self._key_icons[key]
self._all_keys[key] = Button("", partial(self._key_callback, key), icon=texture,
button_style=ButtonStyle.PRIMARY if key == ENTER_KEY else ButtonStyle.NORMAL)
button_style=ButtonStyle.PRIMARY if key == ENTER_KEY else ButtonStyle.KEYBOARD)
else:
self._all_keys[key] = Button(key, partial(self._key_callback, key))
self._all_keys[CAPS_LOCK_KEY] = Button("", partial(self._key_callback, CAPS_LOCK_KEY), icon=self._key_icons[CAPS_LOCK_KEY])
self._all_keys[key] = Button(key, partial(self._key_callback, key), button_style=ButtonStyle.KEYBOARD, font_size=85)
self._all_keys[CAPS_LOCK_KEY] = Button("", partial(self._key_callback, CAPS_LOCK_KEY), icon=self._key_icons[CAPS_LOCK_KEY],
button_style=ButtonStyle.KEYBOARD)
@property
def text(self):
@ -115,6 +118,9 @@ class Keyboard(Widget):
self._title = title
self._sub_title = sub_title
def _eye_button_callback(self):
self._password_mode = not self._password_mode
def _cancel_button_callback(self):
self.clear()
self._render_return_status = 0
@ -198,16 +204,12 @@ class Keyboard(Widget):
eye_texture = self._eye_closed_texture if self._password_mode else self._eye_open_texture
eye_rect = rl.Rectangle(input_rect.x + input_rect.width - 90, input_rect.y, 80, input_rect.height)
self._eye_button.render(eye_rect)
eye_x = eye_rect.x + (eye_rect.width - eye_texture.width) / 2
eye_y = eye_rect.y + (eye_rect.height - eye_texture.height) / 2
rl.draw_texture_v(eye_texture, rl.Vector2(eye_x, eye_y), rl.WHITE)
# Handle click on eye icon
if rl.is_mouse_button_pressed(rl.MouseButton.MOUSE_BUTTON_LEFT) and rl.check_collision_point_rec(
rl.get_mouse_position(), eye_rect
):
self._password_mode = not self._password_mode
else:
self._input_box.render(input_rect)

Loading…
Cancel
Save