Skip to content

Commit

Permalink
fixed Button text_entity not being created correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
petteramland committed Oct 4, 2023
1 parent 3624153 commit 5bc98ef
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
5 changes: 3 additions & 2 deletions ursina/prefabs/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ def __init__(self, parent=camera.ui, text='', model=Default, radius=.1, origin=(
def text_getter(self):
if self.text_entity:
return self.text_entity.text
return ''

def text_setter(self, value):
if not isinstance(value, str):
raise TypeError('Text must be a string')

if not self.text_entity:
self.text_entity = Text(parent=self.model, text=text, position=Vec3(value[0],value[1],-.1), origin=value, add_to_scene_entities=False)
self.text_entity = Text(text=value, parent=self.model, position=Vec3(0,0,-.01), origin=(0,0), add_to_scene_entities=False)
self.text_entity.world_parent = self
self.text_entity.world_scale = Vec3(20 * self.text_size)

Expand Down Expand Up @@ -175,7 +176,7 @@ def on_mouse_exit(self):


def fit_to_text(self, radius=.1, padding=Vec2(Text.size*1.5, Text.size)):
if not self.text_entity.text or self.text_entity.text == '':
if not self.text_entity or not self.text_entity.text or self.text_entity.text == '':
return

self.text_entity.world_parent = scene
Expand Down
1 change: 0 additions & 1 deletion ursina/prefabs/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def value(self):

@value.setter
def value(self, new_value):
# print('set checkbox state to:', value)
self._value = new_value
self.text = ' x'[int(new_value)]

Expand Down
2 changes: 1 addition & 1 deletion ursina/prefabs/input_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ def submit():
print('ursername:', username_field.text)
print('password:', password_field.text)

Button('Login', scale=.1, color=color.cyan.tint(-.4), y=-.26, on_click=submit).fit_to_text()
Button(text='Login', scale=.1, color=color.cyan.tint(-.4), y=-.26, on_click=submit).fit_to_text()
username_field.on_value_changed = submit
app.run()

0 comments on commit 5bc98ef

Please sign in to comment.