Skip to content

TextEdit: Change margin property to egui::Margin type #3993

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

5 changes: 4 additions & 1 deletion crates/egui/src/widgets/drag_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,10 @@ impl<'a> Widget for DragValue<'a> {
.clip_text(false)
.horizontal_align(ui.layout().horizontal_align())
.vertical_align(ui.layout().vertical_align())
.margin(ui.spacing().button_padding)
.margin(Margin::symmetric(
ui.spacing().button_padding.x,
ui.spacing().button_padding.y,
))
.min_size(ui.spacing().interact_size)
.id(id)
.desired_width(ui.spacing().interact_size.x)
Expand Down
16 changes: 9 additions & 7 deletions crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct TextEdit<'t> {
layouter: Option<&'t mut dyn FnMut(&Ui, &str, f32) -> Arc<Galley>>,
password: bool,
frame: bool,
margin: Vec2,
margin: Margin,
multiline: bool,
interactive: bool,
desired_width: Option<f32>,
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'t> TextEdit<'t> {
layouter: None,
password: false,
frame: true,
margin: vec2(4.0, 2.0),
margin: Margin::symmetric(4.0, 2.0),
multiline: true,
interactive: true,
desired_width: None,
Expand Down Expand Up @@ -381,13 +381,14 @@ impl<'t> TextEdit<'t> {
let where_to_put_background = ui.painter().add(Shape::Noop);

let margin = self.margin;
let max_rect = ui.available_rect_before_wrap().shrink2(margin);
let available = ui.available_rect_before_wrap();
let max_rect = margin.shrink_rect(available);
let mut content_ui = ui.child_ui(max_rect, *ui.layout());

let mut output = self.show_content(&mut content_ui);

let id = output.response.id;
let frame_rect = output.response.rect.expand2(margin);
let frame_rect = margin.expand_rect(output.response.rect);
ui.allocate_space(frame_rect.size());
if interactive {
output.response |= ui.interact(frame_rect, id, Sense::click());
Expand Down Expand Up @@ -470,7 +471,7 @@ impl<'t> TextEdit<'t> {
available_width
} else {
desired_width.min(available_width)
} - margin.x * 2.0;
} - margin.sum().x;

let font_id_clone = font_id.clone();
let mut default_layouter = move |ui: &Ui, text: &str, wrap_width: f32| {
Expand All @@ -493,8 +494,9 @@ impl<'t> TextEdit<'t> {
galley.size().x.max(wrap_width)
};
let desired_height = (desired_height_rows.at_least(1) as f32) * row_height;
let desired_size = vec2(desired_width, galley.size().y.max(desired_height))
.at_least(min_size - margin * 2.0);
let at_least = min_size - margin.sum();
let desired_size =
vec2(desired_width, galley.size().y.max(desired_height)).at_least(at_least);

let (auto_id, rect) = ui.allocate_space(desired_size);

Expand Down