Coder Social home page Coder Social logo

Comments (11)

xythobuz avatar xythobuz commented on May 14, 2024

👍 I have exactly the same problem trying to implement a console.

from imgui.

ocornut avatar ocornut commented on May 14, 2024

I'll have to think how to handle that. To handle cursor-position based completion (and cursor preserving history) your code will need to have access to data such as cursor position, selection.

Once InputText is able to expose those data into a small structure and read them back if modified then it could just call a callback and you can do what you want within it. So maybe the system doesn't need to be created with keystroke in mind in particular.

Note that if you don't need the cursor position you could probably get away with just using a function that can tell you if the current widget has focus, and then run your code after. This function is currently missing in ImGui but trivial to implement so I could add that as a first step.

What do you mean by "(Would be nice to have an ImGuiKey_Tab for this as well,)" ?

from imgui.

JarrettBillingsley avatar JarrettBillingsley commented on May 14, 2024

What do you mean by "(Would be nice to have an ImGuiKey_Tab for this as well,)" ?

Oh, I mean currently Tab is treated as a "text" character and wouldn't be intercepted by the code in InputText. But I suppose the "text input" loop could check for '\t' as well.

from imgui.

ocornut avatar ocornut commented on May 14, 2024

Yes, however this is implemented it would have to work for TAB obviously.

from imgui.

ocornut avatar ocornut commented on May 14, 2024

I am now working on implementing a nice console with those example as a test ground for adding the missing features.

from imgui.

JarrettBillingsley avatar JarrettBillingsley commented on May 14, 2024

Yay!

On Wed, Oct 29, 2014 at 5:19 AM, omar [email protected] wrote:

I am now working on implementing a nice console with those example as a
test ground for adding the missing features.


Reply to this email directly or view it on GitHub
#68 (comment).

from imgui.

ocornut avatar ocornut commented on May 14, 2024

Not much progress on the actual requests (history/completion) but I have implemented a basic console (that doesn't have those features yet!). However toward doing this I already made a few others small changes/additions to the library.
Stay tuned!

edit the example in included as part of the demo window.

imgui_console_wip

from imgui.

JarrettBillingsley avatar JarrettBillingsley commented on May 14, 2024

Coool! :D

from imgui.

ocornut avatar ocornut commented on May 14, 2024

I have added the callback options now.

( It was messier than initially expected because the text input manipulates wchar internally and I wanted to provide UTF-8 to the user because that is what the user provides as input. With variable-size characters in UTF-8 have to convert thing like cursor-pos and selection range from character-to-byte and vice-versa, along with the text itself, and InputText() has a bunch of hoops already. I may want to clean that mess in the future. )

I have implemented a demo of completion in the console.
If you TAB It lists commands, input "h" and TAB it replace with "HELP" (the example replace casing in what you typed). If there are multiple matches it displays the matches and complete as much as possible, so "C" become "CL".

imgui_completion

I have not implemented history in the demo yet but the callback should be there (untested).

The console demo app is 170 lines which is starting to be a little too much but that is due to the fancy completion scheme. It might be time to move sample code to a separate location? hmm?

from imgui.

ocornut avatar ocornut commented on May 14, 2024

Closing this now. Will add a sample code for History using up/down later on but the feature is available.

from imgui.

ocornut avatar ocornut commented on May 14, 2024

fyi - the Console example now handles history with Up/Down arrows along with a command "History.

from imgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.