mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-31 07:37:24 +00:00
Python: Some Image docs
This commit is contained in:
parent
c46846b3cb
commit
30aefd4957
1 changed files with 8 additions and 0 deletions
|
@ -3,6 +3,8 @@
|
|||
|
||||
use pyo3::prelude::*;
|
||||
|
||||
/// Image objects can be set on Slint Image elements for display. Construct Image objects from a path to an
|
||||
/// image file on disk, using `Image.load_from_path`.
|
||||
#[pyclass(unsendable, name = "Image")]
|
||||
pub struct PyImage {
|
||||
pub image: slint_interpreter::Image,
|
||||
|
@ -15,32 +17,38 @@ impl PyImage {
|
|||
Ok(Self { image: Default::default() })
|
||||
}
|
||||
|
||||
/// The size of the image as tuple of `width` and `height`.
|
||||
#[getter]
|
||||
fn size(&self) -> PyResult<(u32, u32)> {
|
||||
Ok(self.image.size().into())
|
||||
}
|
||||
|
||||
/// The width of the image in pixels.
|
||||
#[getter]
|
||||
fn width(&self) -> PyResult<u32> {
|
||||
Ok(self.image.size().width)
|
||||
}
|
||||
|
||||
/// The height of the image in pixels.
|
||||
#[getter]
|
||||
fn height(&self) -> PyResult<u32> {
|
||||
Ok(self.image.size().height)
|
||||
}
|
||||
|
||||
/// The path of the image if it was loaded from disk, or None.
|
||||
#[getter]
|
||||
fn path(&self) -> PyResult<Option<&std::path::Path>> {
|
||||
Ok(self.image.path())
|
||||
}
|
||||
|
||||
/// Loads the image from the specified path. Returns None if the image can't be loaded.
|
||||
#[staticmethod]
|
||||
fn load_from_path(path: std::path::PathBuf) -> Result<Self, crate::errors::PyLoadImageError> {
|
||||
let image = slint_interpreter::Image::load_from_path(&path)?;
|
||||
Ok(Self { image })
|
||||
}
|
||||
|
||||
/// Creates a new image from a string that describes the image in SVG format.
|
||||
#[staticmethod]
|
||||
fn load_from_svg_data(data: &[u8]) -> Result<Self, crate::errors::PyLoadImageError> {
|
||||
let image = slint_interpreter::Image::load_from_svg_data(data)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue