Allow distinct corner radii for images
This commit is contained in:
parent
84dc4090bd
commit
40f478937e
5 changed files with 21 additions and 11 deletions
|
@ -103,7 +103,7 @@ impl<V: View> Element<V> for Image {
|
||||||
scene.push_image(scene::Image {
|
scene.push_image(scene::Image {
|
||||||
bounds,
|
bounds,
|
||||||
border: self.style.border,
|
border: self.style.border,
|
||||||
corner_radius: self.style.corner_radius,
|
corner_radii: self.style.corner_radius.into(),
|
||||||
grayscale: self.style.grayscale,
|
grayscale: self.style.grayscale,
|
||||||
data: data.clone(),
|
data: data.clone(),
|
||||||
});
|
});
|
||||||
|
|
|
@ -741,7 +741,7 @@ impl Renderer {
|
||||||
for image in images {
|
for image in images {
|
||||||
let origin = image.bounds.origin() * scale_factor;
|
let origin = image.bounds.origin() * scale_factor;
|
||||||
let target_size = image.bounds.size() * scale_factor;
|
let target_size = image.bounds.size() * scale_factor;
|
||||||
let corner_radius = image.corner_radius * scale_factor;
|
let corner_radii = image.corner_radii * scale_factor;
|
||||||
let border_width = image.border.width * scale_factor;
|
let border_width = image.border.width * scale_factor;
|
||||||
let (alloc_id, atlas_bounds) = self.image_cache.render(&image.data);
|
let (alloc_id, atlas_bounds) = self.image_cache.render(&image.data);
|
||||||
images_by_atlas
|
images_by_atlas
|
||||||
|
@ -757,7 +757,10 @@ impl Renderer {
|
||||||
border_bottom: border_width * (image.border.bottom as usize as f32),
|
border_bottom: border_width * (image.border.bottom as usize as f32),
|
||||||
border_left: border_width * (image.border.left as usize as f32),
|
border_left: border_width * (image.border.left as usize as f32),
|
||||||
border_color: image.border.color.to_uchar4(),
|
border_color: image.border.color.to_uchar4(),
|
||||||
corner_radius,
|
corner_radius_top_left: corner_radii.top_left,
|
||||||
|
corner_radius_top_right: corner_radii.top_right,
|
||||||
|
corner_radius_bottom_right: corner_radii.bottom_right,
|
||||||
|
corner_radius_bottom_left: corner_radii.bottom_left,
|
||||||
grayscale: image.grayscale as u8,
|
grayscale: image.grayscale as u8,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -780,7 +783,10 @@ impl Renderer {
|
||||||
border_bottom: 0.,
|
border_bottom: 0.,
|
||||||
border_left: 0.,
|
border_left: 0.,
|
||||||
border_color: Default::default(),
|
border_color: Default::default(),
|
||||||
corner_radius: 0.,
|
corner_radius_top_left: 0.,
|
||||||
|
corner_radius_top_right: 0.,
|
||||||
|
corner_radius_bottom_right: 0.,
|
||||||
|
corner_radius_bottom_left: 0.,
|
||||||
grayscale: false as u8,
|
grayscale: false as u8,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -92,7 +92,10 @@ typedef struct {
|
||||||
float border_bottom;
|
float border_bottom;
|
||||||
float border_left;
|
float border_left;
|
||||||
vector_uchar4 border_color;
|
vector_uchar4 border_color;
|
||||||
float corner_radius;
|
float corner_radius_top_left;
|
||||||
|
float corner_radius_top_right;
|
||||||
|
float corner_radius_bottom_right;
|
||||||
|
float corner_radius_bottom_left;
|
||||||
uint8_t grayscale;
|
uint8_t grayscale;
|
||||||
} GPUIImage;
|
} GPUIImage;
|
||||||
|
|
||||||
|
|
|
@ -273,10 +273,10 @@ vertex QuadFragmentInput image_vertex(
|
||||||
image.border_bottom,
|
image.border_bottom,
|
||||||
image.border_left,
|
image.border_left,
|
||||||
coloru_to_colorf(image.border_color),
|
coloru_to_colorf(image.border_color),
|
||||||
image.corner_radius,
|
image.corner_radius_top_left,
|
||||||
image.corner_radius,
|
image.corner_radius_top_right,
|
||||||
image.corner_radius,
|
image.corner_radius_bottom_right,
|
||||||
image.corner_radius,
|
image.corner_radius_bottom_left,
|
||||||
image.grayscale,
|
image.grayscale,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ mod mouse_region;
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
|
use derive_more::Mul;
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
@ -68,7 +69,7 @@ pub struct Quad {
|
||||||
pub corner_radii: CornerRadii,
|
pub corner_radii: CornerRadii,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug, Mul, Clone, Copy)]
|
||||||
pub struct CornerRadii {
|
pub struct CornerRadii {
|
||||||
pub top_left: f32,
|
pub top_left: f32,
|
||||||
pub top_right: f32,
|
pub top_right: f32,
|
||||||
|
@ -196,7 +197,7 @@ pub struct PathVertex {
|
||||||
pub struct Image {
|
pub struct Image {
|
||||||
pub bounds: RectF,
|
pub bounds: RectF,
|
||||||
pub border: Border,
|
pub border: Border,
|
||||||
pub corner_radius: f32,
|
pub corner_radii: CornerRadii,
|
||||||
pub grayscale: bool,
|
pub grayscale: bool,
|
||||||
pub data: Arc<ImageData>,
|
pub data: Arc<ImageData>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue