frang75 / nappgui_src

SDK for building cross-platform desktop apps in ANSI-C
https://www.nappgui.com
MIT License
503 stars 50 forks source link

Enhancement: make table column data follow column header alignment #113

Closed SamSandq closed 8 months ago

SamSandq commented 8 months ago

Currently, one may set the alignment of table header columns, for example:

tableview_header_align(collections, id, ekRIGHT);

It is not possible right now to set the same for column data. I suggest it would be natural to allow the data to follow the column header.

This is easily accomplished by changing tableview.c: i_draw_cell, line

draw_text_halign(ctx, cell->align);

to read instead

draw_text_halign(ctx, col->align);

I propose that this be done, or a separate function tableview_column_align(...) be written.

frang75 commented 8 months ago

In TableView, the text alignment is cell-based and not column-based. You have to return the desired alignment in EvTbCell result in ekGUI_EVENT_TBL_CELL event.

    case ekGUI_EVENT_TBL_CELL:
    {
        const EvTbPos *pos = event_params(e, EvTbPos);
        EvTbCell *cell = event_result(e, EvTbCell);

        switch(pos->col) {
        case 0:
            cell->align = ekLEFT;
            bstd_sprintf(data->temp_string, sizeof(data->temp_string), "Name %d", pos->row);
            break;
       ...

cell_align

SamSandq commented 8 months ago

I see - and this works beautifully.