Skip to content

Commit fb684ef

Browse files
committed
Move TEXTBOX_INSETS back into the env
1 parent eec8ce8 commit fb684ef

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

druid/src/theme.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub(crate) fn add_to_env(env: Env) -> Env {
136136
.adding(BORDERED_WIDGET_HEIGHT, 24.0)
137137
.adding(TEXTBOX_BORDER_RADIUS, 2.)
138138
.adding(TEXTBOX_BORDER_WIDTH, 1.)
139-
.adding(TEXTBOX_INSETS, Insets::new(4.0, 2.0, 4.0, 4.0))
139+
.adding(TEXTBOX_INSETS, Insets::new(4.0, 4.0, 4.0, 4.0))
140140
.adding(SCROLLBAR_COLOR, Color::rgb8(0xff, 0xff, 0xff))
141141
.adding(SCROLLBAR_BORDER_COLOR, Color::rgb8(0x77, 0x77, 0x77))
142142
.adding(SCROLLBAR_MAX_OPACITY, 0.7)

druid/src/widget/textbox.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use crate::{
2626
theme, Color, FontDescriptor, KeyOrValue, Point, Rect, TextAlignment, TimerToken, Vec2,
2727
};
2828

29-
const TEXTBOX_INSETS: Insets = Insets::new(4.0, 2.0, 4.0, 2.0);
3029
const CURSOR_BLINK_DURATION: Duration = Duration::from_millis(500);
3130
const MAC_OR_LINUX: bool = cfg!(any(target_os = "macos", target_os = "linux"));
3231

@@ -73,7 +72,7 @@ impl<T: EditableText + TextStorage> TextBox<T> {
7372
let mut scroll = Scroll::new(TextComponent::default()).content_must_fill(true);
7473
scroll.set_enabled_scrollbars(crate::scroll_component::ScrollbarsEnabled::None);
7574
Self {
76-
inner: Padding::new(TEXTBOX_INSETS, scroll),
75+
inner: Padding::new(theme::TEXTBOX_INSETS, scroll),
7776
scroll_to_selection_after_layout: false,
7877
placeholder,
7978
multiline: false,
@@ -474,6 +473,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
474473
tracing::warn!("Widget::layout called with outstanding IME lock.");
475474
}
476475
let min_width = env.get(theme::WIDE_WIDGET_WIDTH);
476+
let textbox_insets = env.get(theme::TEXTBOX_INSETS);
477477

478478
self.placeholder.rebuild_if_needed(ctx.text(), env);
479479
let min_size = bc.constrain((min_width, 0.0));
@@ -491,7 +491,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
491491
let baseline_off = layout_baseline
492492
- (self.inner.wrapped().child_size().height
493493
- self.inner.wrapped().viewport_rect().height())
494-
+ TEXTBOX_INSETS.y1;
494+
+ textbox_insets.y1;
495495
ctx.set_baseline_offset(baseline_off);
496496
if self.scroll_to_selection_after_layout {
497497
self.scroll_to_selection_end();
@@ -516,6 +516,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
516516
let background_color = env.get(theme::BACKGROUND_LIGHT);
517517
let cursor_color = env.get(theme::CURSOR_COLOR);
518518
let border_width = env.get(theme::TEXTBOX_BORDER_WIDTH);
519+
let textbox_insets = env.get(theme::TEXTBOX_INSETS);
519520

520521
let is_focused = ctx.is_focused();
521522

@@ -540,7 +541,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
540541
ctx.with_save(|ctx| {
541542
ctx.clip(clip_rect);
542543
self.placeholder
543-
.draw(ctx, (TEXTBOX_INSETS.x0, TEXTBOX_INSETS.y0));
544+
.draw(ctx, (textbox_insets.x0, textbox_insets.y0));
544545
})
545546
}
546547

@@ -554,7 +555,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
554555
.borrow()
555556
.cursor_line_for_text_position(cursor_pos);
556557

557-
let padding_offset = Vec2::new(TEXTBOX_INSETS.x0, TEXTBOX_INSETS.y0);
558+
let padding_offset = Vec2::new(textbox_insets.x0, textbox_insets.y0);
558559

559560
let cursor = if data.is_empty() {
560561
cursor_line + padding_offset

0 commit comments

Comments
 (0)