From d14f9aebe27cd48a8d21c0eb691c8e7bf94722a8 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 22 Oct 2021 07:22:15 +0300 Subject: Working on tab close buttons An [x] button appears on tab buttons when hovering on them. Still needs a bit of layout tweaks and the first tab doesn't have a button yet. --- src/ui/widget.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/ui/widget.c') diff --git a/src/ui/widget.c b/src/ui/widget.c index ec92ac5a..75c07c5a 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c @@ -973,6 +973,18 @@ iLocalDef iBool isMouseEvent_(const SDL_Event *ev) { ev->type == SDL_MOUSEBUTTONUP || ev->type == SDL_MOUSEBUTTONDOWN); } +iLocalDef iBool isHidden_Widget_(const iWidget *d) { + if (d->flags & visibleOnParentHover_WidgetFlag && + (isHover_Widget(d) || isHover_Widget(d->parent))) { + return iFalse; + } + return (d->flags & hidden_WidgetFlag) != 0; +} + +iLocalDef iBool isDrawn_Widget_(const iWidget *d) { + return !isHidden_Widget_(d) || d->flags & visualOffset_WidgetFlag; +} + static iBool filterEvent_Widget_(const iWidget *d, const SDL_Event *ev) { if (d->flags & destroyPending_WidgetFlag) { return iFalse; /* no more events handled */ @@ -983,7 +995,7 @@ static iBool filterEvent_Widget_(const iWidget *d, const SDL_Event *ev) { d->flags & disabledWhenHidden_WidgetFlag)) { if (isKey || isMouse) return iFalse; } - if (d->flags & hidden_WidgetFlag) { + if (isHidden_Widget_(d)) { if (isMouse) return iFalse; } return iTrue; @@ -1032,7 +1044,7 @@ iBool dispatchEvent_Widget(iWidget *d, const SDL_Event *ev) { else if (ev->type == SDL_MOUSEMOTION && ev->motion.windowID == SDL_GetWindowID(window_Widget(d)->win) && (!window_Widget(d)->hover || hasParent_Widget(d, window_Widget(d)->hover)) && - flags_Widget(d) & hover_WidgetFlag && ~flags_Widget(d) & hidden_WidgetFlag && + flags_Widget(d) & hover_WidgetFlag && !isHidden_Widget_(d) && ~flags_Widget(d) & disabled_WidgetFlag) { if (contains_Widget(d, init_I2(ev->motion.x, ev->motion.y))) { setHover_Widget(d); @@ -1282,10 +1294,6 @@ int backgroundFadeColor_Widget(void) { } } -iLocalDef iBool isDrawn_Widget_(const iWidget *d) { - return ~d->flags & hidden_WidgetFlag || d->flags & visualOffset_WidgetFlag; -} - void drawLayerEffects_Widget(const iWidget *d) { /* Layered effects are not buffered, so they are drawn here separately. */ iAssert(isDrawn_Widget_(d)); @@ -1711,7 +1719,7 @@ size_t childIndex_Widget(const iWidget *d, const iAnyObject *child) { } iAny *hitChild_Widget(const iWidget *d, iInt2 coord) { - if (d->flags & hidden_WidgetFlag) { + if (isHidden_Widget_(d)) { return NULL; } /* Check for on-top widgets first. */ -- cgit v1.2.3