how to set a fixed size for egui::TextEdit::multiline? #3423
-
|
Im trying to make a TextEdit area that is scrollable in my gui but i cant find any thing in the docs for setting a height and width of TextEdit. I tried to use a Grid to try add a fixed_size but i think its the wrong tool for the job so the question is. Is there a way to set a fixed_size for TextEdit? here is the relevant code: |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
|
I had to face the same issue and found out, that there is no good solution. Either you resize your font (the height of your TextEdit is determined by its font height) or you create a new window that creates a fixed frame. let fixed_size = vec2(200.0, 100.0);
ui.style_mut().visuals.window_shadow = Shadow::NONE;
ctx.set_style(ui.style().clone());
Window::new("")
.hscroll(true)
.movable(false)
.open(&mut true)
.current_pos(ui.next_widget_position())
.fixed_size(fixed_size)
.resizable(false)
.title_bar(false)
.vscroll(true)
.show(ctx, |ui| {
ui.add(TextEdit::multiline(&mut "my lines\n".repeat(100)));
}); It is really weird, that the normal window allows this TextEdit to go outside the frame and all of that stuff. Functions like max_height etc. do not seem to work either. |
Beta Was this translation helpful? Give feedback.
-
|
For a similar problem I used the following line to insert the sized multiline: |
Beta Was this translation helpful? Give feedback.
-
|
Just put it in ScrollArea |
Beta Was this translation helpful? Give feedback.
-
|
For setting the width of a TextEdit, |
Beta Was this translation helpful? Give feedback.
For setting the width of a TextEdit,
egui::TextEdit::desired_widthseems to work. (so for example for a textedit that takes up just the space of its text,TextEdit::singleline(text).desired_width(0.0).clip_text(false).show()works)This of course affects the minimum, and not the maximum size. For the latter, you can use the
add_sizedmethod as described here previously.