-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Add a "HyperLink" control (clickable text with link-like styling) #7660
Comments
I am puzzled because I thought there was a topic or PR exactly about this but I can't find one now.
You are right. The reasons something like this is not in yet:
I'm going to keep this open and see if we can implement something simple. |
Hah, alright. Perhaps a version that takes colors as parameters, a la
A significant number of uses here have nothing to do with browers, but rather just replacing buttons for navigating within the app itself. That is, this is just a differently-styled button. It certainly would be awesome to have an A control that's actually built around opening links in browsers is slightly different in other ways. It needs both URL and optional label parameters. It needs default behaviours to show the URL in a tooltip (assuming the label is not omitted). It needs some way to easily copy the URL to clipboard, e.g. via a context menu. That's a lot more stuff and a lot more "opinion" the that a URL/browser-focused control needs to provide over the core UI functionality of having clickable hyperlinks.
👍🏼 Some work I'm doing right now on an experimental "advancing layout+styling in imgui" project makes me think you're right about that. Breaking up text into separate runs across line breaks, with each run having its own hitbox/etc. makes handling advanced behavior w/ wordwrap much easier. Leaving all the wordwrap to the DrawList limits flexibility substantially. |
I have work in progress new text functions which will be more flexible in many ways (and also faster) but they aren't ready yet. |
… in OS shell, added IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS. (#7660)
I have added a |
Added new widgets functions 5496050 bool TextLink(const char* label); // hyperlink text button, return true when clicked
void TextLinkOpenURL(const char* label, const char* url = NULL); // hyperlink text button, automatically open file/url when clicked (right-click has a context menu with a Copy Link button) Two things I'm not happy about:
Glad we have this in! @juliettef @dougbinks @mekhontsev: note the underlying @floooh @ypujante |
@ocornut As far as I know there is no built-in function to call in emscripten proper, but it is super easy to add one (feel free to name whatever makes sense...). Being in a browser environment in the first place makes the code trivial... #ifdef __EMSCRIPTEN__
EM_JS(void, open_url, (char const *url), {
url = url ? UTF8ToString(url): null;
if(url)
window.open(url, '_blank');
});
#endif
// example usage:
if (ImGui::Button("Open URL"))
open_url("https://github.com/ocornut/imgui"); I don't know how you would translate this into the "handler" api/implementation, but this is the code you need to open a URL in emscripten... |
Thanks! Added and tested the Emscripten handlers in GLFW and SDL backends now: 380b355 |
Happy to help. Let me know if you have any issues. |
This is what I do to open a link in a new browser tab, it's essentially the same as above: EM_JS(void, emsc_js_open_link, (const char* c_url), {
var url = UTF8ToString(c_url);
window.open(url);
}); But: IIRC it is important to call this code from within a HTML input event handler (or equivalent from within an Emscripten event callback) - more on that below. ...I'm using this here (go to "Help => About": https://floooh.github.io/visual6502remix/). The About-box content is rendered with imgui-markdown which has support for links. The way link-clicks are handled is awkward though because of the above limitation that tabs can only be opened from within an HTML event handler: I'm hooking into ImGuiMarkdown's "link-clicked callback" (which seems to be called when the mouse button is pressed down over the link) and only record the information that a link was clicked and its url. Then in the sokol_app.h mouse-up event handler (which is called from within the HTML event handler) I check that flag and call PS: @ypujante I'm very surprised that this works because of the above mentioned limitation that browser tabs can only be opened from within HTML event handlers:
Because (from: https://developer.mozilla.org/en-US/docs/Web/API/Window/open): |
This should be called when the mouse button is released: https://github.com/enkisoftware/imgui_markdown/blob/main/imgui_markdown.h#L852-L862 |
@dougbinks Hmm indeed, now I'm actually wondering why it works :D My link-clicked callback looks like this: https://github.com/floooh/v6502r/blob/2c3dd083b2087577a9a49364c2822564cc2dfc52/src/ui.cc#L2032-L2046 ...this just records that a link has been clicked... ...and then in the sokol_app.h event handler I'm handling that before even passing input events to Dear ImGui (this test_click() function checks for mouse-button-up): https://github.com/floooh/v6502r/blob/2c3dd083b2087577a9a49364c2822564cc2dfc52/src/ui.cc#L520-L525 ...and only further down I'm passing input events to Dear ImGui: https://github.com/floooh/v6502r/blob/2c3dd083b2087577a9a49364c2822564cc2dfc52/src/ui.cc#L616-L621 ...need to investigate, one sec... |
@dougbinks: mystery solved, I actually changed imgui_markdown.h so that the callback is always called as soon as it is hovered: (also this is a very old version of imgui_markdown.h) |
Afaik in my test it worked on Firefox but it was from localhost:8000 and i don't know if there are varying policies for this. |
Yeah it's a mess tbh (like many things on the web platform unfortunately), serving from localhost typically enables a couple of security-related features to make testing easier. But I don't know if opening a new browser tab via |
@floooh I tried with 3 different browsers on my desktop (macOS): Firefox / Chrome and Safari. I use Chrome and Firefox all the time. Rarely Safari. Firefox and Chrome opened the link with no issue. Safari blocked the popup window, but displayed a message about it with a button to allow it: I clicked it and it worked. I probably have allowed popups from localhost on Firefox and Chrome a while back since I use them for development a lot But I believe Safari is the "normal" behavior: browsers will more likely block the popup but will let you know about it and you can override it. |
Hmm yeah, I seem to remember that there's just a subtle icon that a "popup" has been blocked when serving from real web servers, and clicking the icon may allow to define an exception, but this kind-of sucks because it looks like the application wants to do something fishy :) I think it would still be good to allow applications to open the browser tab from a different place where the Dear ImGui link is defined, but I don't know how this could be best done without breaking the ImGui philosophy too much. The way I solved it is basically to keep track if the currently hovered item is a link (and which link), because I need to know this information before the actual click-event on the link happens. Then in my own 'mouse button event handler' (which is running inside the HTML event handler) I check that earlier recorded 'is-link-hovered' flag and call PS: this hover-check wouldn't work for touch UIs unfortunately :( PPS: yeah, confirmed, my approach doesn't work on Android because it relies on the information that an item is hovered. |
@floooh this is definitely one of the major drawbacks of Immediate GUI in general... in the browser everything is event based and that is a very different model... |
The regular key- and pointer-input from browser to Dear ImGui works pretty well, it's mostly about special browser features which require to be called from a "short-lived event handler" for security reasons. So far I stumbled over this issue for:
...also slightly unrelated, text input on mobile devices is its own special circle of hell, I simply gave up on that. For the link-input I can think of a model that could work also on mobile though, instead of recording 'hover' I could probably record whether a touch-start event happens over a link, and then in the following associated touch-end event try to open the tab. Similar with mouse-down / mouse-up. I wonder why I didn't try that - or maybe I tried it and it didn't work for some reason :/ |
* Version 1.90.8 * Version 1.90.9 WIP * Internals: renamed HoveredIdDisabled to HoveredIdIsDisabled for consistency. * Examples: GLFW+Vulkan: handle swap chain resize even without Vulkan returning VK_SUBOPTIMAL_KHR (ocornut#7671) * Examples: SDL+Vulkan: handle swap chain resize even without Vulkan returning VK_SUBOPTIMAL_KHR (ocornut#7671) * Removed old nested structure: renaming ImGuiStorage::ImGuiStoragePair type to ImGuiStoragePair (simpler for many languages). * Internals: made ImLowerBound() accessible in internals + take a span. + rearrange child/popup/tooltips section. Because upcoming rework of ImGuiSelectionBasicStorage will want to do a lower bound on a span. * IO: do not disable io.ConfigWindowsResizeFromEdges when ImGuiBackendFlags_HasMouseCursors is not set by backend. Amend 42bf149 * Style: (Breaking) renamed ImGuiCol_TabActive -> ImGuiCol_TabSelected, ImGuiCol_TabUnfocused -> ImGuiCol_TabDimmed, ImGuiCol_TabUnfocusedActive -> ImGuiCol_TabDimmedSelected. Amend ocornut#261, ocornut#351 * TabBar, Style: added ImGuiTabBarFlags_DrawSelectedOverline and ImGuiCol_TabSelectedOverline, ImGuiCol_TabDimmedSelectedOverline. * Drag and Drop: BeginDragDropSource() with ImGuiDragDropFlags_SourceExtern. (ocornut#143) Amend 0c6e260 * Drag and Drop: Fixes an issue when elapsing payload would be based on last payload frame instead of last drag source frame. * Internals: added ImGuiContext::ContextName optionally used by debug log and to facilitate debugging. * Drag and Drop: comments, debug log entries. * Drag and Drop: BeginDragDropSource() with ImGuiDragDropFlags_SourceExtern assume a mouse button being pressed. (ocornut#143) * Drag and Drop: (Breaking) renamed ImGuiDragDropFlags_SourceAutoExpirePayload to ImGuiDragDropFlags_PayloadAutoExpire. (ocornut#1725, ocornut#143) * Drag and Drop: Added ImGuiDragDropFlags_PayloadNoCrossContext and ImGuiDragDropFlags_PayloadNoCrossProcess flags. * Ignore .ini file with other suffixes. * Fixed build warning. * IO: added ClearInputMouse(). made ClearInputKeys() not clear mouse data. (ocornut#4921) Amend 6aa408c * IO: added ImGuiConfigFlags_NoKeyboard for consistency and convenience. (ocornut#4921) # Conflicts: # imgui.h # imgui_demo.cpp * Nav: CTRL+Tab overlay display context name if any. * Internals: storing HoveredWindowBeforeClear for use by multi-context compositor drag and drop propagation. # Conflicts: # imgui.cpp # imgui_internal.h * (Breaking) Move ImGuiWindowFlags_NavFlattened to ImGuiChildFlags_NavFlattened. (ocornut#7687) * Backends: SDL3: Follow SDL3 removal of keysym field in SDL_KeyboardEvent (ocornut#7729) * Demo: Style Editor: clarify how _CalcCircleAutoSegmentCount() doesn't always get exact final segment count. (ocornut#7731) * Backends: Vulkan: Remove Volk/ from volk.h #include directives (ocornut#7722, ocornut#6582, ocornut#4854) * Metrics/Debugger: Browsing a Storage perform hover lookup on identifier. * Viewports: Backported 'void* ImGuiViewport::PlatformHandle' from docking branch for use by backends. * Backends: SDL3: Update for SDL_StartTextInput()/SDL_StopTextInput() API changes. (ocornut#7735) * Examples: undo adding SDL3 example to Visual Studio sln. * Backends: OSX: build fix. Amend 32f9dfc * ImGuiStorage: tweak impl for BuildSortByKey(). * Inputs: fixed using Shortcut() or SetNextItemShortcut() within a disabled block bypassing the disabled state. (ocornut#7726) * Tables: moved TableGetHoveredColumn() to public API. (ocornut#7715, ocornut#3740) * Windows: BeginChild(): fixed a glitch when during a resize of a child window which is tightly close to the boundaries of its parent. (ocornut#7706) * Nav: store NavJustMovedToIsTabbing + shuffle a few nav related fields. (for usage by multi-select) * Backends: OpenGL2, OpenGL3: ImGui_ImplOpenGL3_NewFrame() recreates font texture if it has been destroyed by ImGui_ImplOpenGL3_DestroyFontsTexture(). (ocornut#7748) Analogous to change to Vulkan backend in 1.90. * Backends: Win32: Fixed warning with old MinGW/GCC versions. * Drags: added ImGuisliderFlags_WrapAround flag for DragInt(), DragFloat() etc. (ocornut#7749) * Fix typo, rename ImGuisliderFlags_WrapAround flag to ImGuiSliderFlags_WrapAround. (ocornut#7752, ocornut#7749) * Checkbox: minor tidying up to simplify work on multi-select branch. * Backends: Allegro5: Correctly handle unstable bit in version checks (ocornut#7755) * Backends: SDLRenderer3: Update for SDL_RenderGeometryRaw() API changes. * Backends: SDL3: update for SDL_SetTextInputRect() -> SDL_SetTextInputArea() api change. (ocornut#7760, ocornut#7754) * Examples: SDL3: Remove use of SDL_HINT_IME_NATIVE_UI. * Disabled: Reworked 1.90.8 behavior of Begin() not inheriting current BeginDisabled() state. Only tooltip are clearing that state. (ocornut#211, ocornut#7640) * imgui_freetype: fixed divide by zero while handling FT_PIXEL_MODE_BGRA glyphs. (ocornut#7267, ocornut#3369) * IO: do not claim io.WantCaptureMouse=true on the mouse release frame of a button which was pressed over void. (ocornut#1392) * Version 1.90.9 * Version 1.91.0 WIP * Backends: SDL3: Update for API changes: SDLK_x renames and SDLK_KP_x removals (ocornut#7761, ocornut#7762) Also updated function signature in SDL2 backend to match and because it is expected we will use that data (as per ocornut#7672) * Backends: SDL3: Updated comments (IME seems fixed in SDL3). Added SDL3 examples to Visual Studio solution. * Debug Tools: Added IMGUI_DEBUG_LOG(), ImGui::DebugLog() in public API. (ocornut#5855) * Debug Log: Added "Configure Outputs.." button. (ocornut#5855) * Backends: SDL3: add default case to fix warnings. (ocornut#7763) * Demo: changed style editor inline block to its own window. * IO: added io.PlatformOpenInShellFn handler to open a link/folder/file in OS shell, added IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS. (ocornut#7660) * (Breaking) IO, IME: renamed platform IME hook io.SetPlatformImeDataFn() -> io.PlatformSetImeDataFn() and added explicit context. * Commented out obsolete ImGuiModFlags and ImGuiModFlags_XXX values (renamed to ImGuiKeyChord and ImGuiMod_XXX in 1.89). (ocornut#4921, ocornut#456) * Build fix for non Windows platforms. * IO: disable default io.PlatformOpenInShellFn() implementation on iPhone, as compiler errors that system() is not available on iOS. * Internals: added FontScale storage. * Added TextLink(), TextLinkOpenURL() hyperlink widgets. (ocornut#7660) * Internals: added FontScale storage (amend 0f63d3e). * Backends: GLFW,SDL2: Added ioPlatformOpenInShellFn handler for web/Emscripten versions. (ocornut#7660) * IO: amend PlatformOpenInShellFn specs to return a bool. (ocornut#7660) Amend 8f36798 * Misc tweaks, comments. * TreeNode: rename/rework ImGuiNavTreeNodeData system to be usable by more features. (ocornut#2920, ocornut#1131, ocornut#7553) Reworked to it is easier during TreeNode code to request extra data to be stored. * Fixed Unix version of PlatformOpenInShellFn_DefaultImpl. (ocornut#7772, ocornut#7660) + Enable on non-iPhone macOS builds * DemosFix typo in help text in demo Tables/Borders (ocornut#7780) The help text for flags had a "V" flag duplicated, this change corrects it to the missing "H" flag. * Backends: Win32: fixed ImGuiMod_Super being mapped to VK_APPS instead of VK_LWIN||VK_RWIN (ocornut#7768, ocornut#4858, ocornut#2622) Amend 0755767 The `ImGui_ImplWin32_UpdateKeyModifiers()` function maps `ImGuiMod_Super` to `VK_APPS`, the "Application" key located between the Right Windows (Super) and Right Control keys on the keyboard, see https://conemu.github.io/en/AppsKey.html This means that when using `ImGui::GetIO().KeySuper` to try to get the down state of the `VK_RWIN` or `VK_LWIN` keys, it'll always return FALSE when either of those keys are held down, and only return TRUE when `VK_APPS` is held down. * Backends: GLFW+Emscripten: (Breaking) Renamed ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback() to ImGui_ImplGlfw_InstallEmscriptenCallbacks(), added GLFWwindow* parameter. (ocornut#7647, ocornut#7600) + Fixed Emscripten warning when using mouse wheel on some setups. * Backends: GLFW+Emscripten: Added support for GLFW3 contrib port. (ocornut#7647) * Backends: GLFW+Emscripten: Fixed build (ocornut#7647) * Examples: SDL3+OpenGL: Update for API changes: SDL_GL_DeleteContext() renamed to SDL_GL_DestroyContext(). * Fix definition check (ocornut#7793) * Backends: SDL3: Update for API changes: SDL_GetProperty() change to SDL_GetPointerProperty(). (ocornut#7794) * Backends: SDL3: fixed typo leading to PlatformHandleRaw not being set leading to SHOWNA path not working for multi-viewports. * Internals: Added TreeNodeIsOpen() to facilitate discoverability. (ocornut#7553, ocornut#1131, ocornut#2958, ocornut#2079, ocornut#722) * Added ImGuiDataType_Bool for convenience. * Demo: Reworked "Property Editor" demo in a manner that more ressemble the tree data and struct description data that a real application would want to use. * Added PushItemFlag(), PopItemFlag(), ImGuiItemFlags. * (Breaking) Obsoleted PushButtonRepeat()/PopButtonRepeat() in favor of using new PushItemFlag()/PopItemFlag() with ImGuiItemFlags_ButtonRepeat. * Added ImGuiItemFlags_AutoClosePopups as a replacement for internal's ImGuiItemFlags_SelectableDontClosePopup. (ocornut#1379, ocornut#1468, ocornut#2200, ocornut#4936, ocornut#5216, ocornut#7302, ocornut#7573) * (Breaking) Renamed ImGuiSelectableFlags_DontClosePopups to ImGuiSelectableFlags_NoAutoClosePopups. (ocornut#1379, ocornut#1468, ocornut#2200, ocornut#4936, ocornut#5216, ocornut#7302, ocornut#7573) * Obsoleted PushTabStop()/PopTabStop() in favor of using new PushItemFlag()/PopItemFlag() with ImGuiItemFlags_NoTabStop. * Fixed pvs-studio warning. * Demo: Property Editor: rearrange code + replace use of bool to proper ImGuiChildFlags. Amend 46691d1 * Demo: Property Editor: add basic filter. * Style: close button and collapse/window-menu button hover highlight made rectangular instead of round. The reason they were round in the first place was to work better with rounded windows/frames. However since the 4a81424 rework ocornut#6749 we can naturally use a tigher bounding box and it seems to work ok either way. * Nav, Demo: comments. * Clipper: added SeekCursorForItem() function, for use when using ImGuiListClipper::Begin(INT_MAX). (ocornut#1311) Tagging ocornut#3609 just in case we made a mistake introducing a regression (but tests are passing and have been extended). * TreeNode: Internals: facilitate dissociating item ID from storage ID (useful for 1861) * Internals: rename recently added TreeNodeIsOpen() -> TreeNodeGetOpen(). (ocornut#7553, ocornut#1131, ocornut#2958, ocornut#2079, ocornut#722) Amend ac7d6fb * Backends: SDL3: Update for API changes: SDL_GetClipboardText() string ownership change. (ocornut#7801) * MultiSelect: WIP range-select (ocornut#1861) (rebased six millions times) * MultiSelect: Removed SelectableSpacing as I'm not sure it is of use for now (history insert) * MultiSelect: Added IMGUI_HAS_MULTI_SELECT define. Fixed right-click toggling selection without clearing active id, could lead to MarkItemEdited() asserting. Fixed demo. * MultiSelect: Demo sharing selection helper code. Fixed static analyzer warnings. * MultiSelect: Renamed SetNextItemMultiSelectData() to SetNextItemSelectionUserData() * MultiSelect: Transition to use FocusScope bits merged in master. Preserve ability to shift+arrow into an item that is part of FocusScope but doesn't carry a selection without breaking selection. * MultiSelect: Fix for TreeNode following merge of 011d475. Demo: basic test for tree nodes. * MultiSelect: Fixed CTRL+A not testing focus scope id. Fixed CTRL+A not testing active id. Added demo code. Comments. * MultiSelect: Comments. Tweak demo. * MultiSelect: Fix Selectable() ambiguous return value, clarify need to use IsItemToggledSelection(). * MultiSelect: Fix testing key mods from after the nav request (remove need to hold the mod longer) * MultiSelect: Temporary fix/work-around for child/popup to not inherit MultiSelectEnabled flag, until we make mulit-select data stackable. * MultiSelect: Fixed issue with Ctrl+click on TreeNode + amend demo to test drag and drop. * MultiSelect: Demo: Add a simpler version. * MultiSelect: Added ImGuiMultiSelectFlags_ClearOnEscape (unsure of best design), expose IsFocused for custom shortcuts. * MultiSelect: Demo: Added pointer indirection and indent level. This is to reduce noise for upcoming commits, ahead of adding a loop here. * MultiSelect: Added ImGuiMultiSelectFlags_ClearOnClickWindowVoid. + Demo: showcase multiple selection scopes in same window. * MultiSelect: Enter doesn't alter selection (unlike Space). Fix for changes done in 5606. * MultiSelect: Shallow tweaks/refactors. Including moving IsFocused back internally for now. * MultiSelect: Fixed needing to set RangeSrcPassedBy when not using clipper. * MultiSelect: made SetNextItemSelectionData() optional to allow disjoint selection (e.g. with a CollapsingHeader between items). Amend demo. * MultiSelect: Enter can alter selection if current item is not selected. * MultiSelect: removed DragDropActive/preserve_existing_selection logic which seems unused + comments. Can't find trace of early prototype for range-select but I couldn't find way to trigger this anymore. May be wrong. Will find out. * MultiSelect: refactor before introducing persistant state pool and to facilitate adding recursion + debug log calls. This is mostly the noisy/shallow stuff committed here, to get this out of the way. * MultiSelect: (Breaking) Rename ImGuiMultiSelectData to ImGuiMultiSelectIO. * MultiSelect: Demo tweak. Removed multi-scope from Advanced (too messy), made it a seperate mini-demo. * MultiSelect: Internals rename of IO fields to avoid ambiguity with io/rw concepts + memset constructors, tweaks. debug * MultiSelect: (Breaking) Renamed 'RangeSrc -> 'RangeSrcItem', "RangeDst' -> 'RangeDstItem' This is necessary to have consistent names in upcoming fields (NavIdItem etc.) * MultiSelect: (Breaking) Renamed 'RangeValue' -> 'RangeSelected' + amend comments. * MultiSelect: Remove ImGuiMultiSelectFlags_NoUnselect because I currently can't find use for this specific design. And/or it seem partly broken. * MultiSelect: Remove the need for using IsItemToggledSelection(). Update comments. This is the simple version that past our tests. MultiSelectItemFooter() is in need of a cleanup. * MultiSelect: Tidying up/simpllifying MultiSelectItemFooter(). Intended to be entirely a no-op, merely a transform of source code for simplification. But committing separatey from behavior change in previous change. * MultiSelect: Clarify and better enforce lifetime of BeginMultiSelect() value. * MultiSelect: Demo: first-draft of user-side deletion idioms. (will need support from lib) * MultiSelect: (Breaking) BeginMultiSelect() doesn't need two last params maintained by users. Moving some storage from user to core. Proper deletion demo. * MultiSelect: Maintain NavIdSelected for user. Simplify deletion demo. * MultiSelect: Further simplication of user code to support Deletion. Provide standard RequestFocusItem storage. * MultiSelect: Demo: Delete items from menu. * MultiSelect: Fixed right-click handling in MultiSelectItemFooter() when not focused. * MultiSelect: Cleanup unused comments/code. * MultiSelect: (Breaking) Fix + Rename ImGuiMultiSelectFlags_NoMultiSelect to ImGuiMultiSelectFlags_SingleSelect as it seems easier to grasp. Feature was broken by "Tidying up..." June 30 commit. * MultiSelect: Comments, tweaks. + Alignment to reduce noise on next commit. * MultiSelect: (Breaking) Use ImGuiSelectionUserData (= ImS64) instead of void* for selection user data. Less confusing for most users, less casting. * MultiSelect: move HasSelectionData to ImGuiItemFlags to facilitate copying around in standardized fieds. Required/motivated to simplify support for ImGuiTreeNodeFlags_NavLeftJumpsBackHere (bc3c0ce) in this branch. * MultiSelect: Tweak debug log to print decimal+hex values for item data. Struggled to get standard PRIX64 to work on CI. * MultiSelect: clear selection when leaving a scope with a nav directional request. May need to clarify how to depends on actions being performed (e.g. click doesn't). May become optional? * MultiSelect: (Breaking) RequestSetRange's parameter are RangeFirstItem...RangeLastItem (which was always ordered unlike RangeSrcItem...RangeDstItme). Removed RangeDstItem. Removed RangeDirection. * MultiSelect: Demo: rework ExampleSelection names to map better to typical user code + variety of Comments tweaks. * MultiSelect: Demo: added simpler demo using Clipper. Clarify RangeSrcPassedBy doc. * MultiSelect: (Breaking) Removed RangeSrcPassedBy in favor of favoring user to call IncludeByIndex(RangeSrcItem) which is easier/simpler to honor. Especially as recent changes made it required to also update RangeSrcPassedBy after last clipper Step. Should now be simpler. * MultiSelect: Demo: rework ExampleSelection with an ExampleSelectionAdapter layer, allowing to share more code accross examples using different storage systems. Not ideal way to showcase this demo but this is really more flexible. * MultiSelect: Demo: Remove UserDataToIndex from ExampleSelectionAdapter. Seems to make a better demo this way. * MultiSelect: Demo: Make ExampleSelection use ImGuiID. More self-explanatory. * MultiSelect: Demo: Deletion: Rework ApplyDeletionPreLoop to use adapter + fix PostLoop not using right value of RequestFocusItem. Recovery made it transparent visually but user side selection would be empty for a frame before recovery. * MultiSelect: Demo: Deletion: Various renames to clarify. Use adapter and item list in both ApplyDeletion functions. This also minify the patch for an alternative/wip attmept at redesgining pre/post deletion logic. But turns out current attempt may be easier to grasp. * Demo: Dual List Box: Added a dual list box (6648) * MultiSelect: ImGuiMultiSelectIO's field are not used during loop anymore, stripping them out of comments. * MultiSelect: moved RequestClear output so it'll match request list version better. Use Storage->RangeSrcItem in EndMultiSelect(). * MultiSelect: move shared logic to MultiSelectItemHeader(). No logic change AFAIK but added an indent level in MultiSelectItemHeader(). Logic changes will come in next commit. * MultiSelect: Added ImGuiMultiSelectFlags_SelectOnClickRelease to allow dragging an unselected item without altering selection + update drag and drop demo. * Demo: Assets Browser: Added assets browser demo. * Demo: Assets Browser: store items, sorting, type overlay. * MultiSelect: removed seemingly unnecessary block in BeginMultiSelect(). - EndIO.RangeSelected always set along with EndIO.RequestSetRange - Trying to assert for the assignment making a difference when EndIO.RequestSetRange is already set couldn't find a case (tests passing). * MultiSelect: clarified purpose and use of IsItemToggledSelection(). Added assert. Moved to multi-selection section of imgui.h. * MultiSelect: added missing call on Shutdown(). Better reuse selection buffer. * MultiSelect: (Breaking) io contains a ImVector<ImGuiSelectionRequest> list. * MultiSelect: we don't need to ever write to EndIO.RangeSrcItem as this is not meant to be used. * MultiSelect: added support for recovery in ErrorCheckEndWindowRecover(). * MultiSelect: use a single ImGuiMultiSelectIO buffer. + using local storage var in EndMultiSelect(), should be no-op. * MultiSelect: simplify clearing ImGuiMultiSelectTempData. * Demo: Assets Browser: add hit spacing, requierd for box-select patterns. * MultiSelect: (breaking) renamed ImGuiMultiSelectFlags_ClearOnClickWindowVoid -> ImGuiMultiSelectFlags_ClearOnClickVoid. Added ImGuiMultiSelectFlags_ScopeWindow, ImGuiMultiSelectFlags_ScopeRect. * MultiSelect: Box-Select: added support for ImGuiMultiSelectFlags_BoxSelect. (v11) FIXME: broken on clipping demo. * MultiSelect: Box-Select: added scroll support. * MultiSelect: Demo: rework and move selection adapter inside ExampleSelection. * MultiSelect: added support for nested/stacked BeginMultiSelect(). Mimicking table logic, reusing amortized buffers. * MultiSelect: remove ImGuiSelectionRequest/ImGuiMultiSelectIO details from public api to reduce confusion + comments. * MultiSelect: move demo's ExampleSelection to main api as a convenient ImGuiSelectionBasicStorage for basic users. * MultiSelect: reworked comments in imgui.h now that we have our own section. * MultiSelect: Demo: Assets Browser: added deletion support. Store ID in selection. Moved QueueDeletion to local var to emphasis that this is a user extension. * MultiSelect: Demo: Assets Browser: track scrolling target so we can roughly land on hovered item. It's impossible to do this perfectly without some form of locking on item because as the hovered item X position changes it's easy to drift. * MultiSelect: Box-Select: Fixed holes when using with clipper (in 1D list.) Clipper accounts for Selectable() layout oddity as BoxSelect is sensitive to it. Also tweaked scroll triggering region inward. Rename ImGuiMultiSelectFlags_NoBoxSelectScroll to ImGuiMultiSelectFlags_BoxSelectNoScroll. Fixed use with ImGuiMultiSelectFlags_SinglaSelect. * MultiSelect: Box-Select: Added ImGuiMultiSelectFlags_BoxSelect2d support. Enabled in Asset Browser. Selectable() supports it. * MultiSelect: Box-Select: Refactor into its own structure, designed for single-instance but closer to being reusable outside Multi-Select. Kept same member names. * MultiSelect: Box-Select: Refactor: Renames. Split into two commits to facilite looking into previous one if needed. * MultiSelect: Box-Select: Fixed scrolling on high framerates. * MultiSelect: Box-Select: Further refactor to extra mode code away from multi-select function into box-select funcitons. * MultiSelect: Fixed ImGuiSelectionBasicStorage::ApplyRequests() incorrectly maintaining selection size on SelectAll. * MultiSelect: Comments + Assets Browser : Tweak colors. * MultiSelect: Added ImGuiMultiSelectFlags_NoRangeSelect. Fixed ImGuiMultiSelectFlags_ScopeRect not querying proper window hover. * MultiSelect: Box-Select: Fixed CTRL+drag from void clearing items. * MultiSelect: Box-Select: Fixed initial drag from not claiming hovered id, preventing window behind to move for a frame. * MultiSelect: Fixed ImGuiMultiSelectFlags_SelectOnClickRelease over tree node arrow. * MultiSelect: (Breaking) merge ImGuiSelectionRequestType_Clear and ImGuiSelectionRequestType_SelectAll into ImGuiSelectionRequestType_SetAll., rename ImGuiSelectionRequest::RangeSelected to Selected. The reasoning is that it makes it easier/faster to write an adhoc ImGuiMultiSelectIO handler (e.g. trying to apply multi-select to checkboxes) * MultiSelect: Simplified ImGuiSelectionBasicStorage by using a single SetItemSelected() entry point. * MultiSelect: Comments + tweaked location for widgets to test ImGuiItemFlags_IsMultiSelect to avoid misleading into thinking doing it before ItemAdd() is necessary. * MultiSelect: Demo: make various child windows resizable, with synched heights for the dual list box demo. * MultiSelect: added ImGuiMultiSelectFlags_NoAutoSelect, ImGuiMultiSelectFlags_NoAutoClear features + added Checkbox Demo Refer to "widgets_multiselect_checkboxes" in imgui_test_suite. * MultiSelect: Box-Select: fix preventing focus. amend determination of scope_hovered for decorated/non-child windows + avoid stealing NavId. (ocornut#7424) * MultiSelect: Demo: use Shortcut(). Got rid of suggestion to move Delete signal processing to BeginMultiSelect(), seems unnecessary. * RangeSelect/MultiSelect: (Breaking) Added current_selection_size to BeginMultiSelect(). Required for shortcut routing so we can e.g. have Escape be used to clear selection THEN to exit child window. * MultiSelect: Box-Select: minor refactor, tidying up. * MultiSelect: Box-Select: when dragging from void, first hit item sets NavId by simulating a press, so navigation can resume from that spot. * MultiSelect: added GetMultiSelectState() + store LastSelectionSize as provided by user, convenient for quick debugging and testing. * MultiSelect: Box-Select: fixed "when dragging from void" implementation messing with calling BeginMultiSelect() without a selection size. * MultiSelect: (breaking) renamed ImGuiSelectionBasicStorage::AdapterData to UserData. * MultiSelect: Box-Select: fixes for checkboxes support. Comments. * MultiSelect: (breaking) renamed ImGuiMultiSelectFlags_BoxSelect -> ImGuiMultiSelectFlags_BoxSelect1d, ImGuiMultiSelectFlags_BoxSelect2d -> ImGuiMultiSelectFlags_BoxSelect. ImGuiMultiSelectFlags_BoxSelect1d being an optimization it is the optional flag. * MultiSelect: mark parent child window as navigable into, with highlight. Assume user will always submit interactive items. * MultiSelect: (breaking) Added 'items_count' parameter to BeginMultiSelect(). Will enable extra features, and remove equivalent param from ImGuiSelectionBasicStorage::ApplyRequests(. * MultiSelect: added ImGuiSelectionBasicStorage::GetStorageIdFromIndex() indirection to be easier on the reader. Tempting to make it a virtual. * MultiSelect: fixed ImGuiSelectionBasicStorage::Swap() helper. * MultiSelect: added ImGuiSelectionExternalStorage helper. Simplify bool demo. * MultiSelect: comments, header tweaks., simplication (some of it on wiki). * MultiSelect: ImGuiSelectionBasicStorage: added GetNextSelectedItem() to abstract selection storage from user. Amend Assets Browser demo to handle drag and drop correctly. * MultiSelect: ImGuiSelectionBasicStorage: rework to accept massive selections requests without flinching. Batch modification + storage only keeps selected items. * MultiSelect: ImGuiSelectionBasicStorage: simplify by removing compacting code (compacting may be opt-in?). GetNextSelectedItem() wrapper gives us more flexibility to work on this kind of stuff now. * MultiSelect: ImGuiSelectionBasicStorage: move function bodies to cpp file. + make ImGuiStorage::BuildSortByKey() less affected by msvc debug mode. * Demo: Assets Browser: added a way to disable sorting and hide sorting options. This is mostly designed to showcase that on very large sets (e.g. 1 million) most of the time is likely spent on sorting. * MultiSelect: ImGuiSelectionBasicStorage: (breaking) rework GetNextSelectedItem() api to avoid ambiguity/failure when user uses a zero id. * MultiSelect: provide RangeDirection to allow selection handler to handler backward shift+click. * MultiSelect: ImGuiSelectionBasicStorage: added PreserveOrder, maintain implicit order data in storage. Little tested but provided for completeness. * MultiSelect: (breaking) renamed ImGuiMultiSelectFlags_BoxSelect -> ImGuiMultiSelectFlags_BoxSelect2d. Which include not assuming one flag imply the other. Amend 2024/05/31 commit. * MultiSelect: Shift+Tab doesn't enable Shift select on landing item. * MultiSelect: added ImGuiMultiSelectFlags_NoAutoClearOnReselect + tweak flags comments. (ocornut#7424) * MultiSelect: minor tidying up. Checkbox() was reworked in master effectively fixing render clipping when culled by BoxSelect2d's UnclipMode. * MultiSelect: added courtesy ImGuiMultiSelectFlags_NavWrapX flag so we can demo this until a nav api is designed. * MultiSelect: Box-Select: uses SetActiveIdUsingAllKeyboardKeys() to avoid nav interference, much like most drag operations. * MultiSelect: Box-Select: handle Esc to disable box-select. This avoid remove a one-frame delay when finishing box-select, where Esc wouldn't be routed to selection but to child. * MultiSelect: ImGuiSelectionBasicStorage: optimized for smaller insertion amounts in larger sets + fix caling batch select with same value. * MultiSelect: Better document how TreeNode() is not trivially usable yet. Will revert when the time is right. * MultiSelect: added Changelog for the feature. Removed IMGUI_HAS_MULTI_SELECT. * Demo: moved ExampleTreeNode, ExampleMemberInfo above in the demo file. Tidying up index. + change ExampleTreeNode::UID from ImGuiID to int to not suggest that the user ID needs to be of a certain type * Demo: moved some fields inside a struct. * Demo: moved menu bar code to its own function. * MultiSelect: using ImGuiMultiSelectFlags_NoRangeSelect ensure never having to interpolate between two ImGuiSelectionUserData. * Inputs: added SetItemKeyOwner(ImGuiKey key) in public API. (ocornut#456, ocornut#2637, ocornut#2620, ocornut#2891, ocornut#3370, ocornut#3724, ocornut#4828, ocornut#5108, ocornut#5242, ocornut#5641) * Backends: SDL3: Update for API changes: SDL_GetGamepads() memory ownership change. (ocornut#7807) * TabBar, Style: added style option for the size of the Tab-Bar Overline (ocornut#7804) Amend 21bda2e. * Added a comment hinting at how to set IMGUI_API for shared librairies on e.g. Linux, macOS (ocornut#7806) * Demo: rework Property Editor. * Nav: fixed c licking window decorations (e.g. resize borders) from losing focused item when within a child window using ImGuiChildFlags_NavFlattened. In essence, using ImGuiFocusRequestFlags_RestoreFocusedChild here is a way to reduce changes caused by FocusWindow(), but it could be done more neatly. See amended "nav_flattened" test. * Demo: Property Editor: using ImGuiChildFlags_NavFlattened now that a bug is fixed. Fixed static analyzer. * Backends: OpenGL3: Fixed unsupported option warning with apple clang (ocornut#7810) * Internals, TreeNode: indent all render block into its own scope (aim is to add a is_visible test there later) * Internals, TreeNode, Selectable: tweak span_all_columns paths for clarity. * CollapsingHeader: left-side outer extend matches right-side one (moved left by one pixel) Amend c3a348a * Debug Log: fixed incorrect checkbox layout when partially clipped., doesn't parse 64-bits hex value as ImGuiID lookups. * Groups, Tables: fixed EndGroup() failing to correctly capture current table occupied size. (ocornut#7543) See "layout_group_endtable" test. * MultiSelect: sequential SetRange merging not generally handled by box-select path, useful for others. * MultiSelect: add internal MultiSelectAddSetAll() helper. * MultiSelect: fixed an issue caused by previous commit. Amend a285835. Breaks box-select. --------- Co-authored-by: ocornut <omarcornut@gmail.com> Co-authored-by: cfillion <cfillion@users.noreply.github.com> Co-authored-by: Gary Geng <garygengxiao@gmail.com> Co-authored-by: Martin Ejdestig <marejde@gmail.com> Co-authored-by: Kevin Coghlan <mail@kevincoghlan.com> Co-authored-by: Connor Clark <cjamcl@gmail.com> Co-authored-by: Max Ortner <maxortner01@gmail.com> Co-authored-by: Hugues Evrard <hevrard@users.noreply.github.com> Co-authored-by: Aemony <10578344+Aemony@users.noreply.github.com> Co-authored-by: Yan Pujante <ypujante@proton.me> Co-authored-by: Cyao <94928179+cheyao@users.noreply.github.com> Co-authored-by: wermi <32251376+wermipls@users.noreply.github.com> Co-authored-by: Thomas Stehle <th.stehle@icloud.com>
I'm not sure I understand the problem discussed above. May I close this issue? Is there something that you think should be done on imgui or imgui's backends end? |
Regarding Did you try if it also works on a 'properly hosted' web page hosted via https and not just from localhost, 127.0.0.1 or 0.0.0.0? Normally a link can only be opened in web browsers from within an HTML input event handler, so |
I didn't, no. I tried on localhost. Would this triggers an authorization popup the first time, or would this just fail? If the later we should definitively dig into the workaround. |
I do have a "recent" build not hosted on localhost if you want to try https://pongasoft.github.io/imgui/pr-7647/use_port_contrib_glfw3/ (requires webgpu support). From my experiece clicking on the links work... |
It does work on Chrome indeed. |
Nice, yeah works here too :) @ypujante Is that the regular example_glfw_wgpu in the Dear ImGui repo? I need to check how that magic works ;) @ocornut AFAIK if there would be an old popup blocker exception active, Chrome would show some sort of icon in the navbar. I don't see one though, so I guess it works without a one-time popup blocker exception. In any case, from my pov it's ok to close this issue :) |
Ah ok, as always, Safari is the problem... I get a 'Popup Blocked" message there and nothing happens (since the demo requires WebGPU, need to test with the latest Safari Technology Preview version, and AFAIK a WebGPU flags needs to be enabled). (while my solution in https://floooh.github.io/visualz80remix/ works with Safari since it opens the tab from within an Emscripten event callback) |
@floooh can you point me to the code that does: "works with Safari since it opens the tab from within an Emscripten event callback"? I would like to see if I can implement it in my library. Thank you. |
@ypujante it's a bit of a mess tbh and spread over different places in the code. Best to start here in my event handler and work backwards. The event handler is called from within Emscripten event callbacks, which in turn run inside a HTML event handler (that's why the whole thing works also in Safari): https://github.com/floooh/v6502r/blob/2c3dd083b2087577a9a49364c2822564cc2dfc52/src/ui.cc#L520-L525 That The gist is that inside the regular UI description code I keep track of whether the mouse currently hovers an URL link, and what the URL is... and then defer actually opening the link to my own event handler when a mouse click happens and the mouse currently hovers an URL link, so opening the link is not triggered by Dear ImGui, I'm only "polling" Dear ImGui each frame if the mouse hovers a link basically. In reality I had to hack around a bit in imgui_markdown to call its 'link clicked' callback not only on a click, but each frame as soon as the mouse hovers the link. This was necessary to resolve the chicken-egg-situation that I need to open the the URL from within my own input handler on a click even before Dear ImGui knows about this click, I need to know whether a link needs to be opened before the click happens. Maybe a similar 'hack' is required in Dear ImGui to make it work with the new ...or maybe alternatively Dear ImGui could offer a function |
Thank you for the link and explanation. I will investigate and see if I can come up with something generic for emscripten-glfw and ImGui. TBH I am having somewhat similar issue with get clipboard due to the asynchronous nature of the api: I implemented an extension API (asynchronous) but it is hard to retrofit it in ImGui (since the Paste keyboard event triggers the asynchronous call and only when it happens can you actually apply the paste...) |
Yeah I have the same sorts of hacks for clipboard support on the web. When you look around in the code near the region I linked above, you'll see :D |
@floooh I wanted to let you know that I have a "clean" solution for the "Popup Blocked" Safari issue and that it will be released with the next version of emscripten_glfw with a new convenient API: // cpp API
/**
* Convenient call to open a url */
void OpenURL(std::string_view url, std::optional<std::string_view> target = "_blank");
// C API
/**
* Convenient call to open a url
* @param target can be `nullptr` which defaults to `_blank` */
void emscripten_glfw_open_url(char const *url, char const *target); it will just be a matter of setting this function something like this in ImGui (I will do a PR when ready): #ifdef __EMSCRIPTEN__
#if EMSCRIPTEN_USE_PORT_CONTRIB_GLFW3 > [versionTBD]
void ImGui_ImplGlfw_EmscriptenOpenURL(char const* url)
{
if(url) emscripten_glfw_open_url(url, nullptr);
}
#else
EM_JS(void, ImGui_ImplGlfw_EmscriptenOpenURL, (char const* url), { url = url ? UTF8ToString(url) : null; if (url) window.open(url, '_blank'); });
#endif
#endif |
FYI i have just introduced
(Because this was introduced very recently and presumably not used much as core lib implement a good default, I have choosent to not implement legacy redirection for it.) |
Thanks for the heads up. Much appreciated! |
Version/Branch of Dear ImGui:
Version 1.90.7, Branch: master
Back-ends:
Any (Unity/C# integration most recent case)
Compiler, OS:
Any (Windows, Unity C# 2022.x in most recent case)
Full config/build information:
No response
Details:
Feature Request
A small control that I've written for past projects and which we implemented at Wargaming, Blizzard (SGE), and at my current employer is a "HyperLink" widget, so it seems to me to be a frequently recurring pattern.
A hyperlink is some Text but which is rendered in a different color (e.g. blue) and has an underline, changes color slightly when hovered, and responds to clicks like a button, etc.
For users, this would be something like:
Writing the most basic version of this is almost trivial, of course, but it gets a bit trickier once things like keyboard focus and activation are considered, and really tricky to handle keyboard focus styling well. Every single implementation of such a control that I've seen (including mine!) got some or all of those wrong initially. I'm still not sure that I've seen one that handles word-wrap and focus highlight correctly, now that I think about it.
Having something like this in dear imgui itself instead of being reimplemented (often poorly) would be a small win.
Screenshots/Video:
Example of what a HyperLink control might look like:
And focused (styling could be better, just a quick demo here):
Minimal, Complete and Verifiable Example code:
The text was updated successfully, but these errors were encountered: