Skip to content

Commit

Permalink
Rename viewport to clip_bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Dec 2, 2023
1 parent 43a7cc2 commit b526ce4
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 50 deletions.
6 changes: 3 additions & 3 deletions core/src/renderer/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl text::Renderer for Null {
_paragraph: &Self::Paragraph,
_position: Point,
_color: Color,
_viewport: Rectangle,
_clip_bounds: Rectangle,
) {
}

Expand All @@ -73,7 +73,7 @@ impl text::Renderer for Null {
_editor: &Self::Editor,
_position: Point,
_color: Color,
_viewport: Rectangle,
_clip_bounds: Rectangle,
) {
}

Expand All @@ -82,7 +82,7 @@ impl text::Renderer for Null {
_paragraph: Text<'_, Self::Font>,
_position: Point,
_color: Color,
_viewport: Rectangle,
_clip_bounds: Rectangle,
) {
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub trait Renderer: crate::Renderer {
text: &Self::Paragraph,
position: Point,
color: Color,
viewport: Rectangle,
clip_bounds: Rectangle,
);

/// Draws the given [`Editor`] at the given position and with the given
Expand All @@ -212,7 +212,7 @@ pub trait Renderer: crate::Renderer {
editor: &Self::Editor,
position: Point,
color: Color,
viewport: Rectangle,
clip_bounds: Rectangle,
);

/// Draws the given [`Text`] at the given position and with the given
Expand All @@ -222,6 +222,6 @@ pub trait Renderer: crate::Renderer {
text: Text<'_, Self::Font>,
position: Point,
color: Color,
viewport: Rectangle,
clip_bounds: Rectangle,
);
}
12 changes: 6 additions & 6 deletions graphics/src/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub enum Primitive<T> {
vertical_alignment: alignment::Vertical,
/// The shaping strategy of the text.
shaping: text::Shaping,
/// The viewport of the text.
viewport: Rectangle,
/// The clip bounds of the text.
clip_bounds: Rectangle,
},
/// A paragraph primitive
Paragraph {
Expand All @@ -43,8 +43,8 @@ pub enum Primitive<T> {
position: Point,
/// The color of the paragraph.
color: Color,
/// The viewport of the paragraph.
viewport: Rectangle,
/// The clip bounds of the paragraph.
clip_bounds: Rectangle,
},
/// An editor primitive
Editor {
Expand All @@ -54,8 +54,8 @@ pub enum Primitive<T> {
position: Point,
/// The color of the editor.
color: Color,
/// The viewport of the editor.
viewport: Rectangle,
/// The clip bounds of the editor.
clip_bounds: Rectangle,
},
/// A quad primitive
Quad {
Expand Down
12 changes: 6 additions & 6 deletions graphics/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ where
paragraph: &Self::Paragraph,
position: Point,
color: Color,
viewport: Rectangle,
clip_bounds: Rectangle,
) {
self.primitives.push(Primitive::Paragraph {
paragraph: paragraph.downgrade(),
position,
color,
viewport,
clip_bounds,
});
}

Expand All @@ -179,13 +179,13 @@ where
editor: &Self::Editor,
position: Point,
color: Color,
viewport: Rectangle,
clip_bounds: Rectangle,
) {
self.primitives.push(Primitive::Editor {
editor: editor.downgrade(),
position,
color,
viewport,
clip_bounds,
});
}

Expand All @@ -194,7 +194,7 @@ where
text: Text<'_, Self::Font>,
position: Point,
color: Color,
viewport: Rectangle,
clip_bounds: Rectangle,
) {
self.primitives.push(Primitive::Text {
content: text.content.to_string(),
Expand All @@ -206,7 +206,7 @@ where
horizontal_alignment: text.horizontal_alignment,
vertical_alignment: text.vertical_alignment,
shaping: text.shaping,
viewport,
clip_bounds,
});
}
}
Expand Down
12 changes: 6 additions & 6 deletions renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ impl<T> text::Renderer for Renderer<T> {
paragraph: &Self::Paragraph,
position: Point,
color: Color,
viewport: Rectangle,
clip_bounds: Rectangle,
) {
delegate!(
self,
renderer,
renderer.fill_paragraph(paragraph, position, color, viewport)
renderer.fill_paragraph(paragraph, position, color, clip_bounds)
);
}

Expand All @@ -189,12 +189,12 @@ impl<T> text::Renderer for Renderer<T> {
editor: &Self::Editor,
position: Point,
color: Color,
viewport: Rectangle,
clip_bounds: Rectangle,
) {
delegate!(
self,
renderer,
renderer.fill_editor(editor, position, color, viewport)
renderer.fill_editor(editor, position, color, clip_bounds)
);
}

