From 2f581b8d97ca10c67f4498d2ccec9f39b9c4b7a9 Mon Sep 17 00:00:00 2001 From: Liu Date: Tue, 6 Nov 2018 22:57:50 +0800 Subject: [PATCH] feat(gui): add Widget_SetVisible() and Widget_SetHidden() --- include/LCUI/gui/widget_helper.h | 6 ++++++ src/gui/widget_helper.c | 35 ++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/include/LCUI/gui/widget_helper.h b/include/LCUI/gui/widget_helper.h index 7931347af..9f4df8465 100644 --- a/include/LCUI/gui/widget_helper.h +++ b/include/LCUI/gui/widget_helper.h @@ -62,8 +62,14 @@ LCUI_API void Widget_ResizeWithSurface(LCUI_Widget w, LCUI_API LCUI_Style Widget_GetStyle(LCUI_Widget w, int key); +LCUI_API LCUI_Style Widget_GetInheritedStyle(LCUI_Widget w, int key); + LCUI_API void Widget_SetVisibility(LCUI_Widget w, const char *value); +LCUI_API void Widget_SetVisible(LCUI_Widget w); + +LCUI_API void Widget_SetHidden(LCUI_Widget w); + LCUI_API void Widget_Show(LCUI_Widget w); LCUI_API void Widget_Hide(LCUI_Widget w); diff --git a/src/gui/widget_helper.c b/src/gui/widget_helper.c index 8b7887f9e..d1ea24265 100644 --- a/src/gui/widget_helper.c +++ b/src/gui/widget_helper.c @@ -107,6 +107,12 @@ LCUI_Style Widget_GetStyle(LCUI_Widget w, int key) return &w->custom_style->sheet[key]; } +LCUI_Style Widget_GetInheritedStyle(LCUI_Widget w, int key) +{ + assert(key >= 0 && key < w->inherited_style->length); + return &w->inherited_style->sheet[key]; +} + void Widget_SetVisibility(LCUI_Widget w, const char *value) { LCUI_Style s = Widget_GetStyle(w, key_visibility); @@ -118,16 +124,41 @@ void Widget_SetVisibility(LCUI_Widget w, const char *value) Widget_UpdateStyle(w, FALSE); } -void Widget_Show(LCUI_Widget w) +void Widget_SetVisible(LCUI_Widget w) { Widget_SetVisibility(w, "visible"); } -void Widget_Hide(LCUI_Widget w) +void Widget_SetHidden(LCUI_Widget w) { Widget_SetVisibility(w, "hidden"); } +void Widget_Show(LCUI_Widget w) +{ + LCUI_Style s = Widget_GetStyle(w, key_display); + + if (s->is_valid && s->type == LCUI_STYPE_STYLE && + s->val_style == SV_NONE) { + Widget_UnsetStyle(w, key_display); + } else if (!w->computed_style.visible) { + s = Widget_GetInheritedStyle(w, key_display); + if (s->is_valid && s->type == LCUI_STYPE_STYLE && + s->val_style != SV_NONE) { + Widget_SetStyle(w, key_display, s->val_style, style); + } else { + Widget_SetStyle(w, key_display, SV_BLOCK, style); + } + } + Widget_UpdateStyle(w, FALSE); +} + +void Widget_Hide(LCUI_Widget w) +{ + Widget_SetStyle(w, key_display, SV_NONE, style); + Widget_UpdateStyle(w, FALSE); +} + void Widget_SetPosition(LCUI_Widget w, LCUI_StyleValue position) { Widget_SetStyle(w, key_position, position, style);