[英]Custom background color per item?
I have a Fl_Choice
with few options, for example: 我有一个Fl_Choice
选项很少,例如:
Fl_Choice* o = new Fl_Choice(70, 100, 240, 25, "Some Options:");
o->add("Blue");
o->add("Black");
o->add("Orange");
o->add("Purple");
I did like to set a custom color for the background of each item while leaving the foreground color to white. 我确实想为每个项目的背景设置自定义颜色,同时将前景色保留为白色。
How do I set a custom background per item? 如何为每个项目设置自定义背景?
NOTE: I am using v90, not sure what tag I should use for that one or if vs2008 is sufficient, kindly remove this note if its sufficient as is or drop me a comment with what other tag I should add. 注意:我正在使用v90,不确定该使用哪个标签,或者vs2008是否足够,请按原样删除此注释,或者在注释中添加我应该添加的其他标签。
Not so easy to set the background colour but you can set the foreground colour 设置背景颜色不是那么容易,但是您可以设置前景色
Fl_Menu_Item choices[] =
{
// ,-- The colour
{"red",0,(Fl_Callback*)0, (void*) 0, 0, 0, 0, 0, 0xFF000000},
{"blue",0,(Fl_Callback*)0, (void*) 0, 0, 0, 0, 0, 0x0000FF00},
{"green",0,(Fl_Callback*)0, (void*) 0, 0, 0, 0, 0, 0x00FF0000},
{"yellow",0,(Fl_Callback*)0, (void*) 0, 0, 0, 0, 0, 0xFFFF0000},
{0}
};
...
Fl_Choice *c = new Fl_Choice(50,250,200,25);
c->menu(choices);
Alternatively, you can derive from Fl_Choice if you don't want so many zeros 或者,如果您不希望有太多零,则可以从Fl_Choice派生
class ColourChoice: public Fl_Choice
{
public:
ColourChoice(int x, int y, int w, int h, const char* l = 0)
: Fl_Choice(x, y, w, h, l)
{
}
void add(const char* text, Fl_Color color)
{
Fl_Choice::add(text);
Fl_Menu_Item* item = const_cast<Fl_Menu_Item*>(find_item(text));
item->labelcolor(color);
}
};
...
ColourChoice* c = new ColourChoice(...);
c->add("purple", (Fl_Color)0xFF00FF00);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.