Skip to content

Commit

Permalink
doc / hello_imgui_widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed May 14, 2024
1 parent 60c5593 commit 15e154d
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 3 deletions.
78 changes: 78 additions & 0 deletions src/hello_imgui/doc_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,84 @@ void ShowAppMenu(RunnerParams & runnerParams);
---
# Additional Widgets
## InputTextResizable
```cpp
// `InputTextResizable`: displays a resizable text input widget
//
// The `InputTextResizable` widget allows you to create a text input field that can be resized by the user.
// It supports both single-line and multi-line text input.
// Note: the size of the widget is expressed in em units.
// **Usage example:**
// C++:
// ```cpp
// // Somewhere in the application state
// (static) InputTextData textInput("My text", true, ImVec2(10, 3));
// // In the GUI function
// bool changed = InputTextResizable("Label", &textInput);
// ```
// Python:
// ```python
// # Somewhere in the application state
// text_input = hello_imgui.InputTextData("My text", multiline=True, size_em=ImVec2(10, 3))
// # In the GUI function
// changed = hello_imgui.InputTextResizable("Label", text_input)
// ```
struct InputTextData
{
std::string Text;
bool Multiline = false;
ImVec2 SizeEm = ImVec2(0, 0);
InputTextData(const std::string& text = "", bool multiline = false, ImVec2 size_em = ImVec2(0, 0)) : Text(text), Multiline(multiline), SizeEm(size_em) {}
};
bool InputTextResizable(const char* label, InputTextData* textInput);
// Serialization for InputTextData
// -------------------------------
// to/from dict
using DictTypeInputTextData = std::map<std::string, std::variant<std::string, bool, float>>;
DictTypeInputTextData InputTextDataToDict(const InputTextData& data);
InputTextData InputTextDataFromDict(const DictTypeInputTextData& dict);
// to/from string
std::string InputTextDataToString(const InputTextData& data);
InputTextData InputTextDataFromString(const std::string& str);
```

## WidgetWithResizeHandle

```cpp

// WidgetWithResizeHandle: adds a resize handle to a widget
// Example usage with ImPlot:
// void gui()
// {
// static ImVec2 widget_size(200, 200);
// auto myWidgetFunction = []()
// {
// if (ImPlot::BeginPlot("My Plot", widget_size)) {
// ImPlot::PlotLine("My Line", x.data(), y.data(), 1000);
// ImPlot::EndPlot();
// }
// };
// widget_size = widget_with_resize_handle("plot", myWidgetFunction);
// }
ImVec2 WidgetWithResizeHandle(
const char* id,
VoidFunction widgetGuiFunction,
float handleSizeEm = 1.0f,
std::optional<VoidFunction> onItemResized = std::nullopt,
std::optional<VoidFunction> onItemHovered = std::nullopt
);

```
---
# Handling screens with high DPI
Expand Down
16 changes: 16 additions & 0 deletions src/hello_imgui/doc_api.src.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ See [hello_imgui.h](https://github.com/pthom/hello_imgui/blob/master/src/hello_i
---
# Additional Widgets
## InputTextResizable
```cpp
@import "hello_imgui_widgets.h" {md_id=InputTextResizable}
```

## WidgetWithResizeHandle

```cpp
@import "hello_imgui_widgets.h" {md_id=WidgetWithResizeHandle}
```
---
# Handling screens with high DPI
@import "dpi_aware.h" {md_id=HandlingScreenHighDPI}
4 changes: 4 additions & 0 deletions src/hello_imgui/doc_params.md
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,10 @@ struct FpsIdling
// refresh needs)
float fpsIdle = 9.f;

// `timeActiveAfterLastEvent`: _float, default=3.f_.
// Time in seconds after the last event before the application is considered idling.
float timeActiveAfterLastEvent = 3.f;

// `enableIdling`: _bool, default=true_.
// Disable idling by setting this to false.
// (this can be changed dynamically during execution)
Expand Down
2 changes: 1 addition & 1 deletion src/hello_imgui/hello_imgui_widgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace HelloImGui
// # Somewhere in the application state
// text_input = hello_imgui.InputTextData("My text", multiline=True, size_em=ImVec2(10, 3))
// # In the GUI function
// changed, text_input = hello_imgui.InputTextResizable("Label", text_input)
// changed = hello_imgui.InputTextResizable("Label", text_input)
// ```
struct InputTextData
{
Expand Down
4 changes: 2 additions & 2 deletions src/hello_imgui/impl/hello_imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ namespace HelloImGui
if (dict.find("Multiline") != dict.end())
result.Multiline = std::get<bool>(dict.at("Multiline"));
if (dict.find("SizeEm_x") != dict.end())
result.SizeEm.x = std::get<float>(dict.at("Size_x"));
result.SizeEm.x = std::get<float>(dict.at("SizeEm_x"));
if (dict.find("SizeEm_y") != dict.end())
result.SizeEm.y = std::get<float>(dict.at("Size_y"));
result.SizeEm.y = std::get<float>(dict.at("SizeEm_y"));
return result;
}

Expand Down

0 comments on commit 15e154d

Please sign in to comment.