-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Highlightable/Selectable text? #950
Comments
There's no way currently but I agree it is desirable. Right now a workaround is to use a context menu (right-click on the text item opening a menu that would have a "Copy" option), so you could create yourself a helper that does Text + that menu. Linking to #949 (coincidentally filled on the same time as you): @Megaton: was your intent just to copy text to clipboard and not edit it ? |
@ocornut Yes, that's correct :) Actually I have implemented solution with context menu a while ago, but possibility to copy only part of the text would be nice. I was extending console example a bit and felt that such a feature will look good. |
Are there any examples of implementing the context menu with Copy? |
@nico-abram It is right in ImGui demo window. Look at |
You can use ImGui::SetClipboardText() to call in imgui’s own backend. |
A workaround for this I've found is to use InputText with the readonly flag, like this:
That lets you highlight and copy the text |
Yes we've been using the |
For now I'd prefer not adding extra signatures (as down the line that feature can be provided by a different widget or system), but you can add this signature + wrapper func in your source code. |
Is there way to remove the background of the |
Yes, we can implement the feature with a different widget, but I dont think we can change the colours of the text we want in InputMultiLineText? |
You can customize |
Thank you 😃. I actually needed to have different colors in the same InputTextMultiLine(), so I ended up changing the library on my own, but was still helpful to find where should I needed to change. |
There is a library which already implements rich(er) text: https://github.com/BalazsJako/ImGuiColorTextEdit |
Thank you, I currently do not need an editable text, but might be really handy for a cool side project 😊 |
since we are sharing code snippets, and I wanted a wrapping TextUnformated() that could be selected (and looks like normal text), here is mine: ImGui::PushID(id++);
{
ImVec2 text_size = ImGui::CalcTextSize(msgtext.c_str(), msgtext.c_str()+msgtext.size());
text_size.x = -FLT_MIN; // fill width (suppresses label)
text_size.y += ImGui::GetStyle().FramePadding.y; // single pad
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {0, 0}); // make align with text height
ImGui::PushStyleColor(ImGuiCol_FrameBg, {0.f, 0.f, 0.f, 0.f}); // remove text input box
ImGui::InputTextMultiline(
"",
const_cast<char*>(msgtext.c_str()), // ugly const cast
msgtext.size() + 1, // needs to include '\0'
text_size,
ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_NoHorizontalScroll
);
ImGui::PopStyleColor();
ImGui::PopStyleVar();
}
ImGui::PopID();
it only uses public functions. |
Answering @sakiodre
I don't know yet, if I did part of the work would be done already :)
I haven't tackled this at all yet maybe it's actually easy. I expect it to be a rather low-level thing and needs to be optimal. |
I am also closing #949 as essentially duplicate, see #949 (comment) and I've edited the second post to fix the gist link being https://gist.github.com/hb3p8/d97b7afe9e037339027121ff6c0eb6d9. This is similar to the ideas proposed here (submitting a InputText), but to be clear we inventually intend to support it at a lower-level and more automatically than that. |
Posted by @AidanSun05
Screen.Recording.2024-01-05.at.10.16.18.PM.mov(Adding to https://github.com/ocornut/imgui/wiki/Useful-Extensions) |
I'm currently writing some logging facilities, and it'd be useful to make regular text highlightable so that the user can copy it.
So far I've been doing this using InputText/InputTextMultiLine with ImGuiInputTextFlags_ReadOnly, but it's quite awkward as you have to make a buffer, and pass it in with the length - it can't easily be used with printf formatting.
Is there already a simpler way to do this?
The text was updated successfully, but these errors were encountered: