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

Terminal/In Game Console Widget #319

Open
Pebaz opened this issue Apr 18, 2021 · 7 comments
Open

Terminal/In Game Console Widget #319

Pebaz opened this issue Apr 18, 2021 · 7 comments
Labels
feature New feature or request

Comments

@Pebaz
Copy link

Pebaz commented Apr 18, 2021

Is your feature request related to a problem? Please describe.
I'd like to build an in game console but there does not seem to be a way to do this using the multiline text edit.

Describe the solution you'd like
I'd like a widget that has a way to scroll the cursor to the last character in the text box. Additionally, it would be amazing to be able to color specific text blocks in the output for errors and logging, etc.

Describe alternatives you've considered
I tried to use a multiline text box but when the buffer is modified (to add the prompt), the cursor stays behind the new text, and there is no way to move the cursor programmatically that I could find.

Additional context

let mut terminal_buffer = String::with_capacity(500);
ui.text_edit_multiline(&mut terminal_buffer);

// Later at the end of the frame:
if <there are two newlines in a row, signaling the user wants to process the command> {
    let command = <scrape out from the last ">>> " to the 2 newlines>;
    // process command
    terminal_buffer += &String::from(">>> ");  // Add new prompt <--- This is where the cursor gets left behind
}

Is there a way to move the cursor to the end when the buffer is modified?

@Pebaz Pebaz added the feature New feature or request label Apr 18, 2021
@kotx
Copy link

kotx commented Aug 11, 2021

Maybe try using one multiline TextEdit for scrollback and one singleline TextEdit for input?

@Pebaz
Copy link
Author

Pebaz commented Aug 11, 2021

The hard part here is making the multiline widget scroll down to the most recent line added. As currently implemented, there's no way to scroll down to the most recent line.

@kotx
Copy link

kotx commented Aug 11, 2021

The hard part here is making the multiline widget scroll down to the most recent line added. As currently implemented, there's no way to scroll down to the most recent line.

Yeah, I'm trying to figure that out too. Currently this is what I have, but resizing the window doesn't work (it just slides back), so the scrollbar is never shown:

ScrollArea::auto_sized().show(ui, |ui| {
    ui.text_edit_multiline(...);
    ui.scroll_to_cursor(Align::BOTTOM);
});

@Pebaz
Copy link
Author

Pebaz commented Aug 11, 2021 via email

@kotx
Copy link

kotx commented Aug 11, 2021

It probably doesn't, because it just expands endlessly until I figure out how to make it resize properly :P

@kotx
Copy link

kotx commented Aug 12, 2021

It probably doesn't, because it just expands endlessly until I figure out how to make it resize properly :P

Seems this is a known issue:

// ui.heading("Some additional text here, that should also be visible"); // this works, but messes with the resizing a bit

@pm100
Copy link
Contributor

pm100 commented Jul 7, 2024

I have built a console window that you describe, its got complicated pretty fast. I was wondering about making it a free standing widget.

Trying to make it scroll whole lines rather than stoppig with half a line shown

I thought about 2 (or even three) widgets: history, prompt (static text) and command line. Problem is that you would not be able to mouse highlight the history and command line (for copy), which would be kind of odd.

You dont want that scroll to last all the time, becuase it messes with people scrolling back to look at the history

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

No branches or pull requests

3 participants