Git Product home page Git Product logo

Comments (3)

fredkiefer avatar fredkiefer commented on June 16, 2024

Could you please explain a bit what you mean by this requirement that you state here? There already is a method

- (void) drawButton: (NSRect)frame 
                 in: (NSCell*)cell 
               view: (NSView*)view 
              style: (int)style 
              state: (GSThemeControlState)state 

On GSTheme and by overriding this method in your own theme you should be able to produce about any fancy button that you can think of. Most likely you don't want to do that but would prefer another method to change the appearance of a button without overriding this method. Is this correct? And if so, what is it that you are expecting?
For your specific case NSRecessedBezelStyle this method is actually missing specific code as we were not aware how such a button should look like. If you have suggestions on how to style this sort of button within the GNUstep default style, I am willing to put such code in. And if you make this new code configurable it might also help with your advanced requirements.
In the current code the colour is only influenced by the state of the button not by the style. You will need convincing arguments to get that changed.

from libs-gui.

optimisme avatar optimisme commented on June 16, 2024

The source code of my theme (in development)
https://github.com/optimisme/GNUStep-Theme

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];
    Is this the way to color background and text from button cells while doing a theme?

from libs-gui.

optimisme avatar optimisme commented on June 16, 2024

Closing the issue, it is possible to style the text in each custom style:

        NSMutableParagraphStyle *paragraphStyle;
        NSDictionary *attributes;
        NSAttributedString *coloredTitle;
        NSButtonCell *buttonCell = nil;
        if ([cell isKindOfClass:[NSButtonCell class]]) {
            buttonCell = (NSButtonCell *) cell;
        }
        if (buttonCell != nil) {
            bezelColor = GVThemeColorRGB(111, 111, 111, 1.0);
            paragraphStyle = [[NSMutableParagraphStyle alloc] init];
            [paragraphStyle setAlignment:NSTextAlignmentCenter];
            attributes = @{
                NSForegroundColorAttributeName: bezelColor,
                NSParagraphStyleAttributeName: paragraphStyle,
            };
            coloredTitle = [[NSAttributedString alloc] initWithString:[cell title] attributes:attributes];
            [buttonCell setAttributedTitle:coloredTitle];
        }

from libs-gui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.