-
-
Notifications
You must be signed in to change notification settings - Fork 329
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
Text Scaling and Font Size Issues in Level Editor #748
Comments
The intended way to globally scale text is something like |
Hi @pokepetter, I'm encountering an issue where the following scripts cause the window to immediately close without any error messages or traceback. The scripts are meant to implement a scaled level editor using Script 1: from ursina import *
from ursina.prefabs.dropdown_menu import DropdownMenu, DropdownMenuButton
from ursina.prefabs.file_browser import FileBrowser
from textwrap import dedent
def main():
app = Ursina(borderless=False)
window.fullscreen = False
window.size = (1280, 720)
window.position = (100, 100)
editor = ScaledLevelEditor()
editor.eternal = True # Prevent auto-destruction
app.run()
class ScaledLevelEditor(Entity):
def __init__(self):
super().__init__(eternal=True)
self.setup_ui()
def setup_ui(self):
Text.default_resolution = 1080
Text.size = 24 # Absolute size instead of multiplication
self.ui = Entity(parent=camera.ui, eternal=True)
# File menu
self.file_menu = DropdownMenu(
parent=self.ui,
text='File',
buttons=(
DropdownMenuButton('New'),
DropdownMenuButton('Open'),
DropdownMenuButton('Save'),
),
position=(-0.4, 0.45),
scale=(0.15, 0.05)
)
# Scale menu text
self.file_menu.text_entity.world_scale = 1.5
for button in self.file_menu.buttons:
button.text_entity.world_scale = 1.5
# Entity list
self.entity_list = Entity(
parent=self.ui,
position=(-0.4, 0),
scale=(0.3, 0.8)
)
self.entity_list_text = Text(
parent=self.entity_list,
text='Entities:',
world_scale=2,
position=(0, 0.45)
)
# Grid button
self.grid_button = Button(
parent=self.ui,
text='Grid',
scale=(0.1, 0.05),
position=(0.35, 0.45)
)
self.grid_button.text_entity.world_scale = 1.5
# Model buttons
self.model_buttons = []
for i in range(9):
x = -0.4 + (i % 3) * 0.3
y = 0.25 - (i // 3) * 0.15
btn = Button(
parent=self.ui,
text=str(i+1),
scale=(0.08, 0.08),
position=(x, y)
)
btn.text_entity.world_scale = 1.5
self.model_buttons.append(btn)
# Help button
self.help_button = Button(
parent=self.ui,
text='?',
scale=(0.08, 0.08),
position=(0.45, 0.45)
)
self.help_button.text_entity.world_scale = 1.5
self.help_tooltip = Text(
parent=self.ui,
text=dedent('''
Hotkeys:
left mouse : place/select
right mouse : remove
middle mouse : drag
scroll wheel : rotate
f : move to mouse
1,2,3... : select model
shift+1,2,3 : save model
''').strip(),
world_scale=1.5,
enabled=False,
background=True,
position=(0.2, 0.2)
)
def input(self, key):
if key == 'escape':
self.enabled = not self.enabled
if self.help_button.hovered:
self.help_tooltip.enabled = True
else:
self.help_tooltip.enabled = False
if __name__ == '__main__':
try:
main()
except Exception as e:
print(f"Error: {e}") Script 2: from ursina import *
from ursina.prefabs.dropdown_menu import DropdownMenu, DropdownMenuButton
from ursina.prefabs.file_browser import FileBrowser
class ScaledLevelEditor(Entity):
def __init__(self):
window.fullscreen = False
window.size = (1280, 720) # Fixed window size
super().__init__()
Text.size *= 2
Text.default_resolution = 1080
self.ui = Entity(parent=camera.ui, ignore_paused=True)
# Toolbar
self.toolbar = Entity(parent=self.ui)
self.toolbar.scale_y = 0.1
self.toolbar.y = 0.45
# File menu
self.file_menu = DropdownMenu(
text='File',
buttons=(
DropdownMenuButton('New'),
DropdownMenuButton('Open'),
DropdownMenuButton('Save'),
),
scale=(0.2, 0.05),
position=(-0.4, 0.45)
)
for button in self.file_menu.buttons:
button.text_entity.scale *= 2
# Entity list
self.entity_list = Entity(
parent=self.ui,
position=(-0.4, 0),
scale=(0.3, 0.8)
)
self.entity_list_text = Text(
parent=self.entity_list,
text='Entities:',
scale=2,
position=(0, 0.45)
)
# Help button
self.help_button = Button(
parent=self.ui,
text='?',
scale=(0.1, 0.1),
position=(0.45, 0.45)
)
self.help_button.text_entity.scale *= 2
# Help tooltip
self.help_tooltip = Text(
parent=self.ui,
text=dedent('''
Hotkeys:
left mouse : place/select
right mouse : remove
middle mouse : drag
scroll wheel : rotate
f : move to mouse
1,2,3... : select model
shift+1,2,3 : save model
''').strip(),
scale=2,
enabled=False,
background=True,
position=(0.2, 0.2)
)
# Grid toggle with scaled button
self.grid_button = ScaledButton(
parent=self.ui,
text='Grid',
scale=.08,
position=(.35, .45)
)
# Model selection buttons
self.model_buttons = []
for i in range(9):
x = -.4 + (i % 3) * .4
y = .25 - (i // 3) * .2
btn = ScaledButton(
parent=self.ui,
text=str(i+1),
scale=.08,
position=(x, y)
)
self.model_buttons.append(btn)
def input(self, key):
if key == 'escape':
self.enabled = not self.enabled
if self.help_button.hovered:
self.help_tooltip.enabled = True
else:
self.help_tooltip.enabled = False
class ScaledButton(Button):
def __init__(self, **kwargs):
super().__init__()
self.scale *= 2 # Increase button size
self.text_entity.scale *= 2 # Scale text proportionally
for key, value in kwargs.items():
setattr(self, key, value)
class ScaledDropdownMenu(DropdownMenu):
def __init__(self, text, buttons):
super().__init__(text=text, buttons=buttons)
self.scale *= 2
self.text_entity.scale *= 2
for b in self.buttons:
b.scale *= 2
b.text_entity.scale *= 2
class ScaledDropdownMenuButton(DropdownMenuButton):
def __init__(self, text):
super().__init__(text=text)
self.scale *= 2
self.text_entity.scale *= 2
if __name__ == '__main__':
try:
app = Ursina()
editor = ScaledLevelEditor()
app.run()
except Exception as e:
print(f"An error occurred: {e}") Console Log Output:
Details:
Do you have any insights into why this might be happening? Could it be related to compatibility with Python 3.12 or the |
Fixes pokepetter#748 Update `LevelEditor` and `Help` classes to ensure consistent text scaling and font size adjustments. * **LevelEditor Class:** - Add `ui_scale_factor` attribute for default scale. - Modify `origin_mode_menu` and `local_global_menu` to scale with `ui_scale_factor`. - Update `update_text_scale` function to scale text entities in button groups. - Adjust `editor_camera` position scaling. - Scale `gizmo`, `gizmo_toggler`, and `quick_grabber` with `ui_scale_factor`. - Scale `inspector` and `help` with `ui_scale_factor`. - Scale `point_renderer` model thickness. - Scale `cubes` in `render_selection`. - Scale `ui` in `on_enable` and `on_disable` methods. - Adjust `entity_list_text` and `selected_renderer` scale. - Update `text_field` scale in `InspectorButton`. * **Help Class:** - Modify `tooltip` scale to 1 for noticeable text size changes. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/pokepetter/ursina/issues/748?shareId=XXXX-XXXX-XXXX-XXXX).
Hi @pokepetter, I’ve been working on addressing the problem mentioned in this issue and have made some changes to Progress So Far:
Could you please review the changes in the pull request and provide your guidance on how best to address the remaining issues? Your input would be invaluable in ensuring this gets fully resolved. Thank you! |
Hi @pokepetter,
I’ve been working on customizing the Level Editor in Ursina and encountered some issues related to text scaling and font size adjustments. Specifically:
Text.size
affects some text entities but not others, leading to inconsistent scaling.scale
,original_scale
, andText.size
, there seems to be no noticeable change in the font size of the help menu tooltip text.scale
andText.size
for entity-related text components (likeself.entity_list_text
) does not always yield the expected changes.Here’s an example of the modifications I’ve tried for the help menu tooltip:
Unfortunately, none of the above changes had a significant effect on the font size or appearance of the help menu text.
Questions:
Text
class in Ursina?Environment:
Any guidance or suggestions would be greatly appreciated!
The text was updated successfully, but these errors were encountered: