From 285cff1d513b43e3a5f583c79fc558bba902a92c Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 15 Apr 2024 11:55:10 +0200 Subject: [PATCH] ui: increase keyboard buttons font size simply make the keyboard buttons text larger. makes it easier to type. --- src/ui/c/ui.c | 6 ++++++ src/ui/lvgl.zig | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/ui/c/ui.c b/src/ui/c/ui.c index 81a9b81..dd93970 100644 --- a/src/ui/c/ui.c +++ b/src/ui/c/ui.c @@ -102,6 +102,11 @@ extern lv_style_t *nm_style_title() return &style_title; } +extern const lv_font_t *nm_font_large() +{ + return font_large; +} + /** * a hack to prevent tabview from switching to the next tab * on a scroll event, for example coming from a top layer window. @@ -361,6 +366,7 @@ extern int nm_ui_init_main_tabview(lv_obj_t *scr) if (virt_keyboard == NULL) { return -1; } + lv_obj_set_style_text_font(virt_keyboard, font_large, LV_PART_ITEMS); lv_obj_set_style_max_height(virt_keyboard, NM_DISP_HOR * 2 / 3, 0); lv_obj_add_flag(virt_keyboard, LV_OBJ_FLAG_HIDDEN); diff --git a/src/ui/lvgl.zig b/src/ui/lvgl.zig index 39e0886..059a163 100644 --- a/src/ui/lvgl.zig +++ b/src/ui/lvgl.zig @@ -213,6 +213,9 @@ pub const LvStyle = opaque { }; }; +/// represents lv_font_t in C. +pub const LvFont = opaque {}; + /// a simplified color type compatible with LVGL which defines lv_color_t /// as a union containing an bit-fields struct unsupported in zig cImport. pub const Color = u16; // originally c.lv_color_t; TODO: comptime switch for u32 @@ -981,6 +984,8 @@ pub const Keyboard = struct { pub fn new(parent: anytype, mode: Mode) !Keyboard { const kb = lv_keyboard_create(parent.lvobj) orelse return error.OutOfMemory; lv_keyboard_set_mode(kb, @intFromEnum(mode)); + const sel = LvStyle.Selector{ .part = .item }; + lv_obj_set_style_text_font(kb, nm_font_large(), sel.value()); return .{ .lvobj = kb }; } @@ -1126,6 +1131,8 @@ pub const PosAlign = enum(c.lv_align_t) { pub extern fn nm_style_btn_red() *LvStyle; // TODO: make it private /// returns a title style with a larger font. pub extern fn nm_style_title() *LvStyle; // TODO: make it private +/// returns default font of large size. +pub extern fn nm_font_large() *const LvFont; // TODO: make it private // the "native" lv_obj_set/get user_data are static inline, so make our own funcs. extern "c" fn nm_obj_userdata(obj: *LvObj) ?*anyopaque; @@ -1198,6 +1205,7 @@ extern fn lv_obj_remove_style(obj: *LvObj, style: ?*LvStyle, sel: c.lv_style_sel extern fn lv_obj_remove_style_all(obj: *LvObj) void; extern fn lv_obj_set_style_bg_color(obj: *LvObj, val: Color, sel: c.lv_style_selector_t) void; extern fn lv_obj_set_style_text_color(obj: *LvObj, val: Color, sel: c.lv_style_selector_t) void; +extern fn lv_obj_set_style_text_font(obj: *LvObj, font: *const LvFont, sel: c.lv_style_selector_t) void; extern fn lv_obj_set_style_pad_left(obj: *LvObj, val: c.lv_coord_t, sel: c.lv_style_selector_t) void; extern fn lv_obj_set_style_pad_right(obj: *LvObj, val: c.lv_coord_t, sel: c.lv_style_selector_t) void; extern fn lv_obj_set_style_pad_top(obj: *LvObj, val: c.lv_coord_t, sel: c.lv_style_selector_t) void;