def nickname(y=5, font="freesansbold12", color=0x000000, unusedParameter=None): nick = machine.nvs_getstr("owner", "name") if not nick: return y lines = lineSplit(nick, display.width(), font) for i in range(len(lines)): line = lines[len(lines) - i - 1] display.font(font) pos_x = int((display.width() - display.get_string_width(line)) / 2) lineHeight = display.get_string_height(line) display.cursor(pos_x, y + lineHeight * (len(lines) - i - 1)) display.textColor(color) display.print(line) return len(lines) * lineHeight
def string_box(x, y, w, h, text, font, color, justify): display.textColor(color) display.font(font) if justify == justifyCenter: display.cursor(x + int(display.get_string_width(text) / 2), y + int(display.get_string_height(text) / 2)) elif justify == justifyRight: display.cursor(x + display.get_string_width(text), y + int(display.get_string_height(text) / 2)) else: display.cursor(x, y + int(display.get_string_height(text) / 2)) display.print(text)
def msg_nosplit(message, title='Loading...', reset=False): global NUM_LINES """Show a terminal style loading screen with title title can be optionaly set when resetting or first call """ global messageHistory try: messageHistory if reset: raise exception except: display.greyscale(False) display.fill(0xFFFFFF) display.textColor(0x000000) display.font(version.font_header) display.cursor(0, 0) display.print(title) messageHistory = [] display.font(version.font_default) lineHeight = display.get_string_height(" ") if len(messageHistory) < NUM_LINES: display.textColor(0x000000) display.cursor(0, 19 + (len(messageHistory) * lineHeight)) display.print(message) messageHistory.append(message) else: messageHistory.pop(0) messageHistory.append(message) display.rect(0, 15, display.width(), display.height() - 15, True, 0xFFFFFF) for i, message in enumerate(messageHistory): display.textColor(0x000000) display.font(version.font_default) display.cursor(0, 19 + (i * lineHeight)) display.print(message) display.flush()
def lineCentered(pos_y, line, font, color): display.font(font) pos_x = int((display.width() - display.get_string_width(line)) / 2) display.cursor(pos_x, pos_y) display.textColor(color) display.print(line)
def disp_string_right_bottom(y, s, font="freesans9"): display.font(font) l = display.get_string_width(s) display.cursor(display.width() - l, display.height() - (y + 1) * 14) display.textColor(0x000000) display.print(s)
def start(): ugfx.input_init() ugfx.set_lut(ugfx.LUT_FASTER) ugfx.clear(ugfx.WHITE) # Instructions if orientation.isLandscape(): x0 = int(display.width() / 2) display.font("fairlight8") currentY = 20 display.cursor( x0 + int((display.width() - x0) / 2) - int(display.get_string_width("BADGE.TEAM") / 2), currentY) display.print("BADGE.TEAM\n") display.font("pixelade9") (_, currentY) = display.cursor() display.cursor( x0 + int((display.width() - x0) / 2) - int(display.get_string_width("ESP32 platform") / 2), currentY) display.print("ESP32 platform\n") display.line(x0, 0, x0, display.height() - 1, 0x000000) display.textColor(0x000000) display.font("pixelade9") currentY = display.get_string_height(" ") * 5 - 5 display.line(x0, currentY, display.width() - 1, currentY, 0x000000) display.cursor(x0 + 5, currentY + 5) display.print("A: Run\n") display.print("B: Return to home\n") display.print("SELECT: Uninstall app\n") (_, currentY) = display.cursor() display.line(x0, currentY, display.width() - 1, currentY, 0x000000) _ = display.cursor(x0 + 5, currentY + 5) display.print(consts.INFO_FIRMWARE_NAME) else: ugfx.line(0, ugfx.height() - 18 * 4, ugfx.width(), ugfx.height() - 18 * 4, ugfx.BLACK) ugfx.string_box(0, ugfx.height() - 18 * 4, ugfx.width(), 18, " A: Run", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(0, ugfx.height() - 18 * 3, ugfx.width(), 18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(0, ugfx.height() - 18 * 2, ugfx.width(), 18, " SELECT: Uninstall", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.line(0, ugfx.height() - 18 * 1, ugfx.width(), ugfx.height() - 18 * 1, ugfx.BLACK) ugfx.string_box(0, ugfx.height() - 18 * 1, ugfx.width(), 18, " " + consts.INFO_FIRMWARE_NAME, "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) global options global install_path options = None install_path = None ugfx.input_attach(ugfx.BTN_A, input_a) ugfx.input_attach(ugfx.BTN_B, input_b) ugfx.input_attach(ugfx.BTN_SELECT, input_select) ugfx.input_attach(ugfx.JOY_UP, input_other) ugfx.input_attach(ugfx.JOY_DOWN, input_other) ugfx.input_attach(ugfx.JOY_LEFT, input_other) ugfx.input_attach(ugfx.JOY_RIGHT, input_other) ugfx.input_attach(ugfx.BTN_START, input_other) populate_apps() populate_category() populate_options() # do a greyscale flush on start ugfx.flush(ugfx.GREYSCALE)
def string(x, y, text, font, color): if font: display.font(font) _ = display.cursor(x, y) _ = display.textColor(color) display.print(text)
def _draw(self): if self._visible: display.rect(self.x, self.y, self.w, self.h, True, 0xFFFFFF) display.rect(self.x, self.y, self.w, self.h, False, 0x000000) display.font("freesans9") _ = display.textColor(0x000000) display.cursor(self.x + 1, self.y + 1) totalHeight = 0 for i in range(self.offset, len(self.items)): display.cursor(self.x + 1, display.cursor()[1]) item = self.items[i] lineHeight = display.get_string_height(item) totalHeight += lineHeight if totalHeight < self.h: if i == self.selected: display.rect(self.x, display.cursor()[1], self.w, lineHeight, True, 0x000000) _ = display.textColor(0xFFFFFF) else: _ = display.textColor(0x000000) display.cursor(self.x + 1, display.cursor()[1] + 3) display.print(item + "\n") display.cursor(self.x + 1, display.cursor()[1] - 3)