diff --git a/crates/draw/src/ui/stroke/button.rs b/crates/draw/src/ui/stroke/button.rs index 8bcc8be1f..b2c5c7d7c 100644 --- a/crates/draw/src/ui/stroke/button.rs +++ b/crates/draw/src/ui/stroke/button.rs @@ -43,8 +43,8 @@ struct Opened(Option>); /// [`StrokeEditor`] in a popover under it. /// /// - The field shows a line sample, the style's name (Solid, Dashed, Dotted, Custom; "No Color" while -/// [`stroked`](Self::stroked) is false) and a chevron. Its accessible name is the title, "Stroke Options", with the -/// style's name as its value. +/// [`stroked`](Self::stroked) is false) and a chevron. Its accessible name and tooltip are the title, "Stroke +/// Options", with the style's name as its value. /// - A click, Enter or Space opens the popover below the field and focus moves into it; Escape closes it and returns /// focus to the field; a press outside closes it and reaches nothing under it. It closes when the /// [`target`](Self::target) changes and when the field is disabled. @@ -122,6 +122,7 @@ impl<'a> StrokeButton<'a> { impl Component for StrokeButton<'_> { const ROLE: Role = Role::BUTTON; + const SHOWS_LABEL: bool = false; type Style = StrokeButtonStyle; type Output = EditResponse; diff --git a/crates/font-manager/src/picker/rows.rs b/crates/font-manager/src/picker/rows.rs index 6b99e0e95..13e90e94b 100644 --- a/crates/font-manager/src/picker/rows.rs +++ b/crates/font-manager/src/picker/rows.rs @@ -221,7 +221,7 @@ pub(super) fn popup<'a>(picker: &mut FontPicker<'a>, ui: &mut OverlayUi<'_>, cx: let star = TrailingFace::Icon(IconSpec::svg(IconId::new(icon))); let line = ListRow::new(row.shown.clone()).option().check(current == Some(*key)).trailing_part(STAR, star, name); let line = match row.class { - Some(class) => line.trailing(class_mark(class, &words)), + Some(class) => line.trailing_named(class_mark(class, &words), class_label(class, &words)), None => line, }; match size { diff --git a/crates/pages/src/ui/preview.rs b/crates/pages/src/ui/preview.rs index f81820697..794b05b79 100644 --- a/crates/pages/src/ui/preview.rs +++ b/crates/pages/src/ui/preview.rs @@ -7,20 +7,19 @@ mod stories; use super::view::PageSource; use craft_behavior::IconId; -use craft_behavior::{Input, Metrics, NavMove, Sense}; +use craft_behavior::{Input, Metrics, NavMove, PartKey, Sense}; use craft_ui::buttons::IconButton; use craft_ui::contract::{ - Common, Component, Cx, Focus as _, MeasureCx, NoValue, Outcome, PaintUi, Props as _, Role, Show as _, ShowContainer as _, clicked, + Common, Component, Cx, Focus as _, MeasureCx, NoValue, Outcome, PaintUi, PartsCx, Props as _, Role, Show as _, ShowContainer as _, clicked, }; use craft_ui::dialog::Dialog; use craft_ui::layout_components::Row; use craft_ui::primitives::textures::{ - MAX_TEXTURE, Priority, TextureState, TextureStoreOptions, ThumbPaint, ThumbRequest, ThumbnailOptions, Thumbnails, + MAX_TEXTURE, Priority, TextureState, TextureStoreOptions, TextureWords, ThumbPaint, ThumbRequest, ThumbnailOptions, Thumbnails, }; use craft_ui::primitives::{PaintShape, TextRun}; use craft_ui::runtime::env::Env; use craft_ui::runtime::focus::{ActivateKeys, KeepKeys, KeyUse}; -use craft_ui::runtime::memory::Remember as _; use craft_ui::style::{ComponentStyle, DataColor, StyleColor, StyleCx, TypeRole}; use egui::{CornerRadius, Rect, Response, Ui, Vec2}; use std::cell::Cell; @@ -152,11 +151,21 @@ struct PagePicture<'a> { unavailable: &'a str, paper: DataColor, step: isize, + /// The page's picture as step 7 asked for it, which `paint` shows. + state: Option, } +/// The page's picture; a page that failed to render gives the reason as its tooltip. +const PICTURE: PartKey = PartKey::new("picture"); + impl<'a> PagePicture<'a> { fn new(source: &'a dyn PageSource, page: usize, unavailable: &'a str, paper: DataColor) -> Self { - PagePicture { common: Common::new(), source, page, unavailable, paper, step: 0 } + PagePicture { common: Common::new(), source, page, unavailable, paper, step: 0, state: None } + } + + /// The page pictures of the component `id`. + fn thumbnails(ctx: &egui::Context, id: egui::Id) -> Thumbnails { + Thumbnails::::in_context(ctx, id.with("pictures"), ThumbnailOptions::new().max_side(MAX_TEXTURE).store(TextureStoreOptions::pages())) } /// The part of the room the page fills, whole page and no larger than the ideal. @@ -204,19 +213,26 @@ impl Component for PagePicture<'_> { } } + fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) { + let ctx = cx.ui.ctx().clone(); + let thumbs = Self::thumbnails(&ctx, cx.id); + let shape = self.fitted(rect.size()); + let request = ThumbRequest::for_cell(shape.max_elem(), ctx.pixels_per_point()); + let state = thumbs.state(&ctx, self.source, &self.page, &request, Priority::VISIBLE); + if let TextureState::Failed { failure, .. } = &state { + let reason = failure.text(&cx.env.words::()).to_owned(); + cx.part(PICTURE, Rect::from_center_size(rect.center(), shape)).tooltip(reason); + } + self.state = Some(state); + } + fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) { + let Some(state) = self.state.take() else { return }; let painter = ui.content_painter(cx); let ctx = painter.painter.ctx().clone(); - let thumbs = Thumbnails::::in_context( - &ctx, - cx.key("pictures"), - ThumbnailOptions::new().max_side(MAX_TEXTURE).store(TextureStoreOptions::pages()), - ); + let thumbs = Self::thumbnails(&ctx, cx.id); let area = cx.rect; - let shape = self.fitted(area.size()); - let rect = Rect::from_center_size(area.center(), shape); - let request = ThumbRequest::for_cell(shape.max_elem(), painter.pixels_per_point()); - let state = thumbs.state(&ctx, self.source, &self.page, &request, Priority::VISIBLE); + let rect = Rect::from_center_size(area.center(), self.fitted(area.size())); // The paper shows under a page that has no picture yet; under a picture the thumbnail paints it. ui.draw().data_fill(&PaintShape::Rect(rect, CornerRadius::ZERO), self.paper); thumbs.paint(&painter, rect, &state, &ThumbPaint::default().paper(self.paper)); diff --git a/crates/pages/src/ui/table/properties.rs b/crates/pages/src/ui/table/properties.rs index c354da627..5d9e17e8b 100644 --- a/crates/pages/src/ui/table/properties.rs +++ b/crates/pages/src/ui/table/properties.rs @@ -31,6 +31,7 @@ craft_ui::words! { exactly: "tableProperties.exactly" = "Exactly"; column_width: "tableProperties.columnWidth" = "Column Width"; distribute_rows: "tableProperties.distributeRows" = "Distribute Rows Evenly"; + distribute_rows_tip: "tableProperties.distributeRowsTip" = "Equal fixed heights for the selected rows; cell text may become overset."; cell_text: "tableProperties.cellText" = "Cell Text"; cell_align: "tableProperties.cellAlign" = "Vertical Alignment"; align_top: "tableProperties.alignTop" = "Top"; @@ -237,7 +238,8 @@ impl<'a> TableProperties<'a> { set(choose(ui, &words.row_height_mode, v.row_height_mode, &modes, TableChange::RowHeightMode)); set(length(ui, &words.row_height, v.row_height, unit, TableChange::RowHeight)); set(length(ui, &words.column_width, v.column_width, unit, TableChange::ColumnWidth)); - set(button(ui, &words.distribute_rows, true, TableChange::DistributeRows)); + let distribute = Button::new(words.distribute_rows.clone()).tooltip(words.distribute_rows_tip.clone()).show(ui); + set(clicked(&distribute).then_some(TableChange::DistributeRows)); GroupBox::new(words.cell_text.clone(), None).show(ui, |ui, _| { let aligns = [ Entry::new(CellAlign::Top, words.align_top.clone()), diff --git a/crates/review/src/ui/presence.rs b/crates/review/src/ui/presence.rs index e94fbbd59..f229a24ad 100644 --- a/crates/review/src/ui/presence.rs +++ b/crates/review/src/ui/presence.rs @@ -102,7 +102,7 @@ impl<'a> PeopleBar<'a> { if let Some(me) = me { let action = if me.spotlight { words.stop_spotlight.clone() } else { words.spotlight.clone() }; let avatar = - Avatar::new(me.name.clone()).fill(me.color).pressable(true).selected(me.spotlight).description(action.as_str().to_owned()); + Avatar::new(me.name.clone()).fill(me.color).pressable(true).selected(me.spotlight).tooltip(action.as_str().to_owned()); if avatar.show(ui).clicked { requests.push(CollabRequest::Spotlight(!me.spotlight)); } @@ -116,7 +116,7 @@ impl<'a> PeopleBar<'a> { } else { action }; - let avatar = Avatar::new(person.name.clone()).fill(person.color).pressable(true).selected(followed).description(name).show(ui); + let avatar = Avatar::new(person.name.clone()).fill(person.color).pressable(true).selected(followed).tooltip(name).show(ui); if avatar.clicked { requests.push(CollabRequest::Follow(if followed { None } else { Some(person.id) })); } diff --git a/crates/text/src/ui/character.rs b/crates/text/src/ui/character.rs index edbae00c6..4fa52000c 100644 --- a/crates/text/src/ui/character.rs +++ b/crates/text/src/ui/character.rs @@ -55,6 +55,9 @@ craft_ui::words! { metrics: "character.metrics" = "Metrics"; optical: "character.optical" = "Optical"; tracking: "character.tracking" = "Tracking"; + leading_hint: "character.leadingHint" = "Leading (set to the font size × auto-leading when Auto)"; + kerning_hint: "character.kerningHint" = "Kerning: Metrics, Optical or a value in 1/1000 em (Alt+←/→ at the caret)"; + tracking_hint: "character.trackingHint" = "Tracking (1/1000 em)"; vertical_scale: "character.verticalScale" = "Vertical scale"; horizontal_scale: "character.horizontalScale" = "Horizontal scale"; baseline_shift: "character.baselineShift" = "Baseline shift"; @@ -477,6 +480,7 @@ impl<'a> CharacterControls<'a> { let size = LengthRow { label: words.size.clone(), glyph: GlyphLabel::text("tT"), + hint: None, value: values.size, range: SIZE_RANGE, presets: &size_presets, @@ -486,6 +490,7 @@ impl<'a> CharacterControls<'a> { let leading = LengthRow { label: words.leading.clone(), glyph: GlyphLabel::text("A↕"), + hint: Some(words.leading_hint.clone()), value: leading_value, range: LEADING_RANGE, presets: &leading_presets, @@ -497,11 +502,19 @@ impl<'a> CharacterControls<'a> { } }); Grid::new(&TWO_COLUMNS).fill_width().show(ui, |ui, _| { - let event = lengths.kerning(ui, words.kerning.clone(), GlyphLabel::icon(IconId::new("text_cursor")), kerning_shown, &kerning_presets); + let event = lengths.kerning( + ui, + words.kerning.clone(), + GlyphLabel::icon(IconId::new("text_cursor")), + words.kerning_hint.clone(), + kerning_shown, + &kerning_presets, + ); edits.extend(event.map(|value| CharacterChange::Kerning(kerning_of(value)))); let tracking = PlainRow { label: words.tracking.clone(), glyph: GlyphLabel::text("VA"), + hint: Some(words.tracking_hint.clone()), value: plain(values.tracking), range: TRACKING_RANGE, percent: false, @@ -514,6 +527,7 @@ impl<'a> CharacterControls<'a> { let vertical = PlainRow { label: words.vertical_scale.clone(), glyph: GlyphLabel::text("↕T"), + hint: None, value: plain(values.vertical_scale), range: SCALE_RANGE, percent: true, @@ -524,6 +538,7 @@ impl<'a> CharacterControls<'a> { let horizontal = PlainRow { label: words.horizontal_scale.clone(), glyph: GlyphLabel::text("↔T"), + hint: None, value: plain(values.horizontal_scale), range: SCALE_RANGE, percent: true, @@ -536,6 +551,7 @@ impl<'a> CharacterControls<'a> { let shift = LengthRow { label: words.baseline_shift.clone(), glyph: GlyphLabel::text("Aª"), + hint: None, value: values.baseline_shift, range: SHIFT_RANGE, presets: &[], diff --git a/crates/text/src/ui/character/paragraph.rs b/crates/text/src/ui/character/paragraph.rs index 54798a428..3ed477b12 100644 --- a/crates/text/src/ui/character/paragraph.rs +++ b/crates/text/src/ui/character/paragraph.rs @@ -217,6 +217,7 @@ impl<'a> ParagraphControls<'a> { let start = LengthRow { label: words.start_indent.clone(), glyph: GlyphLabel::text("→|"), + hint: None, value: values.start_indent, range: INDENT_RANGE, presets: &[], @@ -226,6 +227,7 @@ impl<'a> ParagraphControls<'a> { let end = LengthRow { label: words.end_indent.clone(), glyph: GlyphLabel::text("|←"), + hint: None, value: values.end_indent, range: INDENT_RANGE, presets: &[], @@ -235,6 +237,7 @@ impl<'a> ParagraphControls<'a> { let first = LengthRow { label: words.first_line_indent.clone(), glyph: GlyphLabel::text("¶→"), + hint: None, value: values.first_line_indent, range: INDENT_RANGE, presets: &[], @@ -246,6 +249,7 @@ impl<'a> ParagraphControls<'a> { let before = LengthRow { label: words.space_before.clone(), glyph: GlyphLabel::text("↑¶"), + hint: None, value: values.space_before, range: SPACE_RANGE, presets: &[], @@ -255,6 +259,7 @@ impl<'a> ParagraphControls<'a> { let after = LengthRow { label: words.space_after.clone(), glyph: GlyphLabel::text("¶↓"), + hint: None, value: values.space_after, range: SPACE_RANGE, presets: &[], diff --git a/crates/text/src/ui/character/rows.rs b/crates/text/src/ui/character/rows.rs index c3ef2b167..a38869927 100644 --- a/crates/text/src/ui/character/rows.rs +++ b/crates/text/src/ui/character/rows.rs @@ -22,10 +22,11 @@ pub(super) struct Lengths<'u> { pub(super) unit: DocUnit, } -/// A length field of a row: its label, mark, value in points and range in points. +/// A length field of a row: its label, mark, the mark's hint, value in points and range in points. pub(super) struct LengthRow<'p> { pub(super) label: Label, pub(super) glyph: GlyphLabel, + pub(super) hint: Option