Skip to content

Generalize Tooltip Rendering into one function, Also add 9 slice drawing function#3276

Open
SpellDigger wants to merge 15 commits into
PixelGuys:masterfrom
SpellDigger:tooltip_render
Open

Generalize Tooltip Rendering into one function, Also add 9 slice drawing function#3276
SpellDigger wants to merge 15 commits into
PixelGuys:masterfrom
SpellDigger:tooltip_render

Conversation

@SpellDigger

Copy link
Copy Markdown

closes: #2312

Tooltip Example (i added backgroud texture)
{52F36E4C-8F71-4810-BA7F-F0D6AAF1CC8D}

buttons also now use bound9SliceImage to draw its outline instead of it being hardcoded
(they are drawn with slice scale 2 so it matches the original)
{A6A21B87-C8C7-4280-8448-1756F5686CB9}

waiting to get slimed by quantum

@Wunka Wunka moved this to Low Priority in PRs to review Jun 23, 2026
@SpellDigger

Copy link
Copy Markdown
Author

Made the tooltip texture less curved

{0218E725-1F0E-46D0-9D79-626F9D02FB78}

@Wunka

Wunka commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

As I atleast think we need more tooltips (see #3242) I will move this to high priority so it gets soon looked at)

@Wunka Wunka moved this from Low Priority to High Priority in PRs to review Jun 23, 2026
Comment thread src/graphics.zig Outdated
boundSubImage(_destMin, _destMax - _destMin, _uvMin, _uvMax - _uvMin);
}

pub fn bound9SliceImage(_pos: Vec2f, _dim: Vec2f, _textureSize: Vec2f, _sliceCenter: Vec4f, _sliceScale: f32) void {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use underscores everywhere.
Also I'd suggest to rename _sliceCenter to edgeSize, also is there any reason this is a Vec4f instead of a simple float? In my opinion we shouldn't support asymmetrical texture sizes.

Also the existence of sliceScale is just odd. What does this mean? Why is it needed? It looks like it's hiding a bug.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason why _sliceCenter is a Vec4f is to allow for drawing more complex 9 slice images, having a float edgeSize locks away more complex textures from being drawn for which some sides and corners may have different proportions, if you really insist i can make it a single float

sliceScale is not a bug, idk what r u talking about but the whole purpose of sliceScale is quite literally what it says to scale up the size of the slices i think you are forgetting this is a general function for simplicity i can tell u goodluck drawing the buttons outline without it because u wont get the same result as the original i may remind u that the original code for drawing the buttons outline was also scaled x2

also the underscores for the u and v arguments are only there cuz zig compiler was screaming at me and refused to compile i could probably rename them to something else

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why is the button scaling the texture, but the tooltip isn't? Shouldn't everything have the same scale?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a single float, or 2 floats if you really want to have differences between x and y sizes. Anything else seems just weird and shouldn't be allowed in my opinion.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oki doki (i will make it a Vec2f)
the button is being scaled purely so it looks the same as the original buttons did, if you actually prefer a smaller outline i can set the scale to 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why doesn't the tooltip texture need to be scaled by the same amount?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tooltip has scale of 1? its just the buttons who have scale 2 since the original button code scaled them like that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion we should have the same pixel size for the tooltip outline as for the button outline

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oki doki ur the boss i dont really care enough

Comment thread src/gui/components/Button.zig Outdated
}

textures.outlineTexture.bindTo(0);
graphics.draw.bound9SliceImage(self.pos, self.size, textures.outlineTextureSize, .{2, 2, 2, 2}, 2);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously this number was determined from the texture data. Allowing for arbitrary resolution textures. Here you have hardcoded it. Texture information should never be hardcoded.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im assuming you are talking about the slice edges here, well i sure can make the slice edges be determined from the texture

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im doing the same to the tooltip background just incase

