Skip to content

Commit

Permalink
Complete non-member method APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnimuc committed Feb 18, 2019
1 parent 394b91c commit 5847ae9
Show file tree
Hide file tree
Showing 6 changed files with 745 additions and 221 deletions.
8 changes: 8 additions & 0 deletions gen/libcimgui_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,10 @@ function igEndTooltip()
ccall((:igEndTooltip, libcimgui), Cvoid, ())
end

function igSetTooltip(text)
ccall((:igSetTooltip, libcimgui), Cvoid, (Cstring,), text)
end

function igOpenPopup(str_id)
ccall((:igOpenPopup, libcimgui), Cvoid, (Cstring,), str_id)
end
Expand Down Expand Up @@ -1034,6 +1038,10 @@ function igLogButtons()
ccall((:igLogButtons, libcimgui), Cvoid, ())
end

function igLogText(text)
ccall((:igLogText, libcimgui), Cvoid, (Cstring,), text)
end

function igBeginDragDropSource(flags)
ccall((:igBeginDragDropSource, libcimgui), Bool, (ImGuiDragDropFlags,), flags)
end
Expand Down
4 changes: 2 additions & 2 deletions src/CImGui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ include("LibCImGui.jl")
using .LibCImGui

const FLT_MAX = igGET_FLT_MAX()
const IMGUI_VERSION = unsafe_string(igGetVersion())
const IMGUI_VERSION = igGetVersion()

include("convert.jl")
include("helper.jl")
include("wrapper.jl")

include("backend/GLFW/GLFWBackend.jl")
Expand Down
12 changes: 0 additions & 12 deletions src/convert.jl

This file was deleted.

47 changes: 47 additions & 0 deletions src/helper.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# helper convertion functions
Base.convert(::Type{ImVec2}, x::NTuple{2}) = ImVec2(x...)
Base.convert(::Type{ImVec4}, x::NTuple{4}) = ImVec4(x...)
Base.convert(::Type{ImVec4}, x::ImU32) = ColorConvertU32ToFloat4(x)
Base.convert(::Type{ImU32}, x::ImVec4) = ColorConvertFloat4ToU32(x)

# put this in CEnum.jl?
using CSyntax.CEnum: Cenum, enum_names, enum_values

Base.:|(a::T, b::Integer) where {T<:Cenum{UInt32}} = UInt32(a) | UInt32(b)
Base.:|(a::Integer, b::T) where {T<:Cenum{UInt32}} = UInt32(b) | UInt32(a)

Base.:&(a::T, b::Integer) where {T<:Cenum{UInt32}} = UInt32(a) & UInt32(b)
Base.:&(a::Integer, b::T) where {T<:Cenum{UInt32}} = UInt32(b) & UInt32(a)

ShowFlags(::Type{T}) where {T<:Cenum} = foreach(x->println(x), zip(enum_names(T), enum_values(T)))
GetFlags(::Type{T}) where {T<:Cenum} = zip(enum_names(T), enum_values(T)) |> collect

# simple unsafe destruction helper
function UnsafeGetPtr(x::Ptr{T}, name::Symbol) where {T}
offset = x
type = T
flag = false
for i = 1:fieldcount(T)
name == fieldname(T, i) || continue
flag = true
type = fieldtype(T, i)
offset += fieldoffset(T, i)
break
end
flag || throw(ArgumentError("$T has no field named $name."))
return Ptr{type}(offset)
end

function Get(x::Ptr{T}, name::Symbol) where {T}
GC.@preserve x begin
value = unsafe_load(UnsafeGetPtr(x, name))
end
return value
end

function Set(x::Ptr{T}, name::Symbol, value::S) where {T,S}
GC.@preserve x value begin
unsafe_store!(UnsafeGetPtr(x, name), value)
end
return value
end
1 change: 0 additions & 1 deletion src/interface.jl

This file was deleted.

Loading

0 comments on commit 5847ae9

Please sign in to comment.