mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
Fix #10262: Document Info scrolls in a short dock group
Document Info was left out of the panel forms that scroll inside their dock group, so in a short group its lower rows could not be reached. It now scrolls like the other forms.
A test draws every panel in 120 pt and 60 pt groups and scrolls each one until its lowest control is in view.
(cherry picked from commit d7686cd9f4)
This commit is contained in:
1 parent
e5a65cf8e5
commit
b02b7243cd
4 files changed
+77
No files matched your search
@@ -22,6 +22,7 @@ pub(crate) fn panel_body(app: &mut VectorcraftApp, ui: &mut Ui, id: &str) {
|
||||
| "blend"
|
||||
| "character"
|
||||
| "color"
|
||||
| "docInfo"
|
||||
| "magicWand"
|
||||
| "openType"
|
||||
| "paragraph"
|
||||
|
||||
@@ -23,6 +23,7 @@ mod numfields;
|
||||
mod overprint;
|
||||
mod paintchips;
|
||||
pub(crate) mod panel_harness;
|
||||
mod panel_scroll;
|
||||
mod pastechords;
|
||||
mod pathtype;
|
||||
mod pdfoutput;
|
||||
|
||||
@@ -377,6 +377,20 @@ impl Panel {
|
||||
seen.is_some_and(|r| r.width() >= 0.0 && r.height() >= 0.0)
|
||||
}
|
||||
|
||||
/// The named control the latest frame lays out lowest, where its name finds that control: the control a reader
|
||||
/// reaches last.
|
||||
pub(crate) fn lowest(&self) -> Option<String> {
|
||||
let mut names = self.names();
|
||||
names.sort();
|
||||
names.dedup();
|
||||
names
|
||||
.into_iter()
|
||||
.filter_map(|name| self.fixture.by_label(&name).map(|t| (name, t.rect.bottom())))
|
||||
.filter(|(_, bottom)| bottom.is_finite())
|
||||
.max_by(|a, b| a.1.total_cmp(&b.1))
|
||||
.map(|(name, _)| name)
|
||||
}
|
||||
|
||||
/// Whether the control named `name` takes input.
|
||||
pub(crate) fn enabled(&self, name: &str) -> bool {
|
||||
!self.fixture.tree().is_disabled_key(self.look(name).node)
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//! Every panel in a dock group shorter than its contents scrolls to its last control (#10262).
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
use egui::{Ui, pos2, vec2};
|
||||
use serde_json::json;
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
use crate::VectorcraftApp;
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
thread_local! {
|
||||
/// The panel the harness draws.
|
||||
static SHOWN: RefCell<String> = const { RefCell::new(String::new()) };
|
||||
}
|
||||
|
||||
fn draw(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let id = SHOWN.with(|s| s.borrow().clone());
|
||||
crate::dock::panel_body(app, ui, &id);
|
||||
}
|
||||
|
||||
/// The panels whose last control a short dock group hides and the wheel does not bring into view.
|
||||
fn unreachable_panels(room_height: f32) -> Vec<String> {
|
||||
let mut stuck = Vec::new();
|
||||
for (id, _) in crate::state::all_panels() {
|
||||
SHOWN.with(|s| *s.borrow_mut() = id.to_owned());
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
if let Err(e) = app.run("file.new", json!({"width": 200, "height": 200})) {
|
||||
panic!("file.new: {e}");
|
||||
}
|
||||
// A selected path, so the panels that edit a selection show their controls.
|
||||
if let Err(e) = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 40})) {
|
||||
panic!("shape.rectangle: {e}");
|
||||
}
|
||||
let mut panel = Panel::new(app, draw);
|
||||
let Some(last) = panel.lowest() else { continue };
|
||||
panel.room(vec2(300.0, room_height));
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
if !panel.shows(&last) || panel.in_view(&last) {
|
||||
continue;
|
||||
}
|
||||
for _ in 0..60 {
|
||||
panel.scroll_at(pos2(150.0, room_height / 2.0), -120.0);
|
||||
if panel.in_view(&last) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !panel.in_view(&last) {
|
||||
stuck.push(format!("{id}: {last:?}"));
|
||||
}
|
||||
}
|
||||
stuck
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_panel_in_a_short_dock_group_scrolls_to_its_last_control() {
|
||||
let mut stuck = unreachable_panels(120.0);
|
||||
stuck.extend(unreachable_panels(60.0));
|
||||
assert!(stuck.is_empty(), "panels whose last control the wheel cannot reach: {stuck:?}");
|
||||
}
|
||||
Reference in new issue
Block a user