sharkdp / purescript-flare

A special-purpose UI library for Purescript
286 stars 17 forks source link

Support list components #2

Closed paf31 closed 7 years ago

paf31 commented 8 years ago

I don't know if this is possible but something like

many :: forall a. a -> UI a -> UI (List a)

might be nice. It could be rendered as a list of items, each with its own Remove button, and an Add button at the top.

sharkdp commented 8 years ago

That's a great idea. Definitely a bit more complex than the current components, but it should be possible.

Gabriella439 commented 8 years ago

Probably the best way to solve this would be to figure out how to implement Alternative for UI and then many would fall naturally out of that.

Here's a simple sketch of what the user interface might look like that would be compatible with what @paf31 wants: if you have two controls, x and y then x <|> y is a panel that begins with x and has something like a [+] button in the top-left corner. If you click that button then the panel changes to y and the [+] button changes to [-]. If you click the [-] button then the panel switches back to x.

So if you combine that with Haskell's definition for many it should do exactly what @paf31 wants. I'm not sure if this would work with Purescript since Haskell's many depends crucially on laziness, though.

sharkdp commented 8 years ago

@Gabriel439 Thank you! That sounds like a really interesting approach.

Here is what I found out so far:

If I understand you (and the implementation of some and many) correctly, many (int_ 0) :: UI (Array Int) should expand to something like this (cut-off after three iterations):

    pure []
<|> sequence [int_ 0]
<|> sequence [int_ 0, int_ 0]
<|> sequence [int_ 0, int_ 0, int_ 0]

Running this UI actually works (if I add some parentheses to make <|> right-associative), but it suffers from two problems:

Gabriella439 commented 8 years ago

Hmmm. You're right. I didn't think that through.

It seems like if there were some sort of [+]-button functionality it would have to be provided by some separate combinator and not implicitly by the Alternative class operations.

I'll have to think about this some more and experiment with this in typed-spreadsheet first.

sammthomson commented 7 years ago

This was something I wanted also, so I took a stab at it. I didn't use Alternative or anything, just recursively nested UIs that match the List structure. It works nicely, but the code might could use a review. PR incoming...

sharkdp commented 7 years ago

Closed via #26