Skip to content

Commit b2a64a7

Browse files
author
Mathias Gredal
committed
Flip inheritance hierarchy between Application and Window
1 parent 17a8a3b commit b2a64a7

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

example/src/main/java/Main.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import imgui.ImFontGlyphRangesBuilder;
33
import imgui.ImGui;
44
import imgui.ImGuiIO;
5-
import imgui.app.Application;
5+
import imgui.app.BGFXWindow;
66
import imgui.app.Configuration;
77
import imgui.flag.ImGuiConfigFlags;
88
import imgui.flag.ImGuiInputTextFlags;
@@ -14,7 +14,7 @@
1414
import java.nio.file.Files;
1515
import java.nio.file.Paths;
1616

17-
public class Main extends Application {
17+
public class Main extends BGFXWindow {
1818
private final ImString str = new ImString(5);
1919
private final float[] flt = new float[1];
2020
private int count = 0;

imgui-app/src/main/java/imgui/app/Application.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,33 @@
5252
* For example, large list of computations could be separated between application ticks. {@link #process()} method is called constantly.
5353
* Use that wisely and remember that all GUI should be in the main thread.
5454
*/
55-
public abstract class Application extends Window {
55+
public abstract class Application {
56+
57+
protected abstract void init(Configuration config);
58+
5659
/**
5760
* Method called before window creation. Could be used to provide basic window information, like title name etc.
5861
*
5962
* @param config configuration object with basic window information
6063
*/
61-
protected void configure(final Configuration config) {
62-
}
64+
protected abstract void configure(final Configuration config);
6365

6466
/**
6567
* Method called once, before application run loop.
6668
*/
6769
protected void preRun() {
6870
}
6971

72+
protected abstract void run();
73+
7074
/**
7175
* Method called once, after application run loop.
7276
*/
7377
protected void postRun() {
7478
}
7579

80+
protected abstract void dispose();
81+
7682
/**
7783
* Entry point of any ImGui application. Use it to start the application loop.
7884
*
@@ -91,4 +97,6 @@ private static void initialize(final Application app) {
9197
app.configure(config);
9298
app.init(config);
9399
}
100+
101+
public abstract Color getColorBg();
94102
}

imgui-app/src/main/java/imgui/app/BGFXWindow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import static org.lwjgl.system.Configuration.GLFW_LIBRARY_NAME;
2121
import static org.lwjgl.system.MemoryStack.stackPush;
2222

23-
public abstract class BGFXWindow {
23+
public abstract class BGFXWindow extends Application {
2424
private final ImGuiImplBGFX imGuiBGFX = new ImGuiImplBGFX();
2525
private final ImGuiImplGlfw imGuiGlfw = new ImGuiImplGlfw();
2626

imgui-app/src/main/java/imgui/app/Window.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* It's recommended to use {@link Application}, but this class could be extended directly as well.
2323
* When extended, life-cycle methods should be called manually.
2424
*/
25-
public abstract class Window {
25+
public abstract class Window extends Application {
2626

2727
private final ImGuiImplGlfw imGuiGlfw = new ImGuiImplGlfw();
2828
private final ImGuiImplGl3 imGuiGl3 = new ImGuiImplGl3();
@@ -44,7 +44,7 @@ public abstract class Window {
4444
*
4545
* @param config configuration object with basic window information
4646
*/
47-
protected void init(final Configuration config) {
47+
public final void init(final Configuration config) {
4848
initWindow(config);
4949
initImGui(config);
5050
imGuiGlfw.init(handle, true);
@@ -54,7 +54,7 @@ protected void init(final Configuration config) {
5454
/**
5555
* Method to dispose all used application resources and destroy its window.
5656
*/
57-
protected void dispose() {
57+
public final void dispose() {
5858
imGuiGl3.dispose();
5959
imGuiGlfw.dispose();
6060
disposeImGui();

0 commit comments

Comments
 (0)