From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 1F34F1FF17E for ; Thu, 11 Dec 2025 13:59:27 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AA5D8156EF; Thu, 11 Dec 2025 14:00:08 +0100 (CET) From: Dominik Csapak To: yew-devel@lists.proxmox.com Date: Thu, 11 Dec 2025 13:59:28 +0100 Message-ID: <20251211125934.2358700-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.029 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [yew-devel] [PATCH yew-widget-toolkit] props: replace `BuilderFn` with `RenderFn` X-BeenThere: yew-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Yew framework devel list at Proxmox List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Yew framework devel list at Proxmox Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: yew-devel-bounces@lists.proxmox.com Sender: "yew-devel" Since `RenderFn` is now generic also in it's output, we can replace the use of `BuilderFn` with it. Simply using `()` as it's input, and using whatever output we had before. The only slightly awkward changes are: * we now have to use `apply(&())` in this case * when giving a callback to such a builder we have to use `|_: &_|` now, but this was also the case for any closure that got converted into a `RenderFn`. Signed-off-by: Dominik Csapak --- src/props/mod.rs | 2 +- src/props/render_function.rs | 47 ----------------------- src/widget/data_table/header_widget.rs | 2 +- src/widget/data_table/resizable_header.rs | 8 ++-- src/widget/menu/menu_button.rs | 10 ++--- src/widget/menu/split_button.rs | 10 ++--- 6 files changed, 16 insertions(+), 63 deletions(-) diff --git a/src/props/mod.rs b/src/props/mod.rs index 254cb4e..c541110 100644 --- a/src/props/mod.rs +++ b/src/props/mod.rs @@ -200,7 +200,7 @@ mod padding; pub use padding::CssPaddingBuilder; mod render_function; -pub use render_function::{BuilderFn, IntoOptionalBuilderFn, IntoOptionalRenderFn, RenderFn}; +pub use render_function::{IntoOptionalRenderFn, RenderFn}; mod sorter_function; pub use sorter_function::{IntoSorterFn, SorterFn}; diff --git a/src/props/render_function.rs b/src/props/render_function.rs index dd5632d..5caf3c4 100644 --- a/src/props/render_function.rs +++ b/src/props/render_function.rs @@ -46,50 +46,3 @@ impl>> IntoOptionalRenderFn for Opti self.map(|me| me.into()) } } - -/// A [BuilderFn] function is a callback that returns a generic type. -/// -/// Wraps `Rc` around `Fn` so it can be passed as a prop. -#[derive(Derivative)] -#[derivative(Clone(bound = ""), PartialEq(bound = ""))] -pub struct BuilderFn(#[derivative(PartialEq(compare_with = "Rc::ptr_eq"))] Rc T>); - -impl> From> for Html { - fn from(val: BuilderFn) -> Self { - val.apply().into() - } -} - -impl BuilderFn { - /// Creates a new [`BuilderFn`] - pub fn new(builder: impl 'static + Fn() -> T) -> Self { - Self(Rc::new(builder)) - } - /// Apply the builder function - pub fn apply(&self) -> T { - (self.0)() - } -} - -impl T> From for BuilderFn { - fn from(f: F) -> Self { - BuilderFn::new(f) - } -} - -/// Helper trait to create an optional [BuilderFn] property. -pub trait IntoOptionalBuilderFn { - fn into_optional_builder_fn(self) -> Option>; -} - -impl IntoOptionalBuilderFn for Option> { - fn into_optional_builder_fn(self) -> Option> { - self - } -} - -impl T> IntoOptionalBuilderFn for F { - fn into_optional_builder_fn(self) -> Option> { - Some(BuilderFn::new(self)) - } -} diff --git a/src/widget/data_table/header_widget.rs b/src/widget/data_table/header_widget.rs index c1fd806..c4a5541 100644 --- a/src/widget/data_table/header_widget.rs +++ b/src/widget/data_table/header_widget.rs @@ -311,7 +311,7 @@ impl PwtHeaderWidget { let headers = Rc::clone(&props.headers); let link = link.clone(); let hidden_cells = self.state.hidden_cells(); - move || build_header_menu(&headers, &link, cell_idx, &hidden_cells) + move |_: &_| build_header_menu(&headers, &link, cell_idx, &hidden_cells) }), ) .onfocusin(link.callback(move |_| Msg::FocusCell(cell_idx))) diff --git a/src/widget/data_table/resizable_header.rs b/src/widget/data_table/resizable_header.rs index 301adce..88d624f 100644 --- a/src/widget/data_table/resizable_header.rs +++ b/src/widget/data_table/resizable_header.rs @@ -12,7 +12,7 @@ use crate::css::ColorScheme; use crate::dom::element_direction_rtl; use crate::dom::focus::FocusTracker; use crate::dom::DomSizeObserver; -use crate::props::{BuilderFn, IntoOptionalBuilderFn}; +use crate::props::{IntoOptionalRenderFn, RenderFn}; use crate::widget::menu::{Menu, MenuButton, MenuController}; use crate::widget::{Container, Row}; use crate::{impl_class_prop_builder, impl_yew_std_props_builder, prelude::*}; @@ -53,7 +53,7 @@ pub struct ResizableHeader { /// Function to generate the header menu. #[prop_or_default] - pub menu_builder: Option>, + pub menu_builder: Option>, } impl Default for ResizableHeader { @@ -135,8 +135,8 @@ impl ResizableHeader { } /// Builder style method to set the menu builder. - pub fn menu_builder(mut self, builder: impl IntoOptionalBuilderFn) -> Self { - self.menu_builder = builder.into_optional_builder_fn(); + pub fn menu_builder(mut self, builder: impl IntoOptionalRenderFn<(), Menu>) -> Self { + self.menu_builder = builder.into_optional_render_fn(); self } } diff --git a/src/widget/menu/menu_button.rs b/src/widget/menu/menu_button.rs index 7428ce4..b3ca233 100644 --- a/src/widget/menu/menu_button.rs +++ b/src/widget/menu/menu_button.rs @@ -5,7 +5,7 @@ use yew::prelude::*; use crate::dom::focus::FocusTracker; use crate::prelude::*; -use crate::props::{BuilderFn, IntoOptionalBuilderFn}; +use crate::props::{IntoOptionalRenderFn, RenderFn}; use crate::state::SharedStateObserver; use crate::widget::menu::MenuController; use crate::widget::{Button, Container}; @@ -37,7 +37,7 @@ pub struct MenuButton { /// To create menus dynamically. If specified, the 'menu' property /// is ignored. #[prop_or_default] - pub menu_builder: Option>, + pub menu_builder: Option>, /// Automatically popup menu when receiving focus /// @@ -94,8 +94,8 @@ impl MenuButton { } /// Builder style method to set the menu builder. - pub fn menu_builder(mut self, builder: impl IntoOptionalBuilderFn) -> Self { - self.menu_builder = builder.into_optional_builder_fn(); + pub fn menu_builder(mut self, builder: impl IntoOptionalRenderFn<(), Menu>) -> Self { + self.menu_builder = builder.into_optional_render_fn(); self } } @@ -223,7 +223,7 @@ impl Component for PwtMenuButton { let menu = if let Some(menu_builder) = &props.menu_builder { Some( menu_builder - .apply() + .apply(&()) .autofocus(true) .menu_controller(self.menu_controller.clone()) .on_close(ctx.link().callback(|_| Msg::CloseMenu)), diff --git a/src/widget/menu/split_button.rs b/src/widget/menu/split_button.rs index fb84734..32b0336 100644 --- a/src/widget/menu/split_button.rs +++ b/src/widget/menu/split_button.rs @@ -5,7 +5,7 @@ use yew::prelude::*; use crate::dom::focus::FocusTracker; use crate::prelude::*; -use crate::props::{BuilderFn, IntoOptionalBuilderFn}; +use crate::props::{IntoOptionalRenderFn, RenderFn}; use crate::state::SharedStateObserver; use crate::widget::menu::MenuController; use crate::widget::{Button, Container}; @@ -39,7 +39,7 @@ pub struct SplitButton { /// To create menus dynamically. If specified, the 'menu' property /// is ignored. #[prop_or_default] - pub menu_builder: Option>, + pub menu_builder: Option>, #[prop_or_default] #[builder] @@ -88,8 +88,8 @@ impl SplitButton { } /// Builder style method to set the menu builder. - pub fn menu_builder(mut self, builder: impl IntoOptionalBuilderFn) -> Self { - self.menu_builder = builder.into_optional_builder_fn(); + pub fn menu_builder(mut self, builder: impl IntoOptionalRenderFn<(), Menu>) -> Self { + self.menu_builder = builder.into_optional_render_fn(); self } } @@ -234,7 +234,7 @@ impl Component for PwtSplitButton { let menu = if let Some(menu_builder) = &props.menu_builder { Some( menu_builder - .apply() + .apply(&()) .autofocus(true) .menu_controller(self.menu_controller.clone()) .on_close(ctx.link().callback(|_| Msg::CloseMenu)), -- 2.47.3 _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel