|
|
@ -29,9 +29,10 @@ class AlertConstants: |
|
|
|
MARGIN = 50 |
|
|
|
MARGIN = 50 |
|
|
|
SPACING = 30 |
|
|
|
SPACING = 30 |
|
|
|
FONT_SIZE = 48 |
|
|
|
FONT_SIZE = 48 |
|
|
|
BORDER_RADIUS = 30 |
|
|
|
BORDER_RADIUS = 30 * 2 # matches Qt's 30px |
|
|
|
ALERT_HEIGHT = 120 |
|
|
|
ALERT_HEIGHT = 120 |
|
|
|
ALERT_SPACING = 20 |
|
|
|
ALERT_SPACING = 10 |
|
|
|
|
|
|
|
ALERT_INSET = 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass |
|
|
|
@dataclass |
|
|
@ -88,7 +89,7 @@ class AbstractAlert(Widget, ABC): |
|
|
|
HARDWARE.reboot() |
|
|
|
HARDWARE.reboot() |
|
|
|
|
|
|
|
|
|
|
|
def _render(self, rect: rl.Rectangle): |
|
|
|
def _render(self, rect: rl.Rectangle): |
|
|
|
rl.draw_rectangle_rounded(rect, AlertConstants.BORDER_RADIUS / rect.width, 10, AlertColors.BACKGROUND) |
|
|
|
rl.draw_rectangle_rounded(rect, AlertConstants.BORDER_RADIUS / rect.height, 10, AlertColors.BACKGROUND) |
|
|
|
|
|
|
|
|
|
|
|
footer_height = AlertConstants.BUTTON_SIZE[1] + AlertConstants.SPACING |
|
|
|
footer_height = AlertConstants.BUTTON_SIZE[1] + AlertConstants.SPACING |
|
|
|
content_height = rect.height - 2 * AlertConstants.MARGIN - footer_height |
|
|
|
content_height = rect.height - 2 * AlertConstants.MARGIN - footer_height |
|
|
@ -138,7 +139,8 @@ class AbstractAlert(Widget, ABC): |
|
|
|
|
|
|
|
|
|
|
|
self.dismiss_btn_rect.x = rect.x + AlertConstants.MARGIN |
|
|
|
self.dismiss_btn_rect.x = rect.x + AlertConstants.MARGIN |
|
|
|
self.dismiss_btn_rect.y = footer_y |
|
|
|
self.dismiss_btn_rect.y = footer_y |
|
|
|
rl.draw_rectangle_rounded(self.dismiss_btn_rect, 0.3, 10, AlertColors.BUTTON) |
|
|
|
roundness = AlertConstants.BORDER_RADIUS / self.dismiss_btn_rect.height |
|
|
|
|
|
|
|
rl.draw_rectangle_rounded(self.dismiss_btn_rect, roundness, 10, AlertColors.BUTTON) |
|
|
|
|
|
|
|
|
|
|
|
text = "Close" |
|
|
|
text = "Close" |
|
|
|
text_width = measure_text_cached(font, text, AlertConstants.FONT_SIZE).x |
|
|
|
text_width = measure_text_cached(font, text, AlertConstants.FONT_SIZE).x |
|
|
@ -151,7 +153,8 @@ class AbstractAlert(Widget, ABC): |
|
|
|
if self.snooze_visible: |
|
|
|
if self.snooze_visible: |
|
|
|
self.snooze_btn_rect.x = rect.x + rect.width - AlertConstants.MARGIN - AlertConstants.SNOOZE_BUTTON_SIZE[0] |
|
|
|
self.snooze_btn_rect.x = rect.x + rect.width - AlertConstants.MARGIN - AlertConstants.SNOOZE_BUTTON_SIZE[0] |
|
|
|
self.snooze_btn_rect.y = footer_y |
|
|
|
self.snooze_btn_rect.y = footer_y |
|
|
|
rl.draw_rectangle_rounded(self.snooze_btn_rect, 0.3, 10, AlertColors.SNOOZE_BG) |
|
|
|
roundness = AlertConstants.BORDER_RADIUS / self.snooze_btn_rect.height |
|
|
|
|
|
|
|
rl.draw_rectangle_rounded(self.snooze_btn_rect, roundness, 10, AlertColors.SNOOZE_BG) |
|
|
|
|
|
|
|
|
|
|
|
text = "Snooze Update" |
|
|
|
text = "Snooze Update" |
|
|
|
text_width = measure_text_cached(font, text, AlertConstants.FONT_SIZE).x |
|
|
|
text_width = measure_text_cached(font, text, AlertConstants.FONT_SIZE).x |
|
|
@ -162,7 +165,8 @@ class AbstractAlert(Widget, ABC): |
|
|
|
elif self.has_reboot_btn: |
|
|
|
elif self.has_reboot_btn: |
|
|
|
self.reboot_btn_rect.x = rect.x + rect.width - AlertConstants.MARGIN - AlertConstants.REBOOT_BUTTON_SIZE[0] |
|
|
|
self.reboot_btn_rect.x = rect.x + rect.width - AlertConstants.MARGIN - AlertConstants.REBOOT_BUTTON_SIZE[0] |
|
|
|
self.reboot_btn_rect.y = footer_y |
|
|
|
self.reboot_btn_rect.y = footer_y |
|
|
|
rl.draw_rectangle_rounded(self.reboot_btn_rect, 0.3, 10, AlertColors.BUTTON) |
|
|
|
roundness = AlertConstants.BORDER_RADIUS / self.reboot_btn_rect.height |
|
|
|
|
|
|
|
rl.draw_rectangle_rounded(self.reboot_btn_rect, roundness, 10, AlertColors.BUTTON) |
|
|
|
|
|
|
|
|
|
|
|
text = "Reboot and Update" |
|
|
|
text = "Reboot and Update" |
|
|
|
text_width = measure_text_cached(font, text, AlertConstants.FONT_SIZE).x |
|
|
|
text_width = measure_text_cached(font, text, AlertConstants.FONT_SIZE).x |
|
|
@ -215,11 +219,11 @@ class OffroadAlert(AbstractAlert): |
|
|
|
if not alert_data.visible: |
|
|
|
if not alert_data.visible: |
|
|
|
continue |
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
text_width = int(self.content_rect.width - 90) |
|
|
|
text_width = int(self.content_rect.width - (AlertConstants.ALERT_INSET * 2)) |
|
|
|
wrapped_lines = wrap_text(font, alert_data.text, AlertConstants.FONT_SIZE, text_width) |
|
|
|
wrapped_lines = wrap_text(font, alert_data.text, AlertConstants.FONT_SIZE, text_width) |
|
|
|
line_count = len(wrapped_lines) |
|
|
|
line_count = len(wrapped_lines) |
|
|
|
text_height = line_count * (AlertConstants.FONT_SIZE + 5) |
|
|
|
text_height = line_count * (AlertConstants.FONT_SIZE + 5) |
|
|
|
alert_item_height = max(text_height + 40, AlertConstants.ALERT_HEIGHT) |
|
|
|
alert_item_height = max(text_height + (AlertConstants.ALERT_INSET * 2), AlertConstants.ALERT_HEIGHT) |
|
|
|
total_height += alert_item_height + AlertConstants.ALERT_SPACING |
|
|
|
total_height += alert_item_height + AlertConstants.ALERT_SPACING |
|
|
|
|
|
|
|
|
|
|
|
if total_height > 20: |
|
|
|
if total_height > 20: |
|
|
@ -235,7 +239,7 @@ class OffroadAlert(AbstractAlert): |
|
|
|
self.sorted_alerts.append(alert_data) |
|
|
|
self.sorted_alerts.append(alert_data) |
|
|
|
|
|
|
|
|
|
|
|
def _render_content(self, content_rect: rl.Rectangle): |
|
|
|
def _render_content(self, content_rect: rl.Rectangle): |
|
|
|
y_offset = 20 |
|
|
|
y_offset = AlertConstants.ALERT_SPACING |
|
|
|
font = gui_app.font(FontWeight.NORMAL) |
|
|
|
font = gui_app.font(FontWeight.NORMAL) |
|
|
|
|
|
|
|
|
|
|
|
for alert_data in self.sorted_alerts: |
|
|
|
for alert_data in self.sorted_alerts: |
|
|
@ -243,11 +247,11 @@ class OffroadAlert(AbstractAlert): |
|
|
|
continue |
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
bg_color = AlertColors.HIGH_SEVERITY if alert_data.severity > 0 else AlertColors.LOW_SEVERITY |
|
|
|
bg_color = AlertColors.HIGH_SEVERITY if alert_data.severity > 0 else AlertColors.LOW_SEVERITY |
|
|
|
text_width = int(content_rect.width - 90) |
|
|
|
text_width = int(content_rect.width - (AlertConstants.ALERT_INSET * 2)) |
|
|
|
wrapped_lines = wrap_text(font, alert_data.text, AlertConstants.FONT_SIZE, text_width) |
|
|
|
wrapped_lines = wrap_text(font, alert_data.text, AlertConstants.FONT_SIZE, text_width) |
|
|
|
line_count = len(wrapped_lines) |
|
|
|
line_count = len(wrapped_lines) |
|
|
|
text_height = line_count * (AlertConstants.FONT_SIZE + 5) |
|
|
|
text_height = line_count * (AlertConstants.FONT_SIZE + 5) |
|
|
|
alert_item_height = max(text_height + 40, AlertConstants.ALERT_HEIGHT) |
|
|
|
alert_item_height = max(text_height + (AlertConstants.ALERT_INSET * 2), AlertConstants.ALERT_HEIGHT) |
|
|
|
|
|
|
|
|
|
|
|
alert_rect = rl.Rectangle( |
|
|
|
alert_rect = rl.Rectangle( |
|
|
|
content_rect.x + 10, |
|
|
|
content_rect.x + 10, |
|
|
@ -256,10 +260,11 @@ class OffroadAlert(AbstractAlert): |
|
|
|
alert_item_height, |
|
|
|
alert_item_height, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
rl.draw_rectangle_rounded(alert_rect, 0.2, 10, bg_color) |
|
|
|
roundness = AlertConstants.BORDER_RADIUS / min(alert_rect.height, alert_rect.width) |
|
|
|
|
|
|
|
rl.draw_rectangle_rounded(alert_rect, roundness, 10, bg_color) |
|
|
|
|
|
|
|
|
|
|
|
text_x = alert_rect.x + 30 |
|
|
|
text_x = alert_rect.x + AlertConstants.ALERT_INSET |
|
|
|
text_y = alert_rect.y + 20 |
|
|
|
text_y = alert_rect.y + AlertConstants.ALERT_INSET |
|
|
|
|
|
|
|
|
|
|
|
for i, line in enumerate(wrapped_lines): |
|
|
|
for i, line in enumerate(wrapped_lines): |
|
|
|
rl.draw_text_ex( |
|
|
|
rl.draw_text_ex( |
|
|
|