ドキュメント
TableScrollBoxComponent
7 min read
TableScrollBoxComponentはヘッダーy軸固定のテーブルスクロールコンポーネントです。Boxコンポーネントで表示位置を指定します。
table_scroll_box_component.hpp
#pragma once
#include <gui/components/atoms/box/box_component.hpp>
#include <gui/components/atoms/scroll/scroll_bg_layer_component.hpp>
#include <gui/components/atoms/scroll/scroll_component.hpp>
#include <gui/components/atoms/scroll/scroll_disable_component.hpp>
#include <gui/components/atoms/table/table_component.hpp>
#include <gui/components/atoms/capture/capture_component.hpp>
class TableScrollBoxComponent : public Component
{
public:
template<typename Columns>
TableScrollBoxComponent
(
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 scroll_amount,
unsigned char scroll_bg_layer_bg_color_R,
unsigned char scroll_bg_layer_bg_color_G,
unsigned char scroll_bg_layer_bg_color_B,
unsigned char scroll_bg_layer_bg_color_A,
unsigned int th_height,
unsigned char table_header_bg_color_R,
unsigned char table_header_bg_color_G,
unsigned char table_header_bg_color_B,
unsigned char table_header_bg_color_A,
unsigned int tr_height,
std::vector<unsigned int> td_width_vec,
std::list<Columns> data,
std::function<std::list<TdComponent>()> table_header_generator,
std::function<std::list<TdComponent>(Columns)> table_record_generator
) : Component(mod)
{
scroll_bg_layer = std::make_unique<ScrollBgLayerComponent>(
mod
, scroll_bg_layer_bg_color_R
, scroll_bg_layer_bg_color_G
, scroll_bg_layer_bg_color_B
, scroll_bg_layer_bg_color_A );
unsigned int scroll_width = 0;
for (auto const& td_width : td_width_vec)
scroll_width += td_width;
unsigned int scroll_height = th_height + (tr_height * (unsigned int)data.size());
int scroll_min_x = ((int)box_width - (int)scroll_width) < 0
? (int)box_width-(int)scroll_width
: 0;
int scroll_min_y = ((int)box_height - (int)scroll_height) < 0
? (int)box_height - (int)scroll_height
: 0;
scroll = std::make_unique<ScrollComponent>(
mod
, scroll_width
, scroll_height
, true
, true
, scroll_amount
, scroll_min_x
, 0
, scroll_min_y
, 0 );
disable_y = std::make_unique<ScrollDisableComponent>(
mod
, false
, true );
table_box = std::make_unique<BoxComponent>(
mod
, box_width
, box_height
, box_bg_color_R
, box_bg_color_G
, box_bg_color_B
, box_bg_color_A
, pos );
header_box = std::make_unique<BoxComponent>(
mod
, scroll_width
, th_height
, spa::gui::box::POS::TOP_LEFT );
records_box = std::make_unique<BoxComponent>(
mod
, scroll_width
, scroll_height - th_height
, spa::gui::box::POS::BOTTOM_LEFT );
std::list<TrComponent> tr_header = std::list<TrComponent>{};
tr_header.push_back(TrComponent{ mod, table_header_generator() });
header = std::make_unique<TableComponent>(
mod
, th_height
, td_width_vec
, tr_header );
std::list<TrComponent> tr_records = std::list<TrComponent>{};
for (auto const& record : data)
tr_records.push_back(TrComponent{ mod, table_record_generator(record) });
records = std::make_unique<TableComponent>(
mod
, tr_height
, td_width_vec
, tr_records );
header_capture = std::make_unique<CaptureComponent>(mod);
records_capture = std::make_unique<CaptureComponent>(mod);
}
~TableScrollBoxComponent() = default;
TableScrollBoxComponent(TableScrollBoxComponent const& other);
TableScrollBoxComponent& operator=(TableScrollBoxComponent const& other);
void recapture();
void configure();
private:
std::unique_ptr<ScrollBgLayerComponent> scroll_bg_layer;
std::unique_ptr<ScrollComponent> scroll;
std::unique_ptr<ScrollDisableComponent> disable_y;
std::unique_ptr<BoxComponent> table_box;
std::unique_ptr<BoxComponent> header_box;
std::unique_ptr<BoxComponent> records_box;
std::unique_ptr<TableComponent> header;
std::unique_ptr<TableComponent> records;
std::unique_ptr<CaptureComponent> header_capture;
std::unique_ptr<CaptureComponent> records_capture;
};
配置するボックスの幅、高さ、ポジションを指定します。スクロール量、スクロール外背景色を指定します。ヘッダーの高さ、ヘッダーの背景色を指定します。行の高さ、列幅を指定します。テンプレート引数Columnsリストのデータを指定します。ヘッダージェネレーター、データからレコードを生成するレコードジェネレーターを指定します。
テンプレート引数Columnsはstd::tuple型を使って実体化しています。tuple型をテンプレート引数とすることで、色々な型、列幅のテーブルを作成できます。
table_scroll_box_component.cpp
void TableScrollBoxComponent::configure()
{
attach(table_box.get());
table_box->attach(scroll_bg_layer.get());
scroll_bg_layer->attach(scroll.get());
scroll->attach(records_box.get());
//records_box->attach(records.get());
records_box->attach(records_capture.get());
records_capture->attach(records.get());
scroll->attach(disable_y.get());
disable_y->attach(header_box.get());
//header_box->attach(header.get());
header_box->attach(header_capture.get());
header_capture->attach(header.get());
}
コメントを残す