Skip to content

Commit

Permalink
Text rendering updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesridgway committed Dec 28, 2020
1 parent aec6c2b commit 63c27d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion devdeck/controls/name_list_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def pressed(self):
r.image(os.path.join(os.path.dirname(__file__), "../../assets/font-awesome", 'users.png')).end()
else:
initials = ''.join(list(map(lambda x: x[0], self.settings['names'][self.name_index].split(' '))))
r.text(initials).font_size(256).end()
r.text(initials).font_size(256).center_vertically().center_horizontally().end()
self.name_index += 1

def settings_schema(self):
Expand Down
12 changes: 9 additions & 3 deletions devdeck/controls/timer_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ def pressed(self):
self.end_time = datetime.datetime.now()
self.thread.join()
with self.deck_context() as context:
context.render_text(TimerControl.time_diff_to_str(self.end_time - self.start_time),
font_size=120, fill='red')
with context.renderer() as r:
r.text(TimerControl.time_diff_to_str(self.end_time - self.start_time))\
.font_size(120)\
.color('red')\
.center_vertically().center_horizontally().end()
else:
self.start_time = None
self.end_time = None
Expand All @@ -45,7 +48,10 @@ def _update_display(self):
continue
cutoff = datetime.datetime.now() if self.end_time is None else self.end_time
with self.deck_context() as context:
context.render_text(TimerControl.time_diff_to_str(cutoff - self.start_time), font_size=120)
with context.renderer() as r:
r.text(TimerControl.time_diff_to_str(cutoff - self.start_time)) \
.font_size(120) \
.center_vertically().center_horizontally().end()
sleep(1)

@staticmethod
Expand Down
8 changes: 4 additions & 4 deletions tests/devdeck/controls/test_name_list_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ def test_pressed_iterates_initials(self):
assert_that(name_list_control.name_index).is_equal_to(0)

name_list_control.pressed()
assert_rendered(ctx, Renderer().text('SM').font_size(256).end())
assert_rendered(ctx, Renderer().text('SM').font_size(256).center_vertically().center_horizontally().end())
assert_that(name_list_control.name_index).is_equal_to(1)

name_list_control.pressed()
assert_rendered(ctx, Renderer().text('ES').font_size(256).end())
assert_rendered(ctx, Renderer().text('ES').font_size(256).center_vertically().center_horizontally().end())
assert_that(name_list_control.name_index).is_equal_to(2)

name_list_control.pressed()
assert_rendered(ctx, Renderer().text('EB').font_size(256).end())
assert_rendered(ctx, Renderer().text('EB').font_size(256).center_vertically().center_horizontally().end())
assert_that(name_list_control.name_index).is_equal_to(3)

name_list_control.pressed()
assert_rendered(ctx, TestingUtils.get_filename('../assets/font-awesome/users.png'))

name_list_control.pressed()
assert_rendered(ctx, Renderer().text('SM').font_size(256).end())
assert_rendered(ctx, Renderer().text('SM').font_size(256).center_vertically().center_horizontally().end())
assert_that(name_list_control.name_index).is_equal_to(1)

0 comments on commit 63c27d0

Please sign in to comment.