-
Notifications
You must be signed in to change notification settings - Fork 10.1k
refactor(raylib): Fix and standardize rounded corners #35729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
366b11f
4f0146e
25c5463
6ea48d4
8f40569
6255e9b
510989c
3f57dee
750b21e
d2f9bd4
b5431f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,9 @@ | |
from openpilot.common.swaglog import cloudlog | ||
from openpilot.common.params import Params | ||
from openpilot.system.ui.lib.application import FontWeight, gui_app | ||
from openpilot.system.ui.lib.wrap_text import wrap_text | ||
from openpilot.system.ui.lib.rounded_corners import get_roundness | ||
from openpilot.system.ui.lib.text_measure import measure_text_cached | ||
from openpilot.system.ui.lib.wrap_text import wrap_text | ||
|
||
|
||
class PairingDialog: | ||
|
@@ -143,7 +144,7 @@ def _render_instructions(self, rect: rl.Rectangle) -> None: | |
|
||
def _render_qr_code(self, rect: rl.Rectangle) -> None: | ||
if not self.qr_texture: | ||
rl.draw_rectangle_rounded(rect, 0.1, 20, rl.Color(240, 240, 240, 255)) | ||
rl.draw_rectangle_rounded(rect, get_roundness(rect, 30), 20, rl.Color(240, 240, 240, 255)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rounded corners are actually only visible when there's no QR code, which doesn't seem very useful |
||
error_font = gui_app.font(FontWeight.BOLD) | ||
rl.draw_text_ex( | ||
error_font, "QR Code Error", rl.Vector2(rect.x + 20, rect.y + rect.height // 2 - 15), 30, 0.0, rl.RED | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import pyray as rl | ||
|
||
|
||
def get_roundness(rect: rl.Rectangle, border_radius: int) -> float: | ||
"""Calculate the roundness of a rectangle based on its width and height, given a border radius value in pixels. | ||
This is used to standardize the roundness across rectangle with different sizes, since `draw_rectangle_rounded` doesn't use pixels. | ||
""" | ||
return border_radius / (min(rect.width, rect.height) / 2) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import pyray as rl | ||
from openpilot.system.ui.lib.application import FontWeight | ||
from openpilot.system.ui.lib.rounded_corners import get_roundness | ||
from openpilot.system.ui.lib.scroll_panel import GuiScrollPanel | ||
from openpilot.system.ui.widgets import Widget | ||
from openpilot.system.ui.widgets.button import gui_button, ButtonStyle, TextAlignment | ||
from openpilot.system.ui.widgets.label import gui_label | ||
|
||
# Constants | ||
MARGIN = 50 | ||
PANEL_COLOR = rl.Color(30, 30, 30, 255) | ||
PANEL_BORDER_RADIUS = 10 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We really should just make a Panel widget to avoid this stuff being done in different components |
||
TITLE_FONT_SIZE = 70 | ||
ITEM_HEIGHT = 135 | ||
BUTTON_SPACING = 50 | ||
|
@@ -26,7 +29,7 @@ def __init__(self, title, options, current=""): | |
|
||
def _render(self, rect): | ||
dialog_rect = rl.Rectangle(rect.x + MARGIN, rect.y + MARGIN, rect.width - 2 * MARGIN, rect.height - 2 * MARGIN) | ||
rl.draw_rectangle_rounded(dialog_rect, 0.02, 20, rl.Color(30, 30, 30, 255)) | ||
rl.draw_rectangle_rounded(dialog_rect, get_roundness(dialog_rect, PANEL_BORDER_RADIUS), 10, PANEL_COLOR) | ||
|
||
content_rect = rl.Rectangle(dialog_rect.x + MARGIN, dialog_rect.y + MARGIN, | ||
dialog_rect.width - 2 * MARGIN, dialog_rect.height - 2 * MARGIN) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did this to fix a type issue in my IDE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sg if this is true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was the Pylance VSCode extension, if you're wondering. It shows quite a few type issues on a lot of the files, but I can't fix them all.