Skip to content
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
113 changes: 106 additions & 7 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "protextinator"
version = "0.4.0"
version = "0.5.0"
edition = "2021"
description = "Text management, made simple"
keywords = ["text", "rendering", "gui", "graphics", "image"]
Expand All @@ -16,7 +16,7 @@ default = []
serialization = ["dep:serde"]

[dependencies]
cosmic-text = "0.14"
cosmic-text = "0.16.0"
ahash = "0.8.12"
smol_str = "0.3"
serde = { version = "1.0.219", features = ["derive"], optional = true }
Expand Down
128 changes: 73 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,99 @@
# 🚀 Protextinator
# Protextinator

<div align="center">
<a href="https://crates.io/crates/protextinator"><img src="https://img.shields.io/crates/v/protextinator.svg" alt="Crates.io"></a>
<a href="https://docs.rs/protextinator/latest/protextinator/"><img src="https://img.shields.io/docsrs/protextinator" alt="Docs.rs"></a>
<a href="https://github.com/antouhou/protextinator/blob/main/LICENSE_MIT"><img src="https://img.shields.io/crates/l/protextinator" alt="License"></a>
</div>
[![Crates.io](https://img.shields.io/crates/v/protextinator.svg)](https://crates.io/crates/protextinator)
[![Docs.rs](https://img.shields.io/docsrs/protextinator)](https://docs.rs/protextinator/latest/protextinator/)
[![License](https://img.shields.io/crates/l/protextinator)](https://github.com/antouhou/protextinator/blob/main/LICENSE_MIT)

## ✨ Text Management, Made Simple!
Protextinator is a text editing and rendering library for Rust, built on top of [cosmic_text](https://github.com/pop-os/cosmic-text). It provides a simpler API while adding features like vertical alignment, scroll position management, and text selection.

**Protextinator** is a powerful text editing and rendering library built on top of [cosmic_text](https://github.com/pop-os/cosmic-text), providing a simpler API with advanced features for all your text handling needs!
**Note:** This library is still a work in progress. APIs may change.

> 💡 Perfect for game UIs, text editors, and any application that needs sophisticated text rendering with minimal hassle.
## Features

⚠️ **WARNING**: This library is work in progress, use at your own risk! ⚠️
- Vertical text alignment
- Text buffer size measurement
- Scroll position management with absolute coordinates
- Simple font loading from files or embedded bytes
- Text state collection with optional usage tracking
- Custom metadata for text states
- Text selection and editing
- Efficient text buffer caching
- Word wrapping and text styling
- Optional serialization support

## 🔥 Features
## Installation

- **Vertical text alignment** - Position your text exactly where you want it
- **Text buffer size measurement** - Know exactly how much space your text needs
- **Scroll position management** with absolute coordinates
- **Simple font loading interface** - Load fonts from files or embedded bytes
- **Text state collection** with optional usage tracking for garbage collection
- **Custom metadata** for text states
- **Text selection and editing** capabilities
- **Efficient text buffer caching**
- **Word wrapping and text styling**
- **Optional serialization** support via the `serialization` feature

## 📦 Installation

Add Protextinator to your `Cargo.toml`:
Add this to your `Cargo.toml`:

```toml
[dependencies]
protextinator = "0.1.0"
protextinator = "0.5.0"
```

With serialization support:
With serialization:

```toml
[dependencies]
protextinator = { version = "0.1.0", features = ["serialization"] }
```

## 🚀 Quick Start

For code examples and detailed usage, check out:
- [Documentation on docs.rs](https://docs.rs/protextinator/)
- [Example code in the repository](https://github.com/antouhou/protextinator/tree/main/examples)

Protextinator makes it easy to:
1. Create and manage text states
2. Style text with various fonts, colors, and alignments
3. Handle text selection and editing
4. Efficiently render text in your application

## 🎮 Integration Example

Protextinator works great with rendering libraries like [Grafo](https://github.com/antouhou/grafo) and windowing libraries like [Winit](https://github.com/rust-windowing/winit). Check out the examples directory for a complete integration example.

## 📚 API Overview

- **TextManager**: The main entry point for managing text states and fonts
- **TextState**: Represents a text buffer with styling and layout information
- **Id**: A unique identifier for text states
- **TextStyle**: Configure font size, color, alignment, and more
- **Action**: Perform operations like copy, paste, and cursor movement

## 🔧 Contributing
## Quick Start

```rust
use protextinator::{TextManager, TextState, math::Size};
use cosmic_text::{fontdb, Color};
use protextinator::style::TextStyle;

// Create a text manager
let mut text_manager = TextManager::new();

// Create a text state
let id = protextinator::Id::new("my_text");
let text = "Hello, world!";
text_manager.create_state(id, text, ());
// Add fonts
let font_sources: Vec<fontdb::Source> = vec![];
text_manager.load_fonts(font_sources.into_iter());
// Alternatively, you can load fonts from bytes if you want to embed them into the binary
// or download them at runtime as bytes
let byte_sources: Vec<&'static [u8]> = vec![];
text_manager.load_fonts_from_bytes(byte_sources.into_iter());

// Optional: Marks the beginning of a frame so that you can track which text states are accessed
text_manager.start_frame();

// Configure the text area size and style
if let Some(state) = text_manager.text_states.get_mut(&id) {
state.set_outer_size(&Size::new(400.0, 200.0));

let style = TextStyle::new(16.0, Color::rgb(255, 255, 255))
.with_line_height(1.5);
state.set_style(&style);

// Enable editing
state.is_editable = true;
state.is_selectable = true;
state.are_actions_enabled = true;

// Recalculate layout
state.recalculate(&mut text_manager.text_context);

// Get the inner size of the buffer - i.e., how much space the text needs to occupy
let inner_size = state.inner_size();
}

let mut remove_ids = vec![];
// Optional: going to remove all states that were not accessed during the current frame
text_manager.end_frame(&mut remove_ids);
```

Contributions are welcome! Feel free to open issues or submit pull requests.
For a complete example, see the [examples directory](https://github.com/antouhou/protextinator/tree/main/examples).

## 📄 License
## License

Licensed under either of:

- Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
- Apache License, Version 2.0 ([LICENSE-APACHE](http://www.apache.org/licenses/LICENSE-2.0))
- MIT license ([LICENSE-MIT](LICENSE_MIT) or http://opensource.org/licenses/MIT)

at your option.
6 changes: 5 additions & 1 deletion examples/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ impl<'a> App<'a> {
horizontal_alignment: HorizontalTextAlignment::Start,
vertical_alignment: VerticalTextAlignment::Start,
wrap: Some(TextWrap::Wrap),
font_family: FontFamily::SansSerif,
font_family: FontFamily::Name("Arial".into()),
weight: protextinator::style::Weight::NORMAL,
letter_spacing: None,
};

// Create or update the text state
Expand Down Expand Up @@ -191,6 +193,8 @@ impl<'a> App<'a> {
vertical_alignment: VerticalTextAlignment::Start,
wrap: Some(TextWrap::Wrap),
font_family: FontFamily::Serif,
weight: protextinator::style::Weight::NORMAL,
letter_spacing: None,
};

// Create or update the stats text state
Expand Down
Loading
Loading