scarpe-team / scarpe

Scarpe - shoes but running on webview
Other
162 stars 29 forks source link

Text Drawable refit #517

Closed noahgibbs closed 10 months ago

noahgibbs commented 10 months ago

Description

Text Drawables haven't gotten the benefit of a lot of recent changes -- shoes styles, Drawable#initialize doing default values, things like that. This fixes that. We also haven't historically bothered with most styles for text drawables, mostly at all. This fixes that too. We also haven't allowed some of the more fun Text Drawable syntaxes, things like this:

para "This is ", em(strong("emphatically strongly")), " made of text!"
para "This is ", em("emphatically ", hidden: true), "somewhat hidden!"

t = em("emphatically")
@p1 = para "This is ", t, " ", strong("strongly"), " made of text!"
@p2 = para "And ", t, " a great idea!"
para "This is ", link(em("emphatically"), " made of ", span("text!"), click: "http://foo.com", fill: blue)

It's still a draft PR for a few reasons. I'd like to get updating the TextDrawable objects (not only the Para) working - that's nearly done. I'd like to get LinkHover working. That's not far off. And I haven't finished all the testing yet -- definitely not the HTML fixtures, which are going to change. At a minimum they're going to get a class on every TextDrawable so we can select them to do updates.

This is built on top of #515, so a lot of the test changes are that. Once 515 is merged, this should be a single commit.

This is almost a fix for #444. We're still missing a few text properties and LinkHover.

Image(if needed, helps for a faster review)

Screenshot 2023-12-18 at 21 44 56 Screenshot 2023-12-17 at 22 42 31

Checklist

noahgibbs commented 10 months ago

I see 'del' and friends referenced in a few places, where is the canonical place I can see the changes for what they mean implemnted? (e.g. strikethrough, size, etc.)

Right now we use HTML tags where we can. If you check lib/scarpe/wv/text_drawable.rb at the bottom, you'll see they all just use the HTML tag of the same name... except for ins, where there's no equivalent HTML tag, so it's a span (edit: and link, where the equivalent HTML tag is named "a"). For the same reason we do not declare Shoes-side properties like strikethrough for del. Instead, we're using HTML del, which by default has a strikethrough.

This makes for prettier HTML markup -- you'll notice that our em and strong tags didn't turn into span-with-italics and span-with-bold, respectively, which would be a lot wordier.

Arguably that's not good. It means we're relying on a combination of HTML/CSS defaults and Shoes defaults. We could totally do it all in Shoes and make everything a span, or have Shoes overwrite CSS stuff somehow, or have Shoes look at what CSS styles it's going to emit and pick a tag. For now I've opted to use CSS defaults as much as possible, but I'm open to other approaches. They all have interesting tradeoffs, so I stuck with "mostly what we've been doing" for this version :-)

And that means there isn't one place. There's two. One is lib/scarpe/wv/text_drawable.rb where we declare the equivalent HTML tags for each Shoes tag name. And the other is at the very bottom of lacci/lib/shoes/drawables/text_drawable.rb, where we declare that the default style for the ins tag is single-underline.

It also means that the default Shoes styles for the other tags (e.g. strikethrough for del) aren't actually visible to Lacci right now. That's definitely one of the interesting tradeoffs, and may need to change eventually.