mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-02 02:51:42 -06:00
67 lines
2.3 KiB
Rust
67 lines
2.3 KiB
Rust
//! Left tool panel (All tools + tool sub-panels, generated from the engine catalogue) and the
|
|
//! right-hand panels (Comments, Bookmarks, Pages, Fields, Layers, Attachments).
|
|
|
|
use egui::{Align, Align2, Color32, CornerRadius, Layout, Rect, Sense, Stroke, pos2, vec2};
|
|
use pdfcraft_engine::catalog::{self, Availability, TOOL_GROUPS, ToolGroup, ToolItem};
|
|
use pdfcraft_render::{DocInfo, FieldKind, OutlineItem};
|
|
|
|
use crate::theme::{self, Tokens};
|
|
use crate::{LeftPanel, PdfCraftApp, RightPanel, icons, widgets};
|
|
|
|
pub(super) mod all_tools_ui;
|
|
mod bookmarks;
|
|
pub(super) mod comments_panel;
|
|
mod edit;
|
|
pub(super) mod format_text_ui;
|
|
pub(super) mod organize_panel;
|
|
pub(super) mod page_selection_ui;
|
|
mod pages;
|
|
mod right;
|
|
pub(super) mod search_ui;
|
|
pub mod side_panels;
|
|
mod tools;
|
|
|
|
pub use bookmarks::BmAction;
|
|
pub(crate) use bookmarks::ellipsized_prefix;
|
|
pub use right::right_panel;
|
|
pub use tools::left_panel;
|
|
pub(crate) use tools::panel_header;
|
|
|
|
// ───────────────────────────────────────────────────────────────────────────── right panels
|
|
|
|
pub(crate) enum Nav {
|
|
Page(usize),
|
|
/// A bookmark's destination: its page and where on it.
|
|
Dest(usize, pdfcraft_render::DestView),
|
|
/// A bookmark's action that goes nowhere in this document, run as a link's is.
|
|
Action(pdfcraft_render::LinkTarget),
|
|
Flash(usize, [f32; 4]),
|
|
}
|
|
|
|
pub fn human_size(n: usize) -> String {
|
|
match n {
|
|
// A size that rounds to "1024.0 KB" reads as the next unit.
|
|
n if n as f64 / 1024.0 >= 1023.95 => format!("{:.1} MB", n as f64 / (1u64 << 20) as f64),
|
|
n if n >= 1 << 10 => format!("{:.1} KB", n as f64 / (1u64 << 10) as f64),
|
|
n => byte_count(n),
|
|
}
|
|
}
|
|
|
|
/// An exact size in bytes, with the count's own plural form.
|
|
pub fn byte_count(n: usize) -> String {
|
|
crate::i18n::trn(crate::i18n::current(), n as u64, "{n} byte", "{n} bytes")
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod human_size_tests {
|
|
use super::human_size;
|
|
|
|
#[test]
|
|
fn rounds_up_into_next_unit() {
|
|
assert_eq!(human_size(1_048_524), "1023.9 KB");
|
|
assert_eq!(human_size(1_048_525), "1.0 MB");
|
|
assert_eq!(human_size(1_048_575), "1.0 MB");
|
|
assert_eq!(human_size(1_048_576), "1.0 MB");
|
|
}
|
|
}
|