NcEngine
ImGuiUtility.h File Reference
#include "ncengine/type/EngineTypes.h"
#include "ncengine/ui/ImGuiConversion.h"
#include "imgui.h"
#include "ncmath/Vector.h"
#include "ncmath/Geometry.h"
#include <algorithm>
#include <functional>
#include <numbers>
#include <span>
#include <string>
#include <string_view>

Go to the source code of this file.

Classes

struct  nc::ui::Property< Getter, Setter >
 Simple getter/setter-based property wrapper. More...
 
struct  nc::ui::ImGuiId
 RAII wrapper for scoped uids. More...
 
struct  nc::ui::Indent
 RAII wrapper for scoped indentation. More...
 
struct  nc::ui::StyleColor
 RAII wrapper for scoped style color. More...
 
struct  nc::ui::ItemWidth
 RAII wrapper for scoped item width. More...
 
struct  nc::ui::DisableIf
 RAII wrapper for conditionally disabling widgets within a scope. More...
 
struct  nc::ui::internal::InputTextCallbackUserData
 

Macros

#define IMGUI_SCOPE(Property, ...)   auto IMGUI_SCOPE_UNIQUE_NAME(imguiProp, __LINE__) = Property(__VA_ARGS__)
 Create a variable to hold a scoped property.
 

Functions

template<class F >
void nc::ui::Window (const char *label, F &&drawContents)
 Create a top-level window.
 
template<class F >
void nc::ui::Window (const char *label, ImGuiWindowFlags flags, F &&drawContents)
 Create a top-level window.
 
template<class F >
void nc::ui::ChildWindow (const char *label, F &&drawContents)
 Create a child window.
 
auto nc::ui::IsWindowBackgroundClicked () -> bool
 Check if the current window background is clicked on.
 
auto nc::ui::InputInt (int &value, const char *label, int step=1) -> bool
 Input field UI widget for int.
 
auto nc::ui::InputU8 (uint8_t &value, const char *label) -> bool
 Input field UI widget for uint8_t.
 
auto nc::ui::InputU16 (uint16_t &value, const char *label) -> bool
 Input field UI widget for uint16_t.
 
auto nc::ui::InputU32 (uint32_t &value, const char *label) -> bool
 Input field UI widget for uint32_t.
 
auto nc::ui::InputU64 (uint64_t &value, const char *label) -> bool
 Input field UI widget for uint64_t.
 
auto nc::ui::DragFloat (float &value, const char *label, float speed=1.0f, float min=0.0f, float max=1000.0f) -> bool
 Drag slider UI widget for float.
 
auto nc::ui::Checkbox (bool &value, const char *name) -> bool
 Checkbox UI widget for bool.
 
auto nc::ui::InputVector3 (Vector3 &value, const char *label, float speed=1.0f, float min=0.0f, float max=100.0f) -> bool
 Vector3 UI widget with three float drag sliders.
 
auto nc::ui::InputPosition (Vector3 &value, const char *label) -> bool
 Vector3 UI widget constrained for position inputs.
 
auto nc::ui::InputAngles (Vector3 &value, const char *label) -> bool
 Vector3 UI widget constrained for angular (radians) inputs.
 
auto nc::ui::InputScale (Vector3 &value, const char *label, float min=g_minScale, float max=g_maxScale) -> bool
 Vector3 UI widget constrained for scale inputs.
 
auto nc::ui::InputAxis (Vector3 &value, const char *label, float min=-1.0f, float max=1.0f) -> bool
 Vector3 UI widget constrained for normalized axis inputs.
 
auto nc::ui::InputReferenceFrame (Vector3 &basis, Vector3 &normal, const char *basisLabel, const char *normalLabel) -> bool
 Vector3 UI widget constrained for two orthonormal axis inputs.
 
auto nc::ui::InputColor3 (Vector3 &value, const char *label) -> bool
 RGB color picker UI widget.
 
auto nc::ui::InputColor4 (Vector4 &value, const char *label) -> bool
 RGBA color picker UI widget.
 
auto nc::ui::Combobox (std::string &value, const char *label, std::span< const std::string_view > items)
 Combobox UI widget.
 
auto nc::ui::FilteredCombobox (std::string &value, const char *label, std::span< const std::string_view > items, auto &&disableIf)
 Combobox UI widget that allows disabling selection of entries.
 
auto nc::ui::InputText (std::string &value, const char *label) -> bool
 Text input UI widget.
 
auto nc::ui::SelectableWidget (bool selected, const ImVec2 &size, auto &&widget) -> bool
 Wrap a widget with a selectable - allows for things like list box of input widgets.
 
auto nc::ui::PropertyWidget (const auto &property, auto &instance, auto &&widget, auto &&... args) -> bool
 Invoke a widget function with a Property and object instance. More...
 
template<class T >
void nc::ui::DragAndDropSource (T *item)
 Introduce a drag and drop source with item as its payload.
 
template<class T , std::invocable< T * > F>
void nc::ui::DragAndDropTarget (F &&func)
 Introduce a drag and drop target that can accept a payload of type T*.
 
void nc::ui::SameLineSpaced ()
 UI layout helper for spacing.
 
void nc::ui::SameLineRightAligned (float itemWidth)
 UI layout helper for right aligning an item on the same line as the previous item.
 
void nc::ui::SeparatorSpaced ()
 UI layout helper for separator.
 
auto nc::ui::IsCapturingKeyboard () -> bool
 Check if the UI is currently using keyboard events. More...
 
auto nc::ui::IsCapturingMouse () -> bool
 Check if the UI is currently using mouse events. More...
 
auto nc::ui::InputU32 (unsigned &value, const char *label) -> bool
 
auto nc::ui::InputColor (Vector3 &value, const char *label) -> bool
 
auto nc::ui::internal::InputTextCallback (ImGuiInputTextCallbackData *data) -> int
 

Variables

constexpr auto nc::ui::g_defaultItemWidth = 50.0f
 
constexpr auto nc::ui::g_maxPos = 5000.0f
 
constexpr auto nc::ui::g_minPos = -g_maxPos
 
constexpr auto nc::ui::g_maxAngle = std::numbers::pi_v<float> * 2.0f
 
constexpr auto nc::ui::g_minAngle = -g_maxAngle
 
constexpr auto nc::ui::g_minScale = 0.1f
 
constexpr auto nc::ui::g_maxScale = 1000.0f
 

Detailed Description

Note
Unless otherwise noted, all functions in this file must only be called during UI rendering. Calls should be made only from within IUI::Draw() implementations or from ComponentHandler<T>::drawUI callbacks.

Function Documentation

◆ IsCapturingKeyboard()

auto nc::ui::IsCapturingKeyboard ( ) -> bool
inline

Check if the UI is currently using keyboard events.

Note
May be called at any time.

◆ IsCapturingMouse()

auto nc::ui::IsCapturingMouse ( ) -> bool
inline

Check if the UI is currently using mouse events.

Note
May be called at any time.

◆ PropertyWidget()

auto nc::ui::PropertyWidget ( const auto &  property,
auto &  instance,
auto &&  widget,
auto &&...  args 
) -> bool

Invoke a widget function with a Property and object instance.

Parameters
propertyA Property<G, S> instance to be drawn.
instanceAn object instance to query the property from.
widgetThe widget function to call.
argsArguments to widget, excluding initial value and name args.
Returns
A bool indicating whether values were modified through the widget.

Invoke a widget function with a Property instead of a direct value. property supplies both a value and name for widget, so args should only contain any additional arguments required by widget. On write, property.set is called with the updated value.