Move core::Image::clip_bounds to graphics::Image

This commit is contained in:
Héctor Ramón Jiménez 2025-10-28 19:44:46 +01:00
parent 3cc5bd5dbc
commit 7c11ccb046
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
16 changed files with 189 additions and 88 deletions

View file

@ -16,22 +16,17 @@ pub struct Image<H = Handle> {
/// The handle of the image.
pub handle: H,
/// The clip bounds of the [`Image`].
///
/// Anything outside this [`Rectangle`] will not be drawn.
pub clip_bounds: Rectangle,
/// The border radius of the [`Image`].
///
/// Currently, this will only be applied to the `clip_bounds`.
pub border_radius: border::Radius,
/// The filter method of the image.
pub filter_method: FilterMethod,
/// The rotation to be applied to the image; on its center.
pub rotation: Radians,
/// The border radius of the [`Image`].
///
/// Currently, this will only be applied to the `clip_bounds`.
pub border_radius: border::Radius,
/// The opacity of the image.
///
/// 0 means transparent. 1 means opaque.
@ -49,10 +44,9 @@ impl Image<Handle> {
pub fn new(handle: impl Into<Handle>) -> Self {
Self {
handle: handle.into(),
clip_bounds: Rectangle::INFINITE,
border_radius: border::Radius::default(),
filter_method: FilterMethod::default(),
rotation: Radians(0.0),
border_radius: border::Radius::default(),
opacity: 1.0,
snap: false,
}
@ -307,5 +301,10 @@ pub trait Renderer: crate::Renderer {
fn measure_image(&self, handle: &Self::Handle) -> Size<u32>;
/// Draws an [`Image`] inside the provided `bounds`.
fn draw_image(&mut self, image: Image<Self::Handle>, bounds: Rectangle);
fn draw_image(
&mut self,
image: Image<Self::Handle>,
bounds: Rectangle,
clip_bounds: Rectangle,
);
}

View file

@ -217,7 +217,13 @@ impl image::Renderer for () {
Size::default()
}
fn draw_image(&mut self, _image: Image, _bounds: Rectangle) {}
fn draw_image(
&mut self,
_image: Image,
_bounds: Rectangle,
_clip_bounds: Rectangle,
) {
}
}
impl svg::Renderer for () {
@ -225,5 +231,11 @@ impl svg::Renderer for () {
Size::default()
}
fn draw_svg(&mut self, _svg: svg::Svg, _bounds: Rectangle) {}
fn draw_svg(
&mut self,
_svg: svg::Svg,
_bounds: Rectangle,
_clip_bounds: Rectangle,
) {
}
}

View file

@ -155,5 +155,5 @@ pub trait Renderer: crate::Renderer {
fn measure_svg(&self, handle: &Handle) -> Size<u32>;
/// Draws an SVG with the given [`Handle`], an optional [`Color`] filter, and inside the provided `bounds`.
fn draw_svg(&mut self, svg: Svg, bounds: Rectangle);
fn draw_svg(&mut self, svg: Svg, bounds: Rectangle, clip_bounds: Rectangle);
}