CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-imgui

Cython-based Python bindings for dear imgui - a bloat-free immediate mode graphical user interface library

Pending
Overview
Eval results
Files

tables.mddocs/

Tables

Modern table system with sorting, resizing, reordering, and scrolling capabilities. The table API provides a powerful and flexible way to display structured data with interactive features, replacing the legacy column system with a more robust solution.

Capabilities

Table Management

Core functions for creating and managing table structures.

def begin_table(label: str, column: int, flags: int = 0, outer_width: float = 0, outer_height: float = 0, inner_width: float = 0.0) -> bool:
    """Begin table definition. Returns True if table is visible."""

def end_table() -> None:
    """End table definition."""

def table_next_row(row_flags: int = 0, min_row_height: float = 0.0) -> None:
    """Move to next table row."""

def table_next_column() -> bool:
    """Move to next table column. Returns True if column is visible."""

def table_set_column_index(column_n: int) -> bool:
    """Set current table column by index. Returns True if column is visible."""

Table Setup

Functions for configuring table columns and behavior before adding content.

def table_setup_column(label: str, flags: int = 0, init_width_or_weight: float = 0.0, user_id: int = 0) -> None:
    """Setup table column properties."""

def table_setup_scroll_freeze(cols: int, rows: int) -> None:
    """Setup frozen columns and rows (like Excel freeze panes)."""

def table_headers_row() -> None:
    """Submit table headers row using column labels."""

def table_header(label: str) -> None:
    """Submit individual table header cell."""

Table Information

Functions to query table state and properties.

def table_get_sort_specs():
    """Get table sort specifications object."""

def table_get_column_count() -> int:
    """Get number of columns in current table."""

def table_get_column_index() -> int:
    """Get current column index."""

def table_get_row_index() -> int:
    """Get current row index."""

def table_get_column_name(column_n: int = -1) -> str:
    """Get column name by index (-1 for current column)."""

def table_get_column_flags(column_n: int = -1) -> int:
    """Get column flags by index (-1 for current column)."""

def table_set_background_color(target: int, color: int, column_n: int = -1) -> None:
    """Set table background color for row, cell, or column."""

Table Flags

Constants for controlling table behavior and appearance.

# Basic table flags
TABLE_NONE: int
TABLE_RESIZABLE: int              # Enable column resizing
TABLE_REORDERABLE: int            # Enable column reordering
TABLE_HIDEABLE: int               # Enable column hiding
TABLE_SORTABLE: int               # Enable sorting
TABLE_NO_SAVED_SETTINGS: int      # Disable saving settings
TABLE_CONTEXT_MENU_IN_BODY: int   # Right-click context menu in body

# Border flags
TABLE_BORDERS_INNER_HORIZONTAL: int
TABLE_BORDERS_OUTER_HORIZONTAL: int
TABLE_BORDERS_INNER_VERTICAL: int
TABLE_BORDERS_OUTER_VERTICAL: int
TABLE_BORDERS_HORIZONTAL: int     # Inner + outer horizontal
TABLE_BORDERS_VERTICAL: int       # Inner + outer vertical
TABLE_BORDERS_INNER: int          # Inner horizontal + vertical
TABLE_BORDERS_OUTER: int          # Outer horizontal + vertical
TABLE_BORDERS: int                # All borders
TABLE_NO_BORDERS_IN_BODY: int
TABLE_NO_BORDERS_IN_BODY_UTIL_RESIZE: int

# Decoration flags
TABLE_ROW_BACKGROUND: int         # Alternating row background colors

# Sizing flags
TABLE_SIZING_FIXED_FIT: int       # Columns fit contents
TABLE_SIZING_FIXED_SAME: int      # All columns same width
TABLE_SIZING_STRETCH_PROP: int    # Columns stretch proportionally
TABLE_SIZING_STRETCH_SAME: int    # Columns stretch equally

# Size constraint flags
TABLE_NO_HOST_EXTEND_X: int       # Disable extending beyond outer_size.x
TABLE_NO_HOST_EXTEND_Y: int       # Disable extending beyond outer_size.y
TABLE_NO_KEEP_COLUMNS_VISIBLE: int # Allow columns to be completely hidden
TABLE_PRECISE_WIDTHS: int         # Disable distributing remainder width

# Clipping flags
TABLE_NO_CLIP: int                # Disable clipping

# Padding flags
TABLE_PAD_OUTER_X: int            # Enable outer padding
TABLE_NO_PAD_OUTER_X: int         # Disable outer padding
TABLE_NO_PAD_INNER_X: int         # Disable inner padding

# Scrolling flags
TABLE_SCROLL_X: int               # Enable horizontal scrolling
TABLE_SCROLL_Y: int               # Enable vertical scrolling

