Draft new layout API
This commit is contained in:
parent
839e039dbf
commit
2303111e09
30 changed files with 247 additions and 596 deletions
|
|
@ -1,28 +1,18 @@
|
|||
use crate::{Primitive, Renderer};
|
||||
use iced_native::{image, Image, Layout, Length, MouseCursor, Node, Style};
|
||||
use iced_native::{image, layout, Image, Layout, MouseCursor, Rectangle};
|
||||
|
||||
impl image::Renderer for Renderer {
|
||||
fn node(&self, image: &Image) -> Node {
|
||||
let (width, height) = self.image_pipeline.dimensions(&image.path);
|
||||
|
||||
let aspect_ratio = width as f32 / height as f32;
|
||||
|
||||
let mut style = Style::default().align_self(image.align_self);
|
||||
|
||||
// TODO: Deal with additional cases
|
||||
style = match (image.width, image.height) {
|
||||
(Length::Units(width), _) => style.width(image.width).height(
|
||||
Length::Units((width as f32 / aspect_ratio).round() as u16),
|
||||
),
|
||||
(_, _) => style
|
||||
.width(Length::Units(width as u16))
|
||||
.height(Length::Units(height as u16)),
|
||||
};
|
||||
|
||||
Node::new(style)
|
||||
fn layout(&self, image: &Image, limits: &layout::Limits) -> Layout {
|
||||
// TODO
|
||||
Layout::new(Rectangle {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
width: 0.0,
|
||||
height: 0.0,
|
||||
})
|
||||
}
|
||||
|
||||
fn draw(&mut self, image: &Image, layout: Layout<'_>) -> Self::Output {
|
||||
fn draw(&mut self, image: &Image, layout: &Layout) -> Self::Output {
|
||||
(
|
||||
Primitive::Image {
|
||||
path: image.path.clone(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue