* Wireup the `Pixels` change
https://github.com/zed-industries/zed/pull/39367.
This commit is contained in:
Floyd Wang 2025-10-03 14:32:29 +08:00 committed by GitHub
parent 4d459ea160
commit 1358b2906e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 123 additions and 97 deletions

74
Cargo.lock generated
View file

@ -605,7 +605,7 @@ dependencies = [
"bitflags 2.9.1", "bitflags 2.9.1",
"cexpr", "cexpr",
"clang-sys", "clang-sys",
"itertools 0.11.0", "itertools 0.12.1",
"lazy_static", "lazy_static",
"lazycell", "lazycell",
"log", "log",
@ -628,7 +628,7 @@ dependencies = [
"bitflags 2.9.1", "bitflags 2.9.1",
"cexpr", "cexpr",
"clang-sys", "clang-sys",
"itertools 0.11.0", "itertools 0.13.0",
"log", "log",
"prettyplease", "prettyplease",
"proc-macro2", "proc-macro2",
@ -692,14 +692,15 @@ dependencies = [
[[package]] [[package]]
name = "blade-graphics" name = "blade-graphics"
version = "0.6.0" version = "0.7.0"
source = "git+https://github.com/kvark/blade?rev=bfa594ea697d4b6326ea29f747525c85ecf933b9#bfa594ea697d4b6326ea29f747525c85ecf933b9" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4deb8f595ce7f00dee3543ebf6fd9a20ea86fc421ab79600dac30876250bdae"
dependencies = [ dependencies = [
"ash", "ash",
"ash-window", "ash-window",
"bitflags 2.9.1", "bitflags 2.9.1",
"bytemuck", "bytemuck",
"codespan-reporting 0.11.1", "codespan-reporting",
"glow", "glow",
"gpu-alloc", "gpu-alloc",
"gpu-alloc-ash", "gpu-alloc-ash",
@ -717,6 +718,7 @@ dependencies = [
"objc2-metal", "objc2-metal",
"objc2-quartz-core", "objc2-quartz-core",
"objc2-ui-kit", "objc2-ui-kit",
"once_cell",
"raw-window-handle", "raw-window-handle",
"slab", "slab",
"wasm-bindgen", "wasm-bindgen",
@ -726,7 +728,8 @@ dependencies = [
[[package]] [[package]]
name = "blade-macros" name = "blade-macros"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/kvark/blade?rev=bfa594ea697d4b6326ea29f747525c85ecf933b9#bfa594ea697d4b6326ea29f747525c85ecf933b9" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27142319e2f4c264581067eaccb9f80acccdde60d8b4bf57cc50cd3152f109ca"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -735,8 +738,9 @@ dependencies = [
[[package]] [[package]]
name = "blade-util" name = "blade-util"
version = "0.2.0" version = "0.3.0"
source = "git+https://github.com/kvark/blade?rev=bfa594ea697d4b6326ea29f747525c85ecf933b9#bfa594ea697d4b6326ea29f747525c85ecf933b9" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a6be3a82c001ba7a17b6f8e413ede5d1004e6047213f8efaf0ffc15b5c4904c"
dependencies = [ dependencies = [
"blade-graphics", "blade-graphics",
"bytemuck", "bytemuck",
@ -1134,16 +1138,6 @@ dependencies = [
"objc", "objc",
] ]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
dependencies = [
"termcolor",
"unicode-width 0.1.14",
]
[[package]] [[package]]
name = "codespan-reporting" name = "codespan-reporting"
version = "0.12.0" version = "0.12.0"
@ -1152,13 +1146,13 @@ checksum = "fe6d2e5af09e8c8ad56c969f2157a3d4238cebc7c55f0a517728c38f7b200f81"
dependencies = [ dependencies = [
"serde", "serde",
"termcolor", "termcolor",
"unicode-width 0.2.1", "unicode-width",
] ]
[[package]] [[package]]
name = "collections" name = "collections"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"rustc-hash 2.1.1", "rustc-hash 2.1.1",
@ -1586,7 +1580,7 @@ dependencies = [
[[package]] [[package]]
name = "derive_refineable" name = "derive_refineable"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2660,9 +2654,9 @@ dependencies = [
[[package]] [[package]]
name = "glow" name = "glow"
version = "0.14.2" version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d51fa363f025f5c111e03f13eda21162faeacb6911fe8caa0c0349f9cf0c4483" checksum = "c5e5ea60d70410161c8bf5da3fdfeaa1c72ed2c15f8bbb9d19fe3a4fad085f08"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"slotmap", "slotmap",
@ -2714,7 +2708,7 @@ dependencies = [
[[package]] [[package]]
name = "gpui" name = "gpui"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"as-raw-xcb-connection", "as-raw-xcb-connection",
@ -2885,7 +2879,7 @@ dependencies = [
[[package]] [[package]]
name = "gpui_macros" name = "gpui_macros"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"heck 0.5.0", "heck 0.5.0",
"proc-macro2", "proc-macro2",
@ -3152,7 +3146,7 @@ dependencies = [
[[package]] [[package]]
name = "http_client" name = "http_client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -3172,7 +3166,7 @@ dependencies = [
[[package]] [[package]]
name = "http_client_tls" name = "http_client_tls"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"rustls", "rustls",
"rustls-platform-verifier", "rustls-platform-verifier",
@ -4058,7 +4052,7 @@ dependencies = [
[[package]] [[package]]
name = "media" name = "media"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bindgen 0.71.1", "bindgen 0.71.1",
@ -4170,7 +4164,7 @@ dependencies = [
"bit-set", "bit-set",
"bitflags 2.9.1", "bitflags 2.9.1",
"cfg_aliases", "cfg_aliases",
"codespan-reporting 0.12.0", "codespan-reporting",
"half", "half",
"hashbrown 0.15.5", "hashbrown 0.15.5",
"hexf-parse", "hexf-parse",
@ -4818,7 +4812,7 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]] [[package]]
name = "perf" name = "perf"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"collections", "collections",
"serde", "serde",
@ -5637,7 +5631,7 @@ dependencies = [
[[package]] [[package]]
name = "refineable" name = "refineable"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"derive_refineable", "derive_refineable",
"workspace-hack", "workspace-hack",
@ -5748,7 +5742,7 @@ dependencies = [
[[package]] [[package]]
name = "reqwest_client" name = "reqwest_client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -6306,7 +6300,7 @@ checksum = "0f7d95a54511e0c7be3f51e8867aa8cf35148d7b9445d44de2f943e2b206e749"
[[package]] [[package]]
name = "semantic_version" name = "semantic_version"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"serde", "serde",
@ -6492,7 +6486,7 @@ version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b1fdf65dd6331831494dd616b30351c38e96e45921a27745cf98490458b90bb" checksum = "8b1fdf65dd6331831494dd616b30351c38e96e45921a27745cf98490458b90bb"
dependencies = [ dependencies = [
"dirs 4.0.0", "dirs 6.0.0",
] ]
[[package]] [[package]]
@ -6868,7 +6862,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]] [[package]]
name = "sum_tree" name = "sum_tree"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"log", "log",
@ -8024,12 +8018,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94" checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94"
[[package]]
name = "unicode-width"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
version = "0.2.1" version = "0.2.1"
@ -8108,7 +8096,7 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]] [[package]]
name = "util" name = "util"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-fs 2.1.3", "async-fs 2.1.3",
@ -8143,7 +8131,7 @@ dependencies = [
[[package]] [[package]]
name = "util_macros" name = "util_macros"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#6af385235d2dbd145391861556704edb1523ebf3" source = "git+https://github.com/zed-industries/zed.git#e4f90b5da2b8a6d2b267edc02b333b7d7908d4d9"
dependencies = [ dependencies = [
"perf", "perf",
"quote", "quote",

View file

@ -11,8 +11,8 @@ use gpui_component::{
locale, locale,
popup_menu::PopupMenuExt as _, popup_menu::PopupMenuExt as _,
scroll::ScrollbarShow, scroll::ScrollbarShow,
set_locale, ActiveTheme as _, ContextModal as _, IconName, Sizable as _, Theme, ThemeMode, set_locale, ActiveTheme as _, ContextModal as _, IconName, PixelsExt, Sizable as _, Theme,
TitleBar, ThemeMode, TitleBar,
}; };
use crate::{themes::ThemeSwitcher, SelectFont, SelectLocale, SelectRadius, SelectScrollbarShow}; use crate::{themes::ThemeSwitcher, SelectFont, SelectLocale, SelectRadius, SelectScrollbarShow};
@ -219,8 +219,8 @@ impl FontSizeSelector {
impl Render for FontSizeSelector { impl Render for FontSizeSelector {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let focus_handle = self.focus_handle.clone(); let focus_handle = self.focus_handle.clone();
let font_size = cx.theme().font_size.0 as i32; let font_size = cx.theme().font_size.as_f32() as i32;
let radius = cx.theme().radius.0 as i32; let radius = cx.theme().radius.as_f32() as i32;
let scroll_show = cx.theme().scrollbar_show; let scroll_show = cx.theme().scrollbar_show;
div() div()

View file

@ -10,7 +10,7 @@ use crate::{
shape::Area, shape::Area,
Axis, AxisText, Grid, Plot, StrokeStyle, AXIS_GAP, Axis, AxisText, Grid, Plot, StrokeStyle, AXIS_GAP,
}, },
ActiveTheme, ActiveTheme, PixelsExt,
}; };
#[derive(IntoPlot)] #[derive(IntoPlot)]
@ -94,8 +94,8 @@ where
return; return;
} }
let width = bounds.size.width.0; let width = bounds.size.width.as_f32();
let height = bounds.size.height.0 - AXIS_GAP; let height = bounds.size.height.as_f32() - AXIS_GAP;
// X scale // X scale
let x = ScalePoint::new(self.data.iter().map(|v| x_fn(v)).collect(), vec![0., width]); let x = ScalePoint::new(self.data.iter().map(|v| x_fn(v)).collect(), vec![0., width]);

View file

@ -11,7 +11,7 @@ use crate::{
shape::Bar, shape::Bar,
Axis, AxisText, Grid, Plot, AXIS_GAP, Axis, AxisText, Grid, Plot, AXIS_GAP,
}, },
ActiveTheme, ActiveTheme, PixelsExt,
}; };
#[derive(IntoPlot)] #[derive(IntoPlot)]
@ -90,8 +90,8 @@ where
return; return;
}; };
let width = bounds.size.width.0; let width = bounds.size.width.as_f32();
let height = bounds.size.height.0 - AXIS_GAP; let height = bounds.size.height.as_f32() - AXIS_GAP;
// X scale // X scale
let x = ScaleBand::new(self.data.iter().map(|v| x_fn(v)).collect(), vec![0., width]) let x = ScaleBand::new(self.data.iter().map(|v| x_fn(v)).collect(), vec![0., width])

View file

@ -10,7 +10,7 @@ use crate::{
shape::Line, shape::Line,
Axis, AxisText, Grid, Plot, StrokeStyle, AXIS_GAP, Axis, AxisText, Grid, Plot, StrokeStyle, AXIS_GAP,
}, },
ActiveTheme, ActiveTheme, PixelsExt,
}; };
#[derive(IntoPlot)] #[derive(IntoPlot)]
@ -85,8 +85,8 @@ where
return; return;
}; };
let width = bounds.size.width.0; let width = bounds.size.width.as_f32();
let height = bounds.size.height.0 - AXIS_GAP; let height = bounds.size.height.as_f32() - AXIS_GAP;
// X scale // X scale
let x = ScalePoint::new(self.data.iter().map(|v| x_fn(v)).collect(), vec![0., width]); let x = ScalePoint::new(self.data.iter().map(|v| x_fn(v)).collect(), vec![0., width]);

View file

@ -9,7 +9,7 @@ use crate::{
shape::{Arc, Pie}, shape::{Arc, Pie},
Plot, Plot,
}, },
ActiveTheme, ActiveTheme, PixelsExt,
}; };
#[derive(IntoPlot)] #[derive(IntoPlot)]
@ -73,7 +73,7 @@ impl<T> Plot for PieChart<T> {
}; };
let outer_radius = if self.outer_radius.is_zero() { let outer_radius = if self.outer_radius.is_zero() {
bounds.size.height.0 * 0.4 bounds.size.height.as_f32() * 0.4
} else { } else {
self.outer_radius self.outer_radius
}; };

