Skip to content

Commit

Permalink
[Example] Adjust Canva Editor example (SpaiR#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidalmarinho committed Apr 29, 2022
1 parent 1aecc30 commit 5941851
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
22 changes: 10 additions & 12 deletions example/src/main/java/ExampleCanvaEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.List;

public class ExampleCanvaEditor {
private static final String URL = "https://github.com/ocornut/imgui";

private static final List<ImVec2> pointList = new ArrayList<>();
private static final ImVec2 scrolling = new ImVec2();

Expand Down Expand Up @@ -37,13 +35,6 @@ public static void show(final ImBoolean showCanvaWindow) {
imgui.internal.ImGui.alignTextToFramePadding();
imgui.internal.ImGui.text("Repo:");
imgui.internal.ImGui.sameLine();
if (imgui.internal.ImGui.button(URL)) {
try {
Desktop.getDesktop().browse(new URI(URL));
} catch (Exception e) {
e.printStackTrace();
}
}
imgui.internal.ImGui.text("Mouse Left: drag to add lines,\nMouse Right: drag to scroll, click for context menu.");

// Typically, you would use a BeginChild()/EndChild() pair to benefit from a clipping region + own scrolling.
Expand All @@ -61,8 +52,14 @@ public static void show(final ImBoolean showCanvaWindow) {
ImVec2 canvasP0 = ImGui.getCursorScreenPos(); // ImDrawList API uses screen coordinates!
ImVec2 canvasSize = ImGui.getContentRegionAvail(); // Resize canvas to what's available

if (canvasSize.x < 50.0f) canvasSize.x = 50.0f;
if (canvasSize.y < 50.0f) canvasSize.y = 50.0f;
if (canvasSize.x < 50.0f) {
canvasSize.x = 50.0f;
}

if (canvasSize.y < 50.0f) {
canvasSize.y = 50.0f;
}

ImVec2 canvasP1 = new ImVec2(canvasP0.x + canvasSize.x, canvasP0.y + canvasSize.y);

// Draw border and background color
Expand Down Expand Up @@ -92,8 +89,9 @@ public static void show(final ImBoolean showCanvaWindow) {
}
if (addingLine) {
pointList.set(pointList.size() - 1, mousePosInCanvas);
if (!ImGui.isMouseDown(ImGuiMouseButton.Left))
if (!ImGui.isMouseDown(ImGuiMouseButton.Left)) {
addingLine = false;
}
}

// Pan (we use a zero mouse threshold when there's no context menu)
Expand Down
1 change: 1 addition & 0 deletions example/src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private void initFonts(final ImGuiIO io) {

@Override
public void process() {
ImGui.setWindowSize(400, 410);
ImGui.text("Hello, World! " + FontAwesomeIcons.Smile);
if (ImGui.button(FontAwesomeIcons.Save + " Save")) {
count++;
Expand Down

0 comments on commit 5941851

Please sign in to comment.