Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend window's panel clipping area to take into account the padding #704

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ryuukk
Copy link
Contributor

@ryuukk ryuukk commented Sep 25, 2024

Padding shouldn't hide things like widgets border

Before:

image

After:

image

@RobLoach
Copy link
Contributor

RobLoach commented Sep 25, 2024

This seems to fix the button border! Anything else you'd like in before we merge this? #701

Though, I am seeing a weird thing on the Background dropdown...

Screenshot from 2024-09-25 12-39-57

@ryuukk
Copy link
Contributor Author

ryuukk commented Sep 25, 2024

If you resize the window, you can see sometimes the border is properly displayed, wich indicates a rounding issue as you suggested on the other PR

As for this PR, it's pretty more good for merge if nobody oppose, although we should probably wait until we get more people to review, i'm not familiar with the code base

@ryuukk
Copy link
Contributor Author

ryuukk commented Sep 26, 2024

I found an issue when trying to update the skinning example to use 9-slice:

image

It's perhaps due to the footer, i'll investigate

@ryuukk ryuukk changed the title Extend panel's clipping area to take into account the padding Extend window's panel clipping area to take into account the padding Sep 26, 2024
@ryuukk
Copy link
Contributor Author

ryuukk commented Sep 26, 2024

Solved it, window's padding is about the window, just the window

We could do it for other type of panels

    NK_PANEL_MENU
        style->window.menu_padding

    NK_PANEL_GROUP
        style->window.group_padding

    NK_PANEL_CONTEXTUAL
        style->window.contextual_padding

    NK_PANEL_TOOLTIP
        style->window.tooltip_padding

I'm running out of time tho, i'll do it later this week or if someone wants to help, feel free

@ryuukk
Copy link
Contributor Author

ryuukk commented Sep 26, 2024

We can now do cool effects on widgets

fx.webm

@RobLoach
Copy link
Contributor

Looks great haha. Shall we merge this one?

@ryuukk
Copy link
Contributor Author

ryuukk commented Sep 29, 2024

I applied the same for other kind of panel, i tested with the overview demo, and so far so good, no issues noticed

I'd personally merge, but let's encourage other people to test it in their project and see if they don't notice any problems before merging it

@ryuukk
Copy link
Contributor Author

ryuukk commented Sep 29, 2024

I found an issue with the skinning demo when using nk_tree, i'll investigate

image

@@ -319,6 +319,100 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan
layout->clip = layout->bounds;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -156,6 +156,8 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan
     layout->bounds = win->bounds;
     layout->bounds.x += panel_padding.x;
     layout->bounds.w -= 2*panel_padding.x;
+    layout->bounds.y += panel_padding.y;
+    layout->bounds.h -= 2*panel_padding.y;
     if (win->flags & NK_WINDOW_BORDER) {
         layout->border = nk_panel_get_border(style, win->flags, panel_type);
         layout->bounds = nk_shrink_rect(layout->bounds, layout->border);
@@ -317,102 +319,12 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan
     /* set clipping rectangle */
     {struct nk_rect clip;
     layout->clip = layout->bounds;
+    layout->clip.x -= panel_padding.x;
+    layout->clip.w += 2*panel_padding.x;
+    layout->clip.y -= panel_padding.y;
+    layout->clip.h += 2*panel_padding.y;
     nk_unify(&clip, &win->buffer.clip, layout->clip.x, layout->clip.y,
         layout->clip.x + layout->clip.w, layout->clip.y + layout->clip.h);

Try these changes instead, instead of changing the clip after nk_unify.
Fixes the issue with nk_tree while doing the thing you intended.

(Note that with vertical bounds changed like this, windows' heights in user code may need slight increase to accommodate; e.g. in one of my use case I need to increase the default window height to hide vertical scrollbar again)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also while looking at this I've noticed that in nk_panel_get_padding/nk_panel_get_border/nk_panel_get_border_color, case NK_PANEL_TOOLTIP uses menu_* instead of tooltip_* in the current code base. Might as well fix this while we're at it.

Edit: patch here

--- a/src/nuklear_panel.c
+++ b/src/nuklear_panel.c
@@ -42,7 +42,7 @@ nk_panel_get_padding(const struct nk_style *style, enum nk_panel_type type)
     case NK_PANEL_CONTEXTUAL: return style->window.contextual_padding;
     case NK_PANEL_COMBO: return style->window.combo_padding;
     case NK_PANEL_MENU: return style->window.menu_padding;
-    case NK_PANEL_TOOLTIP: return style->window.menu_padding;}
+    case NK_PANEL_TOOLTIP: return style->window.tooltip_padding;}
 }
 NK_LIB float
 nk_panel_get_border(const struct nk_style *style, nk_flags flags,
@@ -57,7 +57,7 @@ nk_panel_get_border(const struct nk_style *style, nk_flags flags,
         case NK_PANEL_CONTEXTUAL: return style->window.contextual_border;
         case NK_PANEL_COMBO: return style->window.combo_border;
         case NK_PANEL_MENU: return style->window.menu_border;
-        case NK_PANEL_TOOLTIP: return style->window.menu_border;
+        case NK_PANEL_TOOLTIP: return style->window.tooltip_border;
     }} else return 0;
 }
 NK_LIB struct nk_color