Expand All @@ -203,12 +203,12 @@ impl<T> text::Renderer for Renderer<T> {
text: Text<'_, Self::Font>,
position: Point,
color: Color,
viewport: Rectangle,
clip_bounds: Rectangle,
) {
delegate!(
self,
renderer,
renderer.fill_text(text, position, color, viewport)
renderer.fill_text(text, position, color, clip_bounds)
);
}
}
Expand Down
15 changes: 9 additions & 6 deletions tiny_skia/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,10 @@ impl Backend {
paragraph,
position,
color,
viewport,
clip_bounds: text_clip_bounds,
} => {
let physical_bounds = (*viewport + translation) * scale_factor;
let physical_bounds =
(*text_clip_bounds + translation) * scale_factor;

if !clip_bounds.intersects(&physical_bounds) {
return;
Expand All @@ -385,9 +386,10 @@ impl Backend {
editor,
position,
color,
viewport,
clip_bounds: text_clip_bounds,
} => {
let physical_bounds = (*viewport + translation) * scale_factor;
let physical_bounds =
(*text_clip_bounds + translation) * scale_factor;

if !clip_bounds.intersects(&physical_bounds) {
return;
Expand Down Expand Up @@ -415,9 +417,10 @@ impl Backend {
horizontal_alignment,
vertical_alignment,
shaping,
viewport,
clip_bounds: text_clip_bounds,
} => {
let physical_bounds = (*viewport + translation) * scale_factor;
let physical_bounds =
(*text_clip_bounds + translation) * scale_factor;

if !clip_bounds.intersects(&physical_bounds) {
return;
Expand Down
2 changes: 1 addition & 1 deletion tiny_skia/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Frame {
horizontal_alignment: text.horizontal_alignment,
vertical_alignment: text.vertical_alignment,
shaping: text.shaping,
viewport: bounds,
clip_bounds: Rectangle::with_size(Size::INFINITY),
});
}

Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl Frame {
horizontal_alignment: text.horizontal_alignment,
vertical_alignment: text.vertical_alignment,
shaping: text.shaping,
viewport: bounds,
clip_bounds: Rectangle::with_size(Size::INFINITY),
});
}

Expand Down
14 changes: 7 additions & 7 deletions wgpu/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> Layer<'a> {
horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: alignment::Vertical::Top,
shaping: core::text::Shaping::Basic,
viewport: Rectangle::with_size(Size::INFINITY),
clip_bounds: Rectangle::with_size(Size::INFINITY),
};

overlay.text.push(Text::Cached(text.clone()));
Expand Down Expand Up @@ -124,30 +124,30 @@ impl<'a> Layer<'a> {
paragraph,
position,
color,
viewport,
clip_bounds,
} => {
let layer = &mut layers[current_layer];

layer.text.push(Text::Paragraph {
paragraph: paragraph.clone(),
position: *position + translation,
color: *color,
viewport: *viewport + translation,
clip_bounds: *clip_bounds + translation,
});
}
Primitive::Editor {
editor,
position,
color,
viewport,
clip_bounds,
} => {
let layer = &mut layers[current_layer];

layer.text.push(Text::Editor {
editor: editor.clone(),
position: *position + translation,
color: *color,
viewport: *viewport + translation,
clip_bounds: *clip_bounds + translation,
});
}
Primitive::Text {
Expand All @@ -160,7 +160,7 @@ impl<'a> Layer<'a> {
horizontal_alignment,
vertical_alignment,
shaping,
viewport,
clip_bounds,
} => {
let layer = &mut layers[current_layer];

Expand All @@ -174,7 +174,7 @@ impl<'a> Layer<'a> {
horizontal_alignment: *horizontal_alignment,
vertical_alignment: *vertical_alignment,
shaping: *shaping,
viewport: *viewport + translation,
clip_bounds: *clip_bounds + translation,
}));
}
Primitive::Quad {
Expand Down
8 changes: 4 additions & 4 deletions wgpu/src/layer/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ pub enum Text<'a> {
paragraph: paragraph::Weak,
position: Point,
color: Color,
viewport: Rectangle,
clip_bounds: Rectangle,
},
/// An editor.
#[allow(missing_docs)]
Editor {
editor: editor::Weak,
position: Point,
color: Color,
viewport: Rectangle,
clip_bounds: Rectangle,
},
/// A cached text.
Cached(Cached<'a>),
Expand Down Expand Up @@ -56,6 +56,6 @@ pub struct Cached<'a> {
/// The shaping strategy of the text.
pub shaping: text::Shaping,

/// The viewport of the text.
pub viewport: Rectangle,
/// The clip bounds of the text.
pub clip_bounds: Rectangle,
}
14 changes: 7 additions & 7 deletions wgpu/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ impl Pipeline {
horizontal_alignment,
vertical_alignment,
color,
viewport,
clip_bounds,
) = match section {
Text::Paragraph {
position,
color,
viewport,
clip_bounds,
..
} => {
use crate::core::text::Paragraph as _;
Expand All @@ -141,13 +141,13 @@ impl Pipeline {
paragraph.horizontal_alignment(),
paragraph.vertical_alignment(),
*color,
*viewport,
*clip_bounds,
)
}
Text::Editor {
position,
color,
viewport,
clip_bounds,
..
} => {
use crate::core::text::Editor as _;
Expand All @@ -163,7 +163,7 @@ impl Pipeline {
alignment::Horizontal::Left,
alignment::Vertical::Top,
*color,
*viewport,
*clip_bounds,
)
}
Text::Cached(text) => {
Expand All @@ -182,7 +182,7 @@ impl Pipeline {
text.horizontal_alignment,
text.vertical_alignment,
text.color,
text.viewport,
text.clip_bounds,
)
}
};
Expand All @@ -206,7 +206,7 @@ impl Pipeline {
};

let clip_bounds =
layer_bounds.intersection(&(viewport * scale_factor))?;
layer_bounds.intersection(&(clip_bounds * scale_factor))?;

Some(glyphon::TextArea {
buffer,
Expand Down

0 comments on commit b526ce4

Please sign in to comment.