# Sorting flags
TABLE_SORT_MULTI: int             # Enable multi-column sorting
TABLE_SORT_TRISTATE: int          # Allow no sorting state

Table Column Flags

Constants for controlling individual column behavior.

# Basic column flags
TABLE_COLUMN_NONE: int
TABLE_COLUMN_DEFAULT_HIDE: int    # Default as hidden column
TABLE_COLUMN_DEFAULT_SORT: int    # Default as sorting column
TABLE_COLUMN_WIDTH_STRETCH: int   # Column will stretch
TABLE_COLUMN_WIDTH_FIXED: int     # Column has fixed width
TABLE_COLUMN_NO_RESIZE: int       # Disable manual resizing
TABLE_COLUMN_NO_REORDER: int      # Disable manual reordering
TABLE_COLUMN_NO_HIDE: int         # Disable hiding
TABLE_COLUMN_NO_CLIP: int         # Disable clipping for this column
TABLE_COLUMN_NO_SORT: int         # Disable sorting on this column
TABLE_COLUMN_NO_SORT_ASCENDING: int  # Disable ascending sort
TABLE_COLUMN_NO_SORT_DESCENDING: int # Disable descending sort
TABLE_COLUMN_NO_HEADER_WIDTH: int    # Don't contribute to auto column width
TABLE_COLUMN_PREFER_SORT_ASCENDING: int  # Prefer ascending sort
TABLE_COLUMN_PREFER_SORT_DESCENDING: int # Prefer descending sort
TABLE_COLUMN_INDENT_ENABLE: int      # Use current indent
TABLE_COLUMN_INDENT_DISABLE: int     # Ignore current indent

# Status flags (read-only)
TABLE_COLUMN_IS_ENABLED: int      # Column is enabled
TABLE_COLUMN_IS_VISIBLE: int      # Column is visible
TABLE_COLUMN_IS_SORTED: int       # Column is sorted
TABLE_COLUMN_IS_HOVERED: int      # Column is hovered

Table Background Target

Constants for specifying background color targets.

TABLE_BACKGROUND_TARGET_NONE: int
TABLE_BACKGROUND_TARGET_ROW_BG0: int  # Row background color 0
TABLE_BACKGROUND_TARGET_ROW_BG1: int  # Row background color 1
TABLE_BACKGROUND_TARGET_CELL_BG: int  # Cell background color

Table Row Flags

Constants for controlling table row behavior.

TABLE_ROW_NONE: int
TABLE_ROW_HEADERS: int            # Identify header row

Usage Examples

Basic Table

import imgui

# Simple table with data
data = [
    ["Alice", 25, "Engineer"],
    ["Bob", 30, "Designer"],
    ["Charlie", 35, "Manager"],
]

if imgui.begin_table("Simple Table", 3):
    # Setup columns
    imgui.table_setup_column("Name")
    imgui.table_setup_column("Age")
    imgui.table_setup_column("Role")
    imgui.table_headers_row()
    
    # Add data rows
    for row in data:
        imgui.table_next_row()
        for i, item in enumerate(row):
            imgui.table_set_column_index(i)
            imgui.text(str(item))
    
    imgui.end_table()

Advanced Table with Features

# Table with borders, sorting, and resizing
table_flags = (imgui.TABLE_BORDERS | imgui.TABLE_RESIZABLE | 
               imgui.TABLE_SORTABLE | imgui.TABLE_ROW_BACKGROUND)

if imgui.begin_table("Advanced Table", 4, table_flags):
    # Setup columns with specific properties
    imgui.table_setup_column("ID", imgui.TABLE_COLUMN_WIDTH_FIXED, 50)
    imgui.table_setup_column("Name", imgui.TABLE_COLUMN_DEFAULT_SORT)
    imgui.table_setup_column("Score", imgui.TABLE_COLUMN_WIDTH_FIXED, 80)
    imgui.table_setup_column("Actions", imgui.TABLE_COLUMN_NO_SORT, 100)
    imgui.table_headers_row()
    
    # Sample data
    items = [
        (1, "Alice", 95.5),
        (2, "Bob", 87.2),
        (3, "Charlie", 92.8),
        (4, "Diana", 89.1),
    ]
    
    for item_id, name, score in items:
        imgui.table_next_row()
        
        imgui.table_next_column()
        imgui.text(str(item_id))
        
        imgui.table_next_column()
        imgui.text(name)
        
        imgui.table_next_column()
        imgui.text(f"{score:.1f}")
        
        imgui.table_next_column()
        if imgui.small_button(f"Edit##{item_id}"):
            print(f"Edit {name}")
        imgui.same_line()
        if imgui.small_button(f"Delete##{item_id}"):
            print(f"Delete {name}")
    
    imgui.end_table()

Scrolling Table

