From f7bb1ceb79249b380813f5cd2743a83f83ec76f6 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 28 Oct 2026 11:16:09 +0300 Subject: [PATCH] Effect panels: borrow the name and reuse the icon key The panel list is painted every frame the inventory is open. An unclipped name was cloned per panel and the icon key was a fresh format! per panel; the name is borrowed and the key is built in one buffer now. Co-Authored-By: Hermes Agent (Nous Research) --- crates/horizon-client/src/inventory_effects.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/horizon-client/src/inventory_effects.rs b/crates/horizon-client/src/inventory_effects.rs index 86dca9963..2bb75ba23 100644 --- a/crates/horizon-client/src/inventory_effects.rs +++ b/crates/horizon-client/src/inventory_effects.rs @@ -1,5 +1,7 @@ //! `EffectsInInventory`: active effect panels beside survival and creative //! inventories, with compact icons when there is little room on the right. +use std::borrow::Cow; + use crate::{ effects::EffectInstance, hud::{HudAtlas, HudBatch}, @@ -123,17 +125,19 @@ pub fn paint( cursor: [i32; 2], ) -> Option<[(String, u32); 2]> { let mut tooltip = None; + let mut icon = String::new(); for panel in panels { background(batch, atlas, panel); let text_width = panel.width - 39; let clipped = atlas.font.width(&panel.name).ceil() as i32 > text_width; if text_width > 0 { - let shown = if clipped { + let shown: Cow<'_, str> = if clipped { let available = text_width as f32 - atlas.font.width("..."); let count = atlas.font.fit(&panel.name, available); - format!("{}...", panel.name.chars().take(count).collect::()) + let text: String = panel.name.chars().take(count).collect(); + Cow::Owned(format!("{text}...")) } else { - panel.name.clone() + Cow::Borrowed(panel.name.as_str()) }; batch.text( atlas, @@ -152,9 +156,12 @@ pub fn paint( true, ); } + icon.clear(); + icon.push_str("mob_effect/"); + icon.push_str(&panel.icon.id); batch.sprite_scaled( atlas, - &format!("mob_effect/{}", panel.icon.id), + &icon, (panel.x + 7) as f32, (panel.y + 7) as f32, 18.0,