scarpe-team / scarpe

Scarpe - shoes but running on webview

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TextDrawables need re-do

noahgibbs opened this issue · comments

Right now you can't do em(strong("blah")) to get em-plus-strong. In old Shoes3 you could. We also don't handle updates to TextDrawable objects well -- you have to just refresh everything, which is pretty silly. And we don't flatten properly -- e.g. para ["Yo", em(["Blah"])]. But that's a pretty minor issue.

I think the right way to handle this is to get TextDrawables out of the display service. Instead of passing a list of strings and IDs, we could pass a list like [["", "Hello"], ["em", "strong", "Good-Looking!"]] to the back end with no IDs. When we update a TextDrawable in Lacci, we'd pass a new list to the back end as a property of the para (or multiple paras.)

[Edit: I no longer believe that this data-based representation is the way to go. The little text-drawable fragments like em() and strong() have a surprising amount of complexity to them. I'm going the other way in PR #517 and making them essentially little full-fledged drawables.]

Something that might go well alongside this: Shoes3 default style values are resolved dynamically, and can change after the drawable is created. We may want to do the same, which would allow e.g. dynamic link-hover styling.

[Edit: nope, as far as I can tell the default values are set internally for the drawable when it's created. Setting an animation timer that changes the LinkHover colour back and forth between red and green does not result in a link that is sometimes red and sometimes green or that flashes when hovered over. It keeps the default colour from when it was created.]

Looks like defaults to not change as dynamically as I thought, at least according to my testing.

We still want dynamic link-hover styling if we can get it, obviously.

For future reference, here's the list of styles that applied to Text objects (TextDrawables in Scarpe) in Shoes3:

# Styles that apply to essentially all Drawables
:left, :top, :right, :bottom, :width, :height, :attach, :hidden,
:displace_left, :displace_top, :margin, :margin_left, :margin_top,
:margin_right, :margin_bottom]

# Text-Specific styles
:strikecolor, :undercolor, :font, :size, :family, :weight,
:rise, :kerning, :emphasis, :strikethrough, :stretch, :underline,
:variant

# Mouse-event styles
:click, :motion, :release, :hover,

# Color styles
:stroke, :fill

I'm not sure whether we want to pass the textdrawables as data at this point. We could, but that might mean a lot of styles as part of the data. We could also treat them as full-fledged drawables with styles and so on, which would make updates easier (we'd still need to tell their parent to redraw or tag their output with an html ID.) With this many styles, though, I'm not wild about putting them in as data.

Heck, what do we want to do about individual strong() tags (etc) that want to set top and left and so on? Urgh. Maybe we know how to render sufficiently-simple TextDrawables to HTML text and the rest turn into some kind of freestanding objects? But converting back and forth between simple text and freestanding objects sounds awful.

Comment from issue #391:

If you update the strong() object itself, right now it doesn't update. A number of legacy examples depend on the old behaviour.

Currently works in Scarpe:

@ctr = 0
@p = para strong("0")
motion do
  @ctr += 1
  @p.replace strong(@ctr.to_s)
end

Currently does not work in Scarpe:

@ctr = 0
@s = strong("0")
para @s
motion do
  @ctr += 1
  @s.text = @ctr.to_s
end

Here are the differences between the different text types in Shoes3:

    STYLE(cCode,        family, monospace);
    STYLE(cDel,         strikethrough, single);
    STYLE(cEm,          emphasis, italic);
    STYLE(cIns,         underline, single);
    STYLE(cLink,        underline, single);
    STYLE(cLink,        stroke, #06E);
    STYLE(cLinkHover,   underline, single);
    STYLE(cLinkHover,   stroke, #039);
    STYLE(cStrong,      weight, bold);
    STYLE(cSup,         rise,   10);
    STYLE(cSup,         size,   x-small);
    STYLE(cSub,         rise,   -10);
    STYLE(cSub,         size,   x-small);

That x-small is a Pango font size, but no clue what its html equivalent would be. Though we know it's for superscript/subscript, so that gives an idea of it.

Worth noting: span has no entry here. It's just natural-style text unless you override something. No modifiers.

#517 does a lot of this. No LinkHover yet, though.

Text styles that we don't support yet even with 517:

:family, :weight, :rise, :kerning, :emphasis, :stretch, :variant

Hm. And "font" isn't quite right. We use it like family, when it's actually several different options combined.

Everything not solved by PR #517 has been moved to the much more specific issue #520.