Merge pull request #3097 from Domanffe/perf/effect-panel-strings

🤖 Agent: read the diff at f7bb1ceb7 ("Effect panels: borrow the name and reuse the icon key") against the 26.3 source it cites; verify green, merges cleanly with main. Proof: cg25 union a051cc285 (local branch cg25/union in t3-ef805fdb: main 6d3489d30 + 38 contributor heads merged cleanly, no fixups): clippy -p horizon-client --all-targets -D warnings clean, horizon-client lib 1105 + bin 133 + integration tests pass, parity --changed 355/355 harnesses PASS on the Mac mini (Cargo.lock changed by #3210, so every harness ran; tab_list passed on its one retry).
This commit is contained in:
Ludovic Marie
2026-10-28 19:57:48 +01:00
committed by GitHub
+11 -4
View File
@@ -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::<String>())
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,