From 91e8b44dd5517fa29f44a73535426570743af745 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Mon, 19 Feb 2024 21:32:13 +0100 Subject: [PATCH] add `pixel_perfect` feature, document stuff --- hui/Cargo.toml | 8 +++++++- hui/src/draw.rs | 4 ++++ hui/src/lib.rs | 7 +++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/hui/Cargo.toml b/hui/Cargo.toml index f3daad4..ecd6c67 100644 --- a/hui/Cargo.toml +++ b/hui/Cargo.toml @@ -23,9 +23,15 @@ fontdue = "0.8" rect_packer = "0.2" log = "0.4" nz = "0.3" +document-features = "0.2" [features] -default = ["builtin_elements", "builtin_font"] +default = ["builtin_elements", "builtin_font", "pixel_perfect"] +## Enable the built-in font (ProggyTiny, adds 35kb to the executable) builtin_font = [] +## Enable the built-in elements (`Container`, `ProgressBar`, etc.) builtin_elements = [] +## Round vertex positions to nearest integer coordinates (fixes blurry text) +pixel_perfect = [] + #parallel = ["dep:rayon", "fontdue/parallel"] diff --git a/hui/src/draw.rs b/hui/src/draw.rs index 4c47461..5132954 100644 --- a/hui/src/draw.rs +++ b/hui/src/draw.rs @@ -317,6 +317,10 @@ impl UiDrawPlan { } } } + #[cfg(feature = "pixel_perfect")] + swapper.current_mut().vertices.iter_mut().for_each(|v| { + v.position = v.position.floor() + }); prev_command = Some(command); } Self { diff --git a/hui/src/lib.rs b/hui/src/lib.rs index fdcaf8a..ce124ee 100644 --- a/hui/src/lib.rs +++ b/hui/src/lib.rs @@ -1,9 +1,12 @@ -#![forbid(unsafe_code)] -#![forbid(unsafe_op_in_unsafe_fn)] #![doc(html_logo_url = "https://raw.githubusercontent.com/griffi-gh/hui/master/.assets/hui.svg")] //! //! Simple UI library for games and other interactive applications //! +//! # Features +#![doc = document_features::document_features!()] + +#![forbid(unsafe_code)] +#![forbid(unsafe_op_in_unsafe_fn)] use std::collections::VecDeque;