Remove Pixels: Mul<Pixels, Output = Pixels> impl, add ScaledPixels ops (#27451)

It doesn't make sense to have `Pixels: Mul<Pixels, Output = Pixels>` as
the output should be `Pixels^2` (area), so these impls are removed. All
code where these impls were used are improved by instead multiplying by
`f32` or `usize`.

Also adds math op impls that are present for `Pixels` but absent for
`ScaledPixels`. Adds missing `Mul<Pixels> for usize` to both.

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-03-25 13:34:26 -06:00 committed by GitHub
parent 581d67398a
commit 9fc570c4be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 120 additions and 56 deletions

View file

@ -6905,7 +6905,7 @@ impl Editor {
)
.child(
h_flex()
.h(line_height + BORDER_WIDTH * px(2.))
.h(line_height + BORDER_WIDTH * 2.)
.px_1p5()
.gap_1()
// Workaround: For some reason, there's a gap if we don't do this

View file

@ -3303,7 +3303,7 @@ impl EditorElement {
let offset = scroll_position - max_row as f32;
if offset > 0.0 {
origin.y -= Pixels(offset) * line_height;
origin.y -= offset * line_height;
}
break;
}
@ -4524,7 +4524,7 @@ impl EditorElement {
hunk_hitbox.origin.x - hunk_hitbox.size.width,
hunk_hitbox.origin.y,
),
size(hunk_hitbox.size.width * px(2.), hunk_hitbox.size.height),
size(hunk_hitbox.size.width * 2., hunk_hitbox.size.height),
),
cx.theme().colors().version_control_deleted,
Corners::all(1. * line_height),
@ -7859,10 +7859,10 @@ impl ScrollbarRangeData {
let text_bounds_size = size(longest_line_width, max_row.0 as f32 * letter_size.height);
let settings = EditorSettings::get_global(cx);
let scroll_beyond_last_line: Pixels = match settings.scroll_beyond_last_line {
ScrollBeyondLastLine::OnePage => px(scrollbar_bounds.size.height / letter_size.height),
ScrollBeyondLastLine::Off => px(1.),
ScrollBeyondLastLine::VerticalScrollMargin => px(1.0 + settings.vertical_scroll_margin),
let scroll_beyond_last_line: f32 = match settings.scroll_beyond_last_line {
ScrollBeyondLastLine::OnePage => scrollbar_bounds.size.height / letter_size.height,
ScrollBeyondLastLine::Off => 1.0,
ScrollBeyondLastLine::VerticalScrollMargin => 1.0 + settings.vertical_scroll_margin,
};
let right_margin = if longest_line_width + longest_line_blame_width >= editor_width {
@ -8534,7 +8534,7 @@ fn compute_auto_height_layout(
snapshot = editor.snapshot(window, cx);
}
let scroll_height = Pixels::from(snapshot.max_point().row().next_row().0) * line_height;
let scroll_height = (snapshot.max_point().row().next_row().0 as f32) * line_height;
let height = scroll_height
.max(line_height)
.min(line_height * max_lines as f32);

View file

@ -29,7 +29,7 @@ use workspace::{OpenOptions, OpenVisible, Workspace};
pub const HOVER_REQUEST_DELAY_MILLIS: u64 = 200;
pub const MIN_POPOVER_CHARACTER_WIDTH: f32 = 20.;
pub const MIN_POPOVER_LINE_HEIGHT: Pixels = px(4.);
pub const MIN_POPOVER_LINE_HEIGHT: f32 = 4.;
pub const HOVER_POPOVER_GAP: Pixels = px(10.);
/// Bindable action which uses the most recent selection head to trigger a hover