//! Drawing: the address bar, the page, and the home screen. use crate::{Clearwake, Page, Picture}; use clearwake_core::html::{Block, Form, Inline}; use egui::{Color32, CornerRadius, FontFamily, FontId, Key, RichText, Stroke, TextStyle, Vec2}; const COLUMN: f32 = 740.0; pub struct Palette { pub bg: Color32, pub bar: Color32, pub ink: Color32, pub soft: Color32, pub line: Color32, pub accent: Color32, pub link: Color32, pub field: Color32, } pub fn palette(dark: bool) -> Palette { if dark { Palette { bg: Color32::from_rgb(0x12, 0x16, 0x18), bar: Color32::from_rgb(0x19, 0x1e, 0x21), ink: Color32::from_rgb(0xe8, 0xec, 0xea), soft: Color32::from_rgb(0x9a, 0xa6, 0xa3), line: Color32::from_rgb(0x2a, 0x32, 0x35), accent: Color32::from_rgb(0x6f, 0xc7, 0xb8), link: Color32::from_rgb(0x8c, 0xc8, 0xf0), field: Color32::from_rgb(0x22, 0x29, 0x2c), } } else { Palette { bg: Color32::from_rgb(0xfa, 0xf9, 0xf6), bar: Color32::from_rgb(0xf1, 0xf0, 0xeb), ink: Color32::from_rgb(0x1c, 0x22, 0x21), soft: Color32::from_rgb(0x66, 0x70, 0x6d), line: Color32::from_rgb(0xdd, 0xdb, 0xd3), accent: Color32::from_rgb(0x1f, 0x7a, 0x6c), link: Color32::from_rgb(0x1a, 0x5f, 0xa8), field: Color32::from_rgb(0xff, 0xff, 0xff), } } } fn is_dark(ctx: &egui::Context) -> bool { ctx.global_style().visuals.dark_mode } pub fn install_style(ctx: &egui::Context, dark: Option) { let theme = match dark { Some(true) => egui::ThemePreference::Dark, Some(false) => egui::ThemePreference::Light, None => egui::ThemePreference::System, }; ctx.set_theme(theme); for d in [true, false] { let p = palette(d); let style_theme = if d { egui::Theme::Dark } else { egui::Theme::Light }; ctx.style_mut_of(style_theme, |s| { s.visuals.panel_fill = p.bg; s.visuals.window_fill = p.bar; s.visuals.extreme_bg_color = p.field; s.visuals.hyperlink_color = p.link; s.visuals.selection.bg_fill = p.accent.gamma_multiply(0.35); s.visuals.widgets.noninteractive.fg_stroke = Stroke::new(1.0, p.ink); s.visuals.widgets.inactive.corner_radius = CornerRadius::same(18); s.visuals.widgets.hovered.corner_radius = CornerRadius::same(18); s.visuals.widgets.active.corner_radius = CornerRadius::same(18); s.spacing.button_padding = Vec2::new(12.0, 6.0); s.text_styles.insert(TextStyle::Body, FontId::new(17.0, FontFamily::Proportional)); s.text_styles.insert(TextStyle::Button, FontId::new(15.0, FontFamily::Proportional)); s.text_styles.insert(TextStyle::Monospace, FontId::new(14.5, FontFamily::Monospace)); s.text_styles.insert(TextStyle::Small, FontId::new(12.5, FontFamily::Proportional)); s.text_styles.insert(TextStyle::Heading, FontId::new(30.0, FontFamily::Proportional)); }); } } pub fn shortcuts(app: &mut Clearwake, ctx: &egui::Context) { let (back, fwd, reload, focus, mark, home) = ctx.input_mut(|i| { let cmd = egui::Modifiers::COMMAND; ( i.consume_key(egui::Modifiers::ALT, Key::ArrowLeft) || i.consume_key(cmd, Key::OpenBracket) || i.consume_key(egui::Modifiers::NONE, Key::BrowserBack), i.consume_key(egui::Modifiers::ALT, Key::ArrowRight) || i.consume_key(cmd, Key::CloseBracket), i.consume_key(cmd, Key::R) || i.consume_key(egui::Modifiers::NONE, Key::F5), i.consume_key(cmd, Key::L), i.consume_key(cmd, Key::D), i.consume_key(cmd | egui::Modifiers::SHIFT, Key::H), ) }); if back { app.back(); } if fwd { app.forward(); } if reload { app.reload(); } if focus { app.address_focus = true; } if mark { toggle_bookmark(app); } if home { app.open(String::from("about:home"), true); } } fn toggle_bookmark(app: &mut Clearwake) { if let Some(u) = app.current_url() { let t = app.current_title(); app.bookmarks.toggle(&u, &t); } } #[derive(Clone, Copy)] enum Icon { Back, Forward, Reload, Stop, Home, Star(bool), Menu, } /// A borderless toolbar button with an icon drawn in code (no icon font). fn pill(ui: &mut egui::Ui, icon: Icon, enabled: bool, tip: &str) -> bool { let (rect, resp) = ui.allocate_exact_size(Vec2::new(36.0, 32.0), if enabled { egui::Sense::click() } else { egui::Sense::hover() }); let p = palette(is_dark(ui.ctx())); let color = if !enabled { p.soft.gamma_multiply(0.45) } else if resp.hovered() { p.accent } else { p.ink }; if enabled && resp.hovered() { ui.painter().rect_filled(rect.shrink(1.0), 16.0, p.line.gamma_multiply(0.6)); } draw_icon(ui.painter(), rect.center(), icon, color); let resp = resp.on_hover_text(tip); enabled && resp.clicked() } fn draw_icon(painter: &egui::Painter, c: egui::Pos2, icon: Icon, color: Color32) { use egui::pos2; let st = Stroke::new(1.8, color); match icon { Icon::Back | Icon::Forward => { let d = if matches!(icon, Icon::Back) { -1.0 } else { 1.0 }; painter.line_segment([pos2(c.x - 7.0 * d, c.y), pos2(c.x + 7.0 * d, c.y)], st); painter.line_segment([pos2(c.x + 7.0 * d, c.y), pos2(c.x + 2.0 * d, c.y - 5.0)], st); painter.line_segment([pos2(c.x + 7.0 * d, c.y), pos2(c.x + 2.0 * d, c.y + 5.0)], st); } Icon::Reload => { let r = 7.0; let pts: Vec = (0..=20) .map(|i| { let a = -1.2 + i as f32 / 20.0 * 5.0; pos2(c.x + r * a.cos(), c.y + r * a.sin()) }) .collect(); let end = *pts.last().unwrap(); painter.add(egui::Shape::line(pts, st)); let a: f32 = -1.2 + 5.0; let tip = pos2(end.x + 4.0 * (a + 1.2).cos(), end.y + 4.0 * (a + 1.2).sin()); painter.line_segment([end, pos2(end.x + 4.5, end.y - 1.0)], st); let _ = tip; painter.line_segment([end, pos2(end.x + 0.5, end.y + 4.5)], st); } Icon::Stop => { painter.line_segment([pos2(c.x - 6.0, c.y - 6.0), pos2(c.x + 6.0, c.y + 6.0)], st); painter.line_segment([pos2(c.x + 6.0, c.y - 6.0), pos2(c.x - 6.0, c.y + 6.0)], st); } Icon::Home => { let pts = vec![ pos2(c.x - 7.0, c.y - 0.5), pos2(c.x, c.y - 7.5), pos2(c.x + 7.0, c.y - 0.5), ]; painter.add(egui::Shape::line(pts, st)); let body = vec![pos2(c.x - 5.0, c.y - 2.0), pos2(c.x - 5.0, c.y + 7.0), pos2(c.x + 5.0, c.y + 7.0), pos2(c.x + 5.0, c.y - 2.0)]; painter.add(egui::Shape::line(body, st)); } Icon::Star(filled) => { let pts: Vec = (0..10) .map(|i| { let r = if i % 2 == 0 { 8.0 } else { 3.6 }; let a = -std::f32::consts::FRAC_PI_2 + i as f32 * std::f32::consts::PI / 5.0; pos2(c.x + r * a.cos(), c.y + 0.6 + r * a.sin()) }) .collect(); if filled { painter.add(egui::Shape::convex_polygon(vec![c], color, Stroke::NONE)); for i in 0..10 { painter.add(egui::Shape::convex_polygon(vec![pos2(c.x, c.y + 0.6), pts[i], pts[(i + 1) % 10]], color, Stroke::NONE)); } } else { painter.add(egui::Shape::closed_line(pts, st)); } } Icon::Menu => { for dy in [-5.0, 0.0, 5.0] { painter.line_segment([pos2(c.x - 7.0, c.y + dy), pos2(c.x + 7.0, c.y + dy)], st); } } } } /// A small shield, drawn before the status line. fn shield(ui: &mut egui::Ui, color: Color32) { use egui::pos2; let (rect, _) = ui.allocate_exact_size(Vec2::new(14.0, 14.0), egui::Sense::hover()); let c = rect.center(); let pts = vec![ pos2(c.x, c.y - 6.0), pos2(c.x + 5.0, c.y - 4.0), pos2(c.x + 4.5, c.y + 1.5), pos2(c.x, c.y + 6.0), pos2(c.x - 4.5, c.y + 1.5), pos2(c.x - 5.0, c.y - 4.0), ]; ui.painter().add(egui::Shape::convex_polygon(pts, color, Stroke::NONE)); } pub fn toolbar(app: &mut Clearwake, ui: &mut egui::Ui) { let p = palette(is_dark(ui.ctx())); egui::Panel::top("toolbar") .frame(egui::Frame::new().fill(p.bar).inner_margin(egui::Margin::symmetric(10, 8)).stroke(Stroke::new(1.0, p.line))) .show(ui, |ui| { ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 4.0; if pill(ui, Icon::Back, app.history.can_back(), "Back") { app.back(); } if pill(ui, Icon::Forward, app.history.can_forward(), "Forward") { app.forward(); } let loading = matches!(app.page, Page::Loading { .. }); if loading { if pill(ui, Icon::Stop, true, "Stop") { app.generation += 1; let url = app.current_url().unwrap_or_default(); app.page = Page::Error { url, message: String::from("Stopped.") }; } } else if pill(ui, Icon::Reload, !matches!(app.page, Page::Home), "Reload") { app.reload(); } if pill(ui, Icon::Home, true, "Home") { app.open(String::from("about:home"), true); } let right = 110.0; let w = (ui.available_width() - right).max(120.0); let edit = egui::TextEdit::singleline(&mut app.address) .hint_text("Search or type a web address") .desired_width(w) .margin(egui::Margin::symmetric(14, 7)) .font(FontId::new(15.5, FontFamily::Proportional)); let resp = ui.add(edit); if app.address_focus { resp.request_focus(); app.address_focus = false; } if resp.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter)) { let typed = app.address.clone(); app.open_input(&typed); } let saved = app.current_url().is_some_and(|u| app.bookmarks.contains(&u)); if pill(ui, Icon::Star(saved), app.current_url().is_some(), if saved { "Remove bookmark" } else { "Bookmark this page" }) { toggle_bookmark(app); } if pill(ui, Icon::Menu, true, "Bookmarks and settings") { app.show_bookmarks = !app.show_bookmarks; } }); if let Page::Loading { .. } = app.page { let t = ui.input(|i| i.time) as f32; let (rect, _) = ui.allocate_exact_size(Vec2::new(ui.available_width(), 2.0), egui::Sense::hover()); let x = rect.left() + (t * 0.6).fract() * rect.width(); ui.painter().rect_filled(egui::Rect::from_min_size(egui::pos2(x - 60.0, rect.top()), Vec2::new(120.0, 2.0)).intersect(rect), 1.0, p.accent); ui.ctx().request_repaint(); } }); if app.show_bookmarks { menu_panel(app, ui); } } fn menu_panel(app: &mut Clearwake, ui: &mut egui::Ui) { let p = palette(is_dark(ui.ctx())); egui::Panel::right("menu") .resizable(false) .exact_size(300.0) .frame(egui::Frame::new().fill(p.bar).inner_margin(16).stroke(Stroke::new(1.0, p.line))) .show(ui, |ui| { ui.label(RichText::new("Bookmarks").size(20.0).strong()); ui.add_space(6.0); if app.bookmarks.items.is_empty() { ui.label(RichText::new("Pages you bookmark show up here. They stay on this device.").color(p.soft)); } let mut open = None; let mut remove = None; egui::ScrollArea::vertical().max_height(ui.available_height() - 190.0).show(ui, |ui| { for b in &app.bookmarks.items { ui.horizontal(|ui| { if ui.add(egui::Link::new(RichText::new(&b.title).color(p.link))).on_hover_text(&b.url).clicked() { open = Some(b.url.clone()); } ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { if ui.small_button("Remove").clicked() { remove = Some(b.url.clone()); } }); }); } }); if let Some(u) = remove { app.bookmarks.remove(&u); } if let Some(u) = open { app.open(u, true); } ui.add_space(12.0); ui.separator(); ui.label(RichText::new("Text size").strong()); ui.horizontal(|ui| { if ui.button("A−").clicked() { app.text_scale = (app.text_scale - 0.1).max(0.7); } ui.label(format!("{}%", (app.text_scale * 100.0).round())); if ui.button("A+").clicked() { app.text_scale = (app.text_scale + 0.1).min(2.0); } }); ui.label(RichText::new("Look").strong()); ui.horizontal(|ui| { for (label, v) in [("System", None), ("Light", Some(false)), ("Dark", Some(true))] { if ui.selectable_label(app.dark == v, label).clicked() { app.dark = v; install_style(ui.ctx(), v); } } }); ui.add_space(8.0); ui.label(RichText::new(format!("Clearwake {} · {} ads and trackers blocked so far", crate::VERSION, app.blocked_total)).small().color(p.soft)); }); } pub fn status_bar(app: &mut Clearwake, ui: &mut egui::Ui) { let p = palette(is_dark(ui.ctx())); egui::Panel::bottom("status") .frame(egui::Frame::new().fill(p.bar).inner_margin(egui::Margin::symmetric(14, 4)).stroke(Stroke::new(1.0, p.line))) .show(ui, |ui| { ui.horizontal(|ui| { if let Some(h) = &app.hover { ui.label(RichText::new(h).small().color(p.soft)); } else { let msg = match &app.page { Page::Doc(d) => { let n = d.stats.blocked + d.stats.hidden; if n > 0 || d.stats.scripts_skipped > 0 { format!("Blocked {} ads and trackers · {} scripts never ran", n, d.stats.scripts_skipped) } else { String::from("No ads found on this page") } } Page::Loading { .. } => String::from("Loading…"), _ => String::from("Ad blocking is always on"), }; shield(ui, p.accent); ui.label(RichText::new(msg).small().color(p.soft)); } }); }); app.hover = None; } pub fn content(app: &mut Clearwake, ui: &mut egui::Ui) { let p = palette(is_dark(ui.ctx())); egui::CentralPanel::default().frame(egui::Frame::new().fill(p.bg)).show(ui, |ui| { let mut scroll = egui::ScrollArea::vertical().auto_shrink([false, false]); if app.scroll_to_top { scroll = scroll.vertical_scroll_offset(0.0); app.scroll_to_top = false; } scroll.show(ui, |ui| { let full = ui.available_width(); let col = full.min(COLUMN); let side = ((full - col) / 2.0).max(0.0); ui.horizontal(|ui| { ui.add_space(side); ui.vertical(|ui| { ui.set_width(col - 24.0); ui.add_space(28.0); page(app, ui, &p); ui.add_space(64.0); }); }); }); }); } enum Action { Open(String), Search(String), } fn page(app: &mut Clearwake, ui: &mut egui::Ui, p: &Palette) { let mut action: Option = None; let scale = app.text_scale; match &app.page { Page::Home => home(app, ui, p, &mut action), Page::Loading { url } => { ui.add_space(80.0); ui.vertical_centered(|ui| { ui.spinner(); ui.label(RichText::new(short(url)).color(p.soft)); }); } Page::Error { url, message } => { ui.add_space(60.0); ui.label(RichText::new("This page didn't open").size(26.0 * scale).strong().color(p.ink)); ui.add_space(8.0); ui.label(RichText::new(message).size(17.0 * scale).color(p.ink)); ui.add_space(4.0); ui.label(RichText::new(short(url)).small().color(p.soft)); ui.add_space(14.0); if ui.button("Try again").clicked() { action = Some(Action::Open(url.clone())); } } Page::Text { text, .. } => { ui.add(egui::Label::new(RichText::new(text).monospace().size(14.5 * scale).color(p.ink)).wrap()); } Page::Picture { url } => { picture(ui, app.pictures.get(url), "", None, None, &mut action, p); } Page::Doc(doc) => { if !doc.title.is_empty() { ui.label(RichText::new(doc.url.display_host()).small().color(p.soft)); ui.add_space(2.0); } if doc.blocks.is_empty() { ui.add_space(20.0); ui.label(RichText::new("This page has nothing Clearwake can show without running its scripts.").color(p.soft)); } for (i, block) in doc.blocks.iter().enumerate() { match block { Block::Heading { level, spans } => { let size = match level { 1 => 32.0, 2 => 25.0, 3 => 21.0, _ => 18.5, } * scale; ui.add_space(if *level <= 2 { 18.0 } else { 12.0 }); spans_ui(ui, spans, size, true, false, p, &mut app.hover, &mut action); ui.add_space(4.0); } Block::Paragraph { spans, quote } => { ui.add_space(6.0); if *quote { egui::Frame::new() .inner_margin(egui::Margin { left: 14, right: 0, top: 2, bottom: 2 }) .show(ui, |ui| { let r = ui.max_rect(); ui.painter().vline(r.left() - 12.0, r.y_range(), Stroke::new(3.0, p.line)); spans_ui(ui, spans, 17.0 * scale, false, true, p, &mut app.hover, &mut action); }); } else { spans_ui(ui, spans, 17.0 * scale, false, false, p, &mut app.hover, &mut action); } ui.add_space(6.0); } Block::ListItem { depth, marker, spans } => { ui.horizontal_top(|ui| { ui.add_space(8.0 + 20.0 * (*depth as f32 - 1.0).clamp(0.0, 6.0)); ui.add_sized([22.0, 20.0 * scale], egui::Label::new(RichText::new(marker).size(17.0 * scale).color(p.soft))); ui.vertical(|ui| { spans_ui(ui, spans, 17.0 * scale, false, false, p, &mut app.hover, &mut action); }); }); ui.add_space(3.0); } Block::Code(code) => { ui.add_space(6.0); egui::Frame::new().fill(p.bar).corner_radius(8).inner_margin(12).show(ui, |ui| { egui::ScrollArea::horizontal().id_salt(("code", i)).show(ui, |ui| { ui.add(egui::Label::new(RichText::new(code).monospace().size(14.0 * scale).color(p.ink)).extend()); }); }); ui.add_space(6.0); } Block::Image { src, alt, width, link, .. } => { ui.add_space(6.0); picture(ui, app.pictures.get(src), alt, *width, link.as_deref(), &mut action, p); ui.add_space(6.0); } Block::Rule => { ui.add_space(8.0); ui.separator(); ui.add_space(8.0); } Block::Form(form) => { let text = app.forms.entry(i).or_insert_with(|| form.value.clone()); if let Some(t) = form_ui(ui, form, text, p) { action = Some(Action::Open(form.target(&t))); } } } } } } match action { Some(Action::Open(u)) => app.open(u, true), Some(Action::Search(s)) => app.open_input(&s), None => {} } } fn home(app: &mut Clearwake, ui: &mut egui::Ui, p: &Palette, action: &mut Option) { ui.add_space(70.0); ui.vertical_centered(|ui| { let (rect, _) = ui.allocate_exact_size(Vec2::splat(64.0), egui::Sense::hover()); draw_mark(ui.painter(), rect, p); ui.add_space(10.0); ui.label(RichText::new("Clearwake").size(40.0).strong().color(p.ink)); ui.label(RichText::new("Less noise. More web.").size(18.0).color(p.soft)); ui.add_space(24.0); let resp = ui.add( egui::TextEdit::singleline(&mut app.home_search) .hint_text("Search the web or type an address") .desired_width(ui.available_width().min(520.0)) .margin(egui::Margin::symmetric(18, 11)) .font(FontId::new(17.0, FontFamily::Proportional)), ); let go = resp.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter)); ui.add_space(10.0); let clicked = ui.add(egui::Button::new(RichText::new("Search").color(Color32::WHITE)).fill(p.accent).min_size(Vec2::new(120.0, 36.0))).clicked(); if (go || clicked) && !app.home_search.trim().is_empty() { *action = Some(Action::Search(app.home_search.trim().to_string())); } ui.add_space(26.0); ui.label( RichText::new(format!( "Ads and trackers are blocked before they load. Scripts never run. {} built-in rules, always on.", app.filter.rule_count() )) .color(p.soft), ); }); if !app.bookmarks.items.is_empty() { ui.add_space(36.0); ui.label(RichText::new("Bookmarks").size(20.0).strong().color(p.ink)); ui.add_space(6.0); for b in &app.bookmarks.items { if ui.add(egui::Link::new(RichText::new(&b.title).size(17.0).color(p.link))).on_hover_text(&b.url).clicked() { *action = Some(Action::Open(b.url.clone())); } ui.add_space(2.0); } } } #[allow(clippy::too_many_arguments)] fn spans_ui(ui: &mut egui::Ui, spans: &[Inline], size: f32, heading: bool, quote: bool, p: &Palette, hover: &mut Option, action: &mut Option) { ui.horizontal_wrapped(|ui| { ui.spacing_mut().item_spacing = Vec2::new(0.0, 3.0); for sp in spans { for (n, piece) in sp.text.split('\n').enumerate() { if n > 0 { ui.end_row(); } if piece.is_empty() { continue; } let mut rt = RichText::new(piece).size(size); if sp.code { rt = rt.monospace().size(size * 0.88).background_color(p.bar); } if heading || sp.bold { rt = rt.strong(); } if sp.italic || quote { rt = rt.italics(); } match &sp.link { Some(href) => { let r = ui.add(egui::Link::new(rt.color(p.link))); if r.hovered() { *hover = Some(href.clone()); } if r.clicked() { *action = Some(Action::Open(href.clone())); } } None => { let color = if heading { p.ink } else if quote { p.soft } else { p.ink }; ui.add(egui::Label::new(rt.color(color)).wrap()); } } } } }); } fn picture(ui: &mut egui::Ui, pic: Option<&Picture>, alt: &str, width: Option, link: Option<&str>, action: &mut Option, p: &Palette) { let max_w = ui.available_width(); match pic { Some(Picture::Ready(tex)) => { let [w, h] = tex.resolution(); let mut want = w as f32; if let Some(attr) = width { want = want.min(attr as f32 * 1.0); } let scale = (want.min(max_w)) / w as f32; let size = Vec2::new(w as f32 * scale, h as f32 * scale); let mut img = egui::Image::new(egui::load::SizedTexture::new(tex.id(), size)).corner_radius(6); if link.is_some() { img = img.sense(egui::Sense::click()); } let r = ui.add(img); let r = if alt.is_empty() { r } else { r.on_hover_text(alt) }; if let Some(l) = link { if r.clicked() { *action = Some(Action::Open(l.to_string())); } } } Some(Picture::Loading) => { let h = 120.0_f32.min(max_w * 0.4); let (rect, _) = ui.allocate_exact_size(Vec2::new(max_w.min(width.map(|w| w as f32).unwrap_or(max_w)), h), egui::Sense::hover()); ui.painter().rect_filled(rect, 6.0, p.bar); if !alt.is_empty() { ui.painter().text(rect.center(), egui::Align2::CENTER_CENTER, short(alt), FontId::proportional(14.0), p.soft); } } _ => { if !alt.is_empty() { ui.label(RichText::new(format!("[{alt}]")).italics().color(p.soft)); } } } } fn form_ui(ui: &mut egui::Ui, form: &Form, text: &mut String, p: &Palette) -> Option { let mut out = None; ui.add_space(6.0); ui.horizontal(|ui| { let hint = if form.placeholder.is_empty() { "Search" } else { form.placeholder.as_str() }; let r = ui.add(egui::TextEdit::singleline(text).hint_text(hint).desired_width((ui.available_width() - 110.0).max(120.0)).margin(egui::Margin::symmetric(12, 6))); let enter = r.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter)); let label = if form.submit.is_empty() { "Search" } else { form.submit.as_str() }; let click = ui.add(egui::Button::new(RichText::new(label).color(Color32::WHITE)).fill(p.accent)).clicked(); if enter || click { out = Some(text.clone()); } }); ui.add_space(6.0); out } fn short(s: &str) -> String { if s.chars().count() > 90 { let mut t: String = s.chars().take(88).collect(); t.push('…'); t } else { s.to_string() } } /// The Clearwake mark: a calm circle with a wake line through it. fn draw_mark(painter: &egui::Painter, rect: egui::Rect, p: &Palette) { let c = rect.center(); let r = rect.width() / 2.0; painter.circle_filled(c, r, p.accent); let wave = |y: f32, amp: f32| -> Vec { (0..=24).map(|i| { let t = i as f32 / 24.0; let x = c.x - r * 0.62 + t * r * 1.24; egui::pos2(x, y + (t * std::f32::consts::TAU).sin() * amp) }).collect() }; painter.add(egui::Shape::line(wave(c.y - r * 0.12, r * 0.12), Stroke::new(r * 0.11, Color32::WHITE))); painter.add(egui::Shape::line(wave(c.y + r * 0.22, r * 0.08), Stroke::new(r * 0.08, Color32::from_white_alpha(170)))); } /// The window icon, drawn in code so every platform shares it. #[allow(dead_code)] pub fn app_icon() -> egui::IconData { let n = 128usize; let mut rgba = vec![0u8; n * n * 4]; let (cr, cg, cb) = (0x1f_u8, 0x7a_u8, 0x6c_u8); let c = n as f32 / 2.0; let r = c - 4.0; for y in 0..n { for x in 0..n { let (fx, fy) = (x as f32 + 0.5 - c, y as f32 + 0.5 - c); let d = (fx * fx + fy * fy).sqrt(); let a = (r + 0.5 - d).clamp(0.0, 1.0); if a <= 0.0 { continue; } let t = (fx + r * 0.62) / (r * 1.24); let mut px = (cr, cg, cb); if (0.0..=1.0).contains(&t) { let w1 = -r * 0.12 + (t * std::f32::consts::TAU).sin() * r * 0.12; let w2 = r * 0.22 + (t * std::f32::consts::TAU).sin() * r * 0.08; if (fy - w1).abs() < r * 0.055 { px = (255, 255, 255); } else if (fy - w2).abs() < r * 0.04 { px = (190, 222, 216); } } let i = (y * n + x) * 4; rgba[i] = px.0; rgba[i + 1] = px.1; rgba[i + 2] = px.2; rgba[i + 3] = (a * 255.0) as u8; } } egui::IconData { rgba, width: n as u32, height: n as u32 } }