예제 #1
0
파일: colorpicker.cpp 프로젝트: eriser/vkit
void ColorPicker::associate() {
	PopupButton::associate();
	ref<Popup> popup = this->popup();

	popup->setLayout(makeref<GroupLayout>());
	mColorWheel = makewidget<ColorWheel>(popup);
	mPickButton = makewidget<Button>(popup, "Pick");
	mPickButton->setFixedSize(Vector2i(100, 25));

	PopupButton::setChangeCallback([&](bool) {
		setColor(backgroundColor());
		mCallback(backgroundColor());
	});

	mColorWheel->setCallback([&](const Color &value) {
		mPickButton->setBackgroundColor(value);
		mPickButton->setTextColor(value.contrastingColor());
		mCallback(value);
	});

	mPickButton->setCallback([&]() {
		Color value = mColorWheel->color();
		setPushed(false);
		setColor(value);
		mCallback(value);
	});
}
예제 #2
0
void ComboBox::setItems(const std::vector<std::string> &items, const std::vector<std::string> &itemsShort) {
    assert(items.size() == itemsShort.size());
    mItems = items;
    mItemsShort = itemsShort;
    if (mSelectedIndex < 0 || mSelectedIndex >= (int) items.size())
        mSelectedIndex = 0;
    while (mPopup->childCount() != 0)
        mPopup->removeChild(mPopup->childCount()-1);
    mPopup->setLayout(new GroupLayout(10));
    int index = 0;
    for (const auto &str: items) {
        Button *button = new Button(mPopup, str);
        button->setFlags(Button::RadioButton);
        button->setCallback([&, index] {
            mSelectedIndex = index;
            setCaption(mItemsShort[index]);
            setPushed(false);
            popup()->setVisible(false);
            if (mCallback)
                mCallback(index);
        });
        index++;
    }
    setSelectedIndex(mSelectedIndex);
}