Refactor Viewport
and Compositor
This commit is contained in:
parent
720e7756f2
commit
a1a5fcfd46
@ -125,17 +125,29 @@ impl Rectangle<f32> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Rounds the [`Rectangle`] to __unsigned__ integer coordinates.
|
||||||
|
///
|
||||||
|
/// [`Rectangle`]: struct.Rectangle.html
|
||||||
|
pub fn round(self) -> Rectangle<u32> {
|
||||||
|
Rectangle {
|
||||||
|
x: self.x as u32,
|
||||||
|
y: self.y as u32,
|
||||||
|
width: (self.width + 0.5).round() as u32,
|
||||||
|
height: (self.height + 0.5).round() as u32,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Mul<f32> for Rectangle<u32> {
|
impl std::ops::Mul<f32> for Rectangle<f32> {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
fn mul(self, scale: f32) -> Self {
|
fn mul(self, scale: f32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
x: (self.x as f32 * scale).round() as u32,
|
x: self.x as f32 * scale,
|
||||||
y: (self.y as f32 * scale).round() as u32,
|
y: self.y as f32 * scale,
|
||||||
width: (self.width as f32 * scale).round() as u32,
|
width: self.width * scale,
|
||||||
height: (self.height as f32 * scale).round() as u32,
|
height: self.height * scale,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,17 +163,6 @@ impl From<Rectangle<u32>> for Rectangle<f32> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Rectangle<f32>> for Rectangle<u32> {
|
|
||||||
fn from(rectangle: Rectangle<f32>) -> Rectangle<u32> {
|
|
||||||
Rectangle {
|
|
||||||
x: rectangle.x as u32,
|
|
||||||
y: rectangle.y as u32,
|
|
||||||
width: (rectangle.width + 0.5).round() as u32,
|
|
||||||
height: (rectangle.height + 0.5).round() as u32,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> std::ops::Add<Vector<T>> for Rectangle<T>
|
impl<T> std::ops::Add<Vector<T>> for Rectangle<T>
|
||||||
where
|
where
|
||||||
T: std::ops::Add<Output = T>,
|
T: std::ops::Add<Output = T>,
|
||||||
|
@ -2,11 +2,20 @@ use std::f32;
|
|||||||
|
|
||||||
/// An amount of space in 2 dimensions.
|
/// An amount of space in 2 dimensions.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Size {
|
pub struct Size<T = f32> {
|
||||||
/// The width.
|
/// The width.
|
||||||
pub width: f32,
|
pub width: T,
|
||||||
/// The height.
|
/// The height.
|
||||||
pub height: f32,
|
pub height: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Size<T> {
|
||||||
|
/// Creates a new [`Size`] with the given width and height.
|
||||||
|
///
|
||||||
|
/// [`Size`]: struct.Size.html
|
||||||
|
pub const fn new(width: T, height: T) -> Self {
|
||||||
|
Size { width, height }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Size {
|
impl Size {
|
||||||
@ -25,13 +34,6 @@ impl Size {
|
|||||||
/// [`Size`]: struct.Size.html
|
/// [`Size`]: struct.Size.html
|
||||||
pub const INFINITY: Size = Size::new(f32::INFINITY, f32::INFINITY);
|
pub const INFINITY: Size = Size::new(f32::INFINITY, f32::INFINITY);
|
||||||
|
|
||||||
/// Creates a new [`Size`] with the given width and height.
|
|
||||||
///
|
|
||||||
/// [`Size`]: struct.Size.html
|
|
||||||
pub const fn new(width: f32, height: f32) -> Self {
|
|
||||||
Size { width, height }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Increments the [`Size`] to account for the given padding.
|
/// Increments the [`Size`] to account for the given padding.
|
||||||
///
|
///
|
||||||
/// [`Size`]: struct.Size.html
|
/// [`Size`]: struct.Size.html
|
||||||
|
@ -4,9 +4,7 @@ mod scene;
|
|||||||
use controls::Controls;
|
use controls::Controls;
|
||||||
use scene::Scene;
|
use scene::Scene;
|
||||||
|
|
||||||
use iced_wgpu::{
|
use iced_wgpu::{wgpu, Backend, Primitive, Renderer, Settings, Viewport};
|
||||||
wgpu, window::SwapChain, Backend, Primitive, Renderer, Settings, Target,
|
|
||||||
};
|
|
||||||
use iced_winit::{
|
use iced_winit::{
|
||||||
futures, mouse, winit, Cache, Clipboard, Size, UserInterface,
|
futures, mouse, winit, Cache, Clipboard, Size, UserInterface,
|
||||||
};
|
};
|
||||||
@ -22,8 +20,12 @@ pub fn main() {
|
|||||||
// Initialize winit
|
// Initialize winit
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
let window = winit::window::Window::new(&event_loop).unwrap();
|
let window = winit::window::Window::new(&event_loop).unwrap();
|
||||||
let mut logical_size =
|
|
||||||
window.inner_size().to_logical(window.scale_factor());
|
let physical_size = window.inner_size();
|
||||||
|
let mut viewport = Viewport::with_physical_size(
|
||||||
|
Size::new(physical_size.width, physical_size.height),
|
||||||
|
window.scale_factor(),
|
||||||
|
);
|
||||||
let mut modifiers = ModifiersState::default();
|
let mut modifiers = ModifiersState::default();
|
||||||
|
|
||||||
// Initialize WGPU
|
// Initialize WGPU
|
||||||
@ -55,7 +57,16 @@ pub fn main() {
|
|||||||
let mut swap_chain = {
|
let mut swap_chain = {
|
||||||
let size = window.inner_size();
|
let size = window.inner_size();
|
||||||
|
|
||||||
SwapChain::new(&device, &surface, format, size.width, size.height)
|
device.create_swap_chain(
|
||||||
|
&surface,
|
||||||
|
&wgpu::SwapChainDescriptor {
|
||||||
|
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
||||||
|
format: format,
|
||||||
|
width: size.width,
|
||||||
|
height: size.height,
|
||||||
|
present_mode: wgpu::PresentMode::Mailbox,
|
||||||
|
},
|
||||||
|
)
|
||||||
};
|
};
|
||||||
let mut resized = false;
|
let mut resized = false;
|
||||||
|
|
||||||
@ -83,8 +94,11 @@ pub fn main() {
|
|||||||
modifiers = new_modifiers;
|
modifiers = new_modifiers;
|
||||||
}
|
}
|
||||||
WindowEvent::Resized(new_size) => {
|
WindowEvent::Resized(new_size) => {
|
||||||
logical_size =
|
viewport = Viewport::with_physical_size(
|
||||||
new_size.to_logical(window.scale_factor());
|
Size::new(new_size.width, new_size.height),
|
||||||
|
window.scale_factor(),
|
||||||
|
);
|
||||||
|
|
||||||
resized = true;
|
resized = true;
|
||||||
}
|
}
|
||||||
WindowEvent::CloseRequested => {
|
WindowEvent::CloseRequested => {
|
||||||
@ -117,7 +131,7 @@ pub fn main() {
|
|||||||
// First, we build our user interface.
|
// First, we build our user interface.
|
||||||
let mut user_interface = UserInterface::build(
|
let mut user_interface = UserInterface::build(
|
||||||
controls.view(&scene),
|
controls.view(&scene),
|
||||||
Size::new(logical_size.width, logical_size.height),
|
viewport.logical_size(),
|
||||||
cache.take().unwrap(),
|
cache.take().unwrap(),
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
);
|
);
|
||||||
@ -151,7 +165,7 @@ pub fn main() {
|
|||||||
// user interface.
|
// user interface.
|
||||||
UserInterface::build(
|
UserInterface::build(
|
||||||
controls.view(&scene),
|
controls.view(&scene),
|
||||||
Size::new(logical_size.width, logical_size.height),
|
viewport.logical_size(),
|
||||||
cache.take().unwrap(),
|
cache.take().unwrap(),
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
)
|
)
|
||||||
@ -170,17 +184,19 @@ pub fn main() {
|
|||||||
if resized {
|
if resized {
|
||||||
let size = window.inner_size();
|
let size = window.inner_size();
|
||||||
|
|
||||||
swap_chain = SwapChain::new(
|
swap_chain = device.create_swap_chain(
|
||||||
&device,
|
|
||||||
&surface,
|
&surface,
|
||||||
format,
|
&wgpu::SwapChainDescriptor {
|
||||||
size.width,
|
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
||||||
size.height,
|
format: format,
|
||||||
|
width: size.width,
|
||||||
|
height: size.height,
|
||||||
|
present_mode: wgpu::PresentMode::Mailbox,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let (frame, viewport) =
|
let frame = swap_chain.get_next_texture().expect("Next frame");
|
||||||
swap_chain.next_frame().expect("Next frame");
|
|
||||||
|
|
||||||
let mut encoder = device.create_command_encoder(
|
let mut encoder = device.create_command_encoder(
|
||||||
&wgpu::CommandEncoderDescriptor { label: None },
|
&wgpu::CommandEncoderDescriptor { label: None },
|
||||||
@ -193,12 +209,9 @@ pub fn main() {
|
|||||||
let mouse_interaction = renderer.backend_mut().draw(
|
let mouse_interaction = renderer.backend_mut().draw(
|
||||||
&mut device,
|
&mut device,
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
Target {
|
&frame.view,
|
||||||
texture: &frame.view,
|
&viewport,
|
||||||
viewport,
|
|
||||||
},
|
|
||||||
&output,
|
&output,
|
||||||
window.scale_factor(),
|
|
||||||
&["Some debug information!"],
|
&["Some debug information!"],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -47,12 +47,10 @@ impl Backend {
|
|||||||
gl: &glow::Context,
|
gl: &glow::Context,
|
||||||
viewport: &Viewport,
|
viewport: &Viewport,
|
||||||
(primitive, mouse_interaction): &(Primitive, mouse::Interaction),
|
(primitive, mouse_interaction): &(Primitive, mouse::Interaction),
|
||||||
scale_factor: f64,
|
|
||||||
overlay_text: &[T],
|
overlay_text: &[T],
|
||||||
) -> mouse::Interaction {
|
) -> mouse::Interaction {
|
||||||
let (width, height) = viewport.dimensions();
|
let viewport_size = viewport.physical_size();
|
||||||
let scale_factor = scale_factor as f32;
|
let projection = viewport.projection();
|
||||||
let transformation = viewport.transformation();
|
|
||||||
|
|
||||||
let mut layers = Layer::generate(primitive, viewport);
|
let mut layers = Layer::generate(primitive, viewport);
|
||||||
layers.push(Layer::overlay(overlay_text, viewport));
|
layers.push(Layer::overlay(overlay_text, viewport));
|
||||||
@ -60,12 +58,11 @@ impl Backend {
|
|||||||
for layer in layers {
|
for layer in layers {
|
||||||
self.flush(
|
self.flush(
|
||||||
gl,
|
gl,
|
||||||
viewport,
|
viewport.scale_factor() as f32,
|
||||||
scale_factor,
|
projection,
|
||||||
transformation,
|
|
||||||
&layer,
|
&layer,
|
||||||
width,
|
viewport_size.width,
|
||||||
height,
|
viewport_size.height,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,19 +72,18 @@ impl Backend {
|
|||||||
fn flush(
|
fn flush(
|
||||||
&mut self,
|
&mut self,
|
||||||
gl: &glow::Context,
|
gl: &glow::Context,
|
||||||
viewport: &Viewport,
|
|
||||||
scale_factor: f32,
|
scale_factor: f32,
|
||||||
transformation: Transformation,
|
transformation: Transformation,
|
||||||
layer: &Layer<'_>,
|
layer: &Layer<'_>,
|
||||||
target_width: u32,
|
target_width: u32,
|
||||||
target_height: u32,
|
target_height: u32,
|
||||||
) {
|
) {
|
||||||
let bounds = layer.bounds * scale_factor;
|
let bounds = (layer.bounds * scale_factor).round();
|
||||||
|
|
||||||
if !layer.quads.is_empty() {
|
if !layer.quads.is_empty() {
|
||||||
self.quad_pipeline.draw(
|
self.quad_pipeline.draw(
|
||||||
gl,
|
gl,
|
||||||
viewport,
|
target_height,
|
||||||
&layer.quads,
|
&layer.quads,
|
||||||
transformation,
|
transformation,
|
||||||
scale_factor,
|
scale_factor,
|
||||||
@ -175,8 +171,7 @@ impl Backend {
|
|||||||
transformation,
|
transformation,
|
||||||
glow_glyph::Region {
|
glow_glyph::Region {
|
||||||
x: bounds.x,
|
x: bounds.x,
|
||||||
y: viewport.height()
|
y: target_height - (bounds.y + bounds.height),
|
||||||
- (bounds.y + bounds.height).min(viewport.height()),
|
|
||||||
width: bounds.width,
|
width: bounds.width,
|
||||||
height: bounds.height,
|
height: bounds.height,
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::{Transformation, Viewport};
|
use crate::Transformation;
|
||||||
use glow::HasContext;
|
use glow::HasContext;
|
||||||
use iced_graphics::layer;
|
use iced_graphics::layer;
|
||||||
use iced_native::Rectangle;
|
use iced_native::Rectangle;
|
||||||
@ -54,7 +54,7 @@ impl Pipeline {
|
|||||||
pub fn draw(
|
pub fn draw(
|
||||||
&mut self,
|
&mut self,
|
||||||
gl: &glow::Context,
|
gl: &glow::Context,
|
||||||
viewport: &Viewport,
|
target_height: u32,
|
||||||
instances: &[layer::Quad],
|
instances: &[layer::Quad],
|
||||||
transformation: Transformation,
|
transformation: Transformation,
|
||||||
scale: f32,
|
scale: f32,
|
||||||
@ -64,9 +64,7 @@ impl Pipeline {
|
|||||||
gl.enable(glow::SCISSOR_TEST);
|
gl.enable(glow::SCISSOR_TEST);
|
||||||
gl.scissor(
|
gl.scissor(
|
||||||
bounds.x as i32,
|
bounds.x as i32,
|
||||||
(viewport.height()
|
(target_height - (bounds.y + bounds.height)) as i32,
|
||||||
- (bounds.y + bounds.height).min(viewport.height()))
|
|
||||||
as i32,
|
|
||||||
bounds.width as i32,
|
bounds.width as i32,
|
||||||
bounds.height as i32,
|
bounds.height as i32,
|
||||||
);
|
);
|
||||||
|
@ -13,11 +13,11 @@ pub struct Compositor {
|
|||||||
gl: Option<glow::Context>,
|
gl: Option<glow::Context>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl iced_native::window::Compositor for Compositor {
|
impl iced_graphics::window::Compositor for Compositor {
|
||||||
type Settings = Settings;
|
type Settings = Settings;
|
||||||
type Renderer = Renderer;
|
type Renderer = Renderer;
|
||||||
type Surface = ();
|
type Surface = ();
|
||||||
type SwapChain = Viewport;
|
type SwapChain = ();
|
||||||
|
|
||||||
fn new(_settings: Self::Settings) -> Self {
|
fn new(_settings: Self::Settings) -> Self {
|
||||||
let connection = surfman::Connection::new().expect("Create connection");
|
let connection = surfman::Connection::new().expect("Create connection");
|
||||||
@ -133,16 +133,14 @@ impl iced_native::window::Compositor for Compositor {
|
|||||||
gl.enable(glow::BLEND);
|
gl.enable(glow::BLEND);
|
||||||
gl.blend_func(glow::SRC_ALPHA, glow::ONE_MINUS_SRC_ALPHA);
|
gl.blend_func(glow::SRC_ALPHA, glow::ONE_MINUS_SRC_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
Viewport::new(width, height)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw<T: AsRef<str>>(
|
fn draw<T: AsRef<str>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
renderer: &mut Self::Renderer,
|
renderer: &mut Self::Renderer,
|
||||||
swap_chain: &mut Self::SwapChain,
|
swap_chain: &mut Self::SwapChain,
|
||||||
|
viewport: &Viewport,
|
||||||
output: &<Self::Renderer as iced_native::Renderer>::Output,
|
output: &<Self::Renderer as iced_native::Renderer>::Output,
|
||||||
scale_factor: f64,
|
|
||||||
overlay: &[T],
|
overlay: &[T],
|
||||||
) -> mouse::Interaction {
|
) -> mouse::Interaction {
|
||||||
let gl = self.gl.as_ref().unwrap();
|
let gl = self.gl.as_ref().unwrap();
|
||||||
@ -151,13 +149,7 @@ impl iced_native::window::Compositor for Compositor {
|
|||||||
gl.clear(glow::COLOR_BUFFER_BIT);
|
gl.clear(glow::COLOR_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mouse = renderer.backend_mut().draw(
|
let mouse = renderer.backend_mut().draw(gl, viewport, output, overlay);
|
||||||
gl,
|
|
||||||
swap_chain,
|
|
||||||
output,
|
|
||||||
scale_factor,
|
|
||||||
overlay,
|
|
||||||
);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut surface = self
|
let mut surface = self
|
||||||
|
@ -13,6 +13,7 @@ font-icons = []
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
bytemuck = "1.2"
|
bytemuck = "1.2"
|
||||||
glam = "0.8"
|
glam = "0.8"
|
||||||
|
raw-window-handle = "0.3"
|
||||||
|
|
||||||
[dependencies.iced_native]
|
[dependencies.iced_native]
|
||||||
version = "0.2"
|
version = "0.2"
|
||||||
|
@ -7,7 +7,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub struct Layer<'a> {
|
pub struct Layer<'a> {
|
||||||
pub bounds: Rectangle<u32>,
|
pub bounds: Rectangle,
|
||||||
pub quads: Vec<Quad>,
|
pub quads: Vec<Quad>,
|
||||||
pub meshes: Vec<Mesh<'a>>,
|
pub meshes: Vec<Mesh<'a>>,
|
||||||
pub text: Vec<Text<'a>>,
|
pub text: Vec<Text<'a>>,
|
||||||
@ -15,7 +15,7 @@ pub struct Layer<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Layer<'a> {
|
impl<'a> Layer<'a> {
|
||||||
pub fn new(bounds: Rectangle<u32>) -> Self {
|
pub fn new(bounds: Rectangle) -> Self {
|
||||||
Self {
|
Self {
|
||||||
bounds,
|
bounds,
|
||||||
quads: Vec::new(),
|
quads: Vec::new(),
|
||||||
@ -26,14 +26,8 @@ impl<'a> Layer<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn overlay(lines: &'a [impl AsRef<str>], viewport: &Viewport) -> Self {
|
pub fn overlay(lines: &'a [impl AsRef<str>], viewport: &Viewport) -> Self {
|
||||||
let (width, height) = viewport.dimensions();
|
let mut overlay =
|
||||||
|
Layer::new(Rectangle::with_size(viewport.logical_size()));
|
||||||
let mut overlay = Layer::new(Rectangle {
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
});
|
|
||||||
|
|
||||||
for (i, line) in lines.iter().enumerate() {
|
for (i, line) in lines.iter().enumerate() {
|
||||||
let text = Text {
|
let text = Text {
|
||||||
@ -61,28 +55,14 @@ impl<'a> Layer<'a> {
|
|||||||
overlay
|
overlay
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn intersection(
|
|
||||||
&self,
|
|
||||||
rectangle: Rectangle,
|
|
||||||
) -> Option<Rectangle<u32>> {
|
|
||||||
let layer_bounds: Rectangle<f32> = self.bounds.into();
|
|
||||||
|
|
||||||
layer_bounds.intersection(&rectangle).map(Into::into)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn generate(
|
pub fn generate(
|
||||||
primitive: &'a Primitive,
|
primitive: &'a Primitive,
|
||||||
viewport: &Viewport,
|
viewport: &Viewport,
|
||||||
) -> Vec<Self> {
|
) -> Vec<Self> {
|
||||||
let mut layers = Vec::new();
|
let first_layer =
|
||||||
let (width, height) = viewport.dimensions();
|
Layer::new(Rectangle::with_size(viewport.logical_size()));
|
||||||
|
|
||||||
layers.push(Layer::new(Rectangle {
|
let mut layers = vec![first_layer];
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
}));
|
|
||||||
|
|
||||||
Self::process_primitive(&mut layers, Vector::new(0.0, 0.0), primitive);
|
Self::process_primitive(&mut layers, Vector::new(0.0, 0.0), primitive);
|
||||||
|
|
||||||
@ -156,11 +136,11 @@ impl<'a> Layer<'a> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Only draw visible content
|
// Only draw visible content
|
||||||
if let Some(clip_bounds) = layer.intersection(bounds) {
|
if let Some(clip_bounds) = layer.bounds.intersection(&bounds) {
|
||||||
layer.meshes.push(Mesh {
|
layer.meshes.push(Mesh {
|
||||||
origin: Point::new(translation.x, translation.y),
|
origin: Point::new(translation.x, translation.y),
|
||||||
buffers,
|
buffers,
|
||||||
clip_bounds: clip_bounds.into(),
|
clip_bounds,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,12 +150,13 @@ impl<'a> Layer<'a> {
|
|||||||
content,
|
content,
|
||||||
} => {
|
} => {
|
||||||
let layer = layers.last_mut().unwrap();
|
let layer = layers.last_mut().unwrap();
|
||||||
|
let translated_bounds = *bounds + translation;
|
||||||
|
|
||||||
// Only draw visible content
|
// Only draw visible content
|
||||||
if let Some(clip_bounds) =
|
if let Some(clip_bounds) =
|
||||||
layer.intersection(*bounds + translation)
|
layer.bounds.intersection(&translated_bounds)
|
||||||
{
|
{
|
||||||
let clip_layer = Layer::new(clip_bounds.into());
|
let clip_layer = Layer::new(clip_bounds);
|
||||||
let new_layer = Layer::new(layer.bounds);
|
let new_layer = Layer::new(layer.bounds);
|
||||||
|
|
||||||
layers.push(clip_layer);
|
layers.push(clip_layer);
|
||||||
@ -236,7 +217,7 @@ pub struct Quad {
|
|||||||
pub struct Mesh<'a> {
|
pub struct Mesh<'a> {
|
||||||
pub origin: Point,
|
pub origin: Point,
|
||||||
pub buffers: &'a triangle::Mesh2D,
|
pub buffers: &'a triangle::Mesh2D,
|
||||||
pub clip_bounds: Rectangle<u32>,
|
pub clip_bounds: Rectangle<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
@ -10,6 +10,7 @@ pub mod backend;
|
|||||||
pub mod font;
|
pub mod font;
|
||||||
pub mod layer;
|
pub mod layer;
|
||||||
pub mod triangle;
|
pub mod triangle;
|
||||||
|
pub mod window;
|
||||||
|
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use widget::*;
|
pub use widget::*;
|
||||||
|
@ -1,33 +1,48 @@
|
|||||||
use crate::Transformation;
|
use crate::{Size, Transformation};
|
||||||
|
|
||||||
/// A viewing region for displaying computer graphics.
|
/// A viewing region for displaying computer graphics.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Viewport {
|
pub struct Viewport {
|
||||||
width: u32,
|
physical_size: Size<u32>,
|
||||||
height: u32,
|
logical_size: Size<f32>,
|
||||||
transformation: Transformation,
|
scale_factor: f64,
|
||||||
|
projection: Transformation,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Viewport {
|
impl Viewport {
|
||||||
/// Creates a new [`Viewport`] with the given dimensions.
|
/// Creates a new [`Viewport`] with the given physical dimensions and scale
|
||||||
pub fn new(width: u32, height: u32) -> Viewport {
|
/// factor.
|
||||||
|
///
|
||||||
|
/// [`Viewport`]: struct.Viewport.html
|
||||||
|
pub fn with_physical_size(size: Size<u32>, scale_factor: f64) -> Viewport {
|
||||||
Viewport {
|
Viewport {
|
||||||
width,
|
physical_size: size,
|
||||||
height,
|
logical_size: Size::new(
|
||||||
transformation: Transformation::orthographic(width, height),
|
(size.width as f64 / scale_factor) as f32,
|
||||||
|
(size.height as f64 / scale_factor) as f32,
|
||||||
|
),
|
||||||
|
scale_factor,
|
||||||
|
projection: Transformation::orthographic(size.width, size.height),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn height(&self) -> u32 {
|
pub fn physical_size(&self) -> Size<u32> {
|
||||||
self.height
|
self.physical_size
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the dimensions of the [`Viewport`].
|
pub fn physical_height(&self) -> u32 {
|
||||||
pub fn dimensions(&self) -> (u32, u32) {
|
self.physical_size.height
|
||||||
(self.width, self.height)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transformation(&self) -> Transformation {
|
pub fn logical_size(&self) -> Size<f32> {
|
||||||
self.transformation
|
self.logical_size
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn scale_factor(&self) -> f64 {
|
||||||
|
self.scale_factor
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn projection(&self) -> Transformation {
|
||||||
|
self.projection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
graphics/src/window.rs
Normal file
3
graphics/src/window.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
mod compositor;
|
||||||
|
|
||||||
|
pub use compositor::Compositor;
|
@ -1,5 +1,5 @@
|
|||||||
use crate::mouse;
|
use crate::Viewport;
|
||||||
|
use iced_native::mouse;
|
||||||
use raw_window_handle::HasRawWindowHandle;
|
use raw_window_handle::HasRawWindowHandle;
|
||||||
|
|
||||||
/// A graphics compositor that can draw to windows.
|
/// A graphics compositor that can draw to windows.
|
||||||
@ -8,7 +8,7 @@ pub trait Compositor: Sized {
|
|||||||
type Settings: Default + Clone;
|
type Settings: Default + Clone;
|
||||||
|
|
||||||
/// The iced renderer of the backend.
|
/// The iced renderer of the backend.
|
||||||
type Renderer: crate::Renderer;
|
type Renderer: iced_native::Renderer;
|
||||||
|
|
||||||
/// The surface of the backend.
|
/// The surface of the backend.
|
||||||
type Surface;
|
type Surface;
|
||||||
@ -53,8 +53,8 @@ pub trait Compositor: Sized {
|
|||||||
&mut self,
|
&mut self,
|
||||||
renderer: &mut Self::Renderer,
|
renderer: &mut Self::Renderer,
|
||||||
swap_chain: &mut Self::SwapChain,
|
swap_chain: &mut Self::SwapChain,
|
||||||
output: &<Self::Renderer as crate::Renderer>::Output,
|
viewport: &Viewport,
|
||||||
scale_factor: f64,
|
output: &<Self::Renderer as iced_native::Renderer>::Output,
|
||||||
overlay: &[T],
|
overlay: &[T],
|
||||||
) -> mouse::Interaction;
|
) -> mouse::Interaction;
|
||||||
}
|
}
|
@ -9,7 +9,6 @@ repository = "https://github.com/hecrj/iced"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
twox-hash = "1.5"
|
twox-hash = "1.5"
|
||||||
raw-window-handle = "0.3"
|
|
||||||
unicode-segmentation = "1.6"
|
unicode-segmentation = "1.6"
|
||||||
|
|
||||||
[dependencies.iced_core]
|
[dependencies.iced_core]
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
//! Build window-based GUI applications.
|
//! Build window-based GUI applications.
|
||||||
mod compositor;
|
|
||||||
mod event;
|
mod event;
|
||||||
|
|
||||||
pub use compositor::Compositor;
|
|
||||||
pub use event::Event;
|
pub use event::Event;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use crate::quad;
|
use crate::quad;
|
||||||
use crate::text;
|
use crate::text;
|
||||||
use crate::triangle;
|
use crate::triangle;
|
||||||
use crate::{Settings, Target, Transformation};
|
use crate::{Settings, Transformation};
|
||||||
use iced_graphics::backend;
|
use iced_graphics::backend;
|
||||||
use iced_graphics::font;
|
use iced_graphics::font;
|
||||||
use iced_graphics::layer::Layer;
|
use iced_graphics::layer::Layer;
|
||||||
use iced_graphics::Primitive;
|
use iced_graphics::{Primitive, Viewport};
|
||||||
use iced_native::mouse;
|
use iced_native::mouse;
|
||||||
use iced_native::{Font, HorizontalAlignment, Size, VerticalAlignment};
|
use iced_native::{Font, HorizontalAlignment, Size, VerticalAlignment};
|
||||||
|
|
||||||
@ -62,19 +62,19 @@ impl Backend {
|
|||||||
&mut self,
|
&mut self,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
encoder: &mut wgpu::CommandEncoder,
|
encoder: &mut wgpu::CommandEncoder,
|
||||||
target: Target<'_>,
|
frame: &wgpu::TextureView,
|
||||||
|
viewport: &Viewport,
|
||||||
(primitive, mouse_interaction): &(Primitive, mouse::Interaction),
|
(primitive, mouse_interaction): &(Primitive, mouse::Interaction),
|
||||||
scale_factor: f64,
|
|
||||||
overlay_text: &[T],
|
overlay_text: &[T],
|
||||||
) -> mouse::Interaction {
|
) -> mouse::Interaction {
|
||||||
log::debug!("Drawing");
|
log::debug!("Drawing");
|
||||||
|
|
||||||
let (width, height) = target.viewport.dimensions();
|
let target_size = viewport.physical_size();
|
||||||
let scale_factor = scale_factor as f32;
|
let scale_factor = viewport.scale_factor() as f32;
|
||||||
let transformation = target.viewport.transformation();
|
let transformation = viewport.projection();
|
||||||
|
|
||||||
let mut layers = Layer::generate(primitive, &target.viewport);
|
let mut layers = Layer::generate(primitive, viewport);
|
||||||
layers.push(Layer::overlay(overlay_text, &target.viewport));
|
layers.push(Layer::overlay(overlay_text, viewport));
|
||||||
|
|
||||||
for layer in layers {
|
for layer in layers {
|
||||||
self.flush(
|
self.flush(
|
||||||
@ -83,9 +83,9 @@ impl Backend {
|
|||||||
transformation,
|
transformation,
|
||||||
&layer,
|
&layer,
|
||||||
encoder,
|
encoder,
|
||||||
target.texture,
|
&frame,
|
||||||
width,
|
target_size.width,
|
||||||
height,
|
target_size.height,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ impl Backend {
|
|||||||
target_width: u32,
|
target_width: u32,
|
||||||
target_height: u32,
|
target_height: u32,
|
||||||
) {
|
) {
|
||||||
let bounds = layer.bounds * scale_factor;
|
let bounds = (layer.bounds * scale_factor).round();
|
||||||
|
|
||||||
if !layer.quads.is_empty() {
|
if !layer.quads.is_empty() {
|
||||||
self.quad_pipeline.draw(
|
self.quad_pipeline.draw(
|
||||||
|
@ -34,7 +34,6 @@ pub mod window;
|
|||||||
|
|
||||||
mod backend;
|
mod backend;
|
||||||
mod quad;
|
mod quad;
|
||||||
mod target;
|
|
||||||
mod text;
|
mod text;
|
||||||
|
|
||||||
pub use iced_graphics::{Defaults, Primitive, Viewport};
|
pub use iced_graphics::{Defaults, Primitive, Viewport};
|
||||||
@ -42,7 +41,6 @@ pub use wgpu;
|
|||||||
|
|
||||||
pub use backend::Backend;
|
pub use backend::Backend;
|
||||||
pub use settings::Settings;
|
pub use settings::Settings;
|
||||||
pub use target::Target;
|
|
||||||
|
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use widget::*;
|
pub use widget::*;
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
use crate::Viewport;
|
|
||||||
|
|
||||||
/// A rendering target.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Target<'a> {
|
|
||||||
/// The texture where graphics will be rendered.
|
|
||||||
pub texture: &'a wgpu::TextureView,
|
|
||||||
|
|
||||||
/// The viewport of the target.
|
|
||||||
///
|
|
||||||
/// Most of the time, you will want this to match the dimensions of the
|
|
||||||
/// texture.
|
|
||||||
pub viewport: &'a Viewport,
|
|
||||||
}
|
|
@ -326,7 +326,8 @@ impl Pipeline {
|
|||||||
for (i, (vertex_offset, index_offset, indices)) in
|
for (i, (vertex_offset, index_offset, indices)) in
|
||||||
offsets.into_iter().enumerate()
|
offsets.into_iter().enumerate()
|
||||||
{
|
{
|
||||||
let clip_bounds = meshes[i].clip_bounds * scale_factor;
|
let clip_bounds =
|
||||||
|
(meshes[i].clip_bounds * scale_factor).round();
|
||||||
|
|
||||||
render_pass.set_scissor_rect(
|
render_pass.set_scissor_rect(
|
||||||
clip_bounds.x,
|
clip_bounds.x,
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
//! Display rendering results on windows.
|
//! Display rendering results on windows.
|
||||||
mod compositor;
|
mod compositor;
|
||||||
mod swap_chain;
|
|
||||||
|
|
||||||
pub use compositor::Compositor;
|
pub use compositor::Compositor;
|
||||||
pub use swap_chain::SwapChain;
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::{window::SwapChain, Renderer, Settings, Target};
|
use crate::{Renderer, Settings};
|
||||||
|
|
||||||
|
use iced_graphics::Viewport;
|
||||||
use iced_native::{futures, mouse};
|
use iced_native::{futures, mouse};
|
||||||
use raw_window_handle::HasRawWindowHandle;
|
use raw_window_handle::HasRawWindowHandle;
|
||||||
|
|
||||||
@ -11,11 +12,11 @@ pub struct Compositor {
|
|||||||
format: wgpu::TextureFormat,
|
format: wgpu::TextureFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl iced_native::window::Compositor for Compositor {
|
impl iced_graphics::window::Compositor for Compositor {
|
||||||
type Settings = Settings;
|
type Settings = Settings;
|
||||||
type Renderer = Renderer;
|
type Renderer = Renderer;
|
||||||
type Surface = wgpu::Surface;
|
type Surface = wgpu::Surface;
|
||||||
type SwapChain = SwapChain;
|
type SwapChain = wgpu::SwapChain;
|
||||||
|
|
||||||
fn new(settings: Self::Settings) -> Self {
|
fn new(settings: Self::Settings) -> Self {
|
||||||
let (device, queue) = futures::executor::block_on(async {
|
let (device, queue) = futures::executor::block_on(async {
|
||||||
@ -66,19 +67,28 @@ impl iced_native::window::Compositor for Compositor {
|
|||||||
surface: &Self::Surface,
|
surface: &Self::Surface,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
) -> SwapChain {
|
) -> Self::SwapChain {
|
||||||
SwapChain::new(&self.device, surface, self.format, width, height)
|
self.device.create_swap_chain(
|
||||||
|
surface,
|
||||||
|
&wgpu::SwapChainDescriptor {
|
||||||
|
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
||||||
|
format: self.format,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
present_mode: wgpu::PresentMode::Mailbox,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw<T: AsRef<str>>(
|
fn draw<T: AsRef<str>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
renderer: &mut Self::Renderer,
|
renderer: &mut Self::Renderer,
|
||||||
swap_chain: &mut SwapChain,
|
swap_chain: &mut Self::SwapChain,
|
||||||
|
viewport: &Viewport,
|
||||||
output: &<Self::Renderer as iced_native::Renderer>::Output,
|
output: &<Self::Renderer as iced_native::Renderer>::Output,
|
||||||
scale_factor: f64,
|
|
||||||
overlay: &[T],
|
overlay: &[T],
|
||||||
) -> mouse::Interaction {
|
) -> mouse::Interaction {
|
||||||
let (frame, viewport) = swap_chain.next_frame().expect("Next frame");
|
let frame = swap_chain.get_next_texture().expect("Next frame");
|
||||||
|
|
||||||
let mut encoder = self.device.create_command_encoder(
|
let mut encoder = self.device.create_command_encoder(
|
||||||
&wgpu::CommandEncoderDescriptor { label: None },
|
&wgpu::CommandEncoderDescriptor { label: None },
|
||||||
@ -103,12 +113,9 @@ impl iced_native::window::Compositor for Compositor {
|
|||||||
let mouse_interaction = renderer.backend_mut().draw(
|
let mouse_interaction = renderer.backend_mut().draw(
|
||||||
&mut self.device,
|
&mut self.device,
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
Target {
|
&frame.view,
|
||||||
texture: &frame.view,
|
viewport,
|
||||||
viewport,
|
|
||||||
},
|
|
||||||
output,
|
output,
|
||||||
scale_factor,
|
|
||||||
overlay,
|
overlay,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
use crate::Viewport;
|
|
||||||
|
|
||||||
/// The rendering target of a window.
|
|
||||||
///
|
|
||||||
/// It represents a series of virtual framebuffers with a scale factor.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct SwapChain {
|
|
||||||
raw: wgpu::SwapChain,
|
|
||||||
viewport: Viewport,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SwapChain {}
|
|
||||||
|
|
||||||
impl SwapChain {
|
|
||||||
/// Creates a new [`SwapChain`] for the given surface.
|
|
||||||
///
|
|
||||||
/// [`SwapChain`]: struct.SwapChain.html
|
|
||||||
pub fn new(
|
|
||||||
device: &wgpu::Device,
|
|
||||||
surface: &wgpu::Surface,
|
|
||||||
format: wgpu::TextureFormat,
|
|
||||||
width: u32,
|
|
||||||
height: u32,
|
|
||||||
) -> SwapChain {
|
|
||||||
SwapChain {
|
|
||||||
raw: new_swap_chain(surface, format, width, height, device),
|
|
||||||
viewport: Viewport::new(width, height),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the next frame of the [`SwapChain`] alongside its [`Viewport`].
|
|
||||||
///
|
|
||||||
/// [`SwapChain`]: struct.SwapChain.html
|
|
||||||
/// [`Viewport`]: ../struct.Viewport.html
|
|
||||||
pub fn next_frame(
|
|
||||||
&mut self,
|
|
||||||
) -> Result<(wgpu::SwapChainOutput, &Viewport), wgpu::TimeOut> {
|
|
||||||
let viewport = &self.viewport;
|
|
||||||
|
|
||||||
self.raw.get_next_texture().map(|output| (output, viewport))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new_swap_chain(
|
|
||||||
surface: &wgpu::Surface,
|
|
||||||
format: wgpu::TextureFormat,
|
|
||||||
width: u32,
|
|
||||||
height: u32,
|
|
||||||
device: &wgpu::Device,
|
|
||||||
) -> wgpu::SwapChain {
|
|
||||||
device.create_swap_chain(
|
|
||||||
&surface,
|
|
||||||
&wgpu::SwapChainDescriptor {
|
|
||||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
|
||||||
format,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
present_mode: wgpu::PresentMode::Mailbox,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
@ -22,5 +22,9 @@ log = "0.4"
|
|||||||
version = "0.2"
|
version = "0.2"
|
||||||
path = "../native"
|
path = "../native"
|
||||||
|
|
||||||
|
[dependencies.iced_graphics]
|
||||||
|
version = "0.1"
|
||||||
|
path = "../graphics"
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies.winapi]
|
[target.'cfg(target_os = "windows")'.dependencies.winapi]
|
||||||
version = "0.3.6"
|
version = "0.3.6"
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
conversion, mouse, size::Size, window, Cache, Clipboard, Command, Debug,
|
conversion, mouse, Cache, Clipboard, Command, Debug, Element, Executor,
|
||||||
Element, Executor, Mode, Proxy, Runtime, Settings, Subscription,
|
Mode, Proxy, Runtime, Settings, Size, Subscription, UserInterface,
|
||||||
UserInterface,
|
|
||||||
};
|
};
|
||||||
|
use iced_graphics::window;
|
||||||
|
use iced_graphics::Viewport;
|
||||||
|
|
||||||
/// An interactive, native cross-platform application.
|
/// An interactive, native cross-platform application.
|
||||||
///
|
///
|
||||||
@ -124,7 +125,7 @@ pub trait Application: Sized {
|
|||||||
) where
|
) where
|
||||||
Self: 'static,
|
Self: 'static,
|
||||||
{
|
{
|
||||||
use window::Compositor as _;
|
use iced_graphics::window::Compositor as _;
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{self, WindowEvent},
|
event::{self, WindowEvent},
|
||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::{ControlFlow, EventLoop},
|
||||||
@ -181,7 +182,11 @@ pub trait Application: Sized {
|
|||||||
window_builder.build(&event_loop).expect("Open window")
|
window_builder.build(&event_loop).expect("Open window")
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut size = Size::new(window.inner_size(), window.scale_factor());
|
let physical_size = window.inner_size();
|
||||||
|
let mut viewport = Viewport::with_physical_size(
|
||||||
|
Size::new(physical_size.width, physical_size.height),
|
||||||
|
window.scale_factor(),
|
||||||
|
);
|
||||||
let mut resized = false;
|
let mut resized = false;
|
||||||
|
|
||||||
let clipboard = Clipboard::new(&window);
|
let clipboard = Clipboard::new(&window);
|
||||||
@ -190,21 +195,17 @@ pub trait Application: Sized {
|
|||||||
let surface = compositor.create_surface(&window);
|
let surface = compositor.create_surface(&window);
|
||||||
let mut renderer = compositor.create_renderer(backend_settings);
|
let mut renderer = compositor.create_renderer(backend_settings);
|
||||||
|
|
||||||
let mut swap_chain = {
|
let mut swap_chain = compositor.create_swap_chain(
|
||||||
let physical_size = size.physical();
|
&surface,
|
||||||
|
physical_size.width,
|
||||||
compositor.create_swap_chain(
|
physical_size.height,
|
||||||
&surface,
|
);
|
||||||
physical_size.width,
|
|
||||||
physical_size.height,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
let user_interface = build_user_interface(
|
let user_interface = build_user_interface(
|
||||||
&mut application,
|
&mut application,
|
||||||
Cache::default(),
|
Cache::default(),
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
size.logical(),
|
viewport.logical_size(),
|
||||||
&mut debug,
|
&mut debug,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -226,16 +227,11 @@ pub trait Application: Sized {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: We should be able to keep a user interface alive
|
|
||||||
// between events once we remove state references.
|
|
||||||
//
|
|
||||||
// This will allow us to rebuild it only when a message is
|
|
||||||
// handled.
|
|
||||||
let mut user_interface = build_user_interface(
|
let mut user_interface = build_user_interface(
|
||||||
&mut application,
|
&mut application,
|
||||||
cache.take().unwrap(),
|
cache.take().unwrap(),
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
size.logical(),
|
viewport.logical_size(),
|
||||||
&mut debug,
|
&mut debug,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -306,7 +302,7 @@ pub trait Application: Sized {
|
|||||||
&mut application,
|
&mut application,
|
||||||
temp_cache,
|
temp_cache,
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
size.logical(),
|
viewport.logical_size(),
|
||||||
&mut debug,
|
&mut debug,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -326,7 +322,7 @@ pub trait Application: Sized {
|
|||||||
debug.render_started();
|
debug.render_started();
|
||||||
|
|
||||||
if resized {
|
if resized {
|
||||||
let physical_size = size.physical();
|
let physical_size = viewport.physical_size();
|
||||||
|
|
||||||
swap_chain = compositor.create_swap_chain(
|
swap_chain = compositor.create_swap_chain(
|
||||||
&surface,
|
&surface,
|
||||||
@ -340,8 +336,8 @@ pub trait Application: Sized {
|
|||||||
let new_mouse_interaction = compositor.draw(
|
let new_mouse_interaction = compositor.draw(
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
&mut swap_chain,
|
&mut swap_chain,
|
||||||
|
&viewport,
|
||||||
&primitive,
|
&primitive,
|
||||||
size.scale_factor(),
|
|
||||||
&debug.overlay(),
|
&debug.overlay(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -364,7 +360,12 @@ pub trait Application: Sized {
|
|||||||
} => {
|
} => {
|
||||||
match window_event {
|
match window_event {
|
||||||
WindowEvent::Resized(new_size) => {
|
WindowEvent::Resized(new_size) => {
|
||||||
size = Size::new(new_size, window.scale_factor());
|
let size = Size::new(new_size.width, new_size.height);
|
||||||
|
|
||||||
|
viewport = Viewport::with_physical_size(
|
||||||
|
size,
|
||||||
|
window.scale_factor(),
|
||||||
|
);
|
||||||
resized = true;
|
resized = true;
|
||||||
}
|
}
|
||||||
WindowEvent::CloseRequested => {
|
WindowEvent::CloseRequested => {
|
||||||
@ -402,7 +403,7 @@ pub trait Application: Sized {
|
|||||||
|
|
||||||
if let Some(event) = conversion::window_event(
|
if let Some(event) = conversion::window_event(
|
||||||
&window_event,
|
&window_event,
|
||||||
size.scale_factor(),
|
viewport.scale_factor(),
|
||||||
modifiers,
|
modifiers,
|
||||||
) {
|
) {
|
||||||
events.push(event);
|
events.push(event);
|
||||||
@ -419,7 +420,7 @@ fn build_user_interface<'a, A: Application>(
|
|||||||
application: &'a mut A,
|
application: &'a mut A,
|
||||||
cache: Cache,
|
cache: Cache,
|
||||||
renderer: &mut <A::Compositor as window::Compositor>::Renderer,
|
renderer: &mut <A::Compositor as window::Compositor>::Renderer,
|
||||||
size: winit::dpi::LogicalSize<f64>,
|
size: Size,
|
||||||
debug: &mut Debug,
|
debug: &mut Debug,
|
||||||
) -> UserInterface<
|
) -> UserInterface<
|
||||||
'a,
|
'a,
|
||||||
@ -431,15 +432,7 @@ fn build_user_interface<'a, A: Application>(
|
|||||||
debug.view_finished();
|
debug.view_finished();
|
||||||
|
|
||||||
debug.layout_started();
|
debug.layout_started();
|
||||||
let user_interface = UserInterface::build(
|
let user_interface = UserInterface::build(view, size, cache, renderer);
|
||||||
view,
|
|
||||||
iced_native::Size::new(
|
|
||||||
size.width.round() as f32,
|
|
||||||
size.height.round() as f32,
|
|
||||||
),
|
|
||||||
cache,
|
|
||||||
renderer,
|
|
||||||
);
|
|
||||||
debug.layout_finished();
|
debug.layout_finished();
|
||||||
|
|
||||||
user_interface
|
user_interface
|
||||||
|
@ -32,7 +32,6 @@ mod application;
|
|||||||
mod clipboard;
|
mod clipboard;
|
||||||
mod mode;
|
mod mode;
|
||||||
mod proxy;
|
mod proxy;
|
||||||
mod size;
|
|
||||||
|
|
||||||
// We disable debug capabilities on release builds unless the `debug` feature
|
// We disable debug capabilities on release builds unless the `debug` feature
|
||||||
// is explicitly enabled.
|
// is explicitly enabled.
|
||||||
|
Loading…
Reference in New Issue
Block a user