mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-05 20:48:46 +02:00
Merge remote-tracking branch 'origin' into 2016-02-colorpicker
This commit is contained in:
78
imgui.cpp
78
imgui.cpp
@ -141,8 +141,9 @@
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
- You can read back 'io.WantCaptureMouse', 'io.WantCaptureKeybord' etc. flags from the IO structure to tell how ImGui intends to use your
|
||||
inputs and to know if you should share them or hide them from the rest of your application. Read the FAQ below for more information.
|
||||
- When calling NewFrame(), the 'io.WantCaptureMouse'/'io.WantCaptureKeyboard'/'io.WantTextInput' flags are updated.
|
||||
They tell you if ImGui intends to use your inputs. So for example, if 'io.WantCaptureMouse' is set you would typically want to hide
|
||||
mouse inputs from the rest of your application. Read the FAQ below for more information about those flags.
|
||||
|
||||
|
||||
API BREAKING CHANGES
|
||||
@ -400,11 +401,13 @@
|
||||
e.g. when displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state differently. experiment and see what makes more sense!
|
||||
|
||||
Q: How can I tell when ImGui wants my mouse/keyboard inputs and when I can pass them to my application?
|
||||
A: You can read the 'io.WantCaptureXXX' flags in the ImGuiIO structure. Preferably read them after calling ImGui::NewFrame() to avoid those flags lagging by one frame, but either should be fine.
|
||||
When 'io.WantCaptureMouse' or 'io.WantCaptureKeyboard' flags are set you may want to discard/hide the inputs from the rest of your application.
|
||||
When 'io.WantInputsCharacters' is set to may want to notify your OS to popup an on-screen keyboard, if available.
|
||||
ImGui is tracking dragging and widget activity that may occur outside the boundary of a window, so 'io.WantCaptureMouse' is a more accurate and complete than testing for ImGui::IsMouseHoveringAnyWindow().
|
||||
(Advanced note: text input releases focus on Return 'KeyDown', so the following Return 'KeyUp' event that your application receive will typically have 'io.WantcaptureKeyboard=false'.
|
||||
A: You can read the 'io.WantCaptureMouse'/'io.WantCaptureKeyboard'/'ioWantTextInput' flags from the ImGuiIO structure.
|
||||
- When 'io.WantCaptureMouse' or 'io.WantCaptureKeyboard' flags are set you may want to discard/hide the inputs from the rest of your application.
|
||||
- When 'io.WantTextInput' is set to may want to notify your OS to popup an on-screen keyboard, if available (e.g. on a mobile phone, or console without a keyboard).
|
||||
Preferably read the flags after calling ImGui::NewFrame() to avoid them lagging by one frame. But reading those flags before calling NewFrame() is also generally ok,
|
||||
as the bool toggles fairly rarely and you don't generally expect to interact with either ImGui or your application during the same frame when that transition occurs.
|
||||
ImGui is tracking dragging and widget activity that may occur outside the boundary of a window, so 'io.WantCaptureMouse' is more accurate and correct than checking if a window is hovered.
|
||||
(Advanced note: text input releases focus on Return 'KeyDown', so the following Return 'KeyUp' event that your application receive will typically have 'io.WantCaptureKeyboard=false'.
|
||||
Depending on your application logic it may or not be inconvenient. You might want to track which key-downs were for ImGui (e.g. with an array of bool) and filter out the corresponding key-ups.)
|
||||
|
||||
Q: How can I load a different font than the default? (default is an embedded version of ProggyClean.ttf, rendered at size 13)
|
||||
@ -3609,7 +3612,7 @@ static bool BeginPopupEx(const char* str_id, ImGuiWindowFlags extra_flags)
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
||||
ImGuiWindowFlags flags = extra_flags|ImGuiWindowFlags_Popup|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize;
|
||||
ImGuiWindowFlags flags = extra_flags|ImGuiWindowFlags_Popup|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize;
|
||||
|
||||
char name[20];
|
||||
if (flags & ImGuiWindowFlags_ChildMenu)
|
||||
@ -4262,12 +4265,15 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
if (window->ScrollTarget.y < FLT_MAX)
|
||||
{
|
||||
float center_ratio = window->ScrollTargetCenterRatio.y;
|
||||
window->Scroll.y = window->ScrollTarget.y - ((1.0f - center_ratio) * (window->TitleBarHeight() + window->MenuBarHeight())) - (center_ratio * window->SizeFull.y);
|
||||
window->Scroll.y = window->ScrollTarget.y - ((1.0f - center_ratio) * (window->TitleBarHeight() + window->MenuBarHeight())) - (center_ratio * (window->SizeFull.y - window->ScrollbarSizes.y));
|
||||
window->ScrollTarget.y = FLT_MAX;
|
||||
}
|
||||
window->Scroll = ImMax(window->Scroll, ImVec2(0.0f, 0.0f));
|
||||
if (!window->Collapsed && !window->SkipItems)
|
||||
window->Scroll = ImMin(window->Scroll, ImMax(ImVec2(0.0f, 0.0f), window->SizeContents - window->SizeFull + window->ScrollbarSizes));
|
||||
{
|
||||
window->Scroll.x = ImMin(window->Scroll.x, GetScrollMaxX());
|
||||
window->Scroll.y = ImMin(window->Scroll.y, GetScrollMaxY());
|
||||
}
|
||||
|
||||
// Modal window darkens what is behind them
|
||||
if ((flags & ImGuiWindowFlags_Modal) != 0 && window == GetFrontMostModalRootWindow())
|
||||
@ -4321,6 +4327,8 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
// Scrollbars
|
||||
window->ScrollbarY = (flags & ImGuiWindowFlags_AlwaysVerticalScrollbar) || ((window->SizeContents.y > window->Size.y + style.ItemSpacing.y) && !(flags & ImGuiWindowFlags_NoScrollbar));
|
||||
window->ScrollbarX = (flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar) || ((window->SizeContents.x > window->Size.x - (window->ScrollbarY ? style.ScrollbarSize : 0.0f) - window->WindowPadding.x) && !(flags & ImGuiWindowFlags_NoScrollbar) && (flags & ImGuiWindowFlags_HorizontalScrollbar));
|
||||
if (window->ScrollbarX && !window->ScrollbarY)
|
||||
window->ScrollbarY = (window->SizeContents.y > window->Size.y + style.ItemSpacing.y - style.ScrollbarSize) && !(flags & ImGuiWindowFlags_NoScrollbar);
|
||||
window->ScrollbarSizes = ImVec2(window->ScrollbarY ? style.ScrollbarSize : 0.0f, window->ScrollbarX ? style.ScrollbarSize : 0.0f);
|
||||
window->BorderSize = (flags & ImGuiWindowFlags_ShowBorders) ? 1.0f : 0.0f;
|
||||
|
||||
@ -4568,10 +4576,10 @@ static void Scrollbar(ImGuiWindow* window, bool horizontal)
|
||||
// V denote the main axis of the scrollbar
|
||||
float scrollbar_size_v = horizontal ? bb.GetWidth() : bb.GetHeight();
|
||||
float scroll_v = horizontal ? window->Scroll.x : window->Scroll.y;
|
||||
float win_size_avail_v = (horizontal ? window->Size.x : window->Size.y) - other_scrollbar_size_w;
|
||||
float win_size_avail_v = (horizontal ? window->SizeFull.x : window->SizeFull.y) - other_scrollbar_size_w;
|
||||
float win_size_contents_v = horizontal ? window->SizeContents.x : window->SizeContents.y;
|
||||
|
||||
// The grabable box size generally represent the amount visible (vs the total scrollable amount)
|
||||
// The grabbable box size generally represent the amount visible (vs the total scrollable amount)
|
||||
// But we maintain a minimum size in pixel to allow for the user to still aim inside.
|
||||
const float grab_h_pixels = ImMin(ImMax(scrollbar_size_v * ImSaturate(win_size_avail_v / ImMax(win_size_contents_v, win_size_avail_v)), style.GrabMinSize), scrollbar_size_v);
|
||||
const float grab_h_norm = grab_h_pixels / scrollbar_size_v;
|
||||
@ -5328,13 +5336,13 @@ float ImGui::GetScrollY()
|
||||
float ImGui::GetScrollMaxX()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindowRead();
|
||||
return window->SizeContents.x - window->SizeFull.x - window->ScrollbarSizes.x;
|
||||
return ImMax(0.0f, window->SizeContents.x - (window->SizeFull.x - window->ScrollbarSizes.x) + 50);
|
||||
}
|
||||
|
||||
float ImGui::GetScrollMaxY()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindowRead();
|
||||
return window->SizeContents.y - window->SizeFull.y - window->ScrollbarSizes.y;
|
||||
return ImMax(0.0f, window->SizeContents.y - (window->SizeFull.y - window->ScrollbarSizes.y));
|
||||
}
|
||||
|
||||
void ImGui::SetScrollX(float scroll_x)
|
||||
@ -5366,8 +5374,9 @@ void ImGui::SetScrollFromPosY(float pos_y, float center_y_ratio)
|
||||
void ImGui::SetScrollHere(float center_y_ratio)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
float target_y = window->DC.CursorPosPrevLine.y + (window->DC.PrevLineHeight * center_y_ratio) + (GImGui->Style.ItemSpacing.y * (center_y_ratio - 0.5f) * 2.0f); // Precisely aim above, in the middle or below the last line.
|
||||
SetScrollFromPosY(target_y - window->Pos.y, center_y_ratio);
|
||||
float target_y = window->DC.CursorPosPrevLine.y - window->Pos.y; // Top of last item, in window space
|
||||
target_y += (window->DC.PrevLineHeight * center_y_ratio) + (GImGui->Style.ItemSpacing.y * (center_y_ratio - 0.5f) * 2.0f); // Precisely aim above, in the middle or below the last line.
|
||||
SetScrollFromPosY(target_y, center_y_ratio);
|
||||
}
|
||||
|
||||
void ImGui::SetKeyboardFocusHere(int offset)
|
||||
@ -6434,16 +6443,16 @@ static bool DataTypeApplyOpFromText(const char* buf, const char* initial_value_b
|
||||
scalar_format = "%d";
|
||||
int* v = (int*)data_ptr;
|
||||
const int old_v = *v;
|
||||
int arg0 = *v;
|
||||
if (op && sscanf(initial_value_buf, scalar_format, &arg0) < 1)
|
||||
int arg0i = *v;
|
||||
if (op && sscanf(initial_value_buf, scalar_format, &arg0i) < 1)
|
||||
return false;
|
||||
|
||||
// Store operand in a float so we can use fractional value for multipliers (*1.1), but constant always parsed as integer so we can fit big integers (e.g. 2000000003) past float precision
|
||||
float arg1 = 0.0f;
|
||||
if (op == '+') { if (sscanf(buf, "%f", &arg1) == 1) *v = (int)(arg0 + arg1); } // Add (use "+-" to subtract)
|
||||
else if (op == '*') { if (sscanf(buf, "%f", &arg1) == 1) *v = (int)(arg0 * arg1); } // Multiply
|
||||
else if (op == '/') { if (sscanf(buf, "%f", &arg1) == 1 && arg1 != 0.0f) *v = (int)(arg0 / arg1); }// Divide
|
||||
else { if (sscanf(buf, scalar_format, &arg0) == 1) *v = arg0; } // Assign constant
|
||||
float arg1f = 0.0f;
|
||||
if (op == '+') { if (sscanf(buf, "%f", &arg1f) == 1) *v = (int)(arg0i + arg1f); } // Add (use "+-" to subtract)
|
||||
else if (op == '*') { if (sscanf(buf, "%f", &arg1f) == 1) *v = (int)(arg0i * arg1f); } // Multiply
|
||||
else if (op == '/') { if (sscanf(buf, "%f", &arg1f) == 1 && arg1f != 0.0f) *v = (int)(arg0i / arg1f); }// Divide
|
||||
else { if (sscanf(buf, scalar_format, &arg0i) == 1) *v = arg0i; } // Assign constant (read as integer so big values are not lossy)
|
||||
return (old_v != *v);
|
||||
}
|
||||
else if (data_type == ImGuiDataType_Float)
|
||||
@ -6452,17 +6461,17 @@ static bool DataTypeApplyOpFromText(const char* buf, const char* initial_value_b
|
||||
scalar_format = "%f";
|
||||
float* v = (float*)data_ptr;
|
||||
const float old_v = *v;
|
||||
float arg0 = *v;
|
||||
if (op && sscanf(initial_value_buf, scalar_format, &arg0) < 1)
|
||||
float arg0f = *v;
|
||||
if (op && sscanf(initial_value_buf, scalar_format, &arg0f) < 1)
|
||||
return false;
|
||||
|
||||
float arg1 = 0.0f;
|
||||
if (sscanf(buf, scalar_format, &arg1) < 1)
|
||||
float arg1f = 0.0f;
|
||||
if (sscanf(buf, scalar_format, &arg1f) < 1)
|
||||
return false;
|
||||
if (op == '+') { *v = arg0 + arg1; } // Add (use "+-" to subtract)
|
||||
else if (op == '*') { *v = arg0 * arg1; } // Multiply
|
||||
else if (op == '/') { if (arg1 != 0.0f) *v = arg0 / arg1; } // Divide
|
||||
else { *v = arg1; } // Assign constant
|
||||
if (op == '+') { *v = arg0f + arg1f; } // Add (use "+-" to subtract)
|
||||
else if (op == '*') { *v = arg0f * arg1f; } // Multiply
|
||||
else if (op == '/') { if (arg1f != 0.0f) *v = arg0f / arg1f; } // Divide
|
||||
else { *v = arg1f; } // Assign constant
|
||||
return (old_v != *v);
|
||||
}
|
||||
|
||||
@ -9943,7 +9952,7 @@ float ImGui::GetColumnOffset(int column_index)
|
||||
|
||||
IM_ASSERT(column_index < window->DC.ColumnsData.Size);
|
||||
const float t = window->DC.ColumnsData[column_index].OffsetNorm;
|
||||
const float x_offset = window->DC.ColumnsMinX + t * (window->DC.ColumnsMaxX - window->DC.ColumnsMinX);
|
||||
const float x_offset = ImLerp(window->DC.ColumnsMinX, window->DC.ColumnsMaxX, t);
|
||||
return (float)(int)x_offset;
|
||||
}
|
||||
|
||||
@ -10046,7 +10055,7 @@ void ImGui::Columns(int columns_count, const char* id, bool border)
|
||||
window->DC.ColumnsShowBorders = border;
|
||||
|
||||
const float content_region_width = (window->SizeContentsExplicit.x != 0.0f) ? window->SizeContentsExplicit.x : window->Size.x;
|
||||
window->DC.ColumnsMinX = window->DC.IndentX; // Lock our horizontal range
|
||||
window->DC.ColumnsMinX = window->DC.IndentX - g.Style.ItemSpacing.x; // Lock our horizontal range
|
||||
window->DC.ColumnsMaxX = content_region_width - window->Scroll.x - ((window->Flags & ImGuiWindowFlags_NoScrollbar) ? 0 : g.Style.ScrollbarSize);// - window->WindowPadding().x;
|
||||
window->DC.ColumnsStartPosY = window->DC.CursorPos.y;
|
||||
window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.CursorPos.y;
|
||||
@ -10192,7 +10201,10 @@ static const char* GetClipboardTextFn_DefaultImpl(void*)
|
||||
return NULL;
|
||||
HANDLE wbuf_handle = GetClipboardData(CF_UNICODETEXT);
|
||||
if (wbuf_handle == NULL)
|
||||
{
|
||||
CloseClipboard();
|
||||
return NULL;
|
||||
}
|
||||
if (ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle))
|
||||
{
|
||||
int buf_len = ImTextCountUtf8BytesFromStr(wbuf_global, NULL) + 1;
|
||||
|
Reference in New Issue
Block a user