mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 08:11:41 +00:00
Fix #5941: the Color Picker leaves room for its scroll bar
While the picker's content scrolls, its field and columns are sized to the window's width less the scroll bar's column. Before, the content filled the whole width, so with dialogs that scroll sideways when too wide (#8529), in an app window 504 to 624 pt wide and 380 pt tall the picker scrolled sideways as a whole and showed no bar beside its content. The Export As test now also checks that the wheel scrolled the Format list before it checks that the list opens again at its first format.
This commit is contained in:
@@ -346,16 +346,38 @@ fn button_width(ui: &Ui) -> f32 {
|
||||
})
|
||||
}
|
||||
|
||||
/// A compact width shared by the heading and body, bounded by the available window width.
|
||||
/// A compact width shared by the heading and body, bounded by the available window width. While
|
||||
/// the body scrolls, the width leaves out the column of its scroll bar, so the body and its bar fit
|
||||
/// in the window side by side.
|
||||
fn layout_size(ui: &Ui) -> (f32, f32, f32, bool) {
|
||||
let button_w = button_width(ui);
|
||||
let values_w = PREVIEW_W + COLUMN_GAP + button_w;
|
||||
let fixed_w = SLIDER_GAP + SLIDER_W + COLUMN_GAP + values_w;
|
||||
let stacked = ui.available_width() < MIN_FIELD + fixed_w;
|
||||
let side = (ui.available_width() - fixed_w).clamp(MIN_FIELD, FIELD);
|
||||
let fit = |room: f32| ((room - fixed_w).clamp(MIN_FIELD, FIELD), room < MIN_FIELD + fixed_w);
|
||||
let (side, stacked) = fit(ui.available_width());
|
||||
// The margin keeps the bar's column whenever the body may scroll, as its height is estimated.
|
||||
let (side, stacked) = if body_height(ui, side, stacked) + 40.0 > scroll_height(ui) {
|
||||
fit(ui.available_width() - ui.spacing().scroll.allocated_width())
|
||||
} else {
|
||||
(side, stacked)
|
||||
};
|
||||
(side, values_w, button_w, stacked)
|
||||
}
|
||||
|
||||
/// The tallest the body's scrolling content is drawn.
|
||||
fn scroll_height(ui: &Ui) -> f32 {
|
||||
(ui.ctx().content_rect().height() - 112.0).max(1.0)
|
||||
}
|
||||
|
||||
/// How tall the body's field, slider and value columns are with a field `side` wide, `stacked` or
|
||||
/// side by side.
|
||||
fn body_height(ui: &Ui, side: f32, stacked: bool) -> f32 {
|
||||
// Let the auto-sized window grow for the checkbox too, rather than clipping it to the
|
||||
// scroll area's previous height while the dialog measures itself.
|
||||
let field_h = side + 8.0 + 20.0 + 2.0 * ui.spacing().item_spacing.y;
|
||||
if stacked { field_h + COLUMN_GAP + FIELD } else { field_h.max(FIELD) }
|
||||
}
|
||||
|
||||
/// Full-width, draggable title band using the app's existing theme colours.
|
||||
fn header(ui: &mut Ui, title: &str) {
|
||||
let (side, values_w, _, stacked) = layout_size(ui);
|
||||
@@ -395,11 +417,8 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui, d: &mut Dialog) -> DialogAction {
|
||||
let mut action = DialogAction::None;
|
||||
// Shrink the field first, then stack the columns in narrow windows. Only vertical
|
||||
// scrolling is needed, so no controls depend on a horizontal scrollbar.
|
||||
let height = (ui.ctx().content_rect().height() - 112.0).max(1.0);
|
||||
// Let the auto-sized window grow for the checkbox too, rather than clipping it to the
|
||||
// scroll area's previous height while the dialog measures itself.
|
||||
let field_h = side + 8.0 + 20.0 + 2.0 * ui.spacing().item_spacing.y;
|
||||
let body_height = if stacked { field_h + COLUMN_GAP + FIELD } else { field_h.max(FIELD) };
|
||||
let height = scroll_height(ui);
|
||||
let body_height = body_height(ui, side, stacked);
|
||||
let layout = if stacked { egui::Layout::top_down(egui::Align::Min) } else { egui::Layout::left_to_right(egui::Align::Min) };
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt("cp-content")
|
||||
|
||||
@@ -317,9 +317,20 @@ fn the_format_list_shows_its_scroll_bar_at_rest_and_opens_at_its_first_format()
|
||||
phase: egui::TouchPhase::Move,
|
||||
source: egui::MouseWheelSource::Unknown,
|
||||
};
|
||||
let top_before = rows.iter().find(|(s, ..)| s == labels[0]).map(|(_, r, _)| r.top());
|
||||
run(&mut app, vec![wheel]);
|
||||
let mut texts = vec![];
|
||||
for _ in 0..4 {
|
||||
run(&mut app, vec![]);
|
||||
(texts, _) = run(&mut app, vec![]);
|
||||
}
|
||||
// The wheel scrolled the list: its first format moved up or out of view.
|
||||
if rows.len() < labels.len() {
|
||||
let top_after = texts.iter().find(|(s, r, _)| s == labels[0] && list.contains_rect(*r)).map(|(_, r, _)| r.top());
|
||||
assert!(
|
||||
top_before.is_some_and(|before| top_after.is_none_or(|after| after < before - 1.0)),
|
||||
"the wheel scrolls the list: {} at {top_before:?}, then {top_after:?}",
|
||||
labels[0]
|
||||
);
|
||||
}
|
||||
run(&mut app, vec![egui::Event::PointerMoved(field), click_at(field, true)]);
|
||||
run(&mut app, vec![click_at(field, false)]);
|
||||
|
||||
Reference in New Issue
Block a user