Skip to content

Commit

Permalink
make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharktheone committed Sep 5, 2024
1 parent f051f68 commit ffd9697
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 69 deletions.
12 changes: 0 additions & 12 deletions crates/gosub_render_backend/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,6 @@ pub trait CssProperty: Debug {
fn is_none(&self) -> bool;
}

pub type AxisName = [u8; 4];

#[derive(Debug, Clone)]
pub struct Axis {
name: AxisName,
value: f32,
}

pub trait TextLayout {
type Font: Font;
fn dbg_layout(&self) -> String;
Expand All @@ -159,9 +151,5 @@ pub trait TextLayout {

fn font_size(&self) -> f32;

fn axes(&self) -> &[Axis];

fn coords(&self) -> &[i16];

fn text(&self) -> &str;
}
2 changes: 0 additions & 2 deletions crates/gosub_render_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,6 @@ pub trait Text {
fn new<TL: TextLayout>(node: &TL) -> Self
where
TL::Font: Into<Self::Font>;

fn text(&self) -> &str;
}

pub struct ColorStop<B: RenderBackend> {
Expand Down
7 changes: 0 additions & 7 deletions crates/gosub_renderer/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use gosub_render_backend::{
use gosub_rendering::position::PositionTree;
use gosub_shared::types::Result;
use gosub_styling::render_tree::{RenderNodeData, RenderTree, RenderTreeNode};
use gosub_styling::styling::CssProperties;
use log::warn;

mod img;
Expand Down Expand Up @@ -353,12 +352,6 @@ fn render_text<B: RenderBackend, L: Layouter>(
size.height as FP,
);

if [158u64, 160].contains(&u64::from(node.id)) {
println!("IDaaaaa: {:?}", node.id);
println!("Text: {:?}", text.text());
println!("position: {:?}", (pos.x, pos.y));
}

let render_text = RenderText {
text,
rect,
Expand Down
13 changes: 2 additions & 11 deletions crates/gosub_taffy/src/compute/inline.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::cell::LazyCell;
use std::sync::{LazyLock, Mutex};
use taffy::{
AvailableSpace, CollapsibleMarginSet, Layout, LayoutInput, LayoutOutput, LayoutPartialTree,
Expand Down Expand Up @@ -54,8 +53,6 @@ pub fn compute_inline_layout<LT: LayoutTree<TaffyLayouter>>(
str_buf.push(' ');
str_buf.push_str(text);

let text = text.to_string();

let font_family = node
.get_property("font-family")
.and_then(|s| s.as_string())
Expand Down Expand Up @@ -91,10 +88,9 @@ pub fn compute_inline_layout<LT: LayoutTree<TaffyLayouter>>(
font_weight,
font_style,
var_axes,
text,

to: str_buf.len(),
id: node_id.into(),
id: node_id,
});
} else {
if u64::from(node_id) == 162u64 {
Expand Down Expand Up @@ -126,7 +122,7 @@ pub fn compute_inline_layout<LT: LayoutTree<TaffyLayouter>>(
warn!("Failed to get font context");
return LayoutOutput::HIDDEN;
};
let mut builder = layout_cx.ranged_builder(&mut *lock, &str_buf, 1.0);
let mut builder = layout_cx.ranged_builder(&mut lock, &str_buf, 1.0);
let mut align = Alignment::default();

if let Some(default) = text_node_data.first() {
Expand Down Expand Up @@ -336,16 +332,12 @@ pub fn compute_inline_layout<LT: LayoutTree<TaffyLayouter>>(

let coords = grun.normalized_coords().to_owned();

let text = text_node_data[current_node_idx].text.clone();

let text_layout = TextLayout {
size,
font_size: fs,
font: Font(grun.font().clone()),
glyphs,
axes: Vec::new(),
coords,
text,
};

let Some(node) = tree.0.get_node(current_node_id) else {
Expand Down Expand Up @@ -458,7 +450,6 @@ struct TextNodeData {

to: usize,
id: NodeId,
text: String,
}

fn parse_alignment(node: &mut impl Node) -> Alignment {
Expand Down
12 changes: 1 addition & 11 deletions crates/gosub_taffy/src/text.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gosub_render_backend::layout::{Axis, TextLayout as TLayout};
use gosub_render_backend::layout::TextLayout as TLayout;
use gosub_render_backend::Size;
use gosub_typeface::font::Font as TFont;
use gosub_typeface::font::Glyph;
Expand All @@ -25,9 +25,7 @@ pub struct TextLayout {
pub font: Font,
pub font_size: f32,
pub size: Size,
pub axes: Vec<Axis>,
pub coords: Vec<i16>,
pub text: String,
}

impl TLayout for TextLayout {
Expand All @@ -53,15 +51,7 @@ impl TLayout for TextLayout {
self.font_size
}

fn axes(&self) -> &[Axis] {
&self.axes
}

fn coords(&self) -> &[i16] {
&self.coords
}

fn text(&self) -> &str {
&self.text
}
}
27 changes: 1 addition & 26 deletions crates/gosub_vello/src/text.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use crate::VelloBackend;
use gosub_render_backend::geo::FP;
use gosub_render_backend::layout::{Layouter, TextLayout};
use gosub_render_backend::layout::TextLayout;
use gosub_render_backend::{RenderText, Text as TText};
use vello::glyph::Glyph;
use vello::kurbo::Affine;
use vello::peniko::{Fill, Font, StyleRef};
use vello::skrifa::instance::NormalizedCoord;
use vello::skrifa::FontRef;
use vello::Scene;

pub struct Text {
glyphs: Vec<Glyph>,
font: Font,
fs: FP,
coords: Vec<NormalizedCoord>,
text: String,
}

impl TText for Text {
Expand Down Expand Up @@ -42,20 +40,13 @@ impl TText for Text {
.map(|c| NormalizedCoord::from_bits(*c))
.collect();

let text = layout.text().to_string();

Self {
glyphs,
font,
fs,
coords,
text,
}
}

fn text(&self) -> &str {
&self.text
}
}

impl Text {
Expand All @@ -71,13 +62,6 @@ impl Text {

let transform = transform.with_translation((x, y).into());

let x_offset = render.text.glyphs.get(0);
let y_offset = render.text.glyphs.get(4);

println!("Text: {}", render.text.text());
println!("position: {:?}", (x, y));
println!("offset: {:?}", (x_offset, y_offset));

scene
.draw_glyphs(&render.text.font)
.font_size(render.text.fs)
Expand All @@ -88,12 +72,3 @@ impl Text {
.draw(style, render.text.glyphs.iter().copied());
}
}

fn to_font_ref(font: &Font) -> Option<FontRef<'_>> {
use vello::skrifa::raw::FileRef;
let file_ref = FileRef::new(font.data.as_ref()).ok()?;
match file_ref {
FileRef::Font(font) => Some(font),
FileRef::Collection(collection) => collection.get(font.index).ok(),
}
}

0 comments on commit ffd9697

Please sign in to comment.