157 lines
5.3 KiB
C
157 lines
5.3 KiB
C
#ifndef GRID_H
|
|
#define GRID_H
|
|
|
|
#include <clayer/boxlib.h>
|
|
// flags
|
|
#define GRID_FLAG_NO_HEADER_ROW 0b1 // для использования для списков например
|
|
#define GRID_FLAG_NO_HEADER_COL 0b10 // для использования для списков например
|
|
#define GRID_FLAG_NO_SCROLL 0b100 // для использования там где данных излишне много
|
|
#define GRID_FLAG_CLEAN_MODE 0b1000 // без вывода сетки, например для печати
|
|
#define GRID_FLAG_EDIT_DATA 0x80000000 // Выставляется для вывода editbox
|
|
|
|
// border_type_ - Описание формата каждой линии границы
|
|
//#define GRID_BORDER_TYPE_NORMAL 0b0 // 0000 - default full line
|
|
//#define GRID_BORDER_TYPE_HATCHING_FREQUENT 0b1 // 0001 - штриховка, частая
|
|
//#define GRID_BORDER_TYPE_HATCHING_MEDIUM 0b10 // 0010 - штрифовка, средняя
|
|
//#define GRID_BORDER_TYPE_HATCHING_RARE 0b11 // 0011 - штриховка, редкая
|
|
//#define GRID_BORDER_TYPE_CORNERS 0b100 // 0100 - углы
|
|
|
|
#define GRID_BORDER_TYPE_PATTERN 0b1000
|
|
#define GRID_BORDER_TYPE_PATTERN_BEGIN_0 0b1001
|
|
#define GRID_BORDER_TYPE_PATTERN_BEGIN_1 0b1101
|
|
#define GRID_BORDER_TYPE_PATTERN_END_0 0b1011
|
|
#define GRID_BORDER_TYPE_PATTERN_END_1 0b1111
|
|
|
|
// расчитываются от внешних границ ячейки
|
|
#define GRID_BORDER_BITMASK_LINE1 0b0001
|
|
#define GRID_BORDER_BITMASK_LINE2 0b0010
|
|
#define GRID_BORDER_BITMASK_LINE3 0b0100
|
|
#define GRID_BORDER_BITMASK_LINE4 0b1000
|
|
|
|
// text align - составная переменная
|
|
#define GRID_TEXT_ALIGN_LEFT 0b00
|
|
#define GRID_TEXT_ALIGN_CENTER 0b10
|
|
#define GRID_TEXT_ALIGN_RIGHT 0b01
|
|
|
|
#define GRID_TEXT_ALIGN_TOP 0b0000
|
|
#define GRID_TEXT_ALIGN_MEDIUM 0b1000
|
|
#define GRID_TEXT_ALIGN_BOTTOM 0b0100
|
|
|
|
#define GRID_TEXT_STYLE_NORMAL 0b000000
|
|
|
|
|
|
#define GRID_WIDTH_DEFAUT 0
|
|
#define GRID_HEIDHT_DEFAULT 0
|
|
|
|
#define TABLE_CELL_DEFAULT_WIDTH 81
|
|
#define TABLE_CELL_DEFAULT_HEIGHT 21
|
|
|
|
#define GRID_VALUE_TYPE_TEXT 0
|
|
#define GRID_VALUE_TYPE_IMAGE 1
|
|
|
|
typedef struct GRID_BORDER_LINE_FORMAT {
|
|
uint8_t format;
|
|
uint8_t pattern; // bitmask
|
|
}GRID_BORDER_LINE_FORMAT;
|
|
|
|
typedef struct GRID_BORDER_FORMAT {
|
|
GRID_BORDER_LINE_FORMAT line [4];
|
|
ksys_color_t color;
|
|
}GRID_BORDER_FORMAT;
|
|
|
|
typedef struct GRID_CELL_FORMAT {
|
|
uint32_t width;
|
|
uint32_t height;
|
|
ksys_color_t bg_color;
|
|
ksys_color_t text_color;
|
|
uint64_t text_params;
|
|
GRID_BORDER_FORMAT border_l;
|
|
GRID_BORDER_FORMAT border_r;
|
|
GRID_BORDER_FORMAT border_t;
|
|
GRID_BORDER_FORMAT border_b;
|
|
union {
|
|
uint64_t border_bitmask;
|
|
struct {
|
|
uint8_t border_bitmask_l;
|
|
uint8_t border_bitmask_r;
|
|
uint8_t border_bitmask_t;
|
|
uint8_t border_bitmask_b;
|
|
};
|
|
};
|
|
} GRID_CELL_FORMAT;
|
|
|
|
typedef struct GRID_CELL_CONTENT {
|
|
uint32_t type;
|
|
uint32_t size_data;
|
|
} GRID_CELL_CONTENT;
|
|
|
|
typedef struct GRID_CELL_CONTENT_TEXT {
|
|
GRID_CELL_CONTENT type;
|
|
char text;
|
|
} GRID_CELL_CONTENT_TEXT;
|
|
|
|
typedef struct GRID_CELL_CONTENT_IMAGE {
|
|
GRID_CELL_CONTENT type;
|
|
uint32_t width;
|
|
uint32_t height;
|
|
ksys_color_t image;
|
|
} GRID_CELL_CONTENT_IMAGE;
|
|
|
|
typedef struct GRID {
|
|
uint32_t x;
|
|
uint32_t y;
|
|
uint32_t w;
|
|
uint32_t h;
|
|
|
|
uint32_t flags;
|
|
uint32_t pdata; //for callback functions
|
|
|
|
uint32_t grid_color;
|
|
|
|
uint32_t content_pos_col; // позиция первой верхней левой ячейки
|
|
uint32_t content_pos_row; // если есть заголовок строки/столбца
|
|
// то 1..max
|
|
// это диапазон выделенных значений - жирная оконтовка вокруг диапазона
|
|
uint32_t selected_cell_col;
|
|
uint32_t selected_cell_row;
|
|
uint32_t selected_cell_w;
|
|
uint32_t selected_cell_h;
|
|
// чтобы знать куда edit_box рисовать
|
|
uint32_t current_cell_x;
|
|
uint32_t current_cell_y;
|
|
uint32_t current_cell_w;
|
|
uint32_t current_cell_h;
|
|
//calbacks
|
|
void __stdcall (*get_cell_format)(struct GRID* this, GRID_CELL_FORMAT* buff, uint32_t col, uint32_t row); // получить формат ячейки
|
|
table_object* __stdcall (*get_cell_value)(struct GRID* this, uint32_t col, uint32_t row); // получить данные для вывода в обычном режиме
|
|
void __stdcall (*free_cell_value)(struct GRID* this, table_object* buff);
|
|
void __stdcall (*event_cell_mouse)(struct GRID* this, uint32_t col, uint32_t row);
|
|
void __stdcall (*event_cell_key)(struct GRID* this, uint32_t col, uint32_t row, ksys_oskey_t ch);
|
|
// callbacks for draw
|
|
void __stdcall (*draw_text)(struct GRID* this, uint32_t x, uint32_t y, uint32_t w, uint32_t h, char* text, uint64_t text_params);
|
|
void __stdcall (*draw_image)(struct GRID* this, uint32_t x, uint32_t y, uint32_t w, uint32_t h, ksys_color_t* data);
|
|
void __stdcall (*draw_bar)(struct GRID* this, uint32_t x, uint32_t y, uint32_t w, uint32_t h, ksys_color_t color);
|
|
//other items of grid
|
|
scrollbar scroll_row;
|
|
scrollbar scroll_col;
|
|
|
|
} GRID;
|
|
|
|
typedef struct GRID_NOSTD_CELL {
|
|
GRID* rthis;
|
|
GRID_CELL_FORMAT format;
|
|
uint32_t col;
|
|
uint32_t row;
|
|
uint32_t x;
|
|
uint32_t y;
|
|
uint32_t fix_width;
|
|
uint32_t fix_height;
|
|
} GRID_NOSTD_CELL;
|
|
|
|
extern void draw_grid(GRID* this);
|
|
|
|
extern void grid_mouse(GRID* this);
|
|
|
|
extern void grid_key(GRID* this, ksys_oskey_t ch);
|
|
|
|
#endif |