Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion crates/ui/src/app/rail_toggle_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! The button that puts the sidebar away stands at one place, whichever area or page is shown.
//! The ends of the bars: the button that puts the sidebar away stands at one place, whichever area
//! or page is shown, and the HTTP strip ends where the request under it ends.

use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;
Expand Down Expand Up @@ -74,3 +75,42 @@ fn the_sidebar_toggle_stands_at_one_place_in_every_area_at_both_densities() {
}
}
}

#[test]
fn the_environment_picker_ends_at_the_margin_of_the_request_line() {
let directory = tempfile::tempdir().unwrap();
let mut harness = open_library(directory.path());
let backend = harness.state().backend();
let local = crate::http::tests::collection(backend, "Local");
crate::http::tests::request(
backend,
(&local, None),
"Login",
(RequestKind::Http, HttpMethod::Post),
);
click(&mut harness, "area-option-http");
harness
.get_by(|node| {
node.author_id() == Some("http-node-name")
&& node.label().as_deref() == Some("POST Login")
})
.click();
let margin = harness.ctx.content_rect().right() - crate::theme::tokens::BAR_INSET;
for density in [
crate::theme::Density::Comfortable,
crate::theme::Density::Compact,
] {
let ctx = harness.ctx.clone();
let app = harness.state_mut();
app.state.settings.density = density;
app.state.apply_look(&ctx);
settle(&mut harness);
let picker = toggle(&harness, "http-environment-picker").right();
let save = toggle(&harness, "http-save").right();
// « Save » ends where the measured widths of the line leave it: a point or two short.
assert!(
(picker - margin).abs() < 0.5 && save <= margin && margin - save < 3.0,
"{density:?}: the picker ends at {picker}, Save at {save}, the margin at {margin}"
);
}
}
17 changes: 12 additions & 5 deletions crates/ui/src/http/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const DIMMED: f32 = 0.55;
/// Held this close to an end of the strip, a dragged tab scrolls it, by this much a frame.
const EDGE: f32 = 32.0;
const EDGE_STEP: f32 = 8.0;
/// Between « New request » and the environment picker.
const END_GAP: f32 = gap::BLOCKS;

/// What only the strip's drawing sees: the tab being dragged.
#[derive(Default)]
Expand Down Expand Up @@ -79,7 +81,10 @@ pub(super) fn show(ui: &mut Ui, state: &AppState, view: &mut TabsView, actions:
egui::UiBuilder::new()
.max_rect(Rect::from_min_max(
pos2(toggle_rect.right() + 8.0, bar.top()),
pos2(bar.right() - end_width - 20.0, bar.bottom()),
pos2(
bar.right() - end_width - BAR_INSET - gap::INSET,
bar.bottom(),
),
))
.layout(egui::Layout::left_to_right(egui::Align::Min)),
);
Expand Down Expand Up @@ -123,16 +128,18 @@ pub(super) fn show(ui: &mut Ui, state: &AppState, view: &mut TabsView, actions:
list.widget_info(|| WidgetInfo::labeled(Role::TabList, true, &label));
widgets::address(&strip, &list, "http-tabs");
let end = Rect::from_min_max(
pos2(bar.right() - end_width - 10.0, bar.top()),
pos2(bar.right() - 10.0, bar.bottom()),
pos2(bar.right() - end_width - BAR_INSET, bar.top()),
pos2(bar.right() - BAR_INSET, bar.bottom()),
);
let mut end_ui = ui.new_child(
egui::UiBuilder::new()
.max_rect(end)
.layout(egui::Layout::left_to_right(egui::Align::Center)),
);
// `end_width` counts this gap alone: an item spacing on top pushed the picker past the edge.
end_ui.spacing_mut().item_spacing.x = 0.0;
new_request(&mut end_ui, actions, language);
end_ui.add_space(gap::CONTROLS);
end_ui.add_space(END_GAP);
super::environment_picker::show(&mut end_ui, state, actions);
}

Expand Down Expand Up @@ -364,7 +371,7 @@ fn close_glyph(ui: &Ui, close: &Response) {

/// What the end of the strip takes: « New request » and the environment beside it.
fn end_width(ui: &Ui, state: &AppState) -> f32 {
new_request_width(ui, state.language) + super::environment_picker::width(ui, state) + 8.0
new_request_width(ui, state.language) + END_GAP + super::environment_picker::width(ui, state)
}

fn new_request_width(ui: &Ui, language: i18n::Language) -> f32 {
Expand Down