Skip to content

Commit

Permalink
Merge pull request #16 from Eggiverse/master
Browse files Browse the repository at this point in the history
Add Popup
  • Loading branch information
wookay authored Sep 3, 2020
2 parents 9c998a5 + 64125fb commit ae98596
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ docs/build
*.jl.cov
*.jl.*.cov
*.jl.mem
Manifest.toml
34 changes: 17 additions & 17 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ keywords = ["GUI"]
license = "MIT"
desc = "GUI programming in Julia based on CImGui.jl"
authors = ["WooKyoung Noh <[email protected]>"]
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"]
3 changes: 2 additions & 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, Checkbox
export Button, InputText, Label, Slider, Checkbox, Popup, OpenPopup
export Canvas
export ScatterPlot, Spy, BarPlot, LinePlot, MultiLinePlot, Histogram
export Separator, SameLine, NewLine, Spacing, Group
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/Desktop/controls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down Expand Up @@ -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
17 changes: 16 additions & 1 deletion src/Desktop/imgui_controls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
7 changes: 7 additions & 0 deletions src/Desktop/popups.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# module Poptart.Desktop

function OpenPopup(popup::Popup)
CImGui.OpenPopup(popup.label)
end

# module Poptart.Desktop
8 changes: 8 additions & 0 deletions test/poptart/desktop/controls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ae98596

Please sign in to comment.