Skip to content
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

Optional highlighting for InputText-based widgets #3411

Open
Vennor opened this issue Aug 17, 2020 · 2 comments
Open

Optional highlighting for InputText-based widgets #3411

Vennor opened this issue Aug 17, 2020 · 2 comments

Comments

@Vennor
Copy link

Vennor commented Aug 17, 2020

Hi! Currently widgets like ComboBox or Checkbox offer highlighting both for hovered and active state. The same is not true for InputText-based widgets.

We already briefly touched the subject on Discord where the reason why there's no highlight was worded like below.

(...) it seemed less distracting, unlike other widgets which are often active for a short amount of time, InputText() tend to stay active longer.

I agree with that but it also heavily depends on the color style. In my case the differences aren't vast enough to call it distracting and I'd like to have coherent widget behavior.

The only difference in code seems to be that InputText doesn't check the state and color its background so it's trivial to change.

To allow toggling between the current behavior and enabled highlighting we could use ImGuiInputTextFlags and only highlight when a proper flag is rised.

I can do it and make a PR. How do you feel about it?

@ocornut
Copy link
Owner

ocornut commented Apr 23, 2024

Sorry for lack of answer, better late than never.. I was under the impression there was a more complete topic about this and the underlying reasoning, but it might have been a RIP-Discord-only chat.

The code in InputTextEx() could be changed from:

    // Render frame
    if (!is_multiline)
    {
        RenderNavHighlight(frame_bb, id);
--      RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
++      RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32((hovered || g.ActiveId == id) ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), true, style.FrameRounding);
    }

And for multi-line:

        // We reproduce the contents of BeginChildFrame() in order to provide 'label' so our window internal data are easier to read/debug.
--      PushStyleColor(ImGuiCol_ChildBg, style.Colors[ImGuiCol_FrameBg]);
++      const bool use_hovered_bg = (g.ActiveId == id) || (g.HoveredWindow && g.HoveredWindow->ChildId == id);
++      PushStyleColor(ImGuiCol_ChildBg, style.Colors[use_hovered_bg ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg]);

(1) It looks ok with default dark theme, but IMHO rather unusually noisy with StyleColorsLight().
I am not sure how to tackle that yet.

(2) That's not using FrameBgActive so technically still inconsistent, I feel like adding this would be even more noisy for all themes. Note that other items using FrameBgActive are activated for short amounts of time whereas InputText() fields tends to left activated.

(3) I am also not sure how to tackle that for multi-line fields, which tends to be larger and therefore things are largely noticeable.

@ocornut
Copy link
Owner

ocornut commented Apr 23, 2024

We may be able to tackle this by:

  • Adjusting FrameBgHovered/FrameBgActive values in Light theme.
  • Promoting and testing the change to better understand how it would impact people.
  • Hard-coding a custom lerp for multi-line to use an intermediary colors that closer to FrameBg.

An alternative that a bit less consistent but IMHO easier to apply would be to replace

GetColorU32((hovered || g.ActiveId == id) ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg)

with

GetColorU32((hovered && g.ActiveId != id) ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg)

Aka only ever using that color on hover prior to activation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants