mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-21 09:12:25 +08:00
python ui: display FPS on top-left corner if DEBUG_FPS=1 (#34595)
* display FPS on top-left corner if DEBUG_FPS=1 * use generator * use rl.draw_fps
This commit is contained in:
@@ -8,6 +8,9 @@ DEFAULT_TEXT_SIZE = 60
|
||||
DEFAULT_FPS = 60
|
||||
FONT_DIR = os.path.join(BASEDIR, "selfdrive/assets/fonts")
|
||||
|
||||
DEBUG_FPS = os.getenv("DEBUG_FPS") == '1'
|
||||
|
||||
|
||||
class FontWeight(IntEnum):
|
||||
BLACK = 0
|
||||
BOLD = 1
|
||||
@@ -58,6 +61,18 @@ class GuiApplication:
|
||||
|
||||
rl.close_window()
|
||||
|
||||
def render(self):
|
||||
while not rl.window_should_close():
|
||||
rl.begin_drawing()
|
||||
rl.clear_background(rl.BLACK)
|
||||
|
||||
yield
|
||||
|
||||
if DEBUG_FPS:
|
||||
rl.draw_fps(10, 10)
|
||||
|
||||
rl.end_drawing()
|
||||
|
||||
def font(self, font_wight: FontWeight=FontWeight.NORMAL):
|
||||
return self._fonts[font_wight]
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import pyray as rl
|
||||
|
||||
|
||||
class GuiStyleContext:
|
||||
def __init__(self, styles: list[tuple[int, int, int]]):
|
||||
"""styles is a list of tuples (control, prop, new_value)"""
|
||||
|
||||
+1
-4
@@ -110,12 +110,9 @@ def main():
|
||||
if mode == ResetMode.FORMAT:
|
||||
reset.start_reset()
|
||||
|
||||
while not rl.window_should_close():
|
||||
rl.begin_drawing()
|
||||
rl.clear_background(rl.BLACK)
|
||||
for _ in gui_app.render():
|
||||
if not reset.render(rl.Rectangle(45, 200, gui_app.width - 90, gui_app.height - 245)):
|
||||
break
|
||||
rl.end_drawing()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -15,14 +15,17 @@ MARGIN = 200
|
||||
TEXTURE_SIZE = 360
|
||||
FONT_SIZE = 80
|
||||
|
||||
|
||||
def clamp(value, min_value, max_value):
|
||||
return max(min(value, max_value), min_value)
|
||||
|
||||
|
||||
def check_input_non_blocking():
|
||||
if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
|
||||
return sys.stdin.readline().strip()
|
||||
return ""
|
||||
|
||||
|
||||
def main():
|
||||
gui_app.init_window("Spinner")
|
||||
|
||||
@@ -37,10 +40,7 @@ def main():
|
||||
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)
|
||||
|
||||
while not rl.window_should_close():
|
||||
rl.begin_drawing()
|
||||
rl.clear_background(rl.BLACK)
|
||||
|
||||
for _ in gui_app.render():
|
||||
# Update rotation
|
||||
rotation = (rotation + ROTATION_RATE) % 360.0
|
||||
|
||||
@@ -69,8 +69,6 @@ def main():
|
||||
rl.draw_text_ex(gui_app.font(), user_input,
|
||||
rl.Vector2(center.x - text_size.x / 2, y_pos), FONT_SIZE, 1.0, rl.WHITE)
|
||||
|
||||
rl.end_drawing()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
+1
-6
@@ -44,10 +44,7 @@ def main():
|
||||
content_rect = rl.Rectangle(0, 0, textarea_rect.width - 20, len(wrapped_lines) * LINE_HEIGHT)
|
||||
scroll_panel = GuiScrollPanel(textarea_rect, content_rect, show_vertical_scroll_bar=True)
|
||||
|
||||
while not rl.window_should_close():
|
||||
rl.begin_drawing()
|
||||
rl.clear_background(rl.BLACK)
|
||||
|
||||
for _ in gui_app.render():
|
||||
scroll = scroll_panel.handle_scroll()
|
||||
|
||||
rl.begin_scissor_mode(int(textarea_rect.x), int(textarea_rect.y), int(textarea_rect.width), int(textarea_rect.height))
|
||||
@@ -60,8 +57,6 @@ def main():
|
||||
if gui_button(button_bounds, "Reboot"):
|
||||
HARDWARE.reboot()
|
||||
|
||||
rl.end_drawing()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user