Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Jan 21, 2023
1 parent b03491a commit c7a33f1
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions lvgltest.zig
Original file line number Diff line number Diff line change
Expand Up @@ -53,76 +53,76 @@ pub export fn lv_demo_widgets() void {
// Create Widgets

/// Create the LVGL Widgets that will be rendered on the display. Calls the
/// LVGL API directly, without wrapping in Zig. Based on
/// LVGL API that has been wrapped in Zig. Based on
/// https://docs.lvgl.io/master/widgets/label.html?highlight=lv_label_create#line-wrap-recoloring-and-scrolling
fn createWidgetsUnwrapped() !void {
debug("createWidgetsUnwrapped: start", .{});
defer { debug("createWidgetsUnwrapped: end", .{}); }
fn createWidgetsWrapped() !void {
debug("createWidgetsWrapped: start", .{});
defer { debug("createWidgetsWrapped: end", .{}); }

// Get the Active Screen
const screen = c.lv_scr_act().?;
var screen = try lvgl.getActiveScreen();

// Create a Label Widget
const label = c.lv_label_create(screen).?;
var label = try screen.createLabel();

// Wrap long lines in the label text
c.lv_label_set_long_mode(label, c.LV_LABEL_LONG_WRAP);
label.setLongMode(c.LV_LABEL_LONG_WRAP);

// Interpret color codes in the label text
c.lv_label_set_recolor(label, true);
label.setRecolor(true);

// Center align the label text
c.lv_obj_set_style_text_align(label, c.LV_TEXT_ALIGN_CENTER, 0);
label.setAlign(c.LV_TEXT_ALIGN_CENTER);

// Set the label text and colors
c.lv_label_set_text(
label,
label.setText(
"#ff0000 HELLO# " ++ // Red Text
"#00aa00 PINEDIO# " ++ // Green Text
"#0000ff STACK!# " // Blue Text
"#00aa00 LVGL ON# " ++ // Green Text
"#0000ff PINEPHONE!# " // Blue Text
);

// Set the label width
c.lv_obj_set_width(label, 200);
label.setWidth(200);

// Align the label to the center of the screen, shift 30 pixels up
c.lv_obj_align(label, c.LV_ALIGN_CENTER, 0, -30);
label.alignObject(c.LV_ALIGN_CENTER, 0, -30);
}

/// Create the LVGL Widgets that will be rendered on the display. Calls the
/// LVGL API that has been wrapped in Zig. Based on
/// LVGL API directly, without wrapping in Zig. Based on
/// https://docs.lvgl.io/master/widgets/label.html?highlight=lv_label_create#line-wrap-recoloring-and-scrolling
fn createWidgetsWrapped() !void {
debug("createWidgetsWrapped: start", .{});
defer { debug("createWidgetsWrapped: end", .{}); }
fn createWidgetsUnwrapped() !void {
debug("createWidgetsUnwrapped: start", .{});
defer { debug("createWidgetsUnwrapped: end", .{}); }

// Get the Active Screen
var screen = try lvgl.getActiveScreen();
const screen = c.lv_scr_act().?;

// Create a Label Widget
var label = try screen.createLabel();
const label = c.lv_label_create(screen).?;

// Wrap long lines in the label text
label.setLongMode(c.LV_LABEL_LONG_WRAP);
c.lv_label_set_long_mode(label, c.LV_LABEL_LONG_WRAP);

// Interpret color codes in the label text
label.setRecolor(true);
c.lv_label_set_recolor(label, true);

// Center align the label text
label.setAlign(c.LV_TEXT_ALIGN_CENTER);
c.lv_obj_set_style_text_align(label, c.LV_TEXT_ALIGN_CENTER, 0);

// Set the label text and colors
label.setText(
c.lv_label_set_text(
label,
"#ff0000 HELLO# " ++ // Red Text
"#00aa00 PINEDIO# " ++ // Green Text
"#0000ff STACK!# " // Blue Text
"#00aa00 LVGL ON# " ++ // Green Text
"#0000ff PINEPHONE!# " // Blue Text
);

// Set the label width
label.setWidth(200);
c.lv_obj_set_width(label, 200);

// Align the label to the center of the screen, shift 30 pixels up
label.alignObject(c.LV_ALIGN_CENTER, 0, -30);
c.lv_obj_align(label, c.LV_ALIGN_CENTER, 0, -30);
}

///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit c7a33f1

Please sign in to comment.