frang75 / nappgui_src

SDK for building cross-platform desktop apps in ANSI-C
https://www.nappgui.com
MIT License
506 stars 50 forks source link

Margin colours? #87

Closed SamSandq closed 8 months ago

SamSandq commented 10 months ago

I want to give my window a nice grey background colour.

I found the layout_bgcolor() and layout_skcolor() functions that will give my layouts the required colour... however, the layouts also have margins, and these are not coloured.

How can I assign a colour to the margins? I thought that the layout_skcolour should do it but it does not.

frang75 commented 10 months ago

Hi @SamSandq!

Use layout_bgcolor() in the layout of main panel cover all window area.

layout_color_win layout_color_macos

SamSandq commented 10 months ago

You are right, if I do it for the main layout in the main panel it indeed does what I want.

If I don't, and only gve sublayouts colours, their margins are not coloured.

However, leaving sublayouts without colours is fine and achieves what I want.

frang75 commented 10 months ago

layout_bgcolor() and layout_skcolor() covers the entire layout (included the inner margin defined by layout_margin[2|4](). Is it possible that non-colored margins belong a parent layout? If not, please send a screenshot with layout relations, because would be in issue to review.

Thanks Sam!

SamSandq commented 10 months ago

Looks like the margins of sublayouts are not coloured, and the parent layout's colours show through. However, the parent's margins are coloured, so there is definitely an inconsistency here. See the picture, where the sublayouts are coloured and the parent is not.

Screenshot 2024-01-14 at 8 36 39

frang75 commented 10 months ago

Ok, I will leave this issue open for testing this case.

frang75 commented 8 months ago

Layout coloring has been fully testing in this demo: https://nappgui.com/en/howto/drawbig.html#h7 Only detected an issue in Windows drawing order. Please reopen this issue providing compileable code if the problem persists.

SamSandq commented 8 months ago

I reopen this because I found the problem. Test with

The result is this (I use it at the top of my app as a testbed, which shows how the colour is bleeding all over the place):

Screenshot 2024-03-16 at 13 48 17

Now correct this by changing in oslabel.m: - (void) drawRect:(NSRect)rect, line 104:

now:

       draw_rect(self->ctx, ekFILL, 0, 0, (real32_t)rect.size.width, (real32_t)rect.size.height);

should be:

        NSRect myrect = [self bounds];
        draw_rect(self->ctx, ekFILL, 0, 0, (real32_t) myrect.size.width, (real32_t) myrect.size.height);

In other words, one must not exceed the bounds of the control.

The result is now correct:

Screenshot 2024-03-16 at 13 47 24

It is possible that the same problem occurs elsewhere, I have not checked.

frang75 commented 8 months ago

In oslabel (macOS), incoming rectangle in drawRect must be the same of control bounds. If not, is because other issue has this collateral effect. By the images, I can intuit that the Label frame has been changed, but I don't know why. Please report some compilable code in order to debug the origin of the problem. Reviewing all the use of Label in NAppGUI applications, this case does not arise.

label_rect_bounds

SamSandq commented 8 months ago

The only thing slightly out of the ordinary is that the layout where this happens is a sublayout.

I'll try to get you a full example.


Sam

Den sön 17 mars 2024 kl 16:31 skrev Francisco García Collado < @.***>:

In oslabel (macOS), incoming rectangle in drawRect must be the same of control bounds. If not, is because other issue has this collateral effect. By the images, I can intuit that the Label frame has been changed, but I don't know why. Please report some compilable code in order to debug the origin of the problem. Reviewing all the use of Label in NAppGUI applications, this case does not arise.

label_rect_bounds.png (view on web) https://github.com/frang75/nappgui_src/assets/42999199/c95121a0-a935-4ea8-98a3-10d9c62e8332

— Reply to this email directly, view it on GitHub https://github.com/frang75/nappgui_src/issues/87#issuecomment-2002491600, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMAVI5XJUI3EVSWYGZDOYN3YYWSKXAVCNFSM6AAAAABBZMA4UGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBSGQ4TCNRQGA . You are receiving this because you were mentioned.Message ID: @.***>

SamSandq commented 8 months ago

I copied your NappHello.c to a clean directory, and added a line below the label.

    label_text(label, "Hello!, I'm a label");
    label_bgcolor(label, kCOLOR_GREEN);

The result was like this

Screenshot 2024-03-18 at 11 16 38

with my correction it looks like this:

Screenshot 2024-03-18 at 11 17 32

which is what I expected.

frang75 commented 8 months ago

OMG! Its the same macOS Sonoma problem that OSView clipping. https://developer.apple.com/documentation/macos-release-notes/appkit-release-notes-for-macos-14#NSView

Fixed in this commit: https://github.com/frang75/nappgui_src/commit/d7930efee0031f8b4269601fe767a695e5e9ff20

Thanks so much for report! I forget that two modules are related. All my tests are in Ventura OS.