Skip to content

Commit

Permalink
format + clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
StarArawn committed Feb 11, 2024
1 parent 0d2ce27 commit a70b7e6
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 66 deletions.
4 changes: 2 additions & 2 deletions kayak_font/src/msdf/edge_coloring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn simple(shape: &mut Shape, angle_threshold: f64, mut seed: usize) {
edges[i].set_color(EdgeColor::WHITE);
}
} else if corners.len() == 1 {
let mut colors = vec![EdgeColor::WHITE, EdgeColor::WHITE, EdgeColor::BLACK];
let mut colors = [EdgeColor::WHITE, EdgeColor::WHITE, EdgeColor::BLACK];
switch_color(&mut colors[0], &mut seed, EdgeColor::BLACK);
colors[2] = colors[0];
switch_color(&mut colors[2], &mut seed, EdgeColor::BLACK);
Expand Down Expand Up @@ -202,7 +202,7 @@ pub fn ink_trap(shape: &mut Shape, angle_threshold: f64, mut seed: usize) {
edge.set_color(EdgeColor::WHITE);
}
} else if corners.len() == 1 {
let mut colors = vec![EdgeColor::WHITE, EdgeColor::WHITE, EdgeColor::BLACK];
let mut colors = [EdgeColor::WHITE, EdgeColor::WHITE, EdgeColor::BLACK];
switch_color(&mut colors[0], &mut seed, EdgeColor::BLACK);
colors[2] = colors[0];
switch_color(&mut colors[2], &mut seed, EdgeColor::BLACK);
Expand Down
1 change: 0 additions & 1 deletion kayak_font/src/ttf/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ impl AssetLoader for TTFLoader {

let image_bytes = match cache_image {
Ok(cache_image) => {
let cache_image = cache_image;
let image = image::load_from_memory(&cache_image).unwrap();
image.as_bytes().to_vec()
}
Expand Down
8 changes: 3 additions & 5 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ fn recurse_node_tree_to_build_primitives2(
images: &Assets<Image>,
extracted_quads: &mut ExtractedQuads,
current_node: WrappedIndex,
mut prev_clip: &mut Option<ExtractedQuad>,
prev_clip: &mut Option<ExtractedQuad>,
mut current_opacity_layer: u32,
mut total_opacity_layers: u32,
) -> u32 {
Expand All @@ -442,7 +442,7 @@ fn recurse_node_tree_to_build_primitives2(
let new_clip = node.resolved_styles.extract(
current_node.0,
commands,
&layout,
layout,
current_opacity_layer,
extracted_quads,
camera_entity,
Expand Down Expand Up @@ -485,7 +485,6 @@ fn recurse_node_tree_to_build_primitives2(
if node_tree.children.contains_key(&current_node) {
let children = node_tree.children.get(&current_node).unwrap();
extracted_quads.new_layer(if node.z > 0.0 { Some(node.z) } else { None });
let mut i = 0;
for child in children.iter() {
extracted_quads.new_layer(None);
let new_total_opacity_layers = recurse_node_tree_to_build_primitives2(
Expand All @@ -507,12 +506,11 @@ fn recurse_node_tree_to_build_primitives2(
);

total_opacity_layers = new_total_opacity_layers;
i += 1;
extracted_quads.pop_stack();

// // Between each child node we need to reset the clip.
extracted_quads.new_layer(None);
if let (Some(parent_clip), Some(prev_clip)) = (&parent_clip, &prev_clip) {
if let Some(parent_clip) = &parent_clip {
// if prev_clip.rect != parent_clip.rect {
extracted_quads.push(QuadOrMaterial::Quad(ExtractedQuad {
// rect: bevy::prelude::Rect {
Expand Down
6 changes: 2 additions & 4 deletions src/render/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ pub fn extract(
&mut extracted_quads,
);
// Resolve extracted quads
if let (Ok(mut layout_cache), Ok(tree)) =
(context.layout_cache.try_write(), context.tree.try_read())
{
extracted_quads.resolve(&mut commands, &mut layout_cache, &tree);
if let Ok(mut layout_cache) = context.layout_cache.try_write() {
extracted_quads.resolve(&mut commands, &mut layout_cache);
// extracted_quads.debug();
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/render/material/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ pub fn queue_material_ui_quads<M: MaterialUI>(
draw_quad,
pipeline_id.unwrap(),
&mut quad_meta,
&mut quad,
&quad,
camera_entity,
*quad_type_offsets,
&mut current_batch,
Expand All @@ -442,6 +442,7 @@ pub fn queue_material_ui_quads<M: MaterialUI>(
}

if let Some(pipeline) = pipeline_id {
#[allow(clippy::nonminimal_bool)]
if last_quad.quad_type != UIQuadType::Clip
&& last_quad.quad_type != UIQuadType::OpacityLayer
&& last_quad.quad_type != UIQuadType::Clip
Expand All @@ -457,7 +458,7 @@ pub fn queue_material_ui_quads<M: MaterialUI>(
pipeline,
entity: current_batch_entity,
sort_key: FloatOrd(last_quad.z_index),
quad_type: last_quad.quad_type.clone(),
quad_type: last_quad.quad_type,
type_index: last_quad.quad_type.get_type_index(&quad_type_offsets),
rect: last_clip,
batch_range: Some(old_item_start..item_end),
Expand All @@ -470,7 +471,7 @@ pub fn queue_material_ui_quads<M: MaterialUI>(
pipeline,
entity: current_batch_entity,
sort_key: FloatOrd(last_quad.z_index),
quad_type: last_quad.quad_type.clone(),
quad_type: last_quad.quad_type,
type_index: last_quad.quad_type.get_type_index(&quad_type_offsets),
rect: last_clip,
batch_range: Some(old_item_start..item_end),
Expand Down
58 changes: 26 additions & 32 deletions src/render/unified/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use std::marker::PhantomData;

use super::UNIFIED_SHADER_HANDLE;
use crate::layout::LayoutCache;
use crate::prelude::{Corner, Tree};
use crate::prelude::Corner;
use crate::render::extract::{UIExtractedView, UIViewUniform, UIViewUniformOffset, UIViewUniforms};
use crate::render::opacity_layer::OpacityLayerManager;
use crate::render::svg::RenderSvgs;
Expand Down Expand Up @@ -493,7 +493,7 @@ impl ExtractedQuads {
}
pub fn new_layer(&mut self, z_index: Option<f32>) {
let layer = ZLayer {
custom_z: z_index.map(|z| z).unwrap_or(0.0),
custom_z: z_index.unwrap_or(0.0),
parent_id: self.current_layer,
..Default::default()
};
Expand All @@ -513,15 +513,10 @@ impl ExtractedQuads {
self.current_layer = layer.parent_id;
}

pub(crate) fn resolve(
&mut self,
commands: &mut Commands,
layout_cache: &mut LayoutCache,
tree: &Tree,
) {
pub(crate) fn resolve(&mut self, commands: &mut Commands, layout_cache: &mut LayoutCache) {
let mut stack = vec![0];

let mut z = 0.0;
#[allow(clippy::manual_while_let_some)]
while !stack.is_empty() {
let layer_id = stack.pop().unwrap();
let parent_id = self.layers.get(layer_id).map(|l| l.parent_id).unwrap();
Expand Down Expand Up @@ -576,22 +571,22 @@ impl ExtractedQuads {
// has_z = true;
// }
}
z += 1.0;
}
}

pub fn debug(&self) {
let mut items = vec![];
let mut stack = vec![0];
#[allow(clippy::manual_while_let_some)]
while !stack.is_empty() {
let layer_id = stack.pop().unwrap();
let parent_id = self.layers.get(layer_id).map(|l| l.parent_id).unwrap_or(0);
let parent_z = {
self.layers
.get(self.parents.get(&parent_id).map(|id| *id).unwrap_or(0))
.map(|l| l.z)
.unwrap_or(0.0)
};
// let parent_z = {
// self.layers
// .get(self.parents.get(&parent_id).map(|id| *id).unwrap_or(0))
// .map(|l| l.z)
// .unwrap_or(0.0)
// };
let children = self.children.get(&layer_id).cloned().unwrap_or_default();
stack.extend(children);
let layer = &self.layers[layer_id];
Expand All @@ -604,21 +599,22 @@ impl ExtractedQuads {
_ => UIQuadType::None,
})
.unwrap_or(UIQuadType::None);
let rect = layer
.quads
.first()
.map(|q| match q {
QuadOrMaterial::Quad(q) => q.rect,
_ => Rect::default(),
})
.unwrap_or(Rect::default());
// let rect = layer
// .quads
// .first()
// .map(|q| match q {
// QuadOrMaterial::Quad(q) => q.rect,
// _ => Rect::default(),
// })
// .unwrap_or(Rect::default());
if qt != UIQuadType::None {
// items.push((layer.z, format!("{}type: {:?}, layer_id: {}, parent_id: {}, parent_z: {}, z: {}, rect: {:?}", " ".repeat(parent_id + 1), qt, layer_id, parent_id, parent_z, layer.z, rect)));
}
if !layer.quads.is_empty() {
// println!("{}Quads:", " ".repeat(parent_id + 1));
let mut last_type = UIQuadType::None;
for quad in layer.quads.iter() {
#[allow(clippy::single_match)]
match quad {
QuadOrMaterial::Quad(q) => {
if last_type != q.quad_type {
Expand Down Expand Up @@ -972,6 +968,7 @@ pub fn queue_quads(queue_quads: QueueQuads) {
last_quad = (*quad).clone();
}

#[allow(clippy::nonminimal_bool)]
if last_quad.quad_type != UIQuadType::Clip
&& last_quad.quad_type != UIQuadType::OpacityLayer
&& last_quad.quad_type != UIQuadType::Clip
Expand All @@ -987,7 +984,7 @@ pub fn queue_quads(queue_quads: QueueQuads) {
pipeline: spec_pipeline,
entity: current_batch_entity,
sort_key: FloatOrd(last_quad.z_index),
quad_type: last_quad.quad_type.clone(),
quad_type: last_quad.quad_type,
type_index: last_quad.quad_type.get_type_index(&quad_type_offsets),
rect: last_clip,
batch_range: Some(old_item_start..item_end),
Expand All @@ -1000,7 +997,7 @@ pub fn queue_quads(queue_quads: QueueQuads) {
pipeline: spec_pipeline,
entity: current_batch_entity,
sort_key: FloatOrd(last_quad.z_index),
quad_type: last_quad.quad_type.clone(),
quad_type: last_quad.quad_type,
type_index: last_quad.quad_type.get_type_index(&quad_type_offsets),
rect: last_clip,
batch_range: Some(old_item_start..item_end),
Expand Down Expand Up @@ -1103,7 +1100,7 @@ pub fn queue_quads_inner(
pipeline: spec_pipeline,
entity: *current_batch_entity,
sort_key: FloatOrd(old_quad.z_index),
quad_type: old_quad.quad_type.clone(),
quad_type: old_quad.quad_type,
type_index: current_batch.type_id,
rect: *current_clip,
batch_range: Some(*old_item_start..*item_end),
Expand All @@ -1116,7 +1113,7 @@ pub fn queue_quads_inner(
pipeline: spec_pipeline,
entity: *current_batch_entity,
sort_key: FloatOrd(old_quad.z_index),
quad_type: old_quad.quad_type.clone(),
quad_type: old_quad.quad_type,
type_index: current_batch.type_id,
rect: *last_clip,
batch_range: Some(*old_item_start..*item_end),
Expand Down Expand Up @@ -1408,8 +1405,6 @@ pub fn queue_quads_inner(
*index += QUAD_INDICES.len() as u32;
*item_end = *index;
}

return;
}

pub type DrawUI = (
Expand Down Expand Up @@ -1506,8 +1501,7 @@ impl<T: PhaseItem + TransparentUIGeneric> RenderCommand<T> for DrawUIDraw<T> {
} else if let Some(bind_group) = batch
.font_handle_id
.as_ref()
.map(|h| image_bind_groups.font_values.get(h))
.flatten()
.and_then(|h| image_bind_groups.font_values.get(h))
{
pass.set_bind_group(1, bind_group, &[]);
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/render_primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl RenderPrimitive for KStyle {
extracted_quads.extend(
quads
.into_iter()
.map(|q| QuadOrMaterial::Quad(q))
.map(QuadOrMaterial::Quad)
.collect::<Vec<_>>(),
);
}
Expand Down Expand Up @@ -154,7 +154,7 @@ impl RenderPrimitive for KStyle {
} else {
extracted_quads.extend(
text.into_iter()
.map(|q| QuadOrMaterial::Quad(q))
.map(QuadOrMaterial::Quad)
.collect::<Vec<_>>(),
);
}
Expand Down Expand Up @@ -182,7 +182,7 @@ impl RenderPrimitive for KStyle {
extracted_quads.extend(
images
.into_iter()
.map(|q| QuadOrMaterial::Quad(q))
.map(QuadOrMaterial::Quad)
.collect::<Vec<_>>(),
);
}
Expand Down Expand Up @@ -216,7 +216,7 @@ impl RenderPrimitive for KStyle {
extracted_quads.extend(
atlases
.into_iter()
.map(|q| QuadOrMaterial::Quad(q))
.map(QuadOrMaterial::Quad)
.collect::<Vec<_>>(),
);
}
Expand Down Expand Up @@ -245,7 +245,7 @@ impl RenderPrimitive for KStyle {
extracted_quads.extend(
nines
.into_iter()
.map(|q| QuadOrMaterial::Quad(q))
.map(QuadOrMaterial::Quad)
.collect::<Vec<_>>(),
);
}
Expand Down Expand Up @@ -275,7 +275,7 @@ impl RenderPrimitive for KStyle {
} else {
extracted_quads.extend(
svgs.into_iter()
.map(|q| QuadOrMaterial::Quad(q))
.map(QuadOrMaterial::Quad)
.collect::<Vec<_>>(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Default for KayakAppBundle {
styles: Default::default(),
computed_styles: ComputedStyles::default(),
children: Default::default(),
widget_name: KayakApp::default().get_name(),
widget_name: KayakApp.get_name(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Default for BackgroundBundle {
computed_styles: Default::default(),
children: Default::default(),
on_event: Default::default(),
widget_name: Background::default().get_name(),
widget_name: Background.get_name(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ pub struct ClipBundle {
impl Default for ClipBundle {
fn default() -> Self {
Self {
clip: Clip::default(),
clip: Clip,
styles: KStyle::default(),
computed_styles: ComputedStyles::default(),
children: KChildren::default(),
widget_name: Clip::default().get_name(),
widget_name: Clip.get_name(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Default for ElementBundle {
computed_styles: ComputedStyles::default(),
children: Default::default(),
on_event: OnEvent::default(),
widget_name: Element::default().get_name(),
widget_name: Element.get_name(),
}
}
}
Expand Down
Loading

0 comments on commit a70b7e6

Please sign in to comment.