Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistently use FontWeight as the name #778

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions masonry/examples/hello_masonry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
use masonry::dpi::LogicalSize;
use masonry::text::StyleProperty;
use masonry::widget::{Button, Flex, Label, RootWidget};
use masonry::{Action, AppDriver, DriverCtx, WidgetId};
use parley::fontique::Weight;
use masonry::{Action, AppDriver, DriverCtx, FontWeight, WidgetId};
use winit::window::Window;

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

// Arrange the two widgets vertically, with some padding
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ pub use vello::kurbo;

pub use cursor_icon::{CursorIcon, ParseError as CursorIconParseError};
pub use kurbo::{Affine, Insets, Point, Rect, Size, Vec2};
pub use parley::fontique::Weight as TextWeight;
pub use parley::layout::Alignment as TextAlignment;
pub use parley::style::FontWeight;
pub use vello::peniko::{Color, Gradient};

pub use action::Action;
Expand Down
9 changes: 4 additions & 5 deletions masonry/src/widget/variable_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use std::cmp::Ordering;

use accesskit::{Node, Role};
use parley::fontique::Weight;
use smallvec::{smallvec, SmallVec};
use tracing::{trace_span, Span};
use vello::kurbo::{Point, Size};
Expand All @@ -15,8 +14,8 @@ use vello::Scene;
use crate::text::{ArcStr, StyleProperty};
use crate::widget::WidgetMut;
use crate::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx,
RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId,
AccessCtx, AccessEvent, BoxConstraints, EventCtx, FontWeight, LayoutCtx, PaintCtx,
PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};

