Skip to content

Commit

Permalink
Initial implementation of basic docking API
Browse files Browse the repository at this point in the history
  • Loading branch information
dri-richard committed May 7, 2024
1 parent 582d725 commit 93058af
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions example/example.script
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function init(self)
self.show_demo_window = false
self.show_close_window = false
self.show_live_data = false
self.dockspace = false

imgui.set_ini_filename()
set_style()
Expand Down Expand Up @@ -112,6 +113,11 @@ local function update_tab1(self)
self.show_demo_window = checked
end

changed, checked = imgui.checkbox("Docking", self.dockspace)
if changed then
self.dockspace = checked
end

imgui.separator()

if imgui.radio_button("Option 1", self.radio == 1) then
Expand Down Expand Up @@ -494,6 +500,12 @@ end
function update(self, dt)
main_menu_bar(self)

if self.dockspace then
local viewport = imgui.get_main_viewport()
local dockspace = imgui.dock_space_over_viewport(viewport)
print()
end

if self.show_demo_window then
imgui.demo()
end
Expand Down
27 changes: 27 additions & 0 deletions imgui/src/extension_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,30 @@ static int imgui_SetScrollHereY(lua_State *L)
return 0;
}

// ----------------------------
// ----- DOCKING --------------
// ----------------------------

static int imgui_DockSpaceOverViewport(lua_State *L)
{
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;

DM_LUA_STACK_CHECK(L, 1);
ImGuiViewport* viewport = (ImGuiViewport*)lua_touserdata(L, 1);
ImGuiID dockspace_id = ImGui::DockSpaceOverViewport(viewport);

lua_pushnumber(L, dockspace_id);
return 1;
}

static int imgui_GetMainViewport(lua_State *L)
{
DM_LUA_STACK_CHECK(L, 1);
void* viewport = (void*)ImGui::GetMainViewport();
lua_pushlightuserdata(L, viewport);
return 1;
}

// ----------------------------
// ----- FONT -----------------
Expand Down Expand Up @@ -2355,6 +2379,9 @@ static const luaL_reg Module_methods[] =
{"get_frame_height", imgui_GetFrameHeight},

{"set_scroll_here_y", imgui_SetScrollHereY},

{"dock_space_over_viewport", imgui_DockSpaceOverViewport},
{"get_main_viewport", imgui_GetMainViewport},
{0, 0}
};

Expand Down

0 comments on commit 93058af

Please sign in to comment.