Skip to content

Commit

Permalink
Merge branch 'master' into docking
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed Jun 9, 2023
2 parents 8fd0a04 + 4fab72b commit 0664877
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 40 deletions.
9 changes: 9 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ HOW TO UPDATE?
and API updates have been a little more frequent lately. They are documented below and in imgui.cpp and should not affect all users.
- Please report any issue!

-----------------------------------------------------------------------
VERSION 1.89.7 WIP (In Progress)
-----------------------------------------------------------------------

Other changes:

- Tables: Fixed a regression in 1.89.6 leading to the first column of tables with either
ScrollX or ScrollY flags from being impossible to resize. (#6503)


-----------------------------------------------------------------------
DOCKING+MULTI-VIEWPORT BRANCH (In Progress)
Expand Down
69 changes: 45 additions & 24 deletions imgui.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// dear imgui, v1.89.6
// dear imgui, v1.89.7 WIP
// (main code and documentation)

// Help:
Expand Down Expand Up @@ -5589,7 +5589,7 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b

// Process navigation-in immediately so NavInit can run on first frame
// Can enter a child if (A) it has navigatable items or (B) it can be scrolled.
const ImGuiID temp_id_for_activation = (id + 1);
const ImGuiID temp_id_for_activation = ImHashStr("##Child", 0, id);
if (g.ActiveId == temp_id_for_activation)
ClearActiveID();
if (g.NavActivateId == id && !(flags & ImGuiWindowFlags_NavFlattened) && (child_window->DC.NavLayersActiveMask != 0 || child_window->DC.NavWindowHasScrollY))
Expand Down Expand Up @@ -8131,13 +8131,6 @@ void ImGui::SetWindowFontScale(float scale)
g.FontSize = g.DrawListSharedData.FontSize = window->CalcFontSize();
}

void ImGui::ActivateItem(ImGuiID id)
{
ImGuiContext& g = *GImGui;
g.NavNextActivateId = id;
g.NavNextActivateFlags = ImGuiActivateFlags_None;
}

void ImGui::PushFocusScope(ImGuiID id)
{
ImGuiContext& g = *GImGui;
Expand All @@ -8153,28 +8146,56 @@ void ImGui::PopFocusScope()
g.CurrentFocusScopeId = g.FocusScopeStack.Size ? g.FocusScopeStack.back() : 0;
}

// Focus = move navigation cursor, set scrolling, set focus window.
void ImGui::FocusItem()
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
IMGUI_DEBUG_LOG_FOCUS("FocusItem(0x%08x) in window \"%s\"\n", g.LastItemData.ID, window->Name);
if (g.DragDropActive || g.MovingWindow != NULL) // FIXME: Opt-in flags for this?
{
IMGUI_DEBUG_LOG_FOCUS("FocusItem() ignored while DragDropActive!\n");
return;
}

ImGuiNavMoveFlags move_flags = ImGuiNavMoveFlags_Tabbing | ImGuiNavMoveFlags_FocusApi | ImGuiNavMoveFlags_NoSelect;
ImGuiScrollFlags scroll_flags = window->Appearing ? ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_KeepVisibleEdgeY;
SetNavWindow(window);
NavMoveRequestSubmit(ImGuiDir_None, ImGuiDir_Up, move_flags, scroll_flags);
NavMoveRequestResolveWithLastItem(&g.NavMoveResultLocal);
}

void ImGui::ActivateItemByID(ImGuiID id)
{
ImGuiContext& g = *GImGui;
g.NavNextActivateId = id;
g.NavNextActivateFlags = ImGuiActivateFlags_None;
}

// Note: this will likely be called ActivateItem() once we rework our Focus/Activation system!
// But ActivateItem() should function without altering scroll/focus?
void ImGui::SetKeyboardFocusHere(int offset)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
IM_ASSERT(offset >= -1); // -1 is allowed but not below
IMGUI_DEBUG_LOG_ACTIVEID("SetKeyboardFocusHere(%d) in window \"%s\"\n", offset, window->Name);
IMGUI_DEBUG_LOG_FOCUS("SetKeyboardFocusHere(%d) in window \"%s\"\n", offset, window->Name);

