gnustep / libs-gui

The GNUstep gui library is a library of graphical user interface classes written completely in the Objective-C language; the classes are based upon Apple's Cocoa framework (which came from the OpenStep specification). *** Larger patches require copyright assignment to FSF. please file bugs here. ***
http://www.gnustep.org
GNU General Public License v3.0
279 stars 103 forks source link

Theming should be able to define 'accept button' style #227

Closed optimisme closed 11 months ago

optimisme commented 11 months ago

Theming should be able to define 'accept button' style

Like in the picture, theming should be able to define the text color, prevent drawing the line jump symbol and prevent the text movement when clicked (https://github.com/gnustep/libs-gui/issues/219)

Image on the left is GNUStep (background color is not an issue), Right image is the desired themable look and feel (white text, without the line jump, without the text movement)

Screenshot 2023-12-22 at 17 38 56
optimisme commented 11 months ago

As said in bug: https://github.com/gnustep/libs-gui/issues/225

I've seen that I can change the text color this way:

        if ([cell isKindOfClass:[NSButtonCell class]]) {
            NSButtonCell *buttonCell = (NSButtonCell *) cell;
            NSString *keyEquivalent = [buttonCell keyEquivalent];
            if ([keyEquivalent isEqualToString:@"\r"]) {
                NSDictionary *attributes = @{NSForegroundColorAttributeName: [NSColor whiteColor]};
                NSAttributedString *coloredTitle = [[NSAttributedString alloc] initWithString:[cell title] attributes:attributes];
                [buttonCell setAttributedTitle:coloredTitle];
                backgroundColor = GVThemeColorRGB(0, 122, 255, 1.0);
            }
        }
        [backgroundColor set];
        [bezelPath fill];
        [bezelColor setStroke];
        [bezelPath setLineWidth:1.0];
        [bezelPath stroke];

If this is the way of changing background and text color from a button cell, theming needs a way remove the 'return arrow' for 'accept buttons'.

The image on the left is from GNUStep and the image on the right is the expected theme configuration

Screenshot 2023-12-23 at 00 48 23

(centered text without the arrow)

rfm commented 11 months ago

prevent drawing the line jump symbol

I can see at least two ways of doing this, depending on exactly what it is you want.

To change the image everywhere, you just provide a replacement for the default image in your theme; in this case a transparent image may do what you want.

To change behavior in a specific place (eg for just one control rather than throughput the gui) would require implementing -drawButton:in:view:style:state: so that it would set a nil image if it was called to draw that specific control, and would then call the superclass implementation to do all the normal drawing.

rfm commented 11 months ago

set a nil image NB. a well behaved theme should not simply alter the controls being drawn, but should alter them, perform the drawing, and then restore them to the way they were before the drawing was done. That way, if the user decides to change the theme of a running application, the old theme won't interfere with the functioning of the new one. So the actual code should be more on the lines of:

NSImage *originalImage = AUTORELEASE(RETAIN([cell image])); [cell setImage: imageForThisTheme]; // perform drawing [cell setImage: originalImage];

optimisme commented 11 months ago

Looks like [cell setImage: nil]; removes the 'new line' image.