Skip to content

Commit f976bf4

Browse files
Move TextStyle into styled_text
1 parent 7db0cb8 commit f976bf4

File tree

3 files changed

+83
-75
lines changed

3 files changed

+83
-75
lines changed

parley/src/style/mod.rs

+1-74
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
66
mod styleset;
77

8-
use alloc::borrow::Cow;
98
pub use styled_text::{
109
Brush, FontFamily, FontSettings, FontStack, GenericFamily, Stretch as FontStretch,
11-
Style as FontStyle, StyleProperty, Weight as FontWeight,
10+
Style as FontStyle, StyleProperty, TextStyle, Weight as FontWeight,
1211
};
1312

1413
pub use styleset::StyleSet;
@@ -24,75 +23,3 @@ pub enum WhiteSpaceCollapse {
2423
Collapse,
2524
Preserve,
2625
}
27-
28-
/// Unresolved styles.
29-
#[derive(Clone, PartialEq, Debug)]
30-
pub struct TextStyle<'a, B: Brush> {
31-
/// Font family stack.
32-
pub font_stack: FontStack<'a>,
33-
/// Font size.
34-
pub font_size: f32,
35-
/// Font stretch.
36-
pub font_stretch: FontStretch,
37-
/// Font style.
38-
pub font_style: FontStyle,
39-
/// Font weight.
40-
pub font_weight: FontWeight,
41-
/// Font variation settings.
42-
pub font_variations: FontSettings<'a, styled_text::FontVariation>,
43-
/// Font feature settings.
44-
pub font_features: FontSettings<'a, styled_text::FontFeature>,
45-
/// Locale.
46-
pub locale: Option<&'a str>,
47-
/// Brush for rendering text.
48-
pub brush: B,
49-
/// Underline decoration.
50-
pub has_underline: bool,
51-
/// Offset of the underline decoration.
52-
pub underline_offset: Option<f32>,
53-
/// Size of the underline decoration.
54-
pub underline_size: Option<f32>,
55-
/// Brush for rendering the underline decoration.
56-
pub underline_brush: Option<B>,
57-
/// Strikethrough decoration.
58-
pub has_strikethrough: bool,
59-
/// Offset of the strikethrough decoration.
60-
pub strikethrough_offset: Option<f32>,
61-
/// Size of the strikethrough decoration.
62-
pub strikethrough_size: Option<f32>,
63-
/// Brush for rendering the strikethrough decoration.
64-
pub strikethrough_brush: Option<B>,
65-
/// Line height multiplier.
66-
pub line_height: f32,
67-
/// Extra spacing between words.
68-
pub word_spacing: f32,
69-
/// Extra spacing between letters.
70-
pub letter_spacing: f32,
71-
}
72-
73-
impl<B: Brush> Default for TextStyle<'_, B> {
74-
fn default() -> Self {
75-
TextStyle {
76-
font_stack: FontStack::Source(Cow::Borrowed("sans-serif")),
77-
font_size: 16.0,
78-
font_stretch: Default::default(),
79-
font_style: Default::default(),
80-
font_weight: Default::default(),
81-
font_variations: FontSettings::List(Cow::Borrowed(&[])),
82-
font_features: FontSettings::List(Cow::Borrowed(&[])),
83-
locale: Default::default(),
84-
brush: Default::default(),
85-
has_underline: Default::default(),
86-
underline_offset: Default::default(),
87-
underline_size: Default::default(),
88-
underline_brush: Default::default(),
89-
has_strikethrough: Default::default(),
90-
strikethrough_offset: Default::default(),
91-
strikethrough_size: Default::default(),
92-
strikethrough_brush: Default::default(),
93-
line_height: 1.2,
94-
word_spacing: Default::default(),
95-
letter_spacing: Default::default(),
96-
}
97-
}
98-
}

styled_text/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ mod font_family;
2727
mod font_settings;
2828
mod font_stack;
2929
mod generic_family;
30-
pub mod setting;
3130
mod style_property;
31+
mod text_style;
32+
33+
pub mod setting;
3234

3335
pub use attributes::{Stretch, Style, Weight};
3436
pub use brush::Brush;
@@ -37,3 +39,4 @@ pub use font_settings::{FontFeature, FontSettings, FontVariation};
3739
pub use font_stack::FontStack;
3840
pub use generic_family::GenericFamily;
3941
pub use style_property::StyleProperty;
42+
pub use text_style::TextStyle;

styled_text/src/text_style.rs

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2021 the Parley Authors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
use alloc::borrow::Cow;
5+
6+
use crate::{Brush, FontFeature, FontSettings, FontStack, FontVariation, Stretch, Style, Weight};
7+
8+
/// Unresolved styles.
9+
#[derive(Clone, PartialEq, Debug)]
10+
pub struct TextStyle<'a, B: Brush> {
11+
/// Font family stack.
12+
pub font_stack: FontStack<'a>,
13+
/// Font size.
14+
pub font_size: f32,
15+
/// Font stretch.
16+
pub font_stretch: Stretch,
17+
/// Font style.
18+
pub font_style: Style,
19+
/// Font weight.
20+
pub font_weight: Weight,
21+
/// Font variation settings.
22+
pub font_variations: FontSettings<'a, FontVariation>,
23+
/// Font feature settings.
24+
pub font_features: FontSettings<'a, FontFeature>,
25+
/// Locale.
26+
pub locale: Option<&'a str>,
27+
/// Brush for rendering text.
28+
pub brush: B,
29+
/// Underline decoration.
30+
pub has_underline: bool,
31+
/// Offset of the underline decoration.
32+
pub underline_offset: Option<f32>,
33+
/// Size of the underline decoration.
34+
pub underline_size: Option<f32>,
35+
/// Brush for rendering the underline decoration.
36+
pub underline_brush: Option<B>,
37+
/// Strikethrough decoration.
38+
pub has_strikethrough: bool,
39+
/// Offset of the strikethrough decoration.
40+
pub strikethrough_offset: Option<f32>,
41+
/// Size of the strikethrough decoration.
42+
pub strikethrough_size: Option<f32>,
43+
/// Brush for rendering the strikethrough decoration.
44+
pub strikethrough_brush: Option<B>,
45+
/// Line height multiplier.
46+
pub line_height: f32,
47+
/// Extra spacing between words.
48+
pub word_spacing: f32,
49+
/// Extra spacing between letters.
50+
pub letter_spacing: f32,
51+
}
52+
53+
impl<B: Brush> Default for TextStyle<'_, B> {
54+
fn default() -> Self {
55+
TextStyle {
56+
font_stack: FontStack::Source(Cow::Borrowed("sans-serif")),
57+
font_size: 16.0,
58+
font_stretch: Default::default(),
59+
font_style: Default::default(),
60+
font_weight: Default::default(),
61+
font_variations: FontSettings::List(Cow::Borrowed(&[])),
62+
font_features: FontSettings::List(Cow::Borrowed(&[])),
63+
locale: Default::default(),
64+
brush: Default::default(),
65+
has_underline: Default::default(),
66+
underline_offset: Default::default(),
67+
underline_size: Default::default(),
68+
underline_brush: Default::default(),
69+
has_strikethrough: Default::default(),
70+
strikethrough_offset: Default::default(),
71+
strikethrough_size: Default::default(),
72+
strikethrough_brush: Default::default(),
73+
line_height: 1.2,
74+
word_spacing: Default::default(),
75+
letter_spacing: Default::default(),
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)