From 4954e18af4f68ea92133ef560452b95c528f1bfb Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 15 Jan 2025 16:54:14 -0300 Subject: [PATCH] More feature optimization (#595) --- crates/zng-wgt-button/Cargo.toml | 7 ++++++- crates/zng-wgt-button/src/lib.rs | 15 +++++++++++++-- crates/zng-wgt-inspector/src/lib.rs | 1 - crates/zng-wgt-inspector/src/live.rs | 2 ++ crates/zng-wgt-window/Cargo.toml | 2 +- crates/zng/Cargo.toml | 14 +++++++++----- crates/zng/src/config.rs | 1 + crates/zng/src/lib.rs | 8 ++++++-- crates/zng/src/window.rs | 3 ++- 9 files changed, 40 insertions(+), 13 deletions(-) diff --git a/crates/zng-wgt-button/Cargo.toml b/crates/zng-wgt-button/Cargo.toml index b853ea37e..8340344c8 100644 --- a/crates/zng-wgt-button/Cargo.toml +++ b/crates/zng-wgt-button/Cargo.toml @@ -11,6 +11,11 @@ repository = "https://github.com/zng-ui/zng" categories = ["gui"] keywords = ["gui", "ui", "user-interface", "zng"] +[features] +default = ["tooltip"] +# Enable tooltip in cmd buttons. +tooltip = ["dep:zng-wgt-tooltip"] + [dependencies] zng-var = { path = "../zng-var", version = "0.5.14" } zng-app = { path = "../zng-app", version = "0.14.5" } @@ -23,4 +28,4 @@ zng-wgt-access = { path = "../zng-wgt-access", version = "0.3.5" } zng-wgt-fill = { path = "../zng-wgt-fill", version = "0.3.5" } zng-wgt-filter = { path = "../zng-wgt-filter", version = "0.3.5" } zng-wgt-text = { path = "../zng-wgt-text", version = "0.5.6" } -zng-wgt-tooltip = { path = "../zng-wgt-tooltip", version = "0.5.6" } +zng-wgt-tooltip = { path = "../zng-wgt-tooltip", version = "0.5.6", optional = true } diff --git a/crates/zng-wgt-button/src/lib.rs b/crates/zng-wgt-button/src/lib.rs index 0dc23efc5..fc219ce8f 100644 --- a/crates/zng-wgt-button/src/lib.rs +++ b/crates/zng-wgt-button/src/lib.rs @@ -11,7 +11,7 @@ zng_wgt::enable_widget_macros!(); -use std::{any::TypeId, ops}; +use std::any::TypeId; use colors::{ACCENT_COLOR_VAR, BASE_COLOR_VAR}; use zng_app::event::CommandParam; @@ -31,6 +31,8 @@ use zng_wgt_input::{ }; use zng_wgt_style::{impl_style_fn, style_fn, Style, StyleMix}; use zng_wgt_text::{font_color, underline, Text, FONT_COLOR_VAR}; + +#[cfg(feature = "tooltip")] use zng_wgt_tooltip::{tooltip, tooltip_fn, Tip, TooltipArgs}; /// A clickable container. @@ -80,7 +82,10 @@ impl Button { let on_click = wgt.property(property_id!(Self::on_click)).is_none(); let on_disabled_click = wgt.property(property_id!(on_disabled_click)).is_none(); + #[cfg(feature = "tooltip")] let tooltip = wgt.property(property_id!(tooltip)).is_none() && wgt.property(property_id!(tooltip_fn)).is_none(); + #[cfg(not(feature = "tooltip"))] + let tooltip = false; if on_click || on_disabled_click || tooltip { wgt.push_intrinsic( NestGroup::EVENT, @@ -120,6 +125,7 @@ impl Button { ) .boxed(); } + #[cfg(feature = "tooltip")] if tooltip { child = self::tooltip_fn( child, @@ -161,11 +167,13 @@ context_var! { pub static CMD_CHILD_FN_VAR: WidgetFn = WidgetFn::new(default_cmd_child_fn); /// Widget function used when `cmd` is set and `tooltip_fn`, `tooltip` are not set. + #[cfg(feature = "tooltip")] pub static CMD_TOOLTIP_FN_VAR: WidgetFn = WidgetFn::new(default_cmd_tooltip_fn); static CMD_VAR: Option = None; } +#[cfg(feature = "tooltip")] /// Arguments for [`cmd_tooltip_fn`]. /// /// [`cmd_tooltip_fn`]: fn@cmd_tooltip_fn @@ -176,7 +184,8 @@ pub struct CmdTooltipArgs { /// The command. pub cmd: Command, } -impl ops::Deref for CmdTooltipArgs { +#[cfg(feature = "tooltip")] +impl std::ops::Deref for CmdTooltipArgs { type Target = TooltipArgs; fn deref(&self) -> &Self::Target { @@ -189,6 +198,7 @@ pub fn default_cmd_child_fn(cmd: Command) -> impl UiNode { Text!(cmd.name()) } +#[cfg(feature = "tooltip")] /// Default [`CMD_TOOLTIP_FN_VAR`]. pub fn default_cmd_tooltip_fn(args: CmdTooltipArgs) -> impl UiNode { let info = args.cmd.info(); @@ -272,6 +282,7 @@ pub fn cmd_child_fn(child: impl UiNode, cmd_child: impl IntoVar