JuliaGizmos / Escher.jl

Composable Web UIs in Julia
https://juliagizmos.github.io/Escher.jl
Other
335 stars 63 forks source link

Dropdown menu without dropdown? #172

Open izaid opened 7 years ago

izaid commented 7 years ago

This is a great library, thanks for writing it!

I have a really simple question. I'd basically like a selection widget -- a bunch of vertical items with a scrollbar if there are too many. This is exactly what I get with the dropdown menu, except I don't want to be dropdown -- I want it always there.

Is this possible? If so, how?

shashi commented 7 years ago

You can make in Escher:

function select_from(selected, items, current_item)
     map(items) do t
        item = (t == selected ? fillcolor("#9ba", pad(0.5em, t)) : pad(0.5em, t))
        subscribe(current_item, intent(_->t, clickable(item)))
    end |> vbox |> clip(auto) |> size(10em, 22em)
end

Arguments are selected the item currently selected, items a list of items (strings) to show, and finally current_item is a signal that gets updated when the user clicks on an item.

You can make this fancy: make it possible to select multiple items, use checkboxes against each item etc...

izaid commented 7 years ago

@shashi Thanks! This does create exactly the dropdown select I'm looking for, but I'm finding the clicking doesn't change the menu (tried in Firefox and Chrome). The initial selection stays selected all the time. Any thoughts?

I assumed the right way to use this (which may be wrong), would be to something like:

mysig = Signal(0)
select = select_from(inital_item, items, mysig)

map(mysig) do current
    hbox(..., select)
end