Skip to content

Commit

Permalink
Ensure tooltips are constrained to the screen (#2845)
Browse files Browse the repository at this point in the history
  • Loading branch information
douira authored and jellysquid3 committed Oct 27, 2024
1 parent 0ac714c commit 7b77a83
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,21 @@ private void renderOptionTooltip(GuiGraphics graphics, ControlElement<?> element
int textPadding = 3;
int boxPadding = 3;

int boxWidth = 200;

int boxY = dim.y();
int boxX = dim.getLimitX() + boxPadding;

int boxWidth = Math.min(200, this.width - boxX - boxPadding);

Option<?> option = element.getOption();
List<FormattedCharSequence> tooltip = new ArrayList<>(this.font.split(option.getTooltip(), boxWidth - (textPadding * 2)));
var splitWidth = boxWidth - (textPadding * 2);
List<FormattedCharSequence> tooltip = new ArrayList<>(this.font.split(option.getTooltip(),splitWidth));

OptionImpact impact = option.getImpact();

if (impact != null) {
tooltip.add(Language.getInstance().getVisualOrder(Component.translatable("sodium.options.performance_impact_string", impact.getLocalizedName()).withStyle(ChatFormatting.GRAY)));
var impactText = Component.translatable("sodium.options.performance_impact_string",
impact.getLocalizedName());
tooltip.addAll(this.font.split(impactText.withStyle(ChatFormatting.GRAY), splitWidth));
}

int boxHeight = (tooltip.size() * 12) + boxPadding;
Expand Down

0 comments on commit 7b77a83

Please sign in to comment.