diff --git a/src/hello_imgui/doc_api.md b/src/hello_imgui/doc_api.md index 75b4470f..698799db 100644 --- a/src/hello_imgui/doc_api.md +++ b/src/hello_imgui/doc_api.md @@ -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>; + 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 onItemResized = std::nullopt, + std::optional onItemHovered = std::nullopt + ); + +``` + +--- + # Handling screens with high DPI diff --git a/src/hello_imgui/doc_api.src.md b/src/hello_imgui/doc_api.src.md index df8fd9ba..08c5bec8 100644 --- a/src/hello_imgui/doc_api.src.md +++ b/src/hello_imgui/doc_api.src.md @@ -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} diff --git a/src/hello_imgui/doc_params.md b/src/hello_imgui/doc_params.md index 86b0c10d..0188354d 100644 --- a/src/hello_imgui/doc_params.md +++ b/src/hello_imgui/doc_params.md @@ -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) diff --git a/src/hello_imgui/hello_imgui_widgets.h b/src/hello_imgui/hello_imgui_widgets.h index d95f5a1c..9e37ff78 100644 --- a/src/hello_imgui/hello_imgui_widgets.h +++ b/src/hello_imgui/hello_imgui_widgets.h @@ -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 { diff --git a/src/hello_imgui/impl/hello_imgui_widgets.cpp b/src/hello_imgui/impl/hello_imgui_widgets.cpp index 55c91f09..d49c1472 100644 --- a/src/hello_imgui/impl/hello_imgui_widgets.cpp +++ b/src/hello_imgui/impl/hello_imgui_widgets.cpp @@ -203,9 +203,9 @@ namespace HelloImGui if (dict.find("Multiline") != dict.end()) result.Multiline = std::get(dict.at("Multiline")); if (dict.find("SizeEm_x") != dict.end()) - result.SizeEm.x = std::get(dict.at("Size_x")); + result.SizeEm.x = std::get(dict.at("SizeEm_x")); if (dict.find("SizeEm_y") != dict.end()) - result.SizeEm.y = std::get(dict.at("Size_y")); + result.SizeEm.y = std::get(dict.at("SizeEm_y")); return result; }