gnustep/libs-gui

theming does not allow to add padding to the menu

optimisme opened this issue · 5 comments

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

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 commented

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?

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

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?

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