Skip to content

Commit

Permalink
feat(gui): add Widget_SetVisible() and Widget_SetHidden()
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Nov 18, 2018
1 parent 491992f commit 2f581b8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
6 changes: 6 additions & 0 deletions include/LCUI/gui/widget_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 33 additions & 2 deletions src/gui/widget_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 2f581b8

Please sign in to comment.