scarpe-team / scarpe

Scarpe - shoes but running on webview

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow updates to text widgets

noahgibbs opened this issue · comments

For a Shoes item like:

para strong("Bobo")

it turns out you can update it. Something like this:

    b = strong("Bobo")
    changer = para b
    b.text = "Jojo" # Now the para says Jojo

We don't currently keep track of which para has which text items. Like, each para knows for itself, but a text widget doesn't know which paras are using it. Right now you can do this, and actually it works fine, but it does a full-page refresh every time so the widget loses focus (that's another thing we'll need to fix later.)

If we want to support this change behaviour, we'll should track, for each text widget, who's using it. Either it needs a parents-type list (or to set a parent? text widgets don't currently do that), or it needs a notify/subscribe mechanism for when it changes so the para will notice.

I mean, we kind of do - we have Shoes events sent every time the text widgets update. But it's hard to subscribe to those from para (for instance) and be sure they've updated properly at the right time. Ordering in event-based systems is hard.

The old examples/legacy/not_checked/shoes-contrib/elements/edit_box-character-count.rb uses this mechanism, so it's a good test.

Maybe the easiest way to do it, come to think of it, would be to tag the generated text widget html with classes (not IDs - no guarantee that a given text widget is only in one para) so that the text widgets could update them when the text changes.

commented

what's the difference between using .replace and this?

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

Now that I've added show/hide -- those also won't generally work on TextWidget classes. Getting updates working and getting show/hide working are probably the same thing: assign the TextWidget stuff an HTML ID, generally allow messing with them that way.

This will interact with #444 - probably want to do the two together.

Merging into issue #444.