diff options
| -rwxr-xr-x | .ccls | 10 | ||||
| -rwxr-xr-x | compile | 12 | ||||
| -rwxr-xr-x | project | 29 | ||||
| -rwxr-xr-x | run | 7 | ||||
| -rw-r--r-- | src/main.c | 6 | ||||
| -rw-r--r-- | src/ui/tui.c | 25 | ||||
| -rw-r--r-- | src/ui/tui.h | 21 | 
7 files changed, 61 insertions, 49 deletions
@@ -1,6 +1,6 @@ -clang -%c -std=c11 -%cpp -std=c++2a +gcc +%c -std=c23 +%cpp -std=c++23  %h %hpp --include=Global.h  -Iinc  -DMACRO @@ -9,5 +9,5 @@ clang  # %hpp -x  # %hpp c++-header -# %h -x -# %h c-header +%h -x +%h c-header diff --git a/compile b/compile deleted file mode 100755 index 1b54aae..0000000 --- a/compile +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -project_name="atui" - -if [ ! -d build ]; then -	if [ $(mkdir build) ]; then # if error -		echo "cannot make 'build' dir" -		exit -	fi -fi - -gcc -Wall -Wextra -O3 -std=gnu23 src/main.c src/ui/tui.c -o "build/$project_name" @@ -0,0 +1,29 @@ +#!/bin/bash + +project_name="atui" + +function compile(){ +  if [ ! -d build ]; then +    if [ $(mkdir build) ]; then # if error +      echo "cannot make 'build' dir" +      exit +    fi +  fi + +  gcc -Wall -Wextra -O3 src/main.c src/ui/tui.c -o "build/$project_name" +} + +function run(){ +  compile && "./build/$project_name" "$@" +  echo +  echo "$?" +} + +function clear(){ +  rm -r ./build/ +} + +function_name="$1" +shift + +$function_name "$@" @@ -1,7 +0,0 @@ -#!/bin/bash - -project_name="atui" - -./compile && "./build/$project_name" "$@" -echo -echo "$?" @@ -12,9 +12,9 @@ void on_button_click(const MOUSE_ACTION *mouse_action) {  WIDGET *ui_build(TUI *tui) {    if (is_clicked) { -    char frame[20+3+1]; +    char frame[20+4+1];      const uint64_t fps = 1000000000/tui->last_frame; -    sprintf(frame, "%ldfps", fps); +    sprintf(frame, "%ldfps\n", fps);      return tui_make_box(          -1, -1,          tui_make_column(tui_make_widget_array( @@ -25,7 +25,7 @@ WIDGET *ui_build(TUI *tui) {                      20, 3,                      tui_make_column(tui_make_widget_array(                          tui_make_text(frame, COLOR_BLUE), -                        tui_make_button(tui_make_text("       Back", COLOR_RED), +                        tui_make_button(tui_make_text("Back", COLOR_RED),                                          on_button_click))),                      COLOR_WHITE))))),          COLOR_MAGENTA); diff --git a/src/ui/tui.c b/src/ui/tui.c index 5f6acaa..ca87655 100644 --- a/src/ui/tui.c +++ b/src/ui/tui.c @@ -282,7 +282,7 @@ void _tui_draw_widget_to_cells(TUI *tui, const WIDGET *widget, int width_begin,              const int y = height;              const char c = metadata->text[inserted_index];              inserted_index += 1; -            if (c == '\n') { +            if (c == '\n') {// do for other spaces                height += 1;                j = 0;                goto START_OF_HORIZONTAL_LOOP; @@ -388,9 +388,7 @@ void _tui_draw_widget_to_cells(TUI *tui, const WIDGET *widget, int width_begin,    }  } -int _tui_move_to_in_str(char *str, int x, int y) { -  return sprintf(str, "\033[%d;%dH", y + 1, x + 1); -} +void _tui_move_to_start_in_str(char *str) { strcpy(str, "\033[;H"); }  int _tui_get_background_color_ascii(COLOR color) {    if (color == COLOR_NO_COLOR) { @@ -406,7 +404,7 @@ void _tui_draw_cells_to_terminal(TUI *tui) {    const size_t size = tui->cells_length * size_of_cell;    char str[(size + 2) * sizeof(char) + 1]; -  _tui_move_to_in_str(str, 0, 0); +  _tui_move_to_start_in_str(str);    char cell_str[5]; @@ -452,20 +450,21 @@ int kbhit() {    return select(1, &fds, NULL, NULL, &tv) > 0;  } -bool widget_array_eqauls(const WIDGET_ARRAY *restrict left, -                         const WIDGET_ARRAY *restrict right) { +bool tui_widget_array_eqauls(const WIDGET_ARRAY *restrict left, +                             const WIDGET_ARRAY *restrict right) {    if (left->size != right->size) {      return false;    }    for (size_t i = 0; i < left->size; ++i) { -    if (!widget_eqauls(left->widgets[i], right->widgets[i])) { +    if (!tui_widget_eqauls(left->widgets[i], right->widgets[i])) {        return false;      }    }    return true;  } -bool widget_eqauls(const WIDGET *restrict left, const WIDGET *restrict right) { +bool tui_widget_eqauls(const WIDGET *restrict left, +                       const WIDGET *restrict right) {    if (left == NULL || right == NULL) {      return left == NULL && right == NULL;    } @@ -484,17 +483,17 @@ bool widget_eqauls(const WIDGET *restrict left, const WIDGET *restrict right) {        const BUTTON_METADATA *left_data = left->metadata;        const BUTTON_METADATA *right_data = right->metadata;        return left_data->callback == right_data->callback && -             widget_eqauls(left_data->child, right_data->child); +             tui_widget_eqauls(left_data->child, right_data->child);      } break;      case WIDGET_TYPE_COLUMN: {        const COLUMN_METADATA *left_data = left->metadata;        const COLUMN_METADATA *right_data = right->metadata; -      return widget_array_eqauls(left_data->children, right_data->children); +      return tui_widget_array_eqauls(left_data->children, right_data->children);      } break;      case WIDGET_TYPE_ROW: {        const ROW_METADATA *left_data = left->metadata;        const ROW_METADATA *right_data = right->metadata; -      return widget_array_eqauls(left_data->children, right_data->children); +      return tui_widget_array_eqauls(left_data->children, right_data->children);      } break;      case WIDGET_TYPE_BOX: {        const BOX_METADATA *left_data = left->metadata; @@ -502,7 +501,7 @@ bool widget_eqauls(const WIDGET *restrict left, const WIDGET *restrict right) {        return left_data->width == right_data->width &&               left_data->height == right_data->height &&               left_data->color == right_data->color && -             widget_eqauls(left_data->child, right_data->child); +             tui_widget_eqauls(left_data->child, right_data->child);      } break;      default:        fprintf(stderr, "Type error '%d' in tui_delete_widget\n", left->type); diff --git a/src/ui/tui.h b/src/ui/tui.h index baf0c3a..86efa1d 100644 --- a/src/ui/tui.h +++ b/src/ui/tui.h @@ -30,11 +30,10 @@ typedef struct MOUSE_ACTION {  typedef void (*ON_CLICK_CALLBACK)(const MOUSE_ACTION *mouse_action); -  #ifndef __cplusplus -#if (__STDC_VERSION__ < 202000L) +  #if (__STDC_VERSION__ < 202000L)  typedef enum bool : uint8_t { false = 0, true = 1 } bool; -#endif +  #endif  #endif  typedef enum COLOR { @@ -62,7 +61,7 @@ typedef struct TUI {    int init_cursor_x, init_cursor_y;    TERMINAL_CELL *cells;    size_t cells_length; -  uint64_t last_frame; // in nanoseconds +  uint64_t last_frame;  // in nanoseconds  } TUI;  typedef enum WIDGET_TYPE { @@ -128,8 +127,10 @@ extern void _tui_draw_widget_to_cells(TUI *tui, const WIDGET *widget,                                        int height_begin, int height_end,                                        int *child_width, int *childHeight); -extern bool widget_eqauls(const WIDGET *restrict left, const WIDGET *restrict right); -extern bool widget_array_eqauls(const WIDGET_ARRAY *restrict left, const WIDGET_ARRAY * restrict right); +extern bool tui_widget_eqauls(const WIDGET *restrict left, +                              const WIDGET *restrict right); +extern bool tui_widget_array_eqauls(const WIDGET_ARRAY *restrict left, +                                    const WIDGET_ARRAY *restrict right);  extern void tui_main_loop(TUI *tui, WIDGET_BUILDER widget_builder, int fps); @@ -147,8 +148,8 @@ extern BUTTON_METADATA *_tui_make_button_metadata(WIDGET *restrict child,  extern void _tui_delete_button(WIDGET *restrict button);  extern WIDGET *tui_make_column(WIDGET_ARRAY *restrict children); -extern COLUMN_METADATA * -_tui_make_column_metadata(WIDGET_ARRAY *restrict children); +extern COLUMN_METADATA *_tui_make_column_metadata( +    WIDGET_ARRAY *restrict children);  extern void _tui_delete_column(WIDGET *restrict column);  extern WIDGET *tui_make_row(WIDGET_ARRAY *restrict children); @@ -164,6 +165,8 @@ extern void _tui_delete_box(WIDGET *restrict box);  extern WIDGET_ARRAY *tui_make_widget_array_raw(size_t size, ...);  extern void _tui_delete_widget_array(WIDGET_ARRAY *restrict widget_array); -#define tui_make_widget_array(...) tui_make_widget_array_raw(sizeof((WIDGET* []) {__VA_ARGS__}) / sizeof(WIDGET*), __VA_ARGS__) +#define tui_make_widget_array(...) \ +  tui_make_widget_array_raw(       \ +      sizeof((WIDGET *[]){__VA_ARGS__}) / sizeof(WIDGET *), __VA_ARGS__)  #endif  |