-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make changes less breaking. Add Section::builder
- Loading branch information
1 parent
5f4c8a9
commit 3852109
Showing
6 changed files
with
83 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::{Section, Text}; | ||
use glyph_brush_layout::{BuiltInLineBreaker, Layout}; | ||
|
||
/// [`Section`] builder. | ||
#[derive(Debug, Clone, Copy, PartialEq)] | ||
pub struct SectionBuilder { | ||
/// Position on screen to render text, in pixels from top-left. Defaults to (0, 0). | ||
pub screen_position: (f32, f32), | ||
/// Max (width, height) bounds, in pixels from top-left. Defaults to unbounded. | ||
pub bounds: (f32, f32), | ||
/// Built in layout, can be overridden with custom layout logic | ||
/// see [`queue_custom_layout`](struct.GlyphBrush.html#method.queue_custom_layout) | ||
pub layout: Layout<BuiltInLineBreaker>, | ||
} | ||
|
||
impl Default for SectionBuilder { | ||
fn default() -> Self { | ||
Self { | ||
screen_position: (0.0, 0.0), | ||
bounds: (f32::INFINITY, f32::INFINITY), | ||
layout: Layout::default(), | ||
} | ||
} | ||
} | ||
|
||
impl SectionBuilder { | ||
#[inline] | ||
pub fn with_screen_position<P: Into<(f32, f32)>>(mut self, position: P) -> Self { | ||
self.screen_position = position.into(); | ||
self | ||
} | ||
|
||
#[inline] | ||
pub fn with_bounds<P: Into<(f32, f32)>>(mut self, bounds: P) -> Self { | ||
self.bounds = bounds.into(); | ||
self | ||
} | ||
|
||
#[inline] | ||
pub fn with_layout<L: Into<Layout<BuiltInLineBreaker>>>(mut self, layout: L) -> Self { | ||
self.layout = layout.into(); | ||
self | ||
} | ||
|
||
#[inline] | ||
pub fn add_text<X>(self, text: Text<'_, X>) -> Section<'_, X> { | ||
self.with_text(vec![text]) | ||
} | ||
|
||
#[inline] | ||
pub fn with_text<X>(self, text: Vec<Text<'_, X>>) -> Section<'_, X> { | ||
Section { | ||
text, | ||
screen_position: self.screen_position, | ||
bounds: self.bounds, | ||
layout: self.layout, | ||
} | ||
} | ||
} |