Skip to content

Commit 159935c

Browse files
committed
constrain tooltip to screen
1 parent 6788ca7 commit 159935c

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

common/src/main/java/net/caffeinemc/mods/sodium/client/gui/VideoSettingsScreen.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
import java.util.List;
4141
import java.util.stream.Stream;
4242

43-
// TODO: constrain the tooltip to its safe area if it's too big, then show a scroll bar if it's still too big
44-
// TODO: scrolling the tooltip?
43+
// TODO: show a scroll bar on the tooltip if it's too big to fit on the screen
4544
// TODO: make the search bar work
4645
// TODO: wrap options within groups in two columns
4746
// TODO: make the mod config headers interactive: only show one mod's pages at a time, click on a mod header to open that mod's first settings page and close the previous mod's page list
@@ -278,26 +277,30 @@ private Stream<ControlElement<?>> getActiveControls() {
278277
}
279278

280279
private void renderOptionTooltip(GuiGraphics graphics, ControlElement<?> element) {
281-
int textPadding = 5;
282-
int boxPadding = 5;
283-
284-
int boxWidth = this.width - 340;
280+
int textPadding = Layout.INNER_MARGIN;
281+
int boxMargin = Layout.INNER_MARGIN;
282+
int lineHeight = this.font.lineHeight + 3;
285283

286284
int boxY = element.getY();
287-
int boxX = element.getLimitX() + boxPadding;
285+
int boxX = element.getLimitX() + boxMargin;
286+
287+
int boxWidth = Math.min(200, this.width - boxX - boxMargin);
288288

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

292293
OptionImpact impact = option.getImpact();
293294

294295
if (impact != null) {
295-
tooltip.add(Language.getInstance().getVisualOrder(Component.translatable("sodium.options.performance_impact_string", impact.getName()).withStyle(ChatFormatting.GRAY)));
296+
var impactText = Component.translatable("sodium.options.performance_impact_string",
297+
impact.getName());
298+
tooltip.addAll(this.font.split(impactText.withStyle(ChatFormatting.GRAY), splitWidth));
296299
}
297300

298-
int boxHeight = (tooltip.size() * 12) + boxPadding;
301+
int boxHeight = (tooltip.size() * lineHeight) + boxMargin;
299302
int boxYLimit = boxY + boxHeight;
300-
int boxYCutoff = this.height - 40;
303+
int boxYCutoff = this.height - Layout.INNER_MARGIN;
301304

302305
// If the box is going to be cut off on the Y-axis, move it back up the difference
303306
if (boxYLimit > boxYCutoff) {
@@ -307,7 +310,7 @@ private void renderOptionTooltip(GuiGraphics graphics, ControlElement<?> element
307310
graphics.fill(boxX, boxY, boxX + boxWidth, boxY + boxHeight, 0x40000000);
308311

309312
for (int i = 0; i < tooltip.size(); i++) {
310-
graphics.drawString(this.font, tooltip.get(i), boxX + textPadding, boxY + textPadding + (i * 12), Colors.FOREGROUND);
313+
graphics.drawString(this.font, tooltip.get(i), boxX + textPadding, boxY + textPadding + (i * lineHeight), Colors.FOREGROUND);
311314
}
312315
}
313316

0 commit comments

Comments
 (0)