Immediate-Mode-UI / Immediate-Mode-UI/Nuklear

xlib: Images cause scrollable content to break

Open
#729 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.4k
Forks
686
Avg merge
4d 1h
Merged PRs (30d)
3

Description

In the pure x11 demo, after enabling stb_image and loading your images via the `nk_xsurf_load_image_from_file` function

You then use that loaded image later on in for example `nk_button_image_label(ctx, icon, "text1", NK_TEXT_CENTERED);`

However if any content in that window is scrollable it causes weird rendering/clipping issues.

Here it is when there is scrolling

![Screenshot_20241108_125410](https://github.com/user-attachments/assets/db5433da-e823-4802-b985-5400d6082a63)

And when there is no scrolling

![Screenshot_20241108_125601](https://github.com/user-attachments/assets/f4d6c229-21f8-4c79-a048-57b3c5bc2659)

This issue goes away if I forgo the image/icon by doing `nk_button_label(ctx, "text1");` instead, but that kinda defeats the whole point of having image loading support.

To reproduce my examples add the following to `demo/x11/main.c`
line 17:
`#define NK_XLIB_INCLUDE_STB_IMAGE`
`#define NK_XLIB_IMPLEMENT_STB_IMAGE`

line 154:
```
// Make sure the is a image file named 'image.png' in the directory you launch the demo
struct nk_image icon = nk_xsurf_load_image_from_file("image.png");
```
line 177:
```
nk_layout_row_dynamic(ctx, 64, 3);
nk_button_image_label(ctx, icon, "text1", NK_TEXT_CENTERED);
nk_button_image_label(ctx, icon, "text1", NK_TEXT_CENTERED);
nk_button_image_label(ctx, icon, "text1", NK_TEXT_CENTERED);
```
I believe I also had change the makefile to use C99 instead of C89 so that stb_image would compile.

Please let me know if I'm doing anything, wrong or if you guys need more info.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with demo/x11/main.c and reproduce the issue using NK_XLIB_INCLUDE_STB_IMAGE, NK_XLIB_IMPLEMENT_STB_IMAGE, nk_xsurf_load_image_from_file, and nk_button_image_label. Compare the rendering with and without scrolling, then trace the image path involved in those entry points. Done means image buttons render correctly in scrollable and non-scrollable content.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.