hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en/latest/
MIT License
12.63k stars 669 forks source link

Table not honoring pos= keyword #1819

Open MaineTim opened 2 years ago

MaineTim commented 2 years ago

Version of Dear PyGui

Version: 1.6.2 Operating System: Windows 10, Opensuse Tumbleweed

My Issue/Question

When attempting to position a table at a specific spot in the window using the pos keyword, the table seems to ignore the keyword and is placed "next in line" within the window layout. If, for example, pos=(100,100) is given, in an empty window it will be placed at (0,0). It will, however, report (100,100) if queried with get_item_position().

.# To Reproduce

Steps to reproduce the behavior:

Sample code provided.

Expected behavior

The table should be started at (0,100), rather than placed in the normal flow of the layout, as it is now.

Screenshots/Video

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg
import random
import string

def generate_entries():
    entries = []
    for x in range(1, 1000):
        entry = {}
        for y in ["A", "B", "C", "D", "E"]:
            entry[y] = "".join(random.SystemRandom().choices(string.ascii_uppercase, k=6))
        entries.append(entry)
    return entries

def draw_result_table(results, parent):
    table = dpg.add_table(header_row=True, parent=parent, pos=(0,100))
    dpg.add_table_column(label="A", parent=table)
    dpg.add_table_column(label="B", parent=table)
    dpg.add_table_column(label="C", parent=table)
    dpg.add_table_column(label="D", parent=table)
    dpg.add_table_column(label="E", parent=table)
    if results:
        row_count = 0
        for row in results:
            row_count += 1
            with dpg.table_row(parent=table):
                dpg.add_button(
                    tag="row" + str(row_count), label=row["A"], width=100, callback=cb_click_me, user_data=row
                )
                dpg.add_text(row["B"])
                dpg.add_text(row["C"])
                dpg.add_text(row["D"])
                dpg.add_text(row["E"])
    return table

def cb_click_me():
    print("I was clicked!")

def main():
    dpg.create_context()
    dpg.create_viewport(title="TestPos", width=1500, height=800, decorated=True)

    with dpg.window(tag="main", label="Window Test"):
        dpg.add_menu_bar()
    results = generate_entries()
    table = draw_result_table(results, "main")
    print(dpg.get_item_pos(table))
    dpg.set_primary_window("main", True)
    dpg.setup_dearpygui()
    dpg.show_viewport()
    dpg.start_dearpygui()
    dpg.destroy_context()

if __name__ == "__main__":
    main()
mrtnRitter commented 6 months ago

Same issue here.

The workaround is to put the table in a group and positioning the group.