// It makes sense in the vast majority of cases to never interrupt a drag and drop.
// When we refactor this function into ActivateItem() we may want to make this an option.
// MovingWindow is protected from most user inputs using SetActiveIdUsingNavAndKeys(), but
// is also automatically dropped in the event g.ActiveId is stolen.
if (g.DragDropActive || g.MovingWindow != NULL)
{
IMGUI_DEBUG_LOG_ACTIVEID("SetKeyboardFocusHere() ignored while DragDropActive!\n");
IMGUI_DEBUG_LOG_FOCUS("SetKeyboardFocusHere() ignored while DragDropActive!\n");
return;
}

SetNavWindow(window);

ImGuiNavMoveFlags move_flags = ImGuiNavMoveFlags_Tabbing | ImGuiNavMoveFlags_Activate | ImGuiNavMoveFlags_FocusApi;
ImGuiScrollFlags scroll_flags = window->Appearing ? ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_KeepVisibleEdgeY;
NavMoveRequestSubmit(ImGuiDir_None, offset < 0 ? ImGuiDir_Up : ImGuiDir_Down, ImGuiNavMoveFlags_Tabbing | ImGuiNavMoveFlags_FocusApi, scroll_flags); // FIXME-NAV: Once we refactor tabbing, add LegacyApi flag to not activate non-inputable.
NavMoveRequestSubmit(ImGuiDir_None, offset < 0 ? ImGuiDir_Up : ImGuiDir_Down, move_flags, scroll_flags); // FIXME-NAV: Once we refactor tabbing, add LegacyApi flag to not activate non-inputable.
if (offset == -1)
{
NavMoveRequestResolveWithLastItem(&g.NavMoveResultLocal);
Expand Down Expand Up @@ -12221,9 +12242,10 @@ void ImGui::NavUpdateCreateTabbingRequest()
g.NavTabbingDir = g.IO.KeyShift ? -1 : (g.NavDisableHighlight == true && g.ActiveId == 0) ? 0 : +1;
else
g.NavTabbingDir = g.IO.KeyShift ? -1 : (g.ActiveId == 0) ? 0 : +1;
ImGuiNavMoveFlags move_flags = ImGuiNavMoveFlags_Tabbing | ImGuiNavMoveFlags_Activate;
ImGuiScrollFlags scroll_flags = window->Appearing ? ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_KeepVisibleEdgeY;
ImGuiDir clip_dir = (g.NavTabbingDir < 0) ? ImGuiDir_Up : ImGuiDir_Down;
NavMoveRequestSubmit(ImGuiDir_None, clip_dir, ImGuiNavMoveFlags_Tabbing, scroll_flags); // FIXME-NAV: Once we refactor tabbing, add LegacyApi flag to not activate non-inputable.
NavMoveRequestSubmit(ImGuiDir_None, clip_dir, move_flags, scroll_flags); // FIXME-NAV: Once we refactor tabbing, add LegacyApi flag to not activate non-inputable.
g.NavTabbingCounter = -1;
}

Expand All @@ -12249,8 +12271,8 @@ void ImGui::NavMoveRequestApplyResult()
if (result == NULL)
{
if (g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing)
g.NavMoveFlags |= ImGuiNavMoveFlags_DontSetNavHighlight;
if (g.NavId != 0 && (g.NavMoveFlags & ImGuiNavMoveFlags_DontSetNavHighlight) == 0)
g.NavMoveFlags |= ImGuiNavMoveFlags_NoSetNavHighlight;
if (g.NavId != 0 && (g.NavMoveFlags & ImGuiNavMoveFlags_NoSetNavHighlight) == 0)
NavRestoreHighlightAfterMove();
NavClearPreferredPosForAxis(axis); // On a failed move, clear preferred pos for this axis.
IMGUI_DEBUG_LOG_NAV("[nav] NavMoveSubmitted but not led to a result!\n");
Expand Down Expand Up @@ -12289,7 +12311,7 @@ void ImGui::NavMoveRequestApplyResult()
}
if (g.ActiveId != result->ID)
ClearActiveID();
if (g.NavId != result->ID)
if (g.NavId != result->ID && (g.NavMoveFlags & ImGuiNavMoveFlags_NoSelect) == 0)
{
// Don't set NavJustMovedToId if just landed on the same spot (which may happen with ImGuiNavMoveFlags_AllowCurrentNavId)
g.NavJustMovedToId = result->ID;
Expand All @@ -12310,23 +12332,22 @@ void ImGui::NavMoveRequestApplyResult()
g.NavWindow->RootWindowForNav->NavPreferredScoringPosRel[g.NavLayer] = preferred_scoring_pos_rel;
}

