diff --git a/README.md b/README.md index ad51dda..568a2ed 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ History: Initially cimgui was developed by Stephan Dilly as hand-written code but lately turned into an auto-generated version by sonoro1234 in order to keep up with imgui more easily (letting the user select the desired branch and commit) Notes: -* currently this wrapper is based on version [1.91.6 of Dear ImGui with internal api] +* currently this wrapper is based on version [1.91.7 of Dear ImGui with internal api] * only functions, structs and enums from imgui.h (an optionally imgui_internal.h) are wrapped. * if you are interested in imgui backends you should look [LuaJIT-ImGui](https://github.com/sonoro1234/LuaJIT-ImGui) project. * All naming is algorithmic except for those names that were coded in cimgui_overloads table (https://github.com/cimgui/cimgui/blob/master/generator/generator.lua#L60). In the official version this table is empty. diff --git a/cimgui.cpp b/cimgui.cpp index f490dcd..fd9bdfb 100644 --- a/cimgui.cpp +++ b/cimgui.cpp @@ -1,5 +1,5 @@ //This file is automatically generated by generator.lua from https://github.com/cimgui/cimgui -//based on imgui.h file version "1.91.6" 19160 from Dear ImGui https://github.com/ocornut/imgui +//based on imgui.h file version "1.91.7" 19170 from Dear ImGui https://github.com/ocornut/imgui //with imgui_internal.h api //with imgui_freetype.h api @@ -4038,6 +4038,10 @@ CIMGUI_API void igCallContextHooks(ImGuiContext* context,ImGuiContextHookType ty { return ImGui::CallContextHooks(context,type); } +CIMGUI_API void igScaleWindowsInViewport(ImGuiViewportP* viewport,float scale) +{ + return ImGui::ScaleWindowsInViewport(viewport,scale); +} CIMGUI_API void igSetWindowViewport(ImGuiWindow* window,ImGuiViewportP* viewport) { return ImGui::SetWindowViewport(window,viewport); @@ -5446,7 +5450,7 @@ CIMGUI_API void ImGuiFreeType_SetAllocatorFunctions(void*(*alloc_func)(size_t sz /////////////////////////////manual written functions -CIMGUI_API void igLogText(CONST char *fmt, ...) +CIMGUI_API void igLogText(const char *fmt, ...) { char buffer[256]; va_list args; @@ -5456,11 +5460,11 @@ CIMGUI_API void igLogText(CONST char *fmt, ...) ImGui::LogText("%s", buffer); } -CIMGUI_API void ImGuiTextBuffer_appendf(struct ImGuiTextBuffer *buffer, const char *fmt, ...) +CIMGUI_API void ImGuiTextBuffer_appendf(ImGuiTextBuffer *self, const char *fmt, ...) { va_list args; va_start(args, fmt); - buffer->appendfv(fmt, args); + self->appendfv(fmt, args); va_end(args); } diff --git a/cimgui.h b/cimgui.h index 224f3b6..0fa2400 100644 --- a/cimgui.h +++ b/cimgui.h @@ -1,5 +1,5 @@ //This file is automatically generated by generator.lua from https://github.com/cimgui/cimgui -//based on imgui.h file version "1.91.6" 19160 from Dear ImGui https://github.com/ocornut/imgui +//based on imgui.h file version "1.91.7" 19170 from Dear ImGui https://github.com/ocornut/imgui //with imgui_internal.h api //with imgui_freetype.h api #ifndef CIMGUI_INCLUDED @@ -85,6 +85,7 @@ typedef struct ImGuiColorMod ImGuiColorMod; typedef struct ImGuiContextHook ImGuiContextHook; typedef struct ImGuiDataVarInfo ImGuiDataVarInfo; typedef struct ImGuiDataTypeInfo ImGuiDataTypeInfo; +typedef struct ImGuiDeactivatedItemData ImGuiDeactivatedItemData; typedef struct ImGuiErrorRecoveryState ImGuiErrorRecoveryState; typedef struct ImGuiGroupData ImGuiGroupData; typedef struct ImGuiInputTextState ImGuiInputTextState; @@ -323,9 +324,10 @@ typedef enum { ImGuiTreeNodeFlags_FramePadding = 1 << 10, ImGuiTreeNodeFlags_SpanAvailWidth = 1 << 11, ImGuiTreeNodeFlags_SpanFullWidth = 1 << 12, - ImGuiTreeNodeFlags_SpanTextWidth = 1 << 13, + ImGuiTreeNodeFlags_SpanLabelWidth = 1 << 13, ImGuiTreeNodeFlags_SpanAllColumns = 1 << 14, - ImGuiTreeNodeFlags_NavLeftJumpsBackHere = 1 << 15, + ImGuiTreeNodeFlags_LabelSpanAllColumns = 1 << 15, + ImGuiTreeNodeFlags_NavLeftJumpsBackHere = 1 << 17, ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog, }ImGuiTreeNodeFlags_; typedef enum { @@ -446,6 +448,7 @@ typedef enum { ImGuiDataType_Float, ImGuiDataType_Double, ImGuiDataType_Bool, + ImGuiDataType_String, ImGuiDataType_COUNT }ImGuiDataType_; typedef enum { @@ -799,6 +802,7 @@ typedef enum { ImGuiSliderFlags_WrapAround = 1 << 8, ImGuiSliderFlags_ClampOnInput = 1 << 9, ImGuiSliderFlags_ClampZeroRange = 1 << 10, + ImGuiSliderFlags_NoSpeedTweaks = 1 << 11, ImGuiSliderFlags_AlwaysClamp = ImGuiSliderFlags_ClampOnInput | ImGuiSliderFlags_ClampZeroRange, ImGuiSliderFlags_InvalidMask_ = 0x7000000F, }ImGuiSliderFlags_; @@ -1500,6 +1504,7 @@ struct ImGuiContext; struct ImGuiContextHook; struct ImGuiDataVarInfo; struct ImGuiDataTypeInfo; +struct ImGuiDeactivatedItemData; struct ImGuiErrorRecoveryState; struct ImGuiGroupData; struct ImGuiInputTextState; @@ -1621,8 +1626,7 @@ struct ImGuiDataTypeInfo const char* ScanFmt; }; typedef enum { - ImGuiDataType_String = ImGuiDataType_COUNT + 1, - ImGuiDataType_Pointer, + ImGuiDataType_Pointer = ImGuiDataType_COUNT + 1, ImGuiDataType_ID, }ImGuiDataTypePrivate_; typedef enum { @@ -1774,7 +1778,7 @@ struct ImGuiGroupData ImVec2 BackupCurrLineSize; float BackupCurrLineTextBaseOffset; ImGuiID BackupActiveIdIsAlive; - bool BackupActiveIdPreviousFrameIsAlive; + bool BackupDeactivatedIdIsAlive; bool BackupHoveredIdIsAlive; bool BackupIsSameLine; bool EmitItem; @@ -1801,8 +1805,10 @@ struct ImGuiInputTextState { ImGuiContext* Ctx; ImStbTexteditState* Stb; + ImGuiInputTextFlags Flags; ImGuiID ID; int TextLen; + const char* TextSrc; ImVector_char TextA; ImVector_char TextToRevertTo; ImVector_char CallbackTextBackup; @@ -1812,8 +1818,7 @@ struct ImGuiInputTextState bool CursorFollow; bool SelectedAllMouseLock; bool Edited; - ImGuiInputTextFlags Flags; - bool ReloadUserBuf; + bool WantReloadUserBuf; int ReloadSelectionStart; int ReloadSelectionEnd; }; @@ -1931,6 +1936,13 @@ struct ImGuiPtrOrIndex void* Ptr; int Index; }; +struct ImGuiDeactivatedItemData +{ + ImGuiID ID; + int ElapseFrame; + bool HasBeenEditedBefore; + bool IsAlive; +}; typedef enum { ImGuiPopupPositionPolicy_Default, ImGuiPopupPositionPolicy_ComboBox, @@ -2464,9 +2476,9 @@ struct ImGuiContext int FrameCount; int FrameCountEnded; int FrameCountRendered; + ImGuiID WithinEndChildID; bool WithinFrameScope; bool WithinFrameScopeWithImplicitWindow; - bool WithinEndChild; bool GcCompactAll; bool TestEngineHookItems; void* TestEngine; @@ -2520,9 +2532,8 @@ struct ImGuiContext ImGuiWindow* ActiveIdWindow; ImGuiInputSource ActiveIdSource; ImGuiID ActiveIdPreviousFrame; - bool ActiveIdPreviousFrameIsAlive; - bool ActiveIdPreviousFrameHasBeenEditedBefore; - ImGuiWindow* ActiveIdPreviousFrameWindow; + ImGuiDeactivatedItemData DeactivatedItemData; + ImGuiDataTypeStorage ActiveIdValueOnActivation; ImGuiID LastActiveId; float LastActiveIdTimer; double LastKeyModsChangeTime; @@ -4271,6 +4282,7 @@ CIMGUI_API void igUpdateMouseMovingWindowEndFrame(void); CIMGUI_API ImGuiID igAddContextHook(ImGuiContext* context,const ImGuiContextHook* hook); CIMGUI_API void igRemoveContextHook(ImGuiContext* context,ImGuiID hook_to_remove); CIMGUI_API void igCallContextHooks(ImGuiContext* context,ImGuiContextHookType type); +CIMGUI_API void igScaleWindowsInViewport(ImGuiViewportP* viewport,float scale); CIMGUI_API void igSetWindowViewport(ImGuiWindow* window,ImGuiViewportP* viewport); CIMGUI_API void igMarkIniSettingsDirty_Nil(void); CIMGUI_API void igMarkIniSettingsDirty_WindowPtr(ImGuiWindow* window); @@ -4629,7 +4641,7 @@ CIMGUI_API void ImGuiFreeType_SetAllocatorFunctions(void*(*alloc_func)(size_t sz //no LogTextV CIMGUI_API void igLogText(const char *fmt, ...); //no appendfV -CIMGUI_API void ImGuiTextBuffer_appendf(struct ImGuiTextBuffer *buffer, const char *fmt, ...); +CIMGUI_API void ImGuiTextBuffer_appendf(ImGuiTextBuffer *self, const char *fmt, ...); //for getting FLT_MAX in bindings CIMGUI_API float igGET_FLT_MAX(void); //for getting FLT_MIN in bindings diff --git a/generator/cimgui_template.cpp b/generator/cimgui_template.cpp index 7d0e31d..586fa85 100644 --- a/generator/cimgui_template.cpp +++ b/generator/cimgui_template.cpp @@ -12,7 +12,7 @@ /////////////////////////////manual written functions -CIMGUI_API void igLogText(CONST char *fmt, ...) +CIMGUI_API void igLogText(const char *fmt, ...) { char buffer[256]; va_list args; @@ -22,11 +22,11 @@ CIMGUI_API void igLogText(CONST char *fmt, ...) ImGui::LogText("%s", buffer); } -CIMGUI_API void ImGuiTextBuffer_appendf(struct ImGuiTextBuffer *buffer, const char *fmt, ...) +CIMGUI_API void ImGuiTextBuffer_appendf(ImGuiTextBuffer *self, const char *fmt, ...) { va_list args; va_start(args, fmt); - buffer->appendfv(fmt, args); + self->appendfv(fmt, args); va_end(args); } diff --git a/generator/cimgui_template.h b/generator/cimgui_template.h index d977cad..d66489d 100644 --- a/generator/cimgui_template.h +++ b/generator/cimgui_template.h @@ -49,7 +49,7 @@ typedef union SDL_Event SDL_Event; //no LogTextV CIMGUI_API void igLogText(const char *fmt, ...); //no appendfV -CIMGUI_API void ImGuiTextBuffer_appendf(struct ImGuiTextBuffer *buffer, const char *fmt, ...); +CIMGUI_API void ImGuiTextBuffer_appendf(ImGuiTextBuffer *self, const char *fmt, ...); //for getting FLT_MAX in bindings CIMGUI_API float igGET_FLT_MAX(void); //for getting FLT_MIN in bindings diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index dcfe615..1aefbc2 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -320,6 +320,9 @@ local function getRE() function_re = "^([^;{}]+%b()[\n%s]*;)%s*", function_re = "^([^;{}=]+%b()[\n%s%w]*;)", --const at the end function_re = "^([^;{}=]+%b()[\n%s%w%(%)_]*;)", --attribute(deprecated) + --we need to skip = as function because of "var = f()" initialization in struct fields + -- but we don want operator== to appear as a var and as we should skip this kind of function solution is: + operator_re = "^([^;{}]+operator[^;{}]+%b()[\n%s%w%(%)_]*;)", struct_re = "^([^;{}]-struct[^;{}]-%b{}[%s%w_%(%)]*;)", enum_re = "^([^;{}]-enum[^;{}]-%b{}[%s%w_%(%)]*;)", union_re = "^([^;{}]-union[^;{}]-%b{}[%s%w_%(%)]*;)", @@ -344,7 +347,7 @@ local function getRE() } local resN = {"comment2_re","comment_re","emptyline_re", - "functypedef_re","functype_re","function_re","functionD_re","typedef_st_re","struct_re","enum_re","union_re","namespace_re","class_re","typedef_re","vardef_re"} + "functypedef_re","functype_re","function_re","functionD_re","operator_re","typedef_st_re","struct_re","enum_re","union_re","namespace_re","class_re","typedef_re","vardef_re"} return res,resN end @@ -600,7 +603,7 @@ local function clean_names_from_signature(self,signat) return result end local function clean_functypedef(line) - local first, args = line:match("(typedef .-%(%*[_%w]+%))%s*(%b())") + local first, args = line:match("(typedef .-%(%*%s*[_%w]+%))%s*(%b())") if not args then print"not getting args in" @@ -1042,7 +1045,39 @@ local function ADDIMSTR_S(FP) end FP.funcdefs = newcdefs end +--this creates defsBystruct in case you need to list by struct container +local function DefsByStruct(FP) + local structs = {} + for fun,defs in pairs(FP.defsT) do + local stname = defs[1].stname + structs[stname] = structs[stname] or {} + table.insert(structs[stname],defs)--fun) + end + return structs +end +local function get_nonPOD(FP) + local defbystruct = DefsByStruct(FP) + --M.prtable(defbystruct) + local nonPOD = {} + for k,defs in pairs(defbystruct) do + if k~="" then + for i, ww in ipairs(defs) do + -- print(k,i,ww) + -- M.prtable(ww) + if not ww[1].ret then --constructor + nonPOD[k] = true + break; + end + end + end + end + FP.structs_and_enums_table.nonPOD = nonPOD + return nonPOD +end local function ADDnonUDT(FP) + local nonPOD = get_nonPOD(FP) + --print"nonPOD" + --M.prtable(nonPOD) local defsT = FP.defsT --local newcdefs = {} for numcdef,t in ipairs(FP.funcdefs) do @@ -1056,10 +1091,17 @@ local function ADDnonUDT(FP) end --if UDT return generate nonUDT version local isUDT = false - for _,udt_ret in ipairs(FP.UDTs) do - if udt_ret == defT.ret then isUDT=true;break end + --isUDT = FP.structs_and_enums_table.structs[defT.ret] and true or false + isUDT = nonPOD[defT.ret] and true or false + --inherited + if (not isUDT) and FP.cimgui_inherited and FP.cimgui_inherited.nonPOD[defT.ret] then + isUDT = true end - --if defT.ret=="ImVec2" or defT.ret=="ImVec4" or defT.ret=="ImColor" then + for _,udt_ret in ipairs(FP.UDTs) do + if udt_ret == defT.ret then isUDT=true; break end + end + + if isUDT then --passing as a pointer arg local defT2 = {} @@ -1425,6 +1467,7 @@ function M.Parser() --save_data("./preparse"..tostring(self):gsub("table: ","")..".c",txt) --]] self.itemsarr = par:parseItemsR2(txt) + --save_data("./itemsarr.lua",ToStr(self.itemsarr)) itemsarr = self.itemsarr end @@ -1471,10 +1514,13 @@ function M.Parser() local predeclare = "" --local iner = strip_end(stru:match("%b{}"):sub(2,-2)) local inistruct = clean_spaces(stru:match("(.-)%b{}")) + --clean final: + inistruct = inistruct:gsub("%s*final%s*:",":") --local stname = stru:match("struct%s*(%S+)%s*%b{}") local stname, derived if inistruct:match":" then stname,derived = inistruct:match"struct%s*([^%s:]+):(.+)" + --print(inistruct,stname,derived) derived = derived:match"(%S+)$" else if itst.re_name == "struct_re" then @@ -1529,12 +1575,14 @@ function M.Parser() --local ttype,template = it.item:match("([^%s,%(%)]+)%s*<(.+)>") local ttype,template,te,code2 = check_template(it2) --it.item:match"([^%s,%(%)]+)%s*<(.+)>" if template then + --print("not doheader",ttype,template,te) if self.typenames[ttype] ~= template then --rule out T (template typename) self.templates[ttype] = self.templates[ttype] or {} self.templates[ttype][template] = te it2=code2 end if doheader then + local templatetypedef = self:gentemplatetypedef(ttype, template,self.templates[ttype][template]) predeclare = predeclare .. templatetypedef end @@ -1590,7 +1638,7 @@ function M.Parser() end elseif it.re_name == "enum_re" then --nop - elseif it.re_name ~= "functionD_re" and it.re_name ~= "function_re" then + elseif it.re_name ~= "functionD_re" and it.re_name ~= "function_re" and it.re_name ~= "operator_re" then print(it.re_name,"not processed clean_struct in",stname,it.item:sub(1,24)) --M.prtable(it) end @@ -1657,6 +1705,7 @@ function M.Parser() it2 = clean_functypedef(it2) else assert(it.re_name == "vardef_re") + it2 = it2:gsub("constexpr","static const") if it2:match"enum" then print("--skip enum forward declaration:",it2) it2 = "" @@ -1771,7 +1820,9 @@ function M.Parser() local ttype,fun = it.item:match"^%s*template%s+<%s*typename%s+([^>]+)%s*>%s*(.+)$" if self.ftemplate_list and self.ftemplate_list[ttype] then for iT,vT in ipairs(self.ftemplate_list[ttype]) do - local funT = fun:gsub(ttype,vT) + local funT = fun:gsub("([< %(])"..ttype,"%1"..vT) + --funT = funT:gsub("sizeof%("..ttype.."%)","sizeof("..vT..")") + --local funT = fun:gsub(ttype,vT) self:parseFunction(stname,{item=funT},namespace,it.locat) end end @@ -1779,7 +1830,9 @@ function M.Parser() self:parseFunction(stname,it,namespace,it.locat) end else + if it.re_name~="operator_re" then print("not processed gen",it.re_name,it.item:sub(1,20)) + end end end @@ -1938,7 +1991,7 @@ function M.Parser() self.typedefs_dict[typedefname] = strip(typedefdef) elseif it.re_name == "functypedef_re" then -- "^\n*%s*(typedef[%w%s%*_]+%([^*]*%*?%s*[%w_]+%s*%)%s*%b()%s*;)" - local key = it.item:match("%(%*([%w_]+)%)%([^%(%)]*%)") + local key = it.item:match("%(%*%s*([%w_]+)%)%s*%([^%(%)]*%)") if key then local linet = it.item linet = linet:gsub("[\n%s]+typedef ","") @@ -1989,7 +2042,7 @@ function M.Parser() end elseif it.re_name == "namespace_re" or it.re_name == "union_re" or it.re_name == "functype_re" then --nop - elseif it.re_name ~= "functionD_re" and it.re_name ~= "function_re" then + elseif it.re_name ~= "functionD_re" and it.re_name ~= "function_re" and it.re_name ~= "operator_re" then print("not processed gen table",it.re_name) end end @@ -2234,6 +2287,7 @@ function M.Parser() return self:gen_template_typedef_auto(ttype,te,newte) end function par:gen_template_typedef_auto(ttype,te,newte) + --M.prtable(self.templated_structs) assert(self.templated_structs[ttype],ttype) local defi = self.templated_structs[ttype] local Targ = strsplit(self.typenames[ttype],",") @@ -2277,7 +2331,111 @@ function M.Parser() end return par end +-- more compact serialization +local function basicSerialize (o) + if type(o) == "number" then + return string.format("%.17g", o) + elseif type(o)=="boolean" then + return tostring(o) + elseif type(o) == "string" then + return string.format("%q", o) + elseif pcall(function() return o.__serialize end) then + return o.__serialize(o) + elseif type(o)=="cdata" then + return cdataSerialize(o) + else + return tostring(o) --"nil" + end +end +-- very readable and now suited for cyclic tables +local kw = {['and'] = true, ['break'] = true, ['do'] = true, ['else'] = true, + ['elseif'] = true, ['end'] = true, ['false'] = true, ['for'] = true, + ['function'] = true, ['goto'] = true, ['if'] = true, ['in'] = true, + ['local'] = true, ['nil'] = true, ['not'] = true, ['or'] = true, + ['repeat'] = true, ['return'] = true, ['then'] = true, ['true'] = true, + ['until'] = true, ['while'] = true} +function tb2st_serialize(t,options) + options = options or {} + local function sorter(a,b) + if type(a)==type(b) then + return a