mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 04:09:51 +00:00
[1.19.x] Fix ForgeSlider not respecting custom height (#9237)
This commit is contained in:
1 parent
3c19a0309e
commit
94af5cc43a
5 files changed
+95
-9
No files matched your search
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.extensions;
|
||||
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
|
||||
/**
|
||||
* Extension interface for {@link Font}.
|
||||
*/
|
||||
public interface IForgeFont
|
||||
{
|
||||
FormattedText ELLIPSIS = FormattedText.of("...");
|
||||
|
||||
Font self();
|
||||
|
||||
/**
|
||||
* If the width of the text exceeds {@code maxWidth}, an ellipse is added and the text is substringed.
|
||||
*
|
||||
* @param text the text to ellipsize if needed
|
||||
* @param maxWidth the maximum width of the text
|
||||
* @return the ellipsized text
|
||||
*/
|
||||
default FormattedText ellipsize(FormattedText text, int maxWidth)
|
||||
{
|
||||
final Font self = self();
|
||||
final int strWidth = self.width(text);
|
||||
final int ellipsisWidth = self.width(ELLIPSIS);
|
||||
if (strWidth > maxWidth)
|
||||
{
|
||||
if (ellipsisWidth >= maxWidth) return self.substrByWidth(text, maxWidth);
|
||||
return FormattedText.composite(
|
||||
self.substrByWidth(text, maxWidth - ellipsisWidth),
|
||||
ELLIPSIS
|
||||
);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user