Skip to content

Commit

Permalink
added MRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
Osiris-Team committed Jan 29, 2023
1 parent caf23b1 commit 8d74bd5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ public class Main {
App.name = "My-App";

// Create routes
Route home = new Route("/"){
@Override
public Component<?> loadContent() {
return new Layout().text("Hello World!");
}
};
Route home = new MRoute("/", () -> { // You can also create a new class and extend Route
return new Layout().text("Hello World!");
});

// Create windows
new NativeWindow(home);
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/osiris/desku/MRoute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.osiris.desku;

import com.osiris.desku.ui.Component;

import java.util.function.Supplier;

/**
* MRoute (MutableRoute) uses a public, modifiable function that gets executed at {@link #loadContent()},
* which makes it possible to use lambdas.
*/
public class MRoute extends Route{
public Supplier<Component<?>> onLoad;

public MRoute(String path, Supplier<Component<?>> onLoad) {
super(path);
this.onLoad = onLoad;
}

@Override
public Component<?> loadContent() {
return onLoad.get();
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/osiris/desku/ui/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class Text extends Component<Text> {
public Text(String s) {
init(this, "p");
init(this, "txt");
element.appendText(s);
}

Expand Down
10 changes: 3 additions & 7 deletions src/test/java/com/osiris/desku/HelloWorldApp.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.osiris.desku;

import com.osiris.desku.swing.NativeWindow;
import com.osiris.desku.ui.Component;
import com.osiris.desku.ui.Layout;

import java.io.IOException;
Expand All @@ -12,12 +11,9 @@ public static void main(String[] args) throws IOException {
App.name = "My-App";

// Create routes
Route home = new Route("/"){
@Override
public Component<?> loadContent() {
return new Layout().text("Currently at "+ path);
}
};
Route home = new MRoute("/", () -> {
return new Layout().text("Hello World!");
});

// Create windows
new NativeWindow(home);
Expand Down

0 comments on commit 8d74bd5

Please sign in to comment.