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

Determine size which the text would take (DT_CALCRECT alternative)

Open
#761 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
11.4k
Forks
686
Avg merge
4d 1h
Merged PRs (30d)
3

Description

Imagine that you need to determine which window size you should use to contain a label, using current style, font, and for simplicity using no wrap. Label text is defined in runtime (e.g. by input or by setting locale). How would you do that?

E.g.:
```c
char some_string[128];
fgets(some_string, sizeof(some_string), stdin);
if (nk_begin (nk_ctx, some_string, nk_rect( /* ???? */ ), NK_WINDOW_NO_SCROLLBAR)) {
nk_layout_row_dynamic (nk_ctx, /* ???? */ , 1);
nk_label (nk_ctx, some_string, NK_TEXT_CENTERED);
}
nk_end (nk_ctx);
```

In other words, is there any alternative to WinGDI's `DrawText(text, &rect, DT_CALCRECT)`, which determines the width and height of the rectangle the text would occupy?

Thanks.

Contributor guide

Open the contributing guide

Research direction

Start by reading the text and layout behavior used by nk_begin, nk_layout_row_dynamic, and nk_label, then look for an existing way to measure runtime label text with the current style and font. Done means a newcomer can determine the required window and row dimensions without wrapping, equivalent to the requested DT_CALCRECT behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
desktop, frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.