Skip to content

Commit 2f581b8

Browse files
committed
feat(gui): add Widget_SetVisible() and Widget_SetHidden()
1 parent 491992f commit 2f581b8

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

include/LCUI/gui/widget_helper.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ LCUI_API void Widget_ResizeWithSurface(LCUI_Widget w,
6262

6363
LCUI_API LCUI_Style Widget_GetStyle(LCUI_Widget w, int key);
6464

65+
LCUI_API LCUI_Style Widget_GetInheritedStyle(LCUI_Widget w, int key);
66+
6567
LCUI_API void Widget_SetVisibility(LCUI_Widget w, const char *value);
6668

69+
LCUI_API void Widget_SetVisible(LCUI_Widget w);
70+
71+
LCUI_API void Widget_SetHidden(LCUI_Widget w);
72+
6773
LCUI_API void Widget_Show(LCUI_Widget w);
6874

6975
LCUI_API void Widget_Hide(LCUI_Widget w);

src/gui/widget_helper.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ LCUI_Style Widget_GetStyle(LCUI_Widget w, int key)
107107
return &w->custom_style->sheet[key];
108108
}
109109

110+
LCUI_Style Widget_GetInheritedStyle(LCUI_Widget w, int key)
111+
{
112+
assert(key >= 0 && key < w->inherited_style->length);
113+
return &w->inherited_style->sheet[key];
114+
}
115+
110116
void Widget_SetVisibility(LCUI_Widget w, const char *value)
111117
{
112118
LCUI_Style s = Widget_GetStyle(w, key_visibility);
@@ -118,16 +124,41 @@ void Widget_SetVisibility(LCUI_Widget w, const char *value)
118124
Widget_UpdateStyle(w, FALSE);
119125
}
120126

121-
void Widget_Show(LCUI_Widget w)
127+
void Widget_SetVisible(LCUI_Widget w)
122128
{
123129
Widget_SetVisibility(w, "visible");
124130
}
125131

126-
void Widget_Hide(LCUI_Widget w)
132+
void Widget_SetHidden(LCUI_Widget w)
127133
{
128134
Widget_SetVisibility(w, "hidden");
129135
}
130136

137+
void Widget_Show(LCUI_Widget w)
138+
{
139+
LCUI_Style s = Widget_GetStyle(w, key_display);
140+
141+
if (s->is_valid && s->type == LCUI_STYPE_STYLE &&
142+
s->val_style == SV_NONE) {
143+
Widget_UnsetStyle(w, key_display);
144+
} else if (!w->computed_style.visible) {
145+
s = Widget_GetInheritedStyle(w, key_display);
146+
if (s->is_valid && s->type == LCUI_STYPE_STYLE &&
147+
s->val_style != SV_NONE) {
148+
Widget_SetStyle(w, key_display, s->val_style, style);
149+
} else {
150+
Widget_SetStyle(w, key_display, SV_BLOCK, style);
151+
}
152+
}
153+
Widget_UpdateStyle(w, FALSE);
154+
}
155+
156+
void Widget_Hide(LCUI_Widget w)
157+
{
158+
Widget_SetStyle(w, key_display, SV_NONE, style);
159+
Widget_UpdateStyle(w, FALSE);
160+
}
161+
131162
void Widget_SetPosition(LCUI_Widget w, LCUI_StyleValue position)
132163
{
133164
Widget_SetStyle(w, key_position, position, style);

0 commit comments

Comments
 (0)