Skip to content

Commit

Permalink
Flip inheritance hierarchy between Application and Window
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Gredal committed Mar 24, 2023
1 parent 5c2bf1c commit 40910b9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions example/src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import imgui.ImFontGlyphRangesBuilder;
import imgui.ImGui;
import imgui.ImGuiIO;
import imgui.app.Application;
import imgui.app.BGFXWindow;
import imgui.app.Configuration;
import imgui.flag.ImGuiConfigFlags;
import imgui.flag.ImGuiInputTextFlags;
Expand All @@ -14,7 +14,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;

public class Main extends Application {
public class Main extends BGFXWindow {
private final ImString str = new ImString(5);
private final float[] flt = new float[1];
private int count = 0;
Expand Down
14 changes: 11 additions & 3 deletions imgui-app/src/main/java/imgui/app/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,33 @@
* For example, large list of computations could be separated between application ticks. {@link #process()} method is called constantly.
* Use that wisely and remember that all GUI should be in the main thread.
*/
public abstract class Application extends Window {
public abstract class Application {

protected abstract void init(Configuration config);

/**
* Method called before window creation. Could be used to provide basic window information, like title name etc.
*
* @param config configuration object with basic window information
*/
protected void configure(final Configuration config) {
}
protected abstract void configure(final Configuration config);

/**
* Method called once, before application run loop.
*/
protected void preRun() {
}

protected abstract void run();

/**
* Method called once, after application run loop.
*/
protected void postRun() {
}

protected abstract void dispose();

/**
* Entry point of any ImGui application. Use it to start the application loop.
*
Expand All @@ -91,4 +97,6 @@ private static void initialize(final Application app) {
app.configure(config);
app.init(config);
}

public abstract Color getColorBg();
}
2 changes: 1 addition & 1 deletion imgui-app/src/main/java/imgui/app/BGFXWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static org.lwjgl.system.Configuration.GLFW_LIBRARY_NAME;
import static org.lwjgl.system.MemoryStack.stackPush;

public abstract class BGFXWindow {
public abstract class BGFXWindow extends Application {
private final ImGuiImplBGFX imGuiBGFX = new ImGuiImplBGFX();
private final ImGuiImplGlfw imGuiGlfw = new ImGuiImplGlfw();

Expand Down
6 changes: 3 additions & 3 deletions imgui-app/src/main/java/imgui/app/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* It's recommended to use {@link Application}, but this class could be extended directly as well.
* When extended, life-cycle methods should be called manually.
*/
public abstract class Window {
public abstract class Window extends Application {

private final ImGuiImplGlfw imGuiGlfw = new ImGuiImplGlfw();
private final ImGuiImplGl3 imGuiGl3 = new ImGuiImplGl3();
Expand All @@ -44,7 +44,7 @@ public abstract class Window {
*
* @param config configuration object with basic window information
*/
protected void init(final Configuration config) {
public final void init(final Configuration config) {
initWindow(config);
initImGui(config);
imGuiGlfw.init(handle, true);
Expand All @@ -54,7 +54,7 @@ protected void init(final Configuration config) {
/**
* Method to dispose all used application resources and destroy its window.
*/
protected void dispose() {
public final void dispose() {
imGuiGl3.dispose();
imGuiGlfw.dispose();
disposeImGui();
Expand Down

0 comments on commit 40910b9

Please sign in to comment.