mousetrap v0.2.0
Loading...
Searching...
No Matches
mousetrap::MenuModel Class Reference

menu model, used to specifc behavior of menu bars and popover menus More...

#include <menu_model.hpp>

Inheritance diagram for mousetrap::MenuModel:
mousetrap::SignalEmitter mousetrap::has_signal_items_changed< MenuModel >

Public Types

enum  SectionFormat {
  NORMAL , HORIZONTAL_BUTTONS , HORIZONTAL_BUTTONS_LEFT_TO_RIGHT , HORIZONTAL_BUTTONS_RIGHT_TO_LEFT ,
  CIRCULAR_BUTTONS , INLINE_BUTTONS
}
 formatting for sectsion More...
 

Public Member Functions

 MenuModel ()
 construct as emtpy
 
 MenuModel (detail::MenuModelInternal *)
 construct from internal
 
 ~MenuModel ()
 destruct
 
NativeObject get_internal () const override
 expose internal
 
void add_action (const std::string &label, const Action &action)
 add an action to the model, if the action is stateful, the menu item will contain a check box
 
void add_widget (const Widget &widget)
 add widget to menu, note that widgets can only be display when they are part of a section or submenu, not if they are in the toplevel sectino
 
void add_section (const std::string &label, const MenuModel &menu_model, SectionFormat format=NORMAL)
 add a section to a menu. A section is visible in the same scope as the outer menu, it has a title and present its child labels according to the given mousetrap::SectionFormat
 
void add_submenu (const std::string &label, const MenuModel &menu_model)
 add submenu to a menu. A submenut will appear as a single menu item, when clicked, the menu will open another popup to display the menu items contained in the submenu
 
void add_icon (const Icon &, const Action &)
 add menu item that is a button with an icon and no label
 
 operator NativeObject () const override
 expose a GObject \for_internal_use_only
 
 operator GMenuModel * () const
 expose as GMenuModel
 
- Public Member Functions inherited from mousetrap::SignalEmitter
void set_signal_blocked (const std::string &signal_id, bool b)
 block a signal by id \for_internal_use_only
 
bool get_signal_blocked (const std::string &signal_id) const
 get whether a signal is currently blocked
 
std::vector< std::string > get_all_signal_names ()
 get list of possible signal ids \for_internal_use_only
 
template<typename Function_t >
void connect_signal (const std::string &signal_id, Function_t *function, void *data=nullptr)
 connect static function to signal, does not work with lambdas \for_internal_use_only
 
void disconnect_signal (const std::string &signal_id)
 disconnect signal, it may not be invoked until reconnected, if signal is not registered, does nothing. For internal use only
 
virtual operator NativeObject () const =0
 expose as NativeObject, this is the GLib instance that signals are emitted on \for_internal_use_only
 
virtual NativeObject get_internal () const
 expose internally managed object, \for_internal_use_only
 
- Public Member Functions inherited from mousetrap::has_signal_items_changed< MenuModel >
void connect_signal_items_changed (Function_t f, Data_t data)
 connect handler, will be invoked when signal is emitted. Data is passed to the signal handler function
 
void connect_signal_items_changed (Function_t f)
 connect handler, will be invoked when signal is emitted
 
void set_signal_items_changed_blocked (bool b)
 
bool get_signal_items_changed_blocked () const
 
void emit_signal_items_changed (int32_t position, int32_t n_removed, int32_t n_added)
 invoke signal handler manually
 
void disconnect_signal_items_changed ()
 

Protected Member Functions

std::map< std::string, GtkWidget * > get_widgets () const
 get list of registered widgets \for_internal_use_only
 
- Protected Member Functions inherited from mousetrap::SignalEmitter
 SignalEmitter ()
 ctor
 
 ~SignalEmitter ()
 destructor
 
- Protected Member Functions inherited from mousetrap::has_signal_items_changed< MenuModel >
 has_signal_items_changed (MenuModel *instance)
 

Friends

class MenuBar
 
class PopoverMenu
 

Additional Inherited Members

- Static Public Attributes inherited from mousetrap::has_signal_items_changed< MenuModel >
static const char * signal_id
 glib ID
 

Detailed Description

menu model, used to specifc behavior of menu bars and popover menus

signal id signature emitted when...
items_changed (MenuModel&, int32_t position, int32_t n_removed, int32_t n_added, (Data_t)) -> void An item was added or removed from a MenuModel

Member Enumeration Documentation

◆ SectionFormat

formatting for sectsion

Enumerator
NORMAL 

present as nested submenu

HORIZONTAL_BUTTONS 

present as vertical list of round buttons areound each label

HORIZONTAL_BUTTONS_LEFT_TO_RIGHT 

present as horizontal list of round buttons, left to right

HORIZONTAL_BUTTONS_RIGHT_TO_LEFT 

present as horizontal list of round button, right to left

CIRCULAR_BUTTONS 

present label items as circular buttons

INLINE_BUTTONS 

present label items as buttons inline with the outer menu

Member Function Documentation

◆ add_action()

void mousetrap::MenuModel::add_action ( const std::string &  label,
const Action action 
)

add an action to the model, if the action is stateful, the menu item will contain a check box

Parameters
labellabel to be used
actionaction that triggers when the label is activated

References mousetrap::Action::get_id(), mousetrap::Action::get_is_stateful(), and mousetrap::Action::get_state().

◆ add_icon()

void mousetrap::MenuModel::add_icon ( const Icon icon,
const Action action 
)

add menu item that is a button with an icon and no label

Parameters
iconicon
actionacton to trigger

References mousetrap::Action::get_id().

◆ add_section()

void mousetrap::MenuModel::add_section ( const std::string &  label,
const MenuModel menu_model,
SectionFormat  format = NORMAL 
)

add a section to a menu. A section is visible in the same scope as the outer menu, it has a title and present its child labels according to the given mousetrap::SectionFormat

Parameters
labellabel for the section, appears at the start of the section, similar to a heading
menu_modelmodel to use for populating the section items
formatsection format to use

References CIRCULAR_BUTTONS, HORIZONTAL_BUTTONS, HORIZONTAL_BUTTONS_LEFT_TO_RIGHT, HORIZONTAL_BUTTONS_RIGHT_TO_LEFT, and INLINE_BUTTONS.

◆ add_submenu()

void mousetrap::MenuModel::add_submenu ( const std::string &  label,
const MenuModel menu_model 
)

add submenu to a menu. A submenut will appear as a single menu item, when clicked, the menu will open another popup to display the menu items contained in the submenu

Parameters
labellabel for the submenu
menu_modelmodel to use for populating the submenu items

References mousetrap::log::critical().

◆ add_widget()

void mousetrap::MenuModel::add_widget ( const Widget widget)

add widget to menu, note that widgets can only be display when they are part of a section or submenu, not if they are in the toplevel sectino

Parameters
widget

◆ get_internal()

NativeObject mousetrap::MenuModel::get_internal ( ) const
overridevirtual

expose internal

Reimplemented from mousetrap::SignalEmitter.

Referenced by mousetrap::MenuBar::MenuBar(), and mousetrap::PopoverMenu::PopoverMenu().

◆ get_widgets()

std::map< std::string, GtkWidget * > mousetrap::MenuModel::get_widgets ( ) const
protected

get list of registered widgets \for_internal_use_only

Returns
map with internal id to widget mapping

◆ operator NativeObject()

mousetrap::MenuModel::operator NativeObject ( ) const
overridevirtual

expose a GObject \for_internal_use_only

Implements mousetrap::SignalEmitter.


The documentation for this class was generated from the following files: