Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More feature optimization #595

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/zng-wgt-button/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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 }
15 changes: 13 additions & 2 deletions crates/zng-wgt-button/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -120,6 +125,7 @@ impl Button {
)
.boxed();
}
#[cfg(feature = "tooltip")]
if tooltip {
child = self::tooltip_fn(
child,
Expand Down Expand Up @@ -161,11 +167,13 @@ context_var! {
pub static CMD_CHILD_FN_VAR: WidgetFn<Command> = 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<CmdTooltipArgs> = WidgetFn::new(default_cmd_tooltip_fn);

static CMD_VAR: Option<Command> = None;
}

#[cfg(feature = "tooltip")]
/// Arguments for [`cmd_tooltip_fn`].
///
/// [`cmd_tooltip_fn`]: fn@cmd_tooltip_fn
Expand All @@ -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 {
Expand All @@ -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();
Expand Down Expand Up @@ -272,6 +282,7 @@ pub fn cmd_child_fn(child: impl UiNode, cmd_child: impl IntoVar<WidgetFn<Command
with_context_var(child, CMD_CHILD_FN_VAR, cmd_child)
}

#[cfg(feature = "tooltip")]
/// Sets the widget function used to produce the button tooltip when [`cmd`] is set and tooltip is not.
///
/// [`cmd`]: fn@cmd
Expand Down
1 change: 0 additions & 1 deletion crates/zng-wgt-inspector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use zng_wgt::{prelude::*, ICONS};
pub mod crash_handler;
pub mod debug;

#[cfg(feature = "live")]
mod live;

command! {
Expand Down
2 changes: 2 additions & 0 deletions crates/zng-wgt-inspector/src/live.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "live")]

use zng_app::access::ACCESS_CLICK_EVENT;
use zng_ext_config::CONFIG;
use zng_ext_input::{
Expand Down
2 changes: 1 addition & 1 deletion crates/zng-wgt-window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ zng-wgt-layer = { path = "../zng-wgt-layer", version = "0.4.5" }
# used only by fallback_chrome
zng-wgt-size-offset = { path = "../zng-wgt-size-offset", version = "0.3.5" }
zng-wgt-stack = { path = "../zng-wgt-stack", version = "0.4.5" }
zng-wgt-button = { path = "../zng-wgt-button", version = "0.5.6" }
zng-wgt-button = { path = "../zng-wgt-button", version = "0.5.6", default-features = false }

serde = { version = "1.0", features = ["derive"] }
paste = "1.0"
Expand Down
14 changes: 9 additions & 5 deletions crates/zng/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ default = [
"clipboard",
"color_filter",
"config",
"settings_editor",
"data_context",
"data_view",
"dialog",
Expand Down Expand Up @@ -84,7 +85,7 @@ dyn_node = ["zng-app/dyn_node"]

# Instrument each property and widget instance with "Inspector" nodes and
# extend windows to be inspected on Ctrl+Shift+I.
inspector = ["zng-app/inspector", "zng-wgt-inspector/live"]
inspector = ["zng-wgt-inspector", "zng-app/inspector", "zng-wgt-inspector/live"]

# Enable hot reload builds.
#
Expand Down Expand Up @@ -262,6 +263,9 @@ fs_watcher = ["dep:zng-ext-fs-watcher"]
# Enable the configuration service.
config = ["dep:zng-ext-config"]

# Enable settings widgets.
settings_editor = ["dep:zng-wgt-settings"]

# Enable data context service and properties.
data_context = ["dep:zng-wgt-data"]

Expand Down Expand Up @@ -311,7 +315,7 @@ stack = ["dep:zng-wgt-stack"]
text_input = ["dep:zng-wgt-text-input"]

# Enable tooltip widget.
tooltip = ["dep:zng-wgt-tooltip"]
tooltip = ["dep:zng-wgt-tooltip", "zng-wgt-button?/tooltip"]

# Enable undo/redo service.
undo = ["dep:zng-ext-undo", "dep:zng-wgt-undo-history", "dep:zng-wgt-undo"]
Expand Down Expand Up @@ -398,7 +402,7 @@ zng-wgt-undo-history = { path = "../zng-wgt-undo-history", version = "0.4.6", op
zng-wgt-image = { path = "../zng-wgt-image", version = "0.4.6", optional = true }
zng-wgt-text = { path = "../zng-wgt-text", version = "0.5.6" }
zng-wgt-text-input = { path = "../zng-wgt-text-input", version = "0.5.6", optional = true }
zng-wgt-button = { path = "../zng-wgt-button", version = "0.5.6", optional = true }
zng-wgt-button = { path = "../zng-wgt-button", version = "0.5.6", default-features = false, optional = true }
zng-wgt-stack = { path = "../zng-wgt-stack", version = "0.4.5", optional = true }
zng-wgt-panel = { path = "../zng-wgt-panel", version = "0.4.6" }
zng-wgt-grid = { path = "../zng-wgt-grid", version = "0.4.5", optional = true }
Expand All @@ -410,8 +414,8 @@ zng-wgt-scroll = { path = "../zng-wgt-scroll", version = "0.5.5", optional = tru
zng-wgt-ansi-text = { path = "../zng-wgt-ansi-text", version = "0.4.6", optional = true }
zng-wgt-tooltip = { path = "../zng-wgt-tooltip", version = "0.5.6", optional = true }
zng-wgt-markdown = { path = "../zng-wgt-markdown", version = "0.4.6", optional = true }
zng-wgt-inspector = { path = "../zng-wgt-inspector", version = "0.3.6" }
zng-wgt-settings = { path = "../zng-wgt-settings", version = "0.2.6" }
zng-wgt-inspector = { path = "../zng-wgt-inspector", version = "0.3.6", optional = true }
zng-wgt-settings = { path = "../zng-wgt-settings", version = "0.2.6", optional = true }
zng-wgt-dialog = { path = "../zng-wgt-dialog", version = "0.2.6", optional = true }
zng-wgt-progress = { path = "../zng-wgt-progress", version = "0.2.6", optional = true }
zng-wgt-slider = { path = "../zng-wgt-slider", version = "0.2.5", optional = true }
Expand Down
1 change: 1 addition & 0 deletions crates/zng/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pub mod settings {
/// # Full API
///
/// See [`zng_wgt_settings`] for the full settings editor API.
#[cfg(feature = "settings_editor")]
pub mod editor {
pub use zng_wgt_settings::{
categories_list_fn, category_header_fn, category_item_fn, setting_fn, settings_fn, CategoriesListArgs, CategoryHeaderArgs,
Expand Down
8 changes: 6 additions & 2 deletions crates/zng/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ mod __prelude {
#[cfg(feature = "data_view")]
pub use zng_wgt_data_view::{DataView, DataViewArgs};

#[cfg(feature = "settings_editor")]
pub use zng_wgt_settings::SettingBuilderEditorExt as _;

#[cfg(feature = "dialog")]
Expand Down Expand Up @@ -1004,8 +1005,11 @@ mod defaults {
}

// setup SETTINGS_CMD handler
zng_wgt_settings::handle_settings_cmd();
tracing::debug!("defaults init, settings set");
#[cfg(feature = "settings_editor")]
{
zng_wgt_settings::handle_settings_cmd();
tracing::debug!("defaults init, settings set");
}

#[cfg(all(single_instance, feature = "window"))]
{
Expand Down
3 changes: 2 additions & 1 deletion crates/zng/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ pub use zng_wgt_window::events::{
///
/// # Full API
///
/// See [`zng_wgt_inspector`] for the full API.
/// See [`zng_wgt_inspector::debug`] for the full API.
///
/// [`cmd::INSPECT_CMD`]: crate::window::cmd::INSPECT_CMD
#[cfg(feature = "inspector")]
pub mod inspector {
pub use zng_wgt_inspector::debug::{show_bounds, show_center_points, show_directional_query, show_hit_test, show_rows, InspectMode};
}
Expand Down
Loading