Skip to content

Commit

Permalink
Move TEXTBOX_INSETS back into the env
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyr committed Mar 18, 2021
1 parent 7cac723 commit e3fece3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion druid/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub(crate) fn add_to_env(env: Env) -> Env {
.adding(BORDERED_WIDGET_HEIGHT, 24.0)
.adding(TEXTBOX_BORDER_RADIUS, 2.)
.adding(TEXTBOX_BORDER_WIDTH, 1.)
.adding(TEXTBOX_INSETS, Insets::new(4.0, 2.0, 4.0, 4.0))
.adding(TEXTBOX_INSETS, Insets::new(4.0, 4.0, 4.0, 4.0))
.adding(SCROLLBAR_COLOR, Color::rgb8(0xff, 0xff, 0xff))
.adding(SCROLLBAR_BORDER_COLOR, Color::rgb8(0x77, 0x77, 0x77))
.adding(SCROLLBAR_MAX_OPACITY, 0.7)
Expand Down
11 changes: 6 additions & 5 deletions druid/src/widget/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use crate::{
theme, Color, FontDescriptor, KeyOrValue, Point, Rect, TextAlignment, TimerToken, Vec2,
};

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

Expand Down Expand Up @@ -73,7 +72,7 @@ impl<T: EditableText + TextStorage> TextBox<T> {
let mut scroll = Scroll::new(TextComponent::default()).content_must_fill(true);
scroll.set_enabled_scrollbars(crate::scroll_component::ScrollbarsEnabled::None);
Self {
inner: Padding::new(TEXTBOX_INSETS, scroll),
inner: Padding::new(theme::TEXTBOX_INSETS, scroll),
scroll_to_selection_after_layout: false,
placeholder,
multiline: false,
Expand Down Expand Up @@ -471,6 +470,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
tracing::warn!("Widget::layout called with outstanding IME lock.");
}
let min_width = env.get(theme::WIDE_WIDGET_WIDTH);
let textbox_insets = env.get(theme::TEXTBOX_INSETS);

self.placeholder.rebuild_if_needed(ctx.text(), env);
let min_size = bc.constrain((min_width, 0.0));
Expand All @@ -488,7 +488,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
let baseline_off = layout_baseline
- (self.inner.wrapped().child_size().height
- self.inner.wrapped().viewport_rect().height())
+ TEXTBOX_INSETS.y1;
+ textbox_insets.y1;
ctx.set_baseline_offset(baseline_off);
if self.scroll_to_selection_after_layout {
self.scroll_to_selection_end();
Expand All @@ -513,6 +513,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
let background_color = env.get(theme::BACKGROUND_LIGHT);
let cursor_color = env.get(theme::CURSOR_COLOR);
let border_width = env.get(theme::TEXTBOX_BORDER_WIDTH);
let textbox_insets = env.get(theme::TEXTBOX_INSETS);

let is_focused = ctx.is_focused();

Expand All @@ -537,7 +538,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
ctx.with_save(|ctx| {
ctx.clip(clip_rect);
self.placeholder
.draw(ctx, (TEXTBOX_INSETS.x0, TEXTBOX_INSETS.y0));
.draw(ctx, (textbox_insets.x0, textbox_insets.y0));
})
}

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

let padding_offset = Vec2::new(TEXTBOX_INSETS.x0, TEXTBOX_INSETS.y0);
let padding_offset = Vec2::new(textbox_insets.x0, textbox_insets.y0);

let cursor = if data.is_empty() {
cursor_line + padding_offset
Expand Down

0 comments on commit e3fece3

Please sign in to comment.