From 47f0bc5fed16a7ee16a2aa2bf03e0506e27573f3 Mon Sep 17 00:00:00 2001 From: St Z Date: Tue, 1 Sep 2020 21:25:51 +0800 Subject: [PATCH 1/4] add popup --- src/Desktop.jl | 2 +- src/Desktop/controls.jl | 20 ++++++++++++++++++++ src/Desktop/imgui_controls.jl | 13 +++++++++++++ test/poptart/desktop/controls.jl | 3 +++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Desktop.jl b/src/Desktop.jl index bdc948e..0fde430 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, SyncButton, Popup 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 91c7b85..12da911 100644 --- a/src/Desktop/controls.jl +++ b/src/Desktop/controls.jl @@ -51,4 +51,24 @@ end callback::Union{Nothing,Function} = nothing end +""" + SyncButton(; title::String = "Button", callback::Union{Nothing,Function} = nothing) + + A SyncButton is just a button except its callback is run synchronizedly. +""" +@kwdef mutable struct SyncButton <: UIControl + title::String = "Button" + callback::Union{Nothing,Function} = nothing +end + +""" + Popup(; label::String = "", items::Vector{<:UIControl}) + + !!! Note: You cannot use a Button to open a Popup. Use a SyncButton instead. +""" +@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..b934c9e 100644 --- a/src/Desktop/imgui_controls.jl +++ b/src/Desktop/imgui_controls.jl @@ -71,6 +71,10 @@ function imgui_control_item(imctx::Ptr, item::Button) CImGui.Button(item.title) && @async Mouse.leftClick(item) end +function imgui_control_item(imctx::Ptr, item::SyncButton) + CImGui.Button(item.title) && Mouse.leftClick(item) +end + function imgui_control_item(imctx::Ptr, item::Canvas) draw_list = CImGui.GetWindowDrawList() window_pos = CImGui.GetCursorScreenPos() @@ -88,4 +92,13 @@ 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/test/poptart/desktop/controls.jl b/test/poptart/desktop/controls.jl index 72dc2c5..72f92ab 100644 --- a/test/poptart/desktop/controls.jl +++ b/test/poptart/desktop/controls.jl @@ -26,6 +26,9 @@ check1 = Checkbox(label="check1", value=true) check2 = Checkbox(label="check2", value=false) push!(window1.items, check1, check2) +popup1 = Popup(label="popup1", items = [Label("A popup")]) +push!(window1.items, popup1) + pause(app) end # module test_poptart_desktop_controls From 6c208b803dda4fb51171d2e35e46a66412d1bb3a Mon Sep 17 00:00:00 2001 From: St Z Date: Tue, 1 Sep 2020 21:27:00 +0800 Subject: [PATCH 2/4] update version --- Project.toml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) 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"] From dee69bb874c8885664f395cfe42c5d325055ce56 Mon Sep 17 00:00:00 2001 From: St Z Date: Wed, 2 Sep 2020 14:23:25 +0800 Subject: [PATCH 3/4] make merge Button and SyncButton --- src/Desktop.jl | 2 +- src/Desktop/controls.jl | 13 ++----------- src/Desktop/imgui_controls.jl | 16 +++++++++++----- test/poptart/desktop/controls.jl | 7 +++++++ 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Desktop.jl b/src/Desktop.jl index 0fde430..f7b6ab0 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, SyncButton, Popup +export Button, InputText, Label, Slider, Checkbox, Popup, open_popup 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 12da911..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,20 +52,10 @@ end callback::Union{Nothing,Function} = nothing end -""" - SyncButton(; title::String = "Button", callback::Union{Nothing,Function} = nothing) - - A SyncButton is just a button except its callback is run synchronizedly. -""" -@kwdef mutable struct SyncButton <: UIControl - title::String = "Button" - callback::Union{Nothing,Function} = nothing -end - """ Popup(; label::String = "", items::Vector{<:UIControl}) - !!! Note: You cannot use a Button to open a Popup. Use a SyncButton instead. + !!! Note: You must use a sync Button (`Button(async=false)`) to open a Popup. """ @kwdef mutable struct Popup <: UIControl label::String = "" diff --git a/src/Desktop/imgui_controls.jl b/src/Desktop/imgui_controls.jl index b934c9e..a34bb79 100644 --- a/src/Desktop/imgui_controls.jl +++ b/src/Desktop/imgui_controls.jl @@ -68,11 +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) -end - -function imgui_control_item(imctx::Ptr, item::SyncButton) - CImGui.Button(item.title) && 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) @@ -100,5 +103,8 @@ function imgui_control_item(imctx::Ptr, item::Popup) end end +function open_popup(popup::Popup) + CImGui.OpenPopup(popup.label) +end # module Poptart.Desktop diff --git a/test/poptart/desktop/controls.jl b/test/poptart/desktop/controls.jl index 72f92ab..0d9b957 100644 --- a/test/poptart/desktop/controls.jl +++ b/test/poptart/desktop/controls.jl @@ -26,9 +26,16 @@ 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 + open_popup(popup1) +end +# For now, you cannot use Mouse.leftClick to open a popup +# Mouse.leftClick(popup_button) + pause(app) end # module test_poptart_desktop_controls From 64125fb1952da8fdbc7f3ad919437962f56ff21e Mon Sep 17 00:00:00 2001 From: St Z Date: Wed, 2 Sep 2020 22:34:31 +0800 Subject: [PATCH 4/4] finish popup (probably) --- .gitignore | 1 + src/Desktop.jl | 3 ++- src/Desktop/imgui_controls.jl | 4 ---- src/Desktop/popups.jl | 7 +++++++ test/poptart/desktop/controls.jl | 4 +--- 5 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 src/Desktop/popups.jl 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/src/Desktop.jl b/src/Desktop.jl index f7b6ab0..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, Popup, open_popup +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/imgui_controls.jl b/src/Desktop/imgui_controls.jl index a34bb79..08c680f 100644 --- a/src/Desktop/imgui_controls.jl +++ b/src/Desktop/imgui_controls.jl @@ -103,8 +103,4 @@ function imgui_control_item(imctx::Ptr, item::Popup) end end -function open_popup(popup::Popup) - CImGui.OpenPopup(popup.label) -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 0d9b957..3458345 100644 --- a/test/poptart/desktop/controls.jl +++ b/test/poptart/desktop/controls.jl @@ -31,10 +31,8 @@ popup1 = Popup(label="popup1", items = [Label("A popup")]) push!(window1.items, popup1) didClick(popup_button) do event - open_popup(popup1) + OpenPopup(popup1) end -# For now, you cannot use Mouse.leftClick to open a popup -# Mouse.leftClick(popup_button) pause(app)