ドキュメント
SelectBoxComponent
4 min read
SelectBoxComponentはテキストボックスの下にセレクトボックスを表示するコンポーネントです。
select_box_component.hpp
class SelectBoxComponent : public Component
{
public:
using OPTION = std::pair<unsigned int, std::string>;
using OPTIONS = std::map<unsigned int, std::string>;
private:
std::list<FcComponent> select_box_components(OPTIONS options);
private:
class BoxClickEvent;
class ItemClickEvent;
public:
SelectBoxComponent
(
MOD mod,
unsigned int box_width,
unsigned int box_height,
unsigned char box_bg_color_R,
unsigned char box_bg_color_G,
unsigned char box_bg_color_B,
unsigned char box_bg_color_A,
spa::gui::box::POS pos,
unsigned int text_c_size,
unsigned char text_color_R,
unsigned char text_color_G,
unsigned char text_color_B,
unsigned char rect_bg_color_R,
unsigned char rect_bg_color_G,
unsigned char rect_bg_color_B,
unsigned char rect_bg_color_A,
std::string key,
std::map<unsigned int, std::string> options,
std::pair<unsigned int, std::string> option,
std::function<void(unsigned int)> select_event
);
~SelectBoxComponent() = default;
SelectBoxComponent(SelectBoxComponent const&);
SelectBoxComponent& operator=(SelectBoxComponent const&);
void set_options(OPTIONS options);
void set_option(OPTION option);
void configure();
void check_capture();
OPTION get();
private:
unsigned int box_width;
spa::gui::box::POS pos;
unsigned int text_c_size;
unsigned char text_color_R;
unsigned char text_color_G;
unsigned char text_color_B;
unsigned char rect_bg_color_R;
unsigned char rect_bg_color_G;
unsigned char rect_bg_color_B;
unsigned char rect_bg_color_A;
std::string key;
std::string uuid;
std::shared_ptr<OPTION> option;
std::pair<unsigned int, std::string> captured_option;
std::function<void(unsigned int)> select_event;
std::unique_ptr<ClickComponent> input;
std::unique_ptr<BoxTextComponent> text;
std::unique_ptr<SelectComponent> select;
std::unique_ptr<CaptureComponent> capture;
std::unique_ptr<ListVerticalComponent> dropdown;
};
テキストボックス、テキストを指定します。セレクトボックスの背景色(rect-bg_color)を指定します。セレクトボックスの排他制御用のkeyを指定します。オプションリストと値、セレクトボックスで選択した時のイベントを指定します。
セレクトボックスの表示、非表示はmod.store->select[key]がuuidなら表示、そうでない場合、非表示となります。同一keyのセレクトボックス同士で排他制御します。
select_box_component.cpp
void SelectBoxComponent::configure()
{
check_capture();
attach(input.get());
input->attach(text.get());
spa::utils::check::key(mod.store->select, key, __FILE__, __LINE__);
if (mod.store->select.at(key) == uuid)
{
text->attach_inner(select.get());
select->attach(capture.get());
capture->attach(dropdown.get());
//select->attach(dropdown.get());
}
}
void SelectBoxComponent::check_capture()
{
if (captured_option != *option)
{
captured_option = *option;
text->recapture();
}
}
set_options、set_optionメソッドがあります。データ取得後等でオプションを変更する場合に使用します。
コメントを残す