feat(bar): bar item 扩展钩子功能 bar cell 添加 fixed_width 属性与操作接口

- item type 加入可为空的 after_layout 和 after_draw 钩子
- cell 加 fixed_width 属性, cell api 添加 cell_set_fixed_width 和
  cell_get_region 两个接口
- cell api 改为 const 避免外部修改
This commit is contained in:
2026-06-28 02:04:20 +08:00
parent 27aab6f0e9
commit 6b75cda128
5 changed files with 134 additions and 32 deletions

View File

@@ -2,6 +2,7 @@
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <zdwm/types.h>
@@ -119,15 +120,37 @@ bar_cell_set_indicator(zdwm_bar_item_t *item, size_t index, bool show) {
item->dirty = true;
}
static void
bar_cell_set_fixed_width(zdwm_bar_item_t *item, size_t index, int32_t width) {
if (index >= item->count) return;
auto cell = &item->cells[index];
if (cell->fixed_width == width) return;
cell->fixed_width = width;
cell->dirty = true;
item->dirty = true;
}
static bar_x_region_t bar_cell_get_region(zdwm_bar_item_t *item, size_t index) {
if (index >= item->count) return (bar_x_region_t){0};
auto cell = &item->cells[index];
return cell->region;
}
/* clang-format off */
zdwm_bar_cell_api_t bar_cell_api = {
.get_cell_count = bar_cell_get_count,
.set_cell_count = bar_cell_set_count,
.cell_set_text = bar_cell_set_text,
.cell_set_bg = bar_cell_set_bg,
.cell_set_fg = bar_cell_set_fg,
.cell_set_icon = bar_cell_set_icon,
.cell_set_indicator = bar_cell_set_indicator,
const zdwm_bar_cell_api_t bar_cell_api = {
.get_cell_count = bar_cell_get_count,
.set_cell_count = bar_cell_set_count,
.cell_set_text = bar_cell_set_text,
.cell_set_bg = bar_cell_set_bg,
.cell_set_fg = bar_cell_set_fg,
.cell_set_icon = bar_cell_set_icon,
.cell_set_indicator = bar_cell_set_indicator,
.cell_set_fixed_width = bar_cell_set_fixed_width,
.cell_get_region = bar_cell_get_region,
};
/* clang-format on */