Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions crates/egui/src/widgets/button.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
widgets, Align, Color32, CornerRadius, Image, NumExt, Rect, Response, Sense, Stroke, TextStyle,
TextWrapMode, Ui, Vec2, Widget, WidgetInfo, WidgetText, WidgetType,
widgets, Align, Color32, CornerRadius, FontSelection, Image, NumExt, Rect, Response, Sense,
Stroke, TextStyle, TextWrapMode, Ui, Vec2, Widget, WidgetInfo, WidgetText, WidgetType,
};

/// Clickable button with text.
Expand Down Expand Up @@ -224,6 +224,16 @@ impl Widget for Button<'_> {

let frame = frame.unwrap_or_else(|| ui.visuals().button_frame);

let default_font_height = || {
let font_selection = FontSelection::default();
let font_id = font_selection.resolve(ui.style());
ui.fonts(|f| f.row_height(&font_id))
};

let text_font_height = ui
.fonts(|fonts| text.as_ref().map(|wt| wt.font_height(fonts, ui.style())))
.unwrap_or_else(default_font_height);

let mut button_padding = if frame {
ui.spacing().button_padding
} else {
Expand All @@ -233,11 +243,17 @@ impl Widget for Button<'_> {
button_padding.y = 0.0;
}

let space_available_for_image = if let Some(text) = &text {
let (space_available_for_image, right_text_font_height) = if let Some(text) = &text {
let font_height = ui.fonts(|fonts| text.font_height(fonts, ui.style()));
Vec2::splat(font_height) // Reasonable?
(
Vec2::splat(font_height), // Reasonable?
font_height,
)
} else {
ui.available_size() - 2.0 * button_padding
(
ui.available_size() - 2.0 * button_padding,
default_font_height(),
)
};

let image_size = if let Some(image) = &image {
Expand Down Expand Up @@ -283,11 +299,14 @@ impl Widget for Button<'_> {
}
if let Some(galley) = &galley {
desired_size.x += galley.size().x;
desired_size.y = desired_size.y.max(galley.size().y);
desired_size.y = desired_size.y.max(galley.size().y).max(text_font_height);
}
if let Some(right_galley) = &right_galley {
desired_size.x += gap_before_right_text + right_galley.size().x;
desired_size.y = desired_size.y.max(right_galley.size().y);
desired_size.y = desired_size
.y
.max(right_galley.size().y)
.max(right_text_font_height);
}
desired_size += 2.0 * button_padding;
if !small {
Expand Down
4 changes: 3 additions & 1 deletion crates/egui/src/widgets/drag_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,9 @@ impl Widget for DragValue<'_> {
.margin(ui.spacing().button_padding)
.min_size(ui.spacing().interact_size)
.id(id)
.desired_width(ui.spacing().interact_size.x)
.desired_width(
ui.spacing().interact_size.x - 2.0 * ui.spacing().button_padding.x,
)
.font(text_style),
);

Expand Down
11 changes: 2 additions & 9 deletions crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,18 +426,11 @@ impl TextEdit<'_> {
let background_color = self
.background_color
.unwrap_or(ui.visuals().extreme_bg_color);
let margin = self.margin;
let mut output = self.show_content(ui);

// TODO(emilk): return full outer_rect in `TextEditOutput`.
// Can't do it now because this fix is ging into a patch release.
let outer_rect = output.response.rect;
let inner_rect = outer_rect - margin;
output.response.rect = inner_rect;
let output = self.show_content(ui);

if frame {
let visuals = ui.style().interact(&output.response);
let frame_rect = outer_rect.expand(visuals.expansion);
let frame_rect = output.response.rect.expand(visuals.expansion);
Comment on lines -430 to +433
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention this as a breaking change in the changelog

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that something I should do? And where? CHANGELOG.md?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sorry, I was just commenting this for myself, I'll update the title / description accordingly when merging the PR

let shape = if is_mutable {
if output.response.has_focus() {
epaint::RectShape::new(
Expand Down
Loading