The closest that I found is the Input (String Multiline) but it doesn’t wrap the text. The Text (Wrapped) is not selectable. What would be the right choice or configuration here?
yar
April 30, 2024, 10:31am
2
@tonfilm it’s a lot more easier to find answers for this kind of questions on imgui’s github
opened 03:38PM - 16 May 20 UTC
inputtext
First of all, I am aware of the other posts regarding this issue: https://github… .com/ocornut/imgui/issues/952 https://github.com/ocornut/imgui/issues/1062
This is a little bit different, I would like to attempt to implement this myself since this is not a high priority but I have a couple of questions.
Digging through the source code, I found that the editor is a slightly modified version of https://github.com/nothings/stb/blob/master/stb_textedit.h and, there is this particular paragraph commenting on word-wrapping:
> // STB_TEXTEDIT_LAYOUTROW returns information about the shape of one displayed
> // row of characters assuming they start on the i'th character--the width and
> // the height and the number of characters consumed. This allows this library
> // to traverse the entire layout incrementally. You need to compute word-wrapping
> // here.
I see that that function is indeed implemented in imgui, more specifically in imgui_widgets.cpp:
```
static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx)
{
const ImWchar* text = obj->TextW.Data;
const ImWchar* text_remaining = NULL;
const ImVec2 size = InputTextCalcTextSizeW(text + line_start_idx, text + obj->CurLenW, &text_remaining, NULL, true);
r->x0 = 0.0f;
r->x1 = size.x;
r->baseline_y_delta = size.y;
r->ymin = 0.0f;
r->ymax = size.y;
r->num_chars = (int)(text_remaining - (text + line_start_idx));
}
```
So if my understanding is correct, that function gets called when the cursor moves on the text (either by mouse or keyboard), but then I do not understand how that function would aid text wrapping.
That function does not get called when inserting new text, which should be were the wrapping should be checked.
So more specifically:
* Does the function STB_TEXTEDIT_LAYOUTROW have anything to do with how text is rendered or is only used to move the cursor even in wrapped text?
* What would be the overall steps to be able to achieve word wrapping? Is a total rewrite necessary or is it possible to achieve this by overriding a function?
* I see that `ImDrawList::AddText` has a `wrap_width` parameter, I guess that if as a first step I should try to modify the calls to that function in `ImGui::InputTextEx`, is that correct?
Thank you for your understanding, I want to build a note taking application and, for me, this is a requirement so I would like this feature, if someone can help I would greatly appreciate that.
In short, by native tools it’s impossible for now
1 Like
system
Closed
April 30, 2025, 10:32am
3
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.