mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-01 11:32:21 +08:00
ui: skip rendering when screen is off (#36510)
* skip rendering when screen is off * continue and rename * revert that * flip --------- Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
+2
-3
@@ -13,10 +13,9 @@ def main():
|
||||
gui_app.init_window("UI")
|
||||
main_layout = MainLayout()
|
||||
main_layout.set_rect(rl.Rectangle(0, 0, gui_app.width, gui_app.height))
|
||||
for showing_dialog in gui_app.render():
|
||||
for should_render in gui_app.render():
|
||||
ui_state.update()
|
||||
|
||||
if not showing_dialog:
|
||||
if should_render:
|
||||
main_layout.render()
|
||||
|
||||
|
||||
|
||||
@@ -253,6 +253,7 @@ class Device:
|
||||
self._awake = on
|
||||
cloudlog.debug(f"setting display power {int(on)}")
|
||||
HARDWARE.set_display_power(on)
|
||||
gui_app.set_should_render(on)
|
||||
|
||||
|
||||
# Global instance
|
||||
|
||||
@@ -156,6 +156,8 @@ class GuiApplication:
|
||||
self._mouse = MouseState(self._scale)
|
||||
self._mouse_events: list[MouseEvent] = []
|
||||
|
||||
self._should_render = True
|
||||
|
||||
# Debug variables
|
||||
self._mouse_history: deque[MousePos] = deque(maxlen=MOUSE_THREAD_RATE)
|
||||
|
||||
@@ -237,6 +239,9 @@ class GuiApplication:
|
||||
|
||||
self._modal_overlay = ModalOverlay(overlay=overlay, callback=callback)
|
||||
|
||||
def set_should_render(self, should_render: bool):
|
||||
self._should_render = should_render
|
||||
|
||||
def texture(self, asset_path: str, width: int | None = None, height: int | None = None,
|
||||
alpha_premultiply=False, keep_aspect_ratio=True):
|
||||
cache_key = f"{asset_path}_{width}_{height}_{alpha_premultiply}{keep_aspect_ratio}"
|
||||
@@ -322,6 +327,12 @@ class GuiApplication:
|
||||
# Store all mouse events for the current frame
|
||||
self._mouse_events = self._mouse.get_events()
|
||||
|
||||
# Skip rendering when screen is off
|
||||
if not self._should_render:
|
||||
time.sleep(1 / self._target_fps)
|
||||
yield False
|
||||
continue
|
||||
|
||||
if self._render_texture:
|
||||
rl.begin_texture_mode(self._render_texture)
|
||||
rl.clear_background(rl.BLACK)
|
||||
@@ -344,9 +355,9 @@ class GuiApplication:
|
||||
self._modal_overlay = ModalOverlay()
|
||||
if original_modal.callback is not None:
|
||||
original_modal.callback(result)
|
||||
yield True
|
||||
else:
|
||||
yield False
|
||||
else:
|
||||
yield True
|
||||
|
||||
if self._render_texture:
|
||||
rl.end_texture_mode()
|
||||
|
||||
+4
-5
@@ -126,11 +126,10 @@ def main():
|
||||
if mode == ResetMode.FORMAT:
|
||||
reset.start_reset()
|
||||
|
||||
for showing_dialog in gui_app.render():
|
||||
if showing_dialog:
|
||||
continue
|
||||
if not reset.render(rl.Rectangle(45, 200, gui_app.width - 90, gui_app.height - 245)):
|
||||
break
|
||||
for should_render in gui_app.render():
|
||||
if should_render:
|
||||
if not reset.render(rl.Rectangle(45, 200, gui_app.width - 90, gui_app.height - 245)):
|
||||
break
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+3
-4
@@ -432,10 +432,9 @@ def main():
|
||||
try:
|
||||
gui_app.init_window("Setup", 20)
|
||||
setup = Setup()
|
||||
for showing_dialog in gui_app.render():
|
||||
if showing_dialog:
|
||||
continue
|
||||
setup.render(rl.Rectangle(0, 0, gui_app.width, gui_app.height))
|
||||
for should_render in gui_app.render():
|
||||
if should_render:
|
||||
setup.render(rl.Rectangle(0, 0, gui_app.width, gui_app.height))
|
||||
setup.close()
|
||||
except Exception as e:
|
||||
print(f"Setup error: {e}")
|
||||
|
||||
@@ -161,10 +161,9 @@ def main():
|
||||
try:
|
||||
gui_app.init_window("System Update")
|
||||
updater = Updater(updater_path, manifest_path)
|
||||
for showing_dialog in gui_app.render():
|
||||
if showing_dialog:
|
||||
continue
|
||||
updater.render(rl.Rectangle(0, 0, gui_app.width, gui_app.height))
|
||||
for should_render in gui_app.render():
|
||||
if should_render:
|
||||
updater.render(rl.Rectangle(0, 0, gui_app.width, gui_app.height))
|
||||
finally:
|
||||
# Make sure we clean up even if there's an error
|
||||
gui_app.close()
|
||||
|
||||
Reference in New Issue
Block a user