fluent-tray
Fluent Design-based GUI Library for System Tray Applications
Loading...
Searching...
No Matches
Public Member Functions | List of all members
fluent_tray::FluentMenu Class Reference

Class with information on each menu. More...

#include <fluent_tray.hpp>

Public Member Functions

 FluentMenu (bool toggleable=false, const std::function< bool(void)> &callback=[] {return true ;}, const std::function< bool(void)> &unchecked_callback=[] {return true ;})
 Create menu object.
 
 FluentMenu (const FluentMenu &)=default
 
FluentMenuoperator= (const FluentMenu &)=default
 
 FluentMenu (FluentMenu &&)=default
 
FluentMenuoperator= (FluentMenu &&)=default
 
 ~FluentMenu () noexcept
 
bool create_menu (HINSTANCE hinstance, HWND parent_hwnd, std::size_t id, const std::string &label_text="", const std::string &icon_path="", const std::string &checkmark="✓")
 Creates a menu window.
 
bool process_click_event ()
 Execute the process when clicked on the menu.
 
void check () noexcept
 Checks the menu if it is toggleable.
 
void uncheck () noexcept
 Unchecks the menu if it is toggleable.
 
bool is_checked () const noexcept
 Refer to the check status of the menu.
 
bool is_toggleable () const noexcept
 Check if the menu is toggleable.
 
HWND window_handle () const noexcept
 Refer to the menu window handle.
 
HMENU menu_handle () const noexcept
 Refer to the menu handle.
 
std::size_t id () const noexcept
 Refer to the menu identifier.
 
bool get_label (std::string &str) const
 Get menu label as UTF-8 string.
 
void show_separator_line () noexcept
 Show a separator line under the menu.
 
void hide_separator_line () noexcept
 Hide a separator line under the menu.
 
bool set_color (const COLORREF &text_color=CLR_INVALID, const COLORREF &back_color=CLR_INVALID, const COLORREF &border_color=CLR_INVALID) noexcept
 Set the menu color.
 
bool draw_menu (LPDRAWITEMSTRUCT info, HFONT font) const
 Draws a menu using drawing information and the specified font.
 
HBRUSH background_brush () const noexcept
 Refer to the brush for drawing the background.
 
bool calculate_required_dims (HFONT font, SIZE &size) const
 Calculates the size of the bounding box surrounding the menu based on the font information and the length of the label.
 

Detailed Description

Class with information on each menu.

Constructor & Destructor Documentation

◆ FluentMenu() [1/3]

fluent_tray::FluentMenu::FluentMenu ( bool toggleable = false,
const std::function< bool(void)> & callback = [] {return true ;},
const std::function< bool(void)> & unchecked_callback = [] {return true ;} )
inlineexplicit

Create menu object.

Parameters
[in]toggleableCreate a switchable menu
[in]callbackFunction called when a click on the menu or a check is enabled.
[in]unchecked_callbackFunction called when a check is disabled.

The callback function must be a function with a bool return value and no arguments. The tray will exit successfully if the callback function returns false.

◆ FluentMenu() [2/3]

fluent_tray::FluentMenu::FluentMenu ( const FluentMenu & )
default

◆ FluentMenu() [3/3]

fluent_tray::FluentMenu::FluentMenu ( FluentMenu && )
default

◆ ~FluentMenu()

fluent_tray::FluentMenu::~FluentMenu ( )
inlinenoexcept

Member Function Documentation

◆ background_brush()

HBRUSH fluent_tray::FluentMenu::background_brush ( ) const
inlinenoexcept

Refer to the brush for drawing the background.

Returns
The handle of brush.

Used for the return value of WM_CTLCOLORBTN message.

◆ calculate_required_dims()

bool fluent_tray::FluentMenu::calculate_required_dims ( HFONT font,
SIZE & size ) const
inline

Calculates the size of the bounding box surrounding the menu based on the font information and the length of the label.

