调整数据类型和接口函数命名规范

This commit is contained in:
2026-03-23 12:42:19 +08:00
parent 38572bd5f7
commit 34017fb5da
18 changed files with 609 additions and 608 deletions

View File

@@ -6,23 +6,19 @@
#include "utils.h"
void wm_layout_result_init(wm_layout_result_t *result) {
void layout_result_init(layout_result_t *result) {
result->item_count = 0;
result->item_capacity = INIT_CAPACITY;
result->items = p_new(wm_layout_item_t, result->item_capacity);
result->items = p_new(layout_item_t, result->item_capacity);
}
void wm_layout_result_reset(wm_layout_result_t *result) {
result->item_count = 0;
}
void wm_layout_result_cleanup(wm_layout_result_t *result) {
void layout_result_cleanup(layout_result_t *result) {
p_delete(&result->items);
result->item_count = 0;
result->item_capacity = 0;
}
void wm_layout_result_push(wm_layout_result_t *result, wm_layout_item_t item) {
void layout_result_push(layout_result_t *result, layout_item_t item) {
if (result->item_count == result->item_capacity) {
size_t new_capacity = next_capacity(result->item_capacity);
p_realloc(&result->items, new_capacity);
@@ -32,28 +28,27 @@ void wm_layout_result_push(wm_layout_result_t *result, wm_layout_item_t item) {
result->items[result->item_count++] = item;
}
void wm_layout_registry_init(wm_layout_registry_t *registry) {
void layout_registry_init(layout_registry_t *registry) {
registry->slot_count = 0;
registry->slot_capacity = INIT_CAPACITY;
registry->slots = p_new(wm_layout_slot_t, registry->slot_capacity);
registry->slots = p_new(layout_slot_t, registry->slot_capacity);
}
void wm_layout_registry_cleanup(wm_layout_registry_t *registry) {
void layout_registry_cleanup(layout_registry_t *registry) {
while (registry->slot_count > 0) {
wm_layout_slot_t *r = &registry->slots[--registry->slot_count];
layout_slot_t *r = &registry->slots[--registry->slot_count];
p_delete(&r->name);
p_delete(&r->symbol);
p_delete(&r->description);
r->fn = nullptr;
r->id = WM_LAYOUT_ID_INVALID;
r->id = ZDWM_LAYOUT_ID_INVALID;
}
p_delete(&registry->slots);
registry->slot_count = 0;
registry->slot_capacity = 0;
}
bool wm_layout_registry_move(wm_layout_registry_t *src,
wm_layout_registry_t *dest) {
bool layout_registry_move(layout_registry_t *src, layout_registry_t *dest) {
if (!src || !dest) return false;
dest->slots = src->slots;
@@ -67,29 +62,29 @@ bool wm_layout_registry_move(wm_layout_registry_t *src,
return true;
}
size_t wm_layout_registry_count(const wm_layout_registry_t *registry) {
size_t layout_registry_count(const layout_registry_t *registry) {
return registry->slot_count;
}
const wm_layout_slot_t *wm_layout_registry_at(
const wm_layout_registry_t *registry, size_t index) {
const layout_slot_t *layout_registry_at(const layout_registry_t *registry,
size_t index) {
if (index >= registry->slot_count) return nullptr;
return &registry->slots[index];
}
wm_layout_id_t wm_layout_register(wm_layout_registry_t *registry,
const char *name, const char *symbol,
const char *description, wm_layout_fn fn) {
if (!name || !symbol) return WM_LAYOUT_ID_INVALID;
layout_id_t layout_register(layout_registry_t *registry, const char *name,
const char *symbol, const char *description,
layout_fn fn) {
if (!name || !symbol) return ZDWM_LAYOUT_ID_INVALID;
if (registry->slot_count == registry->slot_capacity) {
size_t new_capacity = next_capacity(registry->slot_capacity);
p_realloc(&registry->slots, new_capacity);
registry->slot_capacity = new_capacity;
}
wm_layout_id_t id = (wm_layout_id_t)registry->slot_count;
layout_id_t id = (layout_id_t)registry->slot_count;
wm_layout_slot_t *r = &registry->slots[registry->slot_count];
layout_slot_t *r = &registry->slots[registry->slot_count];
r->id = id;
r->name = p_strdup(name);
r->symbol = p_strdup(symbol);
@@ -100,15 +95,14 @@ wm_layout_id_t wm_layout_register(wm_layout_registry_t *registry,
return id;
}
wm_layout_fn wm_layout_get(const wm_layout_registry_t *registry,
wm_layout_id_t id) {
const wm_layout_slot_t *layout_slot = wm_layout_slot_get(registry, id);
layout_fn layout_get(const layout_registry_t *registry, layout_id_t id) {
const layout_slot_t *layout_slot = layout_slot_get(registry, id);
if (layout_slot) return layout_slot->fn;
return nullptr;
}
const wm_layout_slot_t *wm_layout_slot_get(const wm_layout_registry_t *registry,
wm_layout_id_t id) {
const layout_slot_t *layout_slot_get(const layout_registry_t *registry,
layout_id_t id) {
if (id >= registry->slot_count) return nullptr;
return &registry->slots[id];
}