nicklockwood / layout

A declarative UI framework for iOS
MIT License
2.23k stars 97 forks source link

Macro for font name is not working #155

Closed algrid closed 5 years ago

algrid commented 5 years ago

Hello,

I'm trying to use a macro for a UILabel font like this:

    <macro name="TITLE_W" value="66%"/>  
    <macro name="TITLE_FONT" value="Roboto-Medium 13"/>

    <UILabel
        top="previous.bottom + 12"
        left="parent.left"
        width="TITLE_W"
        font="TITLE_FONT"
        text="some text"/>

It works fine with the TITLE_W but for TITLE_FONT I get:

Invalid font name or specifier TITLE_FONT.

It would be nice to have this feature supported.

nicklockwood commented 5 years ago

@algrid tryfont="{TITLE_FONT}" instead.

algrid commented 5 years ago

@nicklockwood Tried that, I'm getting "Unexpected token 13 in font expression in UILabel...".

When I use Roboto-Medium 13 directly it works fine.

nicklockwood commented 5 years ago

@algrid hmm, I'll look into that. It will probably work if you do:

    <macro name="TITLE_W" value="66%"/>  
    <macro name="TITLE_FONT" value="Roboto-Medium"/>
    <macro name="TITLE_FONT_SIZE" value="13"/>

    <UILabel
        top="previous.bottom + 12"
        left="parent.left"
        width="TITLE_W"
        font="{TITLE_FONT} {TITLE_FONT_SIZE}"
        text="some text"/>
algrid commented 5 years ago

@nicklockwood This time I get:

screen shot 2018-10-31 at 1 30 10 pm

Maybe it's interpreting that dash as a minus sign and trying to calculate it...

It's not critical for me now, just wanted to report it :)

nicklockwood commented 5 years ago

@algrid ah, I think I see the problem. It's interpreting Roboto-Medium 13 as an expression, not a string. try:

    <macro name="TITLE_W" value="66%"/>  
    <macro name="TITLE_FONT" value="'Roboto-Medium 13'"/>

    <UILabel
        top="previous.bottom + 12"
        left="parent.left"
        width="TITLE_W"
        font="{TITLE_FONT}"
        text="some text"/>

(Note the single ' ' quotes around 'Roboto-Medium 13')

algrid commented 5 years ago

@nicklockwood

Works like this:

    <macro name="TITLE_W" value="66%"/>  
    <macro name="TITLE_FONT" value="'Roboto-Medium 13'"/>

    <UILabel
        top="previous.bottom + 12"
        left="parent.left"
        width="TITLE_W"
        font="{TITLE_FONT}"
        text="some text"/>

Thanks!