Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat(desktop): add tip system (#4847)
Elijah Potter165ffc980828
diff --git a/harper-desktop/src-tauri/Cargo.lock b/harper-desktop/src-tauri/Cargo.lockindex 698709b24..6486d6c40 100644--- a/harper-desktop/src-tauri/Cargo.lock+++ b/harper-desktop/src-tauri/Cargo.lock@@ -3823,6 +3823,7 @@ dependencies = ["egui-wgpu","egui-winit","egui_commonmark",+ "fastrand","harper-core","harper-dictionary-wordlist","is-macro",diff --git a/harper-desktop/src-tauri/Cargo.toml b/harper-desktop/src-tauri/Cargo.tomlindex 801aa2e1b..2c0d21aa8 100644--- a/harper-desktop/src-tauri/Cargo.toml+++ b/harper-desktop/src-tauri/Cargo.toml@@ -28,6 +28,7 @@ dirs = "6.0.0"harper-core = { path = "../../harper-core" }harper-dictionary-wordlist = { path = "../../harper-dictionary-wordlist" }egui_commonmark = "0.23.0"+fastrand = "2.5.0"tokio = { version = "1.52.1", default-features = false, features = ["io-std","io-util",diff --git a/harper-desktop/src-tauri/src/highlighter/fonts.rs b/harper-desktop/src-tauri/src/highlighter/fonts.rsnew file mode 100644index 000000000..131fa9eaf--- /dev/null+++ b/harper-desktop/src-tauri/src/highlighter/fonts.rs@@ -0,0 +1,81 @@+//! Native overlay fonts shared by highlighter windows.++use egui::{Context, FontData, FontDefinitions, FontFamily, FontId};++const ATKINSON_REGULAR: &[u8] =+ include_bytes!("../../../static/fonts/atkinson/AtkinsonHyperlegible-Regular.ttf");+const ATKINSON_BOLD: &[u8] =+ include_bytes!("../../../static/fonts/atkinson/AtkinsonHyperlegible-Bold.ttf");+const REGULAR_FONT: &str = "Harper-Regular";+const BOLD_FAMILY: &str = "Harper Bold";+const BOLD_FONT: &str = "Harper-Bold";++/// Loads macOS's installed San Francisco font without redistributing Apple's font files.+/// Uses its text optical size for the small popup UI. Other platforms, or Macs where the system+/// font cannot be read, use the bundled Atkinson Hyperlegible regular and bold faces instead.+fn platform_fonts() -> (FontData, FontData) {+ #[cfg(target_os = "macos")]+ {+ const SYSTEM_FONT: &str = "/System/Library/Fonts/SFNS.ttf";+ match std::fs::read(SYSTEM_FONT) {+ Ok(bytes) => {+ let mut font = FontData::from_owned(bytes);+ font.tweak.coords.push(b"opsz", 17.0);+ font.tweak.coords.push(b"wght", 400.0);+ let mut bold = font.clone();+ bold.tweak.coords.push(b"wght", 700.0);+ return (font, bold);+ }+ Err(error) => {+ eprintln!("Could not load {SYSTEM_FONT}; using Atkinson Hyperlegible: {error}")+ }+ }+ }++ (+ FontData::from_static(ATKINSON_REGULAR),+ FontData::from_static(ATKINSON_BOLD),+ )+}++/// Creates an independent overlay context using San Francisco on macOS and Atkinson elsewhere.+///+/// Both default families use the platform face, including text styled as monospace in markdown.+/// The named bold family uses San Francisco's weight 700 or Atkinson's separate bold face.+/// Hack and egui's emoji fonts remain symbol fallbacks. Keep a separate context per window so each GPU gets its own atlas.+pub fn context() -> Context {+ let mut fonts = FontDefinitions::default();+ fonts.font_data.remove("Ubuntu-Light");+ let (regular, bold) = platform_fonts();+ fonts+ .font_data+ .insert(REGULAR_FONT.to_owned(), regular.into());+ fonts.font_data.insert(BOLD_FONT.to_owned(), bold.into());++ let family = |primary: &str| {+ vec![+ primary.to_owned(),+ "Hack".to_owned(),+ "NotoEmoji-Regular".to_owned(),+ "emoji-icon-font".to_owned(),+ ]+ };+ fonts+ .families+ .insert(FontFamily::Proportional, family(REGULAR_FONT));+ fonts+ .families+ .insert(FontFamily::Monospace, family(REGULAR_FONT));+ fonts+ .families+ .insert(FontFamily::Name(BOLD_FAMILY.into()), family(BOLD_FONT));++ let context = Context::default();+ context.set_fonts(fonts);+ context+}++/// Selects the platform face at weight 700, rather than egui's color-only `RichText::strong` styling.+pub fn bold(size: f32) -> FontId {+ FontId::new(size, FontFamily::Name(BOLD_FAMILY.into()))+}diff --git a/harper-desktop/src-tauri/src/highlighter/mod.rs b/harper-desktop/src-tauri/src/highlighter/mod.rsindex eb37f8361..149a0f78f 100644--- a/harper-desktop/src-tauri/src/highlighter/mod.rs+++ b/harper-desktop/src-tauri/src/highlighter/mod.rs@@ -1,4 +1,5 @@mod error;+mod fonts;mod render_state;mod window;mod window_manager;diff --git a/harper-desktop/src-tauri/src/highlighter/render_state/mod.rs b/harper-desktop/src-tauri/src/highlighter/render_state/mod.rsindex 8a0953ff9..2bbeaec42 100644--- a/harper-desktop/src-tauri/src/highlighter/render_state/mod.rs+++ b/harper-desktop/src-tauri/src/highlighter/render_state/mod.rs@@ -1,6 +1,7 @@mod draw_highlight;mod popup_layout;mod render_lint_card;+mod tips;use std::time::Instant;@@ -11,8 +12,8 @@ use self::{draw_highlight::draw_highlight,popup_layout::{PopupLayout, approach},render_lint_card::{- FIRST_ROW_OFFSET, LintCardAction, popup_layout_for_lint, render_lint_card, row_count,- sidebar_target,+ FIRST_ROW_OFFSET, LintCardAction, TipLayout, popup_layout_for_lint, render_lint_card,+ row_count, sidebar_target,},};use super::{AddToDictionary, DisableRule, IgnoreLint, OpenSettings};@@ -44,6 +45,14 @@ pub struct RenderState {/// Index of the suggestion row that the user hovered last in the visible popup.shown_suggestion: Option<usize>,+ /// The tip chosen when this popup opened. `None` is a retained decision not to show a tip,+ /// not a request to reroll on the next frame; `highlighted_lint` identifies the session.+ current_tip: Option<&'static str>,++ /// Text measured with the active egui fonts before drawing. Hit-testing reuses its height+ /// between frames. A newly selected tip has no extra hit area until its first render.+ tip_layout: Option<TipLayout>,+/// The flyout card's drawn offset from the list card's top, in points.current_sidebar_position: f32,@@ -80,6 +89,8 @@ impl RenderState {last_lints: None,highlighted_lint: None,shown_suggestion: None,+ current_tip: None,+ tip_layout: None,current_sidebar_position: FIRST_ROW_OFFSET,last_render: None,markdown_cache: CommonMarkCache::default(),@@ -94,17 +105,25 @@ impl RenderState {/// Saves successful accessibility reads while retaining the previous lints after a failed read.///- /// Closes the popup when its lint disappeared, and forgets the shown suggestion when the- /// refreshed lint has fewer rows.+ /// Preserves the tip through geometry-only refreshes, but closes the popup if its index no+ /// longer refers to the same rule, span, and source text. Forget the shown suggestion when the+ /// refreshed lint has fewer rows. Conservatively closing on source changes prevents a popup+ /// (and its tip) from silently moving to another occurrence after an edit or lint reordering.pub fn set_lints(&mut self, lints: Vec<ActionableLint>) {- self.last_lints = Some(lints);-- if self- .highlighted_lint- .is_some_and(|index| index >= self.lints().len())- {+ let same_lint = self.highlighted_lint.is_some_and(|index| {+ self.lints()+ .get(index)+ .zip(lints.get(index))+ .is_some_and(|(old, new)| {+ old.rule_name == new.rule_name+ && old.lint.span == new.lint.span+ && old.source_text == new.source_text+ })+ });+ if !same_lint {self.close_popup();}+ self.last_lints = Some(lints);let row_count = self.highlighted_lint@@ -125,17 +144,40 @@ impl RenderState {/// selection. Filtering invalid indexes here keeps stale cursor state from selecting a lint that/// disappeared after the latest accessibility read.///- /// Like the Chrome extension, each new selection starts again from the first suggestion row.+ /// Like the Chrome extension, each new selection starts again from the first suggestion row+ /// and makes one tip decision. Clicking the already-open lint does not reroll its tip.pub fn set_highlighted_lint(&mut self, highlighted_lint: Option<usize>) {- self.highlighted_lint = highlighted_lint.filter(|index| *index < self.lints().len());+ self.open_popup(highlighted_lint, || {+ tips::choose_tip(&mut fastrand::Rng::new())+ });+ }++ /// Applies a popup transition, invoking the supplied selector only for a new valid session.+ fn open_popup(+ &mut self,+ highlighted_lint: Option<usize>,+ choose_tip: impl FnOnce() -> Option<&'static str>,+ ) {+ let highlighted_lint = highlighted_lint.filter(|index| *index < self.lints().len());+ if highlighted_lint.is_none() {+ self.close_popup();+ return;+ }+ if self.highlighted_lint != highlighted_lint {+ self.current_tip = choose_tip();+ self.tip_layout = None;+ }+ self.highlighted_lint = highlighted_lint;self.shown_suggestion = None;self.current_sidebar_position = FIRST_ROW_OFFSET;}- /// Centralizes the close behavior so the popup close button only has to clear the selected lint.+ /// Clears all popup-session state, including a selected tip, for every close path.pub fn close_popup(&mut self) {self.highlighted_lint = None;self.shown_suggestion = None;+ self.current_tip = None;+ self.tip_layout = None;self.current_sidebar_position = FIRST_ROW_OFFSET;}@@ -156,8 +198,9 @@ impl RenderState {.map_or(HitTarget::None, HitTarget::Lint)}- /// Computes popup hit-test bounds from our layout contract instead of waiting for egui to report- /// rendered bounds, which keeps hit-testing available before the next render pass completes.+ /// Computes hit-test bounds from fixed row geometry and the tip's most recent text measurement.+ /// `render` updates that measurement before computing and drawing the same bounds; until a new+ /// tip's first render, only the suggestion rows and footer have a hit area.pub fn popup_layout(&self) -> Option<PopupLayout> {self.highlighted_lint.and_then(|index| self.lints().get(index))@@ -166,6 +209,7 @@ impl RenderState {&positioned_lint.rect,&positioned_lint.lint,self.current_sidebar_position,+ self.tip_layout.as_ref().map_or(0.0, TipLayout::height),)})}@@ -180,6 +224,10 @@ impl RenderState {/// Each call also moves the sidebar toward its target by the time since the previous call.pub fn render(&mut self, ui: &mut egui::Ui, screen_rects: &[egui::Rect], window: usize) {let window_rect = screen_rects[window];+ // egui caches text layout internally. Measuring each frame also handles font/DPI changes.+ self.tip_layout = self+ .current_tip+ .map(|tip| TipLayout::new(ui.painter(), tip));let now = Instant::now();let time_since_last_render = self.last_render@@ -211,16 +259,22 @@ impl RenderState {&& popup_window(screen_rects, &positioned_lint.rect) == Some(window){let rect = to_window_space(&positioned_lint.rect, window_rect);+ let layout = popup_layout_for_lint(+ &rect,+ &positioned_lint.lint,+ self.current_sidebar_position,+ self.tip_layout.as_ref().map_or(0.0, TipLayout::height),+ );let lint = positioned_lint.lint.clone();let source_text = positioned_lint.source_text.clone();match render_lint_card(ui,- &rect,+ layout,&lint,&source_text,self.shown_suggestion,- self.current_sidebar_position,+ self.tip_layout.as_ref(),&mut self.markdown_cache,) {Some(LintCardAction::Close) => self.close_popup(),@@ -354,6 +408,31 @@ mod tests {assert_eq!(to_window_space(&rect, BUILT_IN), rect);}+ #[test]+ fn popup_with_tip_uses_window_coordinates_and_preserves_hit_test_size() {+ let rect = Rect::new(-2900.0, -300.0, 30.0, 12.0);+ let lint = harper_core::linting::Lint::default();++ for tip_height in [0.0, 80.0] {+ let screen_layout = popup_layout_for_lint(&rect, &lint, FIRST_ROW_OFFSET, tip_height);+ let window_layout = popup_layout_for_lint(+ &to_window_space(&rect, EXTERNAL),+ &lint,+ FIRST_ROW_OFFSET,+ tip_height,+ );++ assert_eq!(+ window_layout.list,+ screen_layout.list.translate(-EXTERNAL.min.to_vec2())+ );+ assert_eq!(+ window_layout.flyout,+ screen_layout.flyout.translate(-EXTERNAL.min.to_vec2())+ );+ }+ }+#[test]fn popup_window_contains_lint() {let on_built_in = Rect::new(100.0, 100.0, 30.0, 12.0);diff --git a/harper-desktop/src-tauri/src/highlighter/render_state/render_lint_card.rs b/harper-desktop/src-tauri/src/highlighter/render_state/render_lint_card.rsindex abcad467f..dc64d4b0c 100644--- a/harper-desktop/src-tauri/src/highlighter/render_state/render_lint_card.rs+++ b/harper-desktop/src-tauri/src/highlighter/render_state/render_lint_card.rs@@ -1,10 +1,11 @@//! Renders the lint card and defines its shared drawing and hit-test geometry.-use std::hash::Hash;+use std::{hash::Hash, sync::Arc};use egui_commonmark::{CommonMarkCache, CommonMarkViewer};use harper_core::linting::{Lint, LintKind, Suggestion};+use super::super::fonts;use super::lint_kind_color32;use super::popup_layout::{PopupLayout, UNBOUNDED_VIEWPORT, popup_layout};use crate::rect::Rect;@@ -31,6 +32,12 @@ pub const FIRST_ROW_OFFSET: f32 = BORDER_WIDTH + LIST_PADDING_Y;const KIND_HEADER_HEIGHT: f32 = 34.0;const DISABLE_ROW_HEIGHT: f32 = 33.0;const BUTTON_MIN_HEIGHT: f32 = 24.0;+const TIP_PADDING: f32 = 10.0;+const TIP_TITLE_GAP: f32 = 6.0;+const TIP_ICON_SIZE: f32 = 14.0;+const TIP_ICON_GAP: f32 = 6.0;+const TIP_FONT_SIZE: f32 = 13.0;+const TIP_BACKGROUND: egui::Color32 = egui::Color32::from_rgb(0xf6, 0xf8, 0xfa);const POPUP_BACKGROUND: egui::Color32 = egui::Color32::from_rgb(0xff, 0xff, 0xff);const POPUP_BORDER: egui::Color32 = egui::Color32::from_rgb(0xd0, 0xd7, 0xde);@@ -44,6 +51,63 @@ const DISMISS_BACKGROUND: egui::Color32 = egui::Color32::from_rgb(0xe5, 0xe5, 0xconst BUTTON_BACKGROUND: egui::Color32 = egui::Color32::from_rgb(0xef, 0xef, 0xef);const BUTTON_TEXT_COLOR: egui::Color32 = egui::Color32::from_rgb(0x00, 0x00, 0x00);+/// Measured heading and wrapped body shared by tip painting and popup hit-testing.+///+/// Measure with the active egui painter before computing the card bounds. Retaining these galleys+/// avoids wrapping the text differently when drawing and lets shorter tips shrink naturally.+/// The heading reserves space for a decorative bulb; the body retains the full content width.+pub struct TipLayout {+ title: Arc<egui::Galley>,+ body: Arc<egui::Galley>,+}++impl TipLayout {+ pub fn new(painter: &egui::Painter, tip: &str) -> Self {+ let font = egui::FontId::proportional(TIP_FONT_SIZE);+ let width = LIST_WIDTH - 2.0 * TIP_PADDING;+ Self {+ title: painter.layout(+ "Tip".to_owned(),+ fonts::bold(TIP_FONT_SIZE),+ TEXT_COLOR,+ width - TIP_ICON_SIZE - TIP_ICON_GAP,+ ),+ body: painter.layout(tip.to_owned(), font, MUTED_TEXT_COLOR, width),+ }+ }++ /// Fits both the measured label and the icon without changing the body text's width.+ fn heading_height(&self) -> f32 {+ self.title.size().y.max(TIP_ICON_SIZE)+ }++ /// Places the decorative icon and label on a shared vertical center, separated by a fixed gap.+ fn heading_rects(&self, origin: egui::Pos2) -> (egui::Rect, egui::Rect) {+ let center_y = origin.y + self.heading_height() / 2.0;+ let icon = egui::Rect::from_min_size(+ egui::pos2(origin.x, center_y - TIP_ICON_SIZE / 2.0),+ egui::Vec2::splat(TIP_ICON_SIZE),+ );+ let title = egui::Rect::from_min_size(+ egui::pos2(+ icon.right() + TIP_ICON_GAP,+ center_y - self.title.size().y / 2.0,+ ),+ self.title.size(),+ );+ (icon, title)+ }++ fn body_offset(&self) -> f32 {+ DIVIDER_WIDTH + TIP_PADDING + self.heading_height() + TIP_TITLE_GAP+ }++ /// Includes the divider, measured text, heading gap, and top/bottom padding, in egui points.+ pub fn height(&self) -> f32 {+ self.body_offset() + self.body.size().y + TIP_PADDING+ }+}+/// An action selected in the lint card, returned for `RenderState` to apply.////// The renderer reports intent without updating application state or invoking callbacks.@@ -76,21 +140,20 @@ enum ButtonContent<'a> {/// Renders the suggestion popup and returns the action the user picked, if any.////// The layout copies the Chrome extension's suggestion popup: the suggestion list and the lint-/// explanation are two separate floating cards. [`popup_layout_for_lint`] places them, so-/// hit-testing and drawing agree without measuring the popup.+/// explanation are two separate floating cards. The caller supplies the same layout computed by+/// [`popup_layout_for_lint`] for hit-testing, including any tip drawer space.///-/// `sidebar_position` is the flyout card's current offset from the list card's top. The caller-/// animates it toward [`sidebar_target`]. `shown_suggestion` only selects the highlighted row.+/// `shown_suggestion` only selects the highlighted row. `tip` is the session's retained decision;+/// rendering never selects or rotates tips.pub fn render_lint_card(ui: &mut egui::Ui,- rect: &Rect,+ layout: PopupLayout,lint: &Lint,source_text: &str,shown_suggestion: Option<usize>,- sidebar_position: f32,+ tip: Option<&TipLayout>,markdown_cache: &mut CommonMarkCache,) -> Option<LintCardAction> {- let layout = popup_layout_for_lint(rect, lint, sidebar_position);let problem_text = problem_text(lint, source_text);let span = (lint.span.start, lint.span.end);@@ -101,6 +164,7 @@ pub fn render_lint_card(lint,&problem_text,shown_suggestion.unwrap_or(0),+ tip,&mut action,);action@@ -171,7 +235,7 @@ fn card_frame() -> egui::Frame {})}-/// Renders the list card: one row for each suggestion, then the footer.+/// Renders the list card: one row for each suggestion, then the footer and optional tip.////// Clicking a row applies its suggestion. Hovering a row reports its index, so the flyout card can/// align with it. When the lint has no suggestions, one "No replacements" row takes their place,@@ -184,6 +248,7 @@ fn render_suggestion_list(lint: &Lint,problem_text: &str,selected: usize,+ tip: Option<&TipLayout>,action: &mut Option<LintCardAction>,) {ui.add_space(LIST_PADDING_Y);@@ -218,9 +283,54 @@ fn render_suggestion_list(}render_list_footer(ui, action);+ if let Some(tip) = tip {+ render_tip_drawer(ui, tip);+ }ui.add_space(LIST_PADDING_Y);}+/// Draws a passive note using the same measured text and height as the popup's hit-test bounds.+/// Tall content remains inside the list's existing scroll area without taking keyboard focus.+fn render_tip_drawer(ui: &mut egui::Ui, tip: &TipLayout) {+ let (rect, _) =+ ui.allocate_exact_size(egui::vec2(LIST_WIDTH, tip.height()), egui::Sense::hover());+ let painter = ui.painter();+ painter.rect_filled(rect, 0.0, TIP_BACKGROUND);+ painter.hline(+ rect.x_range(),+ rect.top() + DIVIDER_WIDTH / 2.0,+ egui::Stroke::new(DIVIDER_WIDTH, DIVIDER_COLOR),+ );+ let (icon_rect, title_rect) =+ tip.heading_rects(rect.min + egui::vec2(TIP_PADDING, DIVIDER_WIDTH + TIP_PADDING));+ draw_lightbulb_icon(painter, icon_rect, TEXT_COLOR);+ painter.galley(title_rect.min, tip.title.clone(), TEXT_COLOR);+ painter.galley(+ rect.min + egui::vec2(TIP_PADDING, tip.body_offset()),+ tip.body.clone(),+ MUTED_TEXT_COLOR,+ );+}++/// Draws a decorative lightbulb outline in a 24-unit coordinate system scaled into `rect`.+/// Painter primitives avoid font/emoji dependencies; the icon has no independent hit target.+fn draw_lightbulb_icon(painter: &egui::Painter, rect: egui::Rect, color: egui::Color32) {+ let scale = rect.width().min(rect.height()) / 24.0;+ let origin = rect.center() - egui::Vec2::splat(12.0 * scale);+ let point = |x: f32, y: f32| origin + egui::vec2(x, y) * scale;+ let stroke = egui::Stroke::new(1.75 * scale, color);++ let mut bulb = vec![point(9.0, 18.0), point(9.0, 16.0)];+ // The open bottom of the circular bulb tapers into its neck.+ bulb.extend((0..=32).map(|step| {+ let angle = (126.0 + 288.0 * step as f32 / 32.0).to_radians();+ point(12.0 + 6.0 * angle.cos(), 8.0 + 6.0 * angle.sin())+ }));+ bulb.extend([point(15.0, 16.0), point(15.0, 18.0)]);+ painter.add(egui::Shape::closed_line(bulb, stroke));+ painter.line_segment([point(10.0, 21.0), point(14.0, 21.0)], stroke);+}+/// Renders one suggestion row: a swatch in the lint color, the label, and a chevron.////// The row's rectangle is allocated before anything is painted, so the hover background can come@@ -745,17 +855,26 @@ fn problem_text(lint: &Lint, source_text: &str) -> String {/// Defines popup geometry ahead of rendering so the transparent overlay can enable or disable native/// hit-testing based on our intended layout, not a previous frame's measured egui output.///-/// The list card's size comes from its fixed row geometry. The flyout card's content is markdown,+/// The list card combines fixed row geometry with the measured tip height. The flyout is markdown,/// so its bounds always have the maximum size. A flyout with less content is drawn smaller, and the/// overlay catches clicks on the transparent space below it instead of the editor.////// `sidebar_position` is the flyout card's current offset from the list card's top, not its target,-/// so hit-testing follows the card while it moves.-pub fn popup_layout_for_lint(rect: &Rect, lint: &Lint, sidebar_position: f32) -> PopupLayout {+/// so hit-testing follows the card while it moves. `tip_height` is zero without a measured tip;+/// otherwise it comes from `TipLayout`. The card remains capped at `CARD_HEIGHT`.+pub fn popup_layout_for_lint(+ rect: &Rect,+ lint: &Lint,+ sidebar_position: f32,+ tip_height: f32,+) -> PopupLayout {popup_layout(rect,UNBOUNDED_VIEWPORT,- egui::vec2(LIST_CARD_WIDTH, list_card_height(row_count(lint))),+ egui::vec2(+ LIST_CARD_WIDTH,+ list_card_height(row_count(lint), tip_height),+ ),egui::vec2(FLYOUT_CARD_WIDTH, CARD_HEIGHT),sidebar_position,)@@ -765,7 +884,7 @@ pub fn popup_layout_for_lint(rect: &Rect, lint: &Lint, sidebar_position: f32) ->////// The sidebar moves toward this value on each frame, but does not jump to it.pub fn sidebar_target(lint: &Lint, shown_suggestion: Option<usize>) -> f32 {- row_offset(shown_suggestion, list_card_height(row_count(lint)))+ row_offset(shown_suggestion, list_card_height(row_count(lint), 0.0))}/// Counts the list card's suggestion rows, including the "No replacements" row.@@ -773,9 +892,11 @@ pub fn row_count(lint: &Lint) -> usize {lint.suggestions.len().max(1)}-/// Computes the list card's height from its fixed row and footer heights.-fn list_card_height(row_count: usize) -> f32 {- let content = 2.0 * LIST_PADDING_Y + row_count as f32 * ROW_HEIGHT + LIST_FOOTER_HEIGHT;+/// Computes shared drawing/hit-test height from the rows, footer, and optional tip drawer.+/// No-tip popups retain their original dimensions; overflowing content scrolls inside the cap.+fn list_card_height(row_count: usize, tip_height: f32) -> f32 {+ let content =+ 2.0 * LIST_PADDING_Y + row_count as f32 * ROW_HEIGHT + LIST_FOOTER_HEIGHT + tip_height;(2.0 * BORDER_WIDTH + content).min(CARD_HEIGHT)}@@ -804,18 +925,18 @@ mod tests {#[test]fn list_card_height_counts_rows_and_footer() {- assert_eq!(list_card_height(1), 2.0 + 8.0 + 30.0 + 37.0);- assert_eq!(list_card_height(3), 2.0 + 8.0 + 90.0 + 37.0);+ assert_eq!(list_card_height(1, 0.0), 2.0 + 8.0 + 30.0 + 37.0);+ assert_eq!(list_card_height(3, 0.0), 2.0 + 8.0 + 90.0 + 37.0);}#[test]fn list_card_height_caps_at_max() {- assert_eq!(list_card_height(100), CARD_HEIGHT);+ assert_eq!(list_card_height(100, 0.0), CARD_HEIGHT);}#[test]fn row_offset_starts_at_first_row() {- let list_height = list_card_height(3);+ let list_height = list_card_height(3, 0.0);assert_eq!(row_offset(None, list_height), FIRST_ROW_OFFSET);assert_eq!(@@ -826,7 +947,7 @@ mod tests {#[test]fn row_offset_steps_by_row_height() {- let list_height = list_card_height(3);+ let list_height = list_card_height(3, 0.0);assert_eq!(row_offset(Some(2), list_height),@@ -836,7 +957,7 @@ mod tests {#[test]fn row_offset_stays_inside_scrolled_list() {- let list_height = list_card_height(100);+ let list_height = list_card_height(100, 0.0);assert_eq!(row_offset(Some(99), list_height),diff --git a/harper-desktop/src-tauri/src/highlighter/render_state/tips.rs b/harper-desktop/src-tauri/src/highlighter/render_state/tips.rsnew file mode 100644index 000000000..847fdeec3--- /dev/null+++ b/harper-desktop/src-tauri/src/highlighter/render_state/tips.rs@@ -0,0 +1,25 @@+//! Occasional, local-only teaching tips for the native suggestion popup.+//!+//! Keep tips specific to supported Desktop features. Adding a tip requires no persistence or IPC;+//! the drawer measures and wraps each tip to fit its text, with scrolling for tall content.++pub const TIPS: &[&str] = &[+ "Add names and technical terms in Settings → Dictionary.",+ "Use Dismiss to ignore a suggestion without disabling its rule.",+ "Disable an unwanted rule from the suggestion popup. Re-enable it in Settings → Rules.",+ "Choose your English dialect in Settings → General.",+ "Want fewer interruptions? Try a 300 ms checking delay in Settings → General.",+ "Choose which apps Harper checks in Settings → Integrations.",+ "Use the settings button in this popup to open Harper’s preferences.",+ "Harper checks your writing locally. Your text stays on your device.",+ "Read a sentence aloud to catch awkward phrasing.",+ "Use consistent terminology so readers can follow your ideas.",+];++/// Chooses a uniformly random tip with a 10% probability, matching the browser extension.+///+/// Call only when a popup opens or changes lints, and retain `None` as well as selected tips until+/// that session ends.+pub fn choose_tip(rng: &mut fastrand::Rng) -> Option<&'static str> {+ (rng.u8(0..10) == 0).then(|| TIPS[rng.usize(0..TIPS.len())])+}diff --git a/harper-desktop/src-tauri/src/highlighter/window.rs b/harper-desktop/src-tauri/src/highlighter/window.rsindex 2640a7f5e..8b35c416e 100644--- a/harper-desktop/src-tauri/src/highlighter/window.rs+++ b/harper-desktop/src-tauri/src/highlighter/window.rs@@ -31,7 +31,7 @@ pub struct Window {impl Window {pub async fn new(event_loop: &ActiveEventLoop, monitor: MonitorHandle) -> Result<Self, Error> {- let context = egui::Context::default();+ let context = super::fonts::context();let position = monitor.position();let size = monitor.size();let window = Arc::new(diff --git a/harper-desktop/src-tauri/tauri.conf.json b/harper-desktop/src-tauri/tauri.conf.jsonindex 5c5d717a9..668edf3d8 100644--- a/harper-desktop/src-tauri/tauri.conf.json+++ b/harper-desktop/src-tauri/tauri.conf.json@@ -18,6 +18,9 @@"bundle": {"active": true,"targets": "all",+ "resources": {+ "../static/fonts/atkinson/OFL.txt": "licenses/AtkinsonHyperlegible-OFL.txt"+ },"icon": ["icons/32x32.png","icons/128x128.png",diff --git a/harper-desktop/src/lib/settings/settings.css b/harper-desktop/src/lib/settings/settings.cssindex 5b16eaf8f..94e796083 100644--- a/harper-desktop/src/lib/settings/settings.css+++ b/harper-desktop/src/lib/settings/settings.css@@ -1,8 +1,16 @@@font-face {- font-family: Domine;- src: url("/fonts/domine/Domine.ttf") format("truetype");+ font-family: "Atkinson Hyperlegible";+ src: url("/fonts/atkinson/AtkinsonHyperlegible-Regular.ttf") format("truetype");font-style: normal;- font-weight: 400 700;+ font-weight: 400;+ font-display: swap;+}++@font-face {+ font-family: "Atkinson Hyperlegible";+ src: url("/fonts/atkinson/AtkinsonHyperlegible-Bold.ttf") format("truetype");+ font-style: normal;+ font-weight: 700;font-display: swap;}@@ -32,7 +40,7 @@ body.settings-view {overflow: hidden;background: var(--settings-bg-window);color: var(--settings-ink);- font-family: Domine, serif;+ font-family: "Atkinson Hyperlegible", sans-serif;font-size: 13px;-webkit-font-smoothing: antialiased;}@@ -85,7 +93,7 @@ button {--marketing-amber-soft: #d98b3a;--marketing-ink: #1c1a16;--marketing-ink-2: #4a463e;- font-family: Domine, serif;+ font-family: "Atkinson Hyperlegible", sans-serif;overflow-wrap: anywhere;}diff --git a/harper-desktop/static/fonts/atkinson/AtkinsonHyperlegible-Bold.ttf b/harper-desktop/static/fonts/atkinson/AtkinsonHyperlegible-Bold.ttfnew file mode 100644index 000000000..ca3f61384Binary files /dev/null and b/harper-desktop/static/fonts/atkinson/AtkinsonHyperlegible-Bold.ttf differdiff --git a/harper-desktop/static/fonts/atkinson/AtkinsonHyperlegible-Regular.ttf b/harper-desktop/static/fonts/atkinson/AtkinsonHyperlegible-Regular.ttfnew file mode 100644index 000000000..b3cc4200fBinary files /dev/null and b/harper-desktop/static/fonts/atkinson/AtkinsonHyperlegible-Regular.ttf differdiff --git a/harper-desktop/static/fonts/atkinson/OFL.txt b/harper-desktop/static/fonts/atkinson/OFL.txtnew file mode 100644index 000000000..2befc89b0--- /dev/null+++ b/harper-desktop/static/fonts/atkinson/OFL.txt@@ -0,0 +1,92 @@+Copyright 2020 Braille Institute of America, Inc.++This Font Software is licensed under the SIL Open Font License, Version 1.1.+This license is copied below, and is also available with a FAQ at:+http://scripts.sil.org/OFL++-----------------------------------------------------------+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007+-----------------------------------------------------------++PREAMBLE+The goals of the Open Font License (OFL) are to stimulate worldwide+development of collaborative font projects, to support the font creation+efforts of academic and linguistic communities, and to provide a free and+open framework in which fonts may be shared and improved in partnership+with others.++The OFL allows the licensed fonts to be used, studied, modified and+redistributed freely as long as they are not sold by themselves. The+fonts, including any derivative works, can be bundled, embedded,+redistributed and/or sold with any software provided that any reserved+names are not used by derivative works. The fonts and derivatives,+however, cannot be released under any other type of license. The+requirement for fonts to remain under this license does not apply+to any document created using the fonts or their derivatives.++DEFINITIONS+"Font Software" refers to the set of files released by the Copyright+Holder(s) under this license and clearly marked as such. This may+include source files, build scripts and documentation.++"Reserved Font Name" refers to any names specified as such after the+copyright statement(s).++"Original Version" refers to the collection of Font Software components as+distributed by the Copyright Holder(s).++"Modified Version" refers to any derivative made by adding to, deleting,+or substituting -- in part or in whole -- any of the components of the+Original Version, by changing formats or by porting the Font Software to a+new environment.++"Author" refers to any designer, engineer, programmer, technical+writer or other person who contributed to the Font Software.++PERMISSION & CONDITIONS+Permission is hereby granted, free of charge, to any person obtaining+a copy of the Font Software, to use, study, copy, merge, embed, modify,+redistribute, and sell modified and unmodified copies of the Font+Software, subject to the following conditions:++1) Neither the Font Software nor any of its individual components,+in Original or Modified Versions, may be sold by itself.++2) Original or Modified Versions of the Font Software may be bundled,+redistributed and/or sold with any software, provided that each copy+contains the above copyright notice and this license. These can be+included either as stand-alone text files, human-readable headers or+in the appropriate machine-readable metadata fields within text or+binary files as long as those fields can be easily viewed by the user.++3) No Modified Version of the Font Software may use the Reserved Font+Name(s) unless explicit written permission is granted by the corresponding+Copyright Holder. This restriction only applies to the primary font name as+presented to the users.++4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font+Software shall not be used to promote, endorse or advertise any+Modified Version, except to acknowledge the contribution(s) of the+Copyright Holder(s) and the Author(s) or with their explicit written+permission.++5) The Font Software, modified or unmodified, in part or in whole,+must be distributed entirely under this license, and must not be+distributed under any other license. The requirement for fonts to+remain under this license does not apply to any document created+using the Font Software.++TERMINATION+This license becomes null and void if any of the above conditions are+not met.++DISCLAIMER+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM+OTHER DEALINGS IN THE FONT SOFTWARE.diff --git a/harper-desktop/static/fonts/atkinson/README.md b/harper-desktop/static/fonts/atkinson/README.mdnew file mode 100644index 000000000..26e15c912--- /dev/null+++ b/harper-desktop/static/fonts/atkinson/README.md@@ -0,0 +1,8 @@+# Atkinson Hyperlegible++The regular and bold fonts are shared by Desktop's settings/onboarding UI and non-macOS native egui overlays.+The macOS overlay uses the installed San Francisco font, falling back to Atkinson Hyperlegible if it cannot be read.++These unmodified files come from [Google Fonts](https://github.com/google/fonts/tree/main/ofl/atkinsonhyperlegible).+Copyright 2020 Braille Institute of America, Inc. Licensed under the SIL Open Font License 1.1; see `OFL.txt`.+Tauri includes the license at `licenses/AtkinsonHyperlegible-OFL.txt` in its resources.diff --git a/harper-desktop/static/fonts/domine/Domine.ttf b/harper-desktop/static/fonts/domine/Domine.ttfdeleted file mode 100644index d676bdedb..000000000Binary files a/harper-desktop/static/fonts/domine/Domine.ttf and /dev/null differ