Toolbar

A toolbar is a generic concept of an area over the margins of a window (top or bottom margins) where several controls (or toolbar items) reside. A toolbar items are simplier controls that convey their events directly to the window via a spcial trait: ToolBarEvents.

All toolbar items are organized in groups. A group is similar to a flow (all toolbar items are aligned one after another, depending on the direction of the flow). It is important to notice that a toolbar item does not have a layout of itself (its position is decided by the group). The following direction are supported by a toolbar group (via enum toolbar::GroupPosition):

pub enum GroupPosition {
    TopLeft,
    BottomLeft,
    TopRight,
    BottomRight,
}

Constructing a toolbar item

To add a toolbar item into a window, you need to perform the following steps:

  1. create a group
  2. create a toolbar item
  3. add the previously created toolbar item to the group created on step 1.

Typically, a toolbar initialization mechanims is done when creating a window, in a similar manner as with the next snippet:

#[Window(...)]
struct MyWin {
    // data members
}
impl MyWin {
    fn new() -> Self {
        let mut me = Self {
            base: window!("..."),
        };
        let a_group = me.toolbar().create_group(toolbar::GroupPosition::<Value>);
        let item_handle = me.toolbar().add(a_group, toolbar::<Type>::new("..."));
        // other initializations
        me
    }
}

To create a toolbar item, there are two options:

  • use toolbar::<Item>::new(...) method
  • use toolbaritem! macro

Curenly AppCUI supports the following toolbar item types:

Common methods

All toolbar items have a set of common methods that can be used to modify their behavior:

MethodPurpose
set_toooltip(...)Set the tooltip for the current item. Using this method with an empty string clears the tooltip
get_tooltip()Returns the current tooltip associated with an toolbar item
set_visible()Changes the visibility settings for a selected toolbar item
is_visible()Returns true if the current toolbar item is visible, or false otherwise