View file

@ -312,8 +312,8 @@ impl Dock {
.expect("DockArea is missing") .expect("DockArea is missing")
.read(cx); .read(cx);
let area_bounds = dock_area.bounds; let area_bounds = dock_area.bounds;
let mut left_dock_size = Pixels(0.0); let mut left_dock_size = px(0.0);
let mut right_dock_size = Pixels(0.0); let mut right_dock_size = px(0.0);
// Get the size of the left dock if it's open and not the current dock // Get the size of the left dock if it's open and not the current dock
if let Some(left_dock) = &dock_area.left_dock { if let Some(left_dock) = &dock_area.left_dock {

View file

@ -15,7 +15,7 @@ use crate::{
text_wrapper::{LineLayout, TextWrapper}, text_wrapper::{LineLayout, TextWrapper},
RopeExt as _, RopeExt as _,
}, },
ActiveTheme as _, Colorize, Root, ActiveTheme as _, Colorize, PixelsExt, Root,
}; };
use super::{mode::InputMode, InputState, LastLayout}; use super::{mode::InputMode, InputState, LastLayout};
@ -692,21 +692,25 @@ fn print_points_as_svg_path(
for corners in line_corners { for corners in line_corners {
println!( println!(
"tl: ({}, {}), tr: ({}, {}), bl: ({}, {}), br: ({}, {})", "tl: ({}, {}), tr: ({}, {}), bl: ({}, {}), br: ({}, {})",
corners.top_left.x.0 as i32, corners.top_left.x.as_f32() as i32,
corners.top_left.y.0 as i32, corners.top_left.y.as_f32() as i32,
corners.top_right.x.0 as i32, corners.top_right.x.as_f32() as i32,
corners.top_right.y.0 as i32, corners.top_right.y.as_f32() as i32,
corners.bottom_left.x.0 as i32, corners.bottom_left.x.as_f32() as i32,
corners.bottom_left.y.0 as i32, corners.bottom_left.y.as_f32() as i32,
corners.bottom_right.x.0 as i32, corners.bottom_right.x.as_f32() as i32,
corners.bottom_right.y.0 as i32, corners.bottom_right.y.as_f32() as i32,
); );
} }
if points.len() > 0 { if points.len() > 0 {
println!("M{},{}", points[0].x.0 as i32, points[0].y.0 as i32); println!(
"M{},{}",
points[0].x.as_f32() as i32,
points[0].y.as_f32() as i32
);
for p in points.iter().skip(1) { for p in points.iter().skip(1) {
println!("L{},{}", p.x.0 as i32, p.y.0 as i32); println!("L{},{}", p.x.as_f32() as i32, p.y.as_f32() as i32);
} }
} }
} }

