alexrozanski/PXSourceList

Availability to override the selection and the Group names color is missing

kukosk opened this issue · 2 comments

I have written this piece of code to override the selection to a gradient. You should implement it.

  • (void)highlightSelectionInClipRect:(NSRect)theClipRect
    {
    NSRange aVisibleRowIndexes = [self rowsInRect:theClipRect];
    NSIndexSet *aSelectedRowIndexes = [self selectedRowIndexes];
    int aRow = aVisibleRowIndexes.location;
    int anEndRow = aRow + aVisibleRowIndexes.length;

    NSGradient *grad;

    if (self == [[self window] firstResponder] && [[self window] isMainWindow] && [[self window] isKeyWindow])
    {
    grad = [[[NSGradient alloc] initWithColorsAndLocations:[NSColor colorWithCalibratedRed:(120.0/255.0) green:(80.0/255.0) blue:(70.0/255.0) alpha:1], 0.0f, [NSColor colorWithCalibratedRed:(105.0/255.0) green:(54.0/255.0) blue:(43.0/255.0) alpha:1], 1.0f, nil] autorelease];
    }
    else
    {
    grad = [[[NSGradient alloc] initWithColorsAndLocations:[NSColor colorWithCalibratedRed:(126.0/255.0) green:(98.0/255.0) blue:(92.0/255.0) alpha:1], 0.0f, [NSColor colorWithCalibratedRed:(110.0/255.0) green:(62.0/255.0) blue:(52.0/255.0) alpha:1], 1.0f, nil] autorelease];
    }

    for (aRow; aRow < anEndRow; aRow++)
    {
    if([aSelectedRowIndexes containsIndex:aRow])
    {
    NSRect aRowRect = NSInsetRect([self rectOfRow:aRow], 2, 0);
    [[NSBezierPath bezierPathWithRoundedRect:aRowRect xRadius:5.0 yRadius:5.0] addClip];
    [grad drawInRect:aRowRect angle:90.0];
    [[NSBezierPath bezierPathWithRect:[self bounds]] setClip];
    }
    }
    }

You should use some #defines with the gradients and the roundness of the radius selection... :)
And I also want to change the group names color somehow. A #define would be fine. I'm gona look into it now...

Implementation details to satisfy a specific use-case (exact colors, behavior, etc) are best done in a custom subclass or your own fork of PXSourceList.

Perhaps instead you might consider adding a couple properties and updating your code to allow for more generic customization:

@property (nonatomic, retain) NSGradient *selectionGradient;
@property (nonatomic, retain) NSColor *groupHeadingTextColor;

Hi kukosk, thanks for contributing.

However, I agree with Dave – the goal of PXSourceList is to provide a generic Source List control and interface but allow customization if needed – for example it still allows you to use custom cells (badge drawing isn't done in the cell, but rather in the Source List view to allow this) etc, which means it's very flexible, but inherently has a generic and relatively basic implementation to suit most developers' needs.

Selection drawing is also something that I intentionally left out because you get it all for free – drawing the selection gradient, drawing group rows and highlighting group rows with drag and drop is all done by AppKit, so it seemed unnecessary to reimplement it myself.

If you want something more tailored to your needs then you could simply subclass PXSourceList and implement this; and if you want to share this, fork the repository and add it to your own branch :)