Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/The-Young-Maker/OpenMenuOS/llms.txt

Use this file to discover all available pages before exploring further.

CustomScreen gives you a blank canvas to draw anything you like — text, shapes, images, sensor readings — using the full TFT_eSPI sprite API. You assign a drawing function (or lambda) to the customDraw property, and the library calls it automatically whenever the screen needs to be rendered. Pressing SELECT on a CustomScreen navigates back to the previous screen.

Constructors

CustomScreen()

Creates a custom screen without a title.
CustomScreen myScreen;

CustomScreen(const char* title)

Creates a custom screen with a title. The title is used as the item label when you add this screen to a MenuScreen via addItem(Screen*).
title
const char*
required
Title string for this screen.
CustomScreen aboutScreen("About");

Properties

customDraw

Type: std::function<void()> The drawing function called every time the screen renders. Assign a lambda or a regular function pointer here. Inside the function, draw directly to the global canvas (TFT_eSprite) object — the library automatically pushes the canvas to the physical display after customDraw returns.
myScreen.customDraw = []() {
  // Draw to canvas here
};
customDraw must be assigned before menu.begin() is called, typically near the top of setup(). Assigning it after begin() is safe but the screen will render a blank frame on its first draw call.

title

Type: const char* The title string provided to the constructor. Read-only at runtime.
const char* t = myScreen.title; // "About"

Methods

draw()

Renders the screen by invoking customDraw if it is set. Called automatically by the library — you do not need to call it directly.
// Called internally by ScreenManager; no need to call manually.
myScreen.draw();

handleInput()

Processes user input for this screen. Pressing SELECT returns to the previous screen via back navigation. Called automatically inside menu.loop().

The global canvas object

Inside customDraw, you draw to the global TFT_eSprite canvas object that is declared in OpenMenuOS.h:
extern TFT_eSprite canvas;
canvas is a sprite the same size as the display. Use any TFT_eSprite drawing method — fillScreen, drawString, fillCircle, drawRect, pushImage, etc. The library calls drawCanvasOnTFT() after customDraw returns to push the sprite to the physical display.
You can also read menu.getTftWidth() and menu.getTftHeight() inside customDraw to position elements relative to the display size rather than hard-coding pixel coordinates.

Complete example

The following is the customDraw assignment from the official example sketch, showing geometric shapes and a version string drawn to the canvas:
#include "OpenMenuOS.h"

OpenMenuOS menu;

MenuScreen mainMenu("Main Menu");
CustomScreen customScreen("Custom Screen");

void setup() {
  // Assign the drawing function in setup()
  customScreen.customDraw = []() {
    canvas.drawSmoothRoundRect(-15, 50, 40, 0, 50, 50, TFT_BLUE, TFT_BLACK);
    canvas.drawSmoothRoundRect(10, 10, 200, 100, 20, 5, TFT_ORANGE, TFT_BLACK);
    canvas.drawSmoothRoundRect(120, -25, 40, 0, 40, 40, TFT_DARKGREEN, TFT_BLACK);
    canvas.drawString("V" + String(menu.getLibraryVersion()), 10, 10);
    canvas.setTextColor(TFT_WHITE, TFT_BLACK);
    canvas.drawString("Press UP for popup demo", 10, 30);
  };

  mainMenu.addItem(&customScreen); // Label auto-set to "Custom Screen"

  menu.useStylePreset("Rabbit_R1");
  menu.setEncoderPin(5, 2);
  menu.setSelectPin(19);
  menu.begin(&mainMenu);
}

void loop() {
  menu.loop();
}
You can also navigate to a CustomScreen programmatically from an action callback:
void redirectToCustomScreen() {
  menu.redirectToScreen(&customScreen);
}

// Then add to menu:
mainMenu.addItem("Redirect To Screen", nullptr, redirectToCustomScreen);

Build docs developers (and LLMs) love