@@ -71,7 +71,7 @@ nk_panel_get_border_color(const struct nk_style *style, enum nk_panel_type type)
     case NK_PANEL_CONTEXTUAL: return style->window.contextual_border_color;
     case NK_PANEL_COMBO: return style->window.combo_border_color;
     case NK_PANEL_MENU: return style->window.menu_border_color;
-    case NK_PANEL_TOOLTIP: return style->window.menu_border_color;}
+    case NK_PANEL_TOOLTIP: return style->window.tooltip_border_color;}
 }
 NK_LIB nk_bool
 nk_panel_is_sub(enum nk_panel_type type)

Hopefully this doesn't break anything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found out that the layout->bounds.y and layout->bounds.h change breaks group layout.

Can be fixed by

--- a/src/nuklear_group.c
+++ b/src/nuklear_group.c
@@ -82,10 +82,10 @@ nk_group_scrolled_end(struct nk_context *ctx)
     /* dummy window */
     nk_zero_struct(pan);
     panel_padding = nk_panel_get_padding(&ctx->style, NK_PANEL_GROUP);
-    pan.bounds.y = g->bounds.y - (g->header_height + g->menu.h);
+    pan.bounds.y = g->bounds.y - (g->header_height + g->menu.h) - panel_padding.y;
     pan.bounds.x = g->bounds.x - panel_padding.x;
     pan.bounds.w = g->bounds.w + 2 * panel_padding.x;
-    pan.bounds.h = g->bounds.h + g->header_height + g->menu.h;
+    pan.bounds.h = g->bounds.h + g->header_height + g->menu.h + 2 * panel_padding.y;
     if (g->flags & NK_WINDOW_BORDER) {
         pan.bounds.x -= g->border;
         pan.bounds.y -= g->border;
@@ -106,7 +106,7 @@ nk_group_scrolled_end(struct nk_context *ctx)

     /* make sure group has correct clipping rectangle */
     nk_unify(&clip, &parent->clip, pan.bounds.x, pan.bounds.y,
-        pan.bounds.x + pan.bounds.w, pan.bounds.y + pan.bounds.h + panel_padding.x);
+        pan.bounds.x + pan.bounds.w, pan.bounds.y + pan.bounds.h);
     nk_push_scissor(&pan.buffer, clip);
     nk_end(ctx);

And maybe this change as well (didn't break anything visibly but this change make things consistent)

--- a/src/nuklear_panel.c
+++ b/src/nuklear_panel.c
@@ -475,7 +475,7 @@ nk_panel_end(struct nk_context *ctx)
             /* horizontal scrollbar */
             nk_flags state = 0;
             scroll.x = layout->bounds.x;
-            scroll.y = layout->bounds.y + layout->bounds.h;
+            scroll.y = layout->bounds.y + layout->bounds.h + panel_padding.y;
             scroll.w = layout->bounds.w;
             scroll.h = scrollbar_size.y;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants