Skip to content

Commit

Permalink
refactor: separate manager and bridge in ui
Browse files Browse the repository at this point in the history
  • Loading branch information
cEvolve05 committed Aug 12, 2024
1 parent 6788472 commit 4f179f2
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Controller/Core/AccountManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

EVENTO_UI_START

class AccountManager : private GlobalAgent<::AccountManager>,
class AccountManager : private GlobalAgent<AccountManagerBridge>,
std::enable_shared_from_this<AccountManager> {
friend class UiBridge;
UiBridge& bridge;
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Core/MessageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

EVENTO_UI_START

class MessageManager : GlobalAgent<::MessageManager> {
class MessageManager : GlobalAgent<MessageManagerBridge> {
friend class UiBridge;
UiBridge& bridge;
std::string logOrigin = "MessageManager";
Expand Down
5 changes: 2 additions & 3 deletions src/Controller/Core/ViewManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ void ViewManager::hideView(ViewName target) {
visibleViews.erase(target);
}

void ViewManager::onEnterEventLoop() {
auto stack = viewStack;
}
void ViewManager::onEnterEventLoop() {}

void ViewManager::onExitEventLoop() {
// clean up
spdlog::debug("ViewManager: --- onExitEventLoop: clean up all pages ---");
Expand Down
5 changes: 4 additions & 1 deletion src/Controller/Core/ViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

EVENTO_UI_START

class ViewManager : private GlobalAgent<::ViewManager> {
class ViewManager : private GlobalAgent<ViewManagerBridge> {
friend class UiBridge;
UiBridge& bridge;
std::string logOrigin = "ViewManager";
Expand All @@ -26,12 +26,15 @@ class ViewManager : private GlobalAgent<::ViewManager> {
// view will be added to stack and show on top, overlay won't hide prior view.
// auto refresh
void navigateTo(ViewName newView);

// stack will be clean (init view left), and push new view.
// auto refresh
void cleanNavigateTo(ViewName newView);

// current page pop and new view pushed.
// auto refresh
void replaceNavigateTo(ViewName newView);

// view will be pop from stack, new top will be show if it not.
// auto refresh
void priorView();
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/UiBridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ UiBridge::UiBridge(slint::ComponentHandle<UiEntryName> uiEntry)
, messageManager(std::make_shared<MessageManager>(uiEntry, *this)) {
attachAllViews();

slint::invoke_from_event_loop([this] { return onEnterEventLoop(); });

uiEntry->window().on_close_requested([this] {
onExitEventLoop();
return slint::CloseRequestResponse::HideWindow;
});
slint::invoke_from_event_loop([this] { return onEnterEventLoop(); });

viewManager->initStack(ViewName::DiscoveryPage);
if (!accountManager->isLogin()) {
Expand Down
1 change: 1 addition & 0 deletions src/Controller/UiBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ EVENTO_UI_START
class UiBridge : GlobalAgent<::UiBridge> {
friend class ViewManager;
friend class AccountManager;
friend class MessageManager;

slint::ComponentHandle<UiEntryName> uiEntry;
bool eventLoopRunning = false;
Expand Down
10 changes: 8 additions & 2 deletions ui/app.slint
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { Token } from "./global.slint";
import { Button } from "std-widgets.slint";
import { Empty } from "./components/index.slint";
import {
ViewManagerBridge,
AccountManagerBridge,
MessageManagerBridge,
ViewManager,
ViewName,
AccountManager,
MessageManager,
ViewName,
MessageType
} from "./logic/index.slint";

Expand Down Expand Up @@ -35,10 +38,13 @@ import { SAlert } from "modules/surrealism-ui/src/alert/index.slint";

// export for C++ interact
export {
ViewManagerBridge,
AccountManagerBridge,
MessageManagerBridge,
ViewManager,
ViewName,
AccountManager,
MessageManager,
ViewName,
MessageType,
LoginOverlayBridge,
MenuOverlayBridge,
Expand Down
12 changes: 11 additions & 1 deletion ui/logic/account_manager.slint
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
export global AccountManager {
export global AccountManagerBridge {
in-out property <bool> is-login;
callback request-login();
callback request-logout();
}

export global AccountManager {
out property <bool> is-login <=> AccountManagerBridge.is-login;
public function request-login() {
AccountManagerBridge.request-login();
}
public function request-logout() {
AccountManagerBridge.request-logout();
}
}
7 changes: 6 additions & 1 deletion ui/logic/index.slint
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
export { EventoStyleToken } from "./style_token.slint";
export {
ViewManager,
ViewManagerBridge,
ViewName,
} from "./view_manager.slint";
export { AccountManager } from "./account_manager.slint";
export {
AccountManager,
AccountManagerBridge,
} from "./account_manager.slint";
export {
MessageManager,
MessageManagerBridge,
MessageType,
} from "./message_manager.slint";
12 changes: 11 additions & 1 deletion ui/logic/message_manager.slint
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ export enum MessageType{
Error
}

export global MessageManager {
export global MessageManagerBridge {
in-out property <string> content: "Test content";
in-out property <bool> visible;
in-out property <MessageType> type;
in-out property <duration> timeout: 3s;
callback show-message(string, MessageType);
}

export global MessageManager {
out property <string> content <=> MessageManagerBridge.content;
out property <bool> visible <=> MessageManagerBridge.visible;
out property <MessageType> type <=> MessageManagerBridge.type;
out property <duration> timeout <=> MessageManagerBridge.timeout;
public function show-message(content: string, type: MessageType) {
MessageManagerBridge.show-message(content, type);
}
}
22 changes: 21 additions & 1 deletion ui/logic/view_manager.slint
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export enum ViewName{
MenuOverlay,
}

export global ViewManager {
export global ViewManagerBridge {
// nav request
callback navigate-to(ViewName);
callback clean-navigate-to(ViewName);
Expand All @@ -20,3 +20,23 @@ export global ViewManager {
pure callback is-show(ViewName) -> bool;
in-out property <bool> refresh;
}

export global ViewManager {
// nav request
public function navigate-to(view: ViewName) {
ViewManagerBridge.navigate-to(view);
}
public function clean-navigate-to(view: ViewName) {
ViewManagerBridge.clean-navigate-to(view);
}
public function replace-navigate-to(view: ViewName) {
ViewManagerBridge.replace-navigate-to(view);
}
public function prior-view() {
ViewManagerBridge.prior-view();
}
// control view visibility
public pure function is-show(view: ViewName) -> bool {
return ViewManagerBridge.is-show(view);
}
}

0 comments on commit 4f179f2

Please sign in to comment.