GLMakie Menu Filter

Hi, I’m just wondering if anyone has an idea on how to filter the menu items in GLMakie. I have a GUI with >50 menu items and its really difficult scrolling to the specific item I need. Naturally when I click the menu, I’d like to just start typing in the name of the item I want and the menu to automatically filter the results. Is this possible? One way I’m thinking of doing this is to have a textbox labelled “Filter” where I can type in a string that must occur in the menu items to filter them. However, if anyone knows if its possible to just type in the string when the menu is selected or if this is a planned feature in the future, please let me know!

Cheers,

Matt

1 Like

This is a hack to filter based on first character. A real solution would be cool but probably quite a bit of work

using GLMakie


f = Figure()
options = let
    all = filter(x -> startswith(x, r"[a-z]"), string.(names(Base)))
    all[1:(end÷50):end]
end
m = Menu(f[1, 1]; options)

on(m.blockscene.events.keyboardbutton, priority = 100) do (; action, key)
    if action === Makie.Keyboard.press && m.is_open[]
        if Makie.Keyboard.a <= key <= Makie.Keyboard.z
            char = ('a':'z')[Int(key)-Int(Makie.Keyboard.a)+1]
            m.options = filter(startswith(char), options)
        elseif key === Makie.Keyboard.escape
            m.options = options
        end
        return Makie.Consume(true)
    else
        return Makie.Consume(false)
    end
end

on(m.is_open) do is_open
    if !is_open
        m.options = options
    end
end

f
2 Likes

Thanks Jules, I’ll give this a try. I appreciate the help!