mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
Drags, Sliders: Added ImGuiDragFlags_NoInput/ImGuiSliderFlags_NoInput to disable turning widget into a text input with CTRL+Click or Nav Enter.
This commit is contained in:
parent
8018623c5b
commit
f75b29e7be
@ -78,6 +78,8 @@ Other Changes:
|
|||||||
clamping value when using CTRL+Click to type in a value manually. (#1829, #3209, #946, #413).
|
clamping value when using CTRL+Click to type in a value manually. (#1829, #3209, #946, #413).
|
||||||
- Drag, Slider: Added ImGuiDragFlags_NoRoundToFormat/ImGuiSliderFlags_NoRoundToFormat flags
|
- Drag, Slider: Added ImGuiDragFlags_NoRoundToFormat/ImGuiSliderFlags_NoRoundToFormat flags
|
||||||
to disable rounding underlying value to match precision of the display format string. (#642)
|
to disable rounding underlying value to match precision of the display format string. (#642)
|
||||||
|
- Drag, Slider: Added ImGuiDragFlags_NoInput/ImGuiSliderFlags_NoInput to disable turning
|
||||||
|
widget into a text input with CTRL+Click or Nav Enter.
|
||||||
- DragFloatRange2, DragIntRange2: Fixed an issue allowing to drag out of bounds when both
|
- DragFloatRange2, DragIntRange2: Fixed an issue allowing to drag out of bounds when both
|
||||||
min and max value are on the same value. (#1441)
|
min and max value are on the same value. (#1441)
|
||||||
- InputText, ImDrawList: Fixed assert triggering when drawing single line of text with more
|
- InputText, ImDrawList: Fixed assert triggering when drawing single line of text with more
|
||||||
|
10
imgui.h
10
imgui.h
@ -1296,8 +1296,9 @@ enum ImGuiDragFlags_
|
|||||||
ImGuiDragFlags_None = 0,
|
ImGuiDragFlags_None = 0,
|
||||||
ImGuiDragFlags_InvalidMask_ = 0x7000000F, // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast to this enum, and will trigger an assert if needed.
|
ImGuiDragFlags_InvalidMask_ = 0x7000000F, // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast to this enum, and will trigger an assert if needed.
|
||||||
ImGuiDragFlags_ClampOnInput = 1 << 4, // Clamp value to min/max bounds (if any) when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds.
|
ImGuiDragFlags_ClampOnInput = 1 << 4, // Clamp value to min/max bounds (if any) when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds.
|
||||||
ImGuiDragFlags_Logarithmic = 1 << 5, // Make the widget logarithmic (linear otherwise)
|
ImGuiDragFlags_Logarithmic = 1 << 5, // Make the widget logarithmic (linear otherwise). Consider using ImGuiDragFlags_NoRoundToFormat with this if using a format-string with small amount of digits.
|
||||||
ImGuiDragFlags_NoRoundToFormat = 1 << 6 // Disable rounding underlying value to match precision of the display format string (e.g. %.3f values are rounded to those 3 digits)
|
ImGuiDragFlags_NoRoundToFormat = 1 << 6, // Disable rounding underlying value to match precision of the display format string (e.g. %.3f values are rounded to those 3 digits)
|
||||||
|
ImGuiDragFlags_NoInput = 1 << 7 // Disable CTRL+Click or Enter key allowing to input text directly into the widget
|
||||||
};
|
};
|
||||||
|
|
||||||
// Flags for SliderFloat(), SliderInt() etc.
|
// Flags for SliderFloat(), SliderInt() etc.
|
||||||
@ -1306,8 +1307,9 @@ enum ImGuiSliderFlags_
|
|||||||
ImGuiSliderFlags_None = 0,
|
ImGuiSliderFlags_None = 0,
|
||||||
ImGuiSliderFlags_InvalidMask_ = 0x7000000F, // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast to this enum, and will trigger an assert if needed.
|
ImGuiSliderFlags_InvalidMask_ = 0x7000000F, // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast to this enum, and will trigger an assert if needed.
|
||||||
ImGuiSliderFlags_ClampOnInput = 1 << 4, // Clamp value to min/max bounds when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds.
|
ImGuiSliderFlags_ClampOnInput = 1 << 4, // Clamp value to min/max bounds when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds.
|
||||||
ImGuiSliderFlags_Logarithmic = 1 << 5, // Make the widget logarithmic (linear otherwise)
|
ImGuiSliderFlags_Logarithmic = 1 << 5, // Make the widget logarithmic (linear otherwise). Consider using ImGuiSliderFlags_NoRoundToFormat with this if using a format-string with small amount of digits.
|
||||||
ImGuiSliderFlags_NoRoundToFormat = 1 << 6 // Disable rounding underlying value to match precision of the display format string (e.g. %.3f values are rounded to those 3 digits)
|
ImGuiSliderFlags_NoRoundToFormat = 1 << 6, // Disable rounding underlying value to match precision of the display format string (e.g. %.3f values are rounded to those 3 digits)
|
||||||
|
ImGuiSliderFlags_NoInput = 1 << 7 // Disable CTRL+Click or Enter key allowing to input text directly into the widget
|
||||||
};
|
};
|
||||||
|
|
||||||
// Identify a mouse button.
|
// Identify a mouse button.
|
||||||
|
@ -1498,6 +1498,8 @@ static void ShowDemoWindowWidgets()
|
|||||||
ImGui::SameLine(); HelpMarker("Enable logarithmic editing (more precision for small values).");
|
ImGui::SameLine(); HelpMarker("Enable logarithmic editing (more precision for small values).");
|
||||||
ImGui::CheckboxFlags("ImGuiDragFlags_NoRoundToFormat", (unsigned int*)&drag_flags, ImGuiDragFlags_NoRoundToFormat);
|
ImGui::CheckboxFlags("ImGuiDragFlags_NoRoundToFormat", (unsigned int*)&drag_flags, ImGuiDragFlags_NoRoundToFormat);
|
||||||
ImGui::SameLine(); HelpMarker("Disable rounding underlying value to match precision of the format string (e.g. %.3f values are rounded to those 3 digits).");
|
ImGui::SameLine(); HelpMarker("Disable rounding underlying value to match precision of the format string (e.g. %.3f values are rounded to those 3 digits).");
|
||||||
|
ImGui::CheckboxFlags("ImGuiDragFlags_NoInput", (unsigned int*)&drag_flags, ImGuiDragFlags_NoInput);
|
||||||
|
ImGui::SameLine(); HelpMarker("Disable CTRL+Click or Enter key allowing to input text directly into the widget.");
|
||||||
|
|
||||||
static float drag_f = 0.5f;
|
static float drag_f = 0.5f;
|
||||||
static int drag_i = 50;
|
static int drag_i = 50;
|
||||||
@ -1516,6 +1518,8 @@ static void ShowDemoWindowWidgets()
|
|||||||
ImGui::SameLine(); HelpMarker("Enable logarithmic editing (more precision for small values).");
|
ImGui::SameLine(); HelpMarker("Enable logarithmic editing (more precision for small values).");
|
||||||
ImGui::CheckboxFlags("ImGuiSliderFlags_NoRoundToFormat", (unsigned int*)&slider_flags, ImGuiSliderFlags_NoRoundToFormat);
|
ImGui::CheckboxFlags("ImGuiSliderFlags_NoRoundToFormat", (unsigned int*)&slider_flags, ImGuiSliderFlags_NoRoundToFormat);
|
||||||
ImGui::SameLine(); HelpMarker("Disable rounding underlying value to match precision of the format string (e.g. %.3f values are rounded to those 3 digits).");
|
ImGui::SameLine(); HelpMarker("Disable rounding underlying value to match precision of the format string (e.g. %.3f values are rounded to those 3 digits).");
|
||||||
|
ImGui::CheckboxFlags("ImGuiSliderFlags_NoInput", (unsigned int*)&slider_flags, ImGuiSliderFlags_NoInput);
|
||||||
|
ImGui::SameLine(); HelpMarker("Disable CTRL+Click or Enter key allowing to input text directly into the widget.");
|
||||||
|
|
||||||
static float slider_f = 0.5f;
|
static float slider_f = 0.5f;
|
||||||
static int slider_i = 50;
|
static int slider_i = 50;
|
||||||
|
@ -2179,10 +2179,11 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data,
|
|||||||
|
|
||||||
// Tabbing or CTRL-clicking on Drag turns it into an input box
|
// Tabbing or CTRL-clicking on Drag turns it into an input box
|
||||||
const bool hovered = ItemHoverable(frame_bb, id);
|
const bool hovered = ItemHoverable(frame_bb, id);
|
||||||
bool temp_input_is_active = TempInputIsActive(id);
|
const bool temp_input_allowed = (flags & ImGuiDragFlags_NoInput) == 0;
|
||||||
|
bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id);
|
||||||
if (!temp_input_is_active)
|
if (!temp_input_is_active)
|
||||||
{
|
{
|
||||||
const bool focus_requested = FocusableItemRegister(window, id);
|
const bool focus_requested = temp_input_allowed && FocusableItemRegister(window, id);
|
||||||
const bool clicked = (hovered && g.IO.MouseClicked[0]);
|
const bool clicked = (hovered && g.IO.MouseClicked[0]);
|
||||||
const bool double_clicked = (hovered && g.IO.MouseDoubleClicked[0]);
|
const bool double_clicked = (hovered && g.IO.MouseDoubleClicked[0]);
|
||||||
if (focus_requested || clicked || double_clicked || g.NavActivateId == id || g.NavInputId == id)
|
if (focus_requested || clicked || double_clicked || g.NavActivateId == id || g.NavInputId == id)
|
||||||
@ -2191,7 +2192,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data,
|
|||||||
SetFocusID(id, window);
|
SetFocusID(id, window);
|
||||||
FocusWindow(window);
|
FocusWindow(window);
|
||||||
g.ActiveIdUsingNavDirMask = (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right);
|
g.ActiveIdUsingNavDirMask = (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right);
|
||||||
if (focus_requested || (clicked && g.IO.KeyCtrl) || double_clicked || g.NavInputId == id)
|
if (temp_input_allowed && (focus_requested || (clicked && g.IO.KeyCtrl) || double_clicked || g.NavInputId == id))
|
||||||
{
|
{
|
||||||
temp_input_is_active = true;
|
temp_input_is_active = true;
|
||||||
FocusableItemUnregister(window);
|
FocusableItemUnregister(window);
|
||||||
@ -2740,10 +2741,11 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_dat
|
|||||||
|
|
||||||
// Tabbing or CTRL-clicking on Slider turns it into an input box
|
// Tabbing or CTRL-clicking on Slider turns it into an input box
|
||||||
const bool hovered = ItemHoverable(frame_bb, id);
|
const bool hovered = ItemHoverable(frame_bb, id);
|
||||||
bool temp_input_is_active = TempInputIsActive(id);
|
const bool temp_input_allowed = (flags & ImGuiSliderFlags_NoInput) == 0;
|
||||||
|
bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id);
|
||||||
if (!temp_input_is_active)
|
if (!temp_input_is_active)
|
||||||
{
|
{
|
||||||
const bool focus_requested = FocusableItemRegister(window, id);
|
const bool focus_requested = temp_input_allowed && FocusableItemRegister(window, id);
|
||||||
const bool clicked = (hovered && g.IO.MouseClicked[0]);
|
const bool clicked = (hovered && g.IO.MouseClicked[0]);
|
||||||
if (focus_requested || clicked || g.NavActivateId == id || g.NavInputId == id)
|
if (focus_requested || clicked || g.NavActivateId == id || g.NavInputId == id)
|
||||||
{
|
{
|
||||||
@ -2751,7 +2753,7 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_dat
|
|||||||
SetFocusID(id, window);
|
SetFocusID(id, window);
|
||||||
FocusWindow(window);
|
FocusWindow(window);
|
||||||
g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right);
|
g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right);
|
||||||
if (focus_requested || (clicked && g.IO.KeyCtrl) || g.NavInputId == id)
|
if (temp_input_allowed && (focus_requested || (clicked && g.IO.KeyCtrl) || g.NavInputId == id))
|
||||||
{
|
{
|
||||||
temp_input_is_active = true;
|
temp_input_is_active = true;
|
||||||
FocusableItemUnregister(window);
|
FocusableItemUnregister(window);
|
||||||
|
Loading…
Reference in New Issue
Block a user