Generalize Tooltip Rendering into one function, Also add 9 slice drawing function#3276
Generalize Tooltip Rendering into one function, Also add 9 slice drawing function#3276SpellDigger wants to merge 15 commits into
Conversation
|
As I atleast think we need more tooltips (see #3242) I will move this to high priority so it gets soon looked at) |
…_Imspdg into tooltip_render
| boundSubImage(_destMin, _destMax - _destMin, _uvMin, _uvMax - _uvMin); | ||
| } | ||
|
|
||
| pub fn bound9SliceImage(_pos: Vec2f, _dim: Vec2f, _textureSize: Vec2f, _sliceCenter: Vec4f, _sliceScale: f32) void { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
But why is the button scaling the texture, but the tooltip isn't? Shouldn't everything have the same scale?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
But why doesn't the tooltip texture need to be scaled by the same amount?
There was a problem hiding this comment.
tooltip has scale of 1? its just the buttons who have scale 2 since the original button code scaled them like that
There was a problem hiding this comment.
In my opinion we should have the same pixel size for the tooltip outline as for the button outline
There was a problem hiding this comment.
oki doki ur the boss i dont really care enough
| } | ||
|
|
||
| textures.outlineTexture.bindTo(0); | ||
| graphics.draw.bound9SliceImage(self.pos, self.size, textures.outlineTextureSize, .{2, 2, 2, 2}, 2); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
im assuming you are talking about the slice edges here, well i sure can make the slice edges be determined from the texture
There was a problem hiding this comment.
im doing the same to the tooltip background just incase
| var renderpos = pos; | ||
| switch (alignment) { |
There was a problem hiding this comment.
| var renderpos = pos; | |
| switch (alignment) { | |
| const renderpos = switch (alignment) { |
| .right => { | ||
| renderpos = pos + Vec2f{tooltipSliceCenter[0], 0}; | ||
| }, |
There was a problem hiding this comment.
| .right => { | |
| renderpos = pos + Vec2f{tooltipSliceCenter[0], 0}; | |
| }, | |
| .right => pos + Vec2f{tooltipSliceCenter[0], 0}, |
| const Label = @This(); | ||
|
|
||
| const fontSize: f32 = 16; | ||
| pub const fontSize: f32 = 16; |
There was a problem hiding this comment.
No, this is not the place for a global font size.
| pub const fontSize: f32 = 16; | |
| const fontSize: f32 = 16; |
There was a problem hiding this comment.
Why is this slightly transparent? I cannot see through it at all.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I would suggest to just make it opaque.
| 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); |
There was a problem hiding this comment.
I'd suggest to make a convenience function in tooltip.zig to render it as text.
|
woah alot of stuff to do time to get to work |
|
Stuff changed:
|
| boundSubImage(_destMin, _destMax - _destMin, _uvMin, _uvMax - _uvMin); | ||
| } | ||
|
|
||
| pub fn bound9SliceImage(_pos: Vec2f, _dim: Vec2f, _textureSize: Vec2f, _slices: Vec2f, _sliceScale: f32) void { |
There was a problem hiding this comment.
Again please remove all unnecessary underscores inside this and all other functions.
There was a problem hiding this comment.
maybe list the unnecessary underscores so i actually know
There was a problem hiding this comment.
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.
| const ContinuousSlider = @import("components/ContinuousSlider.zig"); | ||
| const DiscreteSlider = @import("components/DiscreteSlider.zig"); | ||
| const TextInput = @import("components/TextInput.zig"); | ||
| const tooltip = @import("tooltip.zig"); |
There was a problem hiding this comment.
Each file should be publicly imported in exactly one place so it's accessible from main.
There was a problem hiding this comment.
im assuming you mean make it public
| }; | ||
| } | ||
|
|
||
| pub fn render(guicomponent: *GuiComponent, pos: Vec2f, alignment: graphics.TextBuffer.Alignment) void { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| label.size = size; | ||
|
|
||
| var component = GuiComponent{.label = label}; | ||
| defer component.deinit(); |
There was a problem hiding this comment.
defer deinit should always be next to the init function, not 10 lines below it.
| } | ||
| label.size = size; | ||
|
|
||
| var component = GuiComponent{.label = label}; |
There was a problem hiding this comment.
use label.toComponent()
|
|
||
| draw.bound9SliceImage(renderpos, size, @floatFromInt(tooltipTexture.size()), cornerSize, 1); | ||
|
|
||
| guicomponent.mutPos().* = renderpos + Vec2f{cornerSize[0], cornerSize[1]}; |
There was a problem hiding this comment.
Instead of modifying the component, please use draw.setTranslation and draw.setClip to define the drawing area and pass an adjusted mouse position.
There was a problem hiding this comment.
im not following what ur trying to make me do here
There was a problem hiding this comment.
Check out VerticalList.render
There was a problem hiding this comment.
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);There was a problem hiding this comment.
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);
closes: #2312
Tooltip Example (i added backgroud texture)

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)
waiting to get slimed by quantum