Immediate-Mode-UI / Immediate-Mode-UI/Nuklear
found bug in using NK_TEXT_ALIGN_MIDDLE
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 11.4k
- Forks
- 686
- Avg merge
- 4d 1h
- Merged PRs (30d)
- 3
Description
This option define if used enables the following code:
```
/* align in y-axis */
/*if (a & NK_TEXT_ALIGN_MIDDLE) { // this is bugged the height is half of what it should be resulting in an incorrect offset of the text on the y-axis
label.y = b.y + b.h/2.0f - (float)f->height/2.0f;
label.h = NK_MAX(b.h/2.0f, b.h - (b.h/2.0f + f->height/2.0f));
} else if (a & NK_TEXT_ALIGN_BOTTOM)*/ {
label.y = b.y + b.h - f->height;
label.h = f->height;
}
nk_draw_text(o, label, (const char*)string, len, f, t->background, t->text);
```
this is bugged - the height is half of what it should be resulting in an incorrect offset of the text on the y-axis
I've verified this with spacing, padding and all other spacing using the FREE STATIC placement of some buttons. Done in process of find the bug causing this offset I was seeing on text on the y-axis.
By using the NK_TEXT_ALIGN_BOTTOM option all is well.
However the options:
```
NK_TEXT_LEFT = NK_TEXT_ALIGN_MIDDLE| NK_TEXT_ALIGN_LEFT,
NK_TEXT_CENTERED = NK_TEXT_ALIGN_MIDDLE| NK_TEXT_ALIGN_CENTERED,
NK_TEXT_RIGHT = NK_TEXT_ALIGN_MIDDLE| NK_TEXT_ALIGN_RIGHT
```
Need to be changed aswell to NK_TEXT_ALIGN_BOTTOM | xxx
This bug and change would break backwards compatibility of Nuklear, however the current implementation w/o the bug fix is incorrect and always offsets the text too much on the y-axis visually.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the NK_TEXT_ALIGN_MIDDLE implementation in Nuklear’s single-header C library and compare its vertical text placement with NK_TEXT_ALIGN_BOTTOM. Reproduce the offset using free-static buttons with spacing and padding, then verify that middle alignment centers text correctly and that the related NK_TEXT_LEFT, NK_TEXT_CENTERED, and NK_TEXT_RIGHT options behave as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100