fix(selection): Chip 禁用改成修饰器,只清消息、不删图标与选中态(复审 P2-1)
- 旧 API Chip::disabled(label, variant) 强制 leading/trailing/selected = None/false:实测 assist 78→54、filter·on 74→50(连填充和勾都没了),禁用列里 filter·on 与 filter 逐像素同形 - 新 API Chip::assist(label, msg).leading(k).disabled():只清 on_press,视觉信息全保留 (research/12b §13 的禁用态是「容器/描边 12%、文字与图标 38%」——只降不删) - 矩阵里禁用格改用修饰器,图标与选中态一并保留
This commit is contained in:
1 parent
00dbb5a5d5
commit
c5765c57e7
2 files changed
+22
-25
No files matched your search
@@ -56,17 +56,15 @@ impl<'a, M> Chip<'a, M> {
|
||||
Self::new(label, ChipVariant::Input, false, on_press)
|
||||
}
|
||||
|
||||
/// 禁用的 chip(无消息)。
|
||||
pub fn disabled(label: &'a str, variant: ChipVariant) -> Self {
|
||||
Self {
|
||||
label,
|
||||
variant,
|
||||
selected: false,
|
||||
leading: None,
|
||||
trailing: None,
|
||||
on_press: None,
|
||||
state: None,
|
||||
}
|
||||
/// 转成禁用:**只清消息**,图标 / 选中态 / 状态层全部保留(复审 P2-1)。
|
||||
///
|
||||
/// 官方禁用态是「容器/描边 12%、文字与**图标** 38%」——只降**不删**。早先的
|
||||
/// `Chip::disabled(label, variant)` 把 leading / trailing / selected 一起丢掉,实测
|
||||
/// assist 78→54、filter·on 74→50(连填充和勾都没了),禁用列里 `filter·on` 与 `filter`
|
||||
/// 逐像素同形,看不出选中与否。
|
||||
pub fn disabled(mut self) -> Self {
|
||||
self.on_press = None;
|
||||
self
|
||||
}
|
||||
|
||||
fn new(label: &'a str, variant: ChipVariant, selected: bool, on_press: M) -> Self {
|
||||
|
||||
@@ -163,22 +163,21 @@ fn draw(ui: &Ui, spec: Row, state: Interaction) -> Element<'_, ()> {
|
||||
ChipVariant::Filter => "Filter",
|
||||
ChipVariant::Input => "Input",
|
||||
};
|
||||
let chip = if disabled {
|
||||
Chip::disabled(label, variant)
|
||||
} else {
|
||||
match variant {
|
||||
ChipVariant::Assist => Chip::assist(label, ()).leading(IconKind::Download),
|
||||
// Filter 的勾只在**选中**时给(选中态才需要「已筛选」的强提示)
|
||||
ChipVariant::Filter if selected => {
|
||||
Chip::filter(label, true, ()).leading(IconKind::Check)
|
||||
}
|
||||
ChipVariant::Filter => Chip::filter(label, false, ()).leading(IconKind::Filter),
|
||||
// Input chip:前置图标 + 后置关闭键(avatar 位用图标代替)
|
||||
ChipVariant::Input => Chip::input(label, ())
|
||||
.leading(IconKind::Folder)
|
||||
.trailing(IconKind::Close),
|
||||
// 禁用**只清消息**(`Chip::disabled()` 是修饰器):图标与选中态必须保留,
|
||||
// 否则禁用列里 `filter·on` 与 `filter` 会逐像素同形(复审 P2-1)。
|
||||
let chip = match variant {
|
||||
ChipVariant::Assist => Chip::assist(label, ()).leading(IconKind::Download),
|
||||
// Filter 的勾只在**选中**时给(选中态才需要「已筛选」的强提示)
|
||||
ChipVariant::Filter if selected => {
|
||||
Chip::filter(label, true, ()).leading(IconKind::Check)
|
||||
}
|
||||
ChipVariant::Filter => Chip::filter(label, false, ()).leading(IconKind::Filter),
|
||||
// Input chip:前置图标 + 后置关闭键(avatar 位用图标代替)
|
||||
ChipVariant::Input => Chip::input(label, ())
|
||||
.leading(IconKind::Folder)
|
||||
.trailing(IconKind::Close),
|
||||
};
|
||||
let chip = if disabled { chip.disabled() } else { chip };
|
||||
selection::chip(ui, chip.state(state))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user