mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-23 07:50:58 +01:00
A clean-room, pure-Rust foundation for MaterialCraft's node-based material authoring: the package/graph/node model, float image planes, the node library (atomic nodes, tileable noises, patterns, filters, PBR utilities, function graphs for the pixel processor), a content-addressed cooking cache, .mcraft packages and texture export, and the command-driven session with snapshot undo. Infrastructure (xtask, CI, packaging) copied from TextureCraft. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
80 lines
2.5 KiB
Markdown
80 lines
2.5 KiB
Markdown
# egui_phosphor
|
|
|
|
Bundles [Phosphor icons](https://phosphoricons.com/) with boilerplate to use in your egui app.
|
|
|
|
## Installation
|
|
|
|
Add the crate as a dependency in Cargo.toml:
|
|
|
|
```toml
|
|
egui-phosphor = "0.14"
|
|
```
|
|
|
|
On startup, update the fonts in your egui context:
|
|
|
|
```rust
|
|
let mut fonts = egui::FontDefinitions::default();
|
|
egui_phosphor::add_to_fonts(&mut fonts, egui_phosphor::Variant::Regular);
|
|
|
|
cc.egui_ctx.set_fonts(fonts);
|
|
```
|
|
|
|
The above `add_to_fonts` helper adds the chosen variant (`Regular`) as a fallback to the primary egui `Proportional` font so that when you use Phosphor icons mixed with plain text in labels, the icon font will take over where necessary. If you want to add multiple variants of Phosphor icons, see [this example](examples/multiple_variants.rs) which shows all variants in use.
|
|
|
|
## Usage
|
|
|
|
Use the constants provided by the crate in your text:
|
|
|
|
```rust
|
|
ui.label(egui::RichText::new(format!("FILE_CODE {}", egui_phosphor::regular::FILE_CODE)).size(32.0));
|
|
```
|
|
|
|
**Note: Make sure to use the appropriate character codes for your chosen variant!** This means for `Variant::Regular` you should use `regular::FILE_CODE`, for `Variant::Fill` you should use `fill::FILE_CODE` etc.
|
|
|
|
## Subsetting
|
|
|
|
The optional `subset` feature reduces the font at compile time to only the icons you specify, at the cost of roughly 0.3s per rebuild of the crate that invokes it:
|
|
|
|
```toml
|
|
egui-phosphor = { version = "0.14", features = ["subset"] }
|
|
```
|
|
|
|
```rust
|
|
egui_phosphor::subset! {
|
|
pub mod icons {
|
|
use regular::{GEAR, HOUSE, TRASH};
|
|
}
|
|
}
|
|
|
|
// on startup:
|
|
let mut fonts = egui::FontDefinitions::default();
|
|
icons::regular::add_to_fonts(&mut fonts);
|
|
cc.egui_ctx.set_fonts(fonts);
|
|
|
|
// in your UI:
|
|
ui.label(format!("{} Settings", icons::regular::GEAR));
|
|
```
|
|
|
|
### Multiple variants
|
|
|
|
Because every variant uses the same codepoints, only one of the variants can be the default fallback for the proportional font. Add that one with `add_to_fonts`, the rest with `add_as_family`, and select those by family:
|
|
|
|
```rust
|
|
egui_phosphor::subset! {
|
|
pub mod icons {
|
|
use regular::{GEAR, HOUSE};
|
|
use fill::{GEAR, HEART};
|
|
}
|
|
}
|
|
|
|
icons::regular::add_to_fonts(&mut fonts);
|
|
icons::fill::add_as_family(&mut fonts);
|
|
|
|
ui.label(format!("{} Settings", icons::regular::GEAR));
|
|
ui.label(icons::fill::rich(format!("{} Favourite", icons::fill::HEART)));
|
|
```
|
|
|
|
## License
|
|
|
|
egui-phosphor is licensed under [MIT](LICENSE-MIT) OR [Apache-2.0](LICENSE-APACHE). Phosphor Icons are licensed under [MIT](https://github.com/phosphor-icons/web/blob/master/LICENSE).
|