2

I tried to improve the Tip Calculator example a bit, so that "Total: " doesn't disappear when you hit enter on the tip field:

REBOL [title: "Tip Calculator"]
view [
    f: field "49.99"
    hpanel [
        t: field "20" on-action [
            set-face x rejoin ["Total: " round/to to money! ((to-decimal get-face f) * ((to-decimal get-face t) * .01 + 1)) $.01 ]
        ]
        title "%"
    ]
    x: title "Total: " facets [ auto-size true ]
]

However, the auto-size doesn't seem to help the fact that x stays too skinny after calculation. This works:

x: title "Total: " 150x20

...as does this:

x: title "Total:                        "

...but how can I get it to resize automatically?

Kev
  • 15,899
  • 15
  • 79
  • 112

1 Answers1

1

As title seems to descend from text, which is defined as auto-size: false, it would be the most easy solution to replace title with a style defined with auto-size: true e.g info

 x:  info "Total: " 

Otherwise you would have to redefine your own title style descending from a autosizing style.

sqlab
  • 6,412
  • 1
  • 14
  • 29
  • This *does* work. How come the `facets [ auto-size true ]` I tried originally doesn't, though? – Kev Feb 18 '15 at 16:59
  • because title descends from text which is defined as auto-size false. – sqlab Feb 22 '15 at 16:10
  • I *had* read that in your answer, and I think I understand. However, what I don't understand is why `facets [ auto-size true ]` does not override `title`'s definition. I thought that that was the syntax for overriding definitions, based on other example code I had seen. So, what then? Is there no way to override `title` at all, or do I have the syntax wrong? If the latter, what's the correct syntax? (Hopefully that clarifies my confusion a bit.) – Kev Feb 23 '15 at 14:44
  • 1
    That's probably a design decision. If you resize text, you would have to change the font size too. I guess that's not so easy. If you look into r3-gui.r3, you will see, that the style **text** has the line ** ff/auto-size: false** in the on-resize actor. So that overwrites **auto** always. You can comment that line and observe a different behavior. – sqlab Feb 23 '15 at 16:55