Skip to content

Commit

Permalink
Restore TextArea size fix, conditional on !clip_text
Browse files Browse the repository at this point in the history
  • Loading branch information
IaVashik committed Jan 27, 2025
1 parent 903a88d commit 19082c4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use emath::Rect;
use epaint::text::{cursor::CCursor, Galley, LayoutJob};

use crate::{
Expand Down Expand Up @@ -562,7 +563,7 @@ impl TextEdit<'_> {
Sense::hover()
};
let mut response = ui.interact(outer_rect, id, sense);
response.intrinsic_size = Some(Vec2::new(desired_width, desired_outer_size.y));
response.intrinsic_size = Some(Vec2::new(desired_width, desired_outer_size.y)); // HERE!!!

// Don't sent `OutputEvent::Clicked` when a user presses the space bar
response.flags -= response::Flags::FAKE_PRIMARY_CLICKED;
Expand Down Expand Up @@ -722,6 +723,19 @@ impl TextEdit<'_> {
}
}

if !clip_text {
// Allocate additional space if edits were made this frame that changed the size. This is important so that,
// if there's a ScrollArea, it can properly scroll to the cursor.
// Condition `!clip_text` is important to avoid breaking layout for `TextEdit::singleline` (PR #5640)
let extra_size = galley.size() - rect.size();
if extra_size.x > 0.0 || extra_size.y > 0.0 {
ui.allocate_rect(
Rect::from_min_size(outer_rect.max, extra_size),
Sense::hover(),
);
}
}

painter.galley(galley_pos, galley.clone(), text_color);

if has_focus {
Expand Down

0 comments on commit 19082c4

Please sign in to comment.