Skip to content

Commit

Permalink
lua: expose ImGui.Image() function
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-lysiuk committed Oct 21, 2024
1 parent b51e740 commit b284f50
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Quake/ls_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ static ImVec2 ToImVec2(const LS_Vector2& value)
return ImVec2(value[0], value[1]);
}

static ImVec4 ToImVec4(const LS_Vector4& value)
{
return ImVec4(value[0], value[1], value[2], value[3]);
}


struct LS_TextBuffer
{
Expand Down
17 changes: 16 additions & 1 deletion Quake/ls_imgui_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,21 @@ static int LS_global_imgui_Checkbox(lua_State* state)
return 2;
}

static int LS_global_imgui_Image(lua_State* state)
{
LS_EnsureFrameScope(state);

const ImTextureID texID = luaL_checkinteger(state, 1);
const LS_Vector2 size = luaL_opt(state, LS_GetVectorValue<2>, 2, LS_Vector2::Zero());
const LS_Vector2 uv0 = luaL_opt(state, LS_GetVectorValue<2>, 3, LS_Vector2::Zero());
const LS_Vector2 uv1 = luaL_opt(state, LS_GetVectorValue<2>, 4, LS_Vector2::One());
const LS_Vector4 tintColor = luaL_opt(state, LS_GetVectorValue<4>, 5, LS_Vector4::One());
const LS_Vector4 borderColor = luaL_opt(state, LS_GetVectorValue<4>, 6, LS_Vector4::Zero());

ImGui::Image(texID, ToImVec2(size), ToImVec2(uv0), ToImVec2(uv1), ToImVec4(tintColor), ToImVec4(borderColor));
return 0;
}

static int LS_global_imgui_BeginCombo(lua_State* state)
{
LS_EnsureFrameScope(state);
Expand Down Expand Up @@ -1037,7 +1052,7 @@ static void LS_InitImGuiFuncs(lua_State* state)
// * TextLinkOpenURL

// Widgets: Images
// * Image
{ "Image", LS_global_imgui_Image },
// * ImageButton

// Widgets: Combo Box
Expand Down

0 comments on commit b284f50

Please sign in to comment.