theming does not allow to add padding to the menu
optimisme opened this issue · 5 comments
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];
}
}
}
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.
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?