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

theming does not allow to add padding to the menu #220

Open
optimisme opened this issue Dec 21, 2023 · 5 comments
Open

theming does not allow to add padding to the menu #220

optimisme opened this issue Dec 21, 2023 · 5 comments
Labels
enhancement An enhancement to existing functionality

Comments

@optimisme
Copy link

optimisme commented Dec 21, 2023

looks like menu size is computed at NSMenuView > sizeToFit, it is not possible from a custom theme to add padding between the limits of the menu pop up and the items

see the attached image

Screenshot 2023-12-21 at 13 19 27
@optimisme
Copy link
Author

optimisme commented Dec 21, 2023

if I modify the drawMenuRect to add padding, it does not fit inside the available space

- (void) drawMenuRect: (NSRect)rect
               inView: (NSView *)view
         isHorizontal: (BOOL)horizontal
            itemCells: (NSArray *)itemCells
{
    int         i = 0;
    int         howMany = [itemCells count];
    NSMenuView *menuView = (NSMenuView *)view;
    NSRect      bounds = [view bounds];
    CGFloat     padding = 5.0; // Ajusta aquest valor per controlar el padding

    [self drawBackgroundForMenuView: menuView
                          withFrame: bounds
                          dirtyRect: rect
                          horizontal: horizontal];
    
    // Draw the menu cells with padding.
    for (i = 0; i < howMany; i++)
    {
        NSRect aRect;
        NSMenuItemCell *aCell;
        
        aRect = [menuView rectOfItemAtIndex: i];

        // Ajustar el rectangle per afegir padding
        if (horizontal) {
            aRect.origin.x += padding;
            aRect.size.width -= padding * 2;
        } else {
            aRect.origin.y += padding;
        }

        if (NSIntersectsRect(rect, aRect) == YES)
        {
            aCell = [menuView menuItemCellForItemAtIndex: i];
            [aCell drawWithFrame: aRect inView: menuView];
        }
    }
}

@gcasa
Copy link
Member

gcasa commented Dec 21, 2023

How does this image relate to the code you are showing here. That's not a theme I recognize. Is the attached image to illustrate what you're trying to achieve?

@optimisme
Copy link
Author

optimisme commented Dec 22, 2023

I tried to add some distance between the limits of the menu popover and the list of items.
The size of the menu popover is decided before the drawing (drawMenuRect), so it is not possible to add 'padding' to enclose the list of items at the center of the popover.
Theming needs a way to define each side padding (top, bottom, left, right) and position the list of items properly, like in the example image.

Screenshot 2023-12-22 at 06 46 42

@gcasa gcasa added the enhancement An enhancement to existing functionality label Dec 22, 2023
@fredkiefer
Copy link
Member

Yes, this is a real issue. Would it be sufficient for you to just have a way to influence the _leftBorderOffset or do you really need a different offset for all the different borders?

@optimisme
Copy link
Author

At least different values for horizontal and vertical panning. But why not use NSEdgeInsets?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement to existing functionality
Development

No branches or pull requests

3 participants