diff --git a/uidev/assets/gui/various_widgets.xml b/uidev/assets/gui/various_widgets.xml
index 3485880..b8ba9b8 100644
--- a/uidev/assets/gui/various_widgets.xml
+++ b/uidev/assets/gui/various_widgets.xml
@@ -11,9 +11,9 @@
-
-
-
+
+
+
diff --git a/wgui/src/drawing.rs b/wgui/src/drawing.rs
index e1603b8..926d7d5 100644
--- a/wgui/src/drawing.rs
+++ b/wgui/src/drawing.rs
@@ -5,6 +5,7 @@ use glam::{Mat4, Vec2};
use taffy::TraversePartialTree;
use crate::{
+ drawing,
layout::Widget,
renderer_vk::text::custom_glyph::CustomGlyph,
transform_stack::{self, TransformStack},
@@ -111,26 +112,18 @@ pub struct Rectangle {
pub round_units: u8,
}
-#[derive(Clone, Copy)]
-pub struct Scissor {
- pub x: u32,
- pub y: u32,
- pub w: u32,
- pub h: u32,
-}
-
-pub struct RenderPrimitive {
+pub struct PrimitiveExtent {
pub(super) boundary: Boundary,
pub(super) transform: Mat4,
- pub(super) depth: f32,
- pub(super) payload: PrimitivePayload,
+ pub(super) depth: f32, // FIXME: remove this
}
-pub enum PrimitivePayload {
- Rectangle(Rectangle),
- Text(Rc
>),
- Sprite(Option), //option because we want as_slice
- Scissor(Scissor),
+pub enum RenderPrimitive {
+ Rectangle(PrimitiveExtent, Rectangle),
+ Text(PrimitiveExtent, Rc>),
+ Sprite(PrimitiveExtent, Option), //option because we want as_slice
+ ScissorEnable(Boundary),
+ ScissorDisable,
}
fn draw_widget(
@@ -161,6 +154,13 @@ fn draw_widget(
dim: Vec2::new(l.size.width, l.size.height),
});
+ // FIXME: this is temporary
+ // FIXME: implement scissor stack (do not allow growing!)
+ if info.is_some() {
+ let boundary = drawing::Boundary::construct(state.transform_stack);
+ state.primitives.push(drawing::RenderPrimitive::ScissorEnable(boundary));
+ }
+
let draw_params = widget::DrawParams {
node_id,
taffy_layout: l,
@@ -171,6 +171,10 @@ fn draw_widget(
draw_children(layout, state, node_id, &transform);
+ if info.is_some() {
+ state.primitives.push(drawing::RenderPrimitive::ScissorDisable);
+ }
+
state.transform_stack.pop();
if let Some(info) = &info {
diff --git a/wgui/src/gfx/pass.rs b/wgui/src/gfx/pass.rs
index 8318286..2dc3c0c 100644
--- a/wgui/src/gfx/pass.rs
+++ b/wgui/src/gfx/pass.rs
@@ -14,7 +14,7 @@ use vulkano::{
},
pipeline::{
Pipeline, PipelineBindPoint,
- graphics::{vertex_input::Vertex, viewport::Viewport},
+ graphics::{self, vertex_input::Vertex, viewport::Viewport},
},
};
@@ -38,6 +38,7 @@ where
vertices: Range,
instances: Range,
descriptor_sets: Vec>,
+ vk_scissor: &graphics::viewport::Scissor,
) -> anyhow::Result {
let viewport = Viewport {
offset: [0.0, 0.0],
@@ -64,6 +65,7 @@ where
unsafe {
command_buffer
.set_viewport(0, smallvec![viewport])?
+ .set_scissor(0, smallvec![*vk_scissor])?
.bind_pipeline_graphics(pipeline_inner)?
.bind_descriptor_sets(
PipelineBindPoint::Graphics,
@@ -88,12 +90,7 @@ where
})
}
- pub fn update_sampler(
- &self,
- set: usize,
- texture: Arc,
- filter: Filter,
- ) -> anyhow::Result<()> {
+ pub fn update_sampler(&self, set: usize, texture: Arc, filter: Filter) -> anyhow::Result<()> {
let sampler = Sampler::new(
self.graphics.device.clone(),
SamplerCreateInfo {
@@ -105,10 +102,7 @@ where
)?;
unsafe {
- self.descriptor_sets[set].update_by_ref(
- [WriteDescriptorSet::image_view_sampler(0, texture, sampler)],
- [],
- )?;
+ self.descriptor_sets[set].update_by_ref([WriteDescriptorSet::image_view_sampler(0, texture, sampler)], [])?;
}
Ok(())
diff --git a/wgui/src/gfx/pipeline.rs b/wgui/src/gfx/pipeline.rs
index 6813b26..1b0afd3 100644
--- a/wgui/src/gfx/pipeline.rs
+++ b/wgui/src/gfx/pipeline.rs
@@ -16,7 +16,7 @@ use vulkano::{
pipeline::{
DynamicState, GraphicsPipeline, Pipeline, PipelineLayout,
graphics::{
- GraphicsPipelineCreateInfo,
+ self, GraphicsPipelineCreateInfo,
color_blend::{AttachmentBlend, ColorBlendAttachmentState, ColorBlendState},
input_assembly::{InputAssemblyState, PrimitiveTopology},
multisample::MultisampleState,
@@ -91,7 +91,7 @@ where
}],
..Default::default()
}),
- dynamic_state: std::iter::once(DynamicState::Viewport).collect(),
+ dynamic_state: [DynamicState::Viewport, DynamicState::Scissor].into_iter().collect(),
subpass: Some(subpass.into()),
..GraphicsPipelineCreateInfo::layout(layout)
},
@@ -105,7 +105,6 @@ where
})
}
-
pub fn inner(&self) -> Arc {
self.pipeline.clone()
}
@@ -151,11 +150,7 @@ where
}
#[allow(clippy::needless_pass_by_value)]
- pub fn uniform_buffer_upload(
- &self,
- set: usize,
- data: Vec,
- ) -> anyhow::Result>
+ pub fn uniform_buffer_upload(&self, set: usize, data: Vec) -> anyhow::Result>
where
T: BufferContents + Copy,
{
@@ -163,8 +158,7 @@ where
self.graphics.memory_allocator.clone(),
SubbufferAllocatorCreateInfo {
buffer_usage: BufferUsage::UNIFORM_BUFFER,
- memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
- | MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
+ memory_type_filter: MemoryTypeFilter::PREFER_DEVICE | MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
);
@@ -219,6 +213,7 @@ where
vertices: Range,
instances: Range,
descriptor_sets: Vec>,
+ vk_scissor: &graphics::viewport::Scissor,
) -> anyhow::Result> {
WGfxPass::new(
&self.clone(),
@@ -227,6 +222,7 @@ where
vertices,
instances,
descriptor_sets,
+ vk_scissor,
)
}
}
diff --git a/wgui/src/renderer_vk/context.rs b/wgui/src/renderer_vk/context.rs
index 3fb43f5..16e2dd0 100644
--- a/wgui/src/renderer_vk/context.rs
+++ b/wgui/src/renderer_vk/context.rs
@@ -3,10 +3,10 @@ use std::{cell::RefCell, rc::Rc, sync::Arc};
use cosmic_text::Buffer;
use glam::{Mat4, Vec2, Vec3};
use slotmap::{SlotMap, new_key_type};
-use vulkano::{buffer::view, pipeline::graphics::viewport};
+use vulkano::pipeline::graphics::viewport;
use crate::{
- drawing::{self, Scissor},
+ drawing::{self},
gfx::{WGfx, cmd::GfxCommandBuffer},
};
@@ -25,11 +25,17 @@ struct RendererPass<'a> {
text_areas: Vec