// Tabbing: Activates Inputable or Focus non-Inputable
if ((g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing) && (result->InFlags & ImGuiItemFlags_Inputable))
{
g.NavNextActivateId = result->ID;
g.NavNextActivateFlags = ImGuiActivateFlags_PreferInput | ImGuiActivateFlags_TryToPreserveState;
g.NavMoveFlags |= ImGuiNavMoveFlags_DontSetNavHighlight;
}
// Tabbing: Activates Inputable, otherwise only Focus
if ((g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing) && (result->InFlags & ImGuiItemFlags_Inputable) == 0)
g.NavMoveFlags &= ~ImGuiNavMoveFlags_Activate;

// Activate
if (g.NavMoveFlags & ImGuiNavMoveFlags_Activate)
{
g.NavNextActivateId = result->ID;
g.NavNextActivateFlags = ImGuiActivateFlags_None;
g.NavMoveFlags |= ImGuiNavMoveFlags_NoSetNavHighlight;
if (g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing)
g.NavNextActivateFlags |= ImGuiActivateFlags_PreferInput | ImGuiActivateFlags_TryToPreserveState;
}

// Enable nav highlight
if ((g.NavMoveFlags & ImGuiNavMoveFlags_DontSetNavHighlight) == 0)
if ((g.NavMoveFlags & ImGuiNavMoveFlags_NoSetNavHighlight) == 0)
NavRestoreHighlightAfterMove();
}

Expand Down
6 changes: 3 additions & 3 deletions imgui.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// dear imgui, v1.89.6
// dear imgui, v1.89.7 WIP
// (headers)

// Help:
Expand All @@ -22,8 +22,8 @@

// Library Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
#define IMGUI_VERSION "1.89.6"
#define IMGUI_VERSION_NUM 18960
#define IMGUI_VERSION "1.89.7 WIP"
#define IMGUI_VERSION_NUM 18962
#define IMGUI_HAS_TABLE
#define IMGUI_HAS_VIEWPORT // Viewport WIP branch
#define IMGUI_HAS_DOCK // Docking WIP branch
Expand Down
8 changes: 4 additions & 4 deletions imgui_demo.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// dear imgui, v1.89.6
// dear imgui, v1.89.7 WIP
// (demo code)

// Help:
Expand Down Expand Up @@ -1452,8 +1452,8 @@ static void ShowDemoWindowWidgets()
// Modify character input by altering 'data->Eventchar' (ImGuiInputTextFlags_CallbackCharFilter callback)
static int FilterCasingSwap(ImGuiInputTextCallbackData* data)
{
if (data->EventChar >= 'a' && data->EventChar <= 'z') { data->EventChar = data->EventChar - 'A' - 'a'; } // Lowercase becomes uppercase
else if (data->EventChar >= 'A' && data->EventChar <= 'Z') { data->EventChar = data->EventChar + 'a' - 'A'; } // Uppercase becomes lowercase
if (data->EventChar >= 'a' && data->EventChar <= 'z') { data->EventChar -= 'a' - 'A'; } // Lowercase becomes uppercase
else if (data->EventChar >= 'A' && data->EventChar <= 'Z') { data->EventChar += 'a' - 'A'; } // Uppercase becomes lowercase
return 0;
}

Expand Down Expand Up @@ -8293,8 +8293,8 @@ void ShowExampleAppDocuments(bool* p_open)
for (int n = 0; n < close_queue.Size; n++)
if (close_queue[n]->Dirty)
ImGui::Text("%s", close_queue[n]->Name);
ImGui::EndChildFrame();
}
ImGui::EndChildFrame();

ImVec2 button_size(ImGui::GetFontSize() * 7.0f, 0.0f);
if (ImGui::Button("Yes", button_size))
Expand Down
2 changes: 1 addition & 1 deletion imgui_draw.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// dear imgui, v1.89.6
// dear imgui, v1.89.7 WIP
// (drawing and font code)

