mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-18 01:22:49 +00:00
Lints: ui-widgets and ui-contract trial findings
This commit is contained in:
@@ -250,6 +250,9 @@ impl ItemSource<usize> for WithSubRow {
|
||||
}
|
||||
}
|
||||
|
||||
/// A step of the trial: what it does with the frames, the scene and the table's `show`.
|
||||
type Act = dyn Fn(&mut Frames, &Scene, &mut dyn FnMut(&mut Ui));
|
||||
|
||||
/// A sub-row's toggle cell lies at the start of its content: a press there flips it, a press in its empty toggle
|
||||
/// column does nothing, and a sweep down the column passes it by.
|
||||
#[trial]
|
||||
@@ -260,7 +263,7 @@ fn a_sub_rows_toggle_takes_presses_at_the_start_of_its_content() {
|
||||
ColumnSpec::new(NAME, "Name", ColumnWidth::Fixed(2.0 * COL)),
|
||||
])
|
||||
};
|
||||
let run = |act: &dyn Fn(&mut Frames, &Scene, &mut dyn FnMut(&mut Ui))| {
|
||||
let run = |act: &Act| {
|
||||
let scene = Scene::default();
|
||||
let mut frames = Frames::new();
|
||||
let mut show = |ui: &mut Ui| show_table(ui, props(), &WithSubRow, &scene);
|
||||
|
||||
@@ -268,8 +268,10 @@ impl BarItems {
|
||||
}
|
||||
_ => groups.push((present.item.section, Group { items: vec![at], extent: length, keep: FitKeep::Free })),
|
||||
}
|
||||
if present.item.keep == FitKeep::Pinned {
|
||||
groups.last_mut().expect("just pushed").1.keep = FitKeep::Pinned;
|
||||
if present.item.keep == FitKeep::Pinned
|
||||
&& let Some((_, group)) = groups.last_mut()
|
||||
{
|
||||
group.keep = FitKeep::Pinned;
|
||||
}
|
||||
}
|
||||
groups.into_iter().map(|(_, group)| group).collect()
|
||||
|
||||
@@ -114,7 +114,7 @@ impl Component for Badge {
|
||||
|
||||
fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 {
|
||||
let text = cx.layout(&TextRun::new(cx.resolved.label).role(cx.style.text.role)).size();
|
||||
Vec2::new(text.x + self.mark_room(&cx.style, text.y), text.y)
|
||||
Vec2::new(text.x + self.mark_room(cx.style, text.y), text.y)
|
||||
}
|
||||
|
||||
fn sense(&self) -> Sense {
|
||||
@@ -126,7 +126,7 @@ impl Component for Badge {
|
||||
let text = if self.muted { &cx.style.muted } else { &cx.style.text };
|
||||
let run = TextRun::new(cx.resolved.label).role(text.role).color(cx.resolve(&text.color)).wrap(Wrap::Elide);
|
||||
let content = cx.content_rect;
|
||||
let room = self.mark_room(&cx.style, content.height());
|
||||
let room = self.mark_room(cx.style, content.height());
|
||||
let (label, _) = Flow::new(content, cx.flow.is_rtl()).take_start((content.width() - room).max(0.0));
|
||||
let layout = draw.layout(&run, label.width());
|
||||
draw.galley(label.center() - layout.size() / 2.0, &layout);
|
||||
|
||||
@@ -22,7 +22,9 @@ impl<K> RowTest<'_, K> {
|
||||
}
|
||||
|
||||
/// A text for the row of a key, or none: `List::rename_draft`.
|
||||
pub struct RowText<'a, K>(Box<dyn Fn(&K) -> Option<String> + 'a>);
|
||||
pub struct RowText<'a, K>(RowTextFn<'a, K>);
|
||||
|
||||
type RowTextFn<'a, K> = Box<dyn Fn(&K) -> Option<String> + 'a>;
|
||||
|
||||
impl<'a, K> RowText<'a, K> {
|
||||
/// The text `text` gives.
|
||||
|
||||
@@ -381,11 +381,11 @@ impl<'a> Notice<'a> {
|
||||
|
||||
/// The sizes of the actions' faces; a centred notice's buttons all take the widest one's width.
|
||||
fn action_sizes(&self, cx: &MeasureCx<'_, Self>) -> Vec<Vec2> {
|
||||
let labels = self.action_labels(cx).into_iter().enumerate();
|
||||
let labels = self.action_labels(cx);
|
||||
if self.row() {
|
||||
return labels.map(|(_, label)| cx.face(Self::link(cx.style.message.role, label))).collect();
|
||||
return labels.into_iter().map(|label| cx.face(Self::link(cx.style.message.role, label))).collect();
|
||||
}
|
||||
let sizes: Vec<Vec2> = labels.map(|(at, label)| cx.face(Self::button(at, label))).collect();
|
||||
let sizes: Vec<Vec2> = labels.into_iter().enumerate().map(|(at, label)| cx.face(Self::button(at, label))).collect();
|
||||
let widest = sizes.iter().map(|size| size.x).fold(0.0, f32::max);
|
||||
sizes.into_iter().map(|size| Vec2::new(widest, size.y)).collect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user