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)
|
Self::new(label, ChipVariant::Input, false, on_press)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 禁用的 chip(无消息)。
|
/// 转成禁用:**只清消息**,图标 / 选中态 / 状态层全部保留(复审 P2-1)。
|
||||||
pub fn disabled(label: &'a str, variant: ChipVariant) -> Self {
|
///
|
||||||
Self {
|
/// 官方禁用态是「容器/描边 12%、文字与**图标** 38%」——只降**不删**。早先的
|
||||||
label,
|
/// `Chip::disabled(label, variant)` 把 leading / trailing / selected 一起丢掉,实测
|
||||||
variant,
|
/// assist 78→54、filter·on 74→50(连填充和勾都没了),禁用列里 `filter·on` 与 `filter`
|
||||||
selected: false,
|
/// 逐像素同形,看不出选中与否。
|
||||||
leading: None,
|
pub fn disabled(mut self) -> Self {
|
||||||
trailing: None,
|
self.on_press = None;
|
||||||
on_press: None,
|
self
|
||||||
state: None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(label: &'a str, variant: ChipVariant, selected: bool, on_press: M) -> 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::Filter => "Filter",
|
||||||
ChipVariant::Input => "Input",
|
ChipVariant::Input => "Input",
|
||||||
};
|
};
|
||||||
let chip = if disabled {
|
// 禁用**只清消息**(`Chip::disabled()` 是修饰器):图标与选中态必须保留,
|
||||||
Chip::disabled(label, variant)
|
// 否则禁用列里 `filter·on` 与 `filter` 会逐像素同形(复审 P2-1)。
|
||||||
} else {
|
let chip = match variant {
|
||||||
match variant {
|
ChipVariant::Assist => Chip::assist(label, ()).leading(IconKind::Download),
|
||||||
ChipVariant::Assist => Chip::assist(label, ()).leading(IconKind::Download),
|
// Filter 的勾只在**选中**时给(选中态才需要「已筛选」的强提示)
|
||||||
// Filter 的勾只在**选中**时给(选中态才需要「已筛选」的强提示)
|
ChipVariant::Filter if selected => {
|
||||||
ChipVariant::Filter if selected => {
|
Chip::filter(label, true, ()).leading(IconKind::Check)
|
||||||
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),
|
|
||||||
}
|
}
|
||||||
|
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))
|
selection::chip(ui, chip.state(state))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user