Added missing to_ variants

This commit is contained in:
Jonathan Johnson 2024-08-28 07:42:11 -07:00
parent 20366698a6
commit 53d3c58cbb
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
2 changed files with 30 additions and 0 deletions

View file

@ -28,6 +28,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`ContextFreeComponent::probe()` and `ContextFreeComponent::probe_wrapping()` `ContextFreeComponent::probe()` and `ContextFreeComponent::probe_wrapping()`
provide an easy interface for creating probes from components. 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) ## v0.4.0 (2024-08-20)

View file

@ -1206,11 +1206,27 @@ pub trait MakeWidget: Sized {
Button::new(self) 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. /// Returns this widget as the label of a Checkbox.
fn into_checkbox(self, value: impl IntoDynamic<CheckboxState>) -> Checkbox { fn into_checkbox(self, value: impl IntoDynamic<CheckboxState>) -> Checkbox {
value.into_checkbox(self) value.into_checkbox(self)
} }
/// Returns this widget as the label of a Checkbox.
fn to_checkbox(&self, value: impl IntoDynamic<CheckboxState>) -> Checkbox
where
Self: Clone,
{
self.clone().into_checkbox(value)
}
/// Aligns `self` to the center vertically and horizontally. /// Aligns `self` to the center vertically and horizontally.
#[must_use] #[must_use]
fn centered(self) -> Align { fn centered(self) -> Align {
@ -1589,6 +1605,14 @@ impl WidgetInstance {
} }
self.data.enabled.get() self.data.enabled.get()
} }
/// Returns a new window containing `self` as the root widget.
pub fn to_window(&self) -> Window<Self>
where
Self: Clone,
{
self.clone().into_window()
}
} }
impl AsRef<WidgetId> for WidgetInstance { impl AsRef<WidgetId> for WidgetInstance {