Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/interface/table.c')
-rw-r--r--source/blender/editors/interface/table.c70
1 files changed, 37 insertions, 33 deletions
diff --git a/source/blender/editors/interface/table.c b/source/blender/editors/interface/table.c
index d2a977677d4..94420613eae 100644
--- a/source/blender/editors/interface/table.c
+++ b/source/blender/editors/interface/table.c
@@ -69,10 +69,7 @@ typedef struct TableHorizontalFlow {
* for size properties (only column widths right now).
*/
typedef struct uiTableSize {
- enum {
- TABLE_UNIT_PX,
- TABLE_UNIT_PERCENT,
- } unit;
+ enum uiTableUnit unit;
int value;
} uiTableSize;
@@ -154,15 +151,24 @@ static void table_row_height_set(uiTable *table, uiTableRow *row, unsigned int h
}
}
-static unsigned int table_get_tot_width_unfixed_columns(const uiTable *table)
+static unsigned int table_column_width_clamp(const uiTableColumn *column, const unsigned int maxwidth,
+ const unsigned int unclamped_width)
+{
+ unsigned int width = unclamped_width;
+ CLAMP(width, column->min_width, maxwidth);
+ return width;
+}
+
+static unsigned int table_calc_tot_width_unfixed_columns(const uiTable *table)
{
unsigned int nonfixed_width = table->max_width;
TABLE_COLUMNS_ITER_BEGIN(table, column)
{
if (column->width.unit == TABLE_UNIT_PX) {
- BLI_assert(nonfixed_width - column->width.value > 0);
- nonfixed_width -= column->width.value;
+ unsigned int width = table_column_width_clamp(column, table->max_width, column->width.value);
+ BLI_assert(nonfixed_width >= width);
+ nonfixed_width -= width;
}
}
TABLE_COLUMNS_ITER_END;
@@ -174,22 +180,23 @@ static struct TableColumnDrawInfo table_column_drawinfo_init(const uiTable *tabl
{
struct TableColumnDrawInfo drawinfo = {};
- drawinfo.totwidth_nonfixed = table_get_tot_width_unfixed_columns(table);
+ drawinfo.totwidth_nonfixed = table_calc_tot_width_unfixed_columns(table);
BLI_assert(drawinfo.totwidth_nonfixed <= table->max_width);
return drawinfo;
}
-static unsigned int table_column_calc_width(const uiTableColumn *column, const struct TableColumnDrawInfo *drawinfo)
+static unsigned int table_column_calc_width(const uiTableColumn *column, const struct TableColumnDrawInfo *drawinfo,
+ const unsigned int maxwidth)
{
unsigned int width = column->width.value;
if (column->width.unit == TABLE_UNIT_PERCENT) {
+ CLAMP_MAX(width, 100); /* more than 100% doesn't make sense */
width = iroundf(width * 0.01f * drawinfo->totwidth_nonfixed);
}
- width = MAX2(column->min_width, width);
- return width;
+ return table_column_width_clamp(column, maxwidth, width);
}
/**
@@ -200,7 +207,7 @@ static void table_column_calc_x_coords(const uiTableColumn *column, const float
struct TableColumnDrawInfo *io_drawinfo,
int *r_xmin, int *r_xmax)
{
- const unsigned int width = table_column_calc_width(column, io_drawinfo);
+ const unsigned int width = table_column_calc_width(column, io_drawinfo, max_width);
if (column->alignment == TABLE_COLUMN_ALIGN_LEFT) {
*r_xmin = io_drawinfo->totwidth_left;
@@ -217,11 +224,18 @@ static void table_column_calc_x_coords(const uiTableColumn *column, const float
}
}
-static void table_row_calc_y_coords(uiTableRow *row, const unsigned int ofs_y, int *r_ymin, int *r_ymax)
+static void table_row_calc_y_coords(uiTable *table, uiTableRow *row, const unsigned int ofs_y, int *r_ymin, int *r_ymax)
{
+ unsigned int height = row->height;
+
+ if (table->flow_direction == TABLE_FLOW_HORIZONTAL) {
+ TableHorizontalFlow *horizontal_table = (TableHorizontalFlow *)table;
+ CLAMP_MAX(height, horizontal_table->max_height);
+ }
+
/* Assuming inverted direction, from top to bottom. */
*r_ymax = -ofs_y;
- *r_ymin = *r_ymax - row->height;
+ *r_ymin = *r_ymax - height;
}
@@ -297,7 +311,7 @@ uiTableColumn *UI_table_column_add(uiTable *table, const char *idname, const cha
col->drawname = drawname;
col->cell_draw = cell_draw;
col->alignment = TABLE_COLUMN_ALIGN_LEFT;
- UI_table_column_width_set(col, UI_table_size_percentage(100), 0);
+ UI_table_column_width_set(col, 100, TABLE_UNIT_PERCENT, 0);
BLI_addtail(&table->columns, col);
@@ -326,11 +340,13 @@ uiTableColumn *UI_table_column_lookup(uiTable *table, const char *idname)
/**
* Set the size info for \a col.
* \param width: The width in either pixels (#UI_table_size_px), or percentage (#UI_table_size_percentage).
+ * \param min_width_px: Minimum width for the column (always in px).
*/
-void UI_table_column_width_set(uiTableColumn *column, const uiTableSize width, const int min_width_px)
+void UI_table_column_width_set(uiTableColumn *column, const unsigned int width, enum uiTableUnit unit,
+ const int min_width_px)
{
- BLI_assert(width.value >= 0);
- column->width = width;
+ column->width.unit = unit;
+ column->width.value = width;
column->min_width = min_width_px;
}
@@ -371,11 +387,10 @@ void UI_table_draw(uiTable *table)
} flow_table = {table};
struct TableColumnDrawInfo column_drawinfo = table_column_drawinfo_init(table);
- unsigned int xofs = 0, yofs = 0;
BLI_mempool_iter iter;
+ unsigned int xofs = 0, yofs = 0;
- BLI_mempool_iternew(table->row_pool, &iter);
TABLE_COLUMNS_ITER_BEGIN(table, column)
{
int prev_row_height = -1; /* to check if rows have consistent height */
@@ -384,6 +399,7 @@ void UI_table_draw(uiTable *table)
table_column_calc_x_coords(column, table->max_width, &column_drawinfo, &drawrect.xmin, &drawrect.xmax);
+ BLI_mempool_iternew(table->row_pool, &iter);
for (uiTableRow *row = BLI_mempool_iterstep(&iter); row; row = BLI_mempool_iterstep(&iter)) {
/* check for consistent row height */
if ((prev_row_height >= 0) && (row->height != prev_row_height)) {
@@ -395,7 +411,7 @@ void UI_table_draw(uiTable *table)
yofs = 0;
}
- table_row_calc_y_coords(row, yofs, &drawrect.ymin, &drawrect.ymax);
+ table_row_calc_y_coords(table, row, yofs, &drawrect.ymin, &drawrect.ymax);
column->cell_draw(row->rowdata, drawrect);
yofs += row->height;
@@ -415,18 +431,6 @@ void UI_table_draw(uiTable *table)
TABLE_COLUMNS_ITER_END;
}
-uiTableSize UI_table_size_px(const int value)
-{
- uiTableSize size = {.unit = TABLE_UNIT_PX, .value = value};
- return size;
-}
-
-uiTableSize UI_table_size_percentage(const int value)
-{
- uiTableSize size = {.unit = TABLE_UNIT_PERCENT, .value = value};
- return size;
-}
-
unsigned int UI_table_get_rowcount(const uiTable *table)
{
return BLI_mempool_count(table->row_pool);