mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 04:58:07 +00:00
pdf-chrome-w10: net change of 3 commits
- pdf-chrome-w10: written from its sheet - pdf-chrome-w10: repair 1 - pdf-chrome-w10: review fixes (review-1)
This commit is contained in:
+70
-1022
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,108 @@
|
||||
//! The top slot: the menus, the mode strip, the document buttons and the command search.
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use craft::behavior::{DisplayOrder, IconId, ItemSource, SelectionChange};
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::menu::Target;
|
||||
use craft::ui::bars::{Bar, BarKind};
|
||||
use craft::ui::buttons::{CommandSearch, IconButton};
|
||||
use craft::ui::contract::{Bind, CollectionEvent, Show as _, ShowCollection as _, ShowContainer as _};
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::menu::HelpEntry;
|
||||
use craft::ui::patterns::panels::CommandPalette;
|
||||
use craft::ui::tabs::{Tab, TabKind, TabStrip};
|
||||
|
||||
use pdfcraft_engine::catalog::{Availability, TOOL_GROUPS};
|
||||
|
||||
use crate::{Mode, PdfCraftApp};
|
||||
|
||||
/// The modes the strip offers. Read is a View command, not a tab.
|
||||
const MODES: [(Mode, &str); 4] = [(Mode::AllTools, "All tools"), (Mode::Edit, "Edit"), (Mode::Convert, "Convert"), (Mode::Sign, "E-Sign")];
|
||||
|
||||
/// The mode labels, keyed by position.
|
||||
struct ModeTabs;
|
||||
|
||||
impl DisplayOrder<usize> for ModeTabs {
|
||||
fn len(&self) -> usize {
|
||||
MODES.len()
|
||||
}
|
||||
|
||||
fn key(&self, at: usize) -> usize {
|
||||
at
|
||||
}
|
||||
|
||||
fn index_of(&self, key: &usize) -> Option<usize> {
|
||||
(*key < MODES.len()).then_some(*key)
|
||||
}
|
||||
|
||||
fn text(&self, at: usize) -> Option<Cow<'_, str>> {
|
||||
MODES.get(at).map(|(_, label)| Cow::Borrowed(tl!(*label)))
|
||||
}
|
||||
}
|
||||
|
||||
impl ItemSource<usize> for ModeTabs {}
|
||||
|
||||
/// Draw the menus, the mode strip and the buttons after it, then the command palette over them.
|
||||
pub(super) fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
|
||||
let hidden = app.hidden_interface();
|
||||
let menus = app.native_menu.is_none() && !hidden.menubar;
|
||||
Row::new().show(ui, |ui, _| {
|
||||
if menus {
|
||||
app.menu_bar_ui(ui);
|
||||
}
|
||||
// The document may hide the tools (`crate::viewer_prefs`); the buttons stay.
|
||||
let shown = MODES.iter().position(|(mode, _)| *mode == app.mode);
|
||||
Bar::new(tl!("Modes"), BarKind::Tool)
|
||||
.trailing(|ui, _| {
|
||||
IconButton::command(IconId::new("printer"), "print.dialog").show(ui);
|
||||
IconButton::command(IconId::new("save"), "file.save").show(ui);
|
||||
IconButton::command(IconId::new("info"), "file.properties").show(ui);
|
||||
CommandSearch::new("view.palette", tl!("Find tools and commands")).show(ui);
|
||||
})
|
||||
.show(ui, |ui, _| {
|
||||
if hidden.toolbar {
|
||||
return;
|
||||
}
|
||||
let strip = TabStrip::new(tl!("Modes")).kind(TabKind::Text);
|
||||
let strip = match shown {
|
||||
Some(at) => strip.shown(at),
|
||||
None => strip,
|
||||
};
|
||||
let out = strip.show_items(ui, &ModeTabs, &mut |key, _| Tab::new(tl!(MODES[*key % MODES.len()].1)));
|
||||
for event in out.response.events {
|
||||
if let CollectionEvent::Selection(SelectionChange::Set(keys)) = event
|
||||
&& let Some((mode, _)) = keys.last().and_then(|at| MODES.get(*at))
|
||||
{
|
||||
app.switch_mode(*mode, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
if app.palette_open {
|
||||
let ctx = ui.ctx().clone();
|
||||
let entries = palette_entries(app, &ctx);
|
||||
CommandPalette::new(tl!("Find tools and commands"), &entries, Bind::bound(&mut app.palette_open)).show(ui);
|
||||
}
|
||||
}
|
||||
|
||||
/// What the palette searches: the menus' commands, each ready tool group, and the catalogue items
|
||||
/// that are not commands of their own.
|
||||
fn palette_entries(app: &PdfCraftApp, ctx: &egui::Context) -> Vec<HelpEntry> {
|
||||
let mut entries = app.menu_bar(ctx).help_entries(Target::current(), &crate::menus::layout_options(), None);
|
||||
for group in TOOL_GROUPS {
|
||||
if group.availability == Availability::Ready {
|
||||
// PLAN: assumed `tool.group` reads a `group` parameter (pdf-chrome-w9)
|
||||
let select = CommandRef::with_params("tool.group", serde_json::json!({ "group": group.id }));
|
||||
entries.push(HelpEntry::new(select, tl!(group.label)).with_path([tl!("Tool")]));
|
||||
}
|
||||
for section in group.sections {
|
||||
for item in section.items {
|
||||
if item.availability == Availability::Ready && pdfcraft_engine::commands::command(item.command).is_none() {
|
||||
entries.push(HelpEntry::new(item.command, tl!(item.label)).with_path([tl!(group.label)]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
entries
|
||||
}
|
||||
@@ -1,462 +0,0 @@
|
||||
//! Window buttons and resize edges for desktops that leave the window frame to the app.
|
||||
//!
|
||||
//! GNOME on Wayland has no server-side decorations (the compositor offers no
|
||||
//! `zxdg_decoration_manager_v1`), so winit drew its own imitation frame. Instead the app turns the
|
||||
//! frame off and the tab strip becomes the header bar, as in GNOME's own apps: it carries the
|
||||
//! minimize, maximize and close buttons in the desktop's order (GNOME's `button-layout`), and
|
||||
//! thin zones along the window's edges resize it. Desktops with server-side decorations (KDE,
|
||||
//! Sway, Hyprland, X11) keep their own frame and never get here.
|
||||
|
||||
use crate::theme::Tokens;
|
||||
use egui::viewport::ResizeDirection;
|
||||
use egui::{Align2, Color32, CursorIcon, Pos2, Rect, Sense, Stroke, Vec2};
|
||||
|
||||
/// A window button.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Button {
|
||||
Minimize,
|
||||
Maximize,
|
||||
Close,
|
||||
}
|
||||
|
||||
/// Which buttons go on which end of the header bar, outermost last.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Layout {
|
||||
pub left: Vec<Button>,
|
||||
pub right: Vec<Button>,
|
||||
}
|
||||
|
||||
impl Default for Layout {
|
||||
/// What a desktop that names no layout gets: all three, on the right.
|
||||
fn default() -> Self {
|
||||
Self { left: Vec::new(), right: vec![Button::Minimize, Button::Maximize, Button::Close] }
|
||||
}
|
||||
}
|
||||
|
||||
impl Layout {
|
||||
/// GNOME's `org.gnome.desktop.wm.preferences button-layout`: `left:right`, each a comma list
|
||||
/// such as `appmenu:minimize,maximize,close` (Fedora's default is `appmenu:close`). Without a
|
||||
/// colon everything is on the left, as in GTK. Names this app has no button for (`appmenu`,
|
||||
/// `icon`, `menu`, `spacer`) are skipped, and a button named twice appears once. `gsettings`
|
||||
/// prints the value quoted; the quotes are dropped.
|
||||
pub fn parse(value: &str) -> Self {
|
||||
let value = value.trim().trim_matches(|c| c == '\'' || c == '"');
|
||||
let (left, right) = value.split_once(':').unwrap_or((value, ""));
|
||||
let mut seen = Vec::new();
|
||||
let mut side = |list: &str| {
|
||||
let mut out = Vec::new();
|
||||
for name in list.split(',') {
|
||||
let button = match name.trim() {
|
||||
"minimize" => Button::Minimize,
|
||||
"maximize" => Button::Maximize,
|
||||
"close" => Button::Close,
|
||||
_ => continue,
|
||||
};
|
||||
if !seen.contains(&button) {
|
||||
seen.push(button);
|
||||
out.push(button);
|
||||
}
|
||||
}
|
||||
out
|
||||
};
|
||||
let left = side(left);
|
||||
let right = side(right);
|
||||
Self { left, right }
|
||||
}
|
||||
}
|
||||
|
||||
/// The round button's diameter, as in Adwaita.
|
||||
pub const BUTTON: f32 = 24.0;
|
||||
/// Between two window buttons.
|
||||
pub const GAP: f32 = 6.0;
|
||||
/// Between the window buttons and the rest of the strip.
|
||||
pub const SIDE_GAP: f32 = 10.0;
|
||||
|
||||
/// The width `buttons` take in the strip, including the gap to the rest of it.
|
||||
pub fn width(buttons: &[Button]) -> f32 {
|
||||
match buttons.len() {
|
||||
0 => 0.0,
|
||||
n => n as f32 * BUTTON + (n - 1) as f32 * GAP + SIDE_GAP,
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw the window buttons for one end of the strip, in reading order, inside a horizontal
|
||||
/// layout running left to right; the caller adds [`SIDE_GAP`] where the strip continues.
|
||||
pub fn buttons(ui: &mut egui::Ui, buttons: &[Button]) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let maximized = ui.ctx().input(|i| i.viewport().maximized.unwrap_or(false));
|
||||
for (n, &button) in buttons.iter().enumerate() {
|
||||
if n > 0 {
|
||||
ui.add_space(GAP);
|
||||
}
|
||||
let label = match button {
|
||||
Button::Minimize => tl!("Minimize"),
|
||||
Button::Maximize if maximized => tl!("Restore"),
|
||||
Button::Maximize => tl!("Maximize"),
|
||||
Button::Close => tl!("Close"),
|
||||
};
|
||||
let (rect, response) = ui.allocate_exact_size(Vec2::splat(BUTTON), Sense::click());
|
||||
response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, label));
|
||||
let response = response.on_hover_text(label);
|
||||
if ui.is_rect_visible(rect) {
|
||||
paint(ui.painter(), rect, button, maximized, &t, &response);
|
||||
}
|
||||
if response.clicked() {
|
||||
let command = match button {
|
||||
Button::Minimize => egui::ViewportCommand::Minimized(true),
|
||||
Button::Maximize => egui::ViewportCommand::Maximized(!maximized),
|
||||
// The same path as the desktop's close: unsaved documents still ask first.
|
||||
Button::Close => egui::ViewportCommand::Close,
|
||||
};
|
||||
ui.ctx().send_viewport_cmd(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Adwaita's look: a round wash of the text colour, stronger on hover and press, and a 16-point
|
||||
/// symbolic glyph drawn with lines (no icon files).
|
||||
fn paint(painter: &egui::Painter, rect: Rect, button: Button, maximized: bool, t: &Tokens, response: &egui::Response) {
|
||||
let alpha = if response.is_pointer_button_down_on() {
|
||||
0.28
|
||||
} else if response.hovered() {
|
||||
0.16
|
||||
} else {
|
||||
0.10
|
||||
};
|
||||
painter.circle_filled(rect.center(), BUTTON / 2.0, t.text.gamma_multiply(alpha));
|
||||
if response.has_focus() {
|
||||
painter.circle_stroke(rect.center(), BUTTON / 2.0 - 0.5, Stroke::new(1.0, t.accent));
|
||||
}
|
||||
let stroke = Stroke::new(1.25, t.text);
|
||||
// The glyph's 16-point square, its corners on pixel centres so lines stay crisp.
|
||||
let c = rect.center();
|
||||
let at = |x: f32, y: f32| Pos2::new((c.x - 8.0 + x).round() + 0.5, (c.y - 8.0 + y).round() + 0.5);
|
||||
match button {
|
||||
Button::Minimize => {
|
||||
painter.line_segment([at(4.0, 11.0), at(11.0, 11.0)], stroke);
|
||||
}
|
||||
Button::Maximize if maximized => {
|
||||
// Restore: a smaller window in front of another.
|
||||
painter.rect_stroke(Rect::from_two_pos(at(4.0, 6.0), at(10.0, 12.0)), 1.0, stroke, egui::StrokeKind::Middle);
|
||||
painter.line_segment([at(6.0, 6.0), at(6.0, 4.0)], stroke);
|
||||
painter.line_segment([at(6.0, 4.0), at(12.0, 4.0)], stroke);
|
||||
painter.line_segment([at(12.0, 4.0), at(12.0, 10.0)], stroke);
|
||||
painter.line_segment([at(12.0, 10.0), at(10.0, 10.0)], stroke);
|
||||
}
|
||||
Button::Maximize => {
|
||||
painter.rect_stroke(Rect::from_two_pos(at(4.0, 4.0), at(11.0, 11.0)), 1.0, stroke, egui::StrokeKind::Middle);
|
||||
}
|
||||
Button::Close => {
|
||||
painter.line_segment([at(4.0, 4.0), at(11.0, 11.0)], stroke);
|
||||
painter.line_segment([at(11.0, 4.0), at(4.0, 11.0)], stroke);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// How far into the window an edge resizes it.
|
||||
const EDGE: f32 = 5.0;
|
||||
/// How far along an edge a corner reaches, so corners are easy to hit.
|
||||
const CORNER: f32 = 16.0;
|
||||
|
||||
/// The resize zones of a window filling `rect`: edges `edge` deep, and each corner an L of two
|
||||
/// strips reaching `corner` along both edges (a square would reach into the content).
|
||||
fn zones(rect: Rect, edge: f32, corner: f32) -> Vec<(ResizeDirection, Rect)> {
|
||||
let (l, r, t, b) = (rect.left(), rect.right(), rect.top(), rect.bottom());
|
||||
// Never inverted, however small the window.
|
||||
let zone = |x0: f32, x1: f32, y0: f32, y1: f32| Rect::from_min_max(Pos2::new(x0, y0), Pos2::new(x1.max(x0), y1.max(y0)));
|
||||
vec![
|
||||
(ResizeDirection::NorthWest, zone(l, l + corner, t, t + edge)),
|
||||
(ResizeDirection::NorthWest, zone(l, l + edge, t + edge, t + corner)),
|
||||
(ResizeDirection::NorthEast, zone(r - corner, r, t, t + edge)),
|
||||
(ResizeDirection::NorthEast, zone(r - edge, r, t + edge, t + corner)),
|
||||
(ResizeDirection::SouthWest, zone(l, l + corner, b - edge, b)),
|
||||
(ResizeDirection::SouthWest, zone(l, l + edge, b - corner, b - edge)),
|
||||
(ResizeDirection::SouthEast, zone(r - corner, r, b - edge, b)),
|
||||
(ResizeDirection::SouthEast, zone(r - edge, r, b - corner, b - edge)),
|
||||
(ResizeDirection::North, zone(l + corner, r - corner, t, t + edge)),
|
||||
(ResizeDirection::South, zone(l + corner, r - corner, b - edge, b)),
|
||||
(ResizeDirection::West, zone(l, l + edge, t + corner, b - corner)),
|
||||
(ResizeDirection::East, zone(r - edge, r, t + corner, b - corner)),
|
||||
]
|
||||
}
|
||||
|
||||
fn cursor(direction: ResizeDirection) -> CursorIcon {
|
||||
match direction {
|
||||
ResizeDirection::North => CursorIcon::ResizeNorth,
|
||||
ResizeDirection::South => CursorIcon::ResizeSouth,
|
||||
ResizeDirection::East => CursorIcon::ResizeEast,
|
||||
ResizeDirection::West => CursorIcon::ResizeWest,
|
||||
ResizeDirection::NorthEast => CursorIcon::ResizeNorthEast,
|
||||
ResizeDirection::SouthEast => CursorIcon::ResizeSouthEast,
|
||||
ResizeDirection::NorthWest => CursorIcon::ResizeNorthWest,
|
||||
ResizeDirection::SouthWest => CursorIcon::ResizeSouthWest,
|
||||
}
|
||||
}
|
||||
|
||||
/// Resize zones along the window's edges and a hairline border, while the window is neither
|
||||
/// maximized nor full screen. The zones sit above everything else (in the foreground order), so a
|
||||
/// press there resizes instead of reaching the scrollbar or panel under it.
|
||||
pub fn resize_edges(ctx: &egui::Context) {
|
||||
let (maximized, fullscreen) = ctx.input(|i| (i.viewport().maximized.unwrap_or(false), i.viewport().fullscreen.unwrap_or(false)));
|
||||
if maximized || fullscreen {
|
||||
return;
|
||||
}
|
||||
let screen = ctx.content_rect();
|
||||
let t = Tokens::get(ctx);
|
||||
egui::Area::new(egui::Id::unique("window_resize_edges"))
|
||||
.order(egui::Order::Foreground)
|
||||
.fixed_pos(screen.min)
|
||||
.pivot(Align2::LEFT_TOP)
|
||||
.interactable(true)
|
||||
.show(ctx, |ui| {
|
||||
ui.set_min_size(Vec2::ZERO);
|
||||
for (n, (direction, rect)) in zones(screen, EDGE, CORNER).into_iter().enumerate() {
|
||||
if rect.width() <= 0.0 || rect.height() <= 0.0 {
|
||||
continue;
|
||||
}
|
||||
let response = ui.interact(rect, ui.scope_id().with(("edge", n)), Sense::drag()).on_hover_cursor(cursor(direction));
|
||||
// Sensing only drags, a drag starts on the press itself.
|
||||
if response.drag_started() {
|
||||
desktop_grab(ui.ctx(), egui::ViewportCommand::BeginResize(direction));
|
||||
}
|
||||
}
|
||||
// Without the desktop's frame or shadow, a hairline keeps the window apart from
|
||||
// what's behind it.
|
||||
ui.painter().rect_stroke(
|
||||
screen,
|
||||
0.0,
|
||||
Stroke::new(1.0, Color32::from_black_alpha(if t.dark() { 160 } else { 60 })),
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// Return the stable egui id for desktop window-grab state.
|
||||
fn grab_id() -> egui::Id {
|
||||
egui::Id::unique("window_controls_desktop_grab")
|
||||
}
|
||||
|
||||
/// Hand the pointer to the desktop to move or resize the window. On Wayland the compositor keeps
|
||||
/// the button's release and winit reports only that the pointer left, which egui doesn't count as
|
||||
/// a release; egui would think the button still held, and the next press on an edge or the title
|
||||
/// bar wouldn't start a drag until a click inside the window. The release comes back on the next
|
||||
/// input (`release_after_desktop_grab`).
|
||||
pub fn desktop_grab(ctx: &egui::Context, command: egui::ViewportCommand) {
|
||||
ctx.send_viewport_cmd(command);
|
||||
ctx.data_mut(|d| d.insert_temp(grab_id(), ()));
|
||||
ctx.request_repaint();
|
||||
}
|
||||
|
||||
/// After `desktop_grab`, add the primary button's release to the next input, unless it brings one.
|
||||
/// The release goes before the input's first press (the next resize or move, or a click), which
|
||||
/// egui would otherwise end straight away; a release after that press is the press's own. It also
|
||||
/// goes before the pointer leaving, as a button event would bring the gone pointer back; a release
|
||||
/// the input brings after the pointer left is the grab's own, and moves there instead.
|
||||
pub fn release_after_desktop_grab(ctx: &egui::Context, raw: &mut egui::RawInput) {
|
||||
if ctx.data_mut(|d| d.remove_temp::<()>(grab_id())).is_none() {
|
||||
return;
|
||||
}
|
||||
let mut at = raw.events.len();
|
||||
let mut gone = None;
|
||||
let mut brought = None;
|
||||
for (n, e) in raw.events.iter().enumerate() {
|
||||
match e {
|
||||
egui::Event::PointerButton { button: egui::PointerButton::Primary, pressed: false, .. } => {
|
||||
brought = Some(n);
|
||||
break;
|
||||
}
|
||||
egui::Event::PointerButton { button: egui::PointerButton::Primary, pressed: true, .. } => {
|
||||
at = n;
|
||||
break;
|
||||
}
|
||||
egui::Event::PointerGone => {
|
||||
gone.get_or_insert(n);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if let Some(n) = brought {
|
||||
// `gone` was found before `n`, so both are in range.
|
||||
if let Some(g) = gone {
|
||||
let release = raw.events.remove(n);
|
||||
raw.events.insert(g, release);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let at = gone.unwrap_or(at);
|
||||
let (pos, modifiers) = ctx.input(|i| (i.pointer.interact_pos().unwrap_or_default(), i.modifiers));
|
||||
raw.events.insert(at, egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed: false, modifiers });
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{Button, Layout, ResizeDirection, zones};
|
||||
use egui::{Pos2, Rect};
|
||||
|
||||
#[test]
|
||||
fn gnome_button_layouts_parse() {
|
||||
let close = Layout { left: vec![], right: vec![Button::Close] };
|
||||
assert_eq!(Layout::parse("'appmenu:close'"), close);
|
||||
assert_eq!(Layout::parse("appmenu:close\n"), close);
|
||||
assert_eq!(Layout::parse(":minimize,maximize,close"), Layout::default());
|
||||
assert_eq!(
|
||||
Layout::parse("close,minimize,maximize:appmenu"),
|
||||
Layout { left: vec![Button::Close, Button::Minimize, Button::Maximize], right: vec![] }
|
||||
);
|
||||
// No colon: the left side, as GTK reads it.
|
||||
assert_eq!(Layout::parse("close"), Layout { left: vec![Button::Close], right: vec![] });
|
||||
// Unknown names, spaces and repeats.
|
||||
assert_eq!(Layout::parse("icon,spacer: close , close,bogus"), close);
|
||||
assert_eq!(Layout::parse(""), Layout { left: vec![], right: vec![] });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn widths_cover_the_buttons_and_their_gaps() {
|
||||
assert_eq!(super::width(&[]), 0.0);
|
||||
assert_eq!(super::width(&[Button::Close]), super::BUTTON + super::SIDE_GAP);
|
||||
assert_eq!(super::width(&Layout::default().right), 3.0 * super::BUTTON + 2.0 * super::GAP + super::SIDE_GAP);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resize_zones_line_the_edges_without_overlapping() {
|
||||
let window = Rect::from_min_size(Pos2::ZERO, egui::vec2(800.0, 600.0));
|
||||
let zones = zones(window, 5.0, 16.0);
|
||||
let at = |x: f32, y: f32| zones.iter().filter(|(_, r)| r.contains(Pos2::new(x, y))).map(|(d, _)| *d).collect::<Vec<_>>();
|
||||
assert_eq!(at(1.0, 1.0), [ResizeDirection::NorthWest]);
|
||||
assert_eq!(at(2.0, 12.0), [ResizeDirection::NorthWest]);
|
||||
assert_eq!(at(400.0, 2.0), [ResizeDirection::North]);
|
||||
assert_eq!(at(799.0, 300.0), [ResizeDirection::East]);
|
||||
assert_eq!(at(400.0, 599.0), [ResizeDirection::South]);
|
||||
assert_eq!(at(1.0, 300.0), [ResizeDirection::West]);
|
||||
assert_eq!(at(799.0, 599.0), [ResizeDirection::SouthEast]);
|
||||
assert!(at(400.0, 300.0).is_empty(), "the middle of the window is left alone");
|
||||
assert!(at(12.0, 12.0).is_empty(), "corners stay along the edges");
|
||||
// Strips meet without overlapping.
|
||||
for y in [0.5, 4.5, 5.5, 15.5, 16.5, 595.5] {
|
||||
for x in [0.5, 4.5, 5.5, 15.5, 16.5, 795.5, 799.5] {
|
||||
assert!(at(x, y).len() <= 1, "({x}, {y}): {:?}", at(x, y));
|
||||
}
|
||||
}
|
||||
// A window smaller than its corners gets empty (not inverted) edge zones.
|
||||
for (_, r) in super::zones(Rect::from_min_size(Pos2::ZERO, egui::vec2(20.0, 20.0)), 5.0, 16.0) {
|
||||
assert!(r.width() >= 0.0 && r.height() >= 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_desktop_grab_gives_the_button_release_back() {
|
||||
let ctx = egui::Context::default();
|
||||
let releases = |raw: &egui::RawInput| {
|
||||
raw.events.iter().filter(|e| matches!(e, egui::Event::PointerButton { button: egui::PointerButton::Primary, pressed: false, .. })).count()
|
||||
};
|
||||
let mut raw = egui::RawInput::default();
|
||||
super::release_after_desktop_grab(&ctx, &mut raw);
|
||||
assert_eq!(releases(&raw), 0, "no grab, no release");
|
||||
|
||||
super::desktop_grab(&ctx, egui::ViewportCommand::StartDrag);
|
||||
super::release_after_desktop_grab(&ctx, &mut raw);
|
||||
assert_eq!(releases(&raw), 1, "the release the desktop kept");
|
||||
|
||||
let mut raw = egui::RawInput::default();
|
||||
super::release_after_desktop_grab(&ctx, &mut raw);
|
||||
assert_eq!(releases(&raw), 0, "only once");
|
||||
|
||||
super::desktop_grab(&ctx, egui::ViewportCommand::BeginResize(ResizeDirection::East));
|
||||
let mut raw = egui::RawInput::default();
|
||||
raw.events.push(egui::Event::PointerButton {
|
||||
pos: Pos2::ZERO,
|
||||
button: egui::PointerButton::Primary,
|
||||
pressed: false,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
});
|
||||
super::release_after_desktop_grab(&ctx, &mut raw);
|
||||
assert_eq!(releases(&raw), 1, "not doubled when the input brings it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_release_goes_before_the_press_of_the_next_grab() {
|
||||
let button = |pressed| egui::Event::PointerButton {
|
||||
pos: Pos2::new(5.0, 5.0),
|
||||
button: egui::PointerButton::Primary,
|
||||
pressed,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
};
|
||||
let primary = |raw: &egui::RawInput| {
|
||||
raw.events
|
||||
.iter()
|
||||
.filter_map(|e| if let egui::Event::PointerButton { pressed, .. } = e { Some(*pressed) } else { None })
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
let ctx = egui::Context::default();
|
||||
let frame = |events: Vec<egui::Event>, grab: Option<egui::ViewportCommand>| {
|
||||
let mut raw = egui::RawInput { events, ..Default::default() };
|
||||
super::release_after_desktop_grab(&ctx, &mut raw);
|
||||
let order = primary(&raw);
|
||||
ctx.run_ui(raw, |ui| {
|
||||
if let Some(command) = grab.clone() {
|
||||
super::desktop_grab(ui.ctx(), command);
|
||||
}
|
||||
})
|
||||
.textures_delta
|
||||
.clear();
|
||||
order
|
||||
};
|
||||
// The press of the first resize starts the grab; the desktop keeps its release.
|
||||
frame(vec![egui::Event::PointerMoved(Pos2::new(5.0, 5.0)), button(true)], Some(egui::ViewportCommand::BeginResize(ResizeDirection::East)));
|
||||
// The next input brings the press of the second resize.
|
||||
assert_eq!(frame(vec![button(true)], None), [false, true], "the kept release, then the new press");
|
||||
assert!(ctx.input(|i| i.pointer.primary_down()), "the second resize holds the button");
|
||||
|
||||
// A quick click's release belongs to its own press, not to the grab before it.
|
||||
frame(vec![], Some(egui::ViewportCommand::StartDrag));
|
||||
assert_eq!(frame(vec![button(true), button(false)], None), [false, true, false]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_release_goes_before_the_pointer_leaving() {
|
||||
let ctx = egui::Context::default();
|
||||
let frame = |events: Vec<egui::Event>, grab: bool| {
|
||||
let mut raw = egui::RawInput { events, ..Default::default() };
|
||||
super::release_after_desktop_grab(&ctx, &mut raw);
|
||||
let order = raw.events.clone();
|
||||
ctx.run_ui(raw, |ui| {
|
||||
if grab {
|
||||
super::desktop_grab(ui.ctx(), egui::ViewportCommand::StartDrag);
|
||||
}
|
||||
})
|
||||
.textures_delta
|
||||
.clear();
|
||||
order
|
||||
};
|
||||
let release = |e: &egui::Event| matches!(e, egui::Event::PointerButton { button: egui::PointerButton::Primary, pressed: false, .. });
|
||||
let press = egui::Event::PointerButton {
|
||||
pos: Pos2::new(5.0, 5.0),
|
||||
button: egui::PointerButton::Primary,
|
||||
pressed: true,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
};
|
||||
// On Wayland the input after a move brings only that the pointer left.
|
||||
frame(vec![egui::Event::PointerMoved(Pos2::new(5.0, 5.0)), press], true);
|
||||
let order = frame(vec![egui::Event::PointerGone], false);
|
||||
assert!(matches!(order.as_slice(), [r, egui::Event::PointerGone] if release(r)), "{order:?}");
|
||||
assert_eq!(ctx.input(|i| i.pointer.latest_pos()), None, "the pointer stays gone");
|
||||
assert!(!ctx.input(|i| i.pointer.primary_down()));
|
||||
|
||||
// A release after the pointer left is the one the desktop kept, not to be doubled.
|
||||
frame(vec![], true);
|
||||
let order = frame(
|
||||
vec![
|
||||
egui::Event::PointerGone,
|
||||
egui::Event::PointerButton {
|
||||
pos: Pos2::new(5.0, 5.0),
|
||||
button: egui::PointerButton::Primary,
|
||||
pressed: false,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
},
|
||||
],
|
||||
false,
|
||||
);
|
||||
assert!(matches!(order.as_slice(), [r, egui::Event::PointerGone] if release(r)), "moved, not doubled: {order:?}");
|
||||
assert_eq!(ctx.input(|i| i.pointer.latest_pos()), None, "the pointer stays gone");
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,196 +0,0 @@
|
||||
//! Lucide icons (ISC licence, see assets/icons/LICENSE-lucide.txt), embedded and tinted at runtime.
|
||||
//! Generated from the contents of assets/icons/.
|
||||
|
||||
pub static ICONS: &[(&str, &[u8])] = &[
|
||||
("accessibility", include_bytes!("../../../../assets/icons/accessibility.svg")),
|
||||
("align-center", include_bytes!("../../../../assets/icons/align-center.svg")),
|
||||
("align-justify", include_bytes!("../../../../assets/icons/align-justify.svg")),
|
||||
("file-spreadsheet", include_bytes!("../../../../assets/icons/file-spreadsheet.svg")),
|
||||
("file-code", include_bytes!("../../../../assets/icons/file-code.svg")),
|
||||
("square-terminal", include_bytes!("../../../../assets/icons/square-terminal.svg")),
|
||||
("align-left", include_bytes!("../../../../assets/icons/align-left.svg")),
|
||||
("align-right", include_bytes!("../../../../assets/icons/align-right.svg")),
|
||||
("app-window", include_bytes!("../../../../assets/icons/app-window.svg")),
|
||||
("arrow-left-right", include_bytes!("../../../../assets/icons/arrow-left-right.svg")),
|
||||
("arrow-up-down", include_bytes!("../../../../assets/icons/arrow-up-down.svg")),
|
||||
("arrow-up-right", include_bytes!("../../../../assets/icons/arrow-up-right.svg")),
|
||||
("badge-check", include_bytes!("../../../../assets/icons/badge-check.svg")),
|
||||
("bandage", include_bytes!("../../../../assets/icons/bandage.svg")),
|
||||
("bell", include_bytes!("../../../../assets/icons/bell.svg")),
|
||||
("blend", include_bytes!("../../../../assets/icons/blend.svg")),
|
||||
("bold", include_bytes!("../../../../assets/icons/bold.svg")),
|
||||
("book-open", include_bytes!("../../../../assets/icons/book-open.svg")),
|
||||
("bookmark", include_bytes!("../../../../assets/icons/bookmark.svg")),
|
||||
("bookmark-plus", include_bytes!("../../../../assets/icons/bookmark-plus.svg")),
|
||||
("braces", include_bytes!("../../../../assets/icons/braces.svg")),
|
||||
("brush", include_bytes!("../../../../assets/icons/brush.svg")),
|
||||
("brush-cleaning", include_bytes!("../../../../assets/icons/brush-cleaning.svg")),
|
||||
("camera", include_bytes!("../../../../assets/icons/camera.svg")),
|
||||
("check", include_bytes!("../../../../assets/icons/check.svg")),
|
||||
("check-circle-2", include_bytes!("../../../../assets/icons/check-circle-2.svg")),
|
||||
("chevron-down", include_bytes!("../../../../assets/icons/chevron-down.svg")),
|
||||
("chevron-left", include_bytes!("../../../../assets/icons/chevron-left.svg")),
|
||||
("chevron-right", include_bytes!("../../../../assets/icons/chevron-right.svg")),
|
||||
("chevron-up", include_bytes!("../../../../assets/icons/chevron-up.svg")),
|
||||
("chevrons-left", include_bytes!("../../../../assets/icons/chevrons-left.svg")),
|
||||
("chevrons-right", include_bytes!("../../../../assets/icons/chevrons-right.svg")),
|
||||
("circle", include_bytes!("../../../../assets/icons/circle.svg")),
|
||||
("circle-check", include_bytes!("../../../../assets/icons/circle-check.svg")),
|
||||
("circle-dashed", include_bytes!("../../../../assets/icons/circle-dashed.svg")),
|
||||
("circle-dot", include_bytes!("../../../../assets/icons/circle-dot.svg")),
|
||||
("circle-help", include_bytes!("../../../../assets/icons/circle-help.svg")),
|
||||
("circle-x", include_bytes!("../../../../assets/icons/circle-x.svg")),
|
||||
("clipboard-paste", include_bytes!("../../../../assets/icons/clipboard-paste.svg")),
|
||||
("clock", include_bytes!("../../../../assets/icons/clock.svg")),
|
||||
("clock-3", include_bytes!("../../../../assets/icons/clock-3.svg")),
|
||||
("cloud", include_bytes!("../../../../assets/icons/cloud.svg")),
|
||||
("cloud-upload", include_bytes!("../../../../assets/icons/cloud-upload.svg")),
|
||||
("code-xml", include_bytes!("../../../../assets/icons/code-xml.svg")),
|
||||
("columns-2", include_bytes!("../../../../assets/icons/columns-2.svg")),
|
||||
("columns-3", include_bytes!("../../../../assets/icons/columns-3.svg")),
|
||||
("compass", include_bytes!("../../../../assets/icons/compass.svg")),
|
||||
("contrast", include_bytes!("../../../../assets/icons/contrast.svg")),
|
||||
("copy", include_bytes!("../../../../assets/icons/copy.svg")),
|
||||
("copy-plus", include_bytes!("../../../../assets/icons/copy-plus.svg")),
|
||||
("crop", include_bytes!("../../../../assets/icons/crop.svg")),
|
||||
("droplet", include_bytes!("../../../../assets/icons/droplet.svg")),
|
||||
("ellipsis", include_bytes!("../../../../assets/icons/ellipsis.svg")),
|
||||
("ellipsis-vertical", include_bytes!("../../../../assets/icons/ellipsis-vertical.svg")),
|
||||
("eraser", include_bytes!("../../../../assets/icons/eraser.svg")),
|
||||
("external-link", include_bytes!("../../../../assets/icons/external-link.svg")),
|
||||
("eye", include_bytes!("../../../../assets/icons/eye.svg")),
|
||||
("eye-off", include_bytes!("../../../../assets/icons/eye-off.svg")),
|
||||
("file-check", include_bytes!("../../../../assets/icons/file-check.svg")),
|
||||
("file-down", include_bytes!("../../../../assets/icons/file-down.svg")),
|
||||
("file-input", include_bytes!("../../../../assets/icons/file-input.svg")),
|
||||
("file-lock-2", include_bytes!("../../../../assets/icons/file-lock-2.svg")),
|
||||
("file-minus", include_bytes!("../../../../assets/icons/file-minus.svg")),
|
||||
("file-output", include_bytes!("../../../../assets/icons/file-output.svg")),
|
||||
("file-pen-line", include_bytes!("../../../../assets/icons/file-pen-line.svg")),
|
||||
("file-plus", include_bytes!("../../../../assets/icons/file-plus.svg")),
|
||||
("file-plus-2", include_bytes!("../../../../assets/icons/file-plus-2.svg")),
|
||||
("file-scan", include_bytes!("../../../../assets/icons/file-scan.svg")),
|
||||
("file-search", include_bytes!("../../../../assets/icons/file-search.svg")),
|
||||
("file-symlink", include_bytes!("../../../../assets/icons/file-symlink.svg")),
|
||||
("file-text", include_bytes!("../../../../assets/icons/file-text.svg")),
|
||||
("file-x", include_bytes!("../../../../assets/icons/file-x.svg")),
|
||||
("files", include_bytes!("../../../../assets/icons/files.svg")),
|
||||
("film", include_bytes!("../../../../assets/icons/film.svg")),
|
||||
("filter", include_bytes!("../../../../assets/icons/filter.svg")),
|
||||
("flip-horizontal-2", include_bytes!("../../../../assets/icons/flip-horizontal-2.svg")),
|
||||
("flip-vertical-2", include_bytes!("../../../../assets/icons/flip-vertical-2.svg")),
|
||||
("folder", include_bytes!("../../../../assets/icons/folder.svg")),
|
||||
("folder-open", include_bytes!("../../../../assets/icons/folder-open.svg")),
|
||||
("folder-plus", include_bytes!("../../../../assets/icons/folder-plus.svg")),
|
||||
("gauge", include_bytes!("../../../../assets/icons/gauge.svg")),
|
||||
("git-compare", include_bytes!("../../../../assets/icons/git-compare.svg")),
|
||||
("globe", include_bytes!("../../../../assets/icons/globe.svg")),
|
||||
("grid-3x3", include_bytes!("../../../../assets/icons/grid-3x3.svg")),
|
||||
("hand", include_bytes!("../../../../assets/icons/hand.svg")),
|
||||
("hash", include_bytes!("../../../../assets/icons/hash.svg")),
|
||||
("heading", include_bytes!("../../../../assets/icons/heading.svg")),
|
||||
("highlighter", include_bytes!("../../../../assets/icons/highlighter.svg")),
|
||||
("house", include_bytes!("../../../../assets/icons/house.svg")),
|
||||
("image", include_bytes!("../../../../assets/icons/image.svg")),
|
||||
("image-plus", include_bytes!("../../../../assets/icons/image-plus.svg")),
|
||||
("info", include_bytes!("../../../../assets/icons/info.svg")),
|
||||
("italic", include_bytes!("../../../../assets/icons/italic.svg")),
|
||||
("languages", include_bytes!("../../../../assets/icons/languages.svg")),
|
||||
("lasso", include_bytes!("../../../../assets/icons/lasso.svg")),
|
||||
("layers", include_bytes!("../../../../assets/icons/layers.svg")),
|
||||
("layout-grid", include_bytes!("../../../../assets/icons/layout-grid.svg")),
|
||||
("link", include_bytes!("../../../../assets/icons/link.svg")),
|
||||
("link-2", include_bytes!("../../../../assets/icons/link-2.svg")),
|
||||
("list", include_bytes!("../../../../assets/icons/list.svg")),
|
||||
("list-checks", include_bytes!("../../../../assets/icons/list-checks.svg")),
|
||||
("list-ordered", include_bytes!("../../../../assets/icons/list-ordered.svg")),
|
||||
("lock", include_bytes!("../../../../assets/icons/lock.svg")),
|
||||
("lock-open", include_bytes!("../../../../assets/icons/lock-open.svg")),
|
||||
("maximize", include_bytes!("../../../../assets/icons/maximize.svg")),
|
||||
("maximize-2", include_bytes!("../../../../assets/icons/maximize-2.svg")),
|
||||
("message-circle-reply", include_bytes!("../../../../assets/icons/message-circle-reply.svg")),
|
||||
("message-square", include_bytes!("../../../../assets/icons/message-square.svg")),
|
||||
("message-square-plus", include_bytes!("../../../../assets/icons/message-square-plus.svg")),
|
||||
("message-square-quote", include_bytes!("../../../../assets/icons/message-square-quote.svg")),
|
||||
("message-square-text", include_bytes!("../../../../assets/icons/message-square-text.svg")),
|
||||
("messages-square", include_bytes!("../../../../assets/icons/messages-square.svg")),
|
||||
("mic", include_bytes!("../../../../assets/icons/mic.svg")),
|
||||
("minimize", include_bytes!("../../../../assets/icons/minimize.svg")),
|
||||
("minimize-2", include_bytes!("../../../../assets/icons/minimize-2.svg")),
|
||||
("minus", include_bytes!("../../../../assets/icons/minus.svg")),
|
||||
("monitor", include_bytes!("../../../../assets/icons/monitor.svg")),
|
||||
("moon", include_bytes!("../../../../assets/icons/moon.svg")),
|
||||
("mouse-pointer-2", include_bytes!("../../../../assets/icons/mouse-pointer-2.svg")),
|
||||
("move", include_bytes!("../../../../assets/icons/move.svg")),
|
||||
("move-right", include_bytes!("../../../../assets/icons/move-right.svg")),
|
||||
("navigation", include_bytes!("../../../../assets/icons/navigation.svg")),
|
||||
("paint-bucket", include_bytes!("../../../../assets/icons/paint-bucket.svg")),
|
||||
("palette", include_bytes!("../../../../assets/icons/palette.svg")),
|
||||
("panel-left", include_bytes!("../../../../assets/icons/panel-left.svg")),
|
||||
("panel-right", include_bytes!("../../../../assets/icons/panel-right.svg")),
|
||||
("panels-top-left", include_bytes!("../../../../assets/icons/panels-top-left.svg")),
|
||||
("paperclip", include_bytes!("../../../../assets/icons/paperclip.svg")),
|
||||
("pen-line", include_bytes!("../../../../assets/icons/pen-line.svg")),
|
||||
("pen-tool", include_bytes!("../../../../assets/icons/pen-tool.svg")),
|
||||
("pencil", include_bytes!("../../../../assets/icons/pencil.svg")),
|
||||
("pentagon", include_bytes!("../../../../assets/icons/pentagon.svg")),
|
||||
("pin", include_bytes!("../../../../assets/icons/pin.svg")),
|
||||
("pipette", include_bytes!("../../../../assets/icons/pipette.svg")),
|
||||
("plus", include_bytes!("../../../../assets/icons/plus.svg")),
|
||||
("presentation", include_bytes!("../../../../assets/icons/presentation.svg")),
|
||||
("printer", include_bytes!("../../../../assets/icons/printer.svg")),
|
||||
("rectangle-horizontal", include_bytes!("../../../../assets/icons/rectangle-horizontal.svg")),
|
||||
("redo-2", include_bytes!("../../../../assets/icons/redo-2.svg")),
|
||||
("replace", include_bytes!("../../../../assets/icons/replace.svg")),
|
||||
("reply", include_bytes!("../../../../assets/icons/reply.svg")),
|
||||
("rotate-ccw", include_bytes!("../../../../assets/icons/rotate-ccw.svg")),
|
||||
("rotate-cw", include_bytes!("../../../../assets/icons/rotate-cw.svg")),
|
||||
("rows-3", include_bytes!("../../../../assets/icons/rows-3.svg")),
|
||||
("ruler", include_bytes!("../../../../assets/icons/ruler.svg")),
|
||||
("save", include_bytes!("../../../../assets/icons/save.svg")),
|
||||
("scan", include_bytes!("../../../../assets/icons/scan.svg")),
|
||||
("scan-text", include_bytes!("../../../../assets/icons/scan-text.svg")),
|
||||
("scissors", include_bytes!("../../../../assets/icons/scissors.svg")),
|
||||
("search", include_bytes!("../../../../assets/icons/search.svg")),
|
||||
("send", include_bytes!("../../../../assets/icons/send.svg")),
|
||||
("settings", include_bytes!("../../../../assets/icons/settings.svg")),
|
||||
("settings-2", include_bytes!("../../../../assets/icons/settings-2.svg")),
|
||||
("share-2", include_bytes!("../../../../assets/icons/share-2.svg")),
|
||||
("shield-check", include_bytes!("../../../../assets/icons/shield-check.svg")),
|
||||
("signature", include_bytes!("../../../../assets/icons/signature.svg")),
|
||||
("sliders-horizontal", include_bytes!("../../../../assets/icons/sliders-horizontal.svg")),
|
||||
("sparkles", include_bytes!("../../../../assets/icons/sparkles.svg")),
|
||||
("spline", include_bytes!("../../../../assets/icons/spline.svg")),
|
||||
("square", include_bytes!("../../../../assets/icons/square.svg")),
|
||||
("square-dashed", include_bytes!("../../../../assets/icons/square-dashed.svg")),
|
||||
("square-dashed-mouse-pointer", include_bytes!("../../../../assets/icons/square-dashed-mouse-pointer.svg")),
|
||||
("squares-subtract", include_bytes!("../../../../assets/icons/squares-subtract.svg")),
|
||||
("stamp", include_bytes!("../../../../assets/icons/stamp.svg")),
|
||||
("star", include_bytes!("../../../../assets/icons/star.svg")),
|
||||
("sticky-note", include_bytes!("../../../../assets/icons/sticky-note.svg")),
|
||||
("strikethrough", include_bytes!("../../../../assets/icons/strikethrough.svg")),
|
||||
("sun", include_bytes!("../../../../assets/icons/sun.svg")),
|
||||
("swatch-book", include_bytes!("../../../../assets/icons/swatch-book.svg")),
|
||||
("tag", include_bytes!("../../../../assets/icons/tag.svg")),
|
||||
("text-cursor-input", include_bytes!("../../../../assets/icons/text-cursor-input.svg")),
|
||||
("text-select", include_bytes!("../../../../assets/icons/text-select.svg")),
|
||||
("thumbs-down", include_bytes!("../../../../assets/icons/thumbs-down.svg")),
|
||||
("thumbs-up", include_bytes!("../../../../assets/icons/thumbs-up.svg")),
|
||||
("trash", include_bytes!("../../../../assets/icons/trash.svg")),
|
||||
("trash-2", include_bytes!("../../../../assets/icons/trash-2.svg")),
|
||||
("triangle-alert", include_bytes!("../../../../assets/icons/triangle-alert.svg")),
|
||||
("type", include_bytes!("../../../../assets/icons/type.svg")),
|
||||
("underline", include_bytes!("../../../../assets/icons/underline.svg")),
|
||||
("undo-2", include_bytes!("../../../../assets/icons/undo-2.svg")),
|
||||
("user-round", include_bytes!("../../../../assets/icons/user-round.svg")),
|
||||
("wand-sparkles", include_bytes!("../../../../assets/icons/wand-sparkles.svg")),
|
||||
("wrench", include_bytes!("../../../../assets/icons/wrench.svg")),
|
||||
("move-horizontal", include_bytes!("../../../../assets/icons/move-horizontal.svg")),
|
||||
("pilcrow", include_bytes!("../../../../assets/icons/pilcrow.svg")),
|
||||
("a-large-small", include_bytes!("../../../../assets/icons/a-large-small.svg")),
|
||||
("subscript", include_bytes!("../../../../assets/icons/subscript.svg")),
|
||||
("superscript", include_bytes!("../../../../assets/icons/superscript.svg")),
|
||||
("x", include_bytes!("../../../../assets/icons/x.svg")),
|
||||
("zoom-in", include_bytes!("../../../../assets/icons/zoom-in.svg")),
|
||||
("zoom-out", include_bytes!("../../../../assets/icons/zoom-out.svg")),
|
||||
];
|
||||
@@ -1,200 +0,0 @@
|
||||
//! Vector icons: embedded Lucide SVGs, recoloured to white, rasterized by egui_extras at the exact
|
||||
//! on-screen pixel size, and tinted per use (PhotoCraft lesson: never use Unicode glyphs as icons).
|
||||
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use craft_ui::buttons::{ButtonVisuals, IconButton, IconButtonStyle};
|
||||
use craft_ui::icons::{SvgIconSet, SvgStyle};
|
||||
|
||||
use egui::{Color32, Rect, Response, Stroke, Vec2};
|
||||
|
||||
use crate::icon_data::ICONS;
|
||||
use crate::theme::{self, Tokens};
|
||||
|
||||
fn white_icons() -> &'static SvgIconSet {
|
||||
static MAP: OnceLock<SvgIconSet> = OnceLock::new();
|
||||
MAP.get_or_init(|| SvgIconSet::new(ICONS, SvgStyle { current_color: "#ffffff", stroke_width: Some("1.75") }, "bytes://icons/", "square"))
|
||||
}
|
||||
|
||||
pub fn exists(name: &str) -> bool {
|
||||
white_icons().contains(name)
|
||||
}
|
||||
|
||||
pub(crate) fn source(name: &str) -> egui::ImageSource<'static> {
|
||||
// PdfCraft caches an unknown name under the resolved fallback name.
|
||||
white_icons().source(white_icons().canonical_name(name).unwrap_or("square"))
|
||||
}
|
||||
|
||||
pub fn image(name: &str, size: f32, tint: Color32) -> egui::Image<'static> {
|
||||
egui::Image::new(source(name)).fit_to_exact_size(Vec2::splat(size)).tint(tint)
|
||||
}
|
||||
|
||||
pub fn paint(ui: &egui::Ui, rect: Rect, name: &str, size: f32, tint: Color32) {
|
||||
image(name, size, tint).paint_at(ui, Rect::from_center_size(rect.center(), Vec2::splat(size)));
|
||||
}
|
||||
|
||||
/// Square icon button: transparent until hovered; `selected` gets the accent treatment.
|
||||
/// `tooltip` is both its accessible name and its one tooltip.
|
||||
pub fn button(ui: &mut egui::Ui, name: &str, box_size: f32, selected: bool, tooltip: &str) -> Response {
|
||||
labeled_button(ui, name, box_size, selected, tooltip, tooltip)
|
||||
}
|
||||
|
||||
/// [`button`] whose tooltip says more than its accessible name (`label`). It shows that one
|
||||
/// tooltip, so callers add no `on_hover_text` of their own (#6548: two tooltips stacked).
|
||||
pub fn labeled_button(ui: &mut egui::Ui, name: &str, box_size: f32, selected: bool, label: &str, tooltip: &str) -> Response {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
// The shared button paints no fill of its own: the eased press wash below replaces it.
|
||||
let clear = |icon| ButtonVisuals { fill: Color32::TRANSPARENT, stroke: Stroke::NONE, icon };
|
||||
let style = IconButtonStyle {
|
||||
normal: clear(t.icon),
|
||||
hovered: clear(t.icon),
|
||||
pressed: Some(clear(t.icon)),
|
||||
selected: clear(t.accent_text),
|
||||
corner_radius: t.radius.into(),
|
||||
focus_stroke: Stroke::new(1.0, t.accent),
|
||||
};
|
||||
let label = if label.is_empty() { name } else { label };
|
||||
// The wash eases from the response, so reserve its place under the icon and focus ring.
|
||||
let wash = ui.painter().add(egui::Shape::Noop);
|
||||
let mut painted = None;
|
||||
let resp = IconButton::new(label, Vec2::splat(box_size), &style).selected(selected).show(ui, |_, rect, tint| painted = Some((rect, tint)));
|
||||
if let Some((rect, tint)) = painted {
|
||||
let press = theme::Press::track(ui, &resp);
|
||||
let mut shapes = Vec::with_capacity(2);
|
||||
let fill = press.wash_color(&t, selected);
|
||||
if fill.a() > 0 {
|
||||
shapes.push(egui::Shape::rect_filled(rect, t.radius, fill));
|
||||
}
|
||||
if selected {
|
||||
shapes.push(egui::Shape::rect_stroke(
|
||||
rect.shrink(0.5),
|
||||
t.radius,
|
||||
Stroke::new(1.0, t.accent.gamma_multiply(0.45)),
|
||||
egui::StrokeKind::Inside,
|
||||
));
|
||||
}
|
||||
ui.painter().set(wash, egui::Shape::Vec(shapes));
|
||||
// The glyph shrinks a little and drops a pixel while the pointer is down.
|
||||
let size = (box_size * 0.5).round() * (1.0 - 0.08 * press.down);
|
||||
paint(ui, rect.translate(press.offset()), name, size, tint);
|
||||
}
|
||||
let resp = theme::hand(resp);
|
||||
if tooltip.is_empty() { resp } else { resp.on_hover_text(tooltip) }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn every_catalog_icon_exists() {
|
||||
for g in pdfcraft_engine::catalog::TOOL_GROUPS {
|
||||
assert!(super::exists(g.icon), "missing icon {}", g.icon);
|
||||
for s in g.sections {
|
||||
for i in s.items {
|
||||
assert!(super::exists(i.icon), "missing icon {}", i.icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_command_icon_exists() {
|
||||
for c in pdfcraft_engine::commands::COMMANDS {
|
||||
assert!(super::exists(c.icon), "missing icon {} ({})", c.icon, c.id);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_catalog_preserves_existing_icons_and_fallback_uri() {
|
||||
assert_eq!(ICONS.len(), 191);
|
||||
assert!(exists("minimize-2"));
|
||||
for (name, original) in ICONS {
|
||||
let expected =
|
||||
String::from_utf8_lossy(original).replace("currentColor", "#ffffff").replace("stroke-width=\"2\"", "stroke-width=\"1.75\"");
|
||||
let egui::ImageSource::Bytes { uri, bytes } = source(name) else { panic!("expected SVG bytes") };
|
||||
assert_eq!(uri.as_ref(), format!("bytes://icons/{name}.svg"));
|
||||
assert_eq!(bytes.as_ref(), expected.as_bytes(), "{name}");
|
||||
}
|
||||
let egui::ImageSource::Bytes { uri, bytes } = source("missing-icon") else { panic!("expected SVG bytes") };
|
||||
let egui::ImageSource::Bytes { bytes: fallback, .. } = source("square") else { panic!("expected SVG bytes") };
|
||||
assert_eq!(uri.as_ref(), "bytes://icons/square.svg");
|
||||
assert_eq!(bytes.as_ref(), fallback.as_ref());
|
||||
assert!(!exists("missing-icon"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_button_preserves_pointer_responses() {
|
||||
// The shared button must respond like the original allocate-and-paint path in both
|
||||
// themes. Its painting differs on purpose (the eased press wash, the selected outline
|
||||
// and the sinking glyph); the keyboard-focus outline is covered in craft-ui.
|
||||
fn frame(
|
||||
ctx: &egui::Context,
|
||||
events: Vec<egui::Event>,
|
||||
selected: bool,
|
||||
enabled: bool,
|
||||
legacy: bool,
|
||||
) -> (egui::Response, Vec<egui::epaint::ClippedShape>) {
|
||||
let mut response = None;
|
||||
let mut output = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| {
|
||||
response = Some(
|
||||
ui.add_enabled_ui(enabled, |ui| {
|
||||
if legacy {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let (rect, response) = ui.allocate_exact_size(Vec2::splat(28.0), egui::Sense::click());
|
||||
if selected {
|
||||
ui.painter().rect_filled(rect, t.radius, t.accent_soft);
|
||||
} else if response.is_pointer_button_down_on() {
|
||||
ui.painter().rect_filled(rect, t.radius, t.pressed);
|
||||
} else if response.hovered() {
|
||||
ui.painter().rect_filled(rect, t.radius, t.hover);
|
||||
}
|
||||
let tint = if selected { t.accent_text } else { t.icon };
|
||||
paint(ui, rect, "square", (28.0_f32 * 0.5).round(), tint);
|
||||
response
|
||||
} else {
|
||||
button(ui, "square", 28.0, selected, "")
|
||||
}
|
||||
})
|
||||
.inner,
|
||||
);
|
||||
});
|
||||
output.textures_delta.clear();
|
||||
(response.unwrap(), output.shapes)
|
||||
}
|
||||
for theme in [crate::theme::ThemeKind::Dark, crate::theme::ThemeKind::Light] {
|
||||
for selected in [false, true] {
|
||||
for enabled in [false, true] {
|
||||
let old = egui::Context::default();
|
||||
let new = egui::Context::default();
|
||||
for ctx in [&old, &new] {
|
||||
crate::theme::apply(ctx, theme);
|
||||
egui_extras::install_image_loaders(ctx);
|
||||
}
|
||||
let mut center = egui::Pos2::ZERO;
|
||||
for step in 0..7 {
|
||||
let events = match step {
|
||||
2 => vec![egui::Event::PointerMoved(center)],
|
||||
3 | 4 => vec![egui::Event::PointerButton {
|
||||
pos: center,
|
||||
button: egui::PointerButton::Primary,
|
||||
pressed: step == 3,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
}],
|
||||
5 => vec![egui::Event::PointerMoved(egui::pos2(300.0, 200.0))],
|
||||
_ => vec![],
|
||||
};
|
||||
let (a, _) = frame(&old, events.clone(), selected, enabled, true);
|
||||
let (b, after) = frame(&new, events, selected, enabled, false);
|
||||
center = a.rect.center();
|
||||
assert_eq!(a.rect, b.rect);
|
||||
assert_eq!(
|
||||
(a.clicked(), a.hovered(), a.is_pointer_button_down_on()),
|
||||
(b.clicked(), b.hovered(), b.is_pointer_button_down_on())
|
||||
);
|
||||
assert!(!after.is_empty(), "{theme:?}, selected={selected}, enabled={enabled}, step={step}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//! The smallest window (#1913): at `MIN_WINDOW_SIZE` the mode bar folds the modes into a menu
|
||||
//! and keeps the command search reachable, instead of hiding them under the search field.
|
||||
//! The smallest window (#1913): at `MIN_WINDOW_SIZE` the mode bar keeps the menus, the modes and
|
||||
//! the command search reachable and inside the window, instead of hiding them under each other.
|
||||
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::Harness;
|
||||
@@ -17,30 +17,25 @@ fn harness(size: egui::Vec2) -> Harness<'static, PdfCraftApp> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn at_the_minimum_width_the_modes_fold_into_a_menu_and_search_stays() {
|
||||
let mut h = harness(egui::vec2(MIN_WINDOW_SIZE[0], MIN_WINDOW_SIZE[1]));
|
||||
assert!(h.query_by_role_and_label(Role::Button, "Convert").is_none(), "no room for the tabs");
|
||||
assert!(h.query_by_role_and_label(Role::Button, "Find tools and commands").is_some(), "command search is reachable");
|
||||
h.get_by_role_and_label(Role::Button, "All tools").click();
|
||||
h.run_steps(4);
|
||||
h.get_by_role_and_label(Role::Button, "E-Sign").click();
|
||||
h.run_steps(4);
|
||||
assert!(h.query_by_role_and_label(Role::Button, "E-Sign").is_some(), "the menu button is named after the mode");
|
||||
fn at_the_minimum_width_the_menus_the_modes_and_search_stay_reachable() {
|
||||
let h = harness(egui::vec2(MIN_WINDOW_SIZE[0], MIN_WINDOW_SIZE[1]));
|
||||
let window = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(MIN_WINDOW_SIZE[0], MIN_WINDOW_SIZE[1]));
|
||||
let search = h.get_by_label("Find tools and commands").rect();
|
||||
assert!(window.contains_rect(search), "command search is inside the window: {search:?}");
|
||||
// The strip shows the current mode whatever the room; the rest fit or fold into its overflow.
|
||||
let mode = h.get_by_label("All tools").rect();
|
||||
assert!(window.contains_rect(mode), "the current mode is inside the window: {mode:?}");
|
||||
assert!(!mode.intersects(search), "the mode strip and the search do not overlap: {mode:?} {search:?}");
|
||||
// The menu bar folds the titles that don't fit into "⋯", or all of them into one "Menu" when not
|
||||
// even the first fits (craft-menu's `MenuBarUi`). macOS's system font is wider, and at this width
|
||||
// the bar is the "Menu" button there; a real macOS window has the native menu bar instead.
|
||||
let menus = |label| h.query_by_role_and_label(Role::MenuItem, label).is_some();
|
||||
let folded = cfg!(target_os = "macos") && menus("Menu");
|
||||
assert!(menus("File") || folded, "main menu reachable");
|
||||
let menus = |label| h.query_by_role_and_label(Role::MenuItem, label);
|
||||
let bar = menus("File").or_else(|| if cfg!(target_os = "macos") { menus("Menu") } else { None });
|
||||
let bar = bar.expect("main menu reachable").rect();
|
||||
assert!(window.contains_rect(bar), "the menus are inside the window: {bar:?}");
|
||||
assert!(!bar.intersects(search), "the menus and the search do not overlap: {bar:?} {search:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wide_window_keeps_the_mode_tabs() {
|
||||
let h = harness(egui::vec2(1400.0, 900.0));
|
||||
for mode in ["All tools", "Edit", "Convert", "E-Sign"] {
|
||||
assert!(h.query_by_role_and_label(Role::Button, mode).is_some(), "{mode} tab");
|
||||
}
|
||||
}
|
||||
|
||||
fn fixture(n: usize) -> Vec<u8> {
|
||||
let mut objs: Vec<String> = vec!["<< /Type /Catalog /Pages 2 0 R >>".into()];
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
//! The title bar's theme button: a click cycles System, Light and Dark (a fresh install starts
|
||||
//! on System, #1248); a right-click opens the menu with the appearance settings.
|
||||
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
|
||||
fn harness() -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| {
|
||||
let mut app = PdfCraftApp::new();
|
||||
app.set_option("language", "en").unwrap();
|
||||
app
|
||||
});
|
||||
h.run_steps(6);
|
||||
h
|
||||
}
|
||||
|
||||
fn preference(h: &Harness<'static, PdfCraftApp>) -> String {
|
||||
format!("{:?}", h.state().theme_preference)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preferences_gear_is_right_of_theme_and_opens_preferences() {
|
||||
let mut h = harness();
|
||||
let theme = h.get_by_label("Display theme: Use system setting").rect();
|
||||
let gear = h.get_by_label("Preferences").rect();
|
||||
assert!(gear.left() >= theme.right());
|
||||
h.get_by_label("Preferences").click();
|
||||
h.run_steps(6);
|
||||
assert!(h.query_by_label("Appearance mode").is_some());
|
||||
assert!(h.query_by_label("Light theme").is_some());
|
||||
assert!(h.query_by_label("Dark theme").is_some());
|
||||
assert_eq!(preference(&h), "System");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_cycles_the_theme_and_a_right_click_opens_the_menu() {
|
||||
let mut h = harness();
|
||||
assert_eq!(preference(&h), "System", "a fresh install follows the desktop (#1248)");
|
||||
for (label, next) in
|
||||
[("Display theme: Use system setting", "Light"), ("Display theme: Light gray", "Dark"), ("Display theme: Dark gray", "System")]
|
||||
{
|
||||
h.get_by_label(label).click();
|
||||
h.run_steps(4);
|
||||
assert_eq!(preference(&h), next);
|
||||
}
|
||||
assert!(h.query_by_label("Appearance settings…").is_none(), "a plain click opens no menu");
|
||||
|
||||
h.get_by_label("Display theme: Use system setting").click_secondary();
|
||||
h.run_steps(4);
|
||||
h.get_by_label("Appearance settings…").click();
|
||||
h.run_steps(4);
|
||||
h.run_steps(10);
|
||||
assert!(h.query_by_label("Light theme").is_some(), "Preferences opens on Appearance");
|
||||
}
|
||||
Reference in New Issue
Block a user