tray-controls
An enhanced menu management utility designed for the tray-icon crate. It provides structured management for Radio, CheckBox, and other menu item types, and is especially suitable for applications that require single-selection menus or complex system tray menus.
Features
🎯 Core Advantages
-
Unified Menu Management Easily manage multiple menu item types, including:
- Standard menu items
- Icon menu items
- Checkboxes
- Radio buttons
-
Group Management Automatically manages Radio menu groups to ensure correct single-selection behavior.
-
Direct Access by ID Access and modify any menu item and its properties directly via its ID.
🔧 Problems This Crate Solves
When using the tray-icon crate, menu event handling only provides the menu ID, not the actual menu item object. As a result:
- Direct access to the clicked menu item is difficult
- Updating menu properties (e.g. text, checked state) is inconvenient
- Synchronizing grouped menus (such as Radio buttons) requires manual bookkeeping
This crate solves these issues by introducing a centralized menu manager that maintains ownership and state of all menu items.
Usage
Add the dependency to your Cargo.toml:
[]
= "0.1.2"
= "0.21.2"
Example
An example demonstrating usage with winit + tray-icon + tray-control:
Core Components
MenuControl<G>
Represents different types of menu items:
CheckMenuKind<G>
Defines the specific behavior of a checkable menu item:
MenuManager<G>
The core manager responsible for menu storage, grouping, and state synchronization:
Example Code
let mut manager = new;
manager.insert;
manager.insert;
// Use together with tray-icon's MenuEvent::set_event_handler
manager.update;
When to Use This Crate
This crate is particularly useful if:
- You rely on
tray-iconand need structured menu state management - Your tray menu includes Radio or grouped CheckBox items
- You want to decouple menu logic from low-level event handling