use super::{Label, WidgetPod};
Expand Down Expand Up @@ -142,7 +141,7 @@ impl VariableLabel {
pub fn from_label_pod(label: WidgetPod<Label>) -> Self {
Self {
label,
weight: AnimatedF32::stable(Weight::NORMAL.value()),
weight: AnimatedF32::stable(FontWeight::NORMAL.value()),
}
}

Expand Down Expand Up @@ -206,7 +205,7 @@ impl Widget for VariableLabel {
}
Label::insert_style(
&mut label,
StyleProperty::FontWeight(Weight::new(new_weight)),
StyleProperty::FontWeight(FontWeight::new(new_weight)),
);
});
if !result.is_completed() {
Expand Down
4 changes: 2 additions & 2 deletions xilem/examples/mason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use xilem::view::{
button, button_any_pointer, checkbox, flex, label, prose, task, textbox, Axis, FlexExt as _,
FlexSpacer,
};
use xilem::{Color, EventLoop, EventLoopBuilder, TextAlignment, TextWeight, WidgetView, Xilem};
use xilem::{Color, EventLoop, EventLoopBuilder, FontWeight, TextAlignment, WidgetView, Xilem};
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.

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. ";
Expand Down Expand Up @@ -66,7 +66,7 @@ fn app_logic(data: &mut AppData) -> impl WidgetView<AppData> {
flex((
flex((
label("Label").brush(Color::REBECCA_PURPLE),
label("Bold Label").weight(TextWeight::BOLD),
label("Bold Label").weight(FontWeight::BOLD),
// TODO masonry doesn't allow setting disabled manually anymore?
// label("Disabled label").disabled(),
))
Expand Down
7 changes: 3 additions & 4 deletions xilem/examples/variable_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use std::time::Duration;

use masonry::parley::fontique::Weight;
use time::error::IndeterminateOffset;
use time::macros::format_description;
use time::{OffsetDateTime, UtcOffset};
Expand All @@ -16,11 +15,11 @@ use xilem::view::{
button, flex, inline_prose, label, portal, prose, sized_box, task, variable_label, Axis,
FlexExt, FlexSpacer,
};
use xilem::{Color, EventLoop, EventLoopBuilder, WidgetView, Xilem};
use xilem::{Color, EventLoop, EventLoopBuilder, FontWeight, WidgetView, Xilem};

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

fn run(event_loop: EventLoopBuilder) -> Result<(), EventLoopError> {
let data = Clocks {
weight: Weight::BLACK.value(),
weight: FontWeight::BLACK.value(),
// TODO: We can't get this on Android, because
local_offset: UtcOffset::current_local_offset(),
now_utc: OffsetDateTime::now_utc(),
Expand Down
2 changes: 1 addition & 1 deletion xilem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use crate::core::{
ViewPathTracker, ViewSequence,
};
pub use masonry::event_loop_runner::{EventLoop, EventLoopBuilder};
pub use masonry::{dpi, Color, TextAlignment, TextWeight};
pub use masonry::{dpi, Color, FontWeight, TextAlignment};
pub use xilem_core as core;

/// Tokio is the async runner used with Xilem.
Expand Down
10 changes: 5 additions & 5 deletions xilem/src/view/label.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright 2024 the Xilem Authors
// SPDX-License-Identifier: Apache-2.0

use masonry::parley::FontStack;
use masonry::parley::style::{FontStack, FontWeight};
use masonry::text::{ArcStr, StyleProperty};
use masonry::widget;
use vello::peniko::Brush;

use crate::core::{DynMessage, Mut, ViewMarker};
use crate::{Color, MessageResult, Pod, TextAlignment, TextWeight, View, ViewCtx, ViewId};
use crate::{Color, MessageResult, Pod, TextAlignment, View, ViewCtx, ViewId};

pub fn label(label: impl Into<ArcStr>) -> Label {
Label {
label: label.into(),
text_brush: Color::WHITE.into(),
alignment: TextAlignment::default(),
text_size: masonry::theme::TEXT_SIZE_NORMAL,
weight: TextWeight::NORMAL,
weight: FontWeight::NORMAL,
font: FontStack::List(std::borrow::Cow::Borrowed(&[])),
}
}
Expand All @@ -28,7 +28,7 @@ pub struct Label {
pub(in crate::view) text_brush: Brush,
pub(in crate::view) alignment: TextAlignment,
pub(in crate::view) text_size: f32,
pub(in crate::view) weight: TextWeight,
pub(in crate::view) weight: FontWeight,
pub(in crate::view) font: FontStack<'static>, // TODO: add more attributes of `masonry::widget::Label`
}

Expand All @@ -50,7 +50,7 @@ impl Label {
self
}

pub fn weight(mut self, weight: TextWeight) -> Self {
pub fn weight(mut self, weight: FontWeight) -> Self {
self.weight = weight;
self
}
Expand Down
13 changes: 6 additions & 7 deletions xilem/src/view/variable_label.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
// Copyright 2024 the Xilem Authors
// SPDX-License-Identifier: Apache-2.0

use masonry::parley::fontique::Weight;
use masonry::parley::style::FontStack;
use masonry::parley::style::{FontStack, FontWeight};
use masonry::text::ArcStr;
use masonry::{widget, TextAlignment};
use vello::peniko::Brush;
use xilem_core::ViewPathTracker;

use crate::core::{DynMessage, Mut, ViewMarker};
use crate::{MessageResult, Pod, TextWeight, View, ViewCtx, ViewId};
use crate::{MessageResult, Pod, View, ViewCtx, ViewId};

use super::{label, Label};

/// A view for displaying non-editable text, with a variable [weight](masonry::parley::style::FontWeight).
pub fn variable_label(text: impl Into<ArcStr>) -> VariableLabel {
VariableLabel {
label: label(text),
target_weight: Weight::NORMAL,
target_weight: FontWeight::NORMAL,
over_millis: 0.,
}
}

#[must_use = "View values do nothing unless provided to Xilem."]
pub struct VariableLabel {
label: Label,
target_weight: Weight,
target_weight: FontWeight,
over_millis: f32,
}

Expand All @@ -45,7 +44,7 @@ impl VariableLabel {
/// If `weight` is non-finite.
pub fn target_weight(mut self, weight: f32, over_millis: f32) -> Self {
assert!(weight.is_finite(), "Invalid target weight {weight}.");
self.target_weight = Weight::new(weight);
self.target_weight = FontWeight::new(weight);
self.over_millis = over_millis;
self
}
Expand Down Expand Up @@ -79,7 +78,7 @@ impl VariableLabel {
self
}

pub fn weight(mut self, weight: TextWeight) -> Self {
pub fn weight(mut self, weight: FontWeight) -> Self {
self.label.weight = weight;
self
}
Expand Down
Loading