ui(raylib): update spinner vertical pos (#35051)

Adjust the spinner vertical position when displaying text or a progress bar

- When displaying the progress bar, center the comma logo and spinner in the middle of the screen
- When displaying text, center the entire content vertically

Also updated `wrap_text` to not include an empty line in the array if it's the first line, so that `wrap_text("")` always returns `[]`
pull/35052/head
Cameron Clough 3 days ago committed by GitHub
parent 651ff78cb0
commit c9259a9bcf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 23
      system/ui/spinner.py
  2. 4
      system/ui/text.py

@ -12,7 +12,6 @@ PROGRESS_BAR_WIDTH = 1000
PROGRESS_BAR_HEIGHT = 20 PROGRESS_BAR_HEIGHT = 20
DEGREES_PER_SECOND = 360.0 # one full rotation per second DEGREES_PER_SECOND = 360.0 # one full rotation per second
MARGIN_H = 100 MARGIN_H = 100
MARGIN_V = 200
TEXTURE_SIZE = 360 TEXTURE_SIZE = 360
FONT_SIZE = 88 FONT_SIZE = 88
LINE_HEIGHT = 96 LINE_HEIGHT = 96
@ -43,7 +42,22 @@ class Spinner:
self._wrapped_lines = wrap_text(text, FONT_SIZE, gui_app.width - MARGIN_H) self._wrapped_lines = wrap_text(text, FONT_SIZE, gui_app.width - MARGIN_H)
def render(self): def render(self):
center = rl.Vector2(gui_app.width / 2.0, gui_app.height / 2.0) with self._lock:
progress = self._progress
wrapped_lines = self._wrapped_lines
if wrapped_lines:
# Calculate total height required for spinner and text
spacing = 50
total_height = TEXTURE_SIZE + spacing + len(wrapped_lines) * LINE_HEIGHT
center_y = (gui_app.height - total_height) / 2.0 + TEXTURE_SIZE / 2.0
else:
# Center spinner vertically
spacing = 150
center_y = gui_app.height / 2.0
y_pos = center_y + TEXTURE_SIZE / 2.0 + spacing
center = rl.Vector2(gui_app.width / 2.0, center_y)
spinner_origin = rl.Vector2(TEXTURE_SIZE / 2.0, TEXTURE_SIZE / 2.0) spinner_origin = rl.Vector2(TEXTURE_SIZE / 2.0, TEXTURE_SIZE / 2.0)
comma_position = rl.Vector2(center.x - TEXTURE_SIZE / 2.0, center.y - TEXTURE_SIZE / 2.0) comma_position = rl.Vector2(center.x - TEXTURE_SIZE / 2.0, center.y - TEXTURE_SIZE / 2.0)
@ -57,11 +71,6 @@ class Spinner:
rl.draw_texture_v(self._comma_texture, comma_position, rl.WHITE) rl.draw_texture_v(self._comma_texture, comma_position, rl.WHITE)
# Display progress bar or text based on user input # Display progress bar or text based on user input
y_pos = rl.get_screen_height() - MARGIN_V - PROGRESS_BAR_HEIGHT
with self._lock:
progress = self._progress
wrapped_lines = self._wrapped_lines
if progress is not None: if progress is not None:
bar = rl.Rectangle(center.x - PROGRESS_BAR_WIDTH / 2.0, y_pos, PROGRESS_BAR_WIDTH, PROGRESS_BAR_HEIGHT) bar = rl.Rectangle(center.x - PROGRESS_BAR_WIDTH / 2.0, y_pos, PROGRESS_BAR_WIDTH, PROGRESS_BAR_HEIGHT)
rl.draw_rectangle_rounded(bar, 1, 10, DARKGRAY) rl.draw_rectangle_rounded(bar, 1, 10, DARKGRAY)

@ -21,7 +21,9 @@ def wrap_text(text, font_size, max_width):
for paragraph in text.split("\n"): for paragraph in text.split("\n"):
if not paragraph.strip(): if not paragraph.strip():
lines.append("") # Don't add empty lines first, ensuring wrap_text("") returns []
if lines:
lines.append("")
continue continue
indent = re.match(r"^\s*", paragraph).group() indent = re.match(r"^\s*", paragraph).group()
current_line = indent current_line = indent

Loading…
Cancel
Save