Menu

Makie.Menu <: Block

A drop-down menu with multiple selectable options. You can pass options with the keyword argument options .

Options are given as an iterable of elements. For each element, the option label in the menu is determined with optionlabel(element) and the option value with optionvalue(element) . These functions can be overloaded for custom types. The default is that tuples of two elements are expected to be label and value, where string(label) is used as the label, while for all other objects, label = string(object) and value = object.

When an item is selected in the menu, the menu's selection attribute is set to optionvalue(selected_element) . When nothing is selected, that value is nothing .

You can set the initial selection by passing one of the labels with the default keyword.

Constructors

Menu(fig_or_scene; default = nothing, kwargs...)              

Examples

Menu with string entries, second preselected:

menu1 = Menu(fig[1, 1], options = ["first", "second", "third"], default = "second")              

Menu with two-element entries, label and function:

funcs = [sin, cos, tan]
labels = ["Sine", "Cosine", "Tangens"]

menu2 = Menu(fig[1, 1], options = zip(labels, funcs))              

Executing a function when a selection is made:

on(menu2.selection) do selected_function
    # do something with the selected function
end              

Attributes

Makie.Menu attributes :

  • cell_color_active : Cell color when active Default: COLOR_ACCENT[]

  • cell_color_hover : Cell color when hovered Default: COLOR_ACCENT_DIMMED[]

  • cell_color_inactive_even : Cell color when inactive even Default: RGBf(0.97, 0.97, 0.97)

  • cell_color_inactive_odd : Cell color when inactive odd Default: RGBf(0.97, 0.97, 0.97)

  • direction : The opening direction of the menu (:up or :down) Default: automatic

  • dropdown_arrow_color : Color of the dropdown arrow Default: (:black, 0.2)

  • dropdown_arrow_size : Size of the dropdown arrow Default: 20

  • i_selected : Index of selected item. Should not be set by the user. Default: 0

  • is_open : Is the menu showing the available options Default: false

  • options : The list of options selectable in the menu. This can be any iterable of a mixture of strings and containers with one string and one other value. If an entry is just a string, that string is both label and selection. If an entry is a container with one string and one other value, the string is the label and the other value is the selection. Default: ["no options"]

  • prompt : The default message prompting a selection when i == 0 Default: "Select..."

  • selection : Selected item value. This is the output observable that you should listen to to react to menu interaction. Should not be set by the user. Default: nothing

  • selection_cell_color_inactive : Selection cell color when inactive Default: RGBf(0.94, 0.94, 0.94)

  • textcolor : Color of entry texts Default: :black

  • textpadding : Padding of entry texts Default: (10, 10, 10, 10)

  • textsize : Font size of the cell texts Default: #= /home/runner/work/Makie.jl/Makie.jl/src/makielayout/types.jl:886 =# @inherit :fontsize 16.0f0

Layout attributes :

  • alignmode : The alignment of the menu in its suggested bounding box. Default: Inside()

  • halign : The horizontal alignment of the menu in its suggested bounding box. Default: :center

  • height : The height setting of the menu. Default: Auto()

  • tellheight : Controls if the parent layout can adjust to this element's height Default: true

  • tellwidth : Controls if the parent layout can adjust to this element's width Default: true

  • valign : The vertical alignment of the menu in its suggested bounding box. Default: :center

  • width : The width setting of the menu. Default: nothing

using GLMakie
fig = Figure()

menu = Menu(fig, options = ["viridis", "heat", "blues"], default = "blues")

funcs = [sqrt, x->x^2, sin, cos]

menu2 = Menu(fig,
    options = zip(["Square Root", "Square", "Sine", "Cosine"], funcs),
    default = "Square")

fig[1, 1] = vgrid!(
    Label(fig, "Colormap", width = nothing),
    menu,
    Label(fig, "Function", width = nothing),
    menu2;
    tellheight = false, width = 200)

ax = Axis(fig[1, 2])

func = Observable{Any}(funcs[1])

ys = lift(func) do f
    f.(0:0.3:10)
end
scat = scatter!(ax, ys, markersize = 10px, color = ys)

cb = Colorbar(fig[1, 3], scat)

on(menu.selection) do s
    scat.colormap = s
end
notify(menu.selection)

on(menu2.selection) do s
    func[] = s
    autolimits!(ax)
end
notify(menu2.selection)

menu2.is_open = true

fig          

You can change the direction of the menu with direction = :up or direction = :down . By default, the direction is determined automatically to avoid cutoff at the figure boundaries.

using GLMakie

fig = Figure()

menu = Menu(fig[1, 1], options = ["A", "B", "C"])
menu2 = Menu(fig[3, 1], options = ["A", "B", "C"])

menu.is_open = true
menu2.is_open = true

fig