code cleanup: Pos2::new -> pos2, Vec2::new -> vec2

This commit is contained in:
Emil Ernerfeldt 2022-07-29 14:34:26 +02:00
parent 105cb4b8f2
commit 51052c08e9
10 changed files with 63 additions and 67 deletions

View file

@ -82,7 +82,7 @@ fn canvas_origin(canvas_id: &str) -> egui::Pos2 {
let rect = canvas_element(canvas_id)
.unwrap()
.get_bounding_client_rect();
egui::Pos2::new(rect.left() as f32, rect.top() as f32)
egui::pos2(rect.left() as f32, rect.top() as f32)
}
pub fn canvas_size_in_points(canvas_id: &str) -> egui::Vec2 {

View file

@ -98,7 +98,7 @@ impl CollapsingState {
ui: &mut Ui,
icon_fn: impl FnOnce(&mut Ui, f32, &Response) + 'static,
) -> Response {
let size = Vec2::new(ui.spacing().indent, ui.spacing().icon_width);
let size = vec2(ui.spacing().indent, ui.spacing().icon_width);
let (_id, rect) = ui.allocate_space(size);
let response = ui.interact(rect, self.id, Sense::click());
if response.clicked() {

View file

@ -92,7 +92,7 @@ impl ComboBox {
/// ) {
/// let rect = egui::Rect::from_center_size(
/// rect.center(),
/// egui::Vec2::new(rect.width() * 0.6, rect.height() * 0.4),
/// egui::vec2(rect.width() * 0.6, rect.height() * 0.4),
/// );
/// ui.painter().add(egui::Shape::convex_polygon(
/// vec![rect.left_top(), rect.right_top(), rect.center_bottom()],

View file

@ -912,7 +912,7 @@ impl Context {
/// How much space is used by panels and windows.
/// You can shrink your egui area to this size and still fit all egui components.
pub fn used_size(&self) -> Vec2 {
self.used_rect().max - Pos2::new(0.0, 0.0)
self.used_rect().max - Pos2::ZERO
}
// ---------------------------------------------------------------------
@ -1200,7 +1200,7 @@ impl Context {
textures.len(),
bytes as f64 * 1e-6
));
let max_preview_size = Vec2::new(48.0, 32.0);
let max_preview_size = vec2(48.0, 32.0);
ui.group(|ui| {
ScrollArea::vertical()
@ -1211,19 +1211,19 @@ impl Context {
Grid::new("textures")
.striped(true)
.num_columns(4)
.spacing(Vec2::new(16.0, 2.0))
.spacing(vec2(16.0, 2.0))
.min_row_height(max_preview_size.y)
.show(ui, |ui| {
for (&texture_id, meta) in textures {
let [w, h] = meta.size;
let mut size = Vec2::new(w as f32, h as f32);
let mut size = vec2(w as f32, h as f32);
size *= (max_preview_size.x / size.x).min(1.0);
size *= (max_preview_size.y / size.y).min(1.0);
ui.image(texture_id, size).on_hover_ui(|ui| {
// show larger on hover
let max_size = 0.5 * ui.ctx().input().screen_rect().size();
let mut size = Vec2::new(w as f32, h as f32);
let mut size = vec2(w as f32, h as f32);
size *= max_size.x / size.x.max(max_size.x);
size *= max_size.y / size.y.max(max_size.y);
ui.image(texture_id, size);

View file

@ -341,15 +341,15 @@ impl Margin {
/// Total margins on both sides
pub fn sum(&self) -> Vec2 {
Vec2::new(self.left + self.right, self.top + self.bottom)
vec2(self.left + self.right, self.top + self.bottom)
}
pub fn left_top(&self) -> Vec2 {
Vec2::new(self.left, self.top)
vec2(self.left, self.top)
}
pub fn right_bottom(&self) -> Vec2 {
Vec2::new(self.right, self.bottom)
vec2(self.right, self.bottom)
}
}

View file

@ -188,8 +188,8 @@ impl BackendPanel {
.on_hover_text("Resize the window to be small like a phone.")
.clicked()
{
// frame.set_window_size(egui::Vec2::new(375.0, 812.0)); // iPhone 12 mini
frame.set_window_size(egui::Vec2::new(375.0, 667.0)); // iPhone SE 2nd gen
// frame.set_window_size(egui::vec2(375.0, 812.0)); // iPhone 12 mini
frame.set_window_size(egui::vec2(375.0, 667.0)); // iPhone SE 2nd gen
ui.close_menu();
}
});

View file

@ -351,7 +351,7 @@ fn pixel_test(ui: &mut Ui) {
let pixels_per_point = ui.ctx().pixels_per_point();
let num_squares: u32 = 8;
let size_pixels = Vec2::new(
let size_pixels = vec2(
((num_squares + 1) * (num_squares + 2) / 2) as f32,
num_squares as f32,
);
@ -379,7 +379,7 @@ fn pixel_test(ui: &mut Ui) {
fn blending_and_feathering_test(ui: &mut Ui) {
ui.label("Some fine lines for testing anti-aliasing and blending:");
let size = Vec2::new(512.0, 512.0);
let size = vec2(512.0, 512.0);
let (response, painter) = ui.allocate_painter(size, Sense::hover());
let rect = response.rect;
@ -399,21 +399,21 @@ fn paint_fine_lines_and_text(painter: &egui::Painter, mut rect: Rect, color: Col
let mut x = 0.0;
for opacity in [1.00, 0.50, 0.25, 0.10, 0.05, 0.02, 0.01, 0.00] {
painter.text(
rect.center_top() + Vec2::new(0.0, x),
rect.center_top() + vec2(0.0, x),
Align2::LEFT_TOP,
format!("{:.0}% white", 100.0 * opacity),
FontId::proportional(16.0),
Color32::WHITE.linear_multiply(opacity),
);
painter.text(
rect.center_top() + Vec2::new(80.0, x),
rect.center_top() + vec2(80.0, x),
Align2::LEFT_TOP,
format!("{:.0}% gray", 100.0 * opacity),
FontId::proportional(16.0),
Color32::GRAY.linear_multiply(opacity),
);
painter.text(
rect.center_top() + Vec2::new(160.0, x),
rect.center_top() + vec2(160.0, x),
Align2::LEFT_TOP,
format!("{:.0}% black", 100.0 * opacity),
FontId::proportional(16.0),
@ -437,7 +437,7 @@ fn paint_fine_lines_and_text(painter: &egui::Painter, mut rect: Rect, color: Col
painter.add(egui::epaint::CubicBezierShape::from_points_stroke(
[
rect.left_top() + Vec2::new(16.0, 0.0),
rect.left_top() + vec2(16.0, 0.0),
rect.right_top(),
rect.right_center(),
rect.right_bottom(),

View file

@ -103,7 +103,7 @@ impl Default for ManualLayoutTest {
fn default() -> Self {
Self {
widget_offset: egui::Vec2::splat(150.0),
widget_size: egui::Vec2::new(200.0, 100.0),
widget_size: egui::vec2(200.0, 100.0),
widget_type: WidgetType::Button,
text_edit_contents: crate::LOREM_IPSUM.to_owned(),
}

View file

@ -10,7 +10,7 @@ fn main() {
let png_data = include_bytes!("../../examples/retained_image/src/rust-logo-256x256.png");
let image = load_glium_image(png_data);
let image_size = egui::Vec2::new(image.width as f32, image.height as f32);
let image_size = egui::vec2(image.width as f32, image.height as f32);
// Load to gpu memory
let glium_texture = glium::texture::SrgbTexture2d::new(&display, image).unwrap();
// Allow us to share the texture with egui:
@ -18,7 +18,7 @@ fn main() {
// Allocate egui's texture id for GL texture
let texture_id = egui_glium.painter.register_native_texture(glium_texture);
// Setup button image size for reasonable image size for button container.
let button_image_size = egui::Vec2::new(32_f32, 32_f32);
let button_image_size = egui::vec2(32_f32, 32_f32);
event_loop.run(move |event, _, control_flow| {
let mut redraw = || {

View file

@ -856,10 +856,10 @@ mod tests {
fn test_cubic_bounding_box() {
let curve = CubicBezierShape {
points: [
Pos2::new(10.0, 10.0),
Pos2::new(110.0, 170.0),
Pos2::new(180.0, 30.0),
Pos2::new(270.0, 210.0),
pos2(10.0, 10.0),
pos2(110.0, 170.0),
pos2(180.0, 30.0),
pos2(270.0, 210.0),
],
closed: false,
fill: Default::default(),
@ -874,10 +874,10 @@ mod tests {
let curve = CubicBezierShape {
points: [
Pos2::new(10.0, 10.0),
Pos2::new(110.0, 170.0),
Pos2::new(270.0, 210.0),
Pos2::new(180.0, 30.0),
pos2(10.0, 10.0),
pos2(110.0, 170.0),
pos2(270.0, 210.0),
pos2(180.0, 30.0),
],
closed: false,
fill: Default::default(),
@ -892,10 +892,10 @@ mod tests {
let curve = CubicBezierShape {
points: [
Pos2::new(110.0, 170.0),
Pos2::new(10.0, 10.0),
Pos2::new(270.0, 210.0),
Pos2::new(180.0, 30.0),
pos2(110.0, 170.0),
pos2(10.0, 10.0),
pos2(270.0, 210.0),
pos2(180.0, 30.0),
],
closed: false,
fill: Default::default(),
@ -913,10 +913,10 @@ mod tests {
fn test_cubic_different_tolerance_flattening() {
let curve = CubicBezierShape {
points: [
Pos2::new(0.0, 0.0),
Pos2::new(100.0, 0.0),
Pos2::new(100.0, 100.0),
Pos2::new(100.0, 200.0),
pos2(0.0, 0.0),
pos2(100.0, 0.0),
pos2(100.0, 100.0),
pos2(100.0, 200.0),
],
closed: false,
fill: Default::default(),
@ -963,10 +963,10 @@ mod tests {
fn test_cubic_different_shape_flattening() {
let curve = CubicBezierShape {
points: [
Pos2::new(90.0, 110.0),
Pos2::new(30.0, 170.0),
Pos2::new(210.0, 170.0),
Pos2::new(170.0, 110.0),
pos2(90.0, 110.0),
pos2(30.0, 170.0),
pos2(210.0, 170.0),
pos2(170.0, 110.0),
],
closed: false,
fill: Default::default(),
@ -982,10 +982,10 @@ mod tests {
let curve = CubicBezierShape {
points: [
Pos2::new(90.0, 110.0),
Pos2::new(90.0, 170.0),
Pos2::new(170.0, 170.0),
Pos2::new(170.0, 110.0),
pos2(90.0, 110.0),
pos2(90.0, 170.0),
pos2(170.0, 170.0),
pos2(170.0, 110.0),
],
closed: false,
fill: Default::default(),
@ -1001,10 +1001,10 @@ mod tests {
let curve = CubicBezierShape {
points: [
Pos2::new(90.0, 110.0),
Pos2::new(110.0, 170.0),
Pos2::new(150.0, 170.0),
Pos2::new(170.0, 110.0),
pos2(90.0, 110.0),
pos2(110.0, 170.0),
pos2(150.0, 170.0),
pos2(170.0, 110.0),
],
closed: false,
fill: Default::default(),
@ -1020,10 +1020,10 @@ mod tests {
let curve = CubicBezierShape {
points: [
Pos2::new(90.0, 110.0),
Pos2::new(110.0, 170.0),
Pos2::new(230.0, 110.0),
Pos2::new(170.0, 110.0),
pos2(90.0, 110.0),
pos2(110.0, 170.0),
pos2(230.0, 110.0),
pos2(170.0, 110.0),
],
closed: false,
fill: Default::default(),
@ -1039,10 +1039,10 @@ mod tests {
let curve = CubicBezierShape {
points: [
Pos2::new(90.0, 110.0),
Pos2::new(110.0, 170.0),
Pos2::new(210.0, 70.0),
Pos2::new(170.0, 110.0),
pos2(90.0, 110.0),
pos2(110.0, 170.0),
pos2(210.0, 70.0),
pos2(170.0, 110.0),
],
closed: false,
fill: Default::default(),
@ -1058,10 +1058,10 @@ mod tests {
let curve = CubicBezierShape {
points: [
Pos2::new(90.0, 110.0),
Pos2::new(110.0, 170.0),
Pos2::new(150.0, 50.0),
Pos2::new(170.0, 110.0),
pos2(90.0, 110.0),
pos2(110.0, 170.0),
pos2(150.0, 50.0),
pos2(170.0, 110.0),
],
closed: false,
fill: Default::default(),
@ -1079,11 +1079,7 @@ mod tests {
#[test]
fn test_quadrtic_flattening() {
let curve = QuadraticBezierShape {
points: [
Pos2::new(0.0, 0.0),
Pos2::new(80.0, 200.0),
Pos2::new(100.0, 30.0),
],
points: [pos2(0.0, 0.0), pos2(80.0, 200.0), pos2(100.0, 30.0)],
closed: false,
fill: Default::default(),
stroke: Default::default(),