diff --git a/.gitignore b/.gitignore index f5e1d7f..b8800aa 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ docs/build *.jl.cov *.jl.*.cov *.jl.mem +Manifest.toml \ No newline at end of file diff --git a/Project.toml b/Project.toml index 1a2118e..000700c 100644 --- a/Project.toml +++ b/Project.toml @@ -4,33 +4,33 @@ keywords = ["GUI"] license = "MIT" desc = "GUI programming in Julia based on CImGui.jl" authors = ["WooKyoung Noh "] -version = "0.3.0" +version = "0.3.1" [deps] CImGui = "5d785b6c-b76f-510e-a07c-3070796c7e87" +ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" +FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" Jive = "ba5e3d4b-8524-549f-bc71-e76ad9e9deed" -UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" -Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" -ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" -FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" - -[extras] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -GLFW = "f7f18e0c-5ee9-5ccd-a5bf-e8befd85ed98" - -[targets] -test = ["Test", "Random", "GLFW"] +UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" [compat] -julia = "1" CImGui = "1.77" -UnicodePlots = "1.2" -GLFW = "3.2" -FixedPointNumbers = "0.8" ColorTypes = "0.10" Colors = "0.12" +FixedPointNumbers = "0.8" +GLFW = "3.2" Jive = "0.2" +UnicodePlots = "1.2" +julia = "1" + +[extras] +GLFW = "f7f18e0c-5ee9-5ccd-a5bf-e8befd85ed98" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test", "Random", "GLFW"] diff --git a/src/Desktop.jl b/src/Desktop.jl index bdc948e..7e7e2c7 100644 --- a/src/Desktop.jl +++ b/src/Desktop.jl @@ -1,7 +1,7 @@ module Desktop # Poptart export Application, Window -export Button, InputText, Label, Slider, Checkbox +export Button, InputText, Label, Slider, Checkbox, Popup, OpenPopup export Canvas export ScatterPlot, Spy, BarPlot, LinePlot, MultiLinePlot, Histogram export Separator, SameLine, NewLine, Spacing, Group @@ -40,6 +40,7 @@ include("Desktop/imgui_controls.jl") include("Desktop/imgui_drawings.jl") include("Desktop/menus.jl") include("Desktop/events.jl") +include("Desktop/popups.jl") env = Dict{Ptr{Cvoid},UIApplication}() include("Desktop/glfw.jl") # env exit_on_esc diff --git a/src/Desktop/controls.jl b/src/Desktop/controls.jl index 91c7b85..8dee56c 100644 --- a/src/Desktop/controls.jl +++ b/src/Desktop/controls.jl @@ -16,6 +16,7 @@ end title::String = "Button" callback::Union{Nothing,Function} = nothing frame::NamedTuple{(:width, :height)} = (width=0, height=0) # deprecated + async::Bool = false end """ @@ -51,4 +52,14 @@ end callback::Union{Nothing,Function} = nothing end +""" + Popup(; label::String = "", items::Vector{<:UIControl}) + + !!! Note: You must use a sync Button (`Button(async=false)`) to open a Popup. +""" +@kwdef mutable struct Popup <: UIControl + label::String = "" + items::Vector{<:UIControl} = [] +end + # module Poptart.Desktop diff --git a/src/Desktop/imgui_controls.jl b/src/Desktop/imgui_controls.jl index 7d73f63..08c680f 100644 --- a/src/Desktop/imgui_controls.jl +++ b/src/Desktop/imgui_controls.jl @@ -68,7 +68,14 @@ function imgui_control_item(imctx::Ptr, item::Slider) end function imgui_control_item(imctx::Ptr, item::Button) - CImGui.Button(item.title) && @async Mouse.leftClick(item) + CImGui.Button(item.title) || return + if item.async + @info "async pressed" + @async Mouse.leftClick(item) + else + @info "sync pressed" + Mouse.leftClick(item) + end end function imgui_control_item(imctx::Ptr, item::Canvas) @@ -88,4 +95,12 @@ function imgui_control_item(imctx::Ptr, item::Checkbox) end end +# Popup +function imgui_control_item(imctx::Ptr, item::Popup) + if CImGui.BeginPopup(item.label) + imgui_control_item.(Ref(imctx), item.items) + CImGui.EndPopup() + end +end + # module Poptart.Desktop diff --git a/src/Desktop/popups.jl b/src/Desktop/popups.jl new file mode 100644 index 0000000..408c467 --- /dev/null +++ b/src/Desktop/popups.jl @@ -0,0 +1,7 @@ +# module Poptart.Desktop + +function OpenPopup(popup::Popup) + CImGui.OpenPopup(popup.label) +end + +# module Poptart.Desktop \ No newline at end of file diff --git a/test/poptart/desktop/controls.jl b/test/poptart/desktop/controls.jl index 72dc2c5..3458345 100644 --- a/test/poptart/desktop/controls.jl +++ b/test/poptart/desktop/controls.jl @@ -26,6 +26,14 @@ check1 = Checkbox(label="check1", value=true) check2 = Checkbox(label="check2", value=false) push!(window1.items, check1, check2) +popup_button = Button(title="Open Popup", async=false) +popup1 = Popup(label="popup1", items = [Label("A popup")]) +push!(window1.items, popup1) + +didClick(popup_button) do event + OpenPopup(popup1) +end + pause(app) end # module test_poptart_desktop_controls