Player12
An open source football management simulator
Loading...
Searching...
No Matches
widgets.h File Reference
#include <imgui.h>
#include <climits>
#include <cstdint>
#include <span>
#include <string>
#include <string_view>
#include <type_traits>

Go to the source code of this file.

Classes

struct  UI::BarDatum
 One bar in a horizontal bar chart. More...
 
class  UI::TileRow
 Lays out a row of equal tiles that wraps onto more lines when the region is too narrow for them all (small windows, large UI scale). More...
 
struct  UI::MoneyChip
 A quick-pick value offered under a money input. More...
 
struct  UI::MoneyInputOptions
 Options of moneyInput(). More...
 
struct  UI::MoneyPreview
 Line shown under a money input while typing. More...
 
struct  UI::Column
 One column of a responsive table. More...
 

Namespaces

namespace  UI
 Small vector icons drawn with ImDrawList (no icon font needed).
 
namespace  UI::Size
 Design-system sizes in unscaled pixels.
 

Typedefs

using UI::ColumnMask = uint32_t
 Visible-column mask produced by fitColumns().
 

Enumerations

enum class  UI::DialogResult : uint8_t { UI::NONE , UI::CONFIRM , UI::CANCEL }
 Result of a modal confirmation dialog. More...
 
enum class  UI::Outcome : uint8_t { UI::WIN , UI::DRAW , UI::LOSS }
 Match outcome for form strips. More...
 
enum class  UI::ButtonSize : uint8_t { UI::REGULAR , UI::COMPACT }
 Button height class. More...
 
enum class  UI::TableHeader : uint8_t { UI::STATIC , UI::SORTABLE , UI::NONE }
 Header row emitted by beginResponsiveTable(). More...
 

Functions

bool UI::drawTextFitted (ImDrawList *drawList, ImVec2 position, ImU32 color, std::string_view text, float maxWidth)
 Draws text cut to maxWidth with a trailing ellipsis when needed.
 
void UI::textFitted (std::string_view text, float maxWidth, const ImVec4 &color)
 Text item limited to maxWidth; shows the full text as a tooltip when it had to be shortened.
 
void UI::pageHeader (const char *title, const char *subtitle=nullptr)
 Large page title with an optional muted subtitle.
 
void UI::sectionLabel (const char *text)
 Small uppercase section label.
 
void UI::beginCard (const char *id, const char *title, ImVec2 size, bool scroll=false)
 Starts a bordered card. Always pair with endCard().
 
void UI::beginAutoHeightCard (const char *id, const char *title, float width=0.0f)
 Starts a card that grows to fit its content (never scrolls).
 
void UI::endCard ()
 Ends a card started with beginCard() or beginAutoHeightCard().
 
void UI::statTile (const char *id, const char *caption, const char *value, const char *footnote, const ImVec4 &valueColor, float width)
 Figure tile: caption, big value and an optional footnote.
 
float UI::statTileHeight ()
 Height used by statTile(), for layout calculations.
 
void UI::attributeBar (const char *label, float value, float labelWidth, float maxValue=100.0f, float width=0.0f)
 Labelled horizontal bar coloured with the rating scale.
 
void UI::meter (const char *label, float fraction, float labelWidth, const ImVec4 &color, const char *valueText)
 Labelled bar with an explicit colour and value text (0-1).
 
void UI::ratingChip (double rating)
 Rounded rating chip, coloured by the rating scale.
 
void UI::badge (const char *text, const ImVec4 &color)
 Small coloured badge with text.
 
void UI::clubBadge (const char *code, uint32_t primary, uint32_t secondary, float height)
 Two-colour club shield (kit colours 0xRRGGBB) with the short code drawn inside when the shield is tall enough to read it.
 
void UI::drawClubBadge (ImDrawList *drawList, ImVec2 min, float height, const char *code, uint32_t primary, uint32_t secondary)
 clubBadge() drawn at a position (height in pixels), no layout.
 
void UI::formStrip (std::span< const Outcome > outcomes)
 Row of W/D/L markers (latest last).
 
void UI::emptyState (const char *title, const char *body)
 Muted placeholder shown when a list has nothing to display.
 
DialogResult UI::confirmDialog (const char *id, const char *title, const char *body, const char *confirmLabel, const char *cancelLabel)
 Modal confirmation. Open with ImGui::OpenPopup(id) beforehand.
 
void UI::sparkline (const char *id, std::span< const float > values, ImVec2 size, const ImVec4 &color)
 Line chart of a series in a fixed box.
 
void UI::deltaBars (const char *id, std::span< const float > values, ImVec2 size)
 Bars above/below a zero line (positive green, negative red).
 
void UI::barChart (const char *id, std::span< const BarDatum > bars, float width, float labelWidth)
 Horizontal bars with labels and values, scaled to the maximum.
 
bool UI::beginDataTable (const char *id, int columns, ImGuiTableFlags flags, float minWidth, ImVec2 size, int freezeColumns=1)
 Begins a data table that scrolls horizontally only when the region is narrower than minWidth, freezing the header row (and freezeColumns leading columns while scrolling). Pair with ImGui::EndTable() when true.
 
