Remove internal and extension API
This commit is contained in:
1 parent
f6e9712b38
commit
b59aea96d9
7 files changed
-1010
No files matched your search
@@ -24,7 +24,6 @@ class GenerateLibs extends DefaultTask {
|
|||||||
// Copy ImGui h/cpp files
|
// Copy ImGui h/cpp files
|
||||||
project.copy { CopySpec spec ->
|
project.copy { CopySpec spec ->
|
||||||
spec.from(project.rootProject.file('imgui')) { CopySpec it -> it.include('*.h', '*.cpp') }
|
spec.from(project.rootProject.file('imgui')) { CopySpec it -> it.include('*.h', '*.cpp') }
|
||||||
spec.from(project.file('src/main/native'))
|
|
||||||
spec.into(jniDir)
|
spec.into(jniDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import imgui.enums.*;
|
|||||||
import java.nio.Buffer;
|
import java.nio.Buffer;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
//import com.badlogic.gdx.jnigen.JniGenSharedLibraryLoader;
|
|
||||||
|
|
||||||
public class ImGui {
|
public class ImGui {
|
||||||
private static final String LIB_NAME_PROP = "imgui.library.name";
|
private static final String LIB_NAME_PROP = "imgui.library.name";
|
||||||
private static final String LIB_NAME_DEFAULT = "imgui-java";
|
private static final String LIB_NAME_DEFAULT = "imgui-java";
|
||||||
@@ -1575,18 +1573,4 @@ public class ImGui {
|
|||||||
public static void SetMouseCursor(ImGuiMouseCursor type) {
|
public static void SetMouseCursor(ImGuiMouseCursor type) {
|
||||||
Native.SetMouseCursor(type.getValue());
|
Native.SetMouseCursor(type.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal methods
|
|
||||||
|
|
||||||
public static void PushMultiItemsWidths(int components, float w_full) {
|
|
||||||
NativeInternal.PushMultiItemsWidths(components, w_full);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ItemAdd(float x1, float y1, float x2, float y2, String id) {
|
|
||||||
NativeInternal.ItemAdd(x1, y1, x2, y2, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ItemSize(float x1, float y1, float x2, float y2, float text_offset_y) {
|
|
||||||
NativeInternal.ItemSize(x1, y1, x2, y2, text_offset_y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
package imgui;
|
|
||||||
|
|
||||||
import imgui.NativeCustomWidget.ImGuiCollapseLayoutOptions;
|
|
||||||
|
|
||||||
public class ImGuiEx {
|
|
||||||
|
|
||||||
protected ImGuiEx() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ShowLayoutDebug() {
|
|
||||||
NativeCustomWidget.ShowLayoutDebug();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void BeginLayout(String id, float sizeX, float sizeY) {
|
|
||||||
NativeCustomWidget.BeginLayout(id, sizeX, sizeY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void BeginLayout(String id, float sizeX, float sizeY, float paddingLeft, float paddingRight, float paddingTop, float paddingBottom) {
|
|
||||||
NativeCustomWidget.BeginLayout(id, sizeX, sizeY, paddingLeft, paddingRight, paddingTop, paddingBottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void EndLayout() {
|
|
||||||
NativeCustomWidget.EndLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean BeginCollapseLayoutEx(String title, float sizeX, float sizeY) {
|
|
||||||
return NativeCustomWidget.BeginCollapseLayoutEx2(title, sizeX, sizeY, NativeCustomWidget.defaultOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean BeginCollapseLayoutEx(String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) {
|
|
||||||
return NativeCustomWidget.BeginCollapseLayoutEx2(title, sizeX, sizeY, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void BeginCollapseLayoutEx(ImGuiBoolean isOpen, String title, float sizeX, float sizeY) {
|
|
||||||
NativeCustomWidget.BeginCollapseLayoutEx(isOpen.data, title, sizeX, sizeY, NativeCustomWidget.defaultOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void BeginCollapseLayoutEx(ImGuiBoolean isOpen, String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) {
|
|
||||||
NativeCustomWidget.BeginCollapseLayoutEx(isOpen.data, title, sizeX, sizeY, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean BeginCollapseLayout(String title, float sizeX, float sizeY) {
|
|
||||||
return NativeCustomWidget.BeginCollapseLayout2(title, sizeX, sizeY, NativeCustomWidget.defaultOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean BeginCollapseLayout(String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) {
|
|
||||||
return NativeCustomWidget.BeginCollapseLayout2(title, sizeX, sizeY, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void BeginCollapseLayout(ImGuiBoolean isOpen, String title, float sizeX, float sizeY) {
|
|
||||||
NativeCustomWidget.BeginCollapseLayout(isOpen.data, title, sizeX, sizeY, NativeCustomWidget.defaultOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void BeginCollapseLayout(ImGuiBoolean isOpen, String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) {
|
|
||||||
NativeCustomWidget.BeginCollapseLayout(isOpen.data, title, sizeX, sizeY, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void EndCollapseFrameLayout() {
|
|
||||||
NativeCustomWidget.EndCollapseFrameLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void EndCollapseLayout() {
|
|
||||||
NativeCustomWidget.EndCollapseLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void BeginAlign(String id, float sizeX, float sizeY, float alignX, float alignY) {
|
|
||||||
NativeCustomWidget.BeginAlign(id, sizeX, sizeY, alignX, alignY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void BeginAlign(String id, float sizeX, float sizeY, float alignX, float alignY, float offsetX, float offsetY) {
|
|
||||||
NativeCustomWidget.BeginAlign(id, sizeX, sizeY, alignX, alignY, offsetX, offsetY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void EndAlign() {
|
|
||||||
NativeCustomWidget.EndAlign();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AlignLayout(float alignX, float alignY) {
|
|
||||||
NativeCustomWidget.AlignLayout(alignX, alignY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AlignLayout(float alignX, float alignY, float offsetX, float offsetY) {
|
|
||||||
NativeCustomWidget.AlignLayout(alignX, alignY, offsetX, offsetY);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Helper methods
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Packs the color components into a 32-bit integer with the format ABGR. Note that no range checking is performed for higher
|
|
||||||
* performance.
|
|
||||||
*
|
|
||||||
* @param r the red component, 0 - 255
|
|
||||||
* @param g the green component, 0 - 255
|
|
||||||
* @param b the blue component, 0 - 255
|
|
||||||
* @param a the alpha component, 0 - 255
|
|
||||||
* @return the packed color as a 32-bit int
|
|
||||||
*/
|
|
||||||
public static int colorToIntBits(int r, int g, int b, int a) {
|
|
||||||
return (a << 24) | (b << 16) | (g << 8) | r;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
package imgui;
|
|
||||||
|
|
||||||
import imgui.enums.ImDrawCornerFlags;
|
|
||||||
|
|
||||||
class NativeCustomWidget {
|
|
||||||
public static ImGuiCollapseLayoutOptions defaultOptions = new ImGuiCollapseLayoutOptions();
|
|
||||||
|
|
||||||
// @formatter:off
|
|
||||||
|
|
||||||
/*JNI
|
|
||||||
#include <imgui_layout_widget.h>
|
|
||||||
|
|
||||||
jfieldID paddingLeftID;
|
|
||||||
jfieldID paddingRightID;
|
|
||||||
jfieldID paddingTopID;
|
|
||||||
jfieldID paddingBottomID;
|
|
||||||
jfieldID arrowColorID;
|
|
||||||
jfieldID arrowBackgroundHoveredColorID;
|
|
||||||
jfieldID arrowBackgroundClickedColorID;
|
|
||||||
jfieldID frameColorID;
|
|
||||||
jfieldID borderColorID;
|
|
||||||
jfieldID borderRoundID;
|
|
||||||
jfieldID roundingCornersID;
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native void init() /*-{ }-*/; /*
|
|
||||||
jclass jLayoutOptionsClass = env->FindClass("imgui/NativeCustomWidget");
|
|
||||||
paddingLeftID = env->GetFieldID(jLayoutOptionsClass, "paddingLeft", "F");
|
|
||||||
paddingRightID = env->GetFieldID(jLayoutOptionsClass, "paddingRight", "F");
|
|
||||||
paddingTopID = env->GetFieldID(jLayoutOptionsClass, "paddingTop", "F");
|
|
||||||
paddingBottomID = env->GetFieldID(jLayoutOptionsClass, "paddingBottom", "F");
|
|
||||||
arrowColorID = env->GetFieldID(jLayoutOptionsClass, "arrowColor", "I");
|
|
||||||
arrowBackgroundHoveredColorID = env->GetFieldID(jLayoutOptionsClass, "arrowBackgroundHoveredColor", "I");
|
|
||||||
arrowBackgroundClickedColorID = env->GetFieldID(jLayoutOptionsClass, "arrowBackgroundClickedColor", "I");
|
|
||||||
frameColorID = env->GetFieldID(jLayoutOptionsClass, "frameColor", "I");
|
|
||||||
borderColorID = env->GetFieldID(jLayoutOptionsClass, "borderColor", "I");
|
|
||||||
borderRoundID = env->GetFieldID(jLayoutOptionsClass, "borderRound", "I");
|
|
||||||
roundingCornersID = env->GetFieldID(jLayoutOptionsClass, "roundingCorners", "I");
|
|
||||||
*/
|
|
||||||
|
|
||||||
static {
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
static native void ShowLayoutDebug() /*-{ }-*/; /*
|
|
||||||
ImGuiEx::ShowLayoutDebug();
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native void BeginLayout(String id, float sizeX, float sizeY); /*-{ }-*/; /*
|
|
||||||
ImGuiEx::BeginLayout(id, sizeX, sizeY);
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native void BeginLayout(String id, float sizeX, float sizeY, float paddingLeft, float paddingRight, float paddingTop, float paddingBottom); /*-{ }-*/; /*
|
|
||||||
ImGuiEx::BeginLayout(id, sizeX, sizeY, paddingLeft, paddingRight, paddingTop, paddingBottom);
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native void EndLayout(); /*-{ }-*/; /*
|
|
||||||
ImGuiEx::EndLayout();
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native boolean BeginCollapseLayoutEx2(String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions jOptions); /*-{ }-*/; /*
|
|
||||||
ImGuiCollapseLayoutOptions options;
|
|
||||||
options.paddingLeft = env->GetFloatField (jOptions, paddingLeftID);
|
|
||||||
options.paddingRight = env->GetFloatField (jOptions, paddingRightID);
|
|
||||||
options.paddingTop = env->GetFloatField (jOptions, paddingTopID);
|
|
||||||
options.paddingBottom = env->GetFloatField (jOptions, paddingBottomID);
|
|
||||||
options.arrowColor = env->GetIntField (jOptions, arrowColorID);
|
|
||||||
options.arrowBackgroundHoveredColor = env->GetIntField (jOptions, arrowBackgroundHoveredColorID);
|
|
||||||
options.arrowBackgroundClickedColor = env->GetIntField (jOptions, arrowBackgroundClickedColorID);
|
|
||||||
options.frameColor = env->GetIntField (jOptions, frameColorID);
|
|
||||||
options.borderColor = env->GetIntField (jOptions, borderColorID);
|
|
||||||
options.borderRound = env->GetIntField (jOptions, borderRoundID);
|
|
||||||
options.roundingCorners = env->GetIntField (jOptions, roundingCornersID);
|
|
||||||
return ImGuiEx::BeginCollapseLayoutEx(title, sizeX, sizeY, options);
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native void BeginCollapseLayoutEx(boolean [] isOpen, String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions jOptions); /*-{ }-*/; /*
|
|
||||||
ImGuiCollapseLayoutOptions options;
|
|
||||||
options.paddingLeft = env->GetFloatField (jOptions, paddingLeftID);
|
|
||||||
options.paddingRight = env->GetFloatField (jOptions, paddingRightID);
|
|
||||||
options.paddingTop = env->GetFloatField (jOptions, paddingTopID);
|
|
||||||
options.paddingBottom = env->GetFloatField (jOptions, paddingBottomID);
|
|
||||||
options.arrowColor = env->GetIntField (jOptions, arrowColorID);
|
|
||||||
options.arrowBackgroundHoveredColor = env->GetIntField (jOptions, arrowBackgroundHoveredColorID);
|
|
||||||
options.arrowBackgroundClickedColor = env->GetIntField (jOptions, arrowBackgroundClickedColorID);
|
|
||||||
options.frameColor = env->GetIntField (jOptions, frameColorID);
|
|
||||||
options.borderColor = env->GetIntField (jOptions, borderColorID);
|
|
||||||
options.borderRound = env->GetIntField (jOptions, borderRoundID);
|
|
||||||
options.roundingCorners = env->GetIntField (jOptions, roundingCornersID);
|
|
||||||
ImGuiEx::BeginCollapseLayoutEx(&isOpen[0], title, sizeX, sizeY, options);
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native boolean BeginCollapseLayout2(String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions jOptions); /*-{ }-*/; /*
|
|
||||||
ImGuiCollapseLayoutOptions options;
|
|
||||||
options.paddingLeft = env->GetFloatField (jOptions, paddingLeftID);
|
|
||||||
options.paddingRight = env->GetFloatField (jOptions, paddingRightID);
|
|
||||||
options.paddingTop = env->GetFloatField (jOptions, paddingTopID);
|
|
||||||
options.paddingBottom = env->GetFloatField (jOptions, paddingBottomID);
|
|
||||||
options.arrowColor = env->GetIntField (jOptions, arrowColorID);
|
|
||||||
options.arrowBackgroundHoveredColor = env->GetIntField (jOptions, arrowBackgroundHoveredColorID);
|
|
||||||
options.arrowBackgroundClickedColor = env->GetIntField (jOptions, arrowBackgroundClickedColorID);
|
|
||||||
options.frameColor = env->GetIntField (jOptions, frameColorID);
|
|
||||||
options.borderColor = env->GetIntField (jOptions, borderColorID);
|
|
||||||
options.borderRound = env->GetIntField (jOptions, borderRoundID);
|
|
||||||
options.roundingCorners = env->GetIntField (jOptions, roundingCornersID);
|
|
||||||
return ImGuiEx::BeginCollapseLayout(title, sizeX, sizeY, options);
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native void BeginCollapseLayout(boolean [] isOpen, String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions jOptions); /*-{ }-*/; /*
|
|
||||||
ImGuiCollapseLayoutOptions options;
|
|
||||||
options.paddingLeft = env->GetFloatField (jOptions, paddingLeftID);
|
|
||||||
options.paddingRight = env->GetFloatField (jOptions, paddingRightID);
|
|
||||||
options.paddingTop = env->GetFloatField (jOptions, paddingTopID);
|
|
||||||
options.paddingBottom = env->GetFloatField (jOptions, paddingBottomID);
|
|
||||||
options.arrowColor = env->GetIntField (jOptions, arrowColorID);
|
|
||||||
options.arrowBackgroundHoveredColor = env->GetIntField (jOptions, arrowBackgroundHoveredColorID);
|
|
||||||
options.arrowBackgroundClickedColor = env->GetIntField (jOptions, arrowBackgroundClickedColorID);
|
|
||||||
options.frameColor = env->GetIntField (jOptions, frameColorID);
|
|
||||||
options.borderColor = env->GetIntField (jOptions, borderColorID);
|
|
||||||
options.borderRound = env->GetIntField (jOptions, borderRoundID);
|
|
||||||
options.roundingCorners = env->GetIntField (jOptions, roundingCornersID);
|
|
||||||
ImGuiEx::BeginCollapseLayout(&isOpen[0], title, sizeX, sizeY, options);
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native void EndCollapseFrameLayout(); /*-{ }-*/; /*
|
|
||||||
ImGuiEx::EndCollapseFrameLayout();
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native void EndCollapseLayout(); /*-{ }-*/; /*
|
|
||||||
ImGuiEx::EndCollapseLayout();
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native void BeginAlign(String id, float sizeX, float sizeY, float alignX, float alignY) /*-{ }-*/; /*
|
|
||||||
ImGuiEx::BeginAlign(id, sizeX, sizeY, alignX, alignY);
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native void BeginAlign(String id, float sizeX, float sizeY, float alignX, float alignY, float offsetX, float offsetY) /*-{ }-*/; /*
|
|
||||||
ImGuiEx::BeginAlign(id, sizeX, sizeY, alignX, alignY, offsetX, offsetY);
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native void EndAlign() /*-{ }-*/; /*
|
|
||||||
ImGuiEx::EndAlign();
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native void AlignLayout(float alignX, float alignY) /*-{ }-*/; /*
|
|
||||||
ImGuiEx::AlignLayout(alignX, alignY);
|
|
||||||
*/
|
|
||||||
|
|
||||||
static native void AlignLayout(float alignX, float alignY, float offsetX, float offsetY) /*-{ }-*/; /*
|
|
||||||
ImGuiEx::AlignLayout(alignX, alignY, offsetX, offsetY);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
public static class ImGuiCollapseLayoutOptions {
|
|
||||||
public float paddingLeft = 2;
|
|
||||||
public float paddingRight = 2;
|
|
||||||
public float paddingTop = 2;
|
|
||||||
public float paddingBottom = 2;
|
|
||||||
public int arrowColor = ImGuiEx.colorToIntBits(0xFF, 0xFF, 0xFF, 0xFF);
|
|
||||||
public int arrowBackgroundHoveredColor = ImGuiEx.colorToIntBits(0x77, 0x77, 0x77, 0xFF);
|
|
||||||
public int arrowBackgroundClickedColor = ImGuiEx.colorToIntBits(0x55, 0x55, 0x55, 0xFF);
|
|
||||||
public int frameColor = ImGuiEx.colorToIntBits(0x24, 0x24, 0x24, 0xFF);
|
|
||||||
public int borderColor = ImGuiEx.colorToIntBits(0x40, 0x40, 0x49, 0xFF);
|
|
||||||
public int borderRound = 4;
|
|
||||||
public int roundingCorners = ImDrawCornerFlags.TopLeft.or(ImDrawCornerFlags.TopRight).getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package imgui;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Same as {@link Native} but "imgui_internal.h" API.
|
|
||||||
*/
|
|
||||||
class NativeInternal {
|
|
||||||
// @formatter:off
|
|
||||||
|
|
||||||
/*JNI
|
|
||||||
#include <imgui.h>
|
|
||||||
#include <imgui_internal.h>
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static native void PushMultiItemsWidths(int components, float w_full) /*-{ }-*/; /*
|
|
||||||
ImGui::PushMultiItemsWidths(components, w_full);
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static native boolean ItemAdd(float x1, float y1, float x2, float y2, String id) /*-{ }-*/; /*
|
|
||||||
ImGuiID imGuiID = ImGui::GetID(id);
|
|
||||||
return ImGui::ItemAdd(ImRect(x1, y1, x2, y2), imGuiID);
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static native void ItemSize(float x1, float y1, float x2, float y2, float text_offset_y) /*-{ }-*/; /*
|
|
||||||
ImGui::ItemSize(ImRect(x1, y1, x2, y2), text_offset_y);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// @formatter:on
|
|
||||||
}
|
|
||||||
@@ -1,512 +0,0 @@
|
|||||||
#include "imgui.h"
|
|
||||||
#include "imgui_internal.h"
|
|
||||||
#include "imgui_layout_widget.h"
|
|
||||||
|
|
||||||
static ImVector<ImGuiLayout *> layoutStack;
|
|
||||||
|
|
||||||
static ImGuiLayout *createOrFind(const char *id)
|
|
||||||
{
|
|
||||||
ImGuiContext &g = *GImGui;
|
|
||||||
ImGuiLayout *childLayout = NULL;
|
|
||||||
ImGuiID hashID = ImHashStr(id);
|
|
||||||
childLayout = (ImGuiLayout *)g.WindowsById.GetVoidPtr(hashID);
|
|
||||||
if (childLayout == NULL)
|
|
||||||
{
|
|
||||||
childLayout = IM_NEW(ImGuiLayout)(id);
|
|
||||||
g.WindowsById.SetVoidPtr(childLayout->id, childLayout);
|
|
||||||
}
|
|
||||||
return childLayout;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ImGuiLayout *pushLayout(const char *id)
|
|
||||||
{
|
|
||||||
ImGuiLayout *parentLayout = NULL;
|
|
||||||
if (!layoutStack.empty())
|
|
||||||
parentLayout = layoutStack.back();
|
|
||||||
ImGuiLayout *childLayout = createOrFind(id);
|
|
||||||
childLayout->parentLayout = parentLayout;
|
|
||||||
layoutStack.push_back(childLayout);
|
|
||||||
return childLayout;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGuiLayout *ImGuiEx::GetCurrentLayout()
|
|
||||||
{
|
|
||||||
if (layoutStack.empty())
|
|
||||||
return NULL;
|
|
||||||
return layoutStack.back();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void popLayout()
|
|
||||||
{
|
|
||||||
layoutStack.pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiEx::ShowLayoutDebug()
|
|
||||||
{
|
|
||||||
ImGuiLayout *curLayout = ImGuiEx::GetCurrentLayout();
|
|
||||||
if (curLayout != NULL)
|
|
||||||
{
|
|
||||||
curLayout->debug = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiEx::BeginLayoutEx(const char *strID)
|
|
||||||
{
|
|
||||||
ImGuiLayout *parentLayout = ImGuiEx::GetCurrentLayout();
|
|
||||||
ImGuiID id = ImHashStr(strID);
|
|
||||||
char title[256];
|
|
||||||
if (parentLayout)
|
|
||||||
ImFormatString(title, IM_ARRAYSIZE(title), "%s/%s_%08X", parentLayout->idStr, strID, id);
|
|
||||||
else
|
|
||||||
ImFormatString(title, IM_ARRAYSIZE(title), "%s/%08X", strID, id);
|
|
||||||
|
|
||||||
pushLayout(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGuiEx::PrepareLayout(float sizeX, float sizeY, float paddingLeft, float paddingRight, float paddingTop, float paddingBottom)
|
|
||||||
{
|
|
||||||
ImGuiContext &g = *GImGui;
|
|
||||||
ImGuiWindow *window = g.CurrentWindow;
|
|
||||||
|
|
||||||
ImGuiLayout *curLayout = ImGuiEx::GetCurrentLayout();
|
|
||||||
bool ret = true;
|
|
||||||
// Update layout
|
|
||||||
|
|
||||||
// Backup windows data
|
|
||||||
curLayout->DC = window->DC;
|
|
||||||
curLayout->WorkRect = window->WorkRect;
|
|
||||||
curLayout->skipping = window->SkipItems;
|
|
||||||
curLayout->AutoFitChildAxises = window->AutoFitChildAxises;
|
|
||||||
curLayout->Pos = window->Pos;
|
|
||||||
curLayout->ContentRegionRect = window->ContentRegionRect;
|
|
||||||
// ******** End Backup windows data
|
|
||||||
|
|
||||||
curLayout->sizeParam.x = sizeX;
|
|
||||||
curLayout->sizeParam.y = sizeY;
|
|
||||||
|
|
||||||
curLayout->paddingLeft = paddingLeft;
|
|
||||||
curLayout->paddingRight = paddingRight;
|
|
||||||
curLayout->paddingTop = paddingTop;
|
|
||||||
curLayout->paddingBottom = paddingBottom;
|
|
||||||
|
|
||||||
curLayout->position = window->DC.CursorPos;
|
|
||||||
|
|
||||||
ImVec2 contentPosition = curLayout->getPositionPadding();
|
|
||||||
|
|
||||||
curLayout->positionContents = curLayout->position;
|
|
||||||
|
|
||||||
const ImVec2 content_avail = ImGui::GetContentRegionAvail();
|
|
||||||
|
|
||||||
ImVec2 sizeItem = ImFloor(curLayout->sizeParam);
|
|
||||||
|
|
||||||
if (curLayout->sizeParam.x < 0.0f)
|
|
||||||
{
|
|
||||||
float sizeX = ImMax(content_avail.x + sizeItem.x, 4.0f);
|
|
||||||
curLayout->size.x = sizeX;
|
|
||||||
}
|
|
||||||
if (curLayout->sizeParam.y < 0.0f)
|
|
||||||
{
|
|
||||||
float sizeY = ImMax(content_avail.y + sizeItem.y, 4.0f);
|
|
||||||
curLayout->size.y = sizeY;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ***** End Update Layout
|
|
||||||
|
|
||||||
// Write to window object
|
|
||||||
|
|
||||||
window->Pos.x = contentPosition.x;
|
|
||||||
window->Pos.y = contentPosition.y;
|
|
||||||
window->DC.Indent.x = 0;
|
|
||||||
|
|
||||||
//window->DC.CursorMaxPos.x = contentPosition.x + curLayout->size.x - curLayout->paddingLeft - curLayout->paddingRight;
|
|
||||||
//window->DC.CursorMaxPos.y = contentPosition.y + curLayout->size.y - curLayout->paddingTop - curLayout->paddingBottom;
|
|
||||||
window->DC.CursorMaxPos.x = contentPosition.x;
|
|
||||||
window->DC.CursorMaxPos.y = contentPosition.y;
|
|
||||||
|
|
||||||
window->DC.CursorStartPos.x = contentPosition.x;
|
|
||||||
window->DC.CursorStartPos.y = contentPosition.y;
|
|
||||||
|
|
||||||
window->DC.CurrLineSize.y = 0; // necessary to keep position inside layout
|
|
||||||
window->DC.CurrLineTextBaseOffset = 0;
|
|
||||||
|
|
||||||
window->DC.CursorPos.x = contentPosition.x;
|
|
||||||
window->DC.CursorPos.y = contentPosition.y;
|
|
||||||
|
|
||||||
window->WorkRect.Min.x = contentPosition.x;
|
|
||||||
window->WorkRect.Min.y = contentPosition.y;
|
|
||||||
window->WorkRect.Max.x = contentPosition.x + curLayout->size.x - curLayout->paddingLeft - curLayout->paddingRight;
|
|
||||||
window->WorkRect.Max.y = contentPosition.y + curLayout->size.y - curLayout->paddingTop - curLayout->paddingBottom;
|
|
||||||
|
|
||||||
window->ContentRegionRect.Min.x = contentPosition.x;
|
|
||||||
window->ContentRegionRect.Min.y = contentPosition.y;
|
|
||||||
window->ContentRegionRect.Max.x = contentPosition.x + curLayout->size.x - curLayout->paddingLeft - curLayout->paddingRight;
|
|
||||||
window->ContentRegionRect.Max.y = contentPosition.y + curLayout->size.y - curLayout->paddingTop - curLayout->paddingBottom;
|
|
||||||
|
|
||||||
// ***** End Write to window object
|
|
||||||
|
|
||||||
if (curLayout->clipping)
|
|
||||||
{
|
|
||||||
ImVec2 min = curLayout->getPositionPadding();
|
|
||||||
ImVec2 max = curLayout->getAbsoluteSizePadding();
|
|
||||||
//ImGui::drawBoundingBox(min, max, 255, 0, 0);
|
|
||||||
ImGui::PushClipRect(min, max, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool skip_items = false;
|
|
||||||
if (window->Collapsed || !window->Active || window->Hidden)
|
|
||||||
/* if (window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && window->HiddenFramesCannotSkipItems <= 0)*/
|
|
||||||
skip_items = true;
|
|
||||||
window->SkipItems = skip_items;
|
|
||||||
ret = !skip_items;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGuiEx::BeginLayout(const char *strID, float sizeX, float sizeY, float paddingLeft, float paddingRight, float paddingTop, float paddingBottom)
|
|
||||||
{
|
|
||||||
BeginLayoutEx(strID);
|
|
||||||
return PrepareLayout(sizeX, sizeY, paddingLeft, paddingRight, paddingTop, paddingBottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiEx::EndLayout()
|
|
||||||
{
|
|
||||||
ImGuiContext &g = *GImGui;
|
|
||||||
ImGuiWindow *window = g.CurrentWindow;
|
|
||||||
ImGuiLayout *curLayout = ImGuiEx::GetCurrentLayout();
|
|
||||||
if (curLayout == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (curLayout->clipping)
|
|
||||||
ImGui::PopClipRect();
|
|
||||||
|
|
||||||
float x = window->DC.CursorPos.x;
|
|
||||||
float y = window->DC.CursorPos.y;
|
|
||||||
|
|
||||||
curLayout->sizeContents.x = window->DC.CursorMaxPos.x - x;
|
|
||||||
//curLayout->sizeContents.y = y - curLayout->position.y - g.Style.ItemSpacing.y;
|
|
||||||
|
|
||||||
//curLayout->sizeContents.x = window->DC.CursorMaxPos.x - curLayout->positionContents.x;
|
|
||||||
curLayout->sizeContents.y = y - curLayout->positionContents.y - g.Style.ItemSpacing.y;
|
|
||||||
|
|
||||||
// Restore windows data
|
|
||||||
window->DC = curLayout->DC;
|
|
||||||
window->WorkRect = curLayout->WorkRect;
|
|
||||||
window->SkipItems = curLayout->skipping;
|
|
||||||
window->AutoFitChildAxises = curLayout->AutoFitChildAxises;
|
|
||||||
window->Pos = curLayout->Pos;
|
|
||||||
window->ContentRegionRect = curLayout->ContentRegionRect;
|
|
||||||
// ********************
|
|
||||||
|
|
||||||
//const ImVec2 content_avail = GetContentRegionAvail();
|
|
||||||
ImVec2 sizeItem = curLayout->sizeParam;
|
|
||||||
|
|
||||||
if (sizeItem.x < 0.0f)
|
|
||||||
{
|
|
||||||
sizeItem.x = curLayout->size.x;
|
|
||||||
if (curLayout->size.x < curLayout->sizeContents.x || curLayout->size.x > curLayout->sizeContents.x)
|
|
||||||
{
|
|
||||||
//special case where dev used MATCH_CONTENT and WRAP_CONTENT wrong. The parent have a WRAP_CONTENT y size and the child have MATCH_CONTENT y size.
|
|
||||||
/* curLayout->error = true;
|
|
||||||
sizeItem.x = 10;*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (sizeItem.x == 0.0f)
|
|
||||||
sizeItem.x = curLayout->sizeContents.x + curLayout->paddingLeft + curLayout->paddingRight;
|
|
||||||
|
|
||||||
if (sizeItem.y < 0.0f)
|
|
||||||
{
|
|
||||||
sizeItem.y = curLayout->size.y;
|
|
||||||
if (curLayout->size.y < curLayout->sizeContents.y)
|
|
||||||
{
|
|
||||||
//special case where dev used MATCH_CONTENT and WRAP_CONTENT wrong. The parent have a WRAP_CONTENT y size and the child have MATCH_CONTENT y size.
|
|
||||||
//curLayout->error = true;
|
|
||||||
//sizeItem.y = curLayout->sizeContents.y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (sizeItem.y == 0.0f)
|
|
||||||
sizeItem.y = curLayout->sizeContents.y + curLayout->paddingBottom;
|
|
||||||
|
|
||||||
curLayout->size = sizeItem;
|
|
||||||
|
|
||||||
ImGui::ItemSize(sizeItem);
|
|
||||||
|
|
||||||
if (curLayout->debug)
|
|
||||||
{
|
|
||||||
curLayout->drawContentDebug();
|
|
||||||
curLayout->drawPaddingAreaDebug();
|
|
||||||
curLayout->drawSizeDebug();
|
|
||||||
curLayout->debug = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (curLayout->error)
|
|
||||||
{
|
|
||||||
curLayout->error = false;
|
|
||||||
curLayout->drawError();
|
|
||||||
}
|
|
||||||
|
|
||||||
popLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool renderFrameArrow(bool *value, int arrowColor, int arrowBackgroundHoveredColor, int arrowBackgroundClickedColor)
|
|
||||||
{
|
|
||||||
ImGuiContext &g = *GImGui;
|
|
||||||
ImGuiWindow *window = g.CurrentWindow;
|
|
||||||
|
|
||||||
ImDrawList *drawList = ImGui::GetWindowDrawList();
|
|
||||||
float getFrameHeight = ImGui::GetFrameHeight();
|
|
||||||
float removedSize = 5.5f; // reduce few pixels
|
|
||||||
float halfSize = (getFrameHeight) / 2.0f - removedSize;
|
|
||||||
|
|
||||||
ImVec2 vec = ImGui::GetCursorScreenPos();
|
|
||||||
|
|
||||||
float screenPosX = vec.x;
|
|
||||||
float screenPosY = vec.y;
|
|
||||||
float arrowPaddingLeft = 6;
|
|
||||||
|
|
||||||
float x = screenPosX + halfSize + arrowPaddingLeft;
|
|
||||||
float y = screenPosY + getFrameHeight / 2.0f;
|
|
||||||
|
|
||||||
bool hovered = ImGui::IsMouseHoveringRect(ImVec2(x - halfSize - removedSize, y - halfSize - removedSize), ImVec2(x + halfSize + removedSize, y + halfSize + removedSize));
|
|
||||||
ImU32 hoveredColor = arrowBackgroundHoveredColor;
|
|
||||||
bool isWindowHovered = ImGui::IsWindowHovered();
|
|
||||||
|
|
||||||
if (isWindowHovered)
|
|
||||||
{
|
|
||||||
if (hovered)
|
|
||||||
{
|
|
||||||
if (ImGui::IsMouseDown(0))
|
|
||||||
hoveredColor = arrowBackgroundClickedColor;
|
|
||||||
if (ImGui::IsMouseReleased(0))
|
|
||||||
*value = !*value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hovered)
|
|
||||||
drawList->AddCircleFilled(ImVec2(x, y), halfSize * 2, hoveredColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
float triA_X = 0;
|
|
||||||
float triA_Y = 0;
|
|
||||||
float triB_X = 0;
|
|
||||||
float triB_Y = 0;
|
|
||||||
float triC_X = 0;
|
|
||||||
float triC_Y = 0;
|
|
||||||
|
|
||||||
if (*value)
|
|
||||||
{
|
|
||||||
// arrow down
|
|
||||||
float offset = -0.5f;
|
|
||||||
triA_X = x - halfSize + offset;
|
|
||||||
triA_Y = y - halfSize;
|
|
||||||
triB_X = x + halfSize + offset;
|
|
||||||
triB_Y = y - halfSize;
|
|
||||||
triC_X = x + offset;
|
|
||||||
triC_Y = y + halfSize;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// arrow right
|
|
||||||
triA_X = x - halfSize;
|
|
||||||
triA_Y = y - halfSize;
|
|
||||||
triB_X = x + halfSize;
|
|
||||||
triB_Y = y;
|
|
||||||
triC_X = x - halfSize;
|
|
||||||
triC_Y = y + halfSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
drawList->AddTriangleFilled(ImVec2(triA_X, triA_Y), ImVec2(triB_X, triB_Y), ImVec2(triC_X, triC_Y), arrowColor);
|
|
||||||
|
|
||||||
float bk = g.Style.ItemSpacing.y;
|
|
||||||
g.Style.ItemSpacing.y = 0;
|
|
||||||
ImGui::ItemSize(ImVec2(halfSize * 2 + 3, getFrameHeight));
|
|
||||||
g.Style.ItemSpacing.y = bk;
|
|
||||||
|
|
||||||
return *value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int OPEN_KEY = 13213;
|
|
||||||
|
|
||||||
bool ImGuiEx::PrepareCollapseLayout(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options)
|
|
||||||
{
|
|
||||||
ImGuiContext &g = *GImGui;
|
|
||||||
ImGuiWindow *window = g.CurrentWindow;
|
|
||||||
ImDrawList *drawList = window->DrawList;
|
|
||||||
ImGuiLayout *rootLayout = ImGuiEx::GetCurrentLayout();
|
|
||||||
|
|
||||||
float frameHeight = ImGui::GetFrameHeight();
|
|
||||||
|
|
||||||
bool flag = rootLayout->map.GetBool(OPEN_KEY, false);
|
|
||||||
bool *isOpen = &flag;
|
|
||||||
|
|
||||||
sizeY = *isOpen ? sizeY : ImLayout::WRAP_PARENT;
|
|
||||||
|
|
||||||
ImGuiEx::PrepareLayout(sizeX, sizeY, 1, 1, 1, 1);
|
|
||||||
|
|
||||||
rootLayout->map.SetFloat(120, options.paddingLeft);
|
|
||||||
rootLayout->map.SetFloat(121, options.paddingRight);
|
|
||||||
rootLayout->map.SetFloat(122, options.paddingTop);
|
|
||||||
rootLayout->map.SetFloat(123, options.paddingBottom);
|
|
||||||
|
|
||||||
ImGuiEx::BeginLayout("frame", ImLayout::MATCH_PARENT, frameHeight, 0, 0, 0, 0);
|
|
||||||
ImGuiLayout *frameLayout = ImGuiEx::GetCurrentLayout();
|
|
||||||
|
|
||||||
ImVec2 mousePos = ImGui::GetMousePos();
|
|
||||||
|
|
||||||
drawList->AddRectFilled(rootLayout->position, ImVec2(rootLayout->getAbsoluteSize().x, frameLayout->getAbsoluteSize().y), options.frameColor, options.borderRound, options.roundingCorners);
|
|
||||||
|
|
||||||
renderFrameArrow(isOpen, options.arrowColor, options.arrowBackgroundHoveredColor, options.arrowBackgroundClickedColor);
|
|
||||||
|
|
||||||
rootLayout->map.SetBool(OPEN_KEY, *isOpen);
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
ImGuiEx::BeginAlign("align", ImLayout::WRAP_PARENT, ImLayout::MATCH_PARENT, 0, 0.5f, 0, 0);
|
|
||||||
|
|
||||||
ImGui::Text(title);
|
|
||||||
|
|
||||||
ImGuiEx::EndAlign();
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
return *isOpen;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiEx::BeginCollapseLayoutEx(bool *isOpen, const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options)
|
|
||||||
{
|
|
||||||
ImGuiEx::BeginLayoutEx(title);
|
|
||||||
ImGuiLayout *rootLayout = ImGuiEx::GetCurrentLayout();
|
|
||||||
rootLayout->map.SetBool(OPEN_KEY, *isOpen);
|
|
||||||
bool flag = ImGuiEx::PrepareCollapseLayout(title, sizeX, sizeY, options);
|
|
||||||
*isOpen = flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGuiEx::BeginCollapseLayoutEx(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options)
|
|
||||||
{
|
|
||||||
ImGuiEx::BeginLayoutEx(title);
|
|
||||||
return ImGuiEx::PrepareCollapseLayout(title, sizeX, sizeY, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImGuiEx::BeginCollapseLayout(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options)
|
|
||||||
{
|
|
||||||
bool flag = ImGuiEx::BeginCollapseLayoutEx(title, sizeX, sizeY, options);
|
|
||||||
ImGuiEx::EndCollapseFrameLayout();
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiEx::BeginCollapseLayout(bool *isOpen, const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options)
|
|
||||||
{
|
|
||||||
ImGuiEx::BeginCollapseLayoutEx(isOpen, title, sizeX, sizeY, options);
|
|
||||||
ImGuiEx::EndCollapseFrameLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiEx::EndCollapseFrameLayout()
|
|
||||||
{
|
|
||||||
ImGuiContext &g = *GImGui;
|
|
||||||
float bk = g.Style.ItemSpacing.y;
|
|
||||||
|
|
||||||
g.Style.ItemSpacing.y = 0;
|
|
||||||
ImGuiEx::EndLayout(); // end frame
|
|
||||||
g.Style.ItemSpacing.y = bk;
|
|
||||||
ImGuiLayout *rootLayout = ImGuiEx::GetCurrentLayout();
|
|
||||||
|
|
||||||
float paddingLeft = rootLayout->map.GetFloat(120, 0.0f);
|
|
||||||
float paddingRight = rootLayout->map.GetFloat(121, 0.0f);
|
|
||||||
float paddingTop = rootLayout->map.GetFloat(122, 0.0f);
|
|
||||||
float paddingBottom = rootLayout->map.GetFloat(123, 0.0f);
|
|
||||||
|
|
||||||
ImGuiEx::BeginLayout("content", ImLayout::MATCH_PARENT, ImLayout::WRAP_PARENT, paddingLeft, paddingRight, paddingTop, paddingBottom);
|
|
||||||
ImGuiLayout *collapseLayout = ImGuiEx::GetCurrentLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiEx::EndCollapseLayout()
|
|
||||||
{
|
|
||||||
ImGuiContext &g = *GImGui;
|
|
||||||
ImGuiWindow *window = g.CurrentWindow;
|
|
||||||
ImDrawList *drawList = window->DrawList;
|
|
||||||
|
|
||||||
ImU32 borderColor = ImGui::GetColorU32(ImVec4(0x40 / 255.0f, 0x40 / 255.0f, 0x49 / 255.0f, 255 / 255.0f));
|
|
||||||
int borderRound = 4;
|
|
||||||
int roundingCorners = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_TopRight;
|
|
||||||
|
|
||||||
ImGuiEx::EndLayout(); // end content
|
|
||||||
|
|
||||||
ImGuiLayout *rootLayout = ImGuiEx::GetCurrentLayout();
|
|
||||||
|
|
||||||
ImGuiEx::EndLayout(); // end root
|
|
||||||
|
|
||||||
ImVec2 borderPosition = rootLayout->position;
|
|
||||||
ImVec2 borderSize = rootLayout->getAbsoluteSize();
|
|
||||||
|
|
||||||
drawList->AddRect(borderPosition, borderSize, borderColor, borderRound, roundingCorners, 1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiEx::BeginAlign(const char *strID, float sizeX, float sizeY, float alignX, float alignY, float offsetX, float offsetY)
|
|
||||||
{
|
|
||||||
ImGuiEx::BeginLayout(strID, sizeX, sizeY);
|
|
||||||
ImGuiEx::AlignLayout(alignX, alignY, offsetX, offsetY);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiEx::AlignLayout(float alignX, float alignY, float offsetX, float offsetY)
|
|
||||||
{
|
|
||||||
ImGuiContext &g = *GImGui;
|
|
||||||
ImGuiWindow *window = g.CurrentWindow;
|
|
||||||
ImGuiLayout *curLayout = ImGuiEx::GetCurrentLayout();
|
|
||||||
if (curLayout == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
|
|
||||||
float totalX = regionAvail.x;
|
|
||||||
float totalY = regionAvail.y;
|
|
||||||
|
|
||||||
ImVec2 posPad = curLayout->getPositionPadding();
|
|
||||||
ImVec2 absSizePad = curLayout->getAbsoluteSizePadding();
|
|
||||||
|
|
||||||
if (alignX >= 0.0f && curLayout->sizeParam.x != ImLayout::WRAP_PARENT)
|
|
||||||
{
|
|
||||||
|
|
||||||
float addX = ImFloor((totalX - curLayout->sizeContents.x) * alignX);
|
|
||||||
float newX = posPad.x + addX + offsetX;
|
|
||||||
if (newX < posPad.x)
|
|
||||||
{
|
|
||||||
curLayout->error = true;
|
|
||||||
newX = posPad.x;
|
|
||||||
}
|
|
||||||
else if (newX + curLayout->sizeContents.x > absSizePad.x)
|
|
||||||
{
|
|
||||||
curLayout->error = true;
|
|
||||||
newX = absSizePad.x - curLayout->sizeContents.x;
|
|
||||||
}
|
|
||||||
curLayout->positionContents.x = newX;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alignY >= 0.0f && curLayout->sizeParam.y != ImLayout::WRAP_PARENT)
|
|
||||||
{
|
|
||||||
float addY = ImFloor((totalY - curLayout->sizeContents.y) * alignY);
|
|
||||||
float newY = posPad.y + addY + offsetY;
|
|
||||||
if (newY < posPad.y)
|
|
||||||
{
|
|
||||||
curLayout->error = true;
|
|
||||||
newY = posPad.y;
|
|
||||||
}
|
|
||||||
else if (newY + curLayout->sizeContents.y > absSizePad.y)
|
|
||||||
{
|
|
||||||
curLayout->error = true;
|
|
||||||
newY = absSizePad.y - curLayout->sizeContents.y;
|
|
||||||
}
|
|
||||||
curLayout->positionContents.y = newY;
|
|
||||||
}
|
|
||||||
window->DC.CursorMaxPos.x = curLayout->positionContents.x;
|
|
||||||
window->DC.CursorMaxPos.y = curLayout->positionContents.y;
|
|
||||||
|
|
||||||
window->DC.CursorStartPos.x = curLayout->positionContents.x;
|
|
||||||
window->DC.CursorStartPos.y = curLayout->positionContents.y;
|
|
||||||
|
|
||||||
window->Pos.x = curLayout->positionContents.x;
|
|
||||||
window->Pos.y = curLayout->positionContents.y;
|
|
||||||
|
|
||||||
window->DC.CursorPos.x = curLayout->positionContents.x;
|
|
||||||
window->DC.CursorPos.y = curLayout->positionContents.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiEx::EndAlign()
|
|
||||||
{
|
|
||||||
ImGuiEx::EndLayout();
|
|
||||||
}
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#include "imgui_internal.h"
|
|
||||||
|
|
||||||
namespace ImGuiEx
|
|
||||||
{
|
|
||||||
inline void drawBoundingBox(float x1, float y1, float x2, float y2, int r, int g, int b, bool clipping = false)
|
|
||||||
{
|
|
||||||
ImDrawList *drawList = clipping ? ImGui::GetWindowDrawList() : ImGui::GetForegroundDrawList();
|
|
||||||
|
|
||||||
float rounding = 0;
|
|
||||||
int color = ImGui::GetColorU32(ImVec4(r / 255.0f, g / 255.0f, b / 255.0f, 205.0f / 255.0f));
|
|
||||||
drawList->AddRect(ImVec2(x1, y1), ImVec2(x2, y2), color, rounding);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void drawBoundingBox(ImVec2 min, ImVec2 max, int r, int g, int b, bool clipping = false)
|
|
||||||
{
|
|
||||||
ImGuiEx::drawBoundingBox(min.x, min.y, max.x, max.y, r, g, b, clipping);
|
|
||||||
}
|
|
||||||
}; // namespace ImGuiEx
|
|
||||||
|
|
||||||
struct ImGuiLayout
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
char *idStr;
|
|
||||||
ImGuiID id;
|
|
||||||
ImGuiLayout *parentLayout;
|
|
||||||
|
|
||||||
bool clipping;
|
|
||||||
bool debug;
|
|
||||||
|
|
||||||
ImGuiStorage map;
|
|
||||||
|
|
||||||
ImVec2 position; // Position of the layout
|
|
||||||
ImVec2 size; // Size of the layout
|
|
||||||
ImVec2 sizeParam; // Size parameter used when calling beginLayout
|
|
||||||
float paddingLeft;
|
|
||||||
float paddingRight;
|
|
||||||
float paddingTop;
|
|
||||||
float paddingBottom;
|
|
||||||
ImVec2 positionContents; // Position of contents.
|
|
||||||
ImVec2 sizeContents; // Size of contents. calculated after the first frame
|
|
||||||
|
|
||||||
bool error;
|
|
||||||
|
|
||||||
// Window Backup data
|
|
||||||
ImGuiWindowTempData DC;
|
|
||||||
ImRect WorkRect;
|
|
||||||
bool skipping;
|
|
||||||
int AutoFitChildAxises;
|
|
||||||
ImVec2 Pos;
|
|
||||||
ImRect ContentRegionRect;
|
|
||||||
|
|
||||||
ImGuiLayout(const char *idStr)
|
|
||||||
{
|
|
||||||
this->idStr = ImStrdup(idStr);
|
|
||||||
this->id = ImHashStr(idStr);
|
|
||||||
paddingLeft = 0;
|
|
||||||
paddingRight = 0;
|
|
||||||
paddingTop = 0;
|
|
||||||
paddingBottom = 0;
|
|
||||||
clipping = true;
|
|
||||||
debug = false;
|
|
||||||
error = false;
|
|
||||||
skipping = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool haveParent() { return parentLayout != NULL; }
|
|
||||||
|
|
||||||
ImVec2 getAbsoluteSize()
|
|
||||||
{
|
|
||||||
return ImVec2(position.x + size.x, position.y + size.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImVec2 getContentSize()
|
|
||||||
{
|
|
||||||
return ImVec2(position.x + sizeContents.x, position.y + sizeContents.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImVec2 getAbsoluteSizePadding()
|
|
||||||
{
|
|
||||||
return ImVec2(position.x + size.x - paddingRight, position.y + size.y - paddingBottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImVec2 getContentSizePadding()
|
|
||||||
{
|
|
||||||
return ImVec2(position.x + sizeContents.x + paddingLeft, position.y + sizeContents.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImVec2 getPositionPadding()
|
|
||||||
{
|
|
||||||
return ImVec2(position.x + paddingLeft, position.y + paddingTop);
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawSizeDebug()
|
|
||||||
{
|
|
||||||
// Render layout space
|
|
||||||
//Green
|
|
||||||
ImGuiEx::drawBoundingBox(position, getAbsoluteSize(), 0, 255, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void drawContentDebug()
|
|
||||||
{
|
|
||||||
// Render content space
|
|
||||||
// Blue
|
|
||||||
ImVec2 max = ImVec2(positionContents.x + sizeContents.x, positionContents.y + sizeContents.y);
|
|
||||||
ImGuiEx::drawBoundingBox(positionContents, max, 0, 0, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawPaddingAreaDebug()
|
|
||||||
{
|
|
||||||
// Render size with padding
|
|
||||||
ImGuiEx::drawBoundingBox(getPositionPadding(), getAbsoluteSizePadding(), 255, 255, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawError()
|
|
||||||
{
|
|
||||||
ImGuiEx::drawBoundingBox(position, getAbsoluteSize(), 255, 0, 0, true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ImGuiCollapseLayoutOptions
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
float paddingLeft;
|
|
||||||
float paddingRight;
|
|
||||||
float paddingTop;
|
|
||||||
float paddingBottom;
|
|
||||||
ImU32 arrowColor;
|
|
||||||
ImU32 arrowBackgroundHoveredColor;
|
|
||||||
ImU32 arrowBackgroundClickedColor;
|
|
||||||
ImU32 frameColor;
|
|
||||||
ImU32 borderColor;
|
|
||||||
int borderRound;
|
|
||||||
int roundingCorners;
|
|
||||||
|
|
||||||
ImGuiCollapseLayoutOptions()
|
|
||||||
{
|
|
||||||
paddingLeft = 2;
|
|
||||||
paddingRight = 2;
|
|
||||||
paddingTop = 2;
|
|
||||||
paddingBottom = 2;
|
|
||||||
arrowColor = ImGui::GetColorU32(ImVec4(0xFF / 255.0f, 0xFF / 255.0f, 0xFF / 255.0f, 0xFF / 255.0f));
|
|
||||||
arrowBackgroundHoveredColor = ImGui::GetColorU32(ImVec4(0x77 / 255.0f, 0x77 / 255.0f, 0x77 / 255.0f, 0xFF / 255.0f));
|
|
||||||
arrowBackgroundClickedColor = ImGui::GetColorU32(ImVec4(0x55 / 255.0f, 0x55 / 255.0f, 0x55 / 255.0f, 0xFF / 255.0f));
|
|
||||||
frameColor = ImGui::GetColorU32(ImVec4(0x24 / 255.0f, 0x24 / 255.0f, 0x24 / 255.0f, 255 / 255.0f));
|
|
||||||
borderColor = ImGui::GetColorU32(ImVec4(0x40 / 255.0f, 0x40 / 255.0f, 0x49 / 255.0f, 255 / 255.0f));
|
|
||||||
borderRound = 4;
|
|
||||||
roundingCorners = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_TopRight;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace ImGuiEx
|
|
||||||
{
|
|
||||||
void ShowLayoutDebug();
|
|
||||||
|
|
||||||
void BeginLayoutEx(const char *id);
|
|
||||||
bool PrepareLayout(float sizeX, float sizeY, float paddingLeft = 0, float paddingRight = 0, float paddingTop = 0, float paddingBottom = 0);
|
|
||||||
bool BeginLayout(const char *id, float sizeX, float sizeY, float paddingLeft = 0, float paddingRight = 0, float paddingTop = 0, float paddingBottom = 0);
|
|
||||||
void EndLayout();
|
|
||||||
ImGuiLayout *GetCurrentLayout();
|
|
||||||
|
|
||||||
bool BeginCollapseLayoutEx(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions());
|
|
||||||
void BeginCollapseLayoutEx(bool *isOpen, const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions());
|
|
||||||
bool PrepareCollapseLayout(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions());
|
|
||||||
bool BeginCollapseLayout(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions());
|
|
||||||
void BeginCollapseLayout(bool *isOpen, const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions());
|
|
||||||
void EndCollapseFrameLayout();
|
|
||||||
void EndCollapseLayout();
|
|
||||||
|
|
||||||
void BeginAlign(const char *id, float sizeX, float sizeY, float alignX = 0.0f, float alignY = 0.0f, float offsetX = 0, float offsetY = 0);
|
|
||||||
void AlignLayout(float alignX = 0.0f, float alignY = 0.0f, float offsetX = 0, float offsetY = 0);
|
|
||||||
void EndAlign();
|
|
||||||
}; // namespace ImGuiEx
|
|
||||||
|
|
||||||
namespace ImLayout
|
|
||||||
{
|
|
||||||
static float WRAP_PARENT = 0;
|
|
||||||
static float MATCH_PARENT = -0.1f;
|
|
||||||
} // namespace ImLayout
|
|
||||||
Reference in new issue
Block a user