diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a1dbebc3..8857a03e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `ContextFreeComponent::probe()` and `ContextFreeComponent::probe_wrapping()` provide an easy interface for creating probes from components. +- These `to_*` variations of existing `into_*` functions have been added to + avoid some cases where cloning might be needed. + + - `MakeWidget::to_button()` + - `MakeWidget::to_checkbox()` + - `WidgetInstance::to_window()` ## v0.4.0 (2024-08-20) diff --git a/src/widget.rs b/src/widget.rs index 4f2cbcd2b..15ca25c32 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -1206,11 +1206,27 @@ pub trait MakeWidget: Sized { Button::new(self) } + /// Returns this widget as the contents of a clickable button. + fn to_button(&self) -> Button + where + Self: Clone, + { + self.clone().into_button() + } + /// Returns this widget as the label of a Checkbox. fn into_checkbox(self, value: impl IntoDynamic) -> Checkbox { value.into_checkbox(self) } + /// Returns this widget as the label of a Checkbox. + fn to_checkbox(&self, value: impl IntoDynamic) -> Checkbox + where + Self: Clone, + { + self.clone().into_checkbox(value) + } + /// Aligns `self` to the center vertically and horizontally. #[must_use] fn centered(self) -> Align { @@ -1589,6 +1605,14 @@ impl WidgetInstance { } self.data.enabled.get() } + + /// Returns a new window containing `self` as the root widget. + pub fn to_window(&self) -> Window + where + Self: Clone, + { + self.clone().into_window() + } } impl AsRef for WidgetInstance {