Add ImColor helper. Increase flexibility of the color API
In most of the places it's now possible to provide a simple int value, instead of float numbers.
This commit is contained in:
1 parent
71e7265858
commit
8ac87a9606
4 files changed
+88
-9
No files matched your search
@@ -0,0 +1,48 @@
|
|||||||
|
package imgui;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class to get ABGR packed color used by Dear ImGui.
|
||||||
|
*/
|
||||||
|
public final class ImColor {
|
||||||
|
private ImColor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int get32(final int r, final int g, final int b, final int a) {
|
||||||
|
return a << 24 | b << 16 | g << 8 | r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int get32(final int r, final int g, final int b) {
|
||||||
|
return get32(r, g, b, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int get32(final float r, final float g, final float b, final float a) {
|
||||||
|
return get32((int) (r * 255), (int) (g * 255), (int) (b * 255), (int) (a * 255));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int get32(final float r, final float g, final float b) {
|
||||||
|
return get32(r, g, b, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param hex e.g. "#FFFFFF"
|
||||||
|
*/
|
||||||
|
public static int get32RGBHex(final String hex) {
|
||||||
|
return get32(
|
||||||
|
Integer.parseInt(hex.substring(1, 3), 16),
|
||||||
|
Integer.parseInt(hex.substring(3, 5), 16),
|
||||||
|
Integer.parseInt(hex.substring(5, 7), 16)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param hex e.g. "#FFFFFFFF"
|
||||||
|
*/
|
||||||
|
public static int get32RGBAHex(final String hex) {
|
||||||
|
return get32(
|
||||||
|
Integer.parseInt(hex.substring(1, 3), 16),
|
||||||
|
Integer.parseInt(hex.substring(3, 5), 16),
|
||||||
|
Integer.parseInt(hex.substring(5, 7), 16),
|
||||||
|
Integer.parseInt(hex.substring(7, 9), 16)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -877,12 +877,16 @@ public final class ImGui {
|
|||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static native void pushStyleColor(int imGuiCol, int col); /*
|
public static native void pushStyleColor(int imGuiCol, float r, float g, float b, float a); /*
|
||||||
ImGui::PushStyleColor(imGuiCol, col);
|
ImGui::PushStyleColor(imGuiCol, (ImU32)ImColor(r, g, b, a));
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static native void pushStyleColor(int imGuiCol, float r, float g, float b, float a); /*
|
public static native void pushStyleColor(int imGuiCol, int r, int g, int b, int a); /*
|
||||||
ImGui::PushStyleColor(imGuiCol, ImVec4(r, g, b, a));
|
ImGui::PushStyleColor(imGuiCol, (ImU32)ImColor(r, g, b, a));
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static native void pushStyleColor(int imGuiCol, int col); /*
|
||||||
|
ImGui::PushStyleColor(imGuiCol, col);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static native void popStyleColor(); /*
|
public static native void popStyleColor(); /*
|
||||||
@@ -1325,7 +1329,21 @@ public final class ImGui {
|
|||||||
* Shortcut for PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();
|
* Shortcut for PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();
|
||||||
*/
|
*/
|
||||||
public static native void textColored(float r, float g, float b, float a, String text); /*
|
public static native void textColored(float r, float g, float b, float a, String text); /*
|
||||||
ImGui::TextColored(ImVec4(r, g, b, a), text, NULL);
|
ImGui::TextColored(ImColor(r, g, b, a), text, NULL);
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shortcut for PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();
|
||||||
|
*/
|
||||||
|
public static native void textColored(int r, int g, int b, int a, String text); /*
|
||||||
|
ImGui::TextColored(ImColor(r, g, b, a), text, NULL);
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shortcut for PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();
|
||||||
|
*/
|
||||||
|
public static native void textColored(int col, String text); /*
|
||||||
|
ImGui::TextColored(ImColor(col), text, NULL);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -602,7 +602,15 @@ public final class ImGuiStyle implements ImGuiDestroyableStruct {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public native void setColor(int imGuiCol, float r, float g, float b, float a); /*
|
public native void setColor(int imGuiCol, float r, float g, float b, float a); /*
|
||||||
IMGUI_STYLE->Colors[imGuiCol] = ImVec4(r, g, b, a);
|
IMGUI_STYLE->Colors[imGuiCol] = ImColor(r, g, b, a);
|
||||||
|
*/
|
||||||
|
|
||||||
|
public native void setColor(int imGuiCol, int r, int g, int b, int a); /*
|
||||||
|
IMGUI_STYLE->Colors[imGuiCol] = ImColor(r, g, b, a);
|
||||||
|
*/
|
||||||
|
|
||||||
|
public native void setColor(int imGuiCol, int col); /*
|
||||||
|
IMGUI_STYLE->Colors[imGuiCol] = ImColor(col);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public native void scaleAllSizes(float scaleFactor); /*
|
public native void scaleAllSizes(float scaleFactor); /*
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import imgui.ImBool;
|
import imgui.ImBool;
|
||||||
|
import imgui.ImColor;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.ImString;
|
import imgui.ImString;
|
||||||
import imgui.ImVec2;
|
import imgui.ImVec2;
|
||||||
@@ -18,6 +19,10 @@ import static org.lwjgl.opengl.GL32.*;
|
|||||||
final class ExampleUi {
|
final class ExampleUi {
|
||||||
private static final String IMGUI_DEMO_LINK = "https://raw.githubusercontent.com/ocornut/imgui/v1.76/imgui_demo.cpp";
|
private static final String IMGUI_DEMO_LINK = "https://raw.githubusercontent.com/ocornut/imgui/v1.76/imgui_demo.cpp";
|
||||||
|
|
||||||
|
private static final int DODGERBLUE_COLOR = ImColor.get32RGBHex("#1E90FF");
|
||||||
|
private static final int CORAL_COLOR = ImColor.get32RGBHex("#FF7F50");
|
||||||
|
private static final int LIMEGREEN_COLOR = ImColor.get32RGBHex("#32CD32");
|
||||||
|
|
||||||
// Test data for payload
|
// Test data for payload
|
||||||
private final byte[] testPayload = "Test Payload".getBytes();
|
private final byte[] testPayload = "Test Payload".getBytes();
|
||||||
private String dropTargetText = "Drop Here";
|
private String dropTargetText = "Drop Here";
|
||||||
@@ -86,11 +91,11 @@ final class ExampleUi {
|
|||||||
ImGui.inputText("Resizable input", resizableStr, ImGuiInputTextFlags.CallbackResize);
|
ImGui.inputText("Resizable input", resizableStr, ImGuiInputTextFlags.CallbackResize);
|
||||||
ImGui.text("text len:");
|
ImGui.text("text len:");
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
ImGui.textColored(.12f, .6f, 1, 1, Integer.toString(resizableStr.getLength()));
|
ImGui.textColored(DODGERBLUE_COLOR, Integer.toString(resizableStr.getLength()));
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
ImGui.text("| buffer size:");
|
ImGui.text("| buffer size:");
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
ImGui.textColored(1, .6f, 0, 1, Integer.toString(resizableStr.getBufferSize()));
|
ImGui.textColored(CORAL_COLOR, Integer.toString(resizableStr.getBufferSize()));
|
||||||
|
|
||||||
ImGui.separator();
|
ImGui.separator();
|
||||||
ImGui.newLine();
|
ImGui.newLine();
|
||||||
@@ -98,7 +103,7 @@ final class ExampleUi {
|
|||||||
// Link to the original demo file
|
// Link to the original demo file
|
||||||
ImGui.text("Consider to look the original ImGui demo: ");
|
ImGui.text("Consider to look the original ImGui demo: ");
|
||||||
ImGui.setNextItemWidth(500);
|
ImGui.setNextItemWidth(500);
|
||||||
ImGui.textColored(0, .8f, 0, 1, IMGUI_DEMO_LINK);
|
ImGui.textColored(LIMEGREEN_COLOR, IMGUI_DEMO_LINK);
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button("Copy")) {
|
if (ImGui.button("Copy")) {
|
||||||
ImGui.setClipboardText(IMGUI_DEMO_LINK);
|
ImGui.setClipboardText(IMGUI_DEMO_LINK);
|
||||||
|
|||||||
Reference in new issue
Block a user