src,lib: zig fmt and clang-format all code

C style is now fixed by .clang-format.
a handy script to check all source code formatting is in
tools/fmt-check.sh.
pull/20/head
alex 2 years ago
parent 161a2b965b
commit 698e5b6f76
Signed by: x1ddos
GPG Key ID: FDEFB4A63CBD8460

@ -0,0 +1,14 @@
# https://clang.llvm.org/docs/ClangFormat.html
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
---
IndentWidth: 4
ContinuationIndentWidth: 4
UseTab: Never
ColumnLimit: 102
PointerAlignment: Right
BreakBeforeBraces: Linux
AlignAfterOpenBracket: DontAlign
BinPackArguments: false
BinPackParameters: false
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true

@ -9,8 +9,8 @@ export fn lv_timer_del(timer: *opaque{}) void {
}
test {
std.testing.refAllDecls(@This());
_ = @import("comm.zig");
_ = @import("ngui.zig");
std.testing.refAllDecls(@This());
}

@ -11,4 +11,3 @@ pub const TestTimer = if (!builtin.is_test) @compileError("TestTimer is for test
return self.value;
}
};

@ -2,9 +2,9 @@
* framebuffer display + evdev touchpad drivers init
*/
#include "lvgl/lvgl.h"
#include "lv_drivers/display/fbdev.h"
#include "lv_drivers/indev/evdev.h"
#include "lvgl/lvgl.h"
#define DISP_BUF_SIZE NM_DISP_HOR *NM_DISP_VER / 10

@ -2,11 +2,11 @@
* SDL2 drivers init for display, keyboard and mouse
*/
#include "lv_drivers/sdl/sdl.h"
#include "lvgl/lvgl.h"
#include "lvgl/src/misc/lv_log.h"
#include "lv_drivers/sdl/sdl.h"
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/
#define SDL_MAIN_HANDLED /* suppress "undefined reference to WinMain" */
#include SDL_INCLUDE_PATH
lv_disp_t *drv_init(void)
@ -20,7 +20,10 @@ lv_disp_t* drv_init(void)
unsigned char bpp = SDL_BITSPERPIXEL(dm.format);
LV_LOG_INFO("%ix%i %dbpp %s", dm.w, dm.h, bpp, SDL_GetPixelFormatName(dm.format));
if (dm.w != NM_DISP_HOR || dm.h != NM_DISP_VER || bpp != LV_COLOR_DEPTH) {
LV_LOG_WARN("SDL display mismatch; expected %dx%d %dbpp", NM_DISP_HOR, NM_DISP_VER, LV_COLOR_DEPTH);
LV_LOG_WARN("SDL display mismatch; expected %dx%d %dbpp",
NM_DISP_HOR,
NM_DISP_VER,
LV_COLOR_DEPTH);
}
}

