Skip to content

Commit

Permalink
add missing ImGui WASM APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Mar 28, 2024
1 parent cf5d6f2 commit ceaaa0e
Show file tree
Hide file tree
Showing 8 changed files with 1,434 additions and 48 deletions.
41 changes: 41 additions & 0 deletions Source/GUI/ImGuiBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1468,4 +1468,45 @@ void ScrollWhenDraggingOnVoid() {
}
}

bool Checkbox(String label, CallStack* stack) {
bool v = std::get<bool>(stack->pop());
bool changed = ImGui::Checkbox(label.c_str(), &v);
stack->push(v);
return changed;
}

bool RadioButton(String label, CallStack* stack, int v_button) {
int v = s_cast<int>(std::get<int64_t>(stack->pop()));
bool changed = ImGui::RadioButton(label.c_str(), &v, v_button);
stack->push(s_cast<int64_t>(v));
return changed;
}

void PlotLines(String label, const std::vector<float>& values, int values_offset, String overlay_text, float scale_min, float scale_max, Vec2 graph_size) {
ImGui::PlotLines(label.c_str(), values.data(), s_cast<int>(values.size()), values_offset, overlay_text.c_str(), scale_min, scale_max, graph_size);
}

void PlotHistogram(String label, const std::vector<float>& values, int values_offset, String overlay_text, float scale_min, float scale_max, Vec2 graph_size) {
ImGui::PlotHistogram(label.c_str(), values.data(), s_cast<int>(values.size()), values_offset, overlay_text.c_str(), scale_min, scale_max, graph_size);
}

bool ListBox(String label, CallStack* stack, const std::vector<std::string>& items, int height_in_items) {
std::vector<const char*> cItems;
cItems.reserve(items.size());
for (const auto& item : items) {
cItems.push_back(item.c_str());
}
int current_item = s_cast<int>(std::get<int64_t>(stack->pop()));
bool changed = ImGui::ListBox(label.c_str(), &current_item, cItems.data(), s_cast<int>(cItems.size()), height_in_items);
stack->push(s_cast<int64_t>(current_item));
return changed;
}

bool SliderAngle(String label, CallStack* stack, float v_degrees_min, float v_degrees_max) {
float v_rad = s_cast<float>(std::get<double>(stack->pop()));
bool changed = ImGui::SliderAngle(label.c_str(), &v_rad, v_degrees_min, v_degrees_max);
stack->push(s_cast<double>(v_rad));
return changed;
}

NS_END(ImGui::Binding)
30 changes: 30 additions & 0 deletions Source/GUI/ImGuiBinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -708,4 +708,34 @@ void SetStyleColor(String name, Color color);

void ScrollWhenDraggingOnVoid();

inline void SetWindowFocus(String name) { ImGui::SetWindowFocus(name.c_str()); }
inline void SeparatorText(String text) { ImGui::SeparatorText(text.c_str()); }
inline void TableHeader(String label) { ImGui::TableHeader(label.c_str()); }
inline void PushID(String str_id) { ImGui::PushID(str_id.c_str()); }
inline uint32_t GetID(String str_id) { return ImGui::GetID(str_id.c_str()); }
inline bool Button(String label, Vec2 size) { return ImGui::Button(label.c_str(), size); };
inline bool SmallButton(String label) { return ImGui::SmallButton(label.c_str()); }
inline bool InvisibleButton(String str_id, Vec2 size) { return ImGui::InvisibleButton(str_id.c_str(), size); }

bool Checkbox(String label, CallStack* stack);
bool RadioButton(String label, CallStack* stack, int v_button);

void PlotLines(String label, const std::vector<float>& values, int values_offset = 0, String overlay_text = nullptr, float scale_min = FLT_MIN, float scale_max = FLT_MAX, Vec2 graph_size = Vec2::zero);

void PlotHistogram(String label, const std::vector<float>& values, int values_offset = 0, String overlay_text = nullptr, float scale_min = FLT_MIN, float scale_max = FLT_MAX, Vec2 graph_size = Vec2::zero);

inline void ProgressBar(float fraction, Vec2 size_arg = Vec2{-1, 0}, String overlay = nullptr) { ImGui::ProgressBar(fraction, size_arg, overlay.c_str()); }

bool ListBox(String label, CallStack* stack, const std::vector<std::string>& items, int height_in_items = -1);

bool SliderAngle(String label, CallStack* stack, float v_degrees_min, float v_degrees_max);

inline void TreePush(String str_id) { ImGui::TreePush(str_id.c_str()); }
inline bool BeginListBox(String label, Vec2 size) { return ImGui::BeginListBox(label.c_str(), size); }
inline void Value(String prefix, bool b) { ImGui::Value(prefix.c_str(), b); }
inline bool BeginMenu(String label, bool enabled) { return ImGui::BeginMenu(label.c_str(), enabled); };
inline bool MenuItem(String label, String shortcut, bool selected, bool enabled) { return ImGui::MenuItem(label.c_str(), shortcut.c_str(), selected, enabled); }
inline void OpenPopup(String str_id) { ImGui::OpenPopup(str_id.c_str()); }
inline bool BeginPopup(String str_id) { return ImGui::BeginPopup(str_id.c_str()); }

NS_END(ImGui::Binding)
Loading

0 comments on commit ceaaa0e

Please sign in to comment.