Skip to content

Commit

Permalink
Merge pull request #15 from Eggiverse/master
Browse files Browse the repository at this point in the history
add Checkbox
  • Loading branch information
wookay authored Aug 31, 2020
2 parents 6df7431 + 5189efd commit 9c998a5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Desktop.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Desktop # Poptart

export Application, Window
export Button, InputText, Label, Slider
export Button, InputText, Label, Slider, Checkbox
export Canvas
export ScatterPlot, Spy, BarPlot, LinePlot, MultiLinePlot, Histogram
export Separator, SameLine, NewLine, Spacing, Group
Expand Down
9 changes: 9 additions & 0 deletions src/Desktop/controls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ end
items::Vector{Drawing} = Drawing[]
end

"""
Checkbox(; label::String = "", value::Bool = false)
"""
@kwdef mutable struct Checkbox <: UIControl
label::String = ""
value::Bool = false
callback::Union{Nothing,Function} = nothing
end

# module Poptart.Desktop
9 changes: 9 additions & 0 deletions src/Desktop/imgui_controls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,13 @@ function imgui_control_item(imctx::Ptr, item::Canvas)
end
end

# CImGui.Checkbox
function imgui_control_item(imctx::Ptr, item::Checkbox)
refvalue = Ref(item.value)
if CImGui.Checkbox(item.label, refvalue)
item.value = refvalue[]
@async Mouse.leftClick(item)
end
end

# module Poptart.Desktop
4 changes: 4 additions & 0 deletions test/poptart/desktop/controls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ slider1 = Slider(label="Int", range=1:10, value=5)
slider2 = Slider(label="Float", range=1:10, value=2.0)
push!(window1.items, label1, slider1, slider2)

check1 = Checkbox(label="check1", value=true)
check2 = Checkbox(label="check2", value=false)
push!(window1.items, check1, check2)

pause(app)

end # module test_poptart_desktop_controls

0 comments on commit 9c998a5

Please sign in to comment.