Skip to content

Commit

Permalink
Added table outer size. Updated example.
Browse files Browse the repository at this point in the history
Fixes #48

Note that you should only call table functions if imgui.begin_table() returns true. See example.
  • Loading branch information
britzl committed Jun 1, 2024
1 parent d5a4849 commit a40e1e9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
47 changes: 24 additions & 23 deletions example/example.script
Original file line number Diff line number Diff line change
Expand Up @@ -160,30 +160,31 @@ local function update_tab1(self)
self.show_close_window = true;
end

imgui.begin_table("table_example", 3)
imgui.table_setup_column("FIRST NAME")
imgui.table_setup_column("LAST NAME")
imgui.table_setup_column("AGE")
imgui.table_headers_row()

imgui.table_next_row()
imgui.table_next_column()
imgui.text("Bilbo")
imgui.table_next_column()
imgui.text("Baggins")
imgui.table_next_column()
imgui.text("129")

imgui.table_next_row()
imgui.table_next_column()
imgui.text("Frodo")
imgui.table_next_column()
imgui.text("Baggins")
imgui.table_next_column()
imgui.text("51")
if imgui.begin_table("table_example", 3) then
imgui.table_setup_column("FIRST NAME")
imgui.table_setup_column("LAST NAME")
imgui.table_setup_column("AGE")
imgui.table_headers_row()

imgui.table_next_row()
imgui.table_next_column()
imgui.text("Bilbo")
imgui.table_next_column()
imgui.text("Baggins")
imgui.table_next_column()
imgui.text("129")

imgui.table_next_row()
imgui.table_next_column()
imgui.text("Frodo")
imgui.table_next_column()
imgui.text("Baggins")
imgui.table_next_column()
imgui.text("51")

imgui.end_table()
end

imgui.end_table()

imgui.separator()

-- Manual wrapping
Expand Down
4 changes: 4 additions & 0 deletions imgui/api/imgui.script_api
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,10 @@
type: number
- name: flags
type: number
- name: outer_size_x
type: number
- name: outer_size_y
type: number

return:
- name: result
Expand Down
9 changes: 8 additions & 1 deletion imgui/src/extension_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,13 @@ static int imgui_BeginTable(lua_State* L)
{
flags = luaL_checkint(L, 3);
}
bool result = ImGui::BeginTable(id, column, flags);
ImVec2 outer_size = ImVec2(0.0f, 0.0f);
if (lua_isnumber(L, 4) && lua_isnumber(L, 5))
{
outer_size.x = luaL_checknumber(L, 4);
outer_size.y = luaL_checknumber(L, 5);
}
bool result = ImGui::BeginTable(id, column, flags, outer_size);
lua_pushboolean(L, result);
return 1;
}
Expand Down Expand Up @@ -2248,6 +2254,7 @@ static const luaL_reg Module_methods[] =
{"table_set_column_index", imgui_TableSetColumnIndex},
{"table_setup_column", imgui_TableSetupColumn},
{"table_headers_row", imgui_TableHeadersRow},
{"table_setup_scroll_freeze", imgui_TableSetupScrollFreeze},

{"begin_popup_context_item", imgui_BeginPopupContextItem},
{"begin_popup", imgui_BeginPopup},
Expand Down

0 comments on commit a40e1e9

Please sign in to comment.