void UI::staticHeadersRow ()
 Header row of a non-sortable table: plain labels without the hover highlight that suggests a clickable header.
 
bool UI::primaryButton (const char *label, ImVec2 size=ImVec2(0, 0), ButtonSize buttonSize=ButtonSize::REGULAR)
 Accent-filled call-to-action button.
 
bool UI::secondaryButton (const char *label, ImVec2 size=ImVec2(0, 0), ButtonSize buttonSize=ButtonSize::REGULAR)
 Neutral button for secondary actions.
 
bool UI::dangerButton (const char *label, ImVec2 size=ImVec2(0, 0), ButtonSize buttonSize=ButtonSize::REGULAR)
 Red button for destructive actions (release, cancel contract).
 
float UI::buttonHeight (ButtonSize buttonSize=ButtonSize::REGULAR)
 Scaled height of a button class.
 
bool UI::moneyInput (const char *id, int64_t &value, const MoneyInputOptions &options={})
 Currency field showing the full amount; typing accepts plain numbers, either decimal mark and k/M/B (mila/mln/mld) units, with the reading or the reason for refusing it shown under the field. -/+ step 5% (Shift 10%, Ctrl 1%), chips set preset values.
 
int64_t UI::stepMoney (int64_t value, bool up, double fraction)
 Next value of a money input's -/+ button: fraction up or down, rounded to three significant figures, and always at least 1 away.
 
bool UI::parseMoney (std::string_view text, int64_t &value)
 Parses "14.4M", "1,5M", "850k", "€1,200,000", "€ 2,25 mln" (false when invalid or ambiguous; see NumberFormat::parseMoney()).
 
MoneyPreview UI::moneyPreview (std::string_view text, const MoneyInputOptions &options={})
 What moneyInput() shows for the typed text.
 
bool UI::toggleButton (const char *label, bool active, ImVec2 size=ImVec2(0, 0), ButtonSize buttonSize=ButtonSize::REGULAR)
 Filter/tab button: neutral when off, selection fill with an accent underline when on (one segment of UI::segmented()).
 
bool UI::segmented (const char *id, int &selected, std::span< const char *const > labels, float width=0.0f)
 Segmented control for small enumerations (joined buttons).
 
void UI::summaryRow (const char *label, const char *value, const ImVec4 *valueColor=nullptr, bool emphasis=false)
 Label on the left, value right-aligned; emphasis draws a rule above and a larger value (totals).
 
void UI::budgetImpact (const char *label, int64_t current, int64_t after, const char *reasonWhenNegative=nullptr)
 Budget before/after bar: "€20.0M -> €5.6M" (drawn arrow). The after part turns red below zero and the reason is shown underneath.
 
ColumnMask UI::fitColumns (std::span< const Column > columns, float availableWidth, float stretchMinimum=160.0f, ColumnMask hidden=0)
 Chooses the columns that fit the available width, dropping the highest priority numbers first (never horizontal scrolling).
 
ColumnMask UI::hiddenColumns (std::string_view table, std::span< const Column > columns)
 Columns the user hid in a table, saved in the settings per table.
 
bool UI::columnPicker (std::string_view table, std::span< const Column > columns, ColumnMask fitted)
 "Columns" button opening a checklist of the table's columns; the choice is saved in the settings at once. Priority-0 columns are listed but locked; columns that are on but squeezed out by the window width are marked as such.
 
bool UI::beginResponsiveTable (const char *id, std::span< const Column > columns, ColumnMask mask, ImGuiTableFlags flags, TableHeader header=TableHeader::STATIC, ImVec2 size=ImVec2(0, 0))
 BeginTable + setup of the visible columns and the header row. Pair with ImGui::EndTable() when it returns true. Re-opening the same id with TableHeader::NONE continues a table split around an inline detail strip (column widths stay shared).
 
bool UI::cell (ColumnMask mask, int index)
 Moves to the next cell when column index is visible.
 
bool UI::link (const char *label, const char *id)
 Selectable text that looks like a link; returns true on click.
 
void UI::keyValue (const char *key, const char *value, float keyWidth)
 Muted key on the left, value on the right of the current row.
 
bool UI::sameLineIfFits (float nextWidth, float spacing=-1.0f)
 SameLine() only when an item of the given width still fits.
 
float UI::buttonWidth (const char *label, ButtonSize buttonSize=ButtonSize::REGULAR)
 Width of a button with this label (at least the minimum width).
 
void UI::textRight (const char *text)
 Text right-aligned in the current table cell or content region.
 
void UI::textRightColored (const ImVec4 &color, const char *text)
 Coloured text right-aligned in the current cell.
 
template<typename T >
int UI::compare (const T &left, const T &right)
 Strictly-weak three-way comparison helper for table sorting.
 

Variables

constexpr float UI::Size::BUTTON = 36.0f
 
constexpr float UI::Size::BUTTON_COMPACT = 28.0f
 
constexpr float UI::Size::BUTTON_PADDING_X = 16.0f
 
constexpr float UI::Size::BUTTON_MIN_WIDTH = 96.0f