payredu

Cross-platform ledger GUI written in c99
git clone git@getsh.org:payredu.git
Log | Files | Refs | README

balance.c (1898B)


      1 #include <stdio.h>
      2 #include <stddef.h>
      3 #include <stdlib.h>
      4 #include <time.h>
      5 #include "common.h"
      6 
      7 #include <GLFW/glfw3.h>
      8 #define NK_INCLUDE_FIXED_TYPES
      9 #define NK_INCLUDE_STANDARD_IO
     10 #define NK_INCLUDE_STANDARD_VARARGS
     11 #define NK_INCLUDE_DEFAULT_ALLOCATOR
     12 #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
     13 #define NK_INCLUDE_FONT_BAKING
     14 #define NK_INCLUDE_DEFAULT_FONT
     15 #define NK_IMPLEMENTATION
     16 #define NK_GLFW_GL2_IMPLEMENTATION
     17 #define NK_KEYSTATE_BASED_INPUT
     18 #include <nuklear.h>
     19 #include <nuklear_glfw_gl2.h>
     20 
     21 #include "book.h"
     22 
     23 float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) {
     24 	return 10.0f;
     25 }
     26 
     27 
     28 void edit_entry(int i) {
     29 	printf("ledger_edit_entry(%d)\n", i);
     30 }
     31 
     32 void* module_main(struct nk_context* ctx, int width, int height) {
     33 	// main render loop
     34 	// handle file loading
     35 	// handle rendering clicks etc
     36 	Entry** new_list = ledger_read_file("october-2023.txt", time(NULL), time(NULL));
     37 	if (nk_begin(ctx, "balance", nk_rect(0, 0, width, height), 0)) {
     38 		float size[] = {0.10, 0.70, 0.30};
     39 		nk_layout_row(ctx, NK_DYNAMIC, 0, 3, size);
     40 		nk_layout_row_begin(ctx, NK_STATIC, 25, 1);
     41 		//nk_layout_row_push(ctx, 40);
     42 		//nk_label(ctx, "500", NK_TEXT_LEFT);
     43 		nk_layout_row_end(ctx);
     44 
     45 		int len = 12;
     46 		for(int i = 0; i < len; i++) {
     47 			nk_layout_row_begin(ctx, NK_DYNAMIC, 0, 2);
     48 			nk_layout_row_push(ctx, 0.7f);
     49 			char* name = (char*)malloc(sizeof(char) * 50);
     50 			sprintf(name, "%s: %d", new_list[i]->to->name, 500);
     51 			if(nk_button_label(ctx, name)) {
     52 				printf("%s\n", name);
     53 				edit_entry(i);
     54 			}
     55 			//nk_layout_row_push(ctx, 0.3f);
     56 			//nk_label(ctx, "500", NK_TEXT_LEFT);
     57 			nk_layout_row_end(ctx);
     58 		}
     59 
     60 		nk_layout_row_begin(ctx, NK_STATIC, 25, 1);
     61 		nk_layout_row_push(ctx, 100);
     62 		if (nk_button_label(ctx, " + Add Entry")) {
     63 			// event handling
     64 			printf("ledger_add_entry\n");
     65 		}
     66 		nk_layout_row_end(ctx);
     67 	}
     68 	nk_end(ctx);
     69 	return NULL;
     70 }