Skip to content

Commit f466dee

Browse files
committed
feat(gui): add Widget_SetHashList()
1 parent be06b93 commit f466dee

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

include/LCUI/gui/widget_base.h

+6
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,12 @@ LCUI_API void Widget_GenerateSelfHash(LCUI_Widget w);
444444
/** Generate hash values for a widget and its children */
445445
LCUI_API void Widget_GenerateHash(LCUI_Widget w);
446446

447+
LCUI_API size_t Widget_SetHashList(LCUI_Widget w, unsigned *hash_list,
448+
size_t len);
449+
450+
LCUI_API size_t Widget_GetHashList(LCUI_Widget w, unsigned *hash_list,
451+
size_t maxlen);
452+
447453
/** Set widget updating rules */
448454
LCUI_API int Widget_SetRules(LCUI_Widget w, const LCUI_WidgetRulesRec *rules);
449455

src/gui/widget_base.c

+90
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,96 @@ void Widget_GenerateHash(LCUI_Widget w)
374374
}
375375
}
376376

377+
size_t Widget_SetHashList(LCUI_Widget w, unsigned *hash_list, size_t len)
378+
{
379+
size_t count = 0;
380+
LCUI_Widget child;
381+
382+
child = w;
383+
if (hash_list) {
384+
child->hash = hash_list[count];
385+
}
386+
++count;
387+
if (len > 0 && count >= len) {
388+
return count;
389+
}
390+
while (child->children.length > 0) {
391+
child = child->children.head.next->data;
392+
}
393+
while (child != w) {
394+
while (child->children.length > 0) {
395+
child = child->children.head.next->data;
396+
}
397+
if (hash_list) {
398+
child->hash = hash_list[count];
399+
}
400+
++count;
401+
if (len > 0 && count >= len) {
402+
break;
403+
}
404+
if (child->node.next) {
405+
child = child->node.next->data;
406+
continue;
407+
}
408+
do {
409+
child = child->parent;
410+
if (child == w) {
411+
break;
412+
}
413+
if (child->node.next) {
414+
child = child->node.next->data;
415+
break;
416+
}
417+
} while (1);
418+
}
419+
return count;
420+
}
421+
422+
size_t Widget_GetHashList(LCUI_Widget w, unsigned *hash_list, size_t maxlen)
423+
{
424+
size_t count = 0;
425+
LCUI_Widget child;
426+
427+
child = w;
428+
if (hash_list) {
429+
hash_list[count] = child->hash;
430+
}
431+
++count;
432+
if (maxlen > 0 && count >= maxlen) {
433+
return count;
434+
}
435+
while (child->children.length > 0) {
436+
child = child->children.head.next->data;
437+
}
438+
while (child != w) {
439+
while (child->children.length > 0) {
440+
child = child->children.head.next->data;
441+
}
442+
if (hash_list) {
443+
hash_list[count] = child->hash;
444+
}
445+
++count;
446+
if (maxlen > 0 && count >= maxlen) {
447+
break;
448+
}
449+
if (child->node.next) {
450+
child = child->node.next->data;
451+
continue;
452+
}
453+
do {
454+
child = child->parent;
455+
if (child == w) {
456+
break;
457+
}
458+
if (child->node.next) {
459+
child = child->node.next->data;
460+
break;
461+
}
462+
} while(1);
463+
}
464+
return count;
465+
}
466+
377467
int Widget_SetRules(LCUI_Widget w, const LCUI_WidgetRulesRec *rules)
378468
{
379469
LCUI_WidgetRulesData data;

0 commit comments

Comments
 (0)