Comment thread src/gui/tooltip.zig Outdated
Comment on lines +28 to +29
var renderpos = pos;
switch (alignment) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var renderpos = pos;
switch (alignment) {
const renderpos = switch (alignment) {

Comment thread src/gui/tooltip.zig Outdated
Comment on lines +30 to +32
.right => {
renderpos = pos + Vec2f{tooltipSliceCenter[0], 0};
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.right => {
renderpos = pos + Vec2f{tooltipSliceCenter[0], 0};
},
.right => pos + Vec2f{tooltipSliceCenter[0], 0},

Comment thread src/gui/components/Label.zig Outdated
const Label = @This();

const fontSize: f32 = 16;
pub const fontSize: f32 = 16;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is not the place for a global font size.

Suggested change
pub const fontSize: f32 = 16;
const fontSize: f32 = 16;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this slightly transparent? I cannot see through it at all.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly i dont know myself i just made it like that cuz it looks nicer, i can make it non transparent or more transparent if you like, i can see through it just fine but maybe its cuz of my monitor settings

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to just make it opaque.

Comment thread src/gui/gui.zig Outdated
const fontSize = 16;
var size = textBuffer.calculateLineBreaks(fontSize, 300);
if (hovered.inventory.getItem(hovered.itemSlot).getTooltip()) |tooltipContent| {
var label = GuiComponent.Label.init(Vec2f{0, 0}, 300, tooltipContent, .left);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to make a convenience function in tooltip.zig to render it as text.

@IntegratedQuantum IntegratedQuantum moved this from High Priority to In review in PRs to review Jun 27, 2026
@SpellDigger

Copy link
Copy Markdown
Author

woah alot of stuff to do time to get to work

@SpellDigger

Copy link
Copy Markdown
Author

Stuff changed:

  • funni quantum requests
  • tooltip background is now opaque
  • added renderFromText
  • tooltip now handles switching between alignments dynamically when the provided one leaves the screen
  • the dynamic corner thingy for buttons and tooltip textures
  • tooltip offset is now not based off texture but a constant (before the offset was gotten from cornerSize which created issues when tooltip texture was big)

Comment thread src/graphics.zig Outdated
boundSubImage(_destMin, _destMax - _destMin, _uvMin, _uvMax - _uvMin);
}

pub fn bound9SliceImage(_pos: Vec2f, _dim: Vec2f, _textureSize: Vec2f, _slices: Vec2f, _sliceScale: f32) void {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again please remove all unnecessary underscores inside this and all other functions.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe list the unnecessary underscores so i actually know

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure most of them are unnecessary.
You only need underscores when you have name conflicts, and I'm pretty sure no similar names exist in scope.

Comment thread src/gui/gui.zig Outdated
const ContinuousSlider = @import("components/ContinuousSlider.zig");
const DiscreteSlider = @import("components/DiscreteSlider.zig");
const TextInput = @import("components/TextInput.zig");
const tooltip = @import("tooltip.zig");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each file should be publicly imported in exactly one place so it's accessible from main.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im assuming you mean make it public

Comment thread src/gui/tooltip.zig Outdated
};
}

pub fn render(guicomponent: *GuiComponent, pos: Vec2f, alignment: graphics.TextBuffer.Alignment) void {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should allow for alignment here. Tooltips should always be rendered in the same way in my opinion.

This would mean you can simplify the logic to a single if, like for the y coordinate.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would argue otherwise incase someone would want to render 1 tooltip on the left and 1 tooltip on the right for whatever reason there could be, but since u say so

Comment thread src/gui/tooltip.zig Outdated
label.size = size;

var component = GuiComponent{.label = label};
defer component.deinit();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer deinit should always be next to the init function, not 10 lines below it.

Comment thread src/gui/tooltip.zig Outdated
}
label.size = size;

var component = GuiComponent{.label = label};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use label.toComponent()

Comment thread src/gui/tooltip.zig Outdated

draw.bound9SliceImage(renderpos, size, @floatFromInt(tooltipTexture.size()), cornerSize, 1);

guicomponent.mutPos().* = renderpos + Vec2f{cornerSize[0], cornerSize[1]};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of modifying the component, please use draw.setTranslation and draw.setClip to define the drawing area and pass an adjusted mouse position.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not following what ur trying to make me do here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out VerticalList.render

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im assuming you mean doing it like this?

const adjustedpos = renderpos + Vec2f{cornerSize[0], cornerSize[1]};
const oldTranslation = draw.setTranslation(adjustedpos);
defer draw.restoreTranslation(oldTranslation);
const oldClip = draw.setClip(guicomponent.size());
defer draw.restoreClip(oldClip);
guicomponent.render(adjustedpos);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm i forgot to consider guicomponent would still use its internal position this might be more correct if we are going for mouse being inside the component

const adjustment = Vec2f{cornerSize[0], cornerSize[1]};
const oldTranslation = draw.setTranslation(renderpos + adjustment);
defer draw.restoreTranslation(oldTranslation);
const oldClip = draw.setClip(guicomponent.size());
defer draw.restoreClip(oldClip);
guicomponent.render(guicomponent.pos() + adjustment);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

generalize tooltip rendering into a single function

3 participants