nui icon indicating copy to clipboard operation
nui copied to clipboard

.nss variables accessible from code

Open Emailrus opened this issue 8 years ago • 7 comments

Hi again :) This time I was thinking about access to variables defined in .nss in code. Very useful in cases, where you need to obtain some global vars, so you won't be having two files with same palette, for example:

/* nss file*/
@color-primary: #123456;

/* constants file */
#define kColorPrimary  @"color-primary";

/* some UI file */
- (void)someSetupMethod
{
    CALayer *border = [CALayer layer];
    bottomBorder.frame = CGRectMake(whatever);
    bottomBorder.backgroundColor = [[NUISettings getColorFromVar:kColorPrimary] CGColor];
    [self.myTextField.layer addSublayer:border];
}

Emailrus avatar Mar 11 '16 12:03 Emailrus

Why would you do that instead of merely doing:

/* nss file*/
MyTextField {
    border-color: #123456;
}

/* some UI file */
- (void)someSetupMethod
{
    self.myTextField.nuiClass = @"MyTextField";
}

Stunner avatar Mar 11 '16 12:03 Stunner

By using CALayer I wanted to point out, that not everything is stylable by NUI. Some custom controls would still require manual approach. Point is, that I still need to access my styles (color palette for example) and since they are moved to .nss file and I don't want to have two files defining same styles (MyTheme.nss and MyTheme.h) it would be nice to do it via NUI.

Emailrus avatar Mar 11 '16 12:03 Emailrus

Can this sort of thing can be addressed by render customization? It has currently been partially implemented at a very granular level, but as per the discussion it needs to be re-architected.

Stunner avatar Mar 11 '16 12:03 Stunner

Partially maybe. I can think of some other scenarios, where you don't have rendering element, like if you need some padding values from .nss file to include them in layout calculations. Also accessing variables might be much easier to implement and use.

Emailrus avatar Mar 11 '16 13:03 Emailrus

Fair enough. I'd like to hear your thoughts on this @timbodeit.

Stunner avatar Mar 11 '16 13:03 Stunner

@Emailrus, while I agree feature is useful, you could you workaround, add dummy style colors you need, App { background-color: @minor; foreground-color: @main; } then in code use NUISettings.getColor("background-color", withClass: "App")

alexeyt820 avatar Mar 15 '16 05:03 alexeyt820

@Stunner I'm sorry, I have been inactive for a little while.

I would suggest the same thing as @alexeyt820. We have "Colors" classes for various components of our app. I don't think we need new API in NUI for this. I do like the idea of a constants file however. It would be awesome to have a code-generating script, that automatically extracts constants for the different Classes and attributes to make accessing them from code safer and a little bit more convenient.

timbodeit avatar Mar 20 '16 14:03 timbodeit