mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 05:53:13 +00:00
Workspace clippy: fix lints across ui crates and tests
This commit is contained in:
@@ -13,6 +13,8 @@ use super::screen_pick::ScreenPickButton;
|
||||
use super::{ColorPicker, ColorPickerLayout, ColorPickerOutput, PickedColor};
|
||||
use crate::ui::{AreaMode, ColorPickerDialog, ColorPickerDialogLayout, ColorPickerTab, ColorWarning};
|
||||
|
||||
type StandardColors = (Vec<(Label, Srgba)>, Vec<(Label, Srgba)>);
|
||||
|
||||
/// A colour of full brightness and saturation at `hue` (0 to 1).
|
||||
fn hue_color(hue: f32) -> Srgba {
|
||||
let channel = |n: f32| (((hue * 6.0 + n) % 6.0 - 3.0).abs() - 1.0).clamp(0.0, 1.0);
|
||||
@@ -20,7 +22,7 @@ fn hue_color(hue: f32) -> Srgba {
|
||||
}
|
||||
|
||||
/// The Standard tab's honeycomb of 19 hues and its row of greys.
|
||||
fn standard_colors() -> (Vec<(Label, Srgba)>, Vec<(Label, Srgba)>) {
|
||||
fn standard_colors() -> StandardColors {
|
||||
let cells = (0..19).map(|i| (Label::from(format!("Color {}", i + 1)), hue_color(i as f32 / 19.0))).collect();
|
||||
let greys = (0..8)
|
||||
.map(|i| {
|
||||
|
||||
@@ -16,7 +16,7 @@ use craft_host::target::Caps;
|
||||
use craft_settings::Remembered;
|
||||
use craft_theme::{ColorModel, Srgba, builtin_models};
|
||||
use craft_ui::choice::{SwatchArrangement, SwatchTable};
|
||||
use craft_ui::contract::{Bind, CanvasGesture, CollectionEvent, Props as _, Sampler as _, ShowCollection as _, ShowContainer as _};
|
||||
use craft_ui::contract::{Bind, CanvasGesture, CollectionEvent, Sampler as _, ShowCollection as _, ShowContainer as _};
|
||||
use craft_ui::dialog::{
|
||||
ButtonPlace, Dialog, DialogId, DialogResult, DialogStack, FieldRefusal, StackDialog, dialog_id, serde_fields, set_serde_field,
|
||||
};
|
||||
@@ -37,6 +37,8 @@ use std::sync::Arc;
|
||||
use super::{ColorPicker, ColorPickerLayout, ColorWarning, PickedColor, ScreenPickGesture};
|
||||
use crate::{AreaMode, CmykModel, not_web_safe, web_safe};
|
||||
|
||||
type StandardColors = (Vec<(Label, Srgba)>, Vec<(Label, Srgba)>);
|
||||
|
||||
craft_ui::words! {
|
||||
/// The Color Picker dialog's own words, English by default. The picker body's words are `ColorPickerWords`; OK and
|
||||
/// Cancel are the common words.
|
||||
@@ -170,7 +172,7 @@ pub struct ColorPickerDialog {
|
||||
open: bool,
|
||||
layout: ColorPickerDialogLayout,
|
||||
/// The Standard tab's honeycomb cells and grey row.
|
||||
standard: Option<(Vec<(Label, Srgba)>, Vec<(Label, Srgba)>)>,
|
||||
standard: Option<StandardColors>,
|
||||
/// The tab the app asked to open on; it wins over the remembered one, once.
|
||||
tab: Option<ColorPickerTab>,
|
||||
}
|
||||
@@ -179,7 +181,7 @@ pub struct ColorPickerDialog {
|
||||
struct TabbedBody<'a> {
|
||||
title: &'a Label,
|
||||
words: &'a ColorPickerDialogWords,
|
||||
standard: Option<&'a (Vec<(Label, Srgba)>, Vec<(Label, Srgba)>)>,
|
||||
standard: Option<&'a StandardColors>,
|
||||
compare: Option<Mixed<PickedColor>>,
|
||||
}
|
||||
|
||||
|
||||
@@ -12,10 +12,7 @@ fn a_portal_answer_falls_back_only_when_it_failed() {
|
||||
assert_eq!(classify(2, quick, false, false, ¬hing), Decision::Retry, "a dialog that closed at once never showed");
|
||||
assert_eq!(classify(2, slow, false, false, ¬hing), Decision::Cancelled, "Esc in GNOME's dialog is a cancel");
|
||||
assert_eq!(classify(1, quick, false, false, ¬hing), Decision::Cancelled, "Cancel is never asked again");
|
||||
assert!(
|
||||
matches!(classify(0, slow, false, false, &file), Decision::Saved(saved) if saved.path == PathBuf::from("/s/a.txt")),
|
||||
"a save names its file"
|
||||
);
|
||||
assert!(matches!(classify(0, slow, false, false, &file), Decision::Saved(saved) if saved.path == *"/s/a.txt"), "a save names its file");
|
||||
assert_eq!(classify(0, slow, true, false, &file), Decision::Cancelled, "an answer after a queued cancel is a cancel");
|
||||
assert!(matches!(classify(0, slow, false, true, ¬hing), Decision::Unavailable(_)), "the portal left the bus");
|
||||
assert!(matches!(classify(3, slow, false, false, &file), Decision::Unavailable(_)), "another code is a failure");
|
||||
|
||||
@@ -398,7 +398,7 @@ impl FileChooser {
|
||||
PickKind::Save => (words.save_title.clone(), words.save.clone()),
|
||||
PickKind::Folder => (words.folder_title.clone(), words.choose.clone()),
|
||||
};
|
||||
let title = self.request.title.clone().map_or_else(|| title.into(), craft_ui::runtime::env::Label::from);
|
||||
let title = self.request.title.clone().map_or_else(|| title, craft_ui::runtime::env::Label::from);
|
||||
let mut types: Vec<Choice<usize>> =
|
||||
self.request.filters.iter().enumerate().map(|(at, filter)| Choice::new(at, filter.name.clone())).collect();
|
||||
types.push(Choice::new(self.request.filters.len(), words.all_files.clone()));
|
||||
@@ -517,7 +517,7 @@ impl FileChooser {
|
||||
return None;
|
||||
}
|
||||
if let Some(path) = seen.activated {
|
||||
let Some(entry) = rows.iter().find(|entry| entry.path == path).cloned() else { return None };
|
||||
let entry = rows.iter().find(|entry| entry.path == path).cloned()?;
|
||||
if entry.folder {
|
||||
self.navigate(entry.path);
|
||||
return None;
|
||||
|
||||
@@ -323,7 +323,7 @@ impl<'a> Keytips<'a> {
|
||||
.elements
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(index, element)| element.rect.is_positive() && !taken.contains(&(region, *index)) && matches(*element))
|
||||
.find(|(index, element)| element.rect.is_positive() && !taken.contains(&(region, *index)) && matches(element))
|
||||
.map(|(index, _)| (region, index))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ fn shown(ui: &mut Ui, size: ControlSize, letters: [Option<&'static str>; 5]) ->
|
||||
let controls: Vec<KeytipControl<'static>> = CONTROLS
|
||||
.iter()
|
||||
.zip(letters)
|
||||
.map(|((command, label), letters)| KeytipControl { command: CommandRef::from(*command), label: *label, letters })
|
||||
.map(|((command, label), letters)| KeytipControl { command: CommandRef::from(*command), label, letters })
|
||||
.collect();
|
||||
let output = Keytips::new(true).tabs(&tabs).controls(&controls).places(&places).show(ui);
|
||||
output.response.into()
|
||||
|
||||
@@ -35,6 +35,8 @@ use group::BodyHeight;
|
||||
pub use group::RibbonGroup;
|
||||
pub use plan::{GroupWidths, plan};
|
||||
|
||||
type ContextMenuBody<'a> = &'a mut dyn FnMut(&mut Ui, &RibbonMenuRequest, &mut BodyCx<'_>);
|
||||
|
||||
craft_ui::words! {
|
||||
/// The words of the ribbon's own controls.
|
||||
struct RibbonWords {
|
||||
@@ -66,7 +68,7 @@ pub struct Ribbon<'a, T: Clone + Eq + Hash + Send + Sync + Debug + 'static> {
|
||||
trailing: &'a [StripEnd<'a>],
|
||||
minimised: Option<Bind<'a, bool>>,
|
||||
/// The body of the context menu: the rows for the request that opened it.
|
||||
context_menu: Option<&'a mut dyn FnMut(&mut Ui, &RibbonMenuRequest, &mut BodyCx<'_>)>,
|
||||
context_menu: Option<ContextMenuBody<'a>>,
|
||||
}
|
||||
|
||||
impl<'a, T: Clone + Eq + Hash + Send + Sync + Debug + 'static> Ribbon<'a, T> {
|
||||
@@ -111,7 +113,7 @@ impl<'a, T: Clone + Eq + Hash + Send + Sync + Debug + 'static> Ribbon<'a, T> {
|
||||
pub fn show(mut self, ui: &mut Ui, mut body: impl FnMut(&mut RibbonRow<'_>, &T)) -> RibbonOutput<T> {
|
||||
let current = self.current();
|
||||
let minimised = self.minimised.as_mut().and_then(|bind| bind.reborrow().get()).and_then(|value| value.same().copied()).unwrap_or(false);
|
||||
let id = ui.id().with(self.label.as_str());
|
||||
let id = ui.scope_id().with(self.label.as_str());
|
||||
let tabs = self.tabs;
|
||||
let trailing = self.trailing;
|
||||
let strip_label = self.label.clone();
|
||||
|
||||
@@ -227,7 +227,7 @@ impl<'a> GalleryFace<'a> {
|
||||
fn picture(&self, aspect: ThumbAspect, size: ThumbSize) -> Picture<'a> {
|
||||
let picture = match self {
|
||||
GalleryFace::Image { key, revision, image } => Picture::new(Label::default(), *key, *image).revision(*revision),
|
||||
GalleryFace::Rendered { key, thumbnails, source } => Picture::rendered(Label::default(), *key, *thumbnails, *source),
|
||||
GalleryFace::Rendered { key, thumbnails, source } => Picture::rendered(Label::default(), *key, thumbnails, *source),
|
||||
GalleryFace::Paint(paint) => {
|
||||
let paint = *paint;
|
||||
Picture::painter(Label::default(), aspect, move |cx: &ContentPainterCx<'_>, rect: Rect| paint(cx, rect))
|
||||
|
||||
@@ -16,6 +16,8 @@ use egui::Ui;
|
||||
use super::{Gallery, GalleryFace, GalleryItem, GalleryMore};
|
||||
use crate::ribbon::GroupLevel;
|
||||
|
||||
type Paint = Box<dyn Fn(&craft_ui::primitives::ContentPainterCx, egui::Rect)>;
|
||||
|
||||
/// How many tiles every story's gallery holds: more than a row at either level.
|
||||
const COUNT: usize = 10;
|
||||
|
||||
@@ -95,7 +97,7 @@ fn gallery_compact(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
|set| {
|
||||
set.values.set(GroupLevel::Compact);
|
||||
},
|
||||
|ui| pictured(ui),
|
||||
pictured,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -128,12 +130,12 @@ fn gallery_more_open(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
#[story(Gallery<'static, usize>, covers = [], drive = Drive::Never)]
|
||||
fn gallery_painted(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
// Glyph tiles: a disc in the content painter's ink whose size grows with the tile's place.
|
||||
let paints: Vec<Box<dyn Fn(&craft_ui::primitives::ContentPainterCx, egui::Rect)>> = (0..COUNT)
|
||||
let paints: Vec<Paint> = (0..COUNT)
|
||||
.map(|at| {
|
||||
Box::new(move |cx: &craft_ui::primitives::ContentPainterCx, rect: egui::Rect| {
|
||||
let radius = rect.size().min_elem() * (at as f32 + 3.0) / (2.0 * COUNT as f32);
|
||||
cx.data_shapes([egui::Shape::circle_filled(rect.center(), radius, cx.ink())]);
|
||||
}) as Box<dyn Fn(&craft_ui::primitives::ContentPainterCx, egui::Rect)>
|
||||
}) as Paint
|
||||
})
|
||||
.collect();
|
||||
let items: Vec<GalleryItem<'_, usize>> =
|
||||
|
||||
@@ -150,7 +150,7 @@ fn detail(ui: &mut Ui, now: f64, env: &mut Env<'_>, state: &mut DialogState) {
|
||||
Text::new(line).shade(Shade::Muted).show(ui);
|
||||
}
|
||||
// A chord the command already holds is not assigned twice.
|
||||
let assignable = state.field.as_ref().is_some_and(|field| !env.keymap.bindings(&command).iter().any(|binding| *binding == field.binding));
|
||||
let assignable = state.field.as_ref().is_some_and(|field| !env.keymap.bindings(&command).contains(&field.binding));
|
||||
Row::new().show(ui, |ui, _| {
|
||||
if clicked(&Button::new(words.assign.clone()).id_salt("assign").enabled(assignable).show(ui)) {
|
||||
state.assign_field(env);
|
||||
|
||||
@@ -127,7 +127,7 @@ impl Rig {
|
||||
let tabs = [(Label::from("Home"), "H", tab_id("Home")), (Label::from("Insert"), "N", tab_id("Insert"))];
|
||||
let controls: Vec<KeytipControl<'_>> = CONTROLS
|
||||
.iter()
|
||||
.map(|(command, label, letters)| KeytipControl { command: CommandRef::from(*command), label: *label, letters: *letters })
|
||||
.map(|(command, label, letters)| KeytipControl { command: CommandRef::from(*command), label, letters: *letters })
|
||||
.collect();
|
||||
let sequences = [("VZ", CommandRef::from(Trial::Zoom)), ("TW", CommandRef::from(Trial::WordCount))];
|
||||
let output = Keytips::new(true).tabs(&tabs).controls(&controls).sequences(&sequences).places(&places).show(ui);
|
||||
|
||||
@@ -480,14 +480,12 @@ impl<'a> ReadingNav<'a> {
|
||||
}
|
||||
|
||||
/// Shows the "n / m" position between the buttons.
|
||||
#[must_use]
|
||||
pub fn position(mut self, shown: bool) -> Self {
|
||||
self.position = shown;
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds one trailing button named `label`, reported as [`ReadingNavOutput::action`].
|
||||
#[must_use]
|
||||
pub fn action(mut self, label: impl Into<craft_ui::runtime::env::Label>) -> Self {
|
||||
self.action = Some(label.into());
|
||||
self
|
||||
|
||||
@@ -178,7 +178,6 @@ pub trait SpoolBackend: Send + Sync {
|
||||
|
||||
/// Whether the user chooses a printer for a job; false where the platform's own print dialog
|
||||
/// does (the browser). [`Spool::chooses_printer`] answers it.
|
||||
|
||||
fn chooses_printer(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ pub(super) fn gap_part(index: usize, edge: GapEdge) -> u64 {
|
||||
|
||||
/// The gap and edge a part index of [`GAP`] stands for.
|
||||
pub(super) fn gap_of_part(part: u64) -> (usize, GapEdge) {
|
||||
((part / 2) as usize, if part % 2 == 0 { GapEdge::End } else { GapEdge::Start })
|
||||
((part / 2) as usize, if part.is_multiple_of(2) { GapEdge::End } else { GapEdge::Start })
|
||||
}
|
||||
|
||||
/// A marker or stop on the ruler.
|
||||
|
||||
@@ -15,9 +15,7 @@ fn toggled(fixture: &Fixture, label: &str) -> Option<Mixed<bool>> {
|
||||
|
||||
#[trial]
|
||||
fn word_paragraph_tabs_leave_mixed_boxes_unset_until_clicked() {
|
||||
let mut format = ParagraphFormat::default();
|
||||
format.breaks = Some(LineBreakOptions::default());
|
||||
format.asian = Some(AsianTypography::default());
|
||||
let format = ParagraphFormat { breaks: Some(LineBreakOptions::default()), asian: Some(AsianTypography::default()), ..ParagraphFormat::default() };
|
||||
let dialog = Rc::new(RefCell::new(ParagraphDialog::new(format).word(true).held_ok().tab(ParagraphTab::LineAndPageBreaks)));
|
||||
let shown = dialog.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
@@ -51,8 +49,7 @@ fn word_paragraph_tabs_leave_mixed_boxes_unset_until_clicked() {
|
||||
#[trial]
|
||||
fn a_mixed_contextual_spacing_box_clicked_is_on_in_the_answer() {
|
||||
const LABEL: &str = "Don't add space between paragraphs of the same style";
|
||||
let mut format = ParagraphFormat::default();
|
||||
format.contextual_spacing = Some(None);
|
||||
let format = ParagraphFormat { contextual_spacing: Some(None), ..ParagraphFormat::default() };
|
||||
let dialog = Rc::new(RefCell::new(ParagraphDialog::new(format).word(true).held_ok()));
|
||||
let shown = dialog.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
|
||||
@@ -16,7 +16,9 @@ fn focused<'a>(fixture: &Fixture, labels: &[&'a str]) -> Option<&'a str> {
|
||||
}
|
||||
|
||||
/// A fixture showing `dialog`, and where the result of a closing OK lands.
|
||||
fn shown(dialog: TabStopsDialog) -> (Fixture, Rc<RefCell<TabStopsDialog>>, Rc<RefCell<Option<TabStopsResult>>>) {
|
||||
type Shown = (Fixture, Rc<RefCell<TabStopsDialog>>, Rc<RefCell<Option<TabStopsResult>>>);
|
||||
|
||||
fn shown(dialog: TabStopsDialog) -> Shown {
|
||||
let dialog = Rc::new(RefCell::new(dialog));
|
||||
let result = Rc::new(RefCell::new(None));
|
||||
let (shown, landed) = (dialog.clone(), result.clone());
|
||||
|
||||
@@ -120,8 +120,7 @@ fn press_menu_key(fixture: &mut Fixture) {
|
||||
#[story(Canvas, covers = [Default])]
|
||||
fn document_wheel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let room = stage(ui);
|
||||
let mut navigation = NavigationOptions::default();
|
||||
navigation.wheel = WheelScheme::Document;
|
||||
let navigation = NavigationOptions { wheel: WheelScheme::Document, ..NavigationOptions::default() };
|
||||
let view = data.value("view", scrolled_view(room, ui.pixels_per_point()));
|
||||
Canvas::new("Document")
|
||||
.navigation(navigation)
|
||||
@@ -143,8 +142,7 @@ fn scrolled_view(room: Rect, pixels_per_point: f32) -> craft_behavior::CanvasVie
|
||||
#[story(Canvas, covers = [], drive = Drive::Custom(middle_click_centre))]
|
||||
fn middle_autoscroll(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let room = stage(ui);
|
||||
let mut navigation = NavigationOptions::default();
|
||||
navigation.middle_button = MiddleButton::Autoscroll;
|
||||
let navigation = NavigationOptions { middle_button: MiddleButton::Autoscroll, ..NavigationOptions::default() };
|
||||
let view = data.value("view", scrolled_view(room, ui.pixels_per_point()));
|
||||
let shown = Canvas::new("Document")
|
||||
.navigation(navigation)
|
||||
|
||||
@@ -109,7 +109,12 @@ fn snap_targets_snap_points_and_boxes_unless_control_suspends() {
|
||||
assert_eq!(snap.apply(Axis::Y, 103.0, Mods::NONE), 100.0);
|
||||
assert_eq!(snapped_with(&mut fixture, Modifiers::CTRL), NEAR, "Ctrl held suspends the tool's snap");
|
||||
|
||||
// With Alt as the suspend key, Alt suspends and Control no longer does, on either OS.
|
||||
alt_suspends(options);
|
||||
snap_off(options);
|
||||
}
|
||||
|
||||
/// With Alt as the suspend key, Alt suspends and Control no longer does, on either OS.
|
||||
fn alt_suspends(options: SnapOptions) {
|
||||
let mut alt = options;
|
||||
alt.suspend = SnapSuspend::Alt;
|
||||
for os in [Platform::Mac, Platform::Windows] {
|
||||
@@ -132,7 +137,10 @@ fn snap_targets_snap_points_and_boxes_unless_control_suspends() {
|
||||
assert_eq!(snapped_with(&mut fixture, Modifiers::ALT), NEAR, "Alt held suspends the tool's snap on {os:?}");
|
||||
assert_eq!(snapped_with(&mut fixture, Modifiers::CTRL), Point::new(100.0, 200.0), "Control held snaps the tool on {os:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// With View > Snap off nothing snaps.
|
||||
fn snap_off(options: SnapOptions) {
|
||||
let mut off = options;
|
||||
off.on = false;
|
||||
let (mut fixture, seen) = rig(Snap::new(targets(), off));
|
||||
|
||||
@@ -263,7 +263,6 @@ impl<'a> AboutDialog<'a> {
|
||||
}
|
||||
|
||||
/// How the About tab lays out the info, and the footer button that goes with it.
|
||||
#[must_use]
|
||||
pub fn layout(mut self, layout: AboutLayout) -> Self {
|
||||
self.layout = layout;
|
||||
self
|
||||
|
||||
@@ -443,7 +443,7 @@ impl<'a, V: Value + Default> FormDialog<'a, V> {
|
||||
reset_with,
|
||||
on_reset,
|
||||
opening,
|
||||
held: mut hold,
|
||||
held: hold,
|
||||
} = self;
|
||||
// A measuring run files and closes nothing: the real run that follows does.
|
||||
let measuring_run = crate::runtime::measure::active(ui.ctx());
|
||||
@@ -616,10 +616,10 @@ impl<'a, V: Value + Default> FormDialog<'a, V> {
|
||||
let _ = held.reborrow().write(cx, &EditEvent::set(Mixed::Same(before.clone()), values.clone(), name.clone(), None));
|
||||
*changed.borrow_mut() = Some(values.clone());
|
||||
}
|
||||
if let Some((reason, refused)) = &refusal {
|
||||
if *refused == values {
|
||||
reason_cell.set(Some(reason.clone()));
|
||||
}
|
||||
if let Some((reason, refused)) = &refusal
|
||||
&& *refused == values
|
||||
{
|
||||
reason_cell.set(Some(reason.clone()));
|
||||
}
|
||||
if finish && !accept_stays_open {
|
||||
cx.request_close_as(CloseReason::Activated);
|
||||
@@ -634,18 +634,18 @@ impl<'a, V: Value + Default> FormDialog<'a, V> {
|
||||
Some(CloseReason::Enter | CloseReason::Activated) if accepts.get() && hold.is_none() && !no_ok => work.borrow().clone(),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(held) = hold.as_deref_mut() {
|
||||
if let Some(held) = hold {
|
||||
let values = work.into_inner();
|
||||
if let (Some((_, refused)), Some(values)) = (held.refusal(), values.as_ref()) {
|
||||
if refused != values {
|
||||
held.clear_refusal();
|
||||
}
|
||||
if let (Some((_, refused)), Some(values)) = (held.refusal(), values.as_ref())
|
||||
&& refused != values
|
||||
{
|
||||
held.clear_refusal();
|
||||
}
|
||||
// The pass reports a press only in the pass that took the input, so a second pass of the frame files nothing.
|
||||
if let (false, true, Some(0), Some(values)) = (measuring_run, accepts.get(), picked, values.as_ref()) {
|
||||
if !held.is_waiting() {
|
||||
held.file(values.clone());
|
||||
}
|
||||
if let (false, true, Some(0), Some(values)) = (measuring_run, accepts.get(), picked, values.as_ref())
|
||||
&& !held.is_waiting()
|
||||
{
|
||||
held.file(values.clone());
|
||||
}
|
||||
if finish && (accept_stays_open || closed == Some(CloseReason::Activated)) {
|
||||
accepted = held.finish();
|
||||
|
||||
@@ -22,6 +22,8 @@ use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
type UnderList<'a> = Box<dyn FnMut(&mut Ui) + 'a>;
|
||||
|
||||
#[cfg(feature = "testing")]
|
||||
mod stories;
|
||||
|
||||
@@ -311,12 +313,11 @@ pub struct ListManager<'a> {
|
||||
#[prop(into)]
|
||||
cancel_label: Option<Label>,
|
||||
/// Draws a section under the list.
|
||||
under: Option<Box<dyn FnMut(&mut Ui) + 'a>>,
|
||||
under: Option<UnderList<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> ListManager<'a> {
|
||||
/// Draws `content` under the list.
|
||||
#[must_use]
|
||||
pub fn under_list(mut self, content: impl FnMut(&mut Ui) + 'a) -> Self {
|
||||
self.under = Some(Box::new(content));
|
||||
self
|
||||
@@ -324,7 +325,6 @@ impl<'a> ListManager<'a> {
|
||||
|
||||
/// Binds the name box's text to `bind`: the caller reads what the user typed and sets the text, which the box
|
||||
/// shows on the next pass. The `name` prop does not apply then.
|
||||
#[must_use]
|
||||
pub fn name_box(mut self, bind: Bind<'a, String>) -> Self {
|
||||
self.name_box = Some(bind);
|
||||
self
|
||||
|
||||
@@ -8,7 +8,6 @@ use crate::display::Text;
|
||||
use crate::form::Field;
|
||||
use crate::pickers::{Anchor9, ReferencePoint, Select};
|
||||
use crate::runtime::env::{ColumnSize, Label, UnitKind};
|
||||
use crate::runtime::overlay::CloseReason;
|
||||
use crate::sections::Section;
|
||||
use craft_behavior::PixelSize;
|
||||
use craft_theme::variant::Tone;
|
||||
|
||||
@@ -166,7 +166,7 @@ impl<'a> CommandPalette<'a> {
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<PanelWords>();
|
||||
let list_id = ui.scope_id().with("palette-rows");
|
||||
let hint: Label = placeholder.unwrap_or_else(|| Label::from(words.palette_placeholder.clone()));
|
||||
let hint: Label = placeholder.unwrap_or_else(|| words.palette_placeholder.clone());
|
||||
let mut chosen = Chosen::default();
|
||||
let shown = Popover::new(label.clone(), open)
|
||||
.collection_body()
|
||||
@@ -218,7 +218,7 @@ impl<'a> CommandPalette<'a> {
|
||||
let scope = ui.scope_id();
|
||||
let list_id = scope.with("palette-rows");
|
||||
let field_id = scope.with("palette-field");
|
||||
let face_hint: Label = placeholder.unwrap_or_else(|| Label::from(words.palette_placeholder.clone()));
|
||||
let face_hint: Label = placeholder.unwrap_or_else(|| words.palette_placeholder.clone());
|
||||
let mut chosen = Chosen::default();
|
||||
let mut closed = None;
|
||||
let shown = Row::new().show(ui, |ui, cx| {
|
||||
|
||||
@@ -36,7 +36,7 @@ fn picker(ui: &mut egui::Ui, picked: &Picked, say: fn(&str) -> String) {
|
||||
});
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
let positions: Vec<usize> = (0..LAYOUTS.len()).collect();
|
||||
TileGrid::<usize>::new("Layouts")
|
||||
let _ = TileGrid::<usize>::new("Layouts")
|
||||
.select(SelectMode::Single)
|
||||
.card_columns(3)
|
||||
.max_rows(3)
|
||||
|
||||
@@ -46,21 +46,18 @@ impl<'a> RecentList<'a> {
|
||||
}
|
||||
|
||||
/// At most this many recent files show.
|
||||
#[must_use]
|
||||
pub fn max_recent(mut self, max_recent: usize) -> Self {
|
||||
self.max_recent = max_recent;
|
||||
self
|
||||
}
|
||||
|
||||
/// The text shown when there are no recent files.
|
||||
#[must_use]
|
||||
pub fn empty(mut self, empty: impl Into<Label>) -> Self {
|
||||
self.empty = Some(empty.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// The time the age lines count from, in seconds since the Unix epoch. Without it the rows show no age.
|
||||
#[must_use]
|
||||
pub fn now(mut self, now: Option<i64>) -> Self {
|
||||
self.now = now;
|
||||
self
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use craft_host::target::ShellInfo;
|
||||
use craft_ui::bars::{Bar, BarKind};
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{Bind, CommandSet, Props as _, Scroll, Show as _, ShowContainer as _};
|
||||
use craft_ui::contract::{Bind, CommandSet, Scroll, Show as _, ShowContainer as _};
|
||||
use craft_ui::dialog::Dialog;
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
|
||||
@@ -228,7 +228,7 @@ fn at_level(ui: &mut Ui, level: GroupLevel, show: fn(&mut Ui) -> Response) -> Re
|
||||
|overrides| {
|
||||
overrides.values.set(level);
|
||||
},
|
||||
|ui| show(ui),
|
||||
show,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -268,7 +268,8 @@ fn shown(name: &str, show: fn(&mut Ui) -> Response, compact: bool) -> Shown {
|
||||
|
||||
#[trial]
|
||||
fn an_inline_button_drops_its_label_under_a_compact_group_and_names_itself_by_tooltip() {
|
||||
let cases: [(&str, fn(&mut Ui) -> Response); 2] = [("Save", save), ("Trace", trace)];
|
||||
type Case<'a> = (&'a str, fn(&mut Ui) -> Response);
|
||||
let cases: [Case; 2] = [("Save", save), ("Trace", trace)];
|
||||
for (name, show) in cases {
|
||||
let full = shown(name, show, false);
|
||||
let compact = shown(name, show, true);
|
||||
|
||||
@@ -25,7 +25,7 @@ fn shown(width: f32) -> (usize, String) {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
Row::new().fill_width().show(ui, |ui, _| {
|
||||
Text::new(LINE).elide(Elide::End).show(ui);
|
||||
levelled_unit(ui, Id::new("levelled"), LEVELS.len(), |ui, at| {
|
||||
levelled_unit(ui, Id::unique("levelled"), LEVELS.len(), |ui, at| {
|
||||
if !is_measuring(ui.ctx()) && !ui.is_sizing_pass() {
|
||||
seen.set(at);
|
||||
}
|
||||
|
||||
@@ -272,10 +272,8 @@ fn a_header_field_edits_and_a_header_remove_reports_its_column() {
|
||||
let mut stops = vec![first];
|
||||
for _ in 0..4 {
|
||||
fixture.key(Key::ArrowRight, Modifiers::NONE).settle();
|
||||
if let Some(stop) = fixture.focused_stop() {
|
||||
if !stops.contains(&stop) {
|
||||
stops.push(stop);
|
||||
}
|
||||
if let Some(stop) = fixture.focused_stop().filter(|stop| !stops.contains(stop)) {
|
||||
stops.push(stop);
|
||||
}
|
||||
}
|
||||
assert!(stops.iter().any(|(_, part)| part.is_some()), "the header's group has a header part: {stops:?}");
|
||||
|
||||
@@ -475,7 +475,7 @@ fn end_view(room: f32) -> EndView {
|
||||
let keys: Vec<usize> = (0..RIBBON.len()).collect();
|
||||
let source = keyed(&keys, |key: &usize| *key);
|
||||
let strip = TabStrip::new("Ribbon").kind(TabKind::Ribbon).shown(1).roles(ribbon_role).trailing(&items);
|
||||
strip.show_items(ui, &source, &mut |key, _| Tab::new(RIBBON[*key]).role(ribbon_role(key)));
|
||||
let _ = strip.show_items(ui, &source, &mut |key, _| Tab::new(RIBBON[*key]).role(ribbon_role(key)));
|
||||
};
|
||||
frames.idle(3, &mut show);
|
||||
let tree = frames.tree();
|
||||
@@ -558,7 +558,7 @@ fn comments_width(menu: bool) -> f32 {
|
||||
let keys: Vec<usize> = (0..RIBBON.len()).collect();
|
||||
let source = keyed(&keys, |key: &usize| *key);
|
||||
let strip = TabStrip::new("Ribbon").kind(TabKind::Ribbon).shown(1).roles(ribbon_role).trailing(&items);
|
||||
strip.show_items(ui, &source, &mut |key, _| Tab::new(RIBBON[*key]).role(ribbon_role(key)));
|
||||
let _ = strip.show_items(ui, &source, &mut |key, _| Tab::new(RIBBON[*key]).role(ribbon_role(key)));
|
||||
};
|
||||
frames.idle(3, &mut show);
|
||||
let tree = frames.tree();
|
||||
|
||||
Reference in New Issue
Block a user