Skip to content

Commit ff6322a

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

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-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: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package imgui.app;
22

3+
import imgui.ImColor;
4+
35
/**
46
* Application class from which ImGui applications extend.
57
* Serves as an abstraction layer to hide all low-level details about window creation and rendering routine.
@@ -52,27 +54,33 @@
5254
* For example, large list of computations could be separated between application ticks. {@link #process()} method is called constantly.
5355
* Use that wisely and remember that all GUI should be in the main thread.
5456
*/
55-
public abstract class Application extends Window {
57+
public abstract class Application {
58+
59+
protected abstract void init(Configuration config);
60+
5661
/**
5762
* Method called before window creation. Could be used to provide basic window information, like title name etc.
5863
*
5964
* @param config configuration object with basic window information
6065
*/
61-
protected void configure(final Configuration config) {
62-
}
66+
protected abstract void configure(final Configuration config);
6367

6468
/**
6569
* Method called once, before application run loop.
6670
*/
6771
protected void preRun() {
6872
}
6973

74+
protected abstract void run();
75+
7076
/**
7177
* Method called once, after application run loop.
7278
*/
7379
protected void postRun() {
7480
}
7581

82+
protected abstract void dispose();
83+
7684
/**
7785
* Entry point of any ImGui application. Use it to start the application loop.
7886
*
@@ -91,4 +99,6 @@ private static void initialize(final Application app) {
9199
app.configure(config);
92100
app.init(config);
93101
}
102+
103+
public abstract Color getColorBg();
94104
}

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)