Skip to content

Commit e2acb29

Browse files
Consistently use FontWeight as the name
Right now, there are uses of `Weight` from Fontique, `TextWeight` from Masonry, and `FontWeight` from Parley. We should just use a single name.
1 parent 9439b55 commit e2acb29

File tree

8 files changed

+24
-28
lines changed

8 files changed

+24
-28
lines changed

masonry/examples/hello_masonry.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
use masonry::dpi::LogicalSize;
1111
use masonry::text::StyleProperty;
1212
use masonry::widget::{Button, Flex, Label, RootWidget};
13-
use masonry::{Action, AppDriver, DriverCtx, WidgetId};
14-
use parley::fontique::Weight;
13+
use masonry::{Action, AppDriver, DriverCtx, FontWeight, WidgetId};
1514
use winit::window::Window;
1615

1716
const VERTICAL_WIDGET_SPACING: f64 = 20.0;
@@ -35,7 +34,7 @@ fn main() {
3534
let label = Label::new("Hello")
3635
.with_style(StyleProperty::FontSize(32.0))
3736
// Ideally there's be an Into in Parley for this
38-
.with_style(StyleProperty::FontWeight(Weight::BOLD));
37+
.with_style(StyleProperty::FontWeight(FontWeight::BOLD));
3938
let button = Button::new("Say hello");
4039

4140
// Arrange the two widgets vertically, with some padding

masonry/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ pub use vello::kurbo;
177177

178178
pub use cursor_icon::{CursorIcon, ParseError as CursorIconParseError};
179179
pub use kurbo::{Affine, Insets, Point, Rect, Size, Vec2};
180-
pub use parley::fontique::Weight as TextWeight;
181180
pub use parley::layout::Alignment as TextAlignment;
181+
pub use parley::style::FontWeight;
182182
pub use vello::peniko::{Color, Gradient};
183183

184184
pub use action::Action;

masonry/src/widget/variable_label.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use std::cmp::Ordering;
77

88
use accesskit::{Node, Role};
9-
use parley::fontique::Weight;
109
use smallvec::{smallvec, SmallVec};
1110
use tracing::{trace_span, Span};
1211
use vello::kurbo::{Point, Size};
@@ -15,8 +14,8 @@ use vello::Scene;
1514
use crate::text::{ArcStr, StyleProperty};
1615
use crate::widget::WidgetMut;
1716
use crate::{
18-
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx,
19-
RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId,
17+
AccessCtx, AccessEvent, BoxConstraints, EventCtx, FontWeight, LayoutCtx, PaintCtx,
18+
PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId,
2019
};
2120

2221
use super::{Label, WidgetPod};
@@ -142,7 +141,7 @@ impl VariableLabel {
142141
pub fn from_label_pod(label: WidgetPod<Label>) -> Self {
143142
Self {
144143
label,
145-
weight: AnimatedF32::stable(Weight::NORMAL.value()),
144+
weight: AnimatedF32::stable(FontWeight::NORMAL.value()),
146145
}
147146
}
148147

@@ -206,7 +205,7 @@ impl Widget for VariableLabel {
206205
}
207206
Label::insert_style(
208207
&mut label,
209-
StyleProperty::FontWeight(Weight::new(new_weight)),
208+
StyleProperty::FontWeight(FontWeight::new(new_weight)),
210209
);
211210
});
212211
if !result.is_completed() {

xilem/examples/mason.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use xilem::view::{
1616
button, button_any_pointer, checkbox, flex, label, prose, task, textbox, Axis, FlexExt as _,
1717
FlexSpacer,
1818
};
19-
use xilem::{Color, EventLoop, EventLoopBuilder, TextAlignment, TextWeight, WidgetView, Xilem};
19+
use xilem::{Color, EventLoop, EventLoopBuilder, FontWeight, TextAlignment, WidgetView, Xilem};
2020
const LOREM: &str = r"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi cursus mi sed euismod euismod. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nullam placerat efficitur tellus at semper. Morbi ac risus magna. Donec ut cursus ex. Etiam quis posuere tellus. Mauris posuere dui et turpis mollis, vitae luctus tellus consectetur. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu facilisis nisl.
2121
2222
Phasellus in viverra dolor, vitae facilisis est. Maecenas malesuada massa vel ultricies feugiat. Vivamus venenatis et nibh nec pharetra. Phasellus vestibulum elit enim, nec scelerisque orci faucibus id. Vivamus consequat purus sit amet orci egestas, non iaculis massa porttitor. Vestibulum ut eros leo. In fermentum convallis magna in finibus. Donec justo leo, maximus ac laoreet id, volutpat ut elit. Mauris sed leo non neque laoreet faucibus. Aliquam orci arcu, faucibus in molestie eget, ornare non dui. Donec volutpat nulla in fringilla elementum. Aliquam vitae ante egestas ligula tempus vestibulum sit amet sed ante. ";
@@ -66,7 +66,7 @@ fn app_logic(data: &mut AppData) -> impl WidgetView<AppData> {
6666
flex((
6767
flex((
6868
label("Label").brush(Color::REBECCA_PURPLE),
69-
label("Bold Label").weight(TextWeight::BOLD),
69+
label("Bold Label").weight(FontWeight::BOLD),
7070
// TODO masonry doesn't allow setting disabled manually anymore?
7171
// label("Disabled label").disabled(),
7272
))

xilem/examples/variable_clock.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use std::time::Duration;
88

9-
use masonry::parley::fontique::Weight;
109
use time::error::IndeterminateOffset;
1110
use time::macros::format_description;
1211
use time::{OffsetDateTime, UtcOffset};
@@ -16,11 +15,11 @@ use xilem::view::{
1615
button, flex, inline_prose, label, portal, prose, sized_box, task, variable_label, Axis,
1716
FlexExt, FlexSpacer,
1817
};
19-
use xilem::{Color, EventLoop, EventLoopBuilder, WidgetView, Xilem};
18+
use xilem::{Color, EventLoop, EventLoopBuilder, FontWeight, WidgetView, Xilem};
2019

2120
/// The state of the application, owned by Xilem and updated by the callbacks below.
2221
struct Clocks {
23-
/// The font [weight](Weight) used for the values.
22+
/// The font [weight](FontWeight) used for the values.
2423
weight: f32,
2524
/// The current UTC offset on this machine.
2625
local_offset: Result<UtcOffset, IndeterminateOffset>,
@@ -182,7 +181,7 @@ const ROBOTO_FLEX: &[u8] = include_bytes!(concat!(
182181

183182
fn run(event_loop: EventLoopBuilder) -> Result<(), EventLoopError> {
184183
let data = Clocks {
185-
weight: Weight::BLACK.value(),
184+
weight: FontWeight::BLACK.value(),
186185
// TODO: We can't get this on Android, because
187186
local_offset: UtcOffset::current_local_offset(),
188187
now_utc: OffsetDateTime::now_utc(),

xilem/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use crate::core::{
5454
ViewPathTracker, ViewSequence,
5555
};
5656
pub use masonry::event_loop_runner::{EventLoop, EventLoopBuilder};
57-
pub use masonry::{dpi, Color, TextAlignment, TextWeight};
57+
pub use masonry::{dpi, Color, FontWeight, TextAlignment};
5858
pub use xilem_core as core;
5959

6060
/// Tokio is the async runner used with Xilem.

xilem/src/view/label.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
// Copyright 2024 the Xilem Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use masonry::parley::FontStack;
4+
use masonry::parley::style::{FontStack, FontWeight};
55
use masonry::text::{ArcStr, StyleProperty};
66
use masonry::widget;
77
use vello::peniko::Brush;
88

99
use crate::core::{DynMessage, Mut, ViewMarker};
10-
use crate::{Color, MessageResult, Pod, TextAlignment, TextWeight, View, ViewCtx, ViewId};
10+
use crate::{Color, MessageResult, Pod, TextAlignment, View, ViewCtx, ViewId};
1111

1212
pub fn label(label: impl Into<ArcStr>) -> Label {
1313
Label {
1414
label: label.into(),
1515
text_brush: Color::WHITE.into(),
1616
alignment: TextAlignment::default(),
1717
text_size: masonry::theme::TEXT_SIZE_NORMAL,
18-
weight: TextWeight::NORMAL,
18+
weight: FontWeight::NORMAL,
1919
font: FontStack::List(std::borrow::Cow::Borrowed(&[])),
2020
}
2121
}
@@ -28,7 +28,7 @@ pub struct Label {
2828
pub(in crate::view) text_brush: Brush,
2929
pub(in crate::view) alignment: TextAlignment,
3030
pub(in crate::view) text_size: f32,
31-
pub(in crate::view) weight: TextWeight,
31+
pub(in crate::view) weight: FontWeight,
3232
pub(in crate::view) font: FontStack<'static>, // TODO: add more attributes of `masonry::widget::Label`
3333
}
3434

@@ -50,7 +50,7 @@ impl Label {
5050
self
5151
}
5252

53-
pub fn weight(mut self, weight: TextWeight) -> Self {
53+
pub fn weight(mut self, weight: FontWeight) -> Self {
5454
self.weight = weight;
5555
self
5656
}

xilem/src/view/variable_label.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
// Copyright 2024 the Xilem Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use masonry::parley::fontique::Weight;
5-
use masonry::parley::style::FontStack;
4+
use masonry::parley::style::{FontStack, FontWeight};
65
use masonry::text::ArcStr;
76
use masonry::{widget, TextAlignment};
87
use vello::peniko::Brush;
98
use xilem_core::ViewPathTracker;
109

1110
use crate::core::{DynMessage, Mut, ViewMarker};
12-
use crate::{MessageResult, Pod, TextWeight, View, ViewCtx, ViewId};
11+
use crate::{MessageResult, Pod, View, ViewCtx, ViewId};
1312

1413
use super::{label, Label};
1514

1615
/// A view for displaying non-editable text, with a variable [weight](masonry::parley::style::FontWeight).
1716
pub fn variable_label(text: impl Into<ArcStr>) -> VariableLabel {
1817
VariableLabel {
1918
label: label(text),
20-
target_weight: Weight::NORMAL,
19+
target_weight: FontWeight::NORMAL,
2120
over_millis: 0.,
2221
}
2322
}
2423

2524
#[must_use = "View values do nothing unless provided to Xilem."]
2625
pub struct VariableLabel {
2726
label: Label,
28-
target_weight: Weight,
27+
target_weight: FontWeight,
2928
over_millis: f32,
3029
}
3130

@@ -45,7 +44,7 @@ impl VariableLabel {
4544
/// If `weight` is non-finite.
4645
pub fn target_weight(mut self, weight: f32, over_millis: f32) -> Self {
4746
assert!(weight.is_finite(), "Invalid target weight {weight}.");
48-
self.target_weight = Weight::new(weight);
47+
self.target_weight = FontWeight::new(weight);
4948
self.over_millis = over_millis;
5049
self
5150
}
@@ -79,7 +78,7 @@ impl VariableLabel {
7978
self
8079
}
8180

82-
pub fn weight(mut self, weight: TextWeight) -> Self {
81+
pub fn weight(mut self, weight: FontWeight) -> Self {
8382
self.label.weight = weight;
8483
self
8584
}

0 commit comments

Comments
 (0)