mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 04:27:49 +00:00
Workspace clippy: unused imports, auto-deref, an unused clipboard helper, a chord-match type, field facts grouped, trial asserts, device tests under cfg(test)
This commit is contained in:
@@ -23,7 +23,8 @@ mod registry;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(all(test, feature = "startup"))]
|
||||
#[cfg(test)]
|
||||
#[cfg(feature = "startup")]
|
||||
mod device_tests;
|
||||
|
||||
pub use caps::DeviceCaps;
|
||||
|
||||
@@ -218,7 +218,7 @@ impl FileIntake {
|
||||
pub fn take(&self) -> Vec<Intake> {
|
||||
#[cfg(any(test, all(target_os = "macos", feature = "apple-events")))]
|
||||
{
|
||||
let mine: Vec<std::rc::Rc<dyn Fn(&IntakeSender)>> = DRAINS.with(|drains| {
|
||||
let mine: Vec<_> = DRAINS.with(|drains| {
|
||||
drains
|
||||
.borrow()
|
||||
.iter()
|
||||
|
||||
@@ -47,7 +47,6 @@ pub fn show_item<C>(ui: &mut Ui, rect: Rect, item: C, at: crate::runtime::access
|
||||
where
|
||||
C: super::Component + super::Props + super::Show,
|
||||
{
|
||||
use super::Show as _;
|
||||
with_item_facts(ui, at, |ui, id| super::Props::id(item, id).show_at(ui, rect))
|
||||
}
|
||||
|
||||
@@ -56,7 +55,6 @@ pub fn show_item_in_flow<C>(ui: &mut Ui, item: C, at: crate::runtime::access::Se
|
||||
where
|
||||
C: super::Component + super::Props + super::Show,
|
||||
{
|
||||
use super::Show as _;
|
||||
with_item_facts(ui, at, |ui, id| super::Props::id(item, id).show(ui))
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::{header, rows};
|
||||
use crate::contract::body::EnvFacts;
|
||||
use crate::contract::collection::RowState;
|
||||
use crate::contract::run::{Measuring, ShowAt};
|
||||
use crate::contract::{Collection, Internal, ItemCx, Props, Show as _, Sizing};
|
||||
use crate::contract::{Collection, Internal, ItemCx, Props, Show as _};
|
||||
use crate::runtime::access::SetPosition;
|
||||
use crate::runtime::env::{Env, EnvView, ItemFacts};
|
||||
use crate::runtime::layout_memory;
|
||||
|
||||
@@ -307,17 +307,16 @@ fn serve_access<C: Component>(cx: &mut Cx<'_, C>, state: &mut TextState, widget:
|
||||
}
|
||||
}
|
||||
|
||||
/// The text facts AccessKit reads this pass, built only while AccessKit runs.
|
||||
fn facts<C: Component>(
|
||||
cx: &Cx<'_, C>,
|
||||
state: &mut TextState,
|
||||
widget: egui::Id,
|
||||
out: &adapter::AdapterOut,
|
||||
rect: Rect,
|
||||
/// What a field says about itself to AccessKit besides its text.
|
||||
struct FieldFacts {
|
||||
masked: bool,
|
||||
read_only: bool,
|
||||
enabled: bool,
|
||||
) {
|
||||
}
|
||||
|
||||
/// The text facts AccessKit reads this pass, built only while AccessKit runs.
|
||||
fn facts<C: Component>(cx: &Cx<'_, C>, state: &mut TextState, widget: egui::Id, out: &adapter::AdapterOut, rect: Rect, field: FieldFacts) {
|
||||
let FieldFacts { masked, read_only, enabled } = field;
|
||||
if !text_access::exposed(&cx.core.ctx, widget) {
|
||||
state.rows = None;
|
||||
return;
|
||||
@@ -514,7 +513,7 @@ pub(crate) fn run<C: Component>(
|
||||
if let Some(baseline) = out.baseline {
|
||||
cx.core.paint.borrow_mut().baseline.get_or_insert(baseline);
|
||||
}
|
||||
facts(cx, &mut state, widget, &out, decl.rect, decl.options.mask, read_only, enabled);
|
||||
facts(cx, &mut state, widget, &out, decl.rect, FieldFacts { masked: decl.options.mask, read_only, enabled });
|
||||
cx.core.text_invalid = state.invalid;
|
||||
cx.core.text_unparsed = decl.options.unparsed.clone().filter(|_| state.invalid);
|
||||
cx.core.escape_to_list = state.completions.open || list_open;
|
||||
|
||||
@@ -658,7 +658,7 @@ fn run_shrinking<R>(ui: &mut Ui, id: Id, mut body: impl FnMut(&mut Ui) -> R) ->
|
||||
vec![0; levelled.len()]
|
||||
};
|
||||
let width_at = |leaf: &Reported, level: usize| leaf.levels.get(level).copied().unwrap_or_default();
|
||||
let held: f32 = levelled.iter().zip(&levels).map(|(leaf, level)| width_at(*leaf, *level)).sum();
|
||||
let held: f32 = levelled.iter().zip(&levels).map(|(leaf, level)| width_at(leaf, *level)).sum();
|
||||
let widths = if room.is_finite() {
|
||||
shrink_or_drop(&units, &whole, &first, (fixed + held, gap), room, order, drops)
|
||||
} else {
|
||||
@@ -675,7 +675,7 @@ fn run_shrinking<R>(ui: &mut Ui, id: Id, mut body: impl FnMut(&mut Ui) -> R) ->
|
||||
}
|
||||
for (leaf, level) in levelled.iter().zip(levels) {
|
||||
// The level travels as the record's height (`level_of`).
|
||||
let measured = layout_memory::Measured::new(Vec2::new(room, 0.0), Vec2::new(width_at(*leaf, level), level as f32));
|
||||
let measured = layout_memory::Measured::new(Vec2::new(room, 0.0), Vec2::new(width_at(leaf, level), level as f32));
|
||||
layout_memory::emit_shrink(&ctx, shrink_key(id, leaf.leaf), measured, false);
|
||||
}
|
||||
again
|
||||
|
||||
@@ -267,6 +267,8 @@ struct View {
|
||||
edits: Option<(EditSet, EditSet)>,
|
||||
gens: ViewGens,
|
||||
}
|
||||
/// A press's double-press matcher, its time, and whether a binding's command accepts the press where it lands.
|
||||
type ChordMatch<'a> = (&'a mut Matcher, f64, &'a dyn Fn(&CommandRef) -> bool);
|
||||
|
||||
/// What a resolution read besides the board's own generation and the gate.
|
||||
#[derive(Default)]
|
||||
@@ -822,13 +824,7 @@ impl KeyScopes {
|
||||
/// held scope's keys stay with the text while typing; a typing scope's keys are the text component's own.
|
||||
/// With a matcher, a binding of a command `accept` refuses (disabled where the press lands) is passed over for the
|
||||
/// press's next binding.
|
||||
fn press(
|
||||
&self,
|
||||
layout: &Layout,
|
||||
input: &KeyInput,
|
||||
typing: bool,
|
||||
matcher: Option<(&mut Matcher, f64, &dyn Fn(&CommandRef) -> bool)>,
|
||||
) -> Option<Hit> {
|
||||
fn press(&self, layout: &Layout, input: &KeyInput, typing: bool, matcher: Option<ChordMatch<'_>>) -> Option<Hit> {
|
||||
let (panel, outer) = self.scopes.split_first().map_or((None, &[][..]), |(panel, outer)| (Some(*panel), outer));
|
||||
let held: &[&'static str] = if typing { &[] } else { &self.held };
|
||||
let contexts: Vec<&str> = self.typing.iter().chain(held).copied().collect();
|
||||
|
||||
@@ -160,13 +160,6 @@ pub(crate) fn copy_text(ctx: &Context, text: String) {
|
||||
});
|
||||
}
|
||||
|
||||
/// Puts `image` on the installed clipboard.
|
||||
pub(crate) fn copy_image(ctx: &Context, image: ColorImage) {
|
||||
with(ctx, |clipboard| {
|
||||
let _ = clipboard.write_image(&clipboard_image(&image));
|
||||
});
|
||||
}
|
||||
|
||||
/// Asks the platform for the clipboard text, which arrives as a paste event.
|
||||
pub(crate) fn request_paste(ctx: &Context) {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::RequestPaste);
|
||||
|
||||
@@ -635,7 +635,7 @@ pub(crate) fn key_id(key: &impl Hash) -> Id {
|
||||
use std::hash::Hasher as _;
|
||||
let mut hasher = std::collections::hash_map::DefaultHasher::new();
|
||||
key.hash(&mut hasher);
|
||||
Id::new(hasher.finish())
|
||||
Id::unique(hasher.finish())
|
||||
}
|
||||
|
||||
/// The types that reach the motion service.
|
||||
|
||||
@@ -133,18 +133,16 @@ fn an_accent_part_paints_in_the_accent_ink_a_fixed_part_as_drawn_and_both_take_t
|
||||
let disabled = paint(LAYERED_NAME, DataMode::Dimmed, ink);
|
||||
let enabled_in_the_disabled_colour = paint(LAYERED_NAME, DataMode::Full, off);
|
||||
|
||||
let [(ink_layer, ink_tint), (accent_layer, accent_tint), (fixed_layer, fixed_tint)] = enabled[..] else {
|
||||
panic!("an app icon paints its ink, accent and fixed layers, got {enabled:?}")
|
||||
};
|
||||
assert_eq!(enabled.len(), 3, "an app icon paints its ink, accent and fixed layers, got {enabled:?}");
|
||||
let [(ink_layer, ink_tint), (accent_layer, accent_tint), (fixed_layer, fixed_tint)] = enabled[..] else { return };
|
||||
assert_eq!(ink_tint, ink, "the plain parts read in the icon's colour");
|
||||
assert_eq!(accent_tint, rgba_color(tokens.color.accent.solid), "the accent parts read in the accent ink");
|
||||
assert_ne!(accent_tint, ink_tint);
|
||||
assert_eq!(fixed_tint, Color32::WHITE, "the fixed parts keep the colours they are drawn in");
|
||||
assert!(ink_layer != accent_layer && accent_layer != fixed_layer && ink_layer != fixed_layer, "each layer is its own texture");
|
||||
|
||||
let [(off_ink, a), (off_accent, b), (off_fixed, c)] = disabled[..] else {
|
||||
panic!("a disabled app icon paints the same three layers, got {disabled:?}")
|
||||
};
|
||||
assert_eq!(disabled.len(), 3, "a disabled app icon paints the same three layers, got {disabled:?}");
|
||||
let [(off_ink, a), (off_accent, b), (off_fixed, c)] = disabled[..] else { return };
|
||||
assert_eq!([a, b, c], [ink; 3], "every layer takes the one ink when the component is disabled");
|
||||
assert_eq!((off_ink, off_accent), (ink_layer, accent_layer), "the ink and accent layers are the same drawings, tinted");
|
||||
assert_ne!(off_fixed, fixed_layer, "a disabled fixed part is drawn as a silhouette, not in its own colours");
|
||||
@@ -153,7 +151,9 @@ fn an_accent_part_paints_in_the_accent_ink_a_fixed_part_as_drawn_and_both_take_t
|
||||
assert_eq!(tints, [off, rgba_color(tokens.color.accent.solid), Color32::WHITE], "an enabled icon in the disabled colour keeps its layers");
|
||||
|
||||
// What each layer holds: the class split is the SVG engine's, so a sheet it ignored would give every layer the whole drawing.
|
||||
let Some(layered) = icon(LAYERED_NAME) else { panic!("the layered icon resolves") };
|
||||
let layered = icon(LAYERED_NAME);
|
||||
assert!(layered.is_some(), "the layered icon resolves");
|
||||
let Some(layered) = layered else { return };
|
||||
let (body, nib, cap) = ((9, 12), (16, 12), (3, 12));
|
||||
let [plain, accent, fixed] = [Layer::Ink, Layer::Accent, Layer::Fixed].map(|layer| layered.layer(24.0, 1.0, layer));
|
||||
assert!(texel(&plain, body.0, body.1).a() > 0 && texel(&plain, nib.0, nib.1).a() == 0, "the ink layer holds the plain body only");
|
||||
|
||||
Reference in New Issue
Block a user