feat(app-iced): M90 —— app.rs 拆成 src/app/ + presenter 真接线 + 实例页端到端

拆分(行为不变,截图四件套逐字节相同):
- 400 行的 app.rs 拆成 src/app/{mod,state,message,update,subscription,view,boot,tests}.rs,
  每个文件 ≤ 300 行;components 的 #[path] 跟着搬到 src/app/mod.rs(逻辑路径仍是 crate::app::components),
  可见性放到 pub(crate) 让页面层能用真组件。
- 拆分前后各出 shell/gallery 浅深四张图,cmp 全部 IDENTICAL。

presenter 接线(crate 文档 §4):
- App 持有 Box<dyn Backend> + SettingsBridge + AppState;启动 build_backend + SettingsBridge::open + AppState::new。
- 截图通道强制 mock(D30 可复现);交互模式走真 host,--data-dir 从 M90 起真的被消费。
- Boot 抽干首屏快照(第 3 帧落盘,等节拍会把空页面拍进图);节拍 = 帧事件 + 33ms 时间闸门
  (iced::time::every 要 tokio/smol,见 finding),tick → drain_events → AppState::apply。
- 用户动作不乐观回显:Launch/Stop 走 Backend::dispatch,状态等事件回来才变。
- 路由:pages::Message::Navigate(Route) 直接进 AppState::navigate,选中项 = 路由栈顶(不再有本地副本);
  首屏自动选中第一行(list-detail 桌面惯例),只做一次。

实例页打通(其余三页保留占位视觉 + Message/update + 路由):
- 列表行换成 components::navigation::ListItem(真五态/选中),页头与详情动作换成 components::buttons
  (Play 是唯一的实心 accent),分隔线换成 components::divider。
- 数据全部来自 presenter 快照:VERSION/LOADER/ISOLATION/VERSION ID/FILES/LAST PLAYED + 运行状态行。
- 导航轨换成真 NavigationRail(88),5 项各自压/替换路由。

版面约束未破(实测):列表列 336、正文列 424(元信息卡 206+12+206,右缘 896)、rail 88(药丸 16..71)、
断点 600/840 走 frame_metrics;新增 pages/tests.rs 的 9 条数值断言钉住它们。
This commit is contained in:
AskaEth committed 2026-11-02 15:56:57 +08:00
1 parent 270026338f
commit b484998fc9
17 files changed
+1990 -676

No files matched your search

+96
View File
@@ -0,0 +1,96 @@
//! 视图模型:**presenter 快照 → 页面要画的东西**的唯一转换产物。
//!
//! ## 为什么页面不直接吃 presenter 的快照
//!
//! 页面层(`pages/*`)要能用**两套数据源**喂同一个渲染函数:
//!
//! | 数据源 | 谁转 | 用途 |
//! |---|---|---|
//! | presenter 的 `AppState` 快照 | `app/view.rs`(`From<&AppState>`) | 产品运行时的真页面 |
//! | `pages/instances/data.rs` 的演示条目 | [`crate::pages::demo`] | M84 骨架图的可复现基线、`pages_demo` example |
//!
//! 如果页面直接读 `InstanceSummary`,演示数据就得先伪造成 `InstanceSummary`(含 core 语义字段),
//! 基线图会跟着业务 DTO 的每次改动漂。所以中间加一层**纯展示字段**的模型:它只含「要画什么」。
//!
//! 文本都是 `String`/`&'static str`,没有框架类型——这一层可以纯单测(见 `pages/tests.rs`)。
use unlucky_presenter::router::NavSection;
use super::Screen;
/// 实例列表的一行(`ListItem` 的槽位:overline = 运行状态,headline = 名字,supporting = 版本)。
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Row {
/// 实例 id(点行 → `Route::Detail(id)`)
pub id: String,
/// 显示名
pub name: String,
/// 副文案(`1.20.4 · Fabric 0.16.5`)
pub supporting: String,
/// 运行状态(`None` = 空闲,不占 overline 槽位)
pub status: Option<String>,
}
/// 元信息卡:标签 + 值(`VERSION` / `Fabric 0.16.5`)。
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Meta {
/// 卡片上排的标签(`LabelMedium`)
pub label: String,
/// 卡片下排的值(`BodyMedium`)
pub value: String,
}
/// 详情列要画的东西。
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Detail {
/// 实例 id(启动/停止命令要用它)
pub id: String,
/// 标题(`TitleLarge`)
pub name: String,
/// 标题下的一行(`BodySmall`)
pub subtitle: String,
/// 元信息网格(顺序 = 展示顺序;列数仍由 `layout::meta_columns` 决定)
pub meta: Vec<Meta>,
/// 正文档(演示数据有;真实快照没有对应字段时为 `None`)
pub note: Option<String>,
/// 运行状态行(`None` = 空闲,不占版面)
pub status: Option<String>,
/// 「Play」可用
pub can_launch: bool,
/// 「Stop」可用
pub can_stop: bool,
}
/// 实例页要画的东西。
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct Instances {
/// 列表列(顺序稳定 = 实例列表顺序)
pub rows: Vec<Row>,
/// 当前选中的实例详情(`None` = 没选中 → 空态)
pub detail: Option<Detail>,
}
/// 一屏的视图模型。
#[derive(Debug, Clone, PartialEq)]
pub struct Model {
/// 当前路由落在哪个页面上
pub screen: Screen,
/// 窗口宽度(**含外壳**:布局档位判据就是它)
pub window_width: f32,
/// 导航轨高亮项(`None` = 没有高亮,如 AI 独立页)
pub active: Option<NavSection>,
/// 实例页的数据(其它三页还是占位视觉,不读)
pub instances: Instances,
}
impl Model {
/// 空模型(只有外壳参数,页面数据全空)——窄窗退化与空态的构造入口。
pub fn new(screen: Screen, window_width: f32, active: Option<NavSection>) -> Self {
Self {
screen,
window_width,
active,
instances: Instances::default(),
}
}
}