Launch AppLauncher at Boot / 启动时显示应用菜单

AppLauncher 是 PixelUI 自带的应用入口。它本身就是一个普通 App:继承自 IconView,从 AppManager 读取已注册 App,用户选中图标后再调用 ViewManager::launch()

AppLauncher interface

AppLauncher 的默认实现。 AppLauncher 自己也是一个标准的 App.

1. 注册可启动的 App

一个常规 App 使用 AppItem::make<T>() 生成注册项:

1
2
AppItem settingsApp =
AppItem::make<SettingsApp>("Settings", settings_icon_bits);

在启动阶段显式放进 AppManager。PixelUI 不提供静态自动注册;注册时机和顺序由启动代码直接控制:

1
2
3
4
5
6
void registerApps() {
auto& apps = AppManager::getInstance();
apps.registerApp(settingsApp);
apps.registerApp(aboutApp);
// ...
}

注册表容量由 PIXELUI_MAX_APP_NUM 决定。实际项目中要在启动前确认所有项目都能放下;配置方法见资源上限

2. 启动 launcher

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "ui/AppLauncher/AppLauncher.h"

int main() {
init_display(u8g2);

registerApps();

ui.begin();

ViewManager& views = *ui.getViewManagerPtr();
const ViewManager::LaunchResult result = AppLauncher::launch(ui, views);
if (result != ViewManager::LaunchResult::Ok) {
// 记录错误,或进入一个最小故障界面。
platform_fatal("Cannot launch AppLauncher");
}

run_ui_loop();
}

Launcher 一般作为栈底 App。页面暂停、恢复、fade 和失败结果见App 生命周期与 ViewManager

最新文章
网站信息
文章数目 :
1
本站访客数 :
本站总浏览量 :
最后更新时间 :