@ -38,21 +38,25 @@ static void textarea_event_cb(lv_event_t* e)
lv_obj_set_height(tabview, NM_DISP_VER);
lv_obj_add_flag(virt_keyboard, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_state(textarea, LV_STATE_FOCUSED);
lv_indev_reset(NULL, textarea); /* forget the last clicked object to make it focusable again */
lv_indev_reset(NULL, textarea); /* forget last obj to make it focusable again */
}
}
static void create_bitcoin_panel(lv_obj_t *parent)
{
lv_obj_t *label = lv_label_create(parent);
lv_label_set_text_static(label, "bitcoin tab isn't designed yet\nfollow https://nakamochi.io");
lv_label_set_text_static(label,
"bitcoin tab isn't designed yet\n"
"follow https://nakamochi.io");
lv_obj_center(label);
}
static void create_lnd_panel(lv_obj_t *parent)
{
lv_obj_t *label = lv_label_create(parent);
lv_label_set_text_static(label, "lightning tab isn't designed yet\nfollow https://nakamochi.io");
lv_label_set_text_static(label,
"lightning tab isn't designed yet\n"
"follow https://nakamochi.io");
lv_obj_center(label);
}
@ -111,11 +115,10 @@ static void power_halt_btn_callback(lv_event_t *e)
/* first button must always be a "proceed", do shutdown;
* text is irrelevant */
static const char *btns[] = {"PROCEED", "ABORT", NULL};
lv_obj_t *msgbox = lv_msgbox_create(
NULL /* modal */,
lv_obj_t *msgbox = lv_msgbox_create(NULL, /* modal */
"SHUTDOWN", /* title */
"are you sure?", /* text */
btns,
btns, /* */
false /* close btn */);
lv_obj_center(msgbox);
lv_obj_add_event_cb(msgbox, power_halt_btn_callback, LV_EVENT_VALUE_CHANGED, msgbox);
@ -198,17 +201,16 @@ static void create_settings_panel(lv_obj_t* parent)
* layout
********************/
static lv_coord_t parent_grid_cols[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
static lv_coord_t parent_grid_rows[] = {
static lv_coord_t parent_grid_rows[] = {/**/
LV_GRID_CONTENT, /* wifi panel */
LV_GRID_CONTENT, /* power panel */
LV_GRID_TEMPLATE_LAST
};
LV_GRID_TEMPLATE_LAST};
lv_obj_set_grid_dsc_array(parent, parent_grid_cols, parent_grid_rows);
lv_obj_set_grid_cell(wifi_panel, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1);
lv_obj_set_grid_cell(power_panel, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 1, 1);
static lv_coord_t wifi_grid_cols[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
static lv_coord_t wifi_grid_rows[] = {
static lv_coord_t wifi_grid_rows[] = {/**/
LV_GRID_CONTENT, /* title */
5, /* separator */
LV_GRID_CONTENT, /* wifi status text */
@ -218,8 +220,7 @@ static void create_settings_panel(lv_obj_t* parent)
30, /* password input */
5, /* separator */
LV_GRID_CONTENT, /* connect btn */
LV_GRID_TEMPLATE_LAST
};
LV_GRID_TEMPLATE_LAST};
lv_obj_set_grid_dsc_array(wifi_panel, wifi_grid_cols, wifi_grid_rows);
lv_obj_set_grid_cell(wifi_panel_title, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1);
lv_obj_set_grid_cell(wifi_spinner, LV_GRID_ALIGN_END, 1, 1, LV_GRID_ALIGN_CENTER, 0, 1);
@ -233,12 +234,11 @@ static void create_settings_panel(lv_obj_t* parent)
lv_obj_set_grid_cell(wifi_connect_btn, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_CENTER, 8, 1);
static lv_coord_t power_grid_cols[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
static lv_coord_t power_grid_rows[] = {
static lv_coord_t power_grid_rows[] = {/**/
LV_GRID_CONTENT, /* title */
5, /* separator */
LV_GRID_CONTENT, /* power off text and btn*/
LV_GRID_TEMPLATE_LAST
};
LV_GRID_TEMPLATE_LAST};
lv_obj_set_grid_dsc_array(power_panel, power_grid_cols, power_grid_rows);
lv_obj_set_grid_cell(power_panel_title, LV_GRID_ALIGN_STRETCH, 0, 2, LV_GRID_ALIGN_CENTER, 0, 1);
/* column 0 */
@ -268,12 +268,11 @@ extern int ui_init()
return -1;
}
/* default theme is static */
lv_theme_t* theme = lv_theme_default_init(
disp,
lv_theme_t *theme = lv_theme_default_init(disp, /**/
lv_palette_main(LV_PALETTE_BLUE), /* primary */
lv_palette_main(LV_PALETTE_RED), /* secondary */
true /*LV_THEME_DEFAULT_DARK*/,
LV_FONT_DEFAULT);
true, /* dark mode, LV_THEME_DEFAULT_DARK */
LV_FONT_DEFAULT /* lv_conf.h def */);
lv_disp_set_theme(disp, theme);
font_large = &lv_font_courierprimecode_24; /* static */

@ -0,0 +1,5 @@
#!/bin/sh
set -e
zig fmt --check .
C_FILES=$(find ./src -type f -name '*.c' ! -name 'lv_font*')
clang-format -style=file -dry-run -verbose -Werror $C_FILES