Skip to content

Commit

Permalink
Fixup last renames from text region
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Nov 21, 2024
1 parent f4765ac commit 9fbe6ab
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion masonry/examples/grid_masonry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn grid_button(params: GridParams) -> Button {
}

fn main() {
let label = SizedBox::new(Prose::from_text_region(
let label = SizedBox::new(Prose::from_text_area(
TextArea::new_immutable("Change spacing by right and left clicking on the buttons")
.with_style(StyleProperty::FontSize(14.0))
.with_alignment(Alignment::Middle),
Expand Down
4 changes: 2 additions & 2 deletions masonry/examples/to_do_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl AppDriver for Driver {
let mut first_row = first_row.downcast::<Flex>();
let mut textbox = Flex::child_mut(&mut first_row, 0).unwrap();
let mut textbox = textbox.downcast::<Textbox>();
let mut text_region = Textbox::text_mut(&mut textbox);
TextArea::reset_text(&mut text_region, "");
let mut text_area = Textbox::text_mut(&mut textbox);
TextArea::reset_text(&mut text_area, "");
}
Action::TextChanged(new_text) => {
self.next_task = new_text.clone();
Expand Down
14 changes: 7 additions & 7 deletions masonry/src/widget/prose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ pub struct Prose {
impl Prose {
/// Create a new `Prose` with the given text.
///
/// To use non-default text properties, use [`from_text_region`](Self::from_text_region) instead.
/// To use non-default text properties, use [`from_text_area`](Self::from_text_area) instead.
pub fn new(text: &str) -> Self {
Self::from_text_region(TextArea::new_immutable(text))
Self::from_text_area(TextArea::new_immutable(text))
}

/// Create a new `Prose` from a styled text area.
pub fn from_text_region(text: TextArea<false>) -> Self {
pub fn from_text_area(text: TextArea<false>) -> Self {
let text = text.with_padding_if_default(PROSE_PADDING);
Self {
text: WidgetPod::new(text),
Expand All @@ -62,7 +62,7 @@ impl Prose {
/// Create a new `Prose` from a styled text area in a [`WidgetPod`].
///
/// Note that the default padding used for prose will not be applied.
pub fn from_text_region_pod(text: WidgetPod<TextArea<false>>) -> Self {
pub fn from_text_area_pod(text: WidgetPod<TextArea<false>>) -> Self {
Self { text, clip: false }
}

Expand All @@ -77,8 +77,8 @@ impl Prose {
self
}

/// Read the underlying text region. Useful for getting its ID.
// This is a bit of a hack, to work around `from_text_region_pod` not being
/// Read the underlying text area. Useful for getting its ID.
// This is a bit of a hack, to work around `from_text_area_pod` not being
// able to set padding.
pub fn region_pod(&self) -> &WidgetPod<TextArea<false>> {
&self.text
Expand Down Expand Up @@ -171,7 +171,7 @@ mod tests {
fn prose_alignment_flex() {
fn base_prose(alignment: Alignment) -> Prose {
// Trailing whitespace is displayed when laying out prose.
Prose::from_text_region(
Prose::from_text_area(
TextArea::new_immutable("Hello ")
.with_style(StyleProperty::FontSize(10.0))
.with_alignment(alignment)
Expand Down
16 changes: 8 additions & 8 deletions masonry/src/widget/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const TEXTBOX_MARGIN: Padding = Padding::horizontal(2.0);
///
/// This widget itself does not emit any actions.
/// However, the child widget will do so, as it is user editable.
/// The ID of the child can be accessed using [`region_pod`](Self::region_pod).
/// The ID of the child can be accessed using [`area_pod`](Self::area_pod).
///
/// At runtime, most properties of the text will be set using [`text_mut`](Self::text_mut).
/// This is because `Textbox` largely serves as a wrapper around a [`TextArea`].
Expand All @@ -47,13 +47,13 @@ pub struct Textbox {
impl Textbox {
/// Create a new `Prose` with the given text.
///
/// To use non-default text properties, use [`from_text_region`](Self::from_text_region) instead.
/// To use non-default text properties, use [`from_area_region`](Self::from_text_area) instead.
pub fn new(text: &str) -> Self {
Self::from_text_region(TextArea::new_editable(text))
Self::from_text_area(TextArea::new_editable(text))
}

/// Create a new `Prose` from a styled text area.
pub fn from_text_region(text: TextArea<true>) -> Self {
pub fn from_text_area(text: TextArea<true>) -> Self {
let text = text.with_padding_if_default(TEXTBOX_PADDING);
Self {
text: WidgetPod::new(text),
Expand All @@ -64,7 +64,7 @@ impl Textbox {
/// Create a new `Prose` from a styled text area in a [`WidgetPod`].
///
/// Note that the default padding used for prose will not apply.
pub fn from_text_region_pod(text: WidgetPod<TextArea<true>>) -> Self {
pub fn from_text_area_pod(text: WidgetPod<TextArea<true>>) -> Self {
Self { text, clip: false }
}

Expand All @@ -79,10 +79,10 @@ impl Textbox {
self
}

/// Read the underlying text region.
/// Read the underlying text area.
///
/// Useful for getting its ID, as most actions from the textbox will be sent by the child.
pub fn region_pod(&self) -> &WidgetPod<TextArea<true>> {
pub fn area_pod(&self) -> &WidgetPod<TextArea<true>> {
&self.text
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ mod tests {
fn prose_alignment_flex() {
fn base_prose(alignment: Alignment) -> Prose {
// Trailing whitespace is displayed when laying out prose.
Prose::from_text_region(
Prose::from_text_area(
TextArea::new_immutable("Hello ")
.with_style(StyleProperty::FontSize(10.0))
.with_alignment(alignment)
Expand Down
4 changes: 2 additions & 2 deletions xilem/src/view/prose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ impl<State, Action> View<State, Action, ViewCtx> for Prose {
type ViewState = ();

fn build(&self, ctx: &mut ViewCtx) -> (Self::Element, Self::ViewState) {
let text_region = widget::TextArea::new_immutable(&self.content)
let text_area = widget::TextArea::new_immutable(&self.content)
.with_brush(self.text_brush.clone())
.with_alignment(self.alignment)
.with_style(StyleProperty::FontSize(self.text_size))
.with_word_wrap(self.line_break_mode == LineBreaking::WordWrap);
let widget_pod = ctx.new_pod(
widget::Prose::from_text_region(text_region)
widget::Prose::from_text_area(text_area)
.with_clip(line_break_clips(self.line_break_mode)),
);
(widget_pod, ())
Expand Down
6 changes: 3 additions & 3 deletions xilem/src/view/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ impl<State: 'static, Action: 'static> View<State, Action, ViewCtx> for Textbox<S

fn build(&self, ctx: &mut ViewCtx) -> (Self::Element, Self::ViewState) {
// TODO: Maybe we want a shared TextArea View?
let text_region = widget::TextArea::new_editable(&self.contents)
let text_area = widget::TextArea::new_editable(&self.contents)
.with_brush(self.text_brush.clone())
.with_alignment(self.alignment);
let textbox = widget::Textbox::from_text_region(text_region);
let textbox = widget::Textbox::from_text_area(text_area);

// Ensure that the actions from the *inner* TextArea get routed correctly.
let id = textbox.region_pod().id();
let id = textbox.area_pod().id();
ctx.record_action(id);
let widget_pod = ctx.new_pod(textbox);
(widget_pod, ())
Expand Down

0 comments on commit 9fbe6ab

Please sign in to comment.