diff --git a/src/Desktop.jl b/src/Desktop.jl index 3941ad7..bdc948e 100644 --- a/src/Desktop.jl +++ b/src/Desktop.jl @@ -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 diff --git a/src/Desktop/controls.jl b/src/Desktop/controls.jl index db7b450..91c7b85 100644 --- a/src/Desktop/controls.jl +++ b/src/Desktop/controls.jl @@ -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 diff --git a/src/Desktop/imgui_controls.jl b/src/Desktop/imgui_controls.jl index 1b071b2..7d73f63 100644 --- a/src/Desktop/imgui_controls.jl +++ b/src/Desktop/imgui_controls.jl @@ -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 diff --git a/test/poptart/desktop/controls.jl b/test/poptart/desktop/controls.jl index 053869c..72dc2c5 100644 --- a/test/poptart/desktop/controls.jl +++ b/test/poptart/desktop/controls.jl @@ -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