def make_editor_gui( self ): # called by main after setting up camera and application.development_mode from ursina import camera, Text, Button, ButtonList, Func, Tooltip import time self.editor_ui = Entity(parent=camera.ui, eternal=True, enabled=bool(application.development_mode)) self.exit_button = Button(parent=self.editor_ui, eternal=True, origin=(.5, .5), position=self.top_right, z=-999, scale=(.05, .025), color=color.red.tint(-.2), text='x', on_click=application.quit) self.exit_button.enabled = self.borderless def _exit_button_input(key): from ursina import held_keys, mouse if held_keys['shift'] and key == 'q' and not mouse.right: self.exit_button.on_click() self.exit_button.input = _exit_button_input self.fps_counter = Text(parent=self.editor_ui, eternal=True, position=(.5 * self.aspect_ratio, .47, -999), origin=(.8, .5), text='60', ignore=False, i=0) def _fps_counter_update(): if self.fps_counter.i > 60: self.fps_counter.text = str(int(1 // time.dt)) self.fps_counter.i = 0 self.fps_counter.i += 1 self.fps_counter.update = _fps_counter_update import webbrowser self.cog_menu = ButtonList( { # 'Build' : Func(print, ' '), 'API Reference': Func(webbrowser.open, 'https://www.ursinaengine.org/cheat_sheet_dark.html'), 'Asset Store': Func(webbrowser.open, 'https://itch.io/tools/tag-ursina'), # 'Open Scene Editor' : Func(print, ' '), 'Change Render Mode <gray>[F10]<default>': self.next_render_mode, 'Reset Render Mode <gray>[F9]<default>': Func(setattr, self, 'render_mode', 'default'), 'Reload Models <gray>[F7]<default>': application.hot_reloader.reload_models, 'Reload Textures <gray>[F6]<default>': application.hot_reloader.reload_textures, 'Reload Code <gray>[F5]<default>': application.hot_reloader.reload_code, }, width=.35, x=.62, enabled=False, eternal=True) self.cog_menu.on_click = Func(setattr, self.cog_menu, 'enabled', False) self.cog_menu.y = -.5 + self.cog_menu.scale_y self.cog_menu.scale *= .75 self.cog_menu.text_entity.x += .025 self.cog_menu.highlight.color = color.azure self.cog_button = Button(parent=self.editor_ui, eternal=True, model='circle', scale=.015, origin=(1, -1), position=self.bottom_right) info_text = '''This menu is not enabled in builds <gray>(unless you set application.development to be not False).''' self.cog_menu.info = Button(parent=self.cog_menu, model='quad', text='<gray>?', scale=.1, x=1, y=.01, origin=(.5, -.5), tooltip=Tooltip(info_text, scale=.75, origin=(-.5, -.5))) self.cog_menu.info.text_entity.scale *= .75 def _toggle_cog_menu(): self.cog_menu.enabled = not self.cog_menu.enabled self.cog_button.on_click = _toggle_cog_menu
elif isinstance(action, str): exec(textwrap.dedent(action)) def fit_to_text(self, radius=.1): if not self.text_entity.text or self.text_entity.text == '': return self.text_entity.world_parent = scene self.scale = ((self.text_entity.width * Text.size * 2) + self.text_entity.height * Text.size * 2, self.text_entity.height * Text.size * 2 * 2) self.model = Quad(aspect=self.scale_x / self.scale_y, radius=radius) self.text_entity.world_parent = self # print('fit to text', self.scale) if __name__ == '__main__': from ursina import Ursina, application, Tooltip app = Ursina() b = Button(text='hello world!', color=color.azure, icon='sword', scale=.25, text_origin=(-.5, 0)) # b.fit_to_text() b.on_click = application.quit # assign a function to the button. b.tooltip = Tooltip('exit') app.run()