Skip to content

Commit

Permalink
fixed bug with TextField being affected by screen resolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
pokepetter committed Mar 4, 2021
1 parent d5e65cd commit 3b7953f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
14 changes: 9 additions & 5 deletions ursina/prefabs/input_field.py
Expand Up @@ -45,7 +45,7 @@ def render():

self.text_field.render = render

self.text_field.scale *= 1.5
self.text_field.scale *= 1.25
self.text_field.text = default_value
self.text_field.render()

Expand Down Expand Up @@ -100,12 +100,16 @@ def active(self, value):

if __name__ == '__main__':
app = Ursina()
input_field = InputField()
print(input_field.default_value)
# window.fullscreen_size = (1366, 768)
background = Sprite('shore', color=color.dark_gray)
username_field = InputField()
password_field = InputField(y=-.06, hide_content=True)
username_field.next_field = password_field

def submit():
print(input_field.text)
print('ursername:', username_field.text)
print('password:', password_field.text)

Button('submit', scale=.1, color=color.azure, y=-.2, on_click=submit).fit_to_text()
Button('Login', scale=.1, color=color.azure, y=-.14, on_click=submit).fit_to_text()

app.run()
20 changes: 6 additions & 14 deletions ursina/prefabs/text_field.py
Expand Up @@ -12,12 +12,8 @@ def __init__(self, **kwargs):
ignore_paused=True,
)

# for key, value in kwargs.items():
# if key in ('font', 'font_size', 'line_height'):
# setattr(self, key, value)

self.font = 'VeraMono.ttf'
self.font_size = 20
self.line_height = 1
# self.max_width = 80
self.max_lines = 99999
Expand All @@ -27,25 +23,21 @@ def __init__(self, **kwargs):
start_tag='☾',
end_tag = '☽',
font = self.font,
resolution = self.font_size * 2,
size = 1/window.fullscreen_size[1] * self.font_size,
text='',
line_height=self.line_height,
origin=(-.5, .5),
)
self.line_numbers = Text(
parent = self,
font = self.font,
resolution = self.font_size * 2,
size = 1/window.fullscreen_size[1] * self.font_size,
text='0',
origin=(.5,.5),
x=-.04,
color=color.gray,
enabled = False,
)
self.character_width = .0111
self.cursor_parent = Entity(parent=self, scale=(self.character_width, -1*self.text_entity.size))
self.character_width = Text.get_width('a', font=self.font)
self.cursor_parent = Entity(parent=self, scale=(self.character_width, -1*Text.size))
# self.max_line_indicatior = Entity(parent=self.cursor_parent, model='quad', origin=(-.5,.5), scale=(100,.05), rotation_x=180, color=color.red)
# self.max_width_indicatior = Entity(
# parent=self.cursor_parent, model='quad', origin=(-.5,.5), scale=(100,.05), rotation_x=180, rotation_z=90, color=color.color(0,0,1,.05), x=80)
Expand Down Expand Up @@ -614,14 +606,14 @@ def draw_selection(self):
app = Ursina()
# camera.orthographic = True
# camera.fov = 1
window.size = window.fullscreen_size
# window.size = window.fullscreen_size
window.x = 200

window.color = color.color(0, 0, .1)
Button.color = color._20
window.color = color._25

Text.size = 1/window.fullscreen_size[1]*16
# Text.size = 1/window.fullscreen_size[1]*16
Text.default_font = 'consola.ttf'
Text.default_resolution = 16*2
# TreeView()
Expand Down Expand Up @@ -650,8 +642,8 @@ def draw_selection(self):
Suspendisse dolor tortor, congue id erat sit amet, sollicitudin facilisis velit.'''
)[1:]
# te.cursor.position = (4,0)
te.selection = [(25,0), (10,3)]
te.draw_selection()
# te.selection = [(25,0), (10,3)]
# te.draw_selection()
te.render()
# te.selection = ((0,0),(4,0))
# te.select_all()
Expand Down

0 comments on commit 3b7953f

Please sign in to comment.