41template<
typename item_type>
48template<
typename item_type>
66template<
typename item_type>
70 std::vector<item_type>
data;
73 if(!
columns[column_index].sortable) {
78 bool offset_found =
false;
105 [&](
const item_type& a,
const item_type& b) {
106 return columns[order.sorted_index].compare(state, container, a, b);
113 [&](
const item_type& a,
const item_type& b) {
114 return columns[order.sorted_index].compare(state, container, b, a);
126template<
typename item_type>
140 send(state,
parent, signal);
154template<
typename item_type>
187template<
typename item_type>
203 auto response = send_and_retrieve<table_signal<item_type>>(state,
parent, signal);
214 send<table_signal_cell_hover>(state,
parent, signal);
223 send<table_signal_cell_click>(state,
parent, signal);
233 send<table_signal_scroll>(state,
parent, signal);
241 signal = send_and_retrieve<table_has_tooltip_signal>(state,
parent, signal);
253 signal.tooltip_layout = &contents;
254 send<table_tooltip_callback_signal>(state,
parent, signal);
259template<
typename item_type>
270 std::vector<entry<item_type>*>
cells{};
285 auto content_off_screen = int32_t(
rows) - int32_t(rows_visible);
288 if(content_off_screen <= 0) {
297 for(
size_t current_row = 0; current_row < rows_visible; current_row++) {
298 for(
uint8_t current_column = 0; current_column <
columns; current_column++) {
299 auto cell_index = current_row *
columns + current_column;
300 if(current_row >=
rows) {
301 cells[cell_index]->set_visible(state,
false);
303 cells[cell_index]->set_visible(state,
true);
304 cells[cell_index]->on_update(state);
313 auto ptr = ui::make_element_by_type<_scrollbar>(state,
"standardlistbox_slider");
325 auto content_off_screen = int32_t(
rows - rows_visible);
326 if(content_off_screen > 0) {
341template<
typename item_type>
364 std::unique_ptr<element_base>
make_child(
sys::state& state, std::string_view name, dcon::gui_def_id
id)
noexcept override {
366 auto ptr_body = ui::make_element_by_type<body<item_type>>(
374 int16_t offset_y = 0;
375 int16_t offset_x = 0;
379 for(
uint8_t column_index = 0; column_index <
content.columns.size(); column_index++) {
381 auto ptr = ui::make_element_by_type<entry<item_type>>(
386 ptr->base_data.position.x += offset_x;
387 ptr->base_data.position.y += offset_y;
389 offset_x += ptr->base_data.size.x;
391 table_body->add_child_to_front(std::move(ptr));
404 window_element_base::on_create(state);
406 int16_t offset_x = 0;
407 for(
uint8_t column_index = 0; column_index <
content.columns.size(); column_index++) {
409 auto def = state.ui_state.defs_by_name.find(
411 )->second.definition;
412 auto ptr = ui::make_element_by_type<sort_button<item_type>>(
418 ptr->base_data.position.x += offset_x;
421 widths.push_back(ptr->base_data.size.x);
422 offset_x += ptr->base_data.size.x;
430 auto index = signal.
column;
447 sort_signal signal = any_cast<sort_signal>(payload);
482 content.update_rows_order(state,
this);
491 constexpr float dt = 0.99f;
496 }
else if (impulse < -dt) {
503 if(std::floor(impulse) != std::floor(
table_body->scroll_impulse)) {
504 table_body->list_scrollbar->update_raw_value(state,
table_body->list_scrollbar->raw_value() + (impulse < 0 ? 1 : -1));
505 state.ui_state.last_tooltip =
nullptr;
510 float tinted_column_x = (float)x;
512 float width = (float)(
widths[i]);
513 tinted_column_x += width;
517 float tinted_column_y = (float)y;
520 auto rtl = state.world.locale_get_native_rtl(
521 state.font_collection.get_current_locale()
525 tinted_column_x, tinted_column_y,
526 tinted_column_width, tinted_column_height,
532 float hovered_row_x = float(x);
539 hovered_row_x, hovered_row_y,
540 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 merge_sort(IT first, IT end, CMP const &cmp) noexcept
void tooltip_fallback(sys::state &state, ui::element_base *container, 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)
Holds important data about the game world, state, and other data regarding windowing,...
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, ui::element_base *container, 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