|
1 | | -# 🚀 Protextinator |
| 1 | +# Protextinator |
2 | 2 |
|
3 | | -<div align="center"> |
4 | | - <a href="https://crates.io/crates/protextinator"><img src="https://img.shields.io/crates/v/protextinator.svg" alt="Crates.io"></a> |
5 | | - <a href="https://docs.rs/protextinator/latest/protextinator/"><img src="https://img.shields.io/docsrs/protextinator" alt="Docs.rs"></a> |
6 | | - <a href="https://github.com/antouhou/protextinator/blob/main/LICENSE_MIT"><img src="https://img.shields.io/crates/l/protextinator" alt="License"></a> |
7 | | -</div> |
| 3 | +[](https://crates.io/crates/protextinator) |
| 4 | +[](https://docs.rs/protextinator/latest/protextinator/) |
| 5 | +[](https://github.com/antouhou/protextinator/blob/main/LICENSE_MIT) |
8 | 6 |
|
9 | | -## ✨ Text Management, Made Simple! |
| 7 | +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. |
10 | 8 |
|
11 | | -**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! |
| 9 | +**Note:** This library is still a work in progress. APIs may change. |
12 | 10 |
|
13 | | -> 💡 Perfect for game UIs, text editors, and any application that needs sophisticated text rendering with minimal hassle. |
| 11 | +## Features |
14 | 12 |
|
15 | | -⚠️ **WARNING**: This library is work in progress, use at your own risk! ⚠️ |
| 13 | +- Vertical text alignment |
| 14 | +- Text buffer size measurement |
| 15 | +- Scroll position management with absolute coordinates |
| 16 | +- Simple font loading from files or embedded bytes |
| 17 | +- Text state collection with optional usage tracking |
| 18 | +- Custom metadata for text states |
| 19 | +- Text selection and editing |
| 20 | +- Efficient text buffer caching |
| 21 | +- Word wrapping and text styling |
| 22 | +- Optional serialization support |
16 | 23 |
|
17 | | -## 🔥 Features |
| 24 | +## Installation |
18 | 25 |
|
19 | | -- **Vertical text alignment** - Position your text exactly where you want it |
20 | | -- **Text buffer size measurement** - Know exactly how much space your text needs |
21 | | -- **Scroll position management** with absolute coordinates |
22 | | -- **Simple font loading interface** - Load fonts from files or embedded bytes |
23 | | -- **Text state collection** with optional usage tracking for garbage collection |
24 | | -- **Custom metadata** for text states |
25 | | -- **Text selection and editing** capabilities |
26 | | -- **Efficient text buffer caching** |
27 | | -- **Word wrapping and text styling** |
28 | | -- **Optional serialization** support via the `serialization` feature |
29 | | - |
30 | | -## 📦 Installation |
31 | | - |
32 | | -Add Protextinator to your `Cargo.toml`: |
| 26 | +Add this to your `Cargo.toml`: |
33 | 27 |
|
34 | 28 | ```toml |
35 | 29 | [dependencies] |
36 | | -protextinator = "0.1.0" |
| 30 | +protextinator = "0.5.0" |
37 | 31 | ``` |
38 | 32 |
|
39 | | -With serialization support: |
| 33 | +With serialization: |
40 | 34 |
|
41 | 35 | ```toml |
42 | 36 | [dependencies] |
43 | 37 | protextinator = { version = "0.1.0", features = ["serialization"] } |
44 | 38 | ``` |
45 | 39 |
|
46 | | -## 🚀 Quick Start |
47 | | - |
48 | | -For code examples and detailed usage, check out: |
49 | | -- [Documentation on docs.rs](https://docs.rs/protextinator/) |
50 | | -- [Example code in the repository](https://github.com/antouhou/protextinator/tree/main/examples) |
51 | | - |
52 | | -Protextinator makes it easy to: |
53 | | -1. Create and manage text states |
54 | | -2. Style text with various fonts, colors, and alignments |
55 | | -3. Handle text selection and editing |
56 | | -4. Efficiently render text in your application |
57 | | - |
58 | | -## 🎮 Integration Example |
59 | | - |
60 | | -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. |
61 | | - |
62 | | -## 📚 API Overview |
63 | | - |
64 | | -- **TextManager**: The main entry point for managing text states and fonts |
65 | | -- **TextState**: Represents a text buffer with styling and layout information |
66 | | -- **Id**: A unique identifier for text states |
67 | | -- **TextStyle**: Configure font size, color, alignment, and more |
68 | | -- **Action**: Perform operations like copy, paste, and cursor movement |
69 | | - |
70 | | -## 🔧 Contributing |
| 40 | +## Quick Start |
| 41 | + |
| 42 | +```rust |
| 43 | +use protextinator::{TextManager, TextState, math::Size}; |
| 44 | +use cosmic_text::{fontdb, Color}; |
| 45 | +use protextinator::style::TextStyle; |
| 46 | + |
| 47 | +// Create a text manager |
| 48 | +let mut text_manager = TextManager::new(); |
| 49 | + |
| 50 | +// Create a text state |
| 51 | +let id = protextinator::Id::new("my_text"); |
| 52 | +let text = "Hello, world!"; |
| 53 | +text_manager.create_state(id, text, ()); |
| 54 | +// Add fonts |
| 55 | +let font_sources: Vec<fontdb::Source> = vec![]; |
| 56 | +text_manager.load_fonts(font_sources.into_iter()); |
| 57 | +// Alternatively, you can load fonts from bytes if you want to embed them into the binary |
| 58 | +// or download them at runtime as bytes |
| 59 | +let byte_sources: Vec<&'static [u8]> = vec![]; |
| 60 | +text_manager.load_fonts_from_bytes(byte_sources.into_iter()); |
| 61 | + |
| 62 | +// Optional: Marks the beginning of a frame so that you can track which text states are accessed |
| 63 | +text_manager.start_frame(); |
| 64 | + |
| 65 | +// Configure the text area size and style |
| 66 | +if let Some(state) = text_manager.text_states.get_mut(&id) { |
| 67 | + state.set_outer_size(&Size::new(400.0, 200.0)); |
| 68 | + |
| 69 | + let style = TextStyle::new(16.0, Color::rgb(255, 255, 255)) |
| 70 | + .with_line_height(1.5); |
| 71 | + state.set_style(&style); |
| 72 | + |
| 73 | + // Enable editing |
| 74 | + state.is_editable = true; |
| 75 | + state.is_selectable = true; |
| 76 | + state.are_actions_enabled = true; |
| 77 | + |
| 78 | + // Recalculate layout |
| 79 | + state.recalculate(&mut text_manager.text_context); |
| 80 | + |
| 81 | + // Get the inner size of the buffer - i.e., how much space the text needs to occupy |
| 82 | + let inner_size = state.inner_size(); |
| 83 | +} |
| 84 | + |
| 85 | +let mut remove_ids = vec![]; |
| 86 | +// Optional: going to remove all states that were not accessed during the current frame |
| 87 | +text_manager.end_frame(&mut remove_ids); |
| 88 | +``` |
71 | 89 |
|
72 | | -Contributions are welcome! Feel free to open issues or submit pull requests. |
| 90 | +For a complete example, see the [examples directory](https://github.com/antouhou/protextinator/tree/main/examples). |
73 | 91 |
|
74 | | -## 📄 License |
| 92 | +## License |
75 | 93 |
|
76 | 94 | Licensed under either of: |
77 | 95 |
|
78 | | -- Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) |
| 96 | +- Apache License, Version 2.0 ([LICENSE-APACHE](http://www.apache.org/licenses/LICENSE-2.0)) |
79 | 97 | - MIT license ([LICENSE-MIT](LICENSE_MIT) or http://opensource.org/licenses/MIT) |
80 | 98 |
|
81 | 99 | at your option. |
0 commit comments