View file

@ -617,7 +617,7 @@ impl InputState {
for (line_index, line) in last_layout.lines.iter().enumerate() { for (line_index, line) in last_layout.lines.iter().enumerate() {
let local_offset = offset.saturating_sub(prev_lines_offset); let local_offset = offset.saturating_sub(prev_lines_offset);
if let Some(pos) = line.position_for_index(local_offset, line_height) { if let Some(pos) = line.position_for_index(local_offset, line_height) {
let sub_line_index = (pos.y.0 / line_height.0) as usize; let sub_line_index = (pos.y / line_height) as usize;
let adjusted_pos = point(pos.x + last_layout.line_number_width, pos.y + y_offset); let adjusted_pos = point(pos.x + last_layout.line_number_width, pos.y + y_offset);
return (line_index, sub_line_index, Some(adjusted_pos)); return (line_index, sub_line_index, Some(adjusted_pos));
} }

View file

@ -11,6 +11,8 @@ use std::{fmt::Debug, ops::Add};
use gpui::{point, px, App, Bounds, IntoElement, Path, PathBuilder, Pixels, Point, Window}; use gpui::{point, px, App, Bounds, IntoElement, Path, PathBuilder, Pixels, Point, Window};
use crate::PixelsExt;
pub use axis::{Axis, AxisText, AXIS_GAP}; pub use axis::{Axis, AxisText, AXIS_GAP};
pub use grid::Grid; pub use grid::Grid;
pub use label::Label; pub use label::Label;
@ -42,8 +44,8 @@ where
.iter() .iter()
.map(|p| { .map(|p| {
point( point(
px(p.x.into() + bounds.origin.x.0), px(p.x.into() + bounds.origin.x.as_f32()),
px(p.y.into() + bounds.origin.y.0), px(p.y.into() + bounds.origin.y.as_f32()),
) )
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View file

@ -4,6 +4,8 @@ use std::{f32::consts::PI, fmt::Debug};
use gpui::{point, px, Bounds, Hsla, Path, PathBuilder, Pixels, Point, Window}; use gpui::{point, px, Bounds, Hsla, Path, PathBuilder, Pixels, Point, Window};
use crate::PixelsExt;
const EPSILON: f32 = 1e-12; const EPSILON: f32 = 1e-12;
const HALF_PI: f32 = PI / 2.; const HALF_PI: f32 = PI / 2.;
@ -82,8 +84,8 @@ impl Arc {
let r1 = self.outer_radius.max(0.); let r1 = self.outer_radius.max(0.);
// Calculate the center point. // Calculate the center point.
let center_x = bounds.origin.x.0 + bounds.size.width.0 / 2.; let center_x = bounds.origin.x.as_f32() + bounds.size.width.as_f32() / 2.;
let center_y = bounds.origin.y.0 + bounds.size.height.0 / 2.; let center_y = bounds.origin.y.as_f32() + bounds.size.height.as_f32() / 2.;
// Angle difference. // Angle difference.
if r1 < EPSILON || da.abs() < EPSILON { if r1 < EPSILON || da.abs() < EPSILON {

View file

@ -5,7 +5,10 @@ use gpui::{
Point, Window, Point, Window,
}; };
use crate::plot::{origin_point, StrokeStyle}; use crate::{
plot::{origin_point, StrokeStyle},
PixelsExt,
};
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
pub struct Line<T> { pub struct Line<T> {
@ -138,7 +141,7 @@ impl<T> Line<T> {
let pos = origin_point(px(x), px(y), origin); let pos = origin_point(px(x), px(y), origin);
if self.dot { if self.dot {
let dot_radius = self.dot_size.0 / 2.; let dot_radius = self.dot_size.as_f32() / 2.;
let dot_pos = origin_point(px(x - dot_radius), px(y - dot_radius), origin); let dot_pos = origin_point(px(x - dot_radius), px(y - dot_radius), origin);
paint_dots.push(self.paint_dot(dot_pos)); paint_dots.push(self.paint_dot(dot_pos));
} }

View file

@ -5,6 +5,8 @@ use gpui::{
Window, Window,
}; };
use crate::PixelsExt;
mod panel; mod panel;
mod resize_handle; mod resize_handle;
pub use panel::*; pub use panel::*;
@ -130,7 +132,7 @@ impl ResizableState {
} }
pub(crate) fn total_size(&self) -> Pixels { pub(crate) fn total_size(&self) -> Pixels {
self.sizes.iter().map(|s| s.0).sum::<f32>().into() self.sizes.iter().map(|s| s.as_f32()).sum::<f32>().into()
} }
pub(crate) fn done_resizing(&mut self, cx: &mut Context<Self>) { pub(crate) fn done_resizing(&mut self, cx: &mut Context<Self>) {
@ -206,7 +208,7 @@ impl ResizableState {
} }
// If total size exceeds container size, adjust the main panel // If total size exceeds container size, adjust the main panel
let total_size: Pixels = new_sizes.iter().map(|s| s.0).sum::<f32>().into(); let total_size: Pixels = new_sizes.iter().map(|s| s.as_f32()).sum::<f32>().into();
if total_size > container_size { if total_size > container_size {
let overflow = total_size - container_size; let overflow = total_size - container_size;
new_sizes[main_ix] = (new_sizes[main_ix] - overflow).max(size_range.start); new_sizes[main_ix] = (new_sizes[main_ix] - overflow).max(size_range.start);

View file

@ -39,12 +39,12 @@ pub(crate) const WIDTH: Pixels = px(2. * 2. + 8.);
const MIN_THUMB_SIZE: f32 = 48.; const MIN_THUMB_SIZE: f32 = 48.;
const THUMB_WIDTH: Pixels = px(6.); const THUMB_WIDTH: Pixels = px(6.);
const THUMB_RADIUS: Pixels = Pixels(6. / 2.); const THUMB_RADIUS: Pixels = px(6. / 2.);
const THUMB_INSET: Pixels = Pixels(2.); const THUMB_INSET: Pixels = px(2.);
const THUMB_ACTIVE_WIDTH: Pixels = px(8.); const THUMB_ACTIVE_WIDTH: Pixels = px(8.);
const THUMB_ACTIVE_RADIUS: Pixels = Pixels(8. / 2.); const THUMB_ACTIVE_RADIUS: Pixels = px(8. / 2.);
const THUMB_ACTIVE_INSET: Pixels = Pixels(2.); const THUMB_ACTIVE_INSET: Pixels = px(2.);
const FADE_OUT_DURATION: f32 = 3.0; const FADE_OUT_DURATION: f32 = 3.0;
const FADE_OUT_DELAY: f32 = 2.0; const FADE_OUT_DELAY: f32 = 2.0;

View file

@ -224,7 +224,7 @@ pub enum Size {
impl Size { impl Size {
fn as_f32(&self) -> f32 { fn as_f32(&self) -> f32 {
match self { match self {
Size::Size(val) => val.0, Size::Size(val) => val.as_f32(),
Size::XSmall => 0., Size::XSmall => 0.,
Size::Small => 1., Size::Small => 1.,
Size::Medium => 2., Size::Medium => 2.,
@ -301,7 +301,7 @@ impl Size {
/// e.g. `Size::XSmall.max(Size::Small)` will return `Size::XSmall`. /// e.g. `Size::XSmall.max(Size::Small)` will return `Size::XSmall`.
pub fn max(&self, other: Self) -> Self { pub fn max(&self, other: Self) -> Self {
match (self, other) { match (self, other) {
(Size::Size(a), Size::Size(b)) => Size::Size(px(a.0.min(b.0))), (Size::Size(a), Size::Size(b)) => Size::Size(px(a.as_f32().min(b.as_f32()))),
(Size::Size(a), _) => Size::Size(*a), (Size::Size(a), _) => Size::Size(*a),
(_, Size::Size(b)) => Size::Size(b), (_, Size::Size(b)) => Size::Size(b),
(a, b) if a.as_f32() < b.as_f32() => *a, (a, b) if a.as_f32() < b.as_f32() => *a,
@ -314,7 +314,7 @@ impl Size {
/// e.g. `Size::XSmall.min(Size::Small)` will return `Size::Small`. /// e.g. `Size::XSmall.min(Size::Small)` will return `Size::Small`.
pub fn min(&self, other: Self) -> Self { pub fn min(&self, other: Self) -> Self {
match (self, other) { match (self, other) {
(Size::Size(a), Size::Size(b)) => Size::Size(px(a.0.max(b.0))), (Size::Size(a), Size::Size(b)) => Size::Size(px(a.as_f32().max(b.as_f32()))),
(Size::Size(a), _) => Size::Size(*a), (Size::Size(a), _) => Size::Size(*a),
(_, Size::Size(b)) => Size::Size(b), (_, Size::Size(b)) => Size::Size(b),
(a, b) if a.as_f32() > b.as_f32() => *a, (a, b) if a.as_f32() > b.as_f32() => *a,
@ -694,6 +694,21 @@ pub trait Collapsible {
fn is_collapsed(&self) -> bool; fn is_collapsed(&self) -> bool;
} }
/// A trait for converting `Pixels` to `f32` and `f64`.
pub trait PixelsExt {
fn as_f32(&self) -> f32;
fn as_f64(self) -> f64;
}
impl PixelsExt for Pixels {
fn as_f32(&self) -> f32 {
f32::from(self)
}
fn as_f64(self) -> f64 {
f64::from(self)
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use gpui::px; use gpui::px;

View file

@ -26,7 +26,7 @@ use gpui::{
}; };
use smallvec::SmallVec; use smallvec::SmallVec;
use crate::{scroll::ScrollHandleOffsetable, AxisExt}; use crate::{scroll::ScrollHandleOffsetable, AxisExt, PixelsExt};
struct VirtualListScrollHandleState { struct VirtualListScrollHandleState {
axis: Axis, axis: Axis,
@ -383,7 +383,11 @@ impl Element for VirtualList {
state.content_size = if self.axis.is_horizontal() { state.content_size = if self.axis.is_horizontal() {
Size { Size {
width: px(state.sizes.iter().map(|size| size.0).sum::<f32>()), width: px(state
.sizes
.iter()
.map(|size| size.as_f32())
.sum::<f32>()),
height: state height: state
.items_sizes .items_sizes
.get(0) .get(0)
@ -395,7 +399,11 @@ impl Element for VirtualList {
.items_sizes .items_sizes
.get(0) .get(0)
.map_or(px(0.), |size| size.width), .map_or(px(0.), |size| size.width),
height: px(state.sizes.iter().map(|size| size.0).sum::<f32>()), height: px(state
.sizes
.iter()
.map(|size| size.as_f32())
.sum::<f32>()),
} }
}; };
} }
@ -564,7 +572,7 @@ impl Element for VirtualList {
- layout.size_layout.content_size.along(self.axis); - layout.size_layout.content_size.along(self.axis);
// Do not trigger scrolling if the content is smaller than the container. // Do not trigger scrolling if the content is smaller than the container.
if min_scroll_offset.0 >= 0. { if min_scroll_offset.as_f32() >= 0. {
scroll_offset.x = px(0.); scroll_offset.x = px(0.);
scroll_offset.y = px(0.); scroll_offset.y = px(0.);
} }

View file

@ -11,6 +11,8 @@ use gpui::{
MouseDownEvent, ParentElement as _, Pixels, Render, Size, Style, Styled as _, Window, MouseDownEvent, ParentElement as _, Pixels, Render, Size, Style, Styled as _, Window,
}; };
use crate::PixelsExt;
pub struct WebView { pub struct WebView {
focus_handle: FocusHandle, focus_handle: FocusHandle,
webview: Rc<wry::WebView>, webview: Rc<wry::WebView>,
@ -176,8 +178,8 @@ impl Element for WebViewElement {
self.view self.view
.set_bounds(Rect { .set_bounds(Rect {
size: dpi::Size::Logical(LogicalSize { size: dpi::Size::Logical(LogicalSize {
width: (bounds.size.width.0).into(), width: (bounds.size.width.as_f32()).into(),
height: (bounds.size.height.0).into(), height: (bounds.size.height.as_f32()).into(),
}), }),
position: dpi::Position::Logical(dpi::LogicalPosition::new( position: dpi::Position::Logical(dpi::LogicalPosition::new(
bounds.origin.x.into(), bounds.origin.x.into(),

View file

@ -9,11 +9,11 @@ use gpui::{
use crate::ActiveTheme; use crate::ActiveTheme;
#[cfg(not(target_os = "linux"))] #[cfg(not(target_os = "linux"))]
const SHADOW_SIZE: Pixels = Pixels(0.0); const SHADOW_SIZE: Pixels = px(0.0);
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
const SHADOW_SIZE: Pixels = Pixels(12.0); const SHADOW_SIZE: Pixels = px(12.0);
const BORDER_SIZE: Pixels = Pixels(1.0); const BORDER_SIZE: Pixels = px(1.0);
pub(crate) const BORDER_RADIUS: Pixels = Pixels(0.0); pub(crate) const BORDER_RADIUS: Pixels = px(0.0);
/// Create a new window border. /// Create a new window border.
pub fn window_border() -> WindowBorder { pub fn window_border() -> WindowBorder {