/*
Expand Down
16 changes: 11 additions & 5 deletions imgui_internal.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// dear imgui, v1.89.6
// dear imgui, v1.89.7 WIP
// (internal structures/api)

// You may use this file to debug, understand or extend Dear ImGui features but we don't provide any guarantee of forward compatibility.
Expand Down Expand Up @@ -1500,10 +1500,11 @@ enum ImGuiNavMoveFlags_
ImGuiNavMoveFlags_ScrollToEdgeY = 1 << 6, // Force scrolling to min/max (used by Home/End) // FIXME-NAV: Aim to remove or reword, probably unnecessary
ImGuiNavMoveFlags_Forwarded = 1 << 7,
ImGuiNavMoveFlags_DebugNoResult = 1 << 8, // Dummy scoring for debug purpose, don't apply result
ImGuiNavMoveFlags_FocusApi = 1 << 9,
ImGuiNavMoveFlags_FocusApi = 1 << 9, // Requests from focus API can land/focus/activate items even if they are marked with _NoTabStop (see NavProcessItemForTabbingRequest() for details)
ImGuiNavMoveFlags_Tabbing = 1 << 10, // == Focus + Activate if item is Inputable + DontChangeNavHighlight
ImGuiNavMoveFlags_Activate = 1 << 11,
ImGuiNavMoveFlags_DontSetNavHighlight = 1 << 12, // Do not alter the visible state of keyboard vs mouse nav highlight
ImGuiNavMoveFlags_Activate = 1 << 11, // Activate/select target item.
ImGuiNavMoveFlags_NoSelect = 1 << 12, // Don't trigger selection by not setting g.NavJustMovedTo
ImGuiNavMoveFlags_NoSetNavHighlight = 1 << 13, // Do not alter the visible state of keyboard vs mouse nav highlight
};

enum ImGuiNavLayer
Expand Down Expand Up @@ -3151,10 +3152,15 @@ namespace ImGui
IMGUI_API void NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags move_flags);
IMGUI_API void NavClearPreferredPosForAxis(ImGuiAxis axis);
IMGUI_API void NavUpdateCurrentWindowIsScrollPushableX();
IMGUI_API void ActivateItem(ImGuiID id); // Remotely activate a button, checkbox, tree node etc. given its unique ID. activation is queued and processed on the next frame when the item is encountered again.
IMGUI_API void SetNavWindow(ImGuiWindow* window);
IMGUI_API void SetNavID(ImGuiID id, ImGuiNavLayer nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel);

// Focus/Activation
// This should be part of a larger set of API: FocusItem(offset = -1), FocusItemByID(id), ActivateItem(offset = -1), ActivateItemByID(id) etc. which are
// much harder to design and implement than expected. I have a couple of private branches on this matter but it's not simple. For now implementing the easy ones.
IMGUI_API void FocusItem(); // Focus last item (no selection/activation).
IMGUI_API void ActivateItemByID(ImGuiID id); // Activate an item by ID (button, checkbox, tree node etc.). Activation is queued and processed on the next frame when the item is encountered again.

// Inputs
// FIXME: Eventually we should aim to move e.g. IsActiveIdUsingKey() into IsKeyXXX functions.
inline bool IsNamedKey(ImGuiKey key) { return key >= ImGuiKey_NamedKey_BEGIN && key < ImGuiKey_NamedKey_END; }
Expand Down
2 changes: 1 addition & 1 deletion imgui_tables.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// dear imgui, v1.89.6
// dear imgui, v1.89.7 WIP
// (tables and columns code)

/*
Expand Down
4 changes: 2 additions & 2 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// dear imgui, v1.89.6
// dear imgui, v1.89.7 WIP
// (widgets code)

/*
Expand Down Expand Up @@ -1835,7 +1835,7 @@ bool ImGui::BeginComboPreview()
if (window->SkipItems || !(g.LastItemData.StatusFlags & ImGuiItemStatusFlags_Visible))
return false;
IM_ASSERT(g.LastItemData.Rect.Min.x == preview_data->PreviewRect.Min.x && g.LastItemData.Rect.Min.y == preview_data->PreviewRect.Min.y); // Didn't call after BeginCombo/EndCombo block or forgot to pass ImGuiComboFlags_CustomPreview flag?
if (!window->ClipRect.Contains(preview_data->PreviewRect)) // Narrower test (optional)
if (!window->ClipRect.Overlaps(preview_data->PreviewRect)) // Narrower test (optional)
return false;

// FIXME: This could be contained in a PushWorkRect() api
Expand Down

0 comments on commit 0664877

Please sign in to comment.