IntoWidgetList

Fixes #182
This commit is contained in:
Jonathan Johnson 2024-10-16 15:39:01 -07:00
parent 5b928327dc
commit 02e60e1049
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
3 changed files with 43 additions and 6 deletions

View file

@ -47,6 +47,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
current outer size.
- `Graphics::draw_texture` and `Graphics::draw_textured_shape` now both accept
an opactiy parameter controlling how opaque the texture should be rendered at.
- `MakeWigetList` has had some of its functions moved to a new trait:
`IntoWidgetList`. A blanket implementation of `MakeWidgetList` is provided
for types that implement `IntoWidgetList`. In general, compilation errors
related to this change can be fixed by importing `IntoWidgetList`.
- `MakeWidgetList::into_rows` -> `IntoWidgetList::into_rows`
- `MakeWidgetList::into_columns` -> `IntoWidgetList::into_columns`
- `MakeWidgetList::into_layers` -> `IntoWidgetList::into_layers`
- `MakeWidgetList::into_wrap` -> `IntoWidgetList::into_wrap`
- `MakeWidgetList::into_list` -> `IntoWidgetList::into_list`
### Changed

View file

@ -2,7 +2,7 @@ use std::path::PathBuf;
use cushy::dialog::{FilePicker, PickFile};
use cushy::value::{Destination, Dynamic, Source};
use cushy::widget::{MakeWidget, MakeWidgetList};
use cushy::widget::{IntoWidgetList, MakeWidget};
use cushy::widgets::button::ButtonClick;
use cushy::widgets::checkbox::Checkable;
use cushy::widgets::layers::Modal;

View file

@ -2395,37 +2395,64 @@ pub trait MakeWidgetList: Sized {
list.push(widget);
list
}
}
/// A type that can be converted to a `Value<WidgetList>`.
pub trait IntoWidgetList: Sized {
/// Returns this list of widgets as a `Value<WidgetList>`.
fn into_widget_list(self) -> Value<WidgetList>;
/// Returns `self` as a vertical [`Stack`] of rows.
#[must_use]
fn into_rows(self) -> Stack {
Stack::rows(self.make_widget_list())
Stack::rows(self.into_widget_list())
}
/// Returns `self` as a horizontal [`Stack`] of columns.
#[must_use]
fn into_columns(self) -> Stack {
Stack::columns(self.make_widget_list())
Stack::columns(self.into_widget_list())
}
/// Returns `self` as [`Layers`], with the widgets being stacked in the Z
/// direction.
#[must_use]
fn into_layers(self) -> Layers {
Layers::new(self.make_widget_list())
Layers::new(self.into_widget_list())
}
/// Returns a [`Wrap`] that lays the children out horizontally, wrapping
/// into additional rows as needed.
#[must_use]
fn into_wrap(self) -> Wrap {
Wrap::new(self.make_widget_list())
Wrap::new(self.into_widget_list())
}
/// Returns `self` as an unordered [`List`].
#[must_use]
fn into_list(self) -> List {
List::new(self.make_widget_list())
List::new(self.into_widget_list())
}
}
impl<T> IntoWidgetList for T
where
T: MakeWidgetList,
{
fn into_widget_list(self) -> Value<WidgetList> {
Value::Constant(self.make_widget_list())
}
}
impl IntoWidgetList for Dynamic<WidgetList> {
fn into_widget_list(self) -> Value<WidgetList> {
Value::Dynamic(self)
}
}
impl IntoWidgetList for Value<WidgetList> {
fn into_widget_list(self) -> Value<WidgetList> {
self
}
}