fix(m161): 收更新键/按钮/矮窗口/启动错误/导入结果五笔债

① update.auto_check / update.channel 登记进 core setting schema(1.6.0)
   - 新增 setting/keys/update.rs(两键 + UPDATE_CHANNELS,只允许 stable);
     SettingSchema 加 with_all 供域键表批量登记。
   - 新增 setting/update_prefs.rs:cache/update/prefs.json → launcher.json 的一次性迁移。
     四条硬约束:源指纹闸门(幂等)、不丢 false、新值胜出、旧文件改名 .migrated 后不再被读;
     主配置不可写时不动旧文件。收据 config/update-prefs-migration.json。
   - presenter Runtime 建会话时迁一次并把结局留在 migration();prefs 字段换成
     auto_check + 每次派发从主配置读 channel(不再硬编码 Channel::Stable)。
     保留旧字段 auto_check 的真实来源(原有测试 cases 会断言)。
   - CLI config get/set/dump 先跑同一次迁移(幂等),输出里给 migration 段与收据路径。

② presenter/dto/events.rs 的「本次会话不再弹提示条」注释改成真实语义
   (记的是版本号:同版本压住、更高版本照弹、手动检查清掉)。

③ 检查/下载进行中按钮禁用:pages/update/busy.rs 的 busy/can_check/can_apply;
   设置页两颗按钮改画禁用(不是消失),app 层 on_update_action 再挡一道
   (忙碌时 CheckNow/Apply 不派发);新增两条用例(含「忙完恢回可点」)。

④ 内容库低高度:content_layout::MIN_BODY_HEIGHT=460 + BodyMode(按固定件+三整行算出来,
   用例守着算式);frame::body_height 从 Ui::metrics 算正文可用高,pages::Model 带 window_height。
   ≥460 列表自己滚;<460 主列整列一个滚动条、列表按自然高度铺开。

⑤ 启动错误文案本地化:presenter 删掉 launch_summary / 「启动失败:」前缀 / 五条中文阶段前缀,
   改发 LaunchFailureView{stage,detail};LaunchFinished 改带 exit_code/uptime_ms/failure,
   Toast 由 app 层按 i18n key 现求(与 install_cancelled 同构)。InstancesFailed 拆成
   InstancesFailedStage(列表单行)+ LaunchStageFailed(详情/Toast 全文)。

⑥ 导入结果块:ImportReportView 加 failure_stage(NotStarted/RolledBack/RollbackIncomplete,
   由 core 的 rollback 机器位推出);标题、图标、底色三处分档,预检失败不再说「已回滚」。

顺带:六处注释/文档漂移(update.rs 的分工表与偏好落点、pack 的「已整包回滚」、
build_request 的 Errors、settings/update 的按钮禁用说明等),
以及为守 400 行把 update/cli-config/core-keys/presenter-dto/presenter-launch/i18n-golden
里贴线或越线的文件按模块拆开(纯搬移,行为不变)。
This commit is contained in:
AskaEth committed 2026-11-07 15:02:13 +08:00
1 parent b2d9f3927f
commit 03741ecd2d
69 files changed
+2653 -707

No files matched your search

