Skip to content

Commit

Permalink
Added some more functions to Gui module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinnegatamante committed Apr 3, 2021
1 parent ed89c26 commit da831e8
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
48 changes: 48 additions & 0 deletions doc/luaGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,52 @@ class Gui {
* @return The updated selected element.
*/
int drawComboBox(string label, int index, table elements);

/**
* Draw a progressbar.
* \ingroup Gui
*
* @par Usage example:
* @code
* Gui.drawProgressbar(0.25, 200, 0)
* end
* @endcode
*
* @param fraction - Progress value to show in 0.0 - 1.0 range.
* @param w - Width of the element in pixels.
* @param h - Height of the element in pixels.
*/
void drawProgressbar(number fraction, number w, number h);

/**
* Draw a progressbar.
* \ingroup Gui
*
* @par Usage example:
* @code
* w, h = Gui.getTextSize("Hello World")
* end
* @endcode
*
* @param text - The text to calculate the size about.
*
* @return The size of the text in pixels.
*/
number[] getTextSize(string text);

/**
* Set next widget position.
* \ingroup Gui
*
* @par Usage example:
* @code
* Gui.setWidgetPos(300, 200)
* Gui.drawText("Hello World")
* end
* @endcode
*
* @param x - X coordinate in pixels.
* @param y - Y coordinate in pixels.
*/
void setWidgetPos(number x, number y);
}
44 changes: 44 additions & 0 deletions source/luaGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,47 @@ static int lua_combobox(lua_State *L) {
return 1;
}

static int lua_cursorpos(lua_State *L) {
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
if (argc != 2) return luaL_error(L, "wrong number of arguments");
#endif
float x = luaL_checknumber(L, 1);
float y = luaL_checknumber(L, 2);
ImGui::SetCursorPos(ImVec2(x, y));
return 0;
}

static int lua_textsize(lua_State *L) {
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
if (argc != 1) return luaL_error(L, "wrong number of arguments");
#endif
char *label = luaL_checkstring(L, 1);
ImVec2 size = ImGui::CalcTextSize(label);
lua_pushnumber(L, size.x);
lua_pushnumber(L, size.y);
return 2;
}

static int lua_progressbar(lua_State *L) {
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
if (argc != 1 && argc != 3) return luaL_error(L, "wrong number of arguments");
#endif
float status = luaL_checknumber(L, 1);
ImVec2 size;
if (argc == 1) {
size = ImVec2(-1, 0);
} else {
float w = luaL_checknumber(L, 2);
float h = luaL_checknumber(L, 3);
size = ImVec2(w, h);
}
ImGui::ProgressBar(status, size);
return 0;
}

//Register our Gui Functions
static const luaL_Reg Gui_functions[] = {
{"init", lua_init},
Expand Down Expand Up @@ -554,6 +595,9 @@ static const luaL_Reg Gui_functions[] = {
{"drawTooltip", lua_tooltip},
{"setInputMode", lua_config},
{"drawComboBox", lua_combobox},
{"setWidgetPos", lua_cursorpos},
{"getTextSize", lua_textsize},
{"drawProgressbar", lua_progressbar},
{0, 0}
};

Expand Down

0 comments on commit da831e8

Please sign in to comment.