Skip to content

Commit 8fa6b5a

Browse files
committed
fix baseline offset for sized widget
Baseline offset is relative to the bottom of a widget. Current code assume that the widget has exacltly the required height. For sized widgets, where there is more vertical space, the baseline is totally wrong. This patch series considers the additional space to adjust the baseline offset. Signed-off-by: Dietmar Maurer <[email protected]>
1 parent d5485ee commit 8fa6b5a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

druid/src/widget/button.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,16 @@ impl<T: Data> Widget<T> for Button<T> {
155155
// HACK: to make sure we look okay at default sizes when beside a textbox,
156156
// we make sure we will have at least the same height as the default textbox.
157157
let min_height = env.get(theme::BORDERED_WIDGET_HEIGHT);
158-
let baseline = self.label.baseline_offset();
159-
ctx.set_baseline_offset(baseline + LABEL_INSETS.y1);
160158

161159
let button_size = bc.constrain(Size::new(
162160
self.label_size.width + padding.width,
163161
(self.label_size.height + padding.height).max(min_height),
164162
));
163+
164+
let extra_height = (button_size.height - self.label_size.height).max(0.0);
165+
let baseline = self.label.baseline_offset() + extra_height / 2.0;
166+
ctx.set_baseline_offset(baseline);
167+
165168
trace!("Computed button size: {}", button_size);
166169
button_size
167170
}

druid/src/widget/label.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,11 @@ impl<T: TextStorage> Widget<T> for RawLabel<T> {
615615
self.layout.rebuild_if_needed(ctx.text(), env);
616616

617617
let text_metrics = self.layout.layout_metrics();
618-
ctx.set_baseline_offset(text_metrics.size.height - text_metrics.first_baseline);
619618
let size = bc.constrain(Size::new(
620619
text_metrics.size.width + 2. * LABEL_X_PADDING,
621620
text_metrics.size.height,
622621
));
622+
ctx.set_baseline_offset(size.height - text_metrics.first_baseline);
623623
trace!("Computed size: {}", size);
624624
size
625625
}

0 commit comments

Comments
 (0)