# Large table with scrolling
if imgui.begin_table("Scrolling Table", 3, 
                     imgui.TABLE_BORDERS | imgui.TABLE_SCROLL_Y, 
                     0, 200):  # Fixed height of 200 pixels
    
    imgui.table_setup_column("Index")
    imgui.table_setup_column("Value")
    imgui.table_setup_column("Description")
    imgui.table_headers_row()
    
    # Generate many rows
    for i in range(100):
        imgui.table_next_row()
        
        imgui.table_next_column()
        imgui.text(str(i))
        
        imgui.table_next_column()
        imgui.text(f"Value {i}")
        
        imgui.table_next_column()
        imgui.text(f"Description for item {i}")
    
    imgui.end_table()

Table with Frozen Columns

# Table with frozen first column and header
if imgui.begin_table("Frozen Table", 5, 
                     imgui.TABLE_BORDERS | imgui.TABLE_SCROLL_X | imgui.TABLE_SCROLL_Y,
                     0, 200):
    
    # Freeze first column and header row
    imgui.table_setup_scroll_freeze(1, 1)
    
    imgui.table_setup_column("Name", imgui.TABLE_COLUMN_WIDTH_FIXED, 100)
    imgui.table_setup_column("Jan")
    imgui.table_setup_column("Feb")
    imgui.table_setup_column("Mar")
    imgui.table_setup_column("Apr")
    imgui.table_headers_row()
    
    months_data = [
        ("Sales", [1200, 1350, 1180, 1420]),
        ("Marketing", [800, 920, 750, 1100]),
        ("Development", [2200, 2100, 2400, 2300]),
        ("Support", [600, 650, 580, 720]),
    ]
    
    for department, values in months_data:
        imgui.table_next_row()
        
        imgui.table_next_column()
        imgui.text(department)
        
        for value in values:
            imgui.table_next_column()
            imgui.text(str(value))
    
    imgui.end_table()

Table with Custom Styling

# Table with custom colors and styling
if imgui.begin_table("Styled Table", 3, imgui.TABLE_BORDERS):
    imgui.table_setup_column("Status")
    imgui.table_setup_column("Task")
    imgui.table_setup_column("Progress")
    imgui.table_headers_row()
    
    tasks = [
        ("Complete", "Design UI", 100),
        ("In Progress", "Implement Backend", 75),
        ("Pending", "Write Tests", 0),
    ]
    
    for status, task, progress in tasks:
        imgui.table_next_row()
        
        # Color-code status column
        imgui.table_next_column()
        if status == "Complete":
            imgui.table_set_background_color(imgui.TABLE_BACKGROUND_TARGET_CELL_BG, 
                                            imgui.get_color_u32_rgba(0.2, 0.8, 0.2, 0.3))
        elif status == "In Progress":
            imgui.table_set_background_color(imgui.TABLE_BACKGROUND_TARGET_CELL_BG,
                                            imgui.get_color_u32_rgba(0.8, 0.8, 0.2, 0.3))
        else:
            imgui.table_set_background_color(imgui.TABLE_BACKGROUND_TARGET_CELL_BG,
                                            imgui.get_color_u32_rgba(0.8, 0.2, 0.2, 0.3))
        imgui.text(status)
        
        imgui.table_next_column()
        imgui.text(task)
        
        imgui.table_next_column()
        imgui.progress_bar(progress / 100.0, (-1, 0), f"{progress}%")
    
    imgui.end_table()

Sortable Table

# Table with sorting capabilities
if imgui.begin_table("Sortable Table", 3, 
                     imgui.TABLE_BORDERS | imgui.TABLE_SORTABLE):
    
    imgui.table_setup_column("Name", imgui.TABLE_COLUMN_DEFAULT_SORT)
    imgui.table_setup_column("Score")
    imgui.table_setup_column("Rank")
    imgui.table_headers_row()
    
    # Check if sorting is needed
    sort_specs = imgui.table_get_sort_specs()
    if sort_specs and sort_specs.specs_dirty:
        # Sort your data based on sort_specs
        print("Table needs sorting")
        # In a real application, you would sort your data here
    
    # Add table data (would be sorted in real application)
    players = [
        ("Alice", 95, 1),
        ("Bob", 87, 3),
        ("Charlie", 92, 2),
    ]
    
    for name, score, rank in players:
        imgui.table_next_row()
        imgui.table_next_column()
        imgui.text(name)
        imgui.table_next_column()
        imgui.text(str(score))
        imgui.table_next_column()
        imgui.text(str(rank))
    
    imgui.end_table()

Install with Tessl CLI

npx tessl i tessl/pypi-imgui

docs

drawing.md

index.md

input.md

integrations.md

layout.md

menus.md

styling.md

tables.md

tabs.md

widgets.md

windows.md

tile.json