You are browsing as a guest. Sign up (or log in) to start making projects!

15h 20m 44s logged


Hi there guys! These are a lot of hours to log i know, but I swear I
have a reason!!


The main problem that took so long

When I started to work on the client I came accross the problem of
making a stable and working UI for it, and because I’m one of the
cool kids developing in C (this is me -> 🤓) I obviously had to go
for a TUI(Text User Interface) for street cred.

Nerdy stuff about library searching and linking

There i came accross the first real problem of the journey, wich library
do I use (because no way im gonna code all of that myself)??

While searching i came accross a second problem: NOBODY USES A TUI,
there are 0, and i mean 0 multi-platform libraries that work for
linux and windows because of console shenanigans.
I spent 2 hours + another 2 hours of changing the build pipe COMPLETELY
(goodbye MSVC, hi there gcc and ninja) to find something.

At last i went with NCurses for linux and PDCurses for windows,
and the coolest thing is that they have (almost) the same exact API,
so i just need to link them conditionally.

Now out of the way with nerdy stuff and hi there cool TUI graphical
stuff.


Hi there graphical elements!!

Now NCurses and PDCurses are mainly low level console libraries, in
short they allow you to manipulate the console and cursor however you
want (with some utility stuff).
but we need a good old UI, so we need textboxes, menus, input
fields
, etc.

while some of these exist for NCurses as addons, they dont for PDCurses, so i went with the bob the builder approach.
I’m spending this much time writing the UI elements, for now the only thing I can show for my work is a textbox element that with a couple of lines
of code can display text with: padding, colors and eventual attributes (bold, italic, etc…).

other than that i made some changes to
utils and added a really cool split_lines function that makes splitting on newline in C pretty easy.

Here’s a little preview of the textboxes!

the code:

    init_pair(1, COLOR_RED, COLOR_BLUE);
    textbox_t* my_txt = create_textbox(stdscr, POINT(0,0), PAD(1, 1, 1, 1), str, A_BOLD, COLOR_PAIR(1));
    if(!my_txt) {
        error("hell naw");
        return 1;
    }
    point_t centered = get_centered_pos(stdscr, my_txt->h, my_txt->w);
    move_text_box(my_txt, centered);
    if(draw_textbox(my_txt) == -1) error("ERR");
    getch();
    destroy_textbox(my_txt);

the result:

0
10

Comments 0

No comments yet. Be the first!