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

Single line Input box contents align right. #1442

Closed
wants to merge 2 commits into from

Conversation

kucoman
Copy link

@kucoman kucoman commented Nov 15, 2017

Added new flag: ImGuiInputTextFlags_AlignRight.
Added implementation in InputTexEx().

Added new flag.
Added implementation in InputTexEx().
@ocornut
Copy link
Owner

ocornut commented Nov 15, 2017

Hello,

Referencing your issue #1440

Some comments:

  • AFAIK this only works when not editing the text and then jumps back to the left, wouldn't that be a problem for you? That's the number one question I have.

  • If it's a flag and it doesn't work for multiline then it it should assert against that.

  • However if you are going to use this flag everywhere in your code (is that the case?), I think this could be exposed in the style structure as e.g. ImVec2 InputTextAlign (to mimic ButtonTextAlign) ?

  • The code doesn't follow the general coding style of imgui (no space after //, tabs instead of space)

(The lack of proper single-line and multi-text text alignment primitives is a long standing issue we ought to fix! Probably for an upcoming cleanup of the internals.)

Omar

@kucoman
Copy link
Author

kucoman commented Nov 15, 2017

Yes, while the field is being edited, the right alignment is lost. Even with that, it considerably broadens the use for listing editable fields for numbers, in the form of a sum for instance. Good enough for me for the time being.

About the flag's assert, I believe it is already set and working. I am not sure if there is something else I missed.

As for the other considerations, this is definitely meant as a workaround more than a solution, for an emergency on my end. As you say, the issue is much deeper than just a couple lines. However, depending on when the nice way can be attended to, it might make sense to include this as a temporary convenience. Your call.

I corrected the coding style.
Also, if you believe it is worth it, I might be able to find a slot for the style approach.

@Lectem
Copy link

Lectem commented Jan 29, 2019

We've been using this in production for a few months now, and didn't have any issues until now.
Would it be possible to get this merged ? Is anything holding it back ?

@forrestsmithfb
Copy link

+1 for requesting this feature

@petrihakkinen
Copy link

It would be great to get this feature in. In the meanwhile here's a hack that I did, which does not require changes to imgui itself (but needs access to internal data structures).

https://gist.github.com/petrihakkinen/c2462974ad41f72a54d9aaf2d62b2536

@ocornut
Copy link
Owner

ocornut commented Dec 9, 2024

I have now pushed d78e823 to support this.

  • The flag is called ImGuiInputTextFlags_ElideLeft. I borrowed terminology from Qt. I realize most people would intuit they want "right alignment" but right alignment would be something else when the container is larger than text, and I needed to choose a n name which would be consistent with upcoming text features.
  • This is based on this PR, but : (1) doesn't right-align when container is too large, and (2) sets initial x scrolling on activation to match what's visible pre-activation.
  • I also made a separate and related change: d264542 to ensure x scrolling is the same before and after activation, regardless of flag.
  • This is not supported for multi-line text. As such, the additional cost of CalcTextSize() calls is fine.

Thanks @kucoman !

image

@ocornut
Copy link
Owner

ocornut commented Dec 9, 2024

I should also mention that while I believe a majority people wanted left-elision for displaying path/file names, the suggestion of "right alignment" really confused/threw me off as it meant something different. My comment about exposing this in the style structure doesn't really make sense for this specific purpose, which is clearly desirable per-instance.

(We will later all right-alignment support as a side effect of adding centering.)

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

Successfully merging this pull request may close these issues.

5 participants