From a5d39db3b2eafe017e3cc47d798c9f276cd1bc26 Mon Sep 17 00:00:00 2001 From: Colin Rofls Date: Wed, 10 Mar 2021 14:38:11 -0500 Subject: [PATCH] Changelog and cleanup --- CHANGELOG.md | 3 +++ druid/src/widget/textbox.rs | 41 ++++++++++++------------------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5d18eb4d3..ad79d01280 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ You can find its changes [documented below](#070---2021-01-01). # Unreleased ### Highlights +- International text input support (IME) on macOS. ### Added - Add `scroll()` method in WidgetExt ([#1600] by [@totsteps]) @@ -22,6 +23,7 @@ You can find its changes [documented below](#070---2021-01-01). - Shell: windows implementation from content_insets ([#1592] by [@HoNile]) - Shell: IME API and macOS IME implementation ([#1619] by [@lord]) - Scroll::content_must_fill and a few other new Scroll methods ([#1635] by [@cmyr]) +- New `TextBox` widget with IME integration ([#1636] by [@cmyr]) ### Changed @@ -632,6 +634,7 @@ Last release without a changelog :( [#1619]: https://github.com/linebender/druid/pull/1619 [#1634]: https://github.com/linebender/druid/pull/1634 [#1635]: https://github.com/linebender/druid/pull/1635 +[#1636]: https://github.com/linebender/druid/pull/1636 [Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master [0.7.0]: https://github.com/linebender/druid/compare/v0.6.0...v0.7.0 diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index 316b176a86..82762b2f49 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -20,7 +20,7 @@ use crate::kurbo::Insets; use crate::piet::TextLayout as _; use crate::text::{EditableText, Selection, TextComponent, TextLayout, TextStorage}; use crate::widget::prelude::*; -use crate::widget::{Padding, Scroll}; +use crate::widget::{Padding, Scroll, WidgetWrapper}; use crate::{ theme, Color, FontDescriptor, KeyOrValue, Point, Rect, TextAlignment, TimerToken, Vec2, }; @@ -90,10 +90,12 @@ impl TextBox { pub fn multiline() -> Self { let mut this = TextBox::new(); this.inner - .child_mut() + .wrapped_mut() .set_enabled_scrollbars(crate::scroll_component::ScrollbarsEnabled::Both); this.text_mut().borrow_mut().set_accepts_newlines(true); - this.inner.child_mut().set_horizontal_scroll_enabled(false); + this.inner + .wrapped_mut() + .set_horizontal_scroll_enabled(false); this.multiline = true; this } @@ -108,7 +110,7 @@ impl TextBox { pub fn with_line_wrapping(mut self, wrap_lines: bool) -> Self { self.wrap_lines = wrap_lines; self.inner - .child_mut() + .wrapped_mut() .set_horizontal_scroll_enabled(!wrap_lines); self } @@ -274,23 +276,6 @@ impl TextBox { } } -impl TextBox { - ///// Set the textbox's selection. - //pub fn set_selection(&mut self, selection: Selection) { - //self.editor.set_selection(selection); - //} - - ///// Set the text and force the editor to update. - ///// - ///// This should be rarely needed; the main use-case would be if you need - ///// to manually set the text and then immediately do hit-testing or other - ///// tasks that rely on having an up-to-date text layout. - //pub fn force_rebuild(&mut self, text: T, factory: &mut PietText, env: &Env) { - //self.editor.set_text(text); - //self.editor.rebuild_if_needed(factory, env); - //} -} - impl TextBox { //FIXME: maybe a more restrictive API? some kind of `with_text` method that //takes a closure and makes sure we're locked, and then also notifies the platform @@ -300,7 +285,7 @@ impl TextBox { /// Using this correctly is difficult; please see the [`TextComponent`] /// docs for more information. pub fn text(&self) -> &TextComponent { - self.inner.child().child() + self.inner.wrapped().child() } /// An immutable reference to the inner [`TextComponent`]. @@ -308,7 +293,7 @@ impl TextBox { /// Using this correctly is difficult; please see the [`TextComponent`] /// docs for more information. pub fn text_mut(&mut self) -> &mut TextComponent { - self.inner.child_mut().child_mut() + self.inner.wrapped_mut().child_mut() } fn reset_cursor_blink(&mut self, token: TimerToken) { @@ -352,11 +337,11 @@ impl TextBox { fn scroll_to_selection_end(&mut self) { let rect = self.rect_for_selection_end(); - let view_rect = self.inner.child().viewport_rect(); + let view_rect = self.inner.wrapped().viewport_rect(); let is_visible = view_rect.contains(rect.origin()) && view_rect.contains(Point::new(rect.x1, rect.y1)); if !is_visible { - self.inner.child_mut().scroll_to(rect + SCROLL_TO_INSETS); + self.inner.wrapped_mut().scroll_to(rect + SCROLL_TO_INSETS); } } } @@ -511,8 +496,8 @@ impl Widget for TextBox { let layout_baseline = text_metrics.size.height - text_metrics.first_baseline; let baseline_off = layout_baseline - - (self.inner.child().child_size().height - - self.inner.child().viewport_rect().height()) + - (self.inner.wrapped().child_size().height + - self.inner.wrapped().viewport_rect().height()) + TEXTBOX_INSETS.y1; ctx.set_baseline_offset(baseline_off); if self.scroll_to_selection_after_layout { @@ -575,7 +560,7 @@ impl Widget for TextBox { let cursor = if data.is_empty() { cursor_line + padding_offset } else { - cursor_line + padding_offset - self.inner.child().offset() + cursor_line + padding_offset - self.inner.wrapped().offset() }; ctx.stroke(cursor, &cursor_color, 1.); }