Skip to content

Commit

Permalink
feat(framework): Make titles accessible through app
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStegii committed Feb 27, 2024
1 parent d811046 commit e4800d4
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions framework/src/main/java/org/fulib/fx/FulibFxApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.ResourceBundle;
import java.util.function.Function;
import java.util.logging.Logger;

import static org.fulib.fx.util.FrameworkUtil.error;

public abstract class FulibFxApp extends Application {
Expand Down Expand Up @@ -208,7 +209,7 @@ public void stop() {
this.currentMainController = controller;
onShow(Optional.empty(), controller, renderedParent, params);
display(renderedParent);
this.component.controllerManager().getTitle(controller).ifPresent(title -> stage.setTitle(title(title)));
getTitle(controller).ifPresent(title -> stage.setTitle(formatTitle(title)));
return renderedParent;
}

Expand All @@ -224,7 +225,7 @@ public void stop() {
Pair<Object, Parent> rendered = this.component.router().renderRoute(route, params);
this.currentMainController = rendered.getKey();
display(rendered.getValue());
this.component.controllerManager().getTitle(currentMainController).ifPresent(title -> stage.setTitle(title(title)));
getTitle(currentMainController).ifPresent(title -> stage.setTitle(formatTitle(title)));
onShow(Optional.of(route), rendered.getKey(), rendered.getValue(), params);
return rendered.getValue();
}
Expand Down Expand Up @@ -367,8 +368,24 @@ public void setTitlePattern(String titlePattern) {
this.titlePattern = titlePattern::formatted;
}

private String title(String title) {
/**
* Formats the title of a controller using the title pattern.
*
* @param title The title of the controller
* @return The formatted title
*/
public String formatTitle(String title) {
return this.titlePattern.apply(title);
}

/**
* Returns the title of the given controller.
*
* @param controller The controller instance
* @return The title of the controller
*/
public Optional<String> getTitle(Object controller) {
return this.component.controllerManager().getTitle(controller);
}

}

0 comments on commit e4800d4

Please sign in to comment.