Parameters
[in]fontThe handle of font.
[out]sizeThe output width and height dimensions.
Returns
Returns true on success, false on failure.

◆ check()

void fluent_tray::FluentMenu::check ( )
inlinenoexcept

Checks the menu if it is toggleable.

Update only the current state without calling the callback function.

◆ create_menu()

bool fluent_tray::FluentMenu::create_menu ( HINSTANCE hinstance,
HWND parent_hwnd,
std::size_t id,
const std::string & label_text = "",
const std::string & icon_path = "",
const std::string & checkmark = "✓" )
inline

Creates a menu window.

Parameters
[in]hinstanceAn instance handle of application.
[in]parent_hwndA window handle of tray.
[in]idA new unique identifier.
[in]label_textA label text.
[in]icon_pathAn icon path to show next to the label.
[in]checkmarkA checkmark string.
Returns
Returns true on success, false on failure.

◆ draw_menu()

bool fluent_tray::FluentMenu::draw_menu ( LPDRAWITEMSTRUCT info,
HFONT font ) const
inline

Draws a menu using drawing information and the specified font.

Parameters
[in]infoStructure that holds drawing information.
[in]fontThe handle of font.
Returns
Returns true on success, false on failure.

info is the DRAWITEMSTRUCT obtained when the owner window receives a WM_DRAWITEM message.

◆ get_label()

bool fluent_tray::FluentMenu::get_label ( std::string & str) const
inline

Get menu label as UTF-8 string.

Parameters
[out]strThe output string.
Returns
Returns true on success, false on failure.

◆ hide_separator_line()

void fluent_tray::FluentMenu::hide_separator_line ( )
inlinenoexcept

Hide a separator line under the menu.

◆ id()

std::size_t fluent_tray::FluentMenu::id ( ) const
inlinenoexcept

Refer to the menu identifier.

Returns
The identifier.

◆ is_checked()

bool fluent_tray::FluentMenu::is_checked ( ) const
inlinenoexcept

Refer to the check status of the menu.

Returns
If the menu is toggleable, returns whether it is checked or not, and always returns false if it is not toggleable.

◆ is_toggleable()

bool fluent_tray::FluentMenu::is_toggleable ( ) const
inlinenoexcept

Check if the menu is toggleable.

Returns
Returns true if the menu is toggleable, false otherwise.

◆ menu_handle()

HMENU fluent_tray::FluentMenu::menu_handle ( ) const
inlinenoexcept

Refer to the menu handle.

Returns
The menu handle.

◆ operator=() [1/2]

FluentMenu & fluent_tray::FluentMenu::operator= ( const FluentMenu & )
default

◆ operator=() [2/2]

FluentMenu & fluent_tray::FluentMenu::operator= ( FluentMenu && )
default

◆ process_click_event()

bool fluent_tray::FluentMenu::process_click_event ( )
inline

Execute the process when clicked on the menu.

Returns
Returns true on success, false on failure.

◆ set_color()

bool fluent_tray::FluentMenu::set_color ( const COLORREF & text_color = CLR_INVALID,
const COLORREF & back_color = CLR_INVALID,
const COLORREF & border_color = CLR_INVALID )
inlinenoexcept

Set the menu color.

Parameters
[in]text_colorThe color for label text.
[in]back_colorThe color for background.
[in]border_colorThe color for separator line.
Returns
Returns true on success, false on failure.

If the set value is CLR_INVALID, the value is not changed.

◆ show_separator_line()

void fluent_tray::FluentMenu::show_separator_line ( )
inlinenoexcept

Show a separator line under the menu.

◆ uncheck()

void fluent_tray::FluentMenu::uncheck ( )
inlinenoexcept

Unchecks the menu if it is toggleable.

Update only the current state without calling the callback function.

◆ window_handle()

HWND fluent_tray::FluentMenu::window_handle ( ) const
inlinenoexcept

Refer to the menu window handle.

Returns
The window handle.

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