Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions modules/app_components/layout.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from events.input import BUTTON_TYPES
from . import tokens, utils
from perf_timer import PerfTimer


class Layoutable:
Expand Down Expand Up @@ -84,6 +85,9 @@ def __init__(self, label, value, button_handler=None):
self.height = 0
self.button_handler = button_handler

def __repr__(self):
return f"<DefinitionDisplay {self.label}={self.value}>"

async def button_event(self, event):
if self.button_handler:
return await self.button_handler(event)
Expand Down Expand Up @@ -146,11 +150,32 @@ def draw(self, ctx):
ctx.scale(self.scale_factor, self.scale_factor)
ctx.translate(12, 0)

# Draw each item in turn
for item in self.items:
item.draw(ctx, focused=item == focused_child)
ctx.translate(0, item.height)
self.height += item.height
with PerfTimer("Layout draw"):
# Draw each item in turn
draw_progressive = True
progressive_y = progressive_y_last = 120
for item in self.items:
if draw_progressive:
if item.height:
progressive_y -= item.height
else:
draw_progressive = False
item.draw(ctx, focused=item == focused_child)

if progressive_y_last < (self.y_offset + 150) and progressive_y > (
self.y_offset - 300
):
with PerfTimer(f"Draw element {item}"):
item.draw(ctx, focused=item == focused_child)
else:
# item.draw(ctx, focused=item == focused_child)
pass # print("Skipping draw of ", item, progressive_y_last, self.y_offset, progressive_y)

progressive_y_last = progressive_y
else:
item.draw(ctx, focused=item == focused_child)
ctx.translate(0, item.height)
self.height += item.height

ctx.restore()

Expand Down
3 changes: 3 additions & 0 deletions modules/app_components/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from os import stat
import micropython


@micropython.native
def fill_line(ctx, text, font_size, width_for_line):
ctx.save()
ctx.font_size = font_size
Expand Down Expand Up @@ -29,6 +31,7 @@ def fill_line(ctx, text, font_size, width_for_line):
return lines


@micropython.native
def wrap_text(ctx, text, font_size=None, width=None):
if width is None:
width = 240
Expand Down
6 changes: 3 additions & 3 deletions modules/firmware_apps/settings_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def run(self, render_update):
self.layout.items = []
for id, label, formatter, editor in self.settings_options():
value = settings.get(id)
print(editor)

if editor:

async def _button_event(event, label=label, id=id, editor=editor):
Expand Down Expand Up @@ -220,8 +220,8 @@ async def _button_event_w(event):
await render_update()
current_time = time.ticks_ms()
self.update(current_time - previous_time)
if self.ctx:
self.draw(self.ctx)
# if self.ctx:
# self.draw(self.ctx)
if self.dialog:
result = await self.dialog.run(render_update)
if (
Expand Down
3 changes: 2 additions & 1 deletion modules/system/scheduler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ async def _render_task(self):
)
)
ctx.restore()
display.end_frame(ctx)
with PerfTimer("End frame"):
display.end_frame(ctx)
await asyncio.sleep(0)

async def _main(self):
Expand Down
2 changes: 2 additions & 0 deletions sim/fakes/micropython.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def native(func):
return func
Loading