Browse Source

SetScrollFromCursorPos() -> SetScrollHere() (#150) final call !

pull/258/head
ocornut 9 years ago
parent
commit
42efc29def
  1. 12
      imgui.cpp
  2. 4
      imgui.h

12
imgui.cpp

@ -4845,7 +4845,7 @@ void ImGui::SetScrollFromPosY(float pos_y, float center_y_ratio)
window->ScrollTargetCenterRatioY = center_y_ratio; window->ScrollTargetCenterRatioY = center_y_ratio;
} }
void ImGui::SetScrollFromCursorPos(float center_y_ratio) void ImGui::SetScrollHere(float center_y_ratio)
{ {
ImGuiWindow* window = GetCurrentWindow(); 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. 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.
@ -7762,7 +7762,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi
*current_item = i; *current_item = i;
} }
if (item_selected && menu_toggled) if (item_selected && menu_toggled)
ImGui::SetScrollFromCursorPos(); ImGui::SetScrollHere();
ImGui::PopID(); ImGui::PopID();
} }
ImGui::EndPopup(); ImGui::EndPopup();
@ -11311,10 +11311,10 @@ void ImGui::ShowTestWindow(bool* opened)
{ {
ImGui::Text("%04d: scrollable region", i); ImGui::Text("%04d: scrollable region", i);
if (goto_line && line == i) if (goto_line && line == i)
ImGui::SetScrollFromCursorPos(); ImGui::SetScrollHere();
} }
if (goto_line && line >= 100) if (goto_line && line >= 100)
ImGui::SetScrollFromCursorPos(); ImGui::SetScrollHere();
ImGui::EndChild(); ImGui::EndChild();
ImGui::SameLine(); ImGui::SameLine();
@ -11529,7 +11529,7 @@ void ImGui::ShowTestWindow(bool* opened)
{ {
ImGui::Text("Line %d", line); ImGui::Text("Line %d", line);
if (track && line == track_line) if (track && line == track_line)
ImGui::SetScrollFromCursorPos(i * 0.50f); // 0.0f:top, 0.5f:center, 1.0f:bottom ImGui::SetScrollHere(i * 0.50f); // 0.0f:top, 0.5f:center, 1.0f:bottom
} }
ImGui::EndChild(); ImGui::EndChild();
ImGui::EndGroup(); ImGui::EndGroup();
@ -12288,7 +12288,7 @@ struct ExampleAppConsole
ImGui::PopStyleColor(); ImGui::PopStyleColor();
} }
if (ScrollToBottom) if (ScrollToBottom)
ImGui::SetScrollFromCursorPos(); ImGui::SetScrollHere();
ScrollToBottom = false; ScrollToBottom = false;
ImGui::PopStyleVar(); ImGui::PopStyleVar();
ImGui::EndChild(); ImGui::EndChild();

4
imgui.h

@ -138,7 +138,7 @@ namespace ImGui
IMGUI_API float GetScrollY(); // get scrolling amount [0..GetScrollMaxY()] IMGUI_API float GetScrollY(); // get scrolling amount [0..GetScrollMaxY()]
IMGUI_API float GetScrollMaxY(); // get maximum scrolling amount == ContentSize.Y - WindowSize.Y IMGUI_API float GetScrollMaxY(); // get maximum scrolling amount == ContentSize.Y - WindowSize.Y
IMGUI_API void SetScrollY(float scroll_y); // set scrolling amount [0..GetScrollMaxY()] IMGUI_API void SetScrollY(float scroll_y); // set scrolling amount [0..GetScrollMaxY()]
IMGUI_API void SetScrollFromCursorPos(float center_y_ratio = 0.5f); // adjust scrolling amount to make current cursor position visible. center_y_ratio=0.0: top, 0.5: center, 1.0: bottom. IMGUI_API void SetScrollHere(float center_y_ratio = 0.5f); // adjust scrolling amount to make current cursor position visible. center_y_ratio=0.0: top, 0.5: center, 1.0: bottom.
IMGUI_API void SetScrollFromPosY(float pos_y, float center_y_ratio = 0.5f); // adjust scrolling amount to make given position valid. use GetCursorPos() or GetCursorStartPos()+offset to get valid positions. IMGUI_API void SetScrollFromPosY(float pos_y, float center_y_ratio = 0.5f); // adjust scrolling amount to make given position valid. use GetCursorPos() or GetCursorStartPos()+offset to get valid positions.
IMGUI_API void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget IMGUI_API void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget
IMGUI_API void SetStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it) IMGUI_API void SetStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it)
@ -411,7 +411,7 @@ namespace ImGui
static inline bool IsClipped(const ImVec2& size) { return !IsRectVisible(size); } // OBSOLETE 1.38+ static inline bool IsClipped(const ImVec2& size) { return !IsRectVisible(size); } // OBSOLETE 1.38+
static inline bool IsRectClipped(const ImVec2& size) { return !IsRectVisible(size); } // OBSOLETE 1.39+ static inline bool IsRectClipped(const ImVec2& size) { return !IsRectVisible(size); } // OBSOLETE 1.39+
static inline bool IsMouseHoveringBox(const ImVec2& rect_min, const ImVec2& rect_max) { return IsMouseHoveringRect(rect_min, rect_max); } // OBSOLETE 1.36+ static inline bool IsMouseHoveringBox(const ImVec2& rect_min, const ImVec2& rect_max) { return IsMouseHoveringRect(rect_min, rect_max); } // OBSOLETE 1.36+
static inline void SetScrollPosHere() { SetScrollFromCursorPos(); } // OBSOLETE 1.42+ static inline void SetScrollPosHere() { SetScrollHere(); } // OBSOLETE 1.42+
#endif #endif
} // namespace ImGui } // namespace ImGui

Loading…
Cancel
Save