mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
Merge pull request #10773 from dotCooCoo/fix/text-panels-empty-state-no-scroll-bar
Panels: Character and Paragraph show no scroll bar over an empty state that fits
This commit is contained in:
3 files changed
+96
-1
No files matched your search
@@ -40,12 +40,26 @@ pub(crate) fn panel_body(app: &mut VectorcraftApp, ui: &mut Ui, id: &str) {
|
||||
{
|
||||
// These panels lay out forms. Collection panels own their scrolling viewport
|
||||
// and reserve their own footer outside it.
|
||||
Stack::new().id_salt(id).fill().scroll(Scroll::vertical()).show(ui, |ui, _| memoized(app, ui, id, icon_panel_body));
|
||||
let scroll = if empty_state_only(app, id) { Scroll::vertical().overlay().at_rest() } else { Scroll::vertical() };
|
||||
Stack::new().id_salt(id).fill().scroll(scroll).show(ui, |ui, _| memoized(app, ui, id, icon_panel_body));
|
||||
}
|
||||
None => memoized(app, ui, id, icon_panel_body),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether panel `id` is the Character or Paragraph panel showing only its empty state. Its body then scrolls with an
|
||||
/// overlay bar, which leaves the message its full width: a scroll body measures its content beside the bar's lane, and a
|
||||
/// message that wraps onto one more line there kept a bar it did not need. This case is temporary: the craft-libs pin
|
||||
/// bump that includes craft-libs#4898, which fixes the measuring run, removes it and the two `shows_only_empty_state`
|
||||
/// helpers.
|
||||
fn empty_state_only(app: &VectorcraftApp, id: &str) -> bool {
|
||||
match id {
|
||||
"character" => panels::character::shows_only_empty_state(app),
|
||||
"paragraph" => panels::paragraph::shows_only_empty_state(app),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The Layers panel's body.
|
||||
fn layers_body(p: &mut BodyProps<'_>, ui: &mut Ui) {
|
||||
#[cfg(test)]
|
||||
@@ -180,6 +194,8 @@ mod tests {
|
||||
static DIRECT: Cell<bool> = const { Cell::new(false) };
|
||||
/// The panel [`draw`] shows.
|
||||
static SHOWN: RefCell<&'static str> = const { RefCell::new("") };
|
||||
/// The height of the body [`draw_unscrolled`] drew last.
|
||||
static UNSCROLLED_HEIGHT: Cell<f32> = const { Cell::new(0.0) };
|
||||
}
|
||||
|
||||
pub(super) fn count_run() {
|
||||
@@ -356,6 +372,75 @@ mod tests {
|
||||
assert!(panel.shows_value_with(|v| v.starts_with('7')), "the panel shows the 7 pt weight: {:?}", panel.values());
|
||||
}
|
||||
|
||||
/// The Character or Paragraph empty state, drawn without a scroll body; [`UNSCROLLED_HEIGHT`] holds its height.
|
||||
fn draw_unscrolled(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let top = ui.min_rect().top();
|
||||
crate::panels::show_icon_panel(app, ui, SHOWN.with(|s| *s.borrow()));
|
||||
UNSCROLLED_HEIGHT.with(|h| h.set(ui.min_rect().bottom() - top));
|
||||
}
|
||||
|
||||
/// Panel `id` drawn by `draw` over a document with nothing selected, in `room`.
|
||||
fn empty_panel(id: &'static str, draw: fn(&mut VectorcraftApp, &mut Ui), room: egui::Vec2) -> Panel {
|
||||
SHOWN.with(|s| *s.borrow_mut() = id);
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
let mut panel = Panel::new(app, draw);
|
||||
panel.room(room);
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
panel
|
||||
}
|
||||
|
||||
/// The empty state's texts as `panel` paints them, in paint order.
|
||||
fn empty_state_texts(panel: &Panel, message: &str) -> Vec<(String, egui::Rect)> {
|
||||
panel.texts().into_iter().filter(|(text, _)| text == "No text selected" || text == message).collect()
|
||||
}
|
||||
|
||||
/// In a dock group tall enough for the Character or Paragraph empty state at the group's full width, the dock body
|
||||
/// lays the message out as an unscrolled body does, and the wheel does not move it: the body shows no scroll bar
|
||||
/// and keeps no room for one. The groups are a little wider than the widths at which the message wraps onto one
|
||||
/// line fewer, so beside a bar's lane it would take one more line, and from the empty state's own height to about
|
||||
/// one line more.
|
||||
#[test]
|
||||
fn an_empty_state_that_fits_its_group_does_not_scroll() {
|
||||
let cases = [
|
||||
("character", "Select a text object to edit its character attributes."),
|
||||
("paragraph", "Select a text object to edit its paragraph attributes."),
|
||||
];
|
||||
for (id, message) in cases {
|
||||
let height_at = |width: f32| {
|
||||
let tall = empty_panel(id, draw_unscrolled, egui::vec2(width, 1600.0));
|
||||
assert_eq!(empty_state_texts(&tall, message).len(), 2, "{id} shows its empty state: {:?}", tall.texts());
|
||||
UNSCROLLED_HEIGHT.with(Cell::get).ceil()
|
||||
};
|
||||
let mut widths = Vec::new();
|
||||
let mut last = height_at(120.0);
|
||||
for step in 1..=50 {
|
||||
let width = 120.0 + 4.0 * step as f32;
|
||||
let height = height_at(width);
|
||||
if height < last {
|
||||
widths.extend([width, width + 2.0]);
|
||||
}
|
||||
last = height;
|
||||
}
|
||||
assert!(widths.len() >= 4, "{id}: the message wraps onto fewer lines as the group widens");
|
||||
for width in widths {
|
||||
let height = height_at(width);
|
||||
for extra in [0.0, 4.0, 8.0, 12.0] {
|
||||
let room = egui::vec2(width, height + extra);
|
||||
let unscrolled = empty_panel(id, draw_unscrolled, room);
|
||||
let mut docked = empty_panel(id, draw, room);
|
||||
docked.scroll_at(egui::pos2(width / 2.0, room.y / 2.0), -120.0);
|
||||
assert_eq!(
|
||||
empty_state_texts(&docked, message),
|
||||
empty_state_texts(&unscrolled, message),
|
||||
"{id} at {room:?}: the docked empty state is laid out and stays where the unscrolled one is"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The texts `id`'s body paints after idle frames, shown in its `MemoView` or, with `direct`, directly.
|
||||
fn texts(id: &'static str, direct: bool) -> Vec<(String, egui::Rect)> {
|
||||
DIRECT.with(|d| d.set(direct));
|
||||
|
||||
@@ -1262,6 +1262,11 @@ pub(crate) fn controls(app: &mut VectorcraftApp, ui: &mut Ui, rows: CharacterRow
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether [`show`] draws only the empty state: no type is selected and the Snap to Glyph options are hidden.
|
||||
pub(crate) fn shows_only_empty_state(app: &VectorcraftApp) -> bool {
|
||||
text_style(app).is_none() && !app.ui.snap_to_glyph_options
|
||||
}
|
||||
|
||||
/// The Character panel: the controls over the selected type (an empty state without any), then the
|
||||
/// Snap to Glyph options while they are shown, which need no type.
|
||||
pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
|
||||
@@ -848,6 +848,11 @@ fn localized_control_words() -> WordRows {
|
||||
.fold(WordRows::new(), |rows, (word, translated)| rows.row(word, translated))
|
||||
}
|
||||
|
||||
/// Whether [`show`] draws only the empty state: no type is selected.
|
||||
pub(crate) fn shows_only_empty_state(app: &VectorcraftApp) -> bool {
|
||||
text_style(app).is_none()
|
||||
}
|
||||
|
||||
pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let Some((_, para)) = text_style(app) else {
|
||||
super::empty_state(ui, "pilcrow", tl!("No text selected"), tl!("Select a text object to edit its paragraph attributes."));
|
||||
|
||||
Reference in new issue
Block a user