Skip to content

Commit 4e23805

Browse files
committed
Move TEXTBOX_INSETS back into the env
1 parent 536c23a commit 4e23805

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,
@@ -471,6 +470,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
471470
tracing::warn!("Widget::layout called with outstanding IME lock.");
472471
}
473472
let min_width = env.get(theme::WIDE_WIDGET_WIDTH);
473+
let textbox_insets = env.get(theme::TEXTBOX_INSETS);
474474

475475
self.placeholder.rebuild_if_needed(ctx.text(), env);
476476
let min_size = bc.constrain((min_width, 0.0));
@@ -488,7 +488,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
488488
let baseline_off = layout_baseline
489489
- (self.inner.wrapped().child_size().height
490490
- self.inner.wrapped().viewport_rect().height())
491-
+ TEXTBOX_INSETS.y1;
491+
+ textbox_insets.y1;
492492
ctx.set_baseline_offset(baseline_off);
493493
if self.scroll_to_selection_after_layout {
494494
self.scroll_to_selection_end();
@@ -513,6 +513,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
513513
let background_color = env.get(theme::BACKGROUND_LIGHT);
514514
let cursor_color = env.get(theme::CURSOR_COLOR);
515515
let border_width = env.get(theme::TEXTBOX_BORDER_WIDTH);
516+
let textbox_insets = env.get(theme::TEXTBOX_INSETS);
516517

517518
let is_focused = ctx.is_focused();
518519

@@ -537,7 +538,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
537538
ctx.with_save(|ctx| {
538539
ctx.clip(clip_rect);
539540
self.placeholder
540-
.draw(ctx, (TEXTBOX_INSETS.x0, TEXTBOX_INSETS.y0));
541+
.draw(ctx, (textbox_insets.x0, textbox_insets.y0));
541542
})
542543
}
543544

@@ -551,7 +552,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
551552
.borrow()
552553
.cursor_line_for_text_position(cursor_pos);
553554

554-
let padding_offset = Vec2::new(TEXTBOX_INSETS.x0, TEXTBOX_INSETS.y0);
555+
let padding_offset = Vec2::new(textbox_insets.x0, textbox_insets.y0);
555556

556557
let cursor = if data.is_empty() {
557558
cursor_line + padding_offset

0 commit comments

Comments
 (0)