Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
Table.h
1#pragma once
2
3#include <cstddef>
4#include <initializer_list>
5#include <optional>
6#include <string>
7#include <string_view>
8#include <vector>
9
10struct ImVec2;
11
12namespace Engine::UI
13{
17 class Table
18 {
19 public:
20 static constexpr float MinimumColumnWidthFraction = 0.02f;
21
25 Table( std::string id, std::vector<std::string> headers );
26
30 void setColumnWidth( std::size_t columnIndex, float widthFraction );
31
35 void addRow( std::vector<std::string> cells );
36
40 void addRow( std::initializer_list<std::string_view> cells );
41
45 void clearRows();
46
50 [[nodiscard]] std::size_t columnCount() const;
51
55 [[nodiscard]] std::vector<float> columnWidthFractions() const;
56
60 void draw( const ImVec2 & outerSize ) const;
61
62 private:
63 void drawClippedCellText( const std::string & text ) const;
64
65 std::string id_;
66 std::vector<std::string> headers_;
67 std::vector<std::optional<float>> columnWidths_;
68 std::vector<std::vector<std::string>> rows_;
69 };
70} // namespace Engine::UI
void addRow(std::initializer_list< std::string_view > cells)
Adds a row from string-view cell literals matching the header count.
std::vector< float > columnWidthFractions() const
Returns normalized column width fractions after applying minimum widths.
static constexpr float MinimumColumnWidthFraction
Minimum normalized width assigned to any column.
Definition Table.h:20
void clearRows()
Removes all table rows while keeping headers and column widths.
std::vector< std::optional< float > > columnWidths_
Definition Table.h:67
void setColumnWidth(std::size_t columnIndex, float widthFraction)
Sets the preferred normalized width for a column.
void drawClippedCellText(const std::string &text) const
void draw(const ImVec2 &outerSize) const
Draws the table into the current ImGui context.
Table(std::string id, std::vector< std::string > headers)
Creates a table with a stable ImGui ID and header labels.
void addRow(std::vector< std::string > cells)
Adds a row of cells matching the header count.
std::size_t columnCount() const
Returns the number of table columns.
std::vector< std::vector< std::string > > rows_
Definition Table.h:68
std::string id_
Definition Table.h:65
std::vector< std::string > headers_
Definition Table.h:66