MeshLib Documentation
Loading...
Searching...
No Matches
MRRibbonButtonDrawer.h
Go to the documentation of this file.
1#pragma once
2#include "MRRibbonMenuItem.h"
3#include "MRRibbonIcons.h"
4#include "imgui.h"
5#include <functional>
6
7namespace MR
8{
9
10struct MenuItemInfo;
11class RibbonMenu;
12class ShortcutManager;
13class ImGuiImage;
14
16{
17 enum class SizeType
18 {
19 Big, // button is big, underline text is divided to 2 lines (maximum) to fit width
20 SmallText, // button is small, text is on same line
21 Small // button is small, no text present
22 } sizeType{ SizeType::Big }; // type of button to draw
23
24 ImVec2 itemSize; // size of whole item group, needed for all, this should respect system scaling
25 float iconSize{ 0.f }; // icon size ( = 0 - use preset according to button type), this is scale factor of cBigIcon size (should not respect system scaling)
27 {
28 Ribbon, // button is on main ribbon bar
29 Toolbar, // button is on toolbar
30 Header // button is on header quick access bar
31 } rootType{ RootType::Ribbon };
32
33 // if true treat this item as hovered
34 bool forceHovered = false;
35 // if true treat this item as pressed
36 bool forcePressed = false;
37};
38
40{
41 // if not set push default ribbon colors
42 std::function<int( bool, bool )> pushColorsCb;
44};
45
47class MRVIEWER_CLASS RibbonButtonDrawer
48{
49public:
50 // Creates GL texture for gradient UI (called on theme apply)
51 MRVIEWER_API static void InitGradientTexture();
52 enum class TextureType
53 {
54 Mono,
55 Gradient,
56 RainbowRect,
57 Count
58 };
59 MRVIEWER_API static std::unique_ptr<ImGuiImage>& GetTexture( TextureType type );
60
61
63 MRVIEWER_API bool GradientCheckboxItem( const MenuItemInfo& item, bool* value ) const;
64
65
68 MRVIEWER_API static bool CustomCollapsingHeader( const char* label, ImGuiTreeNodeFlags flags = 0, int issueCount = 0 );
69
71 {
72 float baseWidth{ 0.0f };
73 float additionalWidth{ 0.0f }; // for small drop buttons
74 };
75 MRVIEWER_API ButtonItemWidth calcItemWidth( const MenuItemInfo& item, DrawButtonParams::SizeType sizeType ) const;
76
78 MRVIEWER_API void drawButtonItem( const MenuItemInfo& item, const DrawButtonParams& params ) const;
79
81 MRVIEWER_API void drawCustomButtonItem( const MenuItemInfo& item, const CustomButtonParameters& customParam,
82 const DrawButtonParams& params ) const;
83
85 MRVIEWER_API void drawButtonIcon( const MenuItemInfo& item, const DrawButtonParams& params ) const;
86
88 MRVIEWER_API bool drawTabArrawButton( const char* icon, const ImVec2& size, float iconSize );
89
91 MRVIEWER_API void setMonochrome( const std::optional<Color>& color );
92
94 void setOnPressAction( std::function<void( std::shared_ptr<RibbonMenuItem>, const std::string& )> action ) { onPressAction_ = action; };
96 void setGetterRequirements( std::function<std::string( std::shared_ptr<RibbonMenuItem> )> getterRequirements ) { getRequirements_ = getterRequirements; };
97
98 void setMenu( RibbonMenu* menu ) { menu_ = menu; };
99 void setShortcutManager( const ShortcutManager* shortcutManager ) { shortcutManager_ = shortcutManager; };
100 void setScaling( float scaling ) { scaling_ = scaling; };
101
102private:
103 void drawButtonDropItem_( const MenuItemInfo& item, const DrawButtonParams& params ) const;
104 void drawDropList_( const std::shared_ptr<RibbonMenuItem>& baseDropItem ) const;
105 void drawTooltip_( const MenuItemInfo& item, const std::string& requirements ) const;
106
107 // returns num of pushed colors
108 int pushRibbonButtonColors_( bool enabled, bool active, bool forceHovered, DrawButtonParams::RootType rootType ) const;
109
110 std::function<void( std::shared_ptr<RibbonMenuItem>, const std::string& )> onPressAction_ = []( std::shared_ptr<RibbonMenuItem>, const std::string& ) {};
111 std::function<std::string( std::shared_ptr<RibbonMenuItem> )> getRequirements_ = []( std::shared_ptr<RibbonMenuItem> ) { return std::string(); };
112 RibbonMenu* menu_ = nullptr;
113 const ShortcutManager* shortcutManager_ = nullptr;
114
115 std::optional<Color> monochrome_;
116
117 float scaling_ = 1.f;
118 static std::vector<std::unique_ptr<MR::ImGuiImage>> textures_;
119};
120
121}
class for drawing ribbon menu buttons
Definition MRRibbonButtonDrawer.h:48
MRVIEWER_API void setMonochrome(const std::optional< Color > &color)
if set color then instead of multicolored icons will be drawn with this color
TextureType
Definition MRRibbonButtonDrawer.h:53
void setScaling(float scaling)
Definition MRRibbonButtonDrawer.h:100
MRVIEWER_API void drawCustomButtonItem(const MenuItemInfo &item, const CustomButtonParameters &customParam, const DrawButtonParams &params) const
draw item button
void setGetterRequirements(std::function< std::string(std::shared_ptr< RibbonMenuItem >)> getterRequirements)
set function to get requirements for activate item
Definition MRRibbonButtonDrawer.h:96
void setOnPressAction(std::function< void(std::shared_ptr< RibbonMenuItem >, const std::string &)> action)
set reaction on press item button
Definition MRRibbonButtonDrawer.h:94
void setShortcutManager(const ShortcutManager *shortcutManager)
Definition MRRibbonButtonDrawer.h:99
static MRVIEWER_API std::unique_ptr< ImGuiImage > & GetTexture(TextureType type)
MRVIEWER_API ButtonItemWidth calcItemWidth(const MenuItemInfo &item, DrawButtonParams::SizeType sizeType) const
MRVIEWER_API void drawButtonItem(const MenuItemInfo &item, const DrawButtonParams &params) const
draw item button
MRVIEWER_API bool GradientCheckboxItem(const MenuItemInfo &item, bool *value) const
draw gradient checkbox with icon (for menu item)
static MRVIEWER_API bool CustomCollapsingHeader(const char *label, ImGuiTreeNodeFlags flags=0, int issueCount=0)
void setMenu(RibbonMenu *menu)
Definition MRRibbonButtonDrawer.h:98
static MRVIEWER_API void InitGradientTexture()
MRVIEWER_API void drawButtonIcon(const MenuItemInfo &item, const DrawButtonParams &params) const
draw item button icon
MRVIEWER_API bool drawTabArrawButton(const char *icon, const ImVec2 &size, float iconSize)
draw custom styled button
IconType
Definition MRRibbonIcons.h:21
Definition MRRibbonMenu.h:32
Definition MRShortcutManager.h:44
Definition MRCameraOrientationPlugin.h:8
Definition MRRibbonButtonDrawer.h:40
RibbonIcons::IconType iconType
Definition MRRibbonButtonDrawer.h:43
std::function< int(bool, bool)> pushColorsCb
Definition MRRibbonButtonDrawer.h:42
Definition MRRibbonButtonDrawer.h:16
RootType
Definition MRRibbonButtonDrawer.h:27
@ Header
Definition MRRibbonButtonDrawer.h:30
@ Toolbar
Definition MRRibbonButtonDrawer.h:29
@ Ribbon
Definition MRRibbonButtonDrawer.h:28
SizeType
Definition MRRibbonButtonDrawer.h:18
float iconSize
Definition MRRibbonButtonDrawer.h:25
ImVec2 itemSize
Definition MRRibbonButtonDrawer.h:24
bool forcePressed
Definition MRRibbonButtonDrawer.h:36
enum MR::DrawButtonParams::SizeType Big
bool forceHovered
Definition MRRibbonButtonDrawer.h:34
Definition MRRibbonSchema.h:24
Definition MRRibbonButtonDrawer.h:71