LVGL GUI Builder and Code Guide
This guide walks you from an empty Lopaka canvas to working LVGL v9 C code on ESP32, STM32, RP2040, or a desktop simulator. Lopaka generates the widget layout function and lv_image_dsc_t image assets; your firmware initializes LVGL, the display driver, touch input, and event callbacks.
What is LVGL?
LVGL (Light and Versatile Graphics Library) is an open-source C graphics library for embedded touchscreens and color displays. Unlike pixel-drawing libraries such as TFT_eSPI or Adafruit GFX, LVGL manages a live object tree of widgets — buttons, sliders, switches, arcs, labels, and images — with built-in styling, states, and input handling.
Use the official LVGL 9 documentation to confirm driver setup and lv_conf.h options for your board.
Before you start
You need:
- A microcontroller with enough RAM and flash for LVGL 9 (typically ESP32, ESP32-S3, STM32, or RP2040) and a color display.
- LVGL v9.x installed in Arduino IDE, PlatformIO, or ESP-IDF.
- A working display flush callback, tick timer, and
lv_timer_handler()loop proven with a minimal LVGL label example.
WARNING
Lopaka generates LVGL v9 C API calls, not display or touch drivers. Confirm that a one-label LVGL 9 example renders on your screen before pasting Lopaka code.
Step 0: Verify LVGL 9 on your board
Install lvgl (v9.x) via Arduino Library Manager, PlatformIO (lvgl/lvgl@^9), or the ESP-IDF Component Registry (espressif/esp_lvgl_port + lvgl/lvgl). Copy lv_conf_template.h to lv_conf.h, enable #if 1, and set LV_COLOR_DEPTH 16 for typical RGB565 SPI/RGB displays.
Before adding Lopaka output, run a minimal check after lv_init() and display registration:
lv_obj_t *hello = lv_label_create(lv_screen_active());
lv_label_set_text(hello, "LVGL 9 ready");
lv_obj_center(hello);When that label appears cleanly, your display driver, color byte order, and timer loop work.
LVGL 8 vs. LVGL 9 API names
Lopaka targets LVGL v9. If you migrate code into an older LVGL 8 project, note the renamed APIs:
| Task | LVGL 8 | LVGL 9 (Lopaka output) |
|---|---|---|
| Active screen | lv_scr_act() | lv_screen_active() |
| Button widget | lv_btn_create() | lv_button_create() |
| Image widget | lv_img_create() | lv_image_create() |
| Image source | lv_img_set_src() | lv_image_set_src() |
| External image macro | LV_IMG_DECLARE() | LV_IMAGE_DECLARE() |
| Image descriptor struct | lv_img_dsc_t | lv_image_dsc_t |
| Label rotation style | transform_angle | transform_rotation |
For image descriptor migration details, read LVGL 9 Images: C Arrays, PNGs, and v8 Migration.
Step 1: Create the Lopaka project
- Open lopaka.app and create a project.
- Select LVGL (v9) as the platform.
- Set Screen Size to your display's logical width and height (for example
320 × 240or480 × 320). - Keep the default
#F5F5F5light-theme screen background or pick a custom screen color.
Lopaka uses an anti-aliased renderer in LVGL projects so rounded corners, arcs, and labels closely approximate LVGL's on-device appearance.
Step 2: Design a screen with LVGL widgets
Place widgets from the toolbar, arrange their draw order in the Layers panel, and configure properties in the Inspector. Rename layers clearly before export — layer names become C variable names such as button_Start, slider_Volume, and arc_Temp.
Lopaka's LVGL generator maps each supported layer to LVGL v9 widget calls:
| Lopaka layer | Generated LVGL v9 C API |
|---|---|
| Panel | lv_obj_create(lv_screen_active()) with position, size, fill, border, radius |
| Button | lv_button_create() with a centered child lv_label_create() |
| Text | lv_label_create(), optional text color and transform_rotation (0/90/180/270) |
| Text Area | lv_textarea_create() with text, border, radius, background, and text color |
| Slider | lv_slider_create() and lv_slider_set_value(..., LV_ANIM_OFF) |
| Switch | lv_switch_create() and optional LV_STATE_CHECKED |
| Checkbox | lv_checkbox_create(), lv_checkbox_set_text(), optional LV_STATE_CHECKED |
| Arc LVGL | lv_arc_create(), lv_arc_set_rotation(), lv_arc_set_bg_angles(), value |
| Paint, icon, image | LV_IMAGE_DECLARE(), lv_image_create(), lv_image_set_src() |
Defaults and minimal generated code
Lopaka matches LVGL v9 light-theme defaults (for example #F5F5F5 screen background, #2196f3 accent color, #FFFFFF panel background, #E0E0E0 border with 2 px width and 6 px radius). When a widget keeps the default value, Lopaka omits redundant lv_obj_set_style_* calls to keep your C code compact.
All colors are emitted as 24-bit hex values via lv_color_hex(0xRRGGBB).
Text rotation
Select a Text layer and rotate it by 0°, 90°, 180°, or 270° in the Inspector. Lopaka emits lv_obj_set_style_transform_rotation(label, angle, LV_PART_MAIN) using LVGL's tenths-of-a-degree units (900, 1800, or 2700).
Step 3: Configure Code Settings
Open Code Settings to tailor the generated C output:
| Setting | Default | What it changes for LVGL |
|---|---|---|
| Wrapper function | On | Wraps the screen in void draw{ScreenName}(void) |
| Declare variables | On | Extracts properties marked as variables into const char* or int declarations |
| Comments, layer titles | On | Adds // <type>: <name> comments before each widget |
| Clear/Fill display | On | Emits lv_obj_set_style_bg_color(lv_screen_active(), ...) when screen background is non-default |
Step 4: Export LVGL images and fonts
Images (lv_image_dsc_t)
Every imported image, icon, or paint layer on LVGL exports as a standalone .c file under Code Settings → Images (named <Name>.c). Inside that file, Lopaka defines:
- A byte array
<Name>_map[]aligned withLV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST. - A
const lv_image_dsc_t image_<Name>_dscdescriptor with.header.magic = LV_IMAGE_HEADER_MAGIC,.header.w,.header.h,.data_size, and.data.
The color format depends on the image's Transparency toggle in the Inspector:
- Transparency off (or opaque image):
LV_COLOR_FORMAT_RGB565(2 bytes per pixel). - Transparency on (with transparent pixels):
LV_COLOR_FORMAT_RGB565A8(RGB565 pixels followed by an 8-bit alpha plane).
In your screen code, Lopaka emits LV_IMAGE_DECLARE(image_<Name>_dsc); and binds it with lv_image_set_src(widget, &image_<Name>_dsc);. Add the downloaded .c file to your firmware build (do not #include the .c file in two places, or the linker reports duplicate symbols).
To convert a single PNG, BMP, or JPEG straight into an LVGL 9 lv_image_dsc_t .c file without an account, use the free Image Converter and choose LVGL.
Fonts
Lopaka's LVGL editor currently renders text with the built-in Montserrat font and does not emit lv_obj_set_style_text_font() calls or upload custom LVGL C fonts inside the editor.
To use a custom size or typeface in your LVGL firmware:
- Enable built-in Montserrat sizes in
lv_conf.h(for example#define LV_FONT_MONTSERRAT_20 1), or convert a TTF, OTF, WOFF, BDF, or GFX font into an LVGL 8/9.cfont file with Lopaka's free browser Font Converter (choose LVGL — no account required). - Add the generated
.cfile to your firmware build, declare it withLV_FONT_DECLARE(), and apply it after calling Lopaka's draw function:
LV_FONT_DECLARE(my_font); // for a custom .c font file
lv_obj_set_style_text_font(label_Title, &my_font, LV_PART_MAIN);The same Font Converter also exports .h headers for U8g2 and Adafruit GFX / TFT_eSPI, and .bdf files.
Step 5: Integrate into ESP32 Arduino or ESP-IDF
Create a screen named Dashboard, add a panel, a label, an arc, and a button, and click Copy. Representative output looks like this:
void drawDashboard(void) {
lv_obj_set_style_bg_color(lv_screen_active(), lv_color_hex(0x101820), LV_PART_MAIN);
// panel: Card
lv_obj_t * panel_Card = lv_obj_create(lv_screen_active());
lv_obj_set_pos(panel_Card, 12, 12);
lv_obj_set_size(panel_Card, 296, 216);
lv_obj_set_style_bg_color(panel_Card, lv_color_hex(0x1E293B), LV_PART_MAIN);
lv_obj_set_style_border_width(panel_Card, 1, LV_PART_MAIN);
// string: Title
lv_obj_t * label_Title = lv_label_create(lv_screen_active());
lv_obj_set_style_text_color(label_Title, lv_color_hex(0xFFFFFF), LV_PART_MAIN);
lv_obj_set_pos(label_Title, 28, 24);
lv_label_set_text(label_Title, "Thermostat");
// arcLvgl: Target
lv_obj_t * arc_Target = lv_arc_create(lv_screen_active());
lv_obj_set_pos(arc_Target, 32, 64);
lv_obj_set_size(arc_Target, 120, 120);
lv_arc_set_bg_angles(arc_Target, 135, 45);
lv_arc_set_value(arc_Target, 65);
// button: Boost
lv_obj_t * button_Boost = lv_button_create(lv_screen_active());
lv_obj_set_pos(button_Boost, 180, 108);
lv_obj_set_size(button_Boost, 104, 42);
lv_obj_t * button_Boost_label = lv_label_create(button_Boost);
lv_label_set_text(button_Boost_label, "Boost");
lv_obj_center(button_Boost_label);
}Calling the screen once, not every frame
Unlike immediate-mode libraries, call drawDashboard() once during initialization (or when switching screens), not inside loop(). Calling lv_*_create() repeatedly in a loop leaks RAM until the microcontroller crashes.
// Arduino or ESP-IDF startup, after lv_init() and display setup:
drawDashboard();
// Main loop:
while (1) {
lv_timer_handler();
vTaskDelay(pdMS_TO_TICKS(5)); // or delay(5) on Arduino
}Wiring events and live values
Because each generated lv_obj_t * pointer is local to drawDashboard(), promote any widget you need to update at runtime to a file-scope pointer or attach lv_obj_add_event_cb() right after creating it:
static lv_obj_t *arc_Target = NULL;
static void on_boost_clicked(lv_event_t *e) {
(void)e;
if (arc_Target) {
lv_arc_set_value(arc_Target, 80);
}
}In ESP-IDF using esp_lvgl_port, always wrap drawDashboard() and later widget updates inside lvgl_port_lock(0) / lvgl_port_unlock().
Lopaka vs. SquareLine Studio and EEZ Studio
Developers often compare visual LVGL tools before committing to a workflow:
| Criterion | Lopaka | SquareLine Studio | EEZ Studio |
|---|---|---|---|
| Installation | Browser-based, zero install | Desktop app | Desktop app (open source) |
| Generated code style | Plain LVGL v9 C function, easy to read/edit | Project tree with helper runtime files | Project tree with EEZ Flow runtime |
| Multi-library support | 10+ libraries (LVGL, U8g2, TFT_eSPI, ESPHome) | LVGL only | LVGL + EEZ Flow |
| Advanced LVGL features | Core widgets + RGB565/RGB565A8 images | Flex/grid, animations, events, fonts | Flex/grid, flow visual logic, fonts |
| Best fit | Fast layouts, prototypes, multi-screen teams | Full commercial LVGL apps | Open-source desktop LVGL + flow apps |
Read the deeper architectural comparison in LVGL vs. Custom Drawing: Why GUI Builders Win for Production.
Lopaka handles vs. you handle
| Lopaka handles | You handle |
|---|---|
| Visual widget placement, sizing, and layering | lv_init(), lv_conf.h, display flush, and tick timer |
| Clean LVGL v9 C widget creation and style calls | Touch/encoder input driver registration |
lv_image_dsc_t .c files (RGB565 / RGB565A8) | Compiling .c asset files into your firmware build |
| Variable declarations for dynamic text/positions | Event callbacks (lv_obj_add_event_cb) and state updates |
| Multi-screen prototyping and shareable URLs | Screen switching (lv_screen_load) and thread locking |
Troubleshooting
Undefined reference to image_<Name>_dsc
The LV_IMAGE_DECLARE() macro only declares the symbol; it does not compile the pixel bytes. Download <Name>.c from Code Settings → Images and add it to your Arduino sketch folder, PlatformIO src/, or ESP-IDF CMakeLists.txt (SRCS).
Compiler errors on lv_button_create or lv_screen_active
Your project is compiling against LVGL 8. Upgrade to LVGL 9, or replace v9 names with their v8 equivalents (lv_btn_create, lv_scr_act, lv_img_create, LV_IMG_DECLARE).
Device crashes or runs out of memory after a few seconds
You are calling drawDashboard() inside loop() or a periodic timer. Call it once when building the screen, then update existing widget pointers with lv_label_set_text() or lv_arc_set_value().
Image colors look swapped or tinted
On 16-bit SPI displays, check LV_COLOR_16_SWAP or your display driver's byte-swap setting in the flush callback. Test with a solid red (0xFF0000) panel first to confirm byte order.
Text looks small or clipped
Enable the Montserrat size you need in lv_conf.h and apply it with lv_obj_set_style_text_font(). Also verify that LV_USE_LABEL and LV_USE_TEXTAREA are enabled in lv_conf.h.
FAQ
Does Lopaka generate LVGL 8 or LVGL 9 code?
Lopaka generates LVGL v9 C code using v9 APIs such as lv_screen_active(), lv_button_create(), lv_image_create(), LV_IMAGE_DECLARE(), and lv_image_dsc_t. For LVGL 8 firmware, either upgrade to LVGL 9 or map the renamed symbols (for example lv_scr_act, lv_btn_create, lv_img_create, and lv_img_dsc_t) in your project.
How do I convert an image to an LVGL 9 lv_image_dsc_t C file?
Use the free browser Image Converter with no account, or import PNG, BMP, or GIF files into an LVGL project in Lopaka. Download the generated .c file from Code Settings → Images and compile it with your firmware; it emits LV_COLOR_FORMAT_RGB565 for opaque images or LV_COLOR_FORMAT_RGB565A8 when Transparency is enabled.
Which LVGL widgets does Lopaka support?
Lopaka's LVGL platform supports Panel (lv_obj_create), Button (lv_button_create with a centered label), Label (lv_label_create with optional rotation), Text Area (lv_textarea_create), Slider (lv_slider_create), Switch (lv_switch_create), Checkbox (lv_checkbox_create), Arc LVGL (lv_arc_create), and Image (lv_image_create with lv_image_dsc_t).
How does Lopaka compare to SquareLine Studio and EEZ Studio?
Lopaka runs in the browser with zero install and generates plain LVGL v9 C functions without a proprietary project runtime. It works well for fast screen layouts, prototypes, and image descriptors. Choose SquareLine Studio or EEZ Studio when you need full LVGL-native visual flows, animations, flex or grid layouts, and custom LVGL font tables.
Can I upload custom fonts in a Lopaka LVGL project?
Not yet inside Lopaka's LVGL editor, which currently uses the built-in Montserrat font. To use custom fonts in LVGL firmware, generate an LVGL 8/9 .c font file with Lopaka's free browser Font Converter (no account required), add it to your build, declare it with LV_FONT_DECLARE(), and apply it with lv_obj_set_style_text_font() in your code.
Does Lopaka configure my ESP32 display driver or touch controller for LVGL?
No. Lopaka generates the UI widget layout function and image asset files. Your Arduino or ESP-IDF firmware must initialize LVGL, the display flush callback, touch input driver, tick source, and lv_timer_handler() loop.