This commit is contained in:
jeremygan2021
2026-03-03 23:31:06 +08:00
parent 0aa8f5f473
commit 20d2e72c51
10 changed files with 220 additions and 201 deletions

View File

@@ -210,3 +210,62 @@ class Display:
self.tft.line(x, y + 5, x + 3, y + 8, st7789.GREEN)
self.tft.line(x + 3, y + 8, x + 10, y, st7789.GREEN)
def render_confirm_screen(self, asr_text=""):
"""渲染确认界面"""
if not self.tft:
return
self.tft.fill(st7789.BLACK)
# Header
self.tft.fill_rect(0, 0, 240, 30, st7789.CYAN)
self.text("说完了吗?", 75, 8, st7789.BLACK)
# Content box
self.tft.fill_rect(10, 50, 220, 90, 0x4208) # DARKGREY
if asr_text:
# 自动换行逻辑
max_width = 200
lines = []
current_line = ""
current_width = 0
for char in asr_text:
char_width = 16 if ord(char) > 127 else 8
if current_width + char_width > max_width:
lines.append(current_line)
current_line = char
current_width = char_width
else:
current_line += char
current_width += char_width
if current_line:
lines.append(current_line)
# 限制显示行数,避免溢出
lines = lines[:4]
# 计算起始Y坐标以垂直居中
total_height = len(lines) * 20
start_y = 50 + (90 - total_height) // 2
for i, line in enumerate(lines):
# 计算水平居中
line_width = 0
for c in line:
line_width += 16 if ord(c) > 127 else 8
center_x = 20 + (200 - line_width) // 2
self.text(line, center_x, start_y + i * 20, st7789.WHITE, wait=False)
else:
self.text("未识别到文字", 70, 85, st7789.WHITE)
# Buttons
self.tft.fill_rect(20, 160, 90, 30, st7789.GREEN)
self.text("短按确认", 30, 168, st7789.BLACK)
self.tft.fill_rect(130, 160, 90, 30, st7789.RED)
self.text("长按重录", 140, 168, st7789.WHITE)