Skip to content

Commit

Permalink
Add coloured text binding for Lua (#1339)
Browse files Browse the repository at this point in the history
Add binding to ImGui::TextColored.
Closes #1336
  • Loading branch information
chreden authored Feb 2, 2025
1 parent 2a18c1f commit 990c331
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/lua/imgui.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The ImGui library allows plugins to render UI elements.
| TableSetupColumn ||`{ string label, ImGuiTableColumnFlags flags }`||
| TableSetupScrollFreeze ||`{ number cols, number rows }`||
| Text || `{ string text } `| Draw some text. |
| TextColored || `{ string text, [optional] float r, [optional] float g, [optional] float b, [optional] float a }`| Draw colored text. RGB default to 0, A defaults to 1. |

# Enumerations

Expand Down
13 changes: 13 additions & 0 deletions trview.lua.imgui/src/trview.lua.imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ namespace trview
return 0;
}

int text_colored(lua_State* L)
{
auto text = get_string(L, 1, "text");
auto r = get_optional_float(L, 1, "r");
auto g = get_optional_float(L, 1, "g");
auto b = get_optional_float(L, 1, "b");
auto a = get_optional_float(L, 1, "a");
ImGui::TextColored(ImVec4(r.value_or(0), g.value_or(0), b.value_or(0), a.value_or(1)), text.c_str());
return 0;
}

int begin_table(lua_State* L)
{
const auto id = get_string(L, 1, "id");
Expand Down Expand Up @@ -287,6 +298,8 @@ namespace trview
// Text
lua_pushcfunction(L, text);
lua_setfield(L, -2, "Text");
lua_pushcfunction(L, text_colored);
lua_setfield(L, -2, "TextColored");
// Table
lua_pushcfunction(L, begin_table);
lua_setfield(L, -2, "BeginTable");
Expand Down

0 comments on commit 990c331

Please sign in to comment.