Skip to content

Commit

Permalink
refactor!: changed manager public function and callback
Browse files Browse the repository at this point in the history
moved view ownership, improved ui structure:
improved `UiBridge` `ViewManager` `BasicView`
added `UiUtility`
removed useless public function in slint

BREAKING CHANGE:
  • Loading branch information
cEvolve05 committed Aug 9, 2024
1 parent d15775f commit 1621e23
Show file tree
Hide file tree
Showing 31 changed files with 419 additions and 294 deletions.
9 changes: 6 additions & 3 deletions src/Controller/Core/BasicView.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

EVENTO_UI_START

class ViewManager;

class BasicView : public std::enable_shared_from_this<BasicView> {
friend class ViewManager;
friend class UiBridge;

protected:
UiBridge& bridge;
BasicView(UiBridge& bridge)
: bridge(bridge) {}

public:
virtual ~BasicView() = default;
Expand Down
5 changes: 5 additions & 0 deletions src/Controller/Core/UiBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ EVENTO_UI_START

using UiEntryName = App;

class UiBridge;
class ViewManager;
class AccountManager;
class NotificationManager;

EVENTO_UI_END
30 changes: 30 additions & 0 deletions src/Controller/Core/UiUtility.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <Controller/Core/UiUtility.h>
#include <set>
#include <spdlog/spdlog.h>

EVENTO_UI_START

std::string UiUtility::getViewName(ViewName target) {
return viewNameMapper.find(target) == viewNameMapper.end() ? "[Unknown View]"
: viewNameMapper.at(target);
}

bool UiUtility::isTransparent(ViewName target) {
static const std::set<ViewName> overlayList{ViewName::MenuOverlay, ViewName::LoginOverlay};
return overlayList.find(target) != overlayList.end();
}

void UiUtility::StylishLog::viewActionTriggered(std::string origin,
std::string actionName,
std::string viewName) {
spdlog::debug("{}: {}: triggered {}", origin, viewName, actionName);
}

void UiUtility::StylishLog::viewVisibilityChanged(std::string origin,
std::string actionName,
std::string viewName) {
// TODO: better log
spdlog::debug("{}: {} visibility changed: {}", origin, viewName, actionName);
}

EVENTO_UI_END
37 changes: 37 additions & 0 deletions src/Controller/Core/UiUtility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <Controller/Core/BasicView.h>
#include <Controller/Core/UiBase.h>

EVENTO_UI_START

class UiUtility {
public:
static std::string getViewName(ViewName target);
static bool isTransparent(ViewName target);

class StylishLog {
public:
static void viewActionTriggered(std::string origin,
std::string actionName,
std::string viewName = std::string("All-View"));
static void viewVisibilityChanged(std::string origin,
std::string actionName,
std::string viewName);
};

private:
static inline const std::unordered_map<ViewName, std::string> viewNameMapper{
{ViewName::DiscoveryPage, "DiscoveryPage"},
{ViewName::SearchPage, "SearchPage"},
{ViewName::HistoryPage, "HistoryPage"},
{ViewName::MyEventPage, "MyEventPage"},
{ViewName::DetailPage, "DetailPage"},
{ViewName::AboutPage, "AboutPage"},
{ViewName::SettingPage, "SettingPage"},
{ViewName::LoginOverlay, "LoginOverlay"},
{ViewName::MenuOverlay, "MenuOverlay"},
};
};

EVENTO_UI_END
Loading

0 comments on commit 1621e23

Please sign in to comment.