Skip to content

Commit

Permalink
Lua: Add more imgui functions
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Mar 13, 2024
1 parent 9f0109c commit 1a551cc
Showing 1 changed file with 58 additions and 4 deletions.
62 changes: 58 additions & 4 deletions src/mods/bindings/ImGui.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <imgui.h>
#include <imgui_internal.h>
#include <imnodes.h>

#include "../ScriptRunner.hpp"
Expand Down Expand Up @@ -1104,6 +1105,28 @@ float calc_item_width() {
return ImGui::CalcItemWidth();
}

void item_size(sol::object pos, sol::object size, sol::object text_baseline_y) {
if (text_baseline_y.is<float>()) {
ImGui::ItemSize(ImRect{create_imvec2(pos), create_imvec2(size)}, text_baseline_y.as<float>());
} else {
ImGui::ItemSize(ImRect{create_imvec2(pos), create_imvec2(size)});
}
}

bool item_add(const char* label, sol::object pos, sol::object size) {
if (label == nullptr) {
label = "";
}

const auto window = ImGui::GetCurrentWindow();

if (window == nullptr) {
return false;
}

return ImGui::ItemAdd(ImRect{create_imvec2(pos), create_imvec2(size)}, window->GetID(label));
}

void push_style_color(int style_color, sol::object color_obj) {
if (color_obj.is<int>()) {
ImGui::PushStyleColor((ImGuiCol)style_color, (ImU32)color_obj.as<int>());
Expand Down Expand Up @@ -1187,6 +1210,14 @@ const char* get_clipboard() {
return ImGui::GetClipboardText();
}

void progress_bar(float progress, sol::object size, const char* overlay ){
if (overlay == nullptr) {
overlay = "";
}

ImGui::ProgressBar(progress, create_imvec2(size), overlay);
}

bool begin_table(const char* str_id, int column, sol::object flags_obj, sol::object outer_size_obj, sol::object inner_width_obj) {
if (str_id == nullptr) {
str_id = "";
Expand Down Expand Up @@ -1283,12 +1314,24 @@ ImGuiTableSortSpecs* table_get_sort_specs() {
return ImGui::TableGetSortSpecs();
}

void progress_bar(float progress, sol::object size, const char* overlay ){
if (overlay == nullptr) {
overlay = "";
// Window Drawlist
void draw_list_path_clear() {
if (auto dl = ImGui::GetWindowDrawList(); dl != nullptr) {
dl->PathClear();
}
}

ImGui::ProgressBar(progress, create_imvec2(size), overlay);
void draw_list_path_line_to(sol::object pos_obj) {
auto pos = create_imvec2(pos_obj);
if (auto dl = ImGui::GetWindowDrawList(); dl != nullptr) {
dl->PathLineTo(pos);
}
}

void draw_list_path_stroke(ImU32 color, bool closed, float thickness) {
if (auto dl = ImGui::GetWindowDrawList(); dl != nullptr) {
dl->PathStroke(color, closed, thickness);
}
}
} // namespace api::imgui

Expand Down Expand Up @@ -1972,10 +2015,15 @@ void bindings::open_imgui(ScriptState* s) {
imgui["end_menu"] = api::imgui::end_menu;
imgui["menu_item"] = api::imgui::menu_item;
imgui["get_display_size"] = api::imgui::get_display_size;

// Item
imgui["push_item_width"] = api::imgui::push_item_width;
imgui["pop_item_width"] = api::imgui::pop_item_width;
imgui["set_next_item_width"] = api::imgui::set_next_item_width;
imgui["calc_item_width"] = api::imgui::calc_item_width;
imgui["item_add"] = api::imgui::item_add;
imgui["item_size"] = api::imgui::item_size;

imgui["push_style_color"] = api::imgui::push_style_color;
imgui["pop_style_color"] = api::imgui::pop_style_color;
imgui["push_style_var"] = api::imgui::push_style_var;
Expand All @@ -1990,6 +2038,12 @@ void bindings::open_imgui(ScriptState* s) {
imgui["get_clipboard"] = api::imgui::get_clipboard;
imgui["progress_bar"] = api::imgui::progress_bar;

// Draw list
imgui["draw_list_path_clear"] = api::imgui::draw_list_path_clear;
imgui["draw_list_path_line_to"] = api::imgui::draw_list_path_line_to;
imgui["draw_list_path_stroke"] = api::imgui::draw_list_path_stroke;


// TABLE APIS
imgui["begin_table"] = api::imgui::begin_table;
imgui["end_table"] = api::imgui::end_table;
Expand Down

0 comments on commit 1a551cc

Please sign in to comment.