Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Feat/unify hotbar quick tools (Fixes #5890) (#5909)

Harsh Verma01ba3ac9d126
diff --git a/crates/ui-egui/src/app/prefs.rs b/crates/ui-egui/src/app/prefs.rs
index d3db335d8..08a20afb4 100644
--- a/crates/ui-egui/src/app/prefs.rs
+++ b/crates/ui-egui/src/app/prefs.rs
@@ -160,6 +160,9 @@ impl PdfCraftApp {
pub fn restore(&mut self, json: &str) {
let Ok(v) = serde_json::from_str::<serde_json::Value>(json) else { return };
if let Ok(mut bar) = serde_json::from_value::<crate::hotbar::Hotbar>(v["hotbar"].clone()) {
+ if v["hotbar"].get("placed").is_none() {
+ bar.adopt_legacy();
+ }
bar.normalize();
self.hotbar = bar;
}
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index 3879cd934..e5209fdfa 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -18,8 +18,8 @@ use crate::theme::{self, Tokens};
use crate::{PdfCraftApp, QuickTool, RightPanel, comments, icons, widgets};
mod area;
-pub(super) mod autoscroll;
-mod bars;
+pub(crate) mod autoscroll;
+pub(crate) mod bars;
mod cache;
pub(super) mod crop;
mod find;
@@ -4063,7 +4063,6 @@ fn apply_frame_requests(app: &mut PdfCraftApp, index: usize, ui: &mut egui::Ui,
// The page nearest the left edge, whose margin the bar sits in.
let page_left = app.views[index].screen_rects.iter().map(|(_, r)| r.left()).reduce(f32::min);
quick_bar(app, avail, page_left, ui);
- crate::hotbar::show(app, avail, ui.ctx());
}
if let Some((source, file, destination)) = remote_open {
app.open_remote_link(source, file, destination);
diff --git a/crates/ui-egui/src/canvas/bars.rs b/crates/ui-egui/src/canvas/bars.rs
index 5ea5e4a19..dd3fe8c49 100644
--- a/crates/ui-egui/src/canvas/bars.rs
+++ b/crates/ui-egui/src/canvas/bars.rs
@@ -1,7 +1,4 @@
-use super::{
- Color32, CornerRadius, DocInfo, DocView, Edit, PdfCraftApp, Pos2, QuickTool, Rect, Sense, SnapshotKind, Stroke, Tokens, comments, icons, theme,
- vec2,
-};
+use super::{Color32, CornerRadius, DocInfo, DocView, PdfCraftApp, Pos2, Rect, Sense, SnapshotKind, Stroke, Tokens, icons, vec2};
/// Whether `p` lies in the bottom-left quadrant of `area`, where the page size shows (#1855).
pub(super) fn in_size_hint_zone(area: Rect, p: Pos2) -> bool {
@@ -277,258 +274,23 @@ fn notice_bar(ui: &mut egui::Ui, t: &Tokens, icon: &str, icon_color: Color32, te
}
/// The bar's narrowest form: one 32 pt button, 6 pt margins and a 1 pt border each side.
-const QUICK_BAR_WIDTH: f32 = 46.0;
-const QUICK_BAR_EDGE: f32 = 14.0;
+pub(crate) const QUICK_BAR_WIDTH: f32 = 46.0;
+pub(crate) const QUICK_BAR_EDGE: f32 = 14.0;
/// How far from the side panel the quick-action bar stands, given the width of the margin between
/// the panel and the page and the bar's own width: centred in the margin when it holds the bar,
/// else 14 pt in (a page filling the width). With no page on screen the caller passes a margin of 0,
/// which is 14 pt too.
-fn quick_bar_offset(margin: f32, width: f32) -> f32 {
+pub(crate) fn quick_bar_offset(margin: f32, width: f32) -> f32 {
// shortcut: centred in at most 100 pt of margin, so a wide margin keeps the bar by the panel.
// `f32::min` returns the other operand for NaN, which would pass the fit check below.
let margin = if margin.is_nan() { 0.0 } else { margin.min(100.0) };
if margin >= width + 2.0 * 8.0 { (margin - width) / 2.0 } else { QUICK_BAR_EDGE }
}
-/// The floating quick-action bar in the margin between the side panel and the page.
+/// The unified quick-action bar and hotbar in the margin or docked to an edge.
pub(super) fn quick_bar(app: &mut PdfCraftApp, area: Rect, page_left: Option<f32>, ui: &mut egui::Ui) {
- let t = Tokens::get(ui.ctx());
- let mut offset = vec2(0.0, 0.0);
- if app.hotbar.full_side {
- match app.hotbar.dock.as_deref() {
- Some("left") => offset.x += app.hotbar.button_size + 14.0,
- Some("top") => offset.y += app.hotbar.button_size + 14.0,
- _ => {}
- }
- }
- let id = egui::Id::unique("quick-bar");
- // Last frame's bar: Fill & Sign's Text and Date tools add a wider row of controls to it.
- let width = ui.ctx().memory(|m| m.area_rect(id)).map_or(QUICK_BAR_WIDTH, |bar| bar.width().max(QUICK_BAR_WIDTH));
- // The margin starts past a hotbar docked on the left.
- let x = quick_bar_offset(page_left.map_or(0.0, |left| left - area.left() - offset.x), width);
- let pos = area.left_top() + vec2(x, QUICK_BAR_EDGE) + offset;
- egui::Area::new(id).order(egui::Order::Middle).fixed_pos(pos).show(ui.ctx(), |ui| {
- egui::Frame::NONE
- .fill(t.card)
- .stroke(Stroke::new(1.0, t.border))
- .corner_radius(CornerRadius::same(12))
- .shadow(egui::Shadow { offset: [0, 4], blur: 16, spread: 0, color: Color32::from_black_alpha(if t.dark() { 100 } else { 28 }) })
- .inner_margin(egui::Margin::same(6))
- .show(ui, |ui| {
- ui.spacing_mut().item_spacing.y = 2.0;
- ui.vertical(|ui| {
- if icons::button(ui, "mouse-pointer-2", 32.0, app.quick_tool == QuickTool::Select, tl!("Select (V)")).clicked() {
- app.quick_tool = QuickTool::Select;
- }
- if icons::button(ui, "hand", 32.0, app.quick_tool == QuickTool::Hand, tl!("Hand (H)")).clicked() {
- app.quick_tool = QuickTool::Hand;
- }
- // Comment ▸, Highlight ▸, Draw ▸ (Acrobat's comment toolbar groups). Clicking a
- // group selects its last-used tool; clicking it again opens the flyout.
- for g in 0..comments::GROUPS.len() {
- let current = app.comment_prefs.group_tool[g];
- let active = matches!(app.quick_tool, QuickTool::Comment(t) if t.group() == g);
- let resp = icons::button(ui, current.icon(), 32.0, active, tl!(current.label()));
- if comments::GROUPS[g].len() == 1 {
- if resp.clicked() {
- app.execute(current.command());
- }
- continue;
- }
- // A small corner triangle marks the flyout.
- let r = resp.rect;
- let tri = [r.right_bottom() + vec2(-4.0, -4.0), r.right_bottom() + vec2(-9.0, -4.0), r.right_bottom() + vec2(-4.0, -9.0)];
- ui.painter().add(egui::Shape::convex_polygon(tri.to_vec(), if active { t.accent } else { t.text_faint }, Stroke::NONE));
- let open = (resp.clicked() && active) || resp.secondary_clicked();
- if resp.clicked() && !active {
- app.execute(current.command());
- }
- egui::Popup::menu(&resp)
- .open_memory(open.then_some(egui::SetOpenCommand::Toggle))
- .align(egui::RectAlign::RIGHT_START)
- .gap(6.0)
- .show(|ui| {
- for tool in comments::GROUPS[g] {
- let on = app.quick_tool == QuickTool::Comment(*tool);
- let (row, click) = ui.allocate_exact_size(vec2(180.0, 28.0), Sense::click());
- let press = theme::Press::track(ui, &click);
- press.wash(ui, row, 4, on);
- let body = row.translate(press.offset());
- icons::paint(ui, Rect::from_min_size(body.min + vec2(8.0, 6.0), vec2(16.0, 16.0)), tool.icon(), 16.0, t.text);
- let reserve = if on { 28.0 } else { 8.0 };
- crate::widgets::paint_left(
- ui,
- body.left_center() + vec2(34.0, 0.0),
- tl!(tool.label()),
- theme::regular(13.0),
- t.text,
- (row.width() - 34.0 - reserve).max(0.0),
- );
- if on {
- icons::paint(
- ui,
- Rect::from_min_size(body.right_top() + vec2(-24.0, 7.0), vec2(14.0, 14.0)),
- "check",
- 14.0,
- t.accent,
- );
- }
- let click = theme::hand(click);
- let info = tl!(tool.label()).to_string();
- click.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, on, info.clone()));
- if click.clicked() {
- app.execute(tool.command());
- ui.close();
- }
- }
- });
- }
- // Edit text & images, while the Edit workspace is open (Acrobat's Edit toolbar)
- // or the tool is in use.
- if app.mode == crate::Mode::Edit || app.quick_tool == QuickTool::EditText {
- let on = app.quick_tool == QuickTool::EditText;
- if icons::button(ui, "text-cursor-input", 32.0, on, tl!("Edit text & images")).clicked() {
- if on {
- app.put_down_edit_text();
- } else {
- app.quick_tool = QuickTool::EditText;
- }
- }
- }
- // Fill & Sign ▸ (text, marks, date, signature).
- let current_fill = match app.quick_tool {
- QuickTool::Fill(f) => Some(f),
- _ => None,
- };
- let shown = current_fill.unwrap_or(crate::fill_sign::FillTool::Text);
- let resp = icons::button(
- ui,
- if current_fill.is_some() { shown.icon() } else { "pen-line" },
- 32.0,
- current_fill.is_some(),
- tl!("Fill & Sign"),
- );
- let r = resp.rect;
- let tri = [r.right_bottom() + vec2(-4.0, -4.0), r.right_bottom() + vec2(-9.0, -4.0), r.right_bottom() + vec2(-4.0, -9.0)];
- ui.painter().add(egui::Shape::convex_polygon(
- tri.to_vec(),
- if current_fill.is_some() { t.accent } else { t.text_faint },
- Stroke::NONE,
- ));
- if resp.clicked() && current_fill.is_none() {
- app.execute(shown.command());
- }
- let open = (resp.clicked() && current_fill.is_some()) || resp.secondary_clicked();
- egui::Popup::menu(&resp)
- .open_memory(open.then_some(egui::SetOpenCommand::Toggle))
- .align(egui::RectAlign::RIGHT_START)
- .gap(6.0)
- .show(|ui| {
- for tool in crate::fill_sign::FILL_TOOLS {
- if matches!(tool, crate::fill_sign::FillTool::Signature | crate::fill_sign::FillTool::Initials) {
- continue;
- }
- let on = current_fill == Some(tool);
- let (row, click) = ui.allocate_exact_size(vec2(180.0, 28.0), Sense::click());
- let press = theme::Press::track(ui, &click);
- press.wash(ui, row, 4, on);
- let body = row.translate(press.offset());
- icons::paint(ui, Rect::from_min_size(body.min + vec2(8.0, 6.0), vec2(16.0, 16.0)), tool.icon(), 16.0, t.text);
- let reserve = if on { 28.0 } else { 8.0 };
- crate::widgets::paint_left(
- ui,
- body.left_center() + vec2(34.0, 0.0),
- tl!(tool.label()),
- theme::regular(13.0),
- t.text,
- (row.width() - 34.0 - reserve).max(0.0),
- );
- if on {
- icons::paint(
- ui,
- Rect::from_min_size(body.right_top() + vec2(-24.0, 7.0), vec2(14.0, 14.0)),
- "check",
- 14.0,
- t.accent,
- );
- }
- let click = theme::hand(click);
- let info = tl!(tool.label()).to_string();
- click.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, on, info.clone()));
- if click.clicked() {
- app.execute(tool.command());
- ui.close();
- }
- }
- ui.separator();
- if let Some(command) = crate::fill_sign::signature_entries(ui, app, &t) {
- app.execute(command);
- ui.close();
- }
- });
- if matches!(current_fill, Some(crate::fill_sign::FillTool::Text | crate::fill_sign::FillTool::Date)) {
- ui.label(tl!("Font size:"));
- let size = ui.add(
- egui::DragValue::new(&mut app.fill_text_size)
- .range(crate::fill_sign::MIN_TEXT_SIZE..=crate::fill_sign::MAX_TEXT_SIZE)
- .speed(0.25)
- .suffix(" pt"),
- );
- // #1274: the size also applies to the Fill & Sign text that is selected,
- // once per change (a typed value, or the end of a drag), so a drag adds
- // one undo step and not one per frame.
- if ((size.changed() && !size.dragged()) || size.drag_stopped())
- && let Some((index, id)) = app.active_ids()
- && let Some((page, annotation)) = app.views.get(index).and_then(|view| view.comments.selected)
- && app.session.get(id).is_some_and(|doc| {
- doc.allows_annotation()
- && doc
- .info
- .annotations
- .iter()
- .any(|a| a.page == page && a.index == annotation && a.fill_sign && a.subtype == "FreeText" && !a.locked)
- })
- {
- app.apply_edit(Edit::FontSizeAnnotation { page, index: annotation, size: app.fill_text_size });
- }
- }
- if matches!(current_fill, Some(crate::fill_sign::FillTool::Text | crate::fill_sign::FillTool::Date)) {
- ui.menu_button(tl!("Colour"), |ui| {
- if let Some(color) = comments::swatch_grid(ui, Some(app.fill_text_color)) {
- app.fill_text_color = color;
- ui.close();
- }
- });
- }
- if let QuickTool::Comment(tool) = app.quick_tool {
- let (r, _) = ui.allocate_exact_size(vec2(32.0, 9.0), Sense::hover());
- ui.painter().hline(r.x_range().shrink(6.0), r.center().y, Stroke::new(1.0, t.divider));
- if let Some(color) = comments::quick_bar_controls(ui, tool, &mut app.comment_prefs)
- && let Some((index, id)) = app.active_ids()
- && let Some((page, annotation)) = app.views.get(index).and_then(|view| view.comments.selected)
- && app.session.get(id).is_some_and(|doc| {
- doc.allows_annotation()
- && doc
- .info
- .annotations
- .iter()
- .any(|a| a.page == page && a.index == annotation && !a.is_reply() && comments::made_by(a, tool))
- })
- {
- app.apply_edit(Edit::StyleAnnotation {
- page,
- index: annotation,
- color: Some(color),
- opacity: None,
- width: None,
- endings: None,
- });
- }
- }
- });
- });
- });
+ crate::hotbar::show(app, area, page_left, ui);
}
#[cfg(test)]
diff --git a/crates/ui-egui/src/dialogs/preferences.rs b/crates/ui-egui/src/dialogs/preferences.rs
index 38cce3274..9e3182e41 100644
--- a/crates/ui-egui/src/dialogs/preferences.rs
+++ b/crates/ui-egui/src/dialogs/preferences.rs
@@ -22,14 +22,12 @@ pub(crate) const PREFERENCES_MIN_SCROLL: f32 = 60.0;
///
/// Draws a rounded container with options inside. The active option is highlighted
/// with the accent colour. Emits AccessKit RadioButton widget info with the option's label.
-#[expect(dead_code, reason = "convenience helpers for non-searched segmented pill controls")]
pub fn segmented_pill_choice<T: PartialEq + Copy>(ui: &mut egui::Ui, t: &Tokens, current: &mut T, options: &[(T, &str)]) -> bool {
let with_a11y: Vec<(T, &str, &str)> = options.iter().map(|&(v, l)| (v, l, l)).collect();
segmented_pill_choice_a11y(ui, t, current, &with_a11y)
}
/// A segmented pill selection bar with separate accessibility labels.
-#[expect(dead_code, reason = "convenience helpers for non-searched segmented pill controls")]
pub fn segmented_pill_choice_a11y<T: PartialEq + Copy>(ui: &mut egui::Ui, t: &Tokens, current: &mut T, options: &[(T, &str, &str)]) -> bool {
segmented_pill_choice_a11y_query(ui, t, current, options, "").0
}
diff --git a/crates/ui-egui/src/hotbar.rs b/crates/ui-egui/src/hotbar.rs
index f6a0c14c7..c66b7e30b 100644
--- a/crates/ui-egui/src/hotbar.rs
+++ b/crates/ui-egui/src/hotbar.rs
@@ -1,9 +1,10 @@
-//! A movable, persistent set of shortcuts to the shared command registry.
-use egui::{Rect, Sense, vec2};
+//! A movable, persistent set of shortcuts to the shared command registry and core document tools.
+use egui::{Color32, CornerRadius, Rect, Sense, Stroke, vec2};
+use pdfcraft_engine::Edit;
use pdfcraft_engine::commands::{COMMANDS, command};
use serde::{Deserialize, Serialize};
-use crate::{PdfCraftApp, icons, theme::Tokens};
+use crate::{PdfCraftApp, QuickTool, comments, icons, theme, theme::Tokens};
/// Persistent state and UI state for the customizable document hotbar.
#[derive(Clone, Debug, Serialize, Deserialize)]
@@ -16,6 +17,8 @@ pub(crate) struct Hotbar {
pub button_size: f32,
pub dock: Option<String>,
pub full_side: bool,
+ #[serde(default)]
+ pub placed: bool,
#[serde(skip)]
search: String,
#[serde(skip)]
@@ -23,15 +26,16 @@ pub(crate) struct Hotbar {
}
impl Default for Hotbar {
- /// Create a default empty horizontal floating hotbar.
+ /// Create a default vertical floating hotbar positioned in the document margin.
fn default() -> Self {
Self {
tools: Vec::new(),
- position: [0.5, 0.0],
- vertical: false,
+ position: [0.0, 0.0],
+ vertical: true,
button_size: 32.0,
dock: None,
full_side: false,
+ placed: false,
search: String::new(),
picker_open: false,
}
@@ -51,6 +55,24 @@ impl Hotbar {
for coordinate in &mut self.position {
*coordinate = if coordinate.is_finite() { coordinate.clamp(0.0, 1.0) } else { 0.5 };
}
+ if self.dock.is_some() || self.position != [0.0, 0.0] {
+ self.placed = true;
+ }
+ }
+
+ /// Adopt preferences saved before the hotbar absorbed the quick-action bar (#5890), which have
+ /// no `placed` key. A bar left at that release's default (floating, horizontal, top centre)
+ /// moves to the new default in the left margin; any other spot is one the user chose, so it
+ /// is kept, including the top-left corner.
+ pub fn adopt_legacy(&mut self) {
+ if self.dock.is_none() && !self.vertical && self.position == [0.5, 0.0] {
+ self.position = [0.0, 0.0];
+ self.vertical = true;
+ self.full_side = false;
+ self.placed = false;
+ } else {
+ self.placed = true;
+ }
}
/// Parse and validate a comma-separated list of command identifiers for the hotbar.
@@ -68,6 +90,7 @@ impl Hotbar {
pub fn place(&mut self, side: &str) -> Result<(), String> {
if side == "float" {
self.dock = None;
+ self.placed = true;
return Ok(());
}
let (position, vertical) = match side {
@@ -80,12 +103,13 @@ impl Hotbar {
self.dock = Some(side.to_owned());
self.position = position;
self.vertical = vertical;
+ self.placed = true;
Ok(())
}
}
/// Render the hotbar settings gear button and open the tool picker when clicked.
-fn settings_button(ui: &mut egui::Ui, cell: f32, picker_open: &mut bool) {
+fn settings_button(ui: &mut egui::Ui, cell: f32, picker_open: &mut bool) -> bool {
let settings = ui
.push_id("hotbar-settings", |ui| {
icons::button(ui, "settings", cell, false, tl!("Hotbar settings")).on_hover_text(tl!("Hotbar settings / add tools"))
@@ -93,6 +117,25 @@ fn settings_button(ui: &mut egui::Ui, cell: f32, picker_open: &mut bool) {
.inner;
if settings.clicked() {
*picker_open = true;
+ true
+ } else {
+ false
+ }
+}
+
+/// Determine where flyout popup menus should open from a toolbar button based on docking and layout.
+fn popup_align_for(dock: Option<&str>, vertical: bool) -> egui::RectAlign {
+ match dock {
+ Some("right") => egui::RectAlign::LEFT_START,
+ Some("bottom") => egui::RectAlign::TOP_START,
+ Some("top") => egui::RectAlign::BOTTOM_START,
+ _ => {
+ if vertical {
+ egui::RectAlign::RIGHT_START
+ } else {
+ egui::RectAlign::BOTTOM_START
+ }
+ }
}
}
@@ -103,7 +146,7 @@ fn matches_search(spec: &pdfcraft_engine::commands::CommandSpec, query: &str) ->
tl!(spec.label).to_lowercase().contains(&search) || spec.label.to_lowercase().contains(&search) || spec.id.to_lowercase().contains(&search)
}
-/// Render the configured tool shortcut buttons and their removal context menus.
+/// Render the configured custom tool shortcut buttons and their removal context menus.
fn tool_buttons(ui: &mut egui::Ui, app: &PdfCraftApp, tools: &[String], cell: f32, run: &mut Option<&'static str>, remove: &mut Option<usize>) {
for (index, id) in tools.iter().enumerate() {
let Some(spec) = command(id) else { continue };
@@ -121,30 +164,279 @@ fn tool_buttons(ui: &mut egui::Ui, app: &PdfCraftApp, tools: &[String], cell: f3
}
}
-/// Draw the floating or side-docked hotbar and its tool picker window inside `area`.
-pub(crate) fn show(app: &mut PdfCraftApp, area: Rect, ctx: &egui::Context) {
+/// Render core quick tools: Select, Hand, Comment groups, Edit text, and Fill & Sign.
+fn core_tool_buttons(ui: &mut egui::Ui, app: &mut PdfCraftApp, cell: f32, popup_align: egui::RectAlign, t: &Tokens) {
+ if icons::button(ui, "mouse-pointer-2", cell, app.quick_tool == QuickTool::Select, tl!("Select (V)")).clicked() {
+ app.quick_tool = QuickTool::Select;
+ }
+ if icons::button(ui, "hand", cell, app.quick_tool == QuickTool::Hand, tl!("Hand (H)")).clicked() {
+ app.quick_tool = QuickTool::Hand;
+ }
+ // Comment ▸, Highlight ▸, Draw ▸ (Acrobat's comment toolbar groups). Clicking a
+ // group selects its last-used tool; clicking it again opens the flyout.
+ for g in 0..comments::GROUPS.len() {
+ let current = app.comment_prefs.group_tool[g];
+ let active = matches!(app.quick_tool, QuickTool::Comment(t) if t.group() == g);
+ let resp = icons::button(ui, current.icon(), cell, active, tl!(current.label()));
+ if comments::GROUPS[g].len() == 1 {
+ if resp.clicked() {
+ app.execute(current.command());
+ }
+ continue;
+ }
+ // A small corner triangle marks the flyout.
+ let r = resp.rect;
+ let tri = [r.right_bottom() + vec2(-4.0, -4.0), r.right_bottom() + vec2(-9.0, -4.0), r.right_bottom() + vec2(-4.0, -9.0)];
+ ui.painter().add(egui::Shape::convex_polygon(tri.to_vec(), if active { t.accent } else { t.text_faint }, Stroke::NONE));
+ let open = (resp.clicked() && active) || resp.secondary_clicked();
+ if resp.clicked() && !active {
+ app.execute(current.command());
+ }
+ egui::Popup::menu(&resp).open_memory(open.then_some(egui::SetOpenCommand::Toggle)).align(popup_align).gap(6.0).show(|ui| {
+ for tool in comments::GROUPS[g] {
+ let on = app.quick_tool == QuickTool::Comment(*tool);
+ let (row, click) = ui.allocate_exact_size(vec2(180.0, 28.0), Sense::click());
+ let press = theme::Press::track(ui, &click);
+ press.wash(ui, row, 4, on);
+ let body = row.translate(press.offset());
+ icons::paint(ui, Rect::from_min_size(body.min + vec2(8.0, 6.0), vec2(16.0, 16.0)), tool.icon(), 16.0, t.text);
+ let reserve = if on { 28.0 } else { 8.0 };
+ crate::widgets::paint_left(
+ ui,
+ body.left_center() + vec2(34.0, 0.0),
+ tl!(tool.label()),
+ theme::regular(13.0),
+ t.text,
+ (row.width() - 34.0 - reserve).max(0.0),
+ );
+ if on {
+ icons::paint(ui, Rect::from_min_size(body.right_top() + vec2(-24.0, 7.0), vec2(14.0, 14.0)), "check", 14.0, t.accent);
+ }
+ let click = theme::hand(click);
+ let info = tl!(tool.label()).to_string();
+ click.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, on, info.clone()));
+ if click.clicked() {
+ app.execute(tool.command());
+ ui.close();
+ }
+ }
+ });
+ }
+ // Edit text & images, while the Edit workspace is open (Acrobat's Edit toolbar)
+ // or the tool is in use.
+ if app.mode == crate::Mode::Edit || app.quick_tool == QuickTool::EditText {
+ let on = app.quick_tool == QuickTool::EditText;
+ if icons::button(ui, "text-cursor-input", cell, on, tl!("Edit text & images")).clicked() {
+ if on {
+ app.put_down_edit_text();
+ } else {
+ app.quick_tool = QuickTool::EditText;
+ }
+ }
+ }
+ // Fill & Sign ▸ (text, marks, date, signature).
+ let current_fill = match app.quick_tool {
+ QuickTool::Fill(f) => Some(f),
+ _ => None,
+ };
+ let shown = current_fill.unwrap_or(crate::fill_sign::FillTool::Text);
+ let resp = icons::button(ui, if current_fill.is_some() { shown.icon() } else { "pen-line" }, cell, current_fill.is_some(), tl!("Fill & Sign"));
+ let r = resp.rect;
+ let tri = [r.right_bottom() + vec2(-4.0, -4.0), r.right_bottom() + vec2(-9.0, -4.0), r.right_bottom() + vec2(-4.0, -9.0)];
+ ui.painter().add(egui::Shape::convex_polygon(tri.to_vec(), if current_fill.is_some() { t.accent } else { t.text_faint }, Stroke::NONE));
+ if resp.clicked() && current_fill.is_none() {
+ app.execute(shown.command());
+ }
+ let open = (resp.clicked() && current_fill.is_some()) || resp.secondary_clicked();
+ egui::Popup::menu(&resp).open_memory(open.then_some(egui::SetOpenCommand::Toggle)).align(popup_align).gap(6.0).show(|ui| {
+ for tool in crate::fill_sign::FILL_TOOLS {
+ if matches!(tool, crate::fill_sign::FillTool::Signature | crate::fill_sign::FillTool::Initials) {
+ continue;
+ }
+ let on = current_fill == Some(tool);
+ let (row, click) = ui.allocate_exact_size(vec2(180.0, 28.0), Sense::click());
+ let press = theme::Press::track(ui, &click);
+ press.wash(ui, row, 4, on);
+ let body = row.translate(press.offset());
+ icons::paint(ui, Rect::from_min_size(body.min + vec2(8.0, 6.0), vec2(16.0, 16.0)), tool.icon(), 16.0, t.text);
+ let reserve = if on { 28.0 } else { 8.0 };
+ crate::widgets::paint_left(
+ ui,
+ body.left_center() + vec2(34.0, 0.0),
+ tl!(tool.label()),
+ theme::regular(13.0),
+ t.text,
+ (row.width() - 34.0 - reserve).max(0.0),
+ );
+ if on {
+ icons::paint(ui, Rect::from_min_size(body.right_top() + vec2(-24.0, 7.0), vec2(14.0, 14.0)), "check", 14.0, t.accent);
+ }
+ let click = theme::hand(click);
+ let info = tl!(tool.label()).to_string();
+ click.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, on, info.clone()));
+ if click.clicked() {
+ app.execute(tool.command());
+ ui.close();
+ }
+ }
+ ui.separator();
+ if let Some(command) = crate::fill_sign::signature_entries(ui, app, t) {
+ app.execute(command);
+ ui.close();
+ }
+ });
+}
+
+/// Extra controls rendered below/beside the buttons when a comment or fill tool is active.
+fn active_tool_controls(ui: &mut egui::Ui, app: &mut PdfCraftApp, t: &Tokens, vertical: bool) {
+ let current_fill = match app.quick_tool {
+ QuickTool::Fill(f) => Some(f),
+ _ => None,
+ };
+ if matches!(current_fill, Some(crate::fill_sign::FillTool::Text | crate::fill_sign::FillTool::Date)) {
+ if vertical {
+ ui.label(tl!("Font size:"));
+ }
+ let size = ui.add(
+ egui::DragValue::new(&mut app.fill_text_size)
+ .range(crate::fill_sign::MIN_TEXT_SIZE..=crate::fill_sign::MAX_TEXT_SIZE)
+ .speed(0.25)
+ .suffix(" pt"),
+ );
+ if ((size.changed() && !size.dragged()) || size.drag_stopped())
+ && let Some((index, id)) = app.active_ids()
+ && let Some((page, annotation)) = app.views.get(index).and_then(|view| view.comments.selected)
+ && app.session.get(id).is_some_and(|doc| {
+ doc.allows_annotation()
+ && doc
+ .info
+ .annotations
+ .iter()
+ .any(|a| a.page == page && a.index == annotation && a.fill_sign && a.subtype == "FreeText" && !a.locked)
+ })
+ {
+ app.apply_edit(Edit::FontSizeAnnotation { page, index: annotation, size: app.fill_text_size });
+ }
+ ui.menu_button(tl!("Colour"), |ui| {
+ if let Some(color) = comments::swatch_grid(ui, Some(app.fill_text_color)) {
+ app.fill_text_color = color;
+ ui.close();
+ }
+ });
+ }
+ if let QuickTool::Comment(tool) = app.quick_tool {
+ let (r, _) = if vertical {
+ ui.allocate_exact_size(vec2(crate::canvas::bars::QUICK_BAR_WIDTH, 9.0), Sense::hover())
+ } else {
+ ui.allocate_exact_size(vec2(9.0, crate::canvas::bars::QUICK_BAR_WIDTH), Sense::hover())
+ };
+ if vertical {
+ ui.painter().hline(r.x_range().shrink(6.0), r.center().y, Stroke::new(1.0, t.divider));
+ } else {
+ ui.painter().vline(r.center().x, r.y_range().shrink(6.0), Stroke::new(1.0, t.divider));
+ }
+ if let Some(color) = comments::quick_bar_controls(ui, tool, &mut app.comment_prefs)
+ && let Some((index, id)) = app.active_ids()
+ && let Some((page, annotation)) = app.views.get(index).and_then(|view| view.comments.selected)
+ && app.session.get(id).is_some_and(|doc| {
+ doc.allows_annotation()
+ && doc
+ .info
+ .annotations
+ .iter()
+ .any(|a| a.page == page && a.index == annotation && !a.is_reply() && !a.locked && comments::made_by(a, tool))
+ })
+ {
+ app.apply_edit(Edit::StyleAnnotation { page, index: annotation, color: Some(color), opacity: None, width: None, endings: None });
+ }
+ }
+}
+
+/// Render a modern iOS-style pill toggle switch.
+fn toggle_switch(ui: &mut egui::Ui, on: &mut bool, label: &str, t: &Tokens) -> egui::Response {
+ let width = 34.0;
+ let height = 18.0;
+ let (rect, mut response) = ui.allocate_exact_size(vec2(width, height), Sense::click());
+ if response.clicked() {
+ *on = !*on;
+ response.mark_changed();
+ }
+ response.widget_info(|| egui::WidgetInfo::selected(egui::Role::Switch, ui.is_enabled(), *on, label));
+
+ if ui.is_rect_visible(rect) {
+ let radius = height / 2.0;
+ let bg_color = if *on { t.accent } else { t.border };
+ ui.painter().rect(rect, CornerRadius::same(radius as u8), bg_color, Stroke::NONE, egui::StrokeKind::Inside);
+ let circle_radius = radius - 2.5;
+ let circle_x = if *on { rect.max.x - radius } else { rect.min.x + radius };
+ ui.painter().circle_filled(egui::pos2(circle_x, rect.center().y), circle_radius, Color32::WHITE);
+ }
+ response
+}
+
+/// Render the dock placement choice: [ Float | Left | Right | Top | Bottom ], scrolling sideways
+/// when the picker is narrower than the row.
+fn segmented_dock_picker(ui: &mut egui::Ui, bar: &mut Hotbar, t: &Tokens) {
+ let options = [
+ (None, tl!("Float")),
+ (Some("left"), tl!("Left")),
+ (Some("right"), tl!("Right")),
+ (Some("top"), tl!("Top")),
+ (Some("bottom"), tl!("Bottom")),
+ ];
+ let mut side = options.iter().map(|(side, _)| *side).find(|side| *side == bar.dock.as_deref()).flatten();
+ let changed = egui::ScrollArea::horizontal()
+ .id_salt("hotbar-dock")
+ .auto_shrink([false, true])
+ .show(ui, |ui| crate::dialogs::preferences::segmented_pill_choice(ui, t, &mut side, &options))
+ .inner;
+ if changed {
+ // `place` accepts every side listed above.
+ let _ = bar.place(side.unwrap_or("float"));
+ }
+}
+
+/// Draw the unified floating or side-docked toolbar, combining quick actions, core tools, and custom shortcuts.
+pub(crate) fn show(app: &mut PdfCraftApp, area: Rect, page_left: Option<f32>, ui: &mut egui::Ui) {
+ let ctx = ui.ctx().clone();
let mut bar = std::mem::take(&mut app.hotbar);
- let t = Tokens::get(ctx);
- let id = egui::Id::unique("custom-hotbar");
+ bar.normalize();
+ let t = Tokens::get(&ctx);
+ let id = egui::Id::unique("quick-bar");
let full_side = bar.full_side && bar.dock.is_some();
let bounds = if full_side { area } else { area.shrink(10.0) };
if let Some(side) = bar.dock.clone() {
let _ = bar.place(&side);
}
let cell = bar.button_size;
- let mut size = ctx.data_mut(|data| data.get_temp::<egui::Vec2>(id)).unwrap_or(vec2(90.0, 44.0));
+ let popup_align = popup_align_for(bar.dock.as_deref(), bar.vertical);
+ let mut size = ctx.data_mut(|data| data.get_temp::<egui::Vec2>(id)).unwrap_or(vec2(crate::canvas::bars::QUICK_BAR_WIDTH, 220.0));
if full_side {
size = if bar.vertical { vec2(cell + 12.0, bounds.height()) } else { vec2(bounds.width(), cell + 12.0) };
}
let travel = (bounds.size() - size).max(vec2(0.0, 0.0));
- let pos = bounds.min + vec2(travel.x * bar.position[0], travel.y * bar.position[1]);
+ let default_x = crate::canvas::bars::quick_bar_offset(page_left.map_or(0.0, |left| left - area.left()), size.x);
+ let pos = if full_side {
+ bounds.min + vec2(travel.x * bar.position[0], travel.y * bar.position[1])
+ } else if bar.dock.is_none() && !bar.placed {
+ area.left_top() + vec2(default_x, crate::canvas::bars::QUICK_BAR_EDGE)
+ } else {
+ bounds.min + vec2(travel.x * bar.position[0], travel.y * bar.position[1])
+ };
let mut run = None;
+ let was_picker_open = bar.picker_open;
let mut picker_open = bar.picker_open;
- let shown = egui::Area::new(id).order(egui::Order::Middle).fixed_pos(pos).constrain_to(bounds).show(ctx, |ui| {
+ let mut settings_clicked = false;
+ let shown = egui::Area::new(id).order(egui::Order::Middle).fixed_pos(pos).constrain_to(bounds).show(&ctx, |ui| {
let frame = if full_side {
egui::Frame::NONE.fill(t.chrome).corner_radius(egui::CornerRadius::ZERO).inner_margin(6)
} else {
- egui::Frame::new().fill(t.card).stroke(egui::Stroke::new(1.0, t.border)).corner_radius(10).inner_margin(6)
+ egui::Frame::new()
+ .fill(t.card)
+ .stroke(egui::Stroke::new(1.0, t.border))
+ .corner_radius(CornerRadius::same(12))
+ .shadow(egui::Shadow { offset: [0, 4], blur: 16, spread: 0, color: Color32::from_black_alpha(if t.dark() { 100 } else { 28 }) })
+ .inner_margin(6)
};
let frame_resp = frame.show(ui, |ui| {
if full_side {
@@ -160,23 +452,33 @@ pub(crate) fn show(app: &mut PdfCraftApp, area: Rect, ctx: &egui::Context) {
if full_side {
if bar.vertical {
ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
- settings_button(ui, cell, &mut picker_open);
+ settings_clicked |= settings_button(ui, cell, &mut picker_open);
ui.add_space(4.0);
let remaining = ui.available_height().max(cell);
- egui::ScrollArea::vertical().max_width(cell).max_height(remaining).show(ui, |ui| {
+ egui::ScrollArea::vertical().max_height(remaining).show(ui, |ui| {
ui.with_layout(egui::Layout::top_down(egui::Align::Center), |ui| {
- tool_buttons(ui, app, &bar.tools, cell, &mut run, &mut remove);
+ core_tool_buttons(ui, app, cell, popup_align, &t);
+ active_tool_controls(ui, app, &t, true);
+ if !bar.tools.is_empty() {
+ ui.separator();
+ tool_buttons(ui, app, &bar.tools, cell, &mut run, &mut remove);
+ }
});
});
});
} else {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
- settings_button(ui, cell, &mut picker_open);
+ settings_clicked |= settings_button(ui, cell, &mut picker_open);
ui.add_space(4.0);
let remaining = ui.available_width().max(cell);
egui::ScrollArea::horizontal().max_height(cell).max_width(remaining).show(ui, |ui| {
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
- tool_buttons(ui, app, &bar.tools, cell, &mut run, &mut remove);
+ core_tool_buttons(ui, app, cell, popup_align, &t);
+ active_tool_controls(ui, app, &t, false);
+ if !bar.tools.is_empty() {
+ ui.separator();
+ tool_buttons(ui, app, &bar.tools, cell, &mut run, &mut remove);
+ }
});
});
});
@@ -198,21 +500,44 @@ pub(crate) fn show(app: &mut PdfCraftApp, area: Rect, ctx: &egui::Context) {
grip.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, drag_label));
if grip.dragged() && bar.dock.is_none() {
let delta = grip.drag_delta();
+ if !bar.placed {
+ let cur_x = (pos.x - bounds.min.x).max(0.0);
+ let cur_y = (pos.y - bounds.min.y).max(0.0);
+ bar.position[0] = (cur_x / travel.x.max(1.0)).clamp(0.0, 1.0);
+ bar.position[1] = (cur_y / travel.y.max(1.0)).clamp(0.0, 1.0);
+ }
bar.position[0] = (bar.position[0] + delta.x / travel.x.max(1.0)).clamp(0.0, 1.0);
bar.position[1] = (bar.position[1] + delta.y / travel.y.max(1.0)).clamp(0.0, 1.0);
+ bar.placed = true;
}
- let scroll_max = if bar.vertical { (bounds.height() - cell - 50.0).max(cell) } else { (bounds.width() - cell - 50.0).max(cell) };
- let scroll = if bar.vertical {
- egui::ScrollArea::vertical().max_width(cell).max_height(scroll_max)
- } else {
- egui::ScrollArea::horizontal().max_height(cell).max_width(scroll_max)
- };
- scroll.auto_shrink([true, true]).show(ui, |ui| {
- ui.with_layout(layout, |ui| {
- tool_buttons(ui, app, &bar.tools, cell, &mut run, &mut remove);
+ if bar.vertical {
+ let fixed_overhead = grip_size.y + cell + 24.0;
+ let max_tools_length = (bounds.height() - fixed_overhead).max(cell);
+ egui::ScrollArea::vertical().max_height(max_tools_length).show(ui, |ui| {
+ ui.with_layout(layout, |ui| {
+ core_tool_buttons(ui, app, cell, popup_align, &t);
+ active_tool_controls(ui, app, &t, true);
+ if !bar.tools.is_empty() {
+ ui.separator();
+ tool_buttons(ui, app, &bar.tools, cell, &mut run, &mut remove);
+ }
+ });
});
- });
- settings_button(ui, cell, &mut picker_open);
+ settings_clicked |= settings_button(ui, cell, &mut picker_open);
+ } else {
+ core_tool_buttons(ui, app, cell, popup_align, &t);
+ active_tool_controls(ui, app, &t, false);
+ if !bar.tools.is_empty() {
+ ui.separator();
+ let scroll_max = (bounds.width() - cell - 50.0).max(cell);
+ egui::ScrollArea::horizontal().max_height(cell).max_width(scroll_max).show(ui, |ui| {
+ ui.with_layout(layout, |ui| {
+ tool_buttons(ui, app, &bar.tools, cell, &mut run, &mut remove);
+ });
+ });
+ }
+ settings_clicked |= settings_button(ui, cell, &mut picker_open);
+ }
});
}
if let Some(index) = remove {
@@ -241,50 +566,132 @@ pub(crate) fn show(app: &mut PdfCraftApp, area: Rect, ctx: &egui::Context) {
});
let picker_id = egui::Id::unique("hotbar-picker");
// A remembered collapsed state can survive disabling the collapse affordance.
- let mut expanded = egui::collapsing_header::CollapsingState::load_with_default_open(ctx, picker_id.with("collapsing"), true);
+ let mut expanded = egui::collapsing_header::CollapsingState::load_with_default_open(&ctx, picker_id.with("collapsing"), true);
expanded.set_open(true);
- expanded.store(ctx);
+ expanded.store(&ctx);
let screen = ctx.content_rect().shrink(12.0);
- let picker_x = if pos.x + cell + 380.0 < screen.right() { pos.x + cell + 20.0 } else { pos.x - 360.0 };
- let picker_pos = egui::pos2(
- picker_x.clamp(screen.left(), (screen.right() - 350.0).max(screen.left())),
- pos.y.clamp(screen.top(), (screen.bottom() - 640.0).max(screen.top())),
- );
- egui::Window::new(tl!("Hotbar tools"))
+ let margin_x = 14.0;
+ let card_margin_total = margin_x * 2.0;
+ let card_width = 280.0f32.min((screen.width() - card_margin_total).max(180.0));
+ let outer_width = card_width + card_margin_total;
+ let bar_rect = shown.response.rect;
+ let picker_x =
+ if bar_rect.right() + outer_width + 10.0 < screen.right() { bar_rect.right() + 14.0 } else { bar_rect.left() - outer_width - 14.0 };
+ let picker_y = if bar.dock.as_deref() == Some("top") {
+ (bar_rect.bottom() + 10.0).clamp(screen.top(), (screen.bottom() - 480.0).max(screen.top()))
+ } else if bar.dock.as_deref() == Some("bottom") {
+ (bar_rect.top() - 500.0).clamp(screen.top(), (screen.bottom() - 480.0).max(screen.top()))
+ } else {
+ bar_rect.top().clamp(screen.top(), (screen.bottom() - 480.0).max(screen.top()))
+ };
+ let picker_pos = egui::pos2(picker_x.clamp(screen.left(), (screen.right() - outer_width).max(screen.left())), picker_y);
+ let mut close_dialog = false;
+ let picker_resp = egui::Window::new(tl!("Hotbar tools"))
.id(picker_id)
.order(egui::Order::Foreground)
.open(&mut picker_open)
.collapsible(false)
.resizable(false)
+ .title_bar(false)
.fixed_pos(picker_pos)
- .max_height((screen.height() - 24.0).max(180.0))
- .vscroll(true)
- .show(ctx, |ui| {
- ui.set_min_width(260.0);
- ui.add(egui::Slider::new(&mut bar.button_size, 24.0..=64.0).text(tl!("Toolbar size")).suffix(" px"));
- ui.add_enabled(bar.dock.is_none(), crate::widgets::checkbox(&mut bar.vertical, tl!("Vertical layout")));
- if ui.selectable_label(bar.dock.is_none(), tl!("Float (drag anywhere)")).clicked() {
- let _ = bar.place("float");
- }
- ui.label(tl!("Stick to a side:"));
+ .frame(
+ egui::Frame::NONE
+ .fill(t.card)
+ .stroke(Stroke::new(1.0, t.border))
+ .corner_radius(CornerRadius::same(10))
+ .shadow(egui::Shadow { offset: [0, 6], blur: 20, spread: 0, color: Color32::from_black_alpha(if t.dark() { 120 } else { 35 }) })
+ .inner_margin(egui::Margin::symmetric(14, 12)),
+ )
+ .show(&ctx, |ui| {
+ ui.set_width(card_width);
+
+ // Title bar: "Hotbar Tools" on the left, "X" close button on the right
ui.horizontal(|ui| {
- for (label, side) in [(tl!("Left"), "left"), (tl!("Right"), "right"), (tl!("Top"), "top"), (tl!("Bottom"), "bottom")] {
- if ui.selectable_label(bar.dock.as_deref() == Some(side), label).clicked() {
- let _ = bar.place(side);
+ ui.label(egui::RichText::new(tl!("Hotbar tools")).size(14.0).strong().color(t.text));
+ ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
+ if icons::button(ui, "x", 16.0, false, tl!("Close menu")).clicked() {
+ close_dialog = true;
}
- }
+ });
+ });
+
+ ui.add_space(10.0);
+
+ // Section 1: Layout & Sizing
+ ui.label(egui::RichText::new(tl!("Layout & Sizing")).size(13.0).strong().color(t.text));
+ ui.add_space(6.0);
+
+ // Toolbar size slider row
+ ui.horizontal(|ui| {
+ ui.label(egui::RichText::new(tl!("Toolbar size")).size(12.5).color(t.text));
+ let slider_width = (ui.available_width() - 55.0).clamp(50.0, 140.0);
+ ui.spacing_mut().slider_width = slider_width;
+ ui.add(egui::Slider::new(&mut bar.button_size, 24.0..=64.0).show_value(false));
+ ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
+ ui.label(egui::RichText::new(format!("{:.0} px", bar.button_size)).size(12.0).color(t.text_muted));
+ });
+ });
+
+ ui.add_space(8.0);
+
+ // Vertical layout toggle switch row
+ ui.horizontal(|ui| {
+ ui.add_enabled_ui(bar.dock.is_none(), |ui| {
+ let label = tl!("Vertical layout");
+ toggle_switch(ui, &mut bar.vertical, label, &t);
+ ui.add_space(8.0);
+ ui.label(egui::RichText::new(label).size(12.5).color(t.text));
+ });
});
+
+ ui.add_space(10.0);
+
+ // Stick to a side section with segmented control
+ ui.label(egui::RichText::new(tl!("Stick to a side:")).size(12.5).color(t.text));
+ ui.add_space(6.0);
+ segmented_dock_picker(ui, &mut bar, &t);
+
+ ui.add_space(8.0);
+
+ // Full-side strip checkbox
let strip_hint = tl!("Extend the docked toolbar along the entire side. Choose a side above to enable.");
ui.add_enabled(bar.dock.is_some(), crate::widgets::checkbox(&mut bar.full_side, tl!("Full-side strip")))
.on_hover_text(strip_hint)
.on_disabled_hover_text(strip_hint);
- if ui.button(tl!("Close menu")).clicked() {
- ui.close();
- }
+
+ ui.add_space(12.0);
ui.separator();
- ui.label(tl!("Add tools to hotbar"));
- ui.add(egui::TextEdit::singleline(&mut bar.search).hint_text(tl!("Search all tools…")));
- egui::ScrollArea::vertical().max_height(300.0).show(ui, |ui| {
+ ui.add_space(10.0);
+
+ // Section 2: Add Tools to Hotbar
+ ui.label(egui::RichText::new(tl!("Add Tools to Hotbar")).size(13.0).strong().color(t.text));
+ ui.add_space(8.0);
+
+ // Search bar pill
+ let search_frame = egui::Frame::NONE
+ .fill(t.field)
+ .stroke(Stroke::new(1.0, t.border))
+ .corner_radius(CornerRadius::same(8))
+ .inner_margin(egui::Margin::symmetric(10, 6));
+ search_frame.show(ui, |ui| {
+ ui.horizontal(|ui| {
+ ui.spacing_mut().item_spacing.x = 8.0;
+ ui.add(icons::image("search", 14.0, t.text_faint));
+ ui.add(
+ egui::TextEdit::singleline(&mut bar.search)
+ .hint_text(tl!("Search all tools…"))
+ .frame(egui::Frame::NONE)
+ .desired_width(ui.available_width()),
+ );
+ });
+ });
+
+ ui.add_space(8.0);
+
+ // Scrollable tools list with checkboxes
+ let max_list_height = (screen.height() - 340.0).clamp(120.0, 220.0);
+ egui::ScrollArea::vertical().max_height(max_list_height).auto_shrink([false, false]).show(ui, |ui| {
+ ui.spacing_mut().item_spacing.y = 5.0;
for spec in COMMANDS {
if !matches_search(spec, &bar.search) {
continue;
@@ -299,9 +706,23 @@ pub(crate) fn show(app: &mut PdfCraftApp, area: Rect, ctx: &egui::Context) {
}
}
});
- ui.separator();
});
- ctx.data_mut(|data| data.insert_temp(id, shown.response.rect.size()));
+ let clicked_outside = was_picker_open
+ && !settings_clicked
+ && picker_resp.as_ref().is_some_and(|wr| {
+ wr.response.clicked_elsewhere()
+ || ctx.input(|i| i.pointer.any_click() && !i.pointer.interact_pos().is_some_and(|p| wr.response.rect.contains(p)))
+ });
+ if clicked_outside || ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ close_dialog = true;
+ }
+ if close_dialog {
+ picker_open = false;
+ }
+ ctx.data_mut(|data| {
+ data.insert_temp(id, shown.response.rect.size());
+ data.insert_temp(egui::Id::unique("custom-hotbar"), shown.response.rect.size());
+ });
bar.picker_open = picker_open;
app.hotbar = bar;
if let Some(id) = run {
@@ -358,6 +779,24 @@ mod tests {
assert_eq!(app.hotbar.position, [0.0, 1.0]);
}
+ #[test]
+ fn hotbar_restore_moves_legacy_default_into_margin_and_keeps_chosen_spots() {
+ let mut app = PdfCraftApp::new();
+ app.restore(r#"{"hotbar":{"tools":["comment.ink"],"position":[0.5,0.0],"vertical":false,"button_size":40.0,"dock":null}}"#);
+ assert_eq!(app.hotbar.position, [0.0, 0.0]);
+ assert!(app.hotbar.vertical);
+ assert!(!app.hotbar.placed);
+ assert_eq!(app.hotbar.tools, ["comment.ink"]);
+ assert_eq!(app.hotbar.button_size, 40.0);
+ app.restore(r#"{"hotbar":{"position":[0.0,0.0],"vertical":false,"dock":null}}"#);
+ assert_eq!(app.hotbar.position, [0.0, 0.0]);
+ assert!(!app.hotbar.vertical);
+ assert!(app.hotbar.placed, "a legacy bar dragged to the corner stays there");
+ app.restore(r#"{"hotbar":{"position":[0.5,0.0],"vertical":false,"dock":null,"placed":true}}"#);
+ assert_eq!(app.hotbar.position, [0.5, 0.0], "current preferences are not migrated");
+ assert!(!app.hotbar.vertical);
+ }
+
#[test]
fn hotbar_search_matches_translated_and_canonical_labels() {
let ink = command("comment.ink").unwrap();
diff --git a/crates/ui-egui/tests/it/comments.rs b/crates/ui-egui/tests/it/comments.rs
index 680573242..939de58df 100644
--- a/crates/ui-egui/tests/it/comments.rs
+++ b/crates/ui-egui/tests/it/comments.rs
@@ -3199,6 +3199,29 @@ fn hotbar_vertical_size_and_docking() {
assert_ne!(saved["hotbar"]["position"], moved["hotbar"]["position"]);
}
+#[test]
+fn hotbar_settings_layout_and_side_controls_are_reachable_by_label() {
+ let mut h = harness(|_| {});
+ h.get_by_label("Hotbar settings").click();
+ h.run_steps(3);
+ fn vertical(h: &Harness<'static, PdfCraftApp>) -> serde_json::Value {
+ serde_json::from_str::<serde_json::Value>(&h.state().persist()).unwrap()["hotbar"]["vertical"].clone()
+ }
+ let before = vertical(&h);
+ h.get_by_role_and_label(Role::Switch, "Vertical layout").click();
+ h.run_steps(3);
+ assert_ne!(vertical(&h), before, "the layout switch toggles by its label");
+ h.get_by_role_and_label(Role::RadioButton, "Right").click();
+ h.run_steps(3);
+ let saved: serde_json::Value = serde_json::from_str(&h.state().persist()).unwrap();
+ assert_eq!(saved["hotbar"]["dock"], "right");
+ assert_eq!(saved["hotbar"]["vertical"], true, "docking at the side lays the bar out vertically");
+ h.get_by_role_and_label(Role::RadioButton, "Float").click();
+ h.run_steps(3);
+ let saved: serde_json::Value = serde_json::from_str(&h.state().persist()).unwrap();
+ assert!(saved["hotbar"]["dock"].is_null());
+}
+
#[test]
fn hotbar_settings_reopen_even_with_remembered_collapsed_state() {
let mut h = harness(|_| {});
@@ -3246,5 +3269,113 @@ fn hotbar_full_side_strip_spans_each_edge_and_returns_to_float() {
h.state_mut().set_option("hotbar-side", "float").unwrap();
h.run_steps(5);
let size = h.ctx.data_mut(|d| d.get_temp::<egui::Vec2>(egui::Id::unique("custom-hotbar"))).unwrap();
- assert!(size.x < 150.0 && size.y < 150.0, "floating toolbar is compact: {size:?}");
+ let (length, thickness) = if size.y > size.x { (size.y, size.x) } else { (size.x, size.y) };
+ assert!(thickness <= 64.0 && length < 550.0, "floating toolbar is compact: {size:?}");
+}
+
+#[test]
+fn hotbar_docked_left_does_not_override_quick_tools() {
+ let mut h = harness(|app| {
+ app.set_option("hotbar-side", "left").unwrap();
+ });
+ h.run_steps(5);
+ // Controls in the docked bar share one layout, so none may overlap (#5890).
+ let labels = ["Drag hotbar", "Select (V)", "Hand (H)", "Add a sticky note", "Highlight", "Draw", "Fill & Sign", "Hotbar settings"];
+ let rects: Vec<_> = labels.iter().map(|&label| h.get_by_label(label).rect()).collect();
+ for (i, a) in rects.iter().enumerate() {
+ for (j, b) in rects.iter().enumerate().skip(i + 1) {
+ let overlap = a.min.x < b.max.x && b.min.x < a.max.x && a.min.y < b.max.y && b.min.y < a.max.y;
+ assert!(!overlap, "{} overlaps {}: {a:?} / {b:?}", labels[i], labels[j]);
+ }
+ }
+}
+
+#[test]
+fn hotbar_docked_in_compact_window_keeps_settings_button_visible() {
+ for side in ["left", "right"] {
+ let mut h = Harness::builder().with_size(egui::vec2(800.0, 480.0)).build_eframe(move |_cc| {
+ let mut app = PdfCraftApp::new();
+ app.set_option("language", "en").unwrap();
+ app.open_bytes("text.pdf", None, TEXT_FIXTURE.to_vec()).expect("opens");
+ app.set_option("left", "closed").unwrap();
+ app.set_option("hotbar-side", side).unwrap();
+ app.set_option("hotbar-size", "48").unwrap();
+ app
+ });
+ h.run_steps(5);
+ let settings_rect = h.get_by_label("Hotbar settings").rect();
+ assert!(settings_rect.max.y <= 480.0, "{side} hotbar settings button must stay within window height: {settings_rect:?}");
+ }
+}
+
+#[test]
+fn hotbar_settings_menu_closes_on_click_outside() {
+ let mut h = harness(|app| {
+ app.open_bytes("text.pdf", None, TEXT_FIXTURE.to_vec()).expect("opens");
+ });
+ h.get_by_label("Hotbar settings").click();
+ h.run_steps(3);
+ assert!(h.query_by_label("Close menu").is_some());
+
+ // Clicking outside on the canvas dismisses the settings menu
+ h.event(egui::Event::PointerButton {
+ pos: egui::pos2(600.0, 300.0),
+ button: egui::PointerButton::Primary,
+ pressed: true,
+ modifiers: Default::default(),
+ });
+ h.event(egui::Event::PointerButton {
+ pos: egui::pos2(600.0, 300.0),
+ button: egui::PointerButton::Primary,
+ pressed: false,
+ modifiers: Default::default(),
+ });
+ h.run_steps(3);
+ assert!(h.query_by_label("Close menu").is_none(), "clicking outside closes the hotbar settings menu");
+
+ // Reopening and clicking another tool outside dismisses the menu and activates that tool
+ h.get_by_label("Hotbar settings").click();
+ h.run_steps(3);
+ assert!(h.query_by_label("Close menu").is_some());
+ h.get_by_label("Hand (H)").click();
+ h.run_steps(3);
+ assert!(h.query_by_label("Close menu").is_none());
+ assert_eq!(h.state().quick_tool, QuickTool::Hand);
+}
+
+#[test]
+fn hotbar_picker_in_narrow_viewport_fits_within_screen_width() {
+ let mut h = Harness::builder().with_size(egui::vec2(270.0, 480.0)).build_eframe(|_cc| {
+ let mut app = PdfCraftApp::new();
+ app.set_option("language", "en").unwrap();
+ app.open_bytes("text.pdf", None, TEXT_FIXTURE.to_vec()).expect("opens");
+ app
+ });
+ h.get_by_label("Hotbar settings").click();
+ h.run_steps(5);
+ let close_btn = h.get_by_label("Close menu");
+ assert!(close_btn.rect().max.x <= 270.0, "Close menu button must stay within viewport width: {:?}", close_btn.rect());
+}
+
+#[test]
+fn hotbar_floating_picker_does_not_overlap_rendered_bar() {
+ let mut h = Harness::builder().with_size(egui::vec2(1000.0, 600.0)).build_eframe(|_cc| {
+ let mut app = PdfCraftApp::new();
+ app.set_option("language", "en").unwrap();
+ app.open_bytes("text.pdf", None, TEXT_FIXTURE.to_vec()).expect("opens");
+ app
+ });
+ let settings_btn = h.get_by_label("Hotbar settings");
+ let settings_rect = settings_btn.rect();
+ settings_btn.click();
+ h.run_steps(5);
+
+ let picker_close = h.get_by_label("Close menu");
+ let picker_rect = picker_close.rect();
+ assert!(
+ picker_rect.min.x >= settings_rect.max.x || picker_rect.max.x <= settings_rect.min.x,
+ "picker ({:?}) must not overlap the settings button ({:?}) on the floating bar",
+ picker_rect,
+ settings_rect
+ );
}
diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml
index ab8f75019..ef4007bc8 100644
--- a/parity/acrobat-features.toml
+++ b/parity/acrobat-features.toml
@@ -1813,6 +1813,12 @@ evidence = [
"crates/ui-egui/tests/it/comments.rs::hotbar_vertical_size_and_docking",
"crates/ui-egui/tests/it/comments.rs::hotbar_settings_reopen_even_with_remembered_collapsed_state",
"crates/ui-egui/tests/it/comments.rs::hotbar_full_side_strip_spans_each_edge_and_returns_to_float",
+ "crates/ui-egui/tests/it/comments.rs::hotbar_docked_left_does_not_override_quick_tools",
+ "crates/ui-egui/tests/it/comments.rs::hotbar_docked_in_compact_window_keeps_settings_button_visible",
+ "crates/ui-egui/tests/it/comments.rs::hotbar_settings_menu_closes_on_click_outside",
+ "crates/ui-egui/tests/it/comments.rs::hotbar_picker_in_narrow_viewport_fits_within_screen_width",
+ "crates/ui-egui/tests/it/comments.rs::hotbar_floating_picker_does_not_overlap_rendered_bar",
+ "crates/ui-egui/tests/it/comments.rs::hotbar_settings_layout_and_side_controls_are_reachable_by_label",
]
notes = "Pin and unpin tools on the Home page via tool card hover button, All Tools row toggle, or 'Pin a tool' search dialog. Pinned tool order persists across sessions. Customizable document hotbar searches the command registry, adds/removes tools, resizes buttons from 24 to 64 pixels, floats or docks on any side with an optional full-side chrome strip, and persists preferences (UI control: hotbar-tools, hotbar-size, hotbar-side, hotbar-full-side). Missing: hotbar shortcut reordering and full Acrobat customization-dialog parity."