abort_handles: Rc<RefCell<HashMap<usize, AbortHandle>>>,
}
+impl Default for AsyncPool {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl AsyncPool {
/// Create a new instance.
pub fn new() -> Self {
let observer =
IntersectionObserver::new(observer_closure.as_ref().unchecked_ref()).unwrap_throw();
- observer.observe(&el);
+ observer.observe(el);
Self {
_observer_closure: observer_closure, // keep it alive
if let Ok(error) = ::wasm_bindgen::JsCast::dyn_into::<js_sys::Error>(js_err) {
format!("{}", error.message())
} else {
- format!("unknown js error: error is no ERROR object")
+ "unknown js error: error is no ERROR object".to_string()
}
}
init.method("GET");
init.signal(Some(&abort.signal()));
- let request =
- web_sys::Request::new_with_str_and_init(url, &init).map_err(|err| convert_js_error(err))?;
+ let request = web_sys::Request::new_with_str_and_init(url, &init).map_err(convert_js_error)?;
- let window = web_sys::window().ok_or_else(|| format!("unable to get window object"))?;
+ let window = web_sys::window().ok_or_else(|| "unable to get window object".to_string())?;
let promise = window.fetch_with_request(&request);
let js_resp = wasm_bindgen_futures::JsFuture::from(promise)
.await
- .map_err(|err| convert_js_error(err))?;
+ .map_err(convert_js_error)?;
let response: web_sys::Response = js_resp.into();
let status = response.status();
- if !(status >= 200 && status < 300) {
+ if !(200..300).contains(&status) {
return Err(format!(
"Catalog download failed -g ot HTTP status {}",
status
));
}
- let promise = response
- .array_buffer()
- .map_err(|err| convert_js_error(err))?;
+ let promise = response.array_buffer().map_err(convert_js_error)?;
let js_fut = wasm_bindgen_futures::JsFuture::from(promise);
- let body = js_fut.await.map_err(|err| convert_js_error(err))?;
+ let body = js_fut.await.map_err(convert_js_error)?;
let body = js_sys::Uint8Array::new(&body).to_vec();
init_i18n_from_blob(body)?;
) {
let key = key.into();
#[cfg(debug_assertions)]
- if key.contains(|x| x == ';' || x == ':') {
+ if key.contains([';', ':']) {
panic!("invalid character in style key: '{key}'");
}
if let Some(value) = value.into_prop_value() {
#[cfg(debug_assertions)]
- if value.contains(|x| x == ';' || x == ':') {
+ if value.contains([';', ':']) {
panic!("invalid character in style value '{value}' for '{key}'");
}
self.styles
#[derivative(Clone(bound = ""), PartialEq(bound = ""))]
pub struct BuilderFn<T>(#[derivative(PartialEq(compare_with = "Rc::ptr_eq"))] Rc<dyn Fn() -> T>);
-impl<T: Into<Html>> Into<Html> for BuilderFn<T> {
- fn into(self) -> Html {
- self.apply().into()
+impl<T: Into<Html>> From<BuilderFn<T>> for Html {
+ fn from(val: BuilderFn<T>) -> Self {
+ val.apply().into()
}
}
.cloned()
.expect("cannot access available languages before they've been set");
- let list = list
- .into_iter()
+ list.into_iter()
.map(|mut info| {
info.translated_text = gettext(&info.english_text);
info
})
- .collect();
-
- list
+ .collect()
}
// this `thread_local!` definition should be fine as this crate is essentially WASM only where
#[derivative(Clone(bound = ""), PartialEq(bound = ""))]
pub struct Loader<T>(SharedState<LoaderState<T>>);
+impl<T: 'static + DeserializeOwned + Serialize> Default for Loader<T> {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl<T: 'static + DeserializeOwned + Serialize> Loader<T> {
/// Create a new instance.
pub fn new() -> Self {
StorageLocation::Session(state_id) => (session_storage(), state_id),
};
if let Some(store) = store {
- let _ = store.delete(&*state_id);
+ let _ = store.delete(state_id);
}
}
};
if let Some(store) = store {
- if let Ok(Some(item_str)) = store.get_item(&*state_id) {
+ if let Ok(Some(item_str)) = store.get_item(state_id) {
if let Ok(data) = serde_json::from_str(&item_str) {
return Some(data);
}
};
if let Some(store) = store {
let item_str = serde_json::to_string(data).unwrap();
- match store.set_item(&*state_id, &item_str) {
- Err(err) => log::error!(
- "store persistent state {} failed: {}",
- state_id,
+ if let Err(err) = store.set_item(state_id, &item_str) {
+ log::error!(
+ "store persistent state {state_id} failed: {}",
crate::convert_js_error(err)
- ),
- Ok(_) => {}
+ )
}
}
}
pub children: Vec<VNode>,
}
+impl Default for NavigationContainer {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl NavigationContainer {
pub fn new() -> Self {
yew::props!(Self {})
let parent_context_handle;
let location_context_handle;
let nav_ctx;
- let on_ctx_update = ctx.link().callback(|nav_ctx| Msg::NavCtxUpdate(nav_ctx));
+ let on_ctx_update = ctx.link().callback(Msg::NavCtxUpdate);
if let Some((parent_nav_ctx, handle)) =
ctx.link().context::<NavigationContext>(on_ctx_update)
{
parent_context_handle = Some(handle);
location_context_handle = None;
} else {
- let on_loc_update = ctx.link().callback(|loc| Msg::LocationUpdate(loc));
+ let on_loc_update = ctx.link().callback(Msg::LocationUpdate);
if let Some(loc_handle) = ctx.link().add_location_listener(on_loc_update) {
nav_ctx = location_to_nav_ctx(&ctx.link().location());
parent_context_handle = None;
}
}
-impl Into<VNode> for NavigationContainer {
- fn into(self) -> VNode {
- let comp = VComp::new::<PwtNavigationContainer>(Rc::new(self), None);
+impl From<NavigationContainer> for VNode {
+ fn from(val: NavigationContainer) -> Self {
+ let comp = VComp::new::<PwtNavigationContainer>(Rc::new(val), None);
VNode::from(comp)
}
}
}
}
+impl Default for Selection {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Selection {
/// Create a new instance.
pub fn new() -> Self {
/// [Selection] object, so each clone can hold a single on_select
/// callback.
pub fn on_select(mut self, cb: impl IntoEventCallback<Selection>) -> Self {
- self.on_select = match cb.into_event_callback() {
- Some(cb) => Some(Rc::new(self.add_listener(cb))),
- None => None,
- };
+ self.on_select = cb
+ .into_event_callback()
+ .map(|cb| Rc::new(self.add_listener(cb)));
self
}
initial_version: usize,
}
-impl<'a> Deref for SelectionWriteGuard<'a> {
+impl Deref for SelectionWriteGuard<'_> {
type Target = SelectionState;
fn deref(&self) -> &Self::Target {
}
}
-impl<'a> DerefMut for SelectionWriteGuard<'a> {
+impl DerefMut for SelectionWriteGuard<'_> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.state
}
}
-impl<'a> Drop for SelectionWriteGuard<'a> {
+impl Drop for SelectionWriteGuard<'_> {
fn drop(&mut self) {
let changed = self.state.version != self.initial_version;
unsafe {
state: Ref<'a, SelectionState>,
}
-impl<'a> Deref for SelectionReadGuard<'a> {
+impl Deref for SelectionReadGuard<'_> {
type Target = SelectionState;
fn deref(&self) -> &Self::Target {
false => {
if let Some(current) = &self.selection {
self.selection = data.find_map(move |rec| {
- let key = extract_key.apply(&rec);
- (&key == current).then(|| key)
+ let key = extract_key.apply(rec);
+ (&key == current).then_some(key)
});
}
}
true => {
let mut new_map = HashSet::new();
for rec in data {
- let key = extract_key.apply(&rec);
+ let key = extract_key.apply(rec);
if self.contains(&key) {
new_map.insert(key);
}
}
pub fn set_on_change(&mut self, cb: impl IntoEventCallback<SharedState<T>>) {
- self.on_change = match cb.into_event_callback() {
- Some(cb) => Some(Rc::new(self.add_listener(cb))),
- None => None,
- };
+ self.on_change = cb
+ .into_event_callback()
+ .map(|cb| Rc::new(self.add_listener(cb)));
}
/// Method to add an shared state observer.
//initial_version: usize,
}
-impl<'a, T> Deref for SharedStateWriteGuard<'a, T> {
+impl<T> Deref for SharedStateWriteGuard<'_, T> {
type Target = SharedStateInner<T>;
fn deref(&self) -> &Self::Target {
}
}
-impl<'a, T> DerefMut for SharedStateWriteGuard<'a, T> {
+impl<T> DerefMut for SharedStateWriteGuard<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.borrowed_state
}
}
-impl<'a, T> Drop for SharedStateWriteGuard<'a, T> {
+impl<T> Drop for SharedStateWriteGuard<'_, T> {
fn drop(&mut self) {
//let changed = self.state.version != self.initial_version;
let changed = true; // TODO: impl change detection?
borrowed_state: Ref<'a, SharedStateInner<T>>,
}
-impl<'a, T> Deref for SharedStateReadGuard<'a, T> {
+impl<T> Deref for SharedStateReadGuard<'_, T> {
type Target = SharedStateInner<T>;
fn deref(&self) -> &Self::Target {
}
}
+impl<T: ExtractPrimaryKey + 'static> Default for Store<T> {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl<T: ExtractPrimaryKey + 'static> Store<T> {
/// Creates a new instance for types implementing [ExtractPrimaryKey].
///
/// [Store] object, so each clone can hold a single on_select
/// callback.
pub fn on_change(mut self, cb: impl IntoEventCallback<()>) -> Self {
- self.on_change = match cb.into_event_callback() {
- Some(cb) => Some(Rc::new(self.add_listener(cb))),
- None => None,
- };
+ self.on_change = cb
+ .into_event_callback()
+ .map(|cb| Rc::new(self.add_listener(cb)));
self
}
}
}
-impl<'a, T> DerefMut for StoreWriteGuard<'a, T> {
+impl<T> DerefMut for StoreWriteGuard<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.state
}
}
-impl<'a, T: 'static> Drop for StoreWriteGuard<'a, T> {
+impl<T: 'static> Drop for StoreWriteGuard<'_, T> {
fn drop(&mut self) {
if self.update {
self.version += 1;
node_id: usize,
}
-impl<'a, T: 'static> DataNode<T> for StoreNodeRef<'a, T> {
+impl<T: 'static> DataNode<T> for StoreNodeRef<'_, T> {
fn record(&self) -> DataNodeDerefGuard<T> {
let data = &self.state.data[self.node_id];
let guard: Box<dyn Deref<Target = T>> = Box::new(data);
fn get_default_theme_name() -> String {
get_available_themes()
- .get(0)
+ .first()
.unwrap_or(&"Material")
.to_string()
}
Self {
mode: ThemeMode::default(),
density: ThemeDensity::Preset, // use default from css
- name: String::from(get_default_theme_name()),
+ name: get_default_theme_name(),
}
}
}
let name = theme.name.to_lowercase();
let themes = get_available_themes();
- if themes.iter().find(|t| t.to_lowercase() == name).is_some() {
+ if themes.iter().any(|t| t.to_lowercase() == name) {
return theme;
}
}
}
-impl<'a, T> KeyedSlabTreeNodeMut<'a, T> {
+impl<T> KeyedSlabTreeNodeMut<'_, T> {
impl_slab_node_ref!(KeyedSlabTreeNodeRef<T>);
impl_slab_node_mut!(KeyedSlabTreeNodeMut<T>, KeyedSlabTree<T>);
/// Iterate over children.
pub fn children(&self) -> KeyedSlabTreeChildren<T> {
let entry = self.tree.get(self.node_id).unwrap();
- let pos = entry.children.is_some().then(|| 0);
+ let pos = entry.children.is_some().then_some(0);
KeyedSlabTreeChildren {
node_id: self.node_id,
tree: self.tree,
/// Iterate over children (mutable).
pub fn children_mut(&mut self) -> KeyedSlabTreeChildrenMut<T> {
let entry = self.tree.get(self.node_id).unwrap();
- let pos = entry.children.is_some().then(|| 0);
+ let pos = entry.children.is_some().then_some(0);
KeyedSlabTreeChildrenMut {
node_id: self.node_id,
tree: self.tree,
}
}
-impl<'a, T> KeyedSlabTreeNodeRef<'a, T> {
+impl<T> KeyedSlabTreeNodeRef<'_, T> {
impl_slab_node_ref!(KeyedSlabTreeNodeRef<T>);
/// Iterate over children.
pub fn children(&self) -> KeyedSlabTreeChildren<T> {
let entry = self.tree.get(self.node_id).unwrap();
- let pos = entry.children.is_some().then(|| 0);
+ let pos = entry.children.is_some().then_some(0);
KeyedSlabTreeChildren {
node_id: self.node_id,
tree: self.tree,
}
}
+impl<T: ExtractPrimaryKey> Default for KeyedSlabTree<T> {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl<T: ExtractPrimaryKey> KeyedSlabTree<T> {
pub fn new() -> Self {
let extract_key = ExtractKeyFn::new(|data: &T| data.extract_key());
inner: Rc<RefCell<KeyedSlabTree<T>>>,
}
+impl<T: ExtractPrimaryKey + 'static> Default for TreeStore<T> {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl<T: ExtractPrimaryKey + 'static> TreeStore<T> {
/// Creates a new instance for types implementing [ExtractPrimaryKey].
///
/// [TreeStore] object, so each clone can hold a single on_select
/// callback.
pub fn on_change(mut self, cb: impl IntoEventCallback<()>) -> Self {
- self.on_change = match cb.into_event_callback() {
- Some(cb) => Some(Rc::new(self.add_listener(cb))),
- None => None,
- };
+ self.on_change = cb
+ .into_event_callback()
+ .map(|cb| Rc::new(self.add_listener(cb)));
self
}
}
}
-impl<'a, T> DerefMut for TreeStoreWriteGuard<'a, T> {
+impl<T> DerefMut for TreeStoreWriteGuard<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.tree
}
}
-impl<'a, T> Drop for TreeStoreWriteGuard<'a, T> {
+impl<T> Drop for TreeStoreWriteGuard<'_, T> {
fn drop(&mut self) {
if self.tree.version() != self.initial_version {
self.tree.notify_listeners();
tree: Ref<'a, KeyedSlabTree<T>>,
}
-impl<'a, T> DataNode<T> for KeyedSlabTreeBorrowRef<'a, T> {
+impl<T> DataNode<T> for KeyedSlabTreeBorrowRef<'_, T> {
fn record(&self) -> DataNodeDerefGuard<T> {
let guard = Box::new(RecordGuard {
node_id: self.node_id,
};
}
-impl<'a, T> SlabTreeNodeRef<'a, T> {
+impl<T> SlabTreeNodeRef<'_, T> {
impl_slab_node_ref!(SlabTreeNodeRef<T>);
/// Iterate over children.
pub fn children(&self) -> SlabTreeChildren<T> {
let entry = self.tree.get(self.node_id).unwrap();
- let pos = entry.children.is_some().then(|| 0);
+ let pos = entry.children.is_some().then_some(0);
SlabTreeChildren {
node_id: self.node_id,
tree: self.tree,
}
}
-impl<'a, T> SlabTreeNodeMut<'a, T> {
+impl<T> SlabTreeNodeMut<'_, T> {
impl_slab_node_ref!(SlabTreeNodeRef<T>);
impl_slab_node_mut!(SlabTreeNodeMut<T>, SlabTree<T>);
/// Iterate over children.
pub fn children(&self) -> SlabTreeChildren<T> {
let entry = self.tree.get(self.node_id).unwrap();
- let pos = entry.children.is_some().then(|| 0);
+ let pos = entry.children.is_some().then_some(0);
SlabTreeChildren {
node_id: self.node_id,
tree: self.tree,
/// Iterate over children (mutable).
pub fn children_mut(&mut self) -> SlabTreeChildrenMut<T> {
let entry = self.tree.get(self.node_id).unwrap();
- let pos = entry.children.is_some().then(|| 0);
+ let pos = entry.children.is_some().then_some(0);
SlabTreeChildrenMut {
node_id: self.node_id,
tree: self.tree,
}
}
+impl<T> Default for SlabTree<T> {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl<T> SlabTree<T> {
pub fn new() -> Self {
Self {
tree: &'a SlabTree<T>,
}
-impl<'a, T: 'static + Serialize> Serialize for ChildList<'a, T> {
+impl<T: 'static + Serialize> Serialize for ChildList<'_, T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
}
}
-impl<'a, T: 'static + Serialize> Serialize for SlabTreeNodeRef<'a, T> {
+impl<T: 'static + Serialize> Serialize for SlabTreeNodeRef<'_, T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
tree: &'a mut SlabTree<T>,
}
-impl<'a, 'de, T: Deserialize<'de>> Visitor<'de> for ChildrenVisitor<'a, T> {
+impl<'de, T: Deserialize<'de>> Visitor<'de> for ChildrenVisitor<'_, T> {
type Value = Vec<usize>;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
}
}
-impl<'a, 'de, T: Deserialize<'de>> DeserializeSeed<'de> for ChildrenVisitor<'a, T> {
+impl<'de, T: Deserialize<'de>> DeserializeSeed<'de> for ChildrenVisitor<'_, T> {
type Value = Vec<usize>;
fn deserialize<D: Deserializer<'de>>(self, deserializer: D) -> Result<Self::Value, D::Error> {
static KNOWN_FIELDS: &[&str] = &["record", "expanded", "children"];
-impl<'a, 'de, T: Deserialize<'de>> Visitor<'de> for TreeNodeVisitor<'a, T> {
+impl<'de, T: Deserialize<'de>> Visitor<'de> for TreeNodeVisitor<'_, T> {
type Value = usize;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
}
}
-impl<'a, 'de, T: Deserialize<'de>> DeserializeSeed<'de> for TreeNodeVisitor<'a, T> {
+impl<'de, T: Deserialize<'de>> DeserializeSeed<'de> for TreeNodeVisitor<'_, T> {
type Value = usize;
fn deserialize<D: Deserializer<'de>>(self, deserializer: D) -> Result<Self::Value, D::Error> {
pub bottom: Option<Html>,
}
+impl Default for ApplicationBar {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl ApplicationBar {
/// Create a new instance.
pub fn new() -> Self {
}
}
-impl Into<VNode> for ApplicationBar {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtApplicationBar>(Rc::new(self), key);
+impl From<ApplicationBar> for VNode {
+ fn from(val: ApplicationBar) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtApplicationBar>(Rc::new(val), key);
VNode::from(comp)
}
}
}
}
-impl Into<VNode> for Fab {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtFab>(Rc::new(self), key);
+impl From<Fab> for VNode {
+ fn from(val: Fab) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtFab>(Rc::new(val), key);
VNode::from(comp)
}
}
pub children: Vec<Fab>,
}
+impl Default for FabMenu {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl FabMenu {
/// Create a new instance.
pub fn new() -> Self {
FabMenuDirection::Left => "pwt-fab-direction-left",
FabMenuDirection::Right => "pwt-fab-direction-right",
})
- .class(self.show_items.then(|| "active"))
+ .class(self.show_items.then_some("active"))
.onkeydown({
let link = ctx.link().clone();
move |event: KeyboardEvent| {
}
}
-impl Into<VNode> for FabMenu {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtFabMenu>(Rc::new(self), key);
+impl From<FabMenu> for VNode {
+ fn from(val: FabMenu) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtFabMenu>(Rc::new(val), key);
VNode::from(comp)
}
}
}
}
-impl Into<VNode> for GestureDetector {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtGestureDetector>(Rc::new(self), key);
+impl From<GestureDetector> for VNode {
+ fn from(val: GestureDetector) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtGestureDetector>(Rc::new(val), key);
VNode::from(comp)
}
}
let dx = (x2 - x1) as f64;
let dy = (y2 - y1) as f64;
- let radius = (dx * dx + dy * dy).sqrt();
- radius
+ (dx * dx + dy * dy).sqrt()
}
state: SharedState<Vec<PageControllerMsg>>,
}
+impl Default for PageController {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl PageController {
/// Create a new instance.
pub fn new() -> Self {
.clone()
.unwrap_or(AnyHistory::from(HashHistory::new()));
- let snackbar_controller = props
- .snackbar_controller
- .clone()
- .unwrap_or(SnackBarController::new());
+ let snackbar_controller = props.snackbar_controller.clone().unwrap_or_default();
let page_controller = PageController::new();
}
}
-impl Into<VNode> for MaterialApp {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtMaterialApp>(Rc::new(self), key);
+impl From<MaterialApp> for VNode {
+ fn from(val: MaterialApp) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtMaterialApp>(Rc::new(val), key);
VNode::from(comp)
}
}
let key = selection.selected_key();
let key = get_active_or_default(props, &key);
- if &self.active == &key {
+ if self.active == key {
return false;
}
if let Some(key) = &self.active {
if props.router {
- ctx.link().push_relative_route(&key);
+ ctx.link().push_relative_route(key);
}
}
log::info!("select {:?}", key);
let key = get_active_or_default(props, &key);
- if &self.active == &key {
+ if self.active == key {
return false;
}
let class = classes!(
"pwt-navigation-bar-icon-container",
- is_active.then(|| "active"),
+ is_active.then_some("active"),
);
Some(html! {<div {class}><i class={icon_class}/></div>})
}
None => None,
};
- let label = match &item.label {
- Some(label) => Some(html! {
+ let label = item.label.as_ref().map(|label| {
+ html! {
<div class="pwt-navigation-bar-label">{label}</div>
- }),
- None => None,
- };
+ }
+ });
Container::new()
.class("pwt-navigation-bar-item")
}
}
-impl Into<VNode> for NavigationBar {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtNavigationBar>(Rc::new(self), key);
+impl From<NavigationBar> for VNode {
+ fn from(val: NavigationBar) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtNavigationBar>(Rc::new(val), key);
VNode::from(comp)
}
}
let key = selection.selected_key();
let key = get_active_or_default(props, &key);
- if &self.active == &key {
+ if self.active == key {
return false;
}
if let Some(key) = &self.active {
if props.router {
- ctx.link().push_relative_route(&key);
+ ctx.link().push_relative_route(key);
}
}
log::info!("select {:?}", key);
let key = get_active_or_default(props, &key);
- if &self.active == &key {
+ if self.active == key {
return false;
}
let class = classes!(
"pwt-navigation-rail-icon-container",
- is_active.then(|| "active"),
+ is_active.then_some("active"),
);
Some(html! {<div {class}><i class={icon_class}/></div>})
}
None => None,
};
- let label = match &item.label {
- Some(label) => Some(html! {
+ let label = item.label.as_ref().map(|label| {
+ html! {
<div class="pwt-navigation-rail-label">{label}</div>
- }),
- None => None,
- };
+ }
+ });
Container::new()
.class("pwt-navigation-rail-item")
}
}
-impl Into<VNode> for NavigationRail {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtNavigationRail>(Rc::new(self), key);
+impl From<NavigationRail> for VNode {
+ fn from(val: NavigationRail) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtNavigationRail>(Rc::new(val), key);
VNode::from(comp)
}
}
Cover,
}
-impl Into<Classes> for PageAnimationStyle {
- fn into(self) -> Classes {
- match self {
+impl From<PageAnimationStyle> for Classes {
+ fn from(val: PageAnimationStyle) -> Self {
+ match val {
PageAnimationStyle::Push => "pwt-page-animation-push",
PageAnimationStyle::Fade => "pwt-page-animation-fade",
PageAnimationStyle::Cover => "pwt-page-animation-cover",
}
}
-impl Into<VNode> for PageStack {
- fn into(self) -> VNode {
- let comp = VComp::new::<PwtPageStack>(Rc::new(self), None);
+impl From<PageStack> for VNode {
+ fn from(val: PageStack) -> Self {
+ let comp = VComp::new::<PwtPageStack>(Rc::new(val), None);
VNode::from(comp)
}
}
pub on_page_change: Option<Callback<usize>>,
}
+impl Default for PageView {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl PageView {
/// Creates a new instance.
pub fn new() -> Self {
}
}
-impl Into<VNode> for PageView {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtPageView>(Rc::new(self), key);
+impl From<PageView> for VNode {
+ fn from(val: PageView) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtPageView>(Rc::new(val), key);
VNode::from(comp)
}
}
pub favorite_action_button: Option<VNode>,
}
+impl Default for Scaffold {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Scaffold {
/// Create a new instance.
pub fn new() -> Self {
}
}
-impl Into<VNode> for Scaffold {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtScaffold>(Rc::new(self), key);
+impl From<Scaffold> for VNode {
+ fn from(val: Scaffold) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtScaffold>(Rc::new(val), key);
VNode::from(comp)
}
}
state: SharedState<Vec<SideDialogControllerMsg>>,
}
+impl Default for SideDialogController {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl SideDialogController {
/// Create a new instance.
pub fn new() -> Self {
}
}
+impl Default for SideDialog {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl SideDialog {
/// Create a new instance.
pub fn new() -> Self {
.active_element()
.and_then(|el| el.dyn_into::<HtmlElement>().ok());
- let controller = props
- .controller
- .clone()
- .unwrap_or(SideDialogController::new());
+ let controller = props.controller.clone().unwrap_or_default();
let _controller_observer = controller
.state
Msg::Swipe(event) => {
let angle = event.direction; // -180 to + 180
let dismiss = match props.direction {
- SideDialogLocation::Left => angle > 135.0 || angle < -135.0,
+ SideDialogLocation::Left => !(-135.0..=135.0).contains(&angle),
SideDialogLocation::Right => angle > -45.0 && angle < 45.0,
SideDialogLocation::Top => angle > 45.0 && angle < 135.0,
SideDialogLocation::Bottom => angle > -135.0 && angle < -45.0,
}
}
-impl Into<VNode> for SideDialog {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtSideDialog>(Rc::new(self), key);
+impl From<SideDialog> for VNode {
+ fn from(val: SideDialog) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtSideDialog>(Rc::new(val), key);
VNode::from(comp)
}
}
fn view(&self, ctx: &Context<Self>) -> Html {
let props = ctx.props();
- let icon = props.icon_class.clone().map(|class| Fa::from_class(class));
+ let icon = props.icon_class.clone().map(Fa::from_class);
let onclick = Callback::from({
let controller = self.controller.clone();
}
}
-impl Into<VNode> for SlidableAction {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtSlidableAction>(Rc::new(self), key);
+impl From<SlidableAction> for VNode {
+ fn from(val: SlidableAction) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtSlidableAction>(Rc::new(val), key);
VNode::from(comp)
}
}
pub id: Option<AttrValue>,
}
+impl Default for SnackBar {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl SnackBar {
/// Create a new instance.
pub fn new() -> Self {
}
}
-impl Into<VTag> for SnackBar {
- fn into(self) -> VTag {
- let attributes = self.std_props.cumulate_attributes(Some("pwt-snackbar"));
+impl From<SnackBar> for VTag {
+ fn from(val: SnackBar) -> Self {
+ let attributes = val.std_props.cumulate_attributes(Some("pwt-snackbar"));
- let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+ let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
let mut children = Vec::new();
children.push(
Container::new()
.class("pwt-snackbar-message")
- .with_child(self.message.clone().unwrap_or(AttrValue::Static("")))
+ .with_child(val.message.clone().unwrap_or(AttrValue::Static("")))
.into(),
);
- if let Some(action_label) = &self.action_label {
+ if let Some(action_label) = &val.action_label {
children.push(
Button::new(action_label.clone())
.class("pwt-button-filled")
.class("pwt-snackbar-action")
.class("pwt-scheme-inverse-surface")
.onclick({
- let on_action = self.on_action.clone();
+ let on_action = val.on_action.clone();
move |_| {
if let Some(on_action) = &on_action {
on_action.emit(());
.into(),
);
}
- if self.show_close_icon {
+ if val.show_close_icon {
children.push(
ActionIcon::new("fa fa-lg fa-close")
- .on_activate(self.on_close.clone())
+ .on_activate(val.on_close.clone())
.into(),
);
}
VTag::__new_other(
Cow::Borrowed("div"),
- self.std_props.node_ref,
- self.std_props.key,
+ val.std_props.node_ref,
+ val.std_props.key,
attributes,
listeners,
children.into(),
state: SharedState<Vec<SnackBarControllerMsg>>,
}
+impl Default for SnackBarController {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl SnackBarController {
pub fn new() -> Self {
Self {
pub bottom_offset: Option<u32>,
}
+impl Default for SnackBarManager {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl SnackBarManager {
/// Create a new instance.
pub fn new() -> Self {
fn create(ctx: &Context<Self>) -> Self {
let props = ctx.props();
- let controller = props
- .controller
- .clone()
- .unwrap_or(SnackBarController::new());
+ let controller = props.controller.clone().unwrap_or_default();
let _state_observer = controller
.state
}
}
-impl Into<VNode> for SnackBarManager {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtSnackBarManager>(Rc::new(self), key);
+impl From<SnackBarManager> for VNode {
+ fn from(val: SnackBarManager) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtSnackBarManager>(Rc::new(val), key);
VNode::from(comp)
}
}
Container::from_tag("i")
.node_ref(props.node_ref.clone())
- .attribute("tabindex", (!disabled).then(|| tabindex))
+ .attribute("tabindex", (!disabled).then_some(tabindex))
.attribute("role", "button")
.attribute("aria-label", props.aria_label.clone())
.class("pwt-action-icon")
- .class(props.disabled.then(|| "disabled"))
+ .class(props.disabled.then_some("disabled"))
.class(props.class.clone())
.class(props.icon_class.clone())
.styles(props.style.clone())
}
}
-impl Into<VNode> for ActionIcon {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtActionIcon>(Rc::new(self), key);
+impl From<ActionIcon> for VNode {
+ fn from(val: ActionIcon) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtActionIcon>(Rc::new(val), key);
VNode::from(comp)
}
}
use pwt_macros::{builder, widget};
-#[derive(PartialEq, Clone, Copy)]
+#[derive(PartialEq, Clone, Copy, Default)]
pub enum ButtonType {
+ #[default]
Button,
Submit,
Reset,
}
}
-impl Default for ButtonType {
- fn default() -> Self {
- ButtonType::Button
- }
-}
-
/// Button.
///
/// Buttons can be text only, icons with text, or icons only.
}
if let Some(text) = &props.text {
- children.push((&*text).into());
+ children.push(text.into());
}
let (x, y, radius) = self.ripple_pos.unwrap_or((0, 0, 0));
children.push({
Container::new()
.class("pwt-button-ripple")
- .class(self.ripple_pos.is_some().then(|| "animate"))
+ .class(self.ripple_pos.is_some().then_some("animate"))
.style("--pwt-ripple-x", format!("{x}px"))
.style("--pwt-ripple-y", format!("{y}px"))
.style("--pwt-ripple-radius", format!("{radius}px"))
.children(children)
.tag("button")
.class("pwt-button")
- .class(props.pressed.then(|| "pressed"))
+ .class(props.pressed.then_some("pressed"))
.attribute("type", Some(props.button_type.to_string()))
- .attribute("aria-disabled", props.disabled.then(|| "true"))
- .attribute("autofocus", props.autofocus.then(|| ""))
+ .attribute("aria-disabled", props.disabled.then_some("true"))
+ .attribute("autofocus", props.autofocus.then_some(""))
.attribute("aria-label", props.aria_label.clone())
.attribute("tabindex", props.tabindex.map(|i| i.to_string()))
.onpointerdown(ctx.link().callback(Msg::ShowRippleAnimation))
}
}
-impl Into<VTag> for Animate {
- fn into(self) -> VTag {
+impl From<Animate> for VTag {
+ fn from(val: Animate) -> Self {
VTag::__new_other(
"animate".into(),
NodeRef::default(),
None,
- self.attributes,
+ val.attributes,
Listeners::None,
VList::new().into(),
)
}
}
-impl Into<VNode> for Animate {
- fn into(self) -> VNode {
- let vtag: VTag = self.into();
+impl From<Animate> for VNode {
+ fn from(val: Animate) -> Self {
+ let vtag: VTag = val.into();
VNode::from(vtag)
}
}
}
}
-impl Into<VTag> for AnimateTransform {
- fn into(self) -> VTag {
+impl From<AnimateTransform> for VTag {
+ fn from(val: AnimateTransform) -> Self {
VTag::__new_other(
"animateTransform".into(),
NodeRef::default(),
None,
- self.attributes,
+ val.attributes,
Listeners::None,
VList::new().into(),
)
}
}
-impl Into<VNode> for AnimateTransform {
- fn into(self) -> VNode {
- let vtag: VTag = self.into();
+impl From<AnimateTransform> for VNode {
+ fn from(val: AnimateTransform) -> Self {
+ let vtag: VTag = val.into();
VNode::from(vtag)
}
}
children: Option<Vec<VNode>>,
}
+impl Default for Circle {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Circle {
/// Create a new instance.
pub fn new() -> Self {
impl_svg_presentation_attributes!();
}
-impl Into<VTag> for Circle {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
+impl From<Circle> for VTag {
+ fn from(val: Circle) -> Self {
+ val.std_props.into_vtag(
Cow::Borrowed("circle"),
None::<&str>,
- Some(self.listeners),
- self.children,
+ Some(val.listeners),
+ val.children,
)
}
}
children: Option<Vec<VNode>>,
}
+impl Default for Ellipse {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Ellipse {
/// Create a new instance.
pub fn new() -> Self {
impl_svg_presentation_attributes!();
}
-impl Into<VTag> for Ellipse {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
+impl From<Ellipse> for VTag {
+ fn from(val: Ellipse) -> Self {
+ val.std_props.into_vtag(
Cow::Borrowed("ellipse"),
None::<&str>,
- Some(self.listeners),
+ Some(val.listeners),
None,
)
}
#[derive(Properties, Clone, PartialEq)]
pub struct Group {}
+impl Default for Group {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Group {
/// Create a new instance.
pub fn new() -> Self {
impl_svg_presentation_attributes!();
}
-impl Into<VTag> for Group {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
+impl From<Group> for VTag {
+ fn from(val: Group) -> Self {
+ val.std_props.into_vtag(
Cow::Borrowed("g"),
None::<&str>,
- Some(self.listeners),
- Some(self.children),
+ Some(val.listeners),
+ Some(val.children),
)
}
}
#[derive(Properties, Clone, PartialEq)]
pub struct Hyperlink {}
+impl Default for Hyperlink {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Hyperlink {
/// Create a new instance.
pub fn new() -> Self {
}
}
-impl Into<VTag> for Hyperlink {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
+impl From<Hyperlink> for VTag {
+ fn from(val: Hyperlink) -> Self {
+ val.std_props.into_vtag(
Cow::Borrowed("a"),
None::<&str>,
- Some(self.listeners),
- Some(self.children),
+ Some(val.listeners),
+ Some(val.children),
)
}
}
impl_svg_presentation_attributes!();
}
-impl Into<VTag> for Line {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
+impl From<Line> for VTag {
+ fn from(val: Line) -> Self {
+ val.std_props.into_vtag(
Cow::Borrowed("line"),
None::<&str>,
- Some(self.listeners),
- self.children,
+ Some(val.listeners),
+ val.children,
)
}
}
}
}
-impl Into<AttrValue> for SvgLength {
- fn into(self) -> AttrValue {
- self.to_string().into()
+impl From<SvgLength> for AttrValue {
+ fn from(val: SvgLength) -> Self {
+ val.to_string().into()
}
}
#[derive(Properties, Clone, PartialEq)]
pub struct Canvas {}
+impl Default for Canvas {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Canvas {
pub fn new() -> Self {
yew::props!(Self {})
}
}
-impl Into<VTag> for Canvas {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
+impl From<Canvas> for VTag {
+ fn from(val: Canvas) -> Self {
+ val.std_props.into_vtag(
Cow::Borrowed("svg"),
None::<&str>,
- Some(self.listeners),
- Some(self.children),
+ Some(val.listeners),
+ Some(val.children),
)
}
}
children: Option<Vec<VNode>>,
}
+impl Default for Path {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Path {
/// Create a new instance.
pub fn new() -> Self {
impl_svg_presentation_attributes!();
}
-impl Into<VTag> for Path {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
+impl From<Path> for VTag {
+ fn from(val: Path) -> Self {
+ val.std_props.into_vtag(
Cow::Borrowed("path"),
None::<&str>,
- Some(self.listeners),
- self.children,
+ Some(val.listeners),
+ val.children,
)
}
}
children: Option<Vec<VNode>>,
}
+impl Default for Polygon {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Polygon {
/// Create a new instance.
pub fn new() -> Self {
impl_svg_presentation_attributes!();
}
-impl Into<VTag> for Polygon {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
+impl From<Polygon> for VTag {
+ fn from(val: Polygon) -> Self {
+ val.std_props.into_vtag(
Cow::Borrowed("polygon"),
None::<&str>,
- Some(self.listeners),
- self.children,
+ Some(val.listeners),
+ val.children,
)
}
}
children: Option<Vec<VNode>>,
}
+impl Default for Polyline {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Polyline {
/// Create a new instance.
pub fn new() -> Self {
impl_svg_presentation_attributes!();
}
-impl Into<VTag> for Polyline {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
+impl From<Polyline> for VTag {
+ fn from(val: Polyline) -> Self {
+ val.std_props.into_vtag(
Cow::Borrowed("polyline"),
None::<&str>,
- Some(self.listeners),
- self.children,
+ Some(val.listeners),
+ val.children,
)
}
}
children: Option<Vec<VNode>>,
}
+impl Default for Rect {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Rect {
/// Create a new instance.
pub fn new() -> Self {
impl_svg_presentation_attributes!();
}
-impl Into<VTag> for Rect {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
+impl From<Rect> for VTag {
+ fn from(val: Rect) -> Self {
+ val.std_props.into_vtag(
Cow::Borrowed("rect"),
None::<&str>,
- Some(self.listeners),
- self.children,
+ Some(val.listeners),
+ val.children,
)
}
}
impl_svg_presentation_attributes!();
}
-impl Into<VTag> for Reference {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
+impl From<Reference> for VTag {
+ fn from(val: Reference) -> Self {
+ val.std_props.into_vtag(
Cow::Borrowed("use"),
None::<&str>,
- Some(self.listeners),
- self.children,
+ Some(val.listeners),
+ val.children,
)
}
}
}
}
-impl Into<VTag> for Text {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
+impl From<Text> for VTag {
+ fn from(val: Text) -> Self {
+ val.std_props.into_vtag(
Cow::Borrowed("text"),
None::<&str>,
- Some(self.listeners),
- Some(self.children),
+ Some(val.listeners),
+ Some(val.children),
)
}
}
}
}
-impl Into<VTag> for TSpan {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
+impl From<TSpan> for VTag {
+ fn from(val: TSpan) -> Self {
+ val.std_props.into_vtag(
Cow::Borrowed("tspan"),
None::<&str>,
- Some(self.listeners),
- Some(self.children),
+ Some(val.listeners),
+ Some(val.children),
)
}
}
#[derive(Debug, Clone, PartialEq, Properties)]
pub struct Card {}
+impl Default for Card {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Card {
/// Create a new instance.
pub fn new() -> Self {
}
}
-impl Into<VTag> for Card {
- fn into(self) -> VTag {
- let attributes = self.std_props.cumulate_attributes(None::<&str>);
+impl From<Card> for VTag {
+ fn from(val: Card) -> Self {
+ let attributes = val.std_props.cumulate_attributes(None::<&str>);
- let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+ let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
- let children = VList::with_children(self.children, None);
+ let children = VList::with_children(val.children, None);
VTag::__new_other(
Cow::Borrowed("div"),
- self.std_props.node_ref,
- self.std_props.key,
+ val.std_props.node_ref,
+ val.std_props.key,
attributes,
listeners,
children.into(),
}
}
-impl Into<VNode> for CatalogLoader {
- fn into(self) -> VNode {
- let comp = VComp::new::<PwtCatalogLoader>(Rc::new(self), None);
+impl From<CatalogLoader> for VNode {
+ fn from(val: CatalogLoader) -> Self {
+ let comp = VComp::new::<PwtCatalogLoader>(Rc::new(val), None);
VNode::from(comp)
}
}
#[derive(Debug, Clone, PartialEq, Properties)]
pub struct Column {}
+impl Default for Column {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Column {
/// Create a new instance.
pub fn new() -> Self {
}
}
-impl Into<VTag> for Column {
- fn into(self) -> VTag {
- let attributes = self.std_props.cumulate_attributes(None::<&str>);
+impl From<Column> for VTag {
+ fn from(val: Column) -> Self {
+ let attributes = val.std_props.cumulate_attributes(None::<&str>);
- let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+ let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
- let children = VList::with_children(self.children, None);
+ let children = VList::with_children(val.children, None);
VTag::__new_other(
Cow::Borrowed("div"),
- self.std_props.node_ref,
- self.std_props.key,
+ val.std_props.node_ref,
+ val.std_props.key,
attributes,
listeners,
children.into(),
}
}
-impl Into<VTag> for Container {
- fn into(self) -> VTag {
- self.std_props.into_vtag(
- self.tag,
+impl From<Container> for VTag {
+ fn from(val: Container) -> Self {
+ val.std_props.into_vtag(
+ val.tag,
None::<&str>,
- Some(self.listeners),
- Some(self.children),
+ Some(val.listeners),
+ Some(val.children),
)
}
}
pub config: CellConfiguration,
}
-impl<'a, T> DataTableCellRenderArgs<'a, T> {
+impl<T> DataTableCellRenderArgs<'_, T> {
/// Return the data node.
pub fn record(&self) -> &T {
self.record
let get_property_fn = Rc::new(get_property_fn);
self.sorter({
let get_property_fn = get_property_fn.clone();
- move |itema: &T, itemb: &T| get_property_fn(itema).cmp(&get_property_fn(itemb))
+ move |itema: &T, itemb: &T| get_property_fn(itema).cmp(get_property_fn(itemb))
})
.render(move |item: &T| html! {{get_property_fn(item)}})
}
}
}
- props.store.filtered_record_pos(&key)
+ props.store.filtered_record_pos(key)
}
fn set_cursor(&mut self, props: &DataTable<S>, pos: Option<usize>) {
if let Some(pos) = pos {
- self.cursor = match props.store.lookup_filtered_record_key(pos) {
- Some(record_key) => Some(Cursor { pos, record_key }),
- None => None,
- }
+ self.cursor = props
+ .store
+ .lookup_filtered_record_key(pos)
+ .map(|record_key| Cursor { pos, record_key })
} else {
self.cursor = None;
}
}
}
selection.bulk_select(keys);
- } else {
- if let Some(key) = selection.selected_key() {
- if props.store.filtered_record_pos(&key).is_none() {
- selection.clear();
- }
+ } else if let Some(key) = selection.selected_key() {
+ if props.store.filtered_record_pos(&key).is_none() {
+ selection.clear();
}
}
}
}
fn focus_cursor(&mut self) {
- match &self.cursor {
- Some(Cursor { record_key, .. }) => self.focus_cell(&record_key.clone()),
- None => return, // nothing to do
- };
+ if let Some(Cursor { record_key, .. }) = &self.cursor {
+ self.focus_cell(&record_key.clone())
+ }
}
fn get_row_el(&self, key: &Key) -> Option<web_sys::Element> {
// do not use table tag here to avoid role="table", instead set display type in style"
.attribute("role", "none")
.class("pwt-datatable-content")
- .class(props.hover.then(|| "table-hover"))
- .class(props.striped.then(|| "table-striped"))
- .class(props.bordered.then(|| "table-bordered"))
- .class(props.borderless.then(|| "table-borderless"))
+ .class(props.hover.then_some("table-hover"))
+ .class(props.striped.then_some("table-striped"))
+ .class(props.bordered.then_some("table-bordered"))
+ .class(props.borderless.then_some("table-borderless"))
.node_ref(self.table_ref.clone())
.style("display", "table")
- .style("table-layout", fixed_mode.then(|| "fixed"))
- .style("width", fixed_mode.then(|| "1px")) // required by table-layout fixed
+ .style("table-layout", fixed_mode.then_some("fixed"))
+ .style("width", fixed_mode.then_some("1px")) // required by table-layout fixed
.style("position", "relative")
.style("top", format!("{offset}px"))
.with_child(first_row);
cell_config: self.cell_config.clone(),
row_render_callback: props.row_render_callback.clone(),
selected,
- active_cell: active.then(|| self.active_column),
+ active_cell: active.then_some(self.active_column),
has_focus: active && self.has_focus,
is_expanded: item.expanded(),
is_leaf: item.is_leaf(),
0
};
- if start > 0 {
- start -= 1;
- }
+ start = start.saturating_sub(1);
if (start & 1) == 1 {
start -= 1;
} // make it work with striped rows
.store
.add_listener(ctx.link().callback(|_| Msg::DataChange));
- let _selection_observer = match &props.selection {
- Some(selection) => {
- Some(selection.add_listener(ctx.link().callback(|_| Msg::SelectionChange)))
- }
- None => None,
- };
+ let _selection_observer = props
+ .selection
+ .as_ref()
+ .map(|selection| selection.add_listener(ctx.link().callback(|_| Msg::SelectionChange)));
let mut me = Self {
_phantom_store: PhantomData::<S>,
Msg::ScrollTo(x, y) => {
self.scroll_top = y.max(0) as usize;
if let Some(el) = self.header_scroll_ref.cast::<web_sys::Element>() {
- el.set_scroll_left(x as i32);
+ el.set_scroll_left(x);
}
self.update_scroll_info(props);
props.virtual_scroll.unwrap_or(true)
let mut active_descendant = None;
if let Some(Cursor { record_key, .. }) = &self.cursor {
- active_descendant = Some(self.get_unique_item_id(&record_key));
+ active_descendant = Some(self.get_unique_item_id(record_key));
}
let column_widths =
}
}
-impl<S: DataStore + 'static> Into<VNode> for DataTable<S> {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtDataTable<S>>(Rc::new(self), key);
+impl<S: DataStore + 'static> From<DataTable<S>> for VNode {
+ fn from(val: DataTable<S>) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtDataTable<S>>(Rc::new(val), key);
VNode::from(comp)
}
}
Some(el) => {
if el.tag_name() == "TR" {
if let Some(key_str) = el.id().strip_prefix(&unique_row_prefix) {
- if key_str.len() == 0 {
+ if key_str.is_empty() {
break;
} // stop on errors
// try to find out the column_num
let cell_count = cells + 1;
let colspan = span.max(1); // at least one column for the group header
- let indexed_group = IndexedHeaderGroup {
+ IndexedHeaderGroup {
parent,
cell_idx,
start_col,
key: group.key.clone(),
hidden: group.hidden,
children,
- };
-
- indexed_group
+ }
}
pub fn lookup_cell(headers: &[IndexedHeader<T>], cell_idx: usize) -> Option<&IndexedHeader<T>> {
pub fn extract_column_list(&self, list: &mut Vec<Rc<IndexedHeaderSingle<T>>>) {
match self {
- Self::Single(single) => list.push(Rc::clone(&single)),
+ Self::Single(single) => list.push(Rc::clone(single)),
Self::Group(group) => group.extract_column_list(list),
}
}
let visible = group
.children
.iter()
- .find(|cell| !self.get_cell_hidden(cell.cell_idx()))
- .is_some();
+ .any(|cell| !self.get_cell_hidden(cell.cell_idx()));
self.cell_state[cell_idx].hidden = !visible;
self.bubble_up_hidden(group.parent);
}
// Note: ARIA has no notation for group headers. We need
// to hide them to get correct column order.
.attribute("role", "none")
- .attribute("tabindex", props.focusable.then(|| tabindex))
+ .attribute("tabindex", props.focusable.then_some(tabindex))
.attribute("id", unique_id)
.class("pwt-datatable-group-header-item")
.class(props.header_class.clone())
Self {
unique_id: get_unique_element_id(),
- node_ref: props.node_ref.clone().unwrap_or(NodeRef::default()),
+ node_ref: props.node_ref.clone().unwrap_or_default(),
state,
cursor: None,
observed_widths,
.resize((col_num + 1).max(self.observed_widths.len()), None);
self.observed_widths[col_num] = Some(width);
- let observed_widths: Vec<f64> = self
- .observed_widths
- .iter()
- .filter_map(|w| w.clone())
- .collect();
+ let observed_widths: Vec<f64> =
+ self.observed_widths.iter().filter_map(|w| *w).collect();
if self.state.columns().len() == observed_widths.len() {
let on_message = props.on_message.clone();
}
}
-impl<T: 'static> Into<VNode> for HeaderWidget<T> {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtHeaderWidget<T>>(Rc::new(self), key);
+impl<T: 'static> From<HeaderWidget<T>> for VNode {
+ fn from(val: HeaderWidget<T>) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtHeaderWidget<T>>(Rc::new(val), key);
VNode::from(comp)
}
}
pub menu_builder: Option<BuilderFn<Menu>>,
}
+impl Default for ResizableHeader {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl ResizableHeader {
/// Create a new instance.
pub fn new() -> Self {
let focus_tracker = FocusTracker::new(ctx.link().callback(Msg::FocusChange));
Self {
- node_ref: props.node_ref.clone().unwrap_or(NodeRef::default()),
+ node_ref: props.node_ref.clone().unwrap_or_default(),
rtl: None,
width: 0.0,
pointermove_listener: None,
.node_ref(self.node_ref.clone())
.attribute("role", "none")
.class("pwt-datatable-header-item")
- .class(self.has_focus.then(|| "focused"))
+ .class(self.has_focus.then_some("focused"))
.class(props.class.clone())
.attribute("id", props.id.clone())
.onfocusin(self.focus_tracker.get_focus_callback(true))
.onfocusout(self.focus_tracker.get_focus_callback(false))
.onkeydown({
let link = ctx.link().clone();
- move |event: KeyboardEvent| match event.key().as_str() {
- "ArrowDown" => {
+ move |event: KeyboardEvent| {
+ if event.key().as_str() == "ArrowDown" {
event.stop_propagation();
link.send_message(Msg::ShowPicker);
}
- _ => {}
}
})
.with_child(
.autoshow_menu(true)
.class("pwt-datatable-header-menu-trigger pwt-button-text")
.class(ColorScheme::Primary)
- .class((self.has_focus || self.show_picker).then(|| "focused"))
+ .class((self.has_focus || self.show_picker).then_some("focused"))
.icon_class("fa fa-lg fa-caret-down")
.ondblclick(|event: MouseEvent| event.stop_propagation())
.menu_builder(props.menu_builder.clone())
}
}
-impl Into<VNode> for ResizableHeader {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtResizableHeader>(Rc::new(self), key);
+impl From<ResizableHeader> for VNode {
+ fn from(val: ResizableHeader) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtResizableHeader>(Rc::new(val), key);
VNode::from(comp)
}
}
let aria_expanded = if props.is_leaf {
None
+ } else if props.is_expanded {
+ Some("true")
} else {
- if props.is_expanded {
- Some("true")
- } else {
- Some("false")
- }
+ Some("false")
};
let mut row = Container::from_tag("tr")
if props.selected { "true" } else { "false" },
)
.attribute("id", item_id)
- .class((props.active_cell.is_some() && props.has_focus).then(|| "row-cursor"))
- .class(props.selected.then(|| "selected")); // fixme: remove
+ .class((props.active_cell.is_some() && props.has_focus).then_some("row-cursor"))
+ .class(props.selected.then_some("selected")); // fixme: remove
if let Some(row_render_callback) = &props.row_render_callback {
let mut args = DataTableRowRenderArgs {
let mut td = Container::from_tag("td")
.class(args.config.class)
- .class((cell_active && props.has_focus).then(|| "cell-cursor"))
+ .class((cell_active && props.has_focus).then_some("cell-cursor"))
.styles(args.config.style)
.style("vertical-align", vertical_align)
.style("text-align", text_align)
}
}
-impl<T: Clone + PartialEq + 'static> Into<VNode> for DataTableRow<T> {
- fn into(self) -> VNode {
- let key = Some(self.record_key.clone());
- let comp = VComp::new::<PwtDataTableRow<T>>(Rc::new(self), key);
+impl<T: Clone + PartialEq + 'static> From<DataTableRow<T>> for VNode {
+ fn from(val: DataTableRow<T>) -> Self {
+ let key = Some(val.record_key.clone());
+ let comp = VComp::new::<PwtDataTableRow<T>>(Rc::new(val), key);
VNode::from(comp)
}
}
pub attributes: IndexMap<AttrValue, AttrValue>,
}
-impl<'a, T> DataTableRowRenderArgs<'a, T> {
+impl<T> DataTableRowRenderArgs<'_, T> {
/// Return the data node.
pub fn record(&self) -> &T {
self.record
}
}
-impl Into<VNode> for DesktopApp {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtDesktopApp>(Rc::new(self), key);
+impl From<DesktopApp> for VNode {
+ fn from(val: DesktopApp) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtDesktopApp>(Rc::new(val), key);
VNode::from(comp)
}
}
}
}
-impl Into<VNode> for Dialog {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtDialog>(Rc::new(self), key);
+impl From<Dialog> for VNode {
+ fn from(val: Dialog) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtDialog>(Rc::new(val), key);
VNode::from(comp)
}
}
show: false,
last_show: false,
pending_change: false,
- value: ctx.props().value.clone().unwrap_or_else(|| String::new()),
+ value: ctx.props().value.clone().unwrap_or_default(),
focus_on_field: false,
change_from_input: false,
input_ref: NodeRef::default(),
link: ctx.link().clone(),
};
- let data_show = self.show.then(|| "true");
+ let data_show = self.show.then_some("true");
let value = props.value.clone().unwrap_or_else(|| self.value.clone());
.attribute("aria-expanded", if self.show { "true" } else { "false" })
.attribute("aria-controls", self.picker_id.clone())
.attribute("aria-haspopup", props.popup_type.clone())
- .attribute("aria-required", props.input_props.required.then(|| ""))
+ .attribute("aria-required", props.input_props.required.then_some(""))
.attribute("aria-label", props.input_props.aria_label.clone())
.attribute("aria-labelledby", props.input_props.label_id.clone())
.attribute("aria-live", "assertive")
"pwt-dropdown-icon",
"pwt-pointer",
if self.show { "fa-angle-up" } else { "fa-angle-down" },
- disabled.then(|| "disabled"),
+ disabled.then_some("disabled"),
};
let mut select = Container::new()
let selected_el = selected_el.dyn_into::<web_sys::HtmlElement>().unwrap();
if element_is_focusable(&selected_el) {
let _ = el.focus();
- } else {
- if let Some(focusable_el) = get_first_focusable(selected_el.into()) {
- let _ = focusable_el.focus();
- }
+ } else if let Some(focusable_el) = get_first_focusable(selected_el.into()) {
+ let _ = focusable_el.focus();
}
}
}
}
}
-impl Into<VNode> for Fa {
- fn into(self) -> VNode {
- let comp = VComp::new::<PwtFa>(Rc::new(self), None);
+impl From<Fa> for VNode {
+ fn from(val: Fa) -> Self {
+ let comp = VComp::new::<PwtFa>(Rc::new(val), None);
VNode::from(comp)
}
}
}
if let Some(text) = &props.text {
- children.push((&*text).into());
+ children.push(text.into());
}
let (x, y, radius) = self.ripple_pos.unwrap_or((0, 0, 0));
children.push({
Container::new()
.class("pwt-button-ripple")
- .class(self.ripple_pos.is_some().then(|| "animate"))
+ .class(self.ripple_pos.is_some().then_some("animate"))
.style("--pwt-ripple-x", format!("{x}px"))
.style("--pwt-ripple-y", format!("{y}px"))
.style("--pwt-ripple-radius", format!("{radius}px"))
.node_ref(self.input_ref.clone())
.attribute("type", "file")
.attribute("accept", props.accept.clone())
- .attribute("multiple", props.multiple.then(|| ""))
+ .attribute("multiple", props.multiple.then_some(""))
.class("pwt-d-none")
.oncancel(suppress_oncancel)
.onchange({
.children(children)
.tag("label")
.class("pwt-button")
- .class(props.pressed.then(|| "pressed"))
- .attribute("aria-disabled", props.disabled.then(|| "true"))
- .attribute("autofocus", props.autofocus.then(|| ""))
+ .class(props.pressed.then_some("pressed"))
+ .attribute("aria-disabled", props.disabled.then_some("true"))
+ .attribute("autofocus", props.autofocus.then_some(""))
.attribute("aria-label", props.aria_label.clone())
.attribute("tabindex", props.tabindex.map(|i| i.to_string()))
.onpointerdown(ctx.link().callback(Msg::ShowRippleAnimation))
pub box_label: Option<FieldLabel>,
}
+impl Default for Checkbox {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Checkbox {
/// Creates a new instance.
pub fn new() -> Self {
pub trigger: Vec<(Trigger, bool)>,
}
+impl Default for Combobox {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Combobox {
/// Create a new instance.
pub fn new() -> Self {
let props = ctx.props();
let link = ctx.link().clone();
- let show_filter = props.show_filter.unwrap_or_else(|| {
- if self.store.data_len() > 10 {
- true
- } else {
- false
- }
- });
+ let show_filter = props
+ .show_filter
+ .unwrap_or_else(|| self.store.data_len() > 10);
let filter = props.filter.clone();
}
}
+impl Default for FormContext {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl FormContext {
pub fn new() -> Self {
Self {
/// [FormContext] object, so each clone can hold a single on_change
/// callback.
pub fn on_change(mut self, cb: impl IntoEventCallback<FormContext>) -> Self {
- self.on_change = match cb.into_event_callback() {
- Some(cb) => Some(Rc::new(self.add_listener(cb))),
- None => None,
- };
+ self.on_change = cb
+ .into_event_callback()
+ .map(|cb| Rc::new(self.add_listener(cb)));
self
}
}
}
-impl<'a> DerefMut for FormContextWriteGuard<'a> {
+impl DerefMut for FormContextWriteGuard<'_> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.state
}
}
-impl<'a> Drop for FormContextWriteGuard<'a> {
+impl Drop for FormContextWriteGuard<'_> {
fn drop(&mut self) {
let changed = self.state.version != self.initial_version;
unsafe {
name: impl IntoPropValue<AttrValue>,
) -> Option<(Value, Result<(), String>)> {
let name = name.into_prop_value();
- match self.find_field_slab_id(&name) {
- Some(key) => Some(self.get_field_data_by_slab_key(key)),
- None => None,
- }
+ self.find_field_slab_id(&name)
+ .map(|key| self.get_field_data_by_slab_key(key))
}
/// Get the field value.
};
// Are there radio group fields?
- let radio_group_key = group
- .members
- .iter()
- .find(|k| self.fields[**k].radio_group == true);
+ let radio_group_key = group.members.iter().find(|k| self.fields[**k].radio_group);
if let Some(radio_group_key) = radio_group_key {
// Note: we only call set_value for one radio_group member
.members
.iter()
.filter(|k| !self.fields[**k].radio_group)
- .map(|k| *k)
+ .copied()
.collect();
let radio_keys: Vec<usize> = group
.members
.iter()
.filter(|k| self.fields[**k].radio_group)
- .map(|k| *k)
+ .copied()
.collect();
if !radio_keys.is_empty() {
match &field.submit_value {
None => continue,
Some(value) => {
- if !submit_empty & value_is_empty(&value) {
+ if !submit_empty & value_is_empty(value) {
continue;
}
data[name.deref()] = value.clone();
match &field.submit_value {
None => continue,
Some(value) => {
- if !submit_empty & value_is_empty(&value) {
+ if !submit_empty & value_is_empty(value) {
continue;
}
list.push(value.clone());
/// Valid Input types for a [Field]
// taken from https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
// Commented out values would be valid, but don't make sense for the field.
-#[derive(PartialEq, Clone, Copy)]
+#[derive(PartialEq, Clone, Copy, Default)]
pub enum InputType {
//Button,
//Checkbox,
Search,
//Submit,
Tel,
+ #[default]
Text,
Time,
Url,
Week,
}
-impl Default for InputType {
- fn default() -> Self {
- InputType::Text
- }
-}
-
impl Display for InputType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
pub tip: Option<AttrValue>,
}
+impl Default for Field {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Field {
/// Create a new instance.
pub fn new() -> Self {
fn validation_args(props: &Self::Properties) -> Self::ValidateClosure {
ValidateClosure {
required: props.input_props.required,
- input_type: props.input_type.clone(),
+ input_type: props.input_type,
min: props.min,
max: props.max,
validate: props.validate.clone(),
pub form_context: Option<FormContext>,
}
+impl Default for Form {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Form {
/// Creates a new instance.
pub fn new() -> Self {
pub on_change: Option<Callback<Value>>,
}
+impl Default for Hidden {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Hidden {
/// Creates a new instance.
pub fn new() -> Self {
type Message = ();
type ValidateClosure = ();
- fn validation_args(_props: &Self::Properties) -> Self::ValidateClosure {
- ()
- }
+ fn validation_args(_props: &Self::Properties) -> Self::ValidateClosure {}
fn setup(props: &Hidden) -> ManagedFieldState {
let mut value = Value::Null;
/// Current field state.
pub fn state(&self) -> &ManagedFieldState {
- &self.comp_state
+ self.comp_state
}
}
}) as Box<dyn Fn()>
});
- if let Some(el) = document.get_element_by_id(&label_id) {
+ if let Some(el) = document.get_element_by_id(label_id) {
let _ = el.add_event_listener_with_callback(
"click",
label_clicked_closure.as_ref().unchecked_ref(),
match value {
Value::Number(n) => match n.as_f64() {
Some(n) => Ok(n),
- None => return Err(Error::msg(tr!("cannot represent number as f64"))),
+ None => Err(Error::msg(tr!("cannot represent number as f64"))),
},
Value::String(s) => {
// Note: this handles localized number format
- let number = crate::dom::parse_float(s).map_err(|err| Error::msg(err))?;
+ let number = crate::dom::parse_float(s).map_err(Error::msg)?;
- return Ok(number);
+ Ok(number)
}
- _ => return Err(Error::msg(tr!("got wrong data type"))),
+ _ => Err(Error::msg(tr!("got wrong data type"))),
}
}
fn number_to_value(&self) -> Value {
pub on_input: Option<Callback<(String, Option<T>)>>,
}
+impl<T: NumberTypeInfo> Default for Number<T> {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl<T: NumberTypeInfo> Number<T> {
/// Create a new instance.
pub fn new() -> Self {
value = force_value.to_string().into();
}
- let value: Value = value.clone().into();
+ let value: Value = value.clone();
let default = match props.default {
Some(default) => T::number_to_value(&default),
move |event: KeyboardEvent| match event.key().as_str() {
"ArrowDown" => link.send_message(Msg::Down),
"ArrowUp" => link.send_message(Msg::Up),
- _ => return,
+ _ => (),
}
})
.onwheel({
pub class: Classes,
}
+impl Default for ResetButton {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl ResetButton {
/// Create a new instance.
pub fn new() -> Self {
}
}
-impl Into<VNode> for ResetButton {
- fn into(self) -> VNode {
- let comp = VComp::new::<PwtResetButton>(Rc::new(self), None);
+impl From<ResetButton> for VNode {
+ fn from(val: ResetButton) -> Self {
+ let comp = VComp::new::<PwtResetButton>(Rc::new(val), None);
VNode::from(comp)
}
}
if !props.store.is_empty() {
if let Some(validate) = &props.validate {
- validate.apply(&(value.clone().into(), props.store.clone()))?;
+ validate.apply(&(value.clone(), props.store.clone()))?;
}
} else {
// Return Ok if we have no data (i.e. because eof load error),
let state = ctx.state();
let value = state.value.as_str().unwrap_or("").to_owned();
- if self.load_error.is_none() {
- if value.is_empty() {
- let mut default = props.default.clone();
+ if self.load_error.is_none() && value.is_empty() {
+ let mut default = props.default.clone();
- if default.is_none() && props.autoselect {
- if let Some((_pos, node)) = props.store.filtered_data().next() {
- default = Some(AttrValue::from(node.key().to_string()));
- }
+ if default.is_none() && props.autoselect {
+ if let Some((_pos, node)) = props.store.filtered_data().next() {
+ default = Some(AttrValue::from(node.key().to_string()));
}
+ }
- if let Some(default) = default {
- ctx.link().update_value(default.to_string());
- ctx.link().update_default(default.to_string());
- }
+ if let Some(default) = default {
+ ctx.link().update_value(default.to_string());
+ ctx.link().update_default(default.to_string());
}
}
ctx.link().validate(); // re-evaluate
pub class: Classes,
}
+impl Default for SubmitButton {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl SubmitButton {
/// Createa new instance.
pub fn new() -> Self {
}
}
-impl Into<VNode> for SubmitButton {
- fn into(self) -> VNode {
- let comp = VComp::new::<PwtSubmitButton>(Rc::new(self), None);
+impl From<SubmitButton> for VNode {
+ fn from(val: SubmitButton) -> Self {
+ let comp = VComp::new::<PwtSubmitButton>(Rc::new(val), None);
VNode::from(comp)
}
}
pub on_input: Option<Callback<String>>,
}
+impl Default for TextArea {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl TextArea {
/// Create a new instance.
pub fn new() -> Self {
pub on_change: Option<Callback<Tristate>>,
}
+impl Default for TristateBoolean {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl TristateBoolean {
/// Create a new instance.
pub fn new() -> Self {
// fixme: value = force_value.to_string();
//}
- let value: Value = value.clone().into();
+ let value: Value = value.clone();
let default = match props.default {
None => Value::Null,
fn create(ctx: &Context<Self>) -> Self {
let props = ctx.props();
let on_select = props.on_select.clone();
- let selection = props
- .selection
- .clone()
- .unwrap_or_else(|| Selection::new())
- .on_select(move |s: Selection| {
- if let Some(key) = s.selected_key() {
- if let Some(on_select) = &on_select {
- on_select.emit(key);
+ let selection =
+ props
+ .selection
+ .clone()
+ .unwrap_or_default()
+ .on_select(move |s: Selection| {
+ if let Some(key) = s.selected_key() {
+ if let Some(on_select) = &on_select {
+ on_select.emit(key);
+ }
}
- }
- });
+ });
let mut me = Self {
_phantom: PhantomData::<S>,
.node_ref(props.node_ref.clone())
.class("pwt-flex-fill pwt-overflow-auto");
- let show_filter = props.show_filter.unwrap_or_else(|| {
- if self.store.data_len() > 10 {
- true
- } else {
- false
- }
- });
+ let show_filter = props
+ .show_filter
+ .unwrap_or_else(|| self.store.data_len() > 10);
if show_filter {
let filter_invalid = false;
"is-valid"
})
.attribute("value", self.filter.clone())
- .attribute("aria-invalid", filter_invalid.then(|| "true"))
+ .attribute("aria-invalid", filter_invalid.then_some("true"))
.oninput(ctx.link().callback(move |event: InputEvent| {
let input: HtmlInputElement = event.target_unchecked_into();
Msg::FilterUpdate(input.value())
}
}
-impl<S: DataStore + 'static> Into<VNode> for GridPicker<S> {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtGridPicker<S>>(Rc::new(self), key);
+impl<S: DataStore + 'static> From<GridPicker<S>> for VNode {
+ fn from(val: GridPicker<S>) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtGridPicker<S>>(Rc::new(val), key);
VNode::from(comp)
}
}
#[derive(Clone, PartialEq, Properties)]
pub struct Input {}
+impl Default for Input {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Input {
/// Creates a new instance.
pub fn new() -> Self {
}
}
-impl Into<VTag> for Input {
- fn into(self) -> VTag {
- let mut attributes = self.std_props.cumulate_attributes(None::<&str>);
+impl From<Input> for VTag {
+ fn from(val: Input) -> Self {
+ let mut attributes = val.std_props.cumulate_attributes(None::<&str>);
let attr_map = attributes.get_mut_index_map();
- self.input_props.cumulate_attributes(attr_map);
+ val.input_props.cumulate_attributes(attr_map);
let value = attr_map
.get(&AttrValue::Static("value"))
let checked = attr_map
.get(&AttrValue::Static("checked"))
.is_some()
- .then(|| true);
+ .then_some(true);
- let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+ let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
VTag::__new_input(
value,
checked,
- self.std_props.node_ref,
- self.std_props.key,
+ val.std_props.node_ref,
+ val.std_props.key,
attributes,
listeners,
)
let style = if visible {
format!("grid-row: {};", row)
} else {
- format!("display: none;")
+ "display: none;".to_string()
};
let label_id = crate::widget::get_unique_element_id();
}
}
-impl Into<VTag> for InputPanel {
- fn into(mut self) -> VTag {
- if self.two_column {
- self.add_class("pwt-form-grid-col4")
+impl From<InputPanel> for VTag {
+ fn from(mut val: InputPanel) -> Self {
+ if val.two_column {
+ val.add_class("pwt-form-grid-col4")
} else {
- self.add_class("pwt-form-grid-col2")
+ val.add_class("pwt-form-grid-col2")
}
- if self.label_width.is_some() || self.field_width.is_some() {
+ if val.label_width.is_some() || val.field_width.is_some() {
let mut column_template = format!(
"{} {}",
- self.label_width
+ val.label_width
.as_deref()
.unwrap_or("minmax(130px, 0.65fr)"),
- self.field_width.as_deref().unwrap_or("minmax(200px, 1fr)")
+ val.field_width.as_deref().unwrap_or("minmax(200px, 1fr)")
);
- if self.two_column {
+ if val.two_column {
column_template = format!(
"{} calc(var(--pwt-spacer-4) * 2) {}",
column_template, column_template
);
}
- self.set_style("grid-template-columns", column_template.to_string());
+ val.set_style("grid-template-columns", column_template.to_string());
}
- let attributes = self.std_props.cumulate_attributes(None::<&str>);
+ let attributes = val.std_props.cumulate_attributes(None::<&str>);
- let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+ let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
- let children = VList::with_children(self.children, None);
+ let children = VList::with_children(val.children, None);
VTag::__new_other(
Cow::Borrowed("div"),
- self.std_props.node_ref,
- self.std_props.key,
+ val.std_props.node_ref,
+ val.std_props.key,
attributes,
listeners,
children.into(),
pub class: Classes,
}
+impl Default for LanguageSelector {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl LanguageSelector {
pub fn new() -> Self {
yew::props!(Self {})
let mut lang = Language::load();
if lang.is_empty() {
- if languages.iter().find(|info| info.lang == "en").is_some() {
+ if languages.iter().any(|info| info.lang == "en") {
lang = "en".into();
} else if let Some(first) = languages.first().map(|info| info.lang.clone()) {
lang = first;
}
}
-impl Into<VNode> for LanguageSelector {
- fn into(self) -> VNode {
- let comp = VComp::new::<PwtLanguageSelector>(Rc::new(self), None);
+impl From<LanguageSelector> for VNode {
+ fn from(val: LanguageSelector) -> Self {
+ let comp = VComp::new::<PwtLanguageSelector>(Rc::new(val), None);
VNode::from(comp)
}
}
}
}
-impl Into<VTag> for ListTile {
- fn into(self) -> VTag {
+impl From<ListTile> for VTag {
+ fn from(val: ListTile) -> Self {
let classes = classes!(
"pwt-list-tile",
- self.interactive.then(|| "pwt-interactive"),
- self.disabled.then(|| "disabled")
+ val.interactive.then_some("pwt-interactive"),
+ val.disabled.then_some("disabled")
);
- self.std_props.into_vtag(
+ val.std_props.into_vtag(
Cow::Borrowed("div"),
Some(classes),
- Some(self.listeners),
- Some(self.children),
+ Some(val.listeners),
+ Some(val.children),
)
}
}
fn _get_row_height(&self, index: usize, min_row_height: u64) -> u64 {
self.height_list
.get(index)
- .map(|v| *v)
+ .copied()
.unwrap_or(min_row_height)
}
.style("top", format!("{}px", self.scroll_info.offset));
let prefetch_count = props.prefetch_count as u64;
- if self.scroll_info.end > self.scroll_info.start {
- if self.scroll_info.start > prefetch_count {
- for index in (self.scroll_info.start - prefetch_count)..self.scroll_info.start {
- // log::info!("ADD CACHED ROW {index}");
-
- let row = ListTileObserver::new(props.renderer.emit(index))
- .key(format!("row-{index}"))
- .force_height(0)
- .tile_pos(index)
- .separator(props.separator)
- .resize_callback(Some(self.tile_resize_callback.clone()));
-
- //row.set_attribute("role", "listitem");
- content.add_child(row);
- }
+ if self.scroll_info.end > self.scroll_info.start && self.scroll_info.start > prefetch_count
+ {
+ for index in (self.scroll_info.start - prefetch_count)..self.scroll_info.start {
+ // log::info!("ADD CACHED ROW {index}");
+
+ let row = ListTileObserver::new(props.renderer.emit(index))
+ .key(format!("row-{index}"))
+ .force_height(0)
+ .tile_pos(index)
+ .separator(props.separator)
+ .resize_callback(Some(self.tile_resize_callback.clone()));
+
+ //row.set_attribute("role", "listitem");
+ content.add_child(row);
}
}
if let Some(el) = &viewport_el {
let link = ctx.link().clone();
let size_observer =
- DomSizeObserver::new(&el, move |(width, height, client_width, _)| {
+ DomSizeObserver::new(el, move |(width, height, client_width, _)| {
link.send_message(Msg::ViewportResize(width, height, width - client_width));
});
self.viewport_size_observer = Some(size_observer);
let mut mask = Container::new()
.class("pwt-load-mask")
- .class(props.visible.then(|| "visible"));
+ .class(props.visible.then_some("visible"));
if props.visible {
mask.add_child(
impl PwtMenuButton {
fn restore_focus(&mut self, props: &MenuButton) {
if let Some(node) = props.std_props.node_ref.get() {
- if let Some(el) = node.dyn_into::<web_sys::HtmlElement>().ok() {
+ if let Ok(el) = node.dyn_into::<web_sys::HtmlElement>() {
let _ = el.focus();
}
}
.menu_controller(self.menu_controller.clone())
.on_close(ctx.link().callback(|_| Msg::CloseMenu)),
)
- } else if let Some(m) = &props.menu {
- Some(
+ } else {
+ props.menu.as_ref().map(|m| {
m.clone()
.autofocus(true)
.menu_controller(self.menu_controller.clone())
- .on_close(ctx.link().callback(|_| Msg::CloseMenu)),
- )
- } else {
- None
+ .on_close(ctx.link().callback(|_| Msg::CloseMenu))
+ })
};
Container::new()
let mut button = Button::new(&props.text)
.show_arrow(props.show_arrow)
.attribute("aria-haspopup", "true")
- .attribute("aria-expanded", self.show_submenu.then(|| "true"))
+ .attribute("aria-expanded", self.show_submenu.then_some("true"))
.tabindex(props.tabindex)
.icon_class(props.icon_class.clone());
type Properties = MenuCheckbox;
type ValidateClosure = ();
- fn validation_args(_props: &Self::Properties) -> Self::ValidateClosure {
- ()
- }
+ fn validation_args(_props: &Self::Properties) -> Self::ValidateClosure {}
fn setup(props: &MenuCheckbox) -> ManagedFieldState {
let on_value = props.value.as_deref().unwrap_or("on").to_string();
} else {
"fa-circle-o"
}
+ } else if checked {
+ "fa-check-square-o"
} else {
- if checked {
- "fa-check-square-o"
- } else {
- "fa-square-o"
- }
+ "fa-square-o"
},
"pwt-menu-item-icon",
);
Container::new()
.class("pwt-menu-item")
- .attribute("tabindex", (!disabled).then(|| "-1"))
- .attribute("aria-disabled", disabled.then(|| "true"))
+ .attribute("tabindex", (!disabled).then_some("-1"))
+ .attribute("aria-disabled", disabled.then_some("true"))
.attribute(
"role",
if props.radio_group {
"menuitemcheckbox"
},
)
- .attribute("aria-checked", checked.then(|| "true"))
+ .attribute("aria-checked", checked.then_some("true"))
.onclick(onclick)
.onkeydown(onkeydown)
.with_child(icon)
}
}
-impl Into<VNode> for MenuCheckbox {
- fn into(self) -> VNode {
- let comp = VComp::new::<ManagedFieldMaster<MenuCheckboxField>>(Rc::new(self), None);
+impl From<MenuCheckbox> for VNode {
+ fn from(val: MenuCheckbox) -> Self {
+ let comp = VComp::new::<ManagedFieldMaster<MenuCheckboxField>>(Rc::new(val), None);
VNode::from(comp)
}
}
} else {
"pwt-menu-item"
})
- .attribute("tabindex", (!props.focusable).then(|| "-1"))
- .attribute("aria-disabled", props.disabled.then(|| "true"))
+ .attribute("tabindex", (!props.focusable).then_some("-1"))
+ .attribute("aria-disabled", props.disabled.then_some("true"))
.attribute("role", "menuitem")
- .attribute("aria-haspopup", has_submenu.then(|| "true"))
+ .attribute("aria-haspopup", has_submenu.then_some("true"))
.attribute(
"aria-expanded",
- has_submenu.then(|| if show_submenu { "true" } else { "false" }),
+ has_submenu.then_some(if show_submenu { "true" } else { "false" }),
)
.with_optional_child(icon)
.with_child(html! {<span class="pwt-flex-fill">{props.text.clone()}</span>})
}
}
-impl Into<VNode> for MenuItem {
- fn into(self) -> VNode {
- let comp = VComp::new::<PwtMenuItem>(Rc::new(self), None);
+impl From<MenuItem> for VNode {
+ fn from(val: MenuItem) -> Self {
+ let comp = VComp::new::<PwtMenuItem>(Rc::new(val), None);
VNode::from(comp)
}
}
}
}
+impl Default for Menu {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Menu {
/// Create a new instance.
pub fn new() -> Self {
None => return false,
};
- let res = match focus_el.focus() {
- Ok(_) => true,
- Err(_) => false,
- };
+ let res = focus_el.focus().is_ok();
if has_focus {
//log::info!("FOCUS {:?}", focus_el);
self.set_cursor(cursor, true);
}
//log::info!("CLOSE {} {} {}", self.unique_id, self.show_submenu, self.inside_submenu);
- return true;
+ true
}
Msg::Redraw => true,
Msg::Next => {
}
}
None => {
- if props.children.len() == 0 {
+ if props.children.is_empty() {
return false;
} else {
props.children.len() - 1
}
}
- if show == false {
+ if !show {
if let Some(on_close) = &props.on_close {
//log::info!("PROPAGATE CLOSE {} {}", self.unique_id, show);
on_close.emit(());
.attribute("id", item_id.clone())
.attribute("data-index", i.to_string()) // fixme: remove
.attribute("role", "none")
- .class((active).then(|| "active"))
+ .class((active).then_some("active"))
.with_child(child)
.onkeydown({
let link = ctx.link().clone();
}
}
-impl Into<VNode> for Menu {
- fn into(self) -> VNode {
- let comp = VComp::new::<PwtMenu>(Rc::new(self), None);
+impl From<Menu> for VNode {
+ fn from(val: Menu) -> Self {
+ let comp = VComp::new::<PwtMenu>(Rc::new(val), None);
VNode::from(comp)
}
}
}
}
-impl Into<VTag> for Meter {
- fn into(self) -> VTag {
- let percentage = ((self.value - self.min).max(0.0) / (self.max - self.min)).clamp(0.0, 1.0);
+impl From<Meter> for VTag {
+ fn from(val: Meter) -> Self {
+ let percentage = ((val.value - val.min).max(0.0) / (val.max - val.min)).clamp(0.0, 1.0);
- let distance_to_optimum = if let Some(optimum) = self.optimum {
- if optimum > self.value {
- self.get_range_index(optimum) - self.get_range_index(self.value)
+ let distance_to_optimum = if let Some(optimum) = val.optimum {
+ if optimum > val.value {
+ val.get_range_index(optimum) - val.get_range_index(val.value)
} else {
- self.get_range_index(self.value) - self.get_range_index(optimum)
+ val.get_range_index(val.value) - val.get_range_index(optimum)
}
} else {
0
let mut children = Vec::new();
let mut class = classes!("pwt-meter");
- if let Some(render_text) = &self.render_text {
- let text = render_text.apply(&self.value);
+ if let Some(render_text) = &val.render_text {
+ let text = render_text.apply(&val.value);
children.push(
Container::new()
.class("pwt-meter-text")
class.push("pwt-meter-small")
}
- if self.animated {
+ if val.animated {
class.push("pwt-animated");
}
.into(),
);
- self.std_props
+ val.std_props
.into_vtag(Cow::Borrowed("div"), Some(class), None, Some(children))
}
}
let left = Container::new()
.node_ref(self.handle_ref.clone())
.class("pwt-mini-scroll-left-arrow")
- .class(arrow_visible.then(|| "visible"))
- .class((self.pos <= 0.0).then(|| "disabled"))
+ .class(arrow_visible.then_some("visible"))
+ .class((self.pos <= 0.0).then_some("disabled"))
.with_child(html! {<i class="fa fa-chevron-left"/>})
.onpointerdown(ctx.link().callback(|_| Msg::ScrollLeft))
.onpointerout(ctx.link().callback(|_| Msg::ScrollStop))
let right = Container::new()
.class("pwt-mini-scroll-right-arrow")
- .class(arrow_visible.then(|| "visible"))
- .class((self.pos >= 1.0).then(|| "disabled"))
+ .class(arrow_visible.then_some("visible"))
+ .class((self.pos >= 1.0).then_some("disabled"))
.with_child(html! {<i class="fa fa-chevron-right"/>})
.onpointerdown(ctx.link().callback(|_| Msg::ScrollRight))
.onpointerout(ctx.link().callback(|_| Msg::ScrollStop))
pub children: Vec<MenuEntry>,
}
+impl Default for Menu {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Menu {
/// Create a new instance.
pub fn new() -> Self {
html! {<span style={format!("width: {}rem", (indent_level as f32) * 1.0)}/>}
}))
// add optional icon on the left
- .with_optional_child(item.icon_class.as_ref().and_then(|icon| {
- Some(html! { <i class={classes!(icon.to_string(), "pwt-nav-menu-icon")}/>})
- }))
+ .with_optional_child(
+ item.icon_class.as_ref().map(
+ |icon| html! { <i class={classes!(icon.to_string(), "pwt-nav-menu-icon")}/>},
+ ),
+ )
// add memu label
.with_child(html! {<div class="pwt-text-truncate pwt-flex-fill">{&item.label}</div>})
// add optional menu-open icon
fn find_item_recursive<'a>(menu: &'a [MenuEntry], desired: &Key) -> Option<&'a MenuEntry> {
for menu in menu.iter() {
- match menu {
- MenuEntry::Item(item) => {
- if item.key.as_ref() == Some(desired) {
- return Some(menu);
- }
+ if let MenuEntry::Item(item) = menu {
+ if item.key.as_ref() == Some(desired) {
+ return Some(menu);
+ }
- if let Some(submenu) = &item.submenu {
- let res = find_item_recursive(&submenu.children[..], desired);
- if res.is_some() {
- return res;
- }
+ if let Some(submenu) = &item.submenu {
+ let res = find_item_recursive(&submenu.children[..], desired);
+ if res.is_some() {
+ return res;
}
}
- _ => {}
};
}
None
}
- match find_item_recursive(&props.menu.children, &desired) {
+ match find_item_recursive(&props.menu.children, desired) {
Some(entry @ MenuEntry::Item(item)) => match &item.submenu {
- None => item.selectable.then(|| entry),
+ None => item.selectable.then_some(entry),
Some(submenu) => {
if item.selectable {
Some(entry)
None
};
- if &self.active == &key {
+ if self.active == key {
return false;
}
}
if let Some(key) = &key {
- self.emit_item_activate(&key, ctx);
+ self.emit_item_activate(key, ctx);
}
if let Some(on_select) = &props.on_select {
}
}
-impl Into<VNode> for NavigationDrawer {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtNavigationDrawer>(Rc::new(self), key);
+impl From<NavigationDrawer> for VNode {
+ fn from(val: NavigationDrawer) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtNavigationDrawer>(Rc::new(val), key);
VNode::from(comp)
}
}
pub header_class: Classes,
}
+impl Default for Panel {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Panel {
/// Creates a new instance.
pub fn new() -> Self {
}
}
-impl Into<VTag> for Panel {
- fn into(mut self) -> VTag {
- self.add_class("pwt-panel");
+impl From<Panel> for VTag {
+ fn from(mut val: Panel) -> Self {
+ val.add_class("pwt-panel");
- if self.title.is_some() || !self.tools.is_empty() {
- let header = create_panel_title(self.title, self.tools)
+ if val.title.is_some() || !val.tools.is_empty() {
+ let header = create_panel_title(val.title, val.tools)
.class("pwt-panel-header")
- .class(self.header_class);
- self.children.insert(0, header.into());
+ .class(val.header_class);
+ val.children.insert(0, header.into());
}
- let attributes = self.std_props.cumulate_attributes(None::<&str>);
+ let attributes = val.std_props.cumulate_attributes(None::<&str>);
- let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+ let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
- let children = VList::with_children(self.children, None);
+ let children = VList::with_children(val.children, None);
VTag::__new_other(
Cow::Borrowed("div"),
- self.std_props.node_ref,
- self.std_props.key,
+ val.std_props.node_ref,
+ val.std_props.key,
attributes,
listeners,
children.into(),
}
}
-impl Into<VTag> for Progress {
- fn into(self) -> VTag {
- let max = self.max.unwrap_or(1.0);
+impl From<Progress> for VTag {
+ fn from(val: Progress) -> Self {
+ let max = val.max.unwrap_or(1.0);
- let bar = match self.value {
+ let bar = match val.value {
Some(value) => {
let percentage = (value / max).clamp(0.0, 1.0);
Container::new()
None => Container::new().class("pwt-progress-infinite").into(),
};
- self.std_props.into_vtag(
+ val.std_props.into_vtag(
Cow::Borrowed("div"),
Some("pwt-progress"),
None,
#[derive(Debug, Clone, PartialEq, Properties)]
pub struct Row {}
+impl Default for Row {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Row {
/// Create a new instance.
pub fn new() -> Self {
}
}
-impl Into<VTag> for Row {
- fn into(self) -> VTag {
- let attributes = self.std_props.cumulate_attributes(None::<&str>);
+impl From<Row> for VTag {
+ fn from(val: Row) -> Self {
+ let attributes = val.std_props.cumulate_attributes(None::<&str>);
- let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+ let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
- let children = VList::with_children(self.children, None);
+ let children = VList::with_children(val.children, None);
VTag::__new_other(
Cow::Borrowed("div"),
- self.std_props.node_ref,
- self.std_props.key,
+ val.std_props.node_ref,
+ val.std_props.key,
attributes,
listeners,
children.into(),
buttons: Vec<Button>,
}
+impl Default for SegmentedButton {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl SegmentedButton {
/// Create a new segmented button.
pub fn new() -> Self {
pub page_cache: bool,
}
+impl Default for SelectionView {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl SelectionView {
/// Creates a new instance.
pub fn new() -> Self {
let _selection_observer = props
.selection
.clone()
- .unwrap_or(Selection::new())
+ .unwrap_or_default()
.add_listener(ctx.link().callback(Msg::SelectionChange));
let (visibility, _visibility_handle) = ctx
self._selection_observer = props
.selection
.clone()
- .unwrap_or(Selection::new())
+ .unwrap_or_default()
.add_listener(ctx.link().callback(Msg::SelectionChange));
}
true
}
}
-impl<W: WidgetBuilder + PartialEq + Clone + 'static> Into<VNode> for SizeObserver<W> {
- fn into(self) -> VNode {
- let key = self.content.as_std_props().key.clone();
- let comp = VComp::new::<PwtSizeObserver<W>>(Rc::new(self), key);
+impl<W: WidgetBuilder + PartialEq + Clone + 'static> From<SizeObserver<W>> for VNode {
+ fn from(val: SizeObserver<W>) -> Self {
+ let key = val.content.as_std_props().key.clone();
+ let comp = VComp::new::<PwtSizeObserver<W>>(Rc::new(val), key);
VNode::from(comp)
}
}
/// Method to set the initial pane size in pixels.
pub fn set_size(&mut self, size: impl IntoPropValue<Option<usize>>) {
- self.size = size.into_prop_value().map(|p| PaneSize::Pixel(p));
+ self.size = size.into_prop_value().map(PaneSize::Pixel);
}
/// Builder style method to set the initial pane size as flex.
/// Method to set the initial pane size as flex.
pub fn set_flex(&mut self, flex: impl IntoPropValue<Option<usize>>) {
- self.size = flex.into_prop_value().map(|f| PaneSize::Flex(f));
+ self.size = flex.into_prop_value().map(PaneSize::Flex);
}
/// Builder style method to set the initial pane size as fraction.
/// Method to set the initial pane size as fraction.
pub fn set_fraction(&mut self, fraction: impl IntoPropValue<Option<f64>>) {
- self.size = fraction.into_prop_value().map(|f| PaneSize::Fraction(f));
+ self.size = fraction.into_prop_value().map(PaneSize::Fraction);
}
/// Builder style method to set the minimal pane size in pixels.
/// Method to set the minimal pane size in pixels.
pub fn set_min_size(&mut self, size: impl IntoPropValue<Option<usize>>) {
- self.min_size = size.into_prop_value().map(|p| PaneSize::Pixel(p));
+ self.min_size = size.into_prop_value().map(PaneSize::Pixel);
}
/// Builder style method to set the minimal pane size as fraction.
/// Method to set the minimal pane size as fraction.
pub fn set_min_fraction(&mut self, fraction: impl IntoPropValue<Option<f64>>) {
- self.min_size = fraction.into_prop_value().map(|f| PaneSize::Fraction(f));
+ self.min_size = fraction.into_prop_value().map(PaneSize::Fraction);
}
/// Builder style method to set the maximal pane size in pixels.
/// Method to set the maximal pane size in pixels.
pub fn set_max_size(&mut self, size: impl IntoPropValue<Option<usize>>) {
- self.max_size = size.into_prop_value().map(|p| PaneSize::Pixel(p));
+ self.max_size = size.into_prop_value().map(PaneSize::Pixel);
}
/// Builder style method to set the maximal pane size as fraction.
/// Method to set the maximal pane size as fraction.
pub fn set_max_fraction(&mut self, fraction: impl IntoPropValue<Option<f64>>) {
- self.max_size = fraction.into_prop_value().map(|f| PaneSize::Fraction(f));
+ self.max_size = fraction.into_prop_value().map(PaneSize::Fraction);
}
/// Builder style method to add a html class
pub handle_size: usize,
}
+impl Default for SplitPane {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl SplitPane {
/// Creates a new instance
pub fn new() -> Self {
.unwrap_or(f64::MAX);
let size = new_size.min(max).max(min);
- let diff = size - current_size;
- diff
+ size - current_size
}
fn resize_pane(&mut self, props: &SplitPane, child_index: usize, new_size1: f64) -> bool {
let fraction = (width > 0f64).then(|| position / width);
children.push(self.create_splitter(ctx, i - 1, fraction));
}
- position += self.sizes.get(i).map(|s| *s).unwrap_or(0.0);
- children.push(self.create_pane(ctx, i, &child))
+ position += self.sizes.get(i).copied().unwrap_or(0.0);
+ children.push(self.create_pane(ctx, i, child))
}
let mut container = yew::props!(Container {
.map(|state_id| PersistentState::<String>::new(state_id.clone()));
if let Some(active_cache) = &active_cache {
- let last_active: &str = &*active_cache;
+ let last_active: &str = active_cache;
if !last_active.is_empty() {
active = Some(Key::from(last_active));
}
let key = selection.selected_key();
let key = get_active_or_default(props, &key);
- if &self.active == &key {
+ if self.active == key {
return false;
}
if let Some(key) = &self.active {
if props.router {
- ctx.link().push_relative_route(&key);
+ ctx.link().push_relative_route(key);
}
}
if let Some(on_select) = &props.on_select {
// Handle internal selection changes
Msg::Select(key, update_route) => {
let key = get_active_or_default(props, &key);
- if &self.active == &key {
+ if self.active == key {
return false;
}
}
}
-impl Into<VNode> for TabBar {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtTabBar>(Rc::new(self), key);
+impl From<TabBar> for VNode {
+ fn from(val: TabBar) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtTabBar>(Rc::new(val), key);
VNode::from(comp)
}
}
pub disabled: bool,
}
+impl Default for TabBarItem {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl TabBarItem {
/// Create a new instance.
pub fn new() -> Self {
pub tab_bar_style: TabBarStyle,
}
+impl Default for TabPanel {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl TabPanel {
/// Creates a new instance.
pub fn new() -> Self {
}
}
-impl Into<VNode> for TabPanel {
- fn into(self) -> VNode {
- let key = self.key.clone();
- let comp = VComp::new::<PwtTabPanel>(Rc::new(self), key);
+impl From<TabPanel> for VNode {
+ fn from(val: TabPanel) -> Self {
+ let key = val.key.clone();
+ let comp = VComp::new::<PwtTabPanel>(Rc::new(val), key);
VNode::from(comp)
}
}
class: Classes,
}
+impl Default for ThemeDensitySelector {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl ThemeDensitySelector {
pub fn new() -> Self {
yew::props!(Self {})
}
}
-impl Into<VNode> for ThemeDensitySelector {
- fn into(self) -> VNode {
- let comp = VComp::new::<PwtThemeDensitySelector>(Rc::new(self), None);
+impl From<ThemeDensitySelector> for VNode {
+ fn from(val: ThemeDensitySelector) -> Self {
+ let comp = VComp::new::<PwtThemeDensitySelector>(Rc::new(val), None);
VNode::from(comp)
}
}
}
}
-impl Into<VNode> for ThemeLoader {
- fn into(self) -> VNode {
- let comp = VComp::new::<PwtThemeLoader>(Rc::new(self), None);
+impl From<ThemeLoader> for VNode {
+ fn from(val: ThemeLoader) -> Self {
+ let comp = VComp::new::<PwtThemeLoader>(Rc::new(val), None);
VNode::from(comp)
}
}
class: Classes,
}
+impl Default for ThemeModeSelector {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl ThemeModeSelector {
pub fn new() -> Self {
yew::props!(Self {})
ThemeMode::Dark => ThemeMode::Light,
ThemeMode::Light => ThemeMode::System,
};
- return yew::Component::update(self, ctx, Msg::SetThemeMode(theme));
+ yew::Component::update(self, ctx, Msg::SetThemeMode(theme))
}
Msg::SetThemeMode(theme) => {
if let Err(err) = Theme::store_theme_mode(theme) {
}
}
-impl Into<VNode> for ThemeModeSelector {
- fn into(self) -> VNode {
- let comp = VComp::new::<PwtThemeModeSelector>(Rc::new(self), None);
+impl From<ThemeModeSelector> for VNode {
+ fn from(val: ThemeModeSelector) -> Self {
+ let comp = VComp::new::<PwtThemeModeSelector>(Rc::new(val), None);
VNode::from(comp)
}
}
class: Classes,
}
+impl Default for ThemeNameSelector {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl ThemeNameSelector {
pub fn new() -> Self {
yew::props!(Self {})
Combobox::new()
.node_ref(self.combobox_ref.clone())
.class(props.class.clone())
- .on_change(ctx.link().callback(|v| Msg::SetThemeName(v)))
+ .on_change(ctx.link().callback(Msg::SetThemeName))
.aria_label("Select Theme")
.default(self.theme.clone())
.required(true)
}
}
-impl Into<VNode> for ThemeNameSelector {
- fn into(self) -> VNode {
- let comp = VComp::new::<PwtThemeNameSelector>(Rc::new(self), None);
+impl From<ThemeNameSelector> for VNode {
+ fn from(val: ThemeNameSelector) -> Self {
+ let comp = VComp::new::<PwtThemeNameSelector>(Rc::new(val), None);
VNode::from(comp)
}
}
pub scroll_mode: Option<MiniScrollMode>,
}
+impl Default for Toolbar {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Toolbar {
/// Create a new instance.
pub fn new() -> Self {
}
}
-impl<W: WidgetBuilder + PartialEq + Clone + 'static> Into<VNode> for VisibilityObserver<W> {
- fn into(self) -> VNode {
- let key = self.content.as_std_props().key.clone();
- let comp = VComp::new::<PwtVisibilityObserver<W>>(Rc::new(self), key);
+impl<W: WidgetBuilder + PartialEq + Clone + 'static> From<VisibilityObserver<W>> for VNode {
+ fn from(val: VisibilityObserver<W>) -> Self {
+ let key = val.content.as_std_props().key.clone();
+ let comp = VComp::new::<PwtVisibilityObserver<W>>(Rc::new(val), key);
VNode::from(comp)
}
}