Skip to content

Commit

Permalink
Changelog and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyr committed Mar 10, 2021
1 parent df6ec41 commit a5d39db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
41 changes: 13 additions & 28 deletions druid/src/widget/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -90,10 +90,12 @@ impl<T: EditableText + TextStorage> TextBox<T> {
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
}
Expand All @@ -108,7 +110,7 @@ impl<T: EditableText + TextStorage> TextBox<T> {
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
}
Expand Down Expand Up @@ -274,23 +276,6 @@ impl<T> TextBox<T> {
}
}

impl<T> TextBox<T> {
///// 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<T> TextBox<T> {
//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
Expand All @@ -300,15 +285,15 @@ impl<T> TextBox<T> {
/// Using this correctly is difficult; please see the [`TextComponent`]
/// docs for more information.
pub fn text(&self) -> &TextComponent<T> {
self.inner.child().child()
self.inner.wrapped().child()
}

/// An immutable reference to the inner [`TextComponent`].
///
/// Using this correctly is difficult; please see the [`TextComponent`]
/// docs for more information.
pub fn text_mut(&mut self) -> &mut TextComponent<T> {
self.inner.child_mut().child_mut()
self.inner.wrapped_mut().child_mut()
}

fn reset_cursor_blink(&mut self, token: TimerToken) {
Expand Down Expand Up @@ -352,11 +337,11 @@ impl<T: TextStorage + EditableText> TextBox<T> {

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);
}
}
}
Expand Down Expand Up @@ -511,8 +496,8 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {

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 {
Expand Down Expand Up @@ -575,7 +560,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {
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.);
}
Expand Down

0 comments on commit a5d39db

Please sign in to comment.