BColorMenuItem: add custom color menufield

http://insightfactory.tumblr.com/image/142366356207

* Make the color box a rectangle with proportions of golden ratio.
* Override GetContentSize() to make menu item area larger.
* Label should never truncate since I make sure there is enough room.
* Draw the label using BMenuItem parent class
* Carefully adjust the spacing so that there is an attractive amount of
  padding between the checkmark and color box and the color box and label.

Add _AddMenu method to BMenuField that adds BColorMenuItem as its
base menu item. This shows the BColorMenuItem in the closed state.

Create BPrivate::MenuItemPrivate

Add a SetSubmenu() method to MenuItemPrivate that gives you
the ability to add a submenu after creating the object. This
method should be public

Skip disabled items

Color gets updated even if you select an item in a submenu
This commit is contained in:
John Scipione
2016-07-31 19:42:39 -07:00
parent ca766a50fe
commit 81364c9d82
8 changed files with 472 additions and 11 deletions
+71
View File
@@ -0,0 +1,71 @@
/*
* Copyright 2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* John Scipione, [email protected]
*/
#ifndef COLOR_MENU_ITEM_H
#define COLOR_MENU_ITEM_H
#include <InterfaceDefs.h>
#include <MenuItem.h>
class BColorMenuItem : public BMenuItem {
public:
BColorMenuItem(const char* label,
BMessage* message, rgb_color color,
char shortcut = 0,
uint32 modifiers = 0);
BColorMenuItem(BMenu* menu, rgb_color color,
BMessage* message = NULL);
BColorMenuItem(BMessage* data);
static BArchivable* Instantiate(BMessage* archive);
virtual status_t Archive(BMessage* archive,
bool deep = true) const;
virtual void DrawContent();
virtual void GetContentSize(float* _width, float* _height);
virtual void SetMarked(bool mark);
rgb_color Color() const { return fColor; };
virtual void SetColor(rgb_color color) { fColor = color; };
private:
virtual void _ReservedColorMenuItem1();
virtual void _ReservedColorMenuItem2();
virtual void _ReservedColorMenuItem3();
virtual void _ReservedColorMenuItem4();
virtual void _ReservedColorMenuItem5();
virtual void _ReservedColorMenuItem6();
virtual void _ReservedColorMenuItem7();
virtual void _ReservedColorMenuItem8();
virtual void _ReservedColorMenuItem9();
virtual void _ReservedColorMenuItem10();
virtual void _ReservedColorMenuItem11();
virtual void _ReservedColorMenuItem12();
virtual void _ReservedColorMenuItem13();
virtual void _ReservedColorMenuItem14();
virtual void _ReservedColorMenuItem15();
virtual void _ReservedColorMenuItem16();
virtual void _ReservedColorMenuItem17();
virtual void _ReservedColorMenuItem18();
virtual void _ReservedColorMenuItem19();
virtual void _ReservedColorMenuItem20();
float _LeftMargin();
float _Padding();
float _ColorRectWidth();
private:
rgb_color fColor;
uint32 _reserved[30];
};
#endif // COLOR_MENU_ITEM_H
@@ -0,0 +1,35 @@
/*
* Copyright 2016 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* John Scipione, [email protected]
*/
#ifndef __MENU_ITEM_PRIVATE_H
#define __MENU_ITEM_PRIVATE_H
#include <MenuItem.h>
class BMenu;
namespace BPrivate {
class MenuItemPrivate {
public:
MenuItemPrivate(BMenuItem* menuItem);
void SetSubmenu(BMenu* submenu);
void Install(BWindow* window);
void Uninstall();
private:
BMenuItem* fMenuItem;
};
}; // namespace BPrivate
#endif // __MENU_ITEM_PRIVATE_H