@@ -74,6 +74,53 @@ impl Tier {
}
}
/// 主列在**矮窗口**下切成「整列一个滚动条」的门槛(M161)。
///
/// ## 为什么需要这条门槛
///
/// 主列自上而下是:搜索条(48)+ 筛选四排(4×32 + 3×8 = 152)+ 计数头(20)+ 结果列表 + 「加载更多」(40)
/// 再加两条 `Space::X2` 间距。列表自己没有最小高度,于是窗口一矮,**列表视口只剩几十像素**:
/// 一行 `ListItem` 是 60/76 高,被切成半行——两行文字(overline + 标题)看起来像「折行挤压」。
///
/// ## 明确的两档行为(不是到处加滚动条)
///
/// | 正文可用高 | 版面 |
/// |---|---|
/// | ≥ [`MIN_BODY_HEIGHT`] | 现状:**列表自己滚**(筛选条常驻,滚的时候不跑掉) |
/// | < [`MIN_BODY_HEIGHT`] | 主列整列变成**一个**纵向滚动区:列表按自然高度铺开,一行都不压 |
///
/// 阈值 = 固定件(48 + 152 + 20 + 40 + 间距 ≈ 276)+ 至少三整行(3×60 = 180)= 456,
/// 取 **460**(往上抹到 4 的倍数,给 divider / 取整留余量)。数值改了就改这里的算式与
/// `layout/tests` 的等式用例。
pub const MIN_BODY_HEIGHT: f32 = 460.0;
/// 正文高度的两档行为。
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BodyMode {
/// 高够:列表自己滚(筛选条常驻)
Split,
/// 矮窗口:主列整列一个滚动区,列表按自然高度铺开
ScrollWhole,
}
impl BodyMode {
/// 判据(纯函数,测得到)。
#[must_use]
pub fn of(body_height: f32) -> Self {
if body_height >= MIN_BODY_HEIGHT {
Self::Split
} else {
Self::ScrollWhole
}
}
/// 列表要不要自己滚。
#[must_use]
pub const fn list_scrolls(self) -> bool {
matches!(self, Self::Split)
}
}
/// `Wide` 的门槛:标签栏 + 间距 + 列表下限 + 间距 + 详情。
pub fn wide_min() -> f32 {
RAIL_LABEL + GAP + layout::LINE_SAFE_WIDTH_PX + GAP + DETAIL
@@ -192,3 +239,49 @@ mod tests {
assert!(!Tier::Narrow.rail_has_labels());
}
}
#[cfg(test)]
mod body_mode_tests {
use super::*;
/// 门槛是**算出来的**:固定件(搜索 48 + 筛选 152 + 计数 20 + 加载更多 40 + 两条 8 间距)
/// 加三整行列表(3 × 60)。谁把 460 改成拍脑袋的数,这条会红。
#[test]
fn the_minimum_body_height_is_fixed_parts_plus_three_rows() {
let fixed = 48.0 + 152.0 + 20.0 + 40.0 + 2.0 * Space::X2.dp();
let three_rows = 3.0 * 60.0;
assert!(
MIN_BODY_HEIGHT >= fixed + three_rows,
"门槛 {MIN_BODY_HEIGHT} 小于「固定件 {fixed} + 三行 {three_rows}」——矮窗口还是会切半行"
);
assert!(
MIN_BODY_HEIGHT <= fixed + three_rows + 16.0,
"门槛留了太多余量:{} 会把还放得下的窗口也推进「整列滚动」档",
MIN_BODY_HEIGHT - (fixed + three_rows)
);
}
/// 两档在门槛处切开,且只有 `Split` 让列表自己滚。
#[test]
fn the_body_mode_flips_at_the_threshold() {
assert_eq!(BodyMode::of(MIN_BODY_HEIGHT), BodyMode::Split);
assert_eq!(BodyMode::of(MIN_BODY_HEIGHT - 0.5), BodyMode::ScrollWhole);
assert!(BodyMode::of(900.0).list_scrolls());
assert!(!BodyMode::of(300.0).list_scrolls());
}
/// 窗口最小尺寸(880×560)落在**矮**档:这是本条债的真实场景,别让它悄悄变回 `Split`。
#[test]
fn the_minimum_window_size_uses_the_scrolling_body() {
// 560 窗口 − 顶栏 56 − 页头 88(两行标题 + 留白)− 上下页边距 2×16 ≈ 384
let body = 560.0 - 56.0 - 88.0 - 32.0;
assert_eq!(
BodyMode::of(body),
BodyMode::ScrollWhole,
"最小窗口(560 高)必须走整列滚动:正文只剩 {body}"
);
// 验收尺寸 760 高 → 约 584,仍走「列表自己滚」。
let body = 760.0 - 56.0 - 88.0 - 32.0;
assert_eq!(BodyMode::of(body), BodyMode::Split, "验收尺寸不该换版面");
}
}
@@ -20,8 +20,8 @@ use unlucky_i18n::Lang;
use unlucky_presenter::dto::{
ConflictChoiceView, ConflictFileView, ConflictReasonView, ExportClassView, ExportFileView,
ExportPreviewView, ExportReasonView, ExportState, FileActionView, ImportErrorView,
ImportProgressView, ImportReportView, ImportStageView, ImportState, ImportStatusView,
InstanceId, LoaderKind, MissingFileView, MissingReasonView, PackFormatView,
ImportFailureStageView, ImportProgressView, ImportReportView, ImportStageView, ImportState,
ImportStatusView, InstanceId, LoaderKind, MissingFileView, MissingReasonView, PackFormatView,
};
use crate::pages::content::Target;
@@ -88,8 +88,22 @@ pub(super) fn pack_in(state: &str, lang: Lang) -> (Pack, PackPageState) {
import.report = Some(report(ImportStatusView::Partial, true));
page.expanded = Some("config/sodium-options.json".to_string());
}
// 致命态:整包回滚 + 容忍域仍在(展示两类失败的视觉分野)
"failed" => {
// 致命态(M161 分成三档出图:预检没过 / 已回滚 / 回滚没做完)。
// `failed` 保留旧名字(= 已回滚),另外两个是新档位。
"failed" | "failed_rolled_back" => {
let mut fatal = report(ImportStatusView::Failed, false);
fatal.error = Some(ImportErrorView {
code: "import_integrity".to_string(),
label: "Integrity check".to_string(),
message: "mods/sodium.jar: sha1 mismatch after write".to_string(),
hint: Some("Re-download the pack from its source".to_string()),
});
fatal.rolled_back = true;
fatal.failure_stage = Some(ImportFailureStageView::RolledBack);
import.report = Some(fatal);
}
// 预检没过:**一个字节都没写**(与上一条只差 `failure_stage`,图上要能一眼分辨)
"failed_preflight" => {
let mut fatal = report(ImportStatusView::Failed, false);
fatal.error = Some(ImportErrorView {
code: "pack_traversal".to_string(),
@@ -99,6 +113,21 @@ pub(super) fn pack_in(state: &str, lang: Lang) -> (Pack, PackPageState) {
});
fatal.files.clear();
fatal.bytes_written = 0;
fatal.rolled_back = true;
fatal.failure_stage = Some(ImportFailureStageView::NotStarted);
import.report = Some(fatal);
}
// 回滚没做完:目标目录可能与导入前不同
"failed_incomplete" => {
let mut fatal = report(ImportStatusView::Failed, false);
fatal.error = Some(ImportErrorView {
code: "import_integrity".to_string(),
label: "Integrity check".to_string(),
message: "mods/sodium.jar: sha1 mismatch after write".to_string(),
hint: None,
});
fatal.rolled_back = false;
fatal.failure_stage = Some(ImportFailureStageView::RollbackIncomplete);
import.report = Some(fatal);
}
// 取消态:面板收回了,但「后台还在跑」这句话要留在屏上
@@ -182,6 +211,7 @@ fn report(status: ImportStatusView, conflicts: bool) -> ImportReportView {
registered: Some("Survival".to_string()),
bytes_written: 3_400_000,
rolled_back: true,
failure_stage: None,
};
if conflicts {
report.conflicts = vec![
@@ -23,7 +23,10 @@
//! ## 容忍 / 致命在模型层就分开
//!
//! [`report::Report::missing`] 是「搞不到某个文件」(实例可用),[`report::Report::fatal`]
//! 是「已整包回滚」。两者字段类型不同、画的时候颜色与图标也不同,不可能混成一个列表。
//! 是致命失败。两者字段类型不同、画的时候颜色与图标也不同,不可能混成一个列表。
//!
//! 致命那一类内部还要再分三档(M161):预检没过(一个字节都没写)/ 已回滚 / 回滚没做完,
//! 见 [`report::FatalKind`]——措辞、图标、底色三处都分开。
mod export;
mod pick;
@@ -33,7 +36,7 @@ mod report;
pub use export::{format_label, request_of as request_export, Export, Preview};
pub use pick::{Pick, PickRow};
pub use progress::Running;
pub use report::{ConflictRow, Report, Row};
pub use report::{ConflictRow, FatalKind, Report, Row};
use std::collections::BTreeMap;
@@ -14,8 +14,8 @@
use unlucky_i18n::{Catalog, Key};
use unlucky_presenter::dto::{
ConflictChoiceView, ConflictFileView, ConflictReasonView, ImportErrorView, ImportReportView,
ImportStatusView, MissingFileView, MissingReasonView,
ConflictChoiceView, ConflictFileView, ConflictReasonView, ImportErrorView,
ImportFailureStageView, ImportReportView, ImportStatusView, MissingFileView, MissingReasonView,
};
use super::PackPageState;
@@ -48,10 +48,40 @@ pub struct ConflictRow {
pub expanded: bool,
}
/// 致命失败块(**已整包回滚**)。
/// 致命失败块(**两种措辞,不共用**)。
///
/// 为什么不是一句「失败」:`NotStarted`(预检就没过,一个字节都没写)与 `RolledBack`
/// (写进去了,又整包回滚干净)对用户是不同的消息——前者「去修包再试」,后者「刚才动过你的目录,
/// 已经复原」。M161 之前两者共用一句「已回滚 —— 目标目录零残留」,预检失败时那句话是假的。
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FatalKind {
/// 预检/装配阶段失败:目标目录**一个字节都没写**
NotStarted,
/// 写过目标目录,回滚**完整**完成
RolledBack,
/// 写过,但回滚有失败项(目标目录可能与导入前不同)
RollbackIncomplete,
}
impl FatalKind {
/// 图标(与 [`Fatal::title`] 各说一遍:颜色/图标关掉时标题仍然分得清)。
#[must_use]
pub const fn icon(self) -> unlucky_design::icons::IconKind {
match self {
// 预检没过 = 「还没开始」,用警示而不是「已出错」:目录是干净的
Self::NotStarted => unlucky_design::icons::IconKind::Warn,
Self::RolledBack => unlucky_design::icons::IconKind::Restore,
Self::RollbackIncomplete => unlucky_design::icons::IconKind::Error,
}
}
}
/// 致命失败块。
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Fatal {
/// 「已回滚 —— 目标目录零残留」
/// 三种阶段之一(决定标题/图标/底色)
pub kind: FatalKind,
/// 标题(预检未通过 / 已回滚 / 回滚不完整)
pub title: String,
/// 大类名(`路径穿越` / `清单损坏` …)
pub label: String,
@@ -124,7 +154,7 @@ pub(super) fn report_of(
Report {
status: report.status,
title: status_title(report.status, catalog).to_owned(),
title: status_title(report, catalog).to_owned(),
subtitle: subtitle(report, catalog),
written_line: catalog.render(
Key::PackReportWritten,
@@ -133,7 +163,10 @@ pub(super) fn report_of(
("bytes", &human(report)),
],
),
fatal: report.error.as_ref().map(|error| fatal_of(error, catalog)),
fatal: report
.error
.as_ref()
.map(|error| fatal_of(error, report.failure_stage, catalog)),
missing_title,
missing: report
.missing
@@ -177,11 +210,22 @@ fn human(report: &ImportReportView) -> String {
unlucky_presenter::dto::human_bytes(report.bytes_written)
}
fn status_title(status: ImportStatusView, catalog: Catalog) -> &'static str {
match status {
/// 标题:三态 + **失败阶段**(预检未通过 ≠ 已回滚,M161)。
fn status_title(report: &ImportReportView, catalog: Catalog) -> &'static str {
match report.status {
ImportStatusView::Success => catalog.text(Key::PackStatusSuccess),
ImportStatusView::Partial => catalog.text(Key::PackStatusPartial),
ImportStatusView::Failed => catalog.text(Key::PackStatusFailed),
ImportStatusView::Failed => match report.failure_stage {
Some(ImportFailureStageView::NotStarted) => {
catalog.text(Key::PackStatusFailedNotStarted)
}
Some(ImportFailureStageView::RollbackIncomplete) => {
catalog.text(Key::PackStatusFailedIncomplete)
}
// `None` 不该出现(失败必有阶段);退回「已回滚」这一句是旧行为,
// 只有拿不到阶段时才会走到(例如未来的旧版对端)。
_ => catalog.text(Key::PackStatusFailed),
},
}
}
@@ -203,9 +247,24 @@ fn subtitle(report: &ImportReportView, catalog: Catalog) -> String {
parts.join(" · ")
}
fn fatal_of(error: &ImportErrorView, catalog: Catalog) -> Fatal {
fn fatal_of(
error: &ImportErrorView,
stage: Option<ImportFailureStageView>,
catalog: Catalog,
) -> Fatal {
let kind = match stage {
Some(ImportFailureStageView::NotStarted) => FatalKind::NotStarted,
Some(ImportFailureStageView::RollbackIncomplete) => FatalKind::RollbackIncomplete,
_ => FatalKind::RolledBack,
};
let title = match kind {
FatalKind::NotStarted => catalog.text(Key::PackFatalTitleNotStarted),
FatalKind::RolledBack => catalog.text(Key::PackFatalTitle),
FatalKind::RollbackIncomplete => catalog.text(Key::PackFatalTitleIncomplete),
};
Fatal {
title: catalog.text(Key::PackFatalTitle).to_owned(),
kind,
title: title.to_owned(),
label: error.label.clone(),
message: error.message.clone(),
code: error.code.clone(),
@@ -4,6 +4,7 @@
//! 哪一态该出现哪一块。所有断言都能在没有图形环境的情况下跑。
mod pick;
mod stage;
use std::path::PathBuf;
@@ -226,6 +227,7 @@ fn report_keeps_tolerable_and_fatal_apart() {
registered: None,
bytes_written: 0,
rolled_back: true,
failure_stage: None,
};
let block = report_of(&report, &PackPageState::default(), catalog());
assert!(block.fatal.is_some(), "致命块必须单独存在");
@@ -262,6 +264,7 @@ fn conflicts_default_to_keeping_the_user_copy() {
registered: None,
bytes_written: 0,
rolled_back: true,
failure_stage: None,
};
// 「以包为准」只在导入到**已有实例**时给(复审 r1 P2-2),所以这里选一个实例
let page = PackPageState {
@@ -359,6 +362,7 @@ fn overwrite_is_offered_only_when_importing_into_an_existing_instance() {
registered: None,
bytes_written: 0,
rolled_back: true,
failure_stage: None,
};
let new_instance = PackPageState::default();
@@ -0,0 +1,109 @@
//! M161:导入失败的**两种阶段**不许共用一句话。
//!
//! 从 `tests.rs` 拆出(那边贴着 400 行硬线):本文件只守「预检没过(一个字节都没写)」与
//! 「已回滚」的措辞/图标分野。夹具在父模块(`use super::*`)。
use unlucky_presenter::dto::ImportFailureStageView;
use super::*;
/// **「预检没过」与「已回滚」必须各说各的话**(M161 收的债)。
///
/// 此前两者共用 `rolled_back: true`,于是预检失败(一个字节都没写)也被写成
/// 「已回滚 —— 目标目录零残留」——一个没发生的回滚。现在标题、图标、底色三处都分开,
/// 且 `NotStarted` 的标题**不许**出现「回滚 / rolled back」这类词(那才是真正的谎)。
#[test]
fn the_two_failure_stages_never_share_one_sentence() {
fn failed(stage: Option<ImportFailureStageView>) -> ImportReportView {
ImportReportView {
status: ImportStatusView::Failed,
format: Some(PackFormatView::Modrinth),
pack_name: Some("Broken".to_string()),
pack_version: None,
game_version: None,
loader: None,
version_id: None,
target: PathBuf::from("C:/tmp"),
files: Vec::new(),
conflicts: Vec::new(),
missing: Vec::new(),
rejected: Vec::new(),
warnings: Vec::new(),
error: Some(ImportErrorView {
code: "pack_traversal".to_string(),
label: "path traversal".to_string(),
message: "../etc/passwd".to_string(),
hint: None,
}),
registered: None,
bytes_written: 0,
rolled_back: true,
failure_stage: stage,
}
}
let zh = Lang::ZhCn.catalog();
let not_started = report_of(
&failed(Some(ImportFailureStageView::NotStarted)),
&PackPageState::default(),
zh,
);
let rolled_back = report_of(
&failed(Some(ImportFailureStageView::RolledBack)),
&PackPageState::default(),
zh,
);
let incomplete = report_of(
&failed(Some(ImportFailureStageView::RollbackIncomplete)),
&PackPageState::default(),
zh,
);
// 三种标题互不相同(三态压力:谁把它们折叠回同一句,这里就红)。
let titles = [
not_started.title.as_str(),
rolled_back.title.as_str(),
incomplete.title.as_str(),
];
assert_eq!(
titles
.iter()
.collect::<std::collections::HashSet<_>>()
.len(),
3,
"三种失败阶段的标题撞了:{titles:?}"
);
// 「预检没过」那一句里不许出现「回滚」(那是没发生的事)。
let fatal = not_started.fatal.expect("致命块");
assert_eq!(
fatal.kind,
crate::pages::content::packui::model::FatalKind::NotStarted
);
assert!(
!fatal.title.contains("回滚"),
"预检失败不该说「回滚」:{}",
fatal.title
);
assert!(!not_started.title.contains("回滚"), "{}", not_started.title);
// 已回滚那一句必须说清「回滚」这件事。
assert!(
rolled_back.title.contains("回滚"),
"已回滚那句要说明回滚:{}",
rolled_back.title
);
// 图标分开:预检没过不是「错误」字形(目录没动过),回滚不完整才是。
assert_ne!(
crate::pages::content::packui::model::FatalKind::NotStarted.icon(),
crate::pages::content::packui::model::FatalKind::RolledBack.icon(),
"两种阶段的图标不许一样"
);
// 成功/部分成功没有「失败阶段」可言。
let mut ok = failed(None);
ok.status = ImportStatusView::Success;
ok.error = None;
assert!(report_of(&ok, &PackPageState::default(), zh)
.fatal
.is_none());
}
@@ -15,7 +15,7 @@ use crate::pages::frame;
use crate::pages::Message as PageMessage;
use crate::theme::Ui;
use super::super::model::{ConflictRow, Report};
use super::super::model::{ConflictRow, FatalKind, Report};
use super::super::PackMessage;
use super::intent;
use super::parts::{bounded, marker_box, rows_block, tolerable_title};
@@ -62,34 +62,46 @@ pub(super) fn report_block<'a>(
.width(Length::Fill);
if let Some(fatal) = &report.fatal {
// 三种阶段各自的底色/图标:预检没过用 `SecondaryContainer`(**不是错的颜色**——
// 目标目录一个字节都没写,没什么可修的残留),已回滚用 `ErrorContainer`,
// 回滚不完整留 `ErrorContainer`(它才是真的要对一眼目录的状态)。
let (role, on_role) = match fatal.kind {
FatalKind::NotStarted => (Role::SecondaryContainer, Role::OnSecondaryContainer),
_ => (Role::ErrorContainer, Role::OnErrorContainer),
};
block = block.push(marker_box(
ui,
Role::ErrorContainer,
column![
frame::text_role(
ui,
TypeRole::LabelLarge,
true,
fatal.title.as_str(),
ui.color(Role::OnErrorContainer),
),
frame::text_role_owned(
ui,
TypeRole::BodyMedium,
false,
format!("{} · {}", fatal.label, fatal.code),
ui.color(Role::OnErrorContainer),
),
frame::text_role(
ui,
TypeRole::BodySmall,
false,
fatal.message.as_str(),
ui.color(Role::OnErrorContainer),
),
role,
row![
frame::glyph(fatal.kind.icon(), ui.color(on_role), frame::ICON_PX),
column![
frame::text_role(
ui,
TypeRole::LabelLarge,
true,
fatal.title.as_str(),
ui.color(on_role),
),
frame::text_role_owned(
ui,
TypeRole::BodyMedium,
false,
format!("{} · {}", fatal.label, fatal.code),
ui.color(on_role),
),
frame::text_role(
ui,
TypeRole::BodySmall,
false,
fatal.message.as_str(),
ui.color(on_role),
),
]
.spacing(ui.space(Space::X1))
.width(Length::Fill),
]
.spacing(ui.space(Space::X1))
.width(Length::Fill),
.spacing(ui.space(Space::X2))
.align_y(Alignment::Start),
));
if let Some(hint) = &fatal.hint {
block = block.push(
+33 -15
View File
@@ -98,12 +98,18 @@ pub(super) fn search<'a>(
.into()
}
/// 结果列表(独立滚动;底部「加载更多」钉在列表之外,见 [`more`])。
/// 结果列表。
///
/// 两档(M161,判据同 [`super::layout::BodyMode`]):
///
/// * `mode.list_scrolls()`:列表**自己滚**(筛选条常驻,高窗口的常态);
/// * 否则:行按自然高度铺开,滚动交给外层主列——矮窗口里一行 `ListItem` 不许被压成半行。
pub(super) fn list<'a>(
ui: &'a Ui,
catalog: Catalog,
model: &'a Content,
rails: Rails,
mode: super::layout::BodyMode,
) -> Element<'a, PageMessage> {
let rows = column(
model
@@ -117,20 +123,32 @@ pub(super) fn list<'a>(
.width(Length::Fill);
let _ = catalog;
container(
scrollable(rows)
.direction(scrollable::Direction::Vertical(
scrollable::Scrollbar::new()
.width(frame::SCROLLBAR_WIDTH)
.scroller_width(frame::SCROLLBAR_WIDTH)
.margin(frame::SCROLLBAR_MARGIN),
))
.height(Length::Fill)
.style(frame::scroll_style(ui)),
)
.width(Length::Fixed(rails.list))
.height(Length::Fill)
.into()
let inner: Element<'a, PageMessage> = if mode.list_scrolls() {
container(
scrollable(rows)
.direction(scrollable::Direction::Vertical(
scrollable::Scrollbar::new()
.width(frame::SCROLLBAR_WIDTH)
.scroller_width(frame::SCROLLBAR_WIDTH)
.margin(frame::SCROLLBAR_MARGIN),
))
.height(Length::Fill)
.style(frame::scroll_style(ui)),
)
.height(Length::Fill)
.into()
} else {
// 自然高度(不给 `Fill`):外层主列的那个滚动条负责滚。
rows.into()
};
container(inner)
.width(Length::Fixed(rails.list))
.height(if mode.list_scrolls() {
Length::Fill
} else {
Length::Shrink
})
.into()
}
fn hit_row<'a>(ui: &'a Ui, model: &Content, hit: &'a Hit) -> Element<'a, PageMessage> {
+42 -9
View File
@@ -49,12 +49,17 @@ pub(super) fn view<'a>(
metrics: FrameMetrics,
model: &'a Content,
lang: unlucky_i18n::Lang,
window_height: f32,
) -> Element<'a, PageMessage> {
let catalog = lang.catalog();
// 正文可用高 → 版面两档(`Split`:列表自己滚;`ScrollWhole`:主列整列一个滚动条)。
// 门槛与判据在 [`content_layout`] 里,那里有用例钉住「不算拍脑袋的数」。
let body_height = frame::body_height(ui, metrics, window_height, true);
let mode = content_layout::BodyMode::of(body_height);
let header = Header::new(catalog.text(Key::ContentTitle))
.subtitle(catalog.text(Key::ContentSubtitle))
.action(parts::section_switcher(ui, catalog, true));
frame::page(ui, metrics, header, body(ui, metrics, catalog, model))
frame::page(ui, metrics, header, body(ui, metrics, catalog, model, mode))
}
fn body<'a>(
@@ -62,6 +67,7 @@ fn body<'a>(
metrics: FrameMetrics,
catalog: Catalog,
model: &'a Content,
mode: content_layout::BodyMode,
) -> Element<'a, PageMessage> {
let rails = content_layout::resolve(metrics.available);
@@ -75,14 +81,14 @@ fn body<'a>(
let main = column![
kind_rail(ui, catalog, model, rails),
divider::full(ui),
main_column(ui, catalog, model, rails)
main_column(ui, catalog, model, rails, mode)
]
.spacing(ui.space(Space::X2))
.width(Length::Fill)
.height(Length::Fill);
columns = row![main].width(Length::Fill).height(Length::Fill);
} else {
columns = columns.push(main_column(ui, catalog, model, rails));
columns = columns.push(main_column(ui, catalog, model, rails, mode));
if rails.tier.has_detail() {
columns = columns.push(detail_column(ui, catalog, model, rails));
}
@@ -151,11 +157,19 @@ fn kind_rail<'a>(
}
/// 主列:搜索条 + 筛选 + 计数 + 结果(或四态之一)。
///
/// `mode` 决定**谁滚**(M161,判据在 `content_layout::BodyMode`):
///
/// * `Split`:列表自己滚(筛选条常驻,高窗口的常态);
/// * `ScrollWhole`:矮窗口——主列(含搜索条与筛选)整列进**一个**纵向滚动区,列表按自然高度铺开。
/// 这样一行 `ListItem` 不会被压成半行(那看起来就是「折行挤压」),也不会出现「列表里一个滚动条、
/// 外层又一个」的双滚动。
fn main_column<'a>(
ui: &'a Ui,
catalog: Catalog,
model: &'a Content,
rails: Rails,
mode: content_layout::BodyMode,
) -> Element<'a, PageMessage> {
// 主列的横向内边距不在这里加:`rails.list` 已经把可用宽算干了,再加 2×X2 会让整排
// 溢出 32px(详情列被切掉一半,复审截图上正是这条)
@@ -178,10 +192,15 @@ fn main_column<'a>(
} else {
// **必须给间距**(复审 P2-1):这一列原先漏了 `.spacing(..)`,而列表自身的纵向内边距是 0,
// 于是「列表视口底边」与「加载更多」贴在一起,末行正好被切在半行上。
let mut list = column![parts::list(ui, catalog, model, rails)]
let mut list = column![parts::list(ui, catalog, model, rails, mode)]
.spacing(ui.space(Space::X2))
.width(Length::Fill)
.height(Length::Fill);
.width(Length::Fill);
// 列表高度:`Split` 吃掉剩余高度(自己滚);`ScrollWhole` 按内容铺开(外层滚)。
list = if mode.list_scrolls() {
list.height(Length::Fill)
} else {
list.height(Length::Shrink)
};
// 紧凑档没有独立详情列:详情压在列表下面(整页替换的成本比「多一块」高)
if !rails.tier.has_detail() {
list = list
@@ -191,10 +210,11 @@ fn main_column<'a>(
list.push(parts::more(ui, catalog, model)).into()
};
// `ScrollWhole` 档:主列整列一个滚动区(列表按自然高度)。**只有这一处**加滚动条,
// 不在列表里再套一个(双滚动是「到处加滚动条糊」的典型症状)。
let mut column = column![]
.spacing(ui.space(Space::X2))
.width(Length::Fixed(rails.list))
.height(Length::Fill);
.width(Length::Fixed(rails.list));
// M113: import/export —— 只有整合包这一类才有「把本地的包装进来 / 把实例打出去」。
// 其它三类(Mod / 资源包 / 光影)的导入就是把文件拖进目录,不属于本条任务。
@@ -204,7 +224,20 @@ fn main_column<'a>(
.push(divider::full(ui));
}
column.push(head).push(body).into()
column = column.push(head).push(body);
if mode.list_scrolls() {
return column.height(Length::Fill).into();
}
iced::widget::scrollable(column.height(Length::Shrink))
.direction(iced::widget::scrollable::Direction::Vertical(
iced::widget::scrollable::Scrollbar::new()
.width(frame::SCROLLBAR_WIDTH)
.scroller_width(frame::SCROLLBAR_WIDTH)
.margin(frame::SCROLLBAR_MARGIN),
))
.height(Length::Fill)
.style(frame::scroll_style(ui))
.into()
}
/// 详情列(只在 `Wide` / `Narrow` 存在)。