Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
#58 updated text bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
bennobuilder committed Mar 25, 2024
1 parent a1de70f commit 2584c61
Show file tree
Hide file tree
Showing 32 changed files with 296 additions and 366 deletions.
80 changes: 29 additions & 51 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions crates/attributed_string/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "attributed-string"
name = "dyn-attributed-string"
version = "0.0.1"
description = ""
edition = { workspace = true }
Expand All @@ -10,6 +10,12 @@ authors = { workspace = true }

[features]
default = []
serde_support = [
"dep:serde",
"dep:specta",
"dyn-utils/serde_support",
"dyn-fonts-book/serde_support",
]
tracing = []

[dependencies]
Expand All @@ -18,16 +24,17 @@ dyn-utils = { path = "../utils" }
fontdb = "0.16.0"
glam = { workspace = true }
rustybuzz = "0.13.0"
ropey = "1.6.1"
rust-lapper = { path = "/Users/benno/Desktop/workspace/contribution/code/rust-lapper" }
smallvec = { workspace = true }
strict-num = "0.2.0"
tiny-skia-path = { workspace = true }
unicode-bidi = "0.3"
unicode-linebreak = "0.1.5"
unicode-script = "0.5"
unicode-vo = "0.1"
self_cell = "1.0.3"

# serde_support (feature)
specta = { workspace = true, features = ["serde", "glam"], optional = true }
serde = { workspace = true, features = ["derive"], optional = true }

# Logging
log = { workspace = true }
Expand Down
6 changes: 6 additions & 0 deletions crates/attributed_string/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub mod shape;
pub mod tokens;
pub mod utils;

pub use dyn_fonts_book;

use crate::{outline::outline, tokens::shape::ShapeToken};
use attrs::{Attrs, AttrsInterval, AttrsIntervals};
use dyn_fonts_book::FontsBook;
Expand Down Expand Up @@ -267,6 +269,10 @@ struct AttributedStringConfig {
}

#[derive(Debug, Default, Clone, Copy)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize, specta::Type)
)]
pub enum LineWrap {
/// No wrapping
#[default]
Expand Down
9 changes: 8 additions & 1 deletion crates/comp_bundles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ authors = { workspace = true }

[features]
default = []
serde_support = ["dep:serde", "dep:specta", "dyn-comp-asset/serde_support"]
serde_support = [
"dep:serde",
"dep:specta",
"dyn-comp-asset/serde_support",
"dyn-attributed-string/serde_support",
"dyn-utils/serde_support",
]
tracing = []

[dependencies]
dyn-comp-asset = { path = "../comp_asset" }
dyn-attributed-string = { path = "../attributed_string" }
dyn-utils = { path = "../utils" }
bevy_ecs = { workspace = true }
bevy_hierarchy = { workspace = true }
Expand Down
134 changes: 5 additions & 129 deletions crates/comp_bundles/src/components/nodes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use bevy_ecs::component::Component;
use dyn_utils::units::abs::Abs;
use dyn_attributed_string::LineWrap;
use smallvec::SmallVec;

use crate::properties::TextAttributeInterval;

#[derive(Component, Debug, Copy, Clone)]
pub struct CompNode {
pub variant: CompNodeVariant,
Expand Down Expand Up @@ -69,135 +71,9 @@ pub struct PolygonCompNode {
/// A text shape node with customizable style and alignment properties.
#[derive(Component, Debug, Default, Clone)]
pub struct TextCompNode {
/// Text spans with individual styles.
pub spans: SmallVec<[TextSpan; 2]>,
/// Horizontal alignment within the container.
pub horizontal_text_alignment: HorizontalTextAlignment,
/// Vertical alignment within the container.
pub vertical_text_alignment: VerticalTextAlignment,
/// Line breaking behavior.
pub linebreak_behavior: BreakLineOn,
}

/// A styled text segment.
#[derive(Debug, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize, specta::Type)
)]
pub struct TextSpan {
/// Text content.
pub text: String,
/// Font metadata.
pub font: FontMetadata,
/// Style properties.
pub style: TextStyle,
}

#[derive(Debug, Default, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize, specta::Type),
serde(rename_all = "camelCase")
)]
pub struct FontMetadata {
/// The font family to which this font belongs.
pub family: String,
/// The style of the font, such as italic or normal.
pub style: FontStyle,
/// The weight of the font, typically ranging from 100 (thin) to 900 (black).
pub weight: u16,
}

#[derive(Debug, Default, Copy, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize, specta::Type)
)]
pub enum FontStyle {
/// A face that is neither italic not obliqued.
#[default]
Normal,
/// A form that is generally cursive in nature.
Italic,
/// A typically-sloped version of the regular face.
Oblique,
}

/// Style properties for a text segment.
#[derive(Debug, Default, Copy, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize, specta::Type),
serde(rename_all = "camelCase")
)]
pub struct TextStyle {
/// Glyph height in pixels, may scale with window.
pub font_size: f32,
/// Character spacing.
pub letter_spacing: LetterSpacing,
/// Line spacing.
pub line_height: LineHeight,
}

#[derive(Debug, Default, Copy, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize, specta::Type)
)]
pub enum HorizontalTextAlignment {
#[default]
Left,
Center,
Right,
Justified,
}

#[derive(Debug, Default, Copy, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize, specta::Type)
)]
pub enum VerticalTextAlignment {
Top,
#[default]
Center,
Bottom,
Justified,
}

#[derive(Debug, Default, Copy, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize, specta::Type)
)]
pub enum LetterSpacing {
#[default]
Auto,
Fixed(Abs),
}

#[derive(Debug, Default, Copy, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize, specta::Type)
)]
pub enum LineHeight {
#[default]
Auto,
Fixed(Abs),
}

#[derive(Debug, Default, Copy, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize, specta::Type)
)]
pub enum BreakLineOn {
#[default]
WordBoundary,
AnyCharacter,
NoWrap,
pub attributes: SmallVec<[TextAttributeInterval; 2]>,
pub line_wrap: LineWrap,
}

/// A vector shape node.
Expand Down
2 changes: 1 addition & 1 deletion crates/comp_bundles/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::viewport::Viewport;
use crate::properties::Viewport;
use bevy_ecs::{entity::Entity, event::Event, world::World};
use dyn_utils::{properties::size::Size, units::angle::Angle};
use std::fmt::Debug;
Expand Down
Loading

0 comments on commit 2584c61

Please sign in to comment.