emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
20.97k stars 1.52k forks source link

Terminal/In Game Console Widget #319

Open Pebaz opened 3 years ago

Pebaz commented 3 years ago

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?

kotx commented 2 years ago

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

Pebaz commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Oh cool I'll try that and see if that works better than what I'm doing now.

On Wed, Aug 11, 2021, 5:48 PM Kot @.***> wrote:

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); });

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/emilk/egui/issues/319#issuecomment-897234793, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGV4FZ7QBMP74SEP6WCBHHLT4MD6BANCNFSM43EMA6NA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

kotx commented 2 years ago

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

kotx commented 2 years ago

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: https://github.com/emilk/egui/blob/9603bb4f85fbad328bce527ff0850fbc925393d6/egui_demo_lib/src/apps/demo/tests.rs#L424

pm100 commented 3 weeks ago

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