From 75456420564e6b92050e9ba51fd558883fcd0e7d Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 15 Nov 2015 22:42:33 +0100 Subject: [PATCH] Created Tips (markdown) --- Tips.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Tips.md diff --git a/Tips.md b/Tips.md new file mode 100644 index 0000000..2d9ec31 --- /dev/null +++ b/Tips.md @@ -0,0 +1,15 @@ +**Tip: use Begin/BeginChild to put yourself into the context of another window prior or after outputting to it**
+https://github.com/ocornut/imgui/issues/270 + +An interesting trick that isn't obvious is that you can use Begin() just to put yourself into the context of that window. So here I want to react to the user inputting an address to scroll to, I use BeginChild() again on the child that I've already drawn so I can use SetScrollFromPosY() on it. + +``` +ImGui::BeginChild("##scrolling", ImVec2(0, -ImGui::GetItemsLineHeightWithSpacing())); +// ...(draw main content) +ImGui::EndChild(); + +// And then much later in the main window, get back into child context to change scrolling offset +ImGui::BeginChild("##scrolling"); +ImGui::SetScrollFromPosY(ImGui::GetCursorStartPos().y + (goto_addr / Rows) * line_height); +ImGui::End(); +```