Advertisement
GamingLVScripts

ImGuiFontManager

Jun 10th, 2025
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. import imgui.ImFont;
  2.  
  3. import java.util.*;
  4.  
  5. /**
  6.  * @author mark
  7.  */
  8. public class ImGuiFontManager {
  9.     private static final Map<String, List<ImFont>> fontRegistry = new HashMap<>();
  10.  
  11.     public static void register(String name, ImFont font, int size) {
  12.         fontRegistry.computeIfAbsent(name.toLowerCase(), k -> new ArrayList<>()).add(font);
  13.         fontRegistry.get(name.toLowerCase()).sort(Comparator.comparingInt(f -> (int) f.getFontSize()));
  14.     }
  15.  
  16.     public static ImFont getFont(String name, int size) {
  17.         List<ImFont> fonts = fontRegistry.get(name.toLowerCase());
  18.         if (fonts == null || fonts.isEmpty()) return null;
  19.  
  20.         // Return closest font by size
  21.         return fonts.stream()
  22.                 .min(Comparator.comparingDouble(f -> Math.abs(f.getFontSize() - size)))
  23.                 .orElse(fonts.getFirst());
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement