41template<
typename item_type>
48template<
typename item_type>
65template<
typename item_type>
69 std::vector<item_type>
data;
72 if(!
columns[column_index].sortable) {
77 bool offset_found =
false;
104 [&](
const item_type& a,
const item_type& b) {
105 return columns[order.sorted_index].compare(state, container, a, b);
112 [&](
const item_type& a,
const item_type& b) {
113 return columns[order.sorted_index].compare(state, container, b, a);
125template<
typename item_type>
139 send(state,
parent, signal);
153template<
typename item_type>
186template<
typename item_type>
202 auto response = send_and_retrieve<table_signal<item_type>>(state,
parent, signal);
213 send<table_signal_cell_hover>(state,
parent, signal);
222 send<table_signal_cell_click>(state,
parent, signal);
232 send<table_signal_scroll>(state,
parent, signal);
240 signal = send_and_retrieve<table_has_tooltip_signal>(state,
parent, signal);
252 signal.tooltip_layout = &contents;
253 send<table_tooltip_callback_signal>(state,
parent, signal);
258template<
typename item_type>
269 std::vector<entry<item_type>*>
cells{};
284 auto content_off_screen = int32_t(
rows) - int32_t(rows_visible);
287 if(content_off_screen <= 0) {
296 for(
size_t current_row = 0; current_row < rows_visible; current_row++) {
297 for(
uint8_t current_column = 0; current_column <
columns; current_column++) {
298 auto cell_index = current_row *
columns + current_column;
299 if(current_row >
rows) {
300 cells[cell_index]->set_visible(state,
false);
302 cells[cell_index]->set_visible(state,
true);
303 cells[cell_index]->on_update(state);
312 auto ptr = ui::make_element_by_type<_scrollbar>(state,
"standardlistbox_slider");
324 auto content_off_screen = int32_t(
rows - rows_visible);
325 if(content_off_screen > 0) {
340template<
typename item_type>
363 std::unique_ptr<element_base>
make_child(
sys::state& state, std::string_view name, dcon::gui_def_id
id)
noexcept override {
365 auto ptr_body = ui::make_element_by_type<body<item_type>>(
373 int16_t offset_y = 0;
374 int16_t offset_x = 0;
378 for(
uint8_t column_index = 0; column_index <
content.columns.size(); column_index++) {
380 auto ptr = ui::make_element_by_type<entry<item_type>>(
385 ptr->base_data.position.x += offset_x;
386 ptr->base_data.position.y += offset_y;
388 offset_x += ptr->base_data.size.x;
390 table_body->add_child_to_front(std::move(ptr));
403 window_element_base::on_create(state);
405 int16_t offset_x = 0;
406 for(
uint8_t column_index = 0; column_index <
content.columns.size(); column_index++) {
408 auto def = state.ui_state.defs_by_name.find(
410 )->second.definition;
411 auto ptr = ui::make_element_by_type<sort_button<item_type>>(
417 ptr->base_data.position.x += offset_x;
420 widths.push_back(ptr->base_data.size.x);
421 offset_x += ptr->base_data.size.x;
429 auto index = signal.
column;
446 sort_signal signal = any_cast<sort_signal>(payload);
480 content.update_rows_order(state,
this);
489 constexpr float dt = 0.99f;
494 }
else if (impulse < -dt) {
501 if(std::floor(impulse) != std::floor(
table_body->scroll_impulse)) {
502 table_body->list_scrollbar->update_raw_value(state,
table_body->list_scrollbar->raw_value() + (impulse < 0 ? 1 : -1));
503 state.ui_state.last_tooltip =
nullptr;
508 float tinted_column_x = (float)x;
510 float width = (float)(
widths[i]);
511 tinted_column_x += width;
515 float tinted_column_y = (float)y;
518 auto rtl = state.world.locale_get_native_rtl(
519 state.font_collection.get_current_locale()
523 tinted_column_x, tinted_column_y,
524 tinted_column_width, tinted_column_height,
530 float hovered_row_x = float(x);
537 hovered_row_x, hovered_row_y,
538 hovered_row_width, hovered_row_height,
void on_value_change(sys::state &state, int32_t v) noexcept override
body(uint8_t in_columns, uint8_t in_rows)
void update(sys::state &state)
_scrollbar * list_scrollbar
ui::message_result get(sys::state &state, Cyto::Any &payload) noexcept override
ui::tooltip_behavior has_tooltip(sys::state &state) noexcept override
std::vector< entry< item_type > * > cells
void on_create(sys::state &state) noexcept override
ui::message_result get(sys::state &state, Cyto::Any &payload) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
body< item_type > * table_body
std::vector< uint16_t > widths
std::function< void(sys::state &state, ui::element_base *container, const item_type &a)> row_callback
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
data< item_type > content
display(std::string body_definition, std::vector< column< item_type > > columns)
void on_update(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
entry(uint8_t in_row, uint8_t in_column)
virtual ui::message_result on_mouse_move(sys::state &state, int32_t x, int32_t y, sys::key_modifiers mods) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
ui::message_result test_mouse(sys::state &state, int32_t x, int32_t y, ui::mouse_probe_type t) noexcept override
ui::tooltip_behavior has_tooltip(sys::state &state) noexcept override
ui::message_result on_scroll(sys::state &state, int32_t x, int32_t y, float amount, sys::key_modifiers mods) noexcept override
void add_child_to_front(std::unique_ptr< element_base > child) noexcept final
virtual void render(sys::state &state, int32_t x, int32_t y) noexcept
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
virtual message_result on_mouse_move(sys::state &state, int32_t x, int32_t y, sys::key_modifiers mods) noexcept
virtual void on_create(sys::state &state) noexcept
void set_visible(sys::state &state, bool vis)
void render_tinted_rect(sys::state const &state, float x, float y, float width, float height, float r, float g, float b, ui::rotation rot, bool flipped, bool rtl)
void tooltip_fallback(sys::state &state, text::columnar_layout &contents, const item_type &a, std::string fallback)
sort_order toggle_sort_order(const sort_order order)
layout_box open_layout_box(layout_base &dest, int32_t indent)
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
void close_layout_box(columnar_layout &dest, layout_box &box)
std::function< bool(sys::state &state, ui::element_base *container, const item_type &a, const item_type &b)> compare
std::function< std::string(sys::state &state, ui::element_base *container, const item_type &a)> view
std::function< void(sys::state &state, text::columnar_layout &contents, const item_type &a, std::string fallback)> update_tooltip
std::string header_definition_string
std::string cell_definition_string
std::vector< sort_data > sort_priority
std::vector< item_type > data
std::vector< column< item_type > > columns
void update_rows_order(sys::state &state, ui::element_base *container)
void toggle_sort_column_by_index(uint8_t column_index)
rotation get_rotation() const