Skip to content

Commit

Permalink
Added missing to_ variants
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Aug 28, 2024
1 parent 2036669 commit 53d3c58
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
24 changes: 24 additions & 0 deletions src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CheckboxState>) -> Checkbox {
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.
#[must_use]
fn centered(self) -> Align {
Expand Down Expand Up @@ -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<Self>
where
Self: Clone,
{
self.clone().into_window()
}
}

impl AsRef<WidgetId> for WidgetInstance {
Expand Down

0 comments on commit 53d3c58

Please sign in to comment.