Improve gauge grid layout
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# pyright: reportGeneralTypeIssues=false
|
||||
|
||||
from collections.abc import Generator
|
||||
from typing import cast
|
||||
|
||||
import dearpygui.dearpygui as dpg
|
||||
import pytest
|
||||
@@ -9,6 +10,10 @@ import dpg_gauges as dpgg
|
||||
from dpg_gauges.state import clear_registry, get_gauge_state
|
||||
|
||||
|
||||
def _children(item: int | str) -> dict[int, list[int | str]]:
|
||||
return cast(dict[int, list[int | str]], dpg.get_item_children(item))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dpg_context() -> Generator[None]:
|
||||
clear_registry()
|
||||
@@ -76,3 +81,42 @@ def test_panel_and_grid_are_lightweight_containers(dpg_context: None) -> None:
|
||||
assert dpg.does_item_exist("engine")
|
||||
assert dpg.does_item_exist("engine_grid")
|
||||
assert get_gauge_state("temp").renderer is not None
|
||||
|
||||
|
||||
def test_grid_columns_wrap_gauges_into_rows(dpg_context: None) -> None:
|
||||
with dpg.window(label="Dashboard", width=720), dpgg.gauge_grid(
|
||||
tag="wrap_grid", columns=3, min_column_width=1
|
||||
):
|
||||
for index in range(5):
|
||||
dpgg.digital_gauge(tag=f"metric_{index}", value=index, height=60)
|
||||
|
||||
children = _children("wrap_grid")
|
||||
assert len(children[0]) == 3
|
||||
assert len(children[1]) == 2
|
||||
assert [len(_children(row)[1]) for row in children[1]] == [3, 2]
|
||||
|
||||
|
||||
def test_grid_auto_reduces_columns_to_parent_width(dpg_context: None) -> None:
|
||||
with dpg.window(label="Narrow", width=380), dpgg.gauge_grid(
|
||||
tag="narrow_grid", columns=3, min_column_width=180
|
||||
):
|
||||
for index in range(5):
|
||||
dpgg.digital_gauge(tag=f"narrow_metric_{index}", value=index, height=60)
|
||||
|
||||
children = _children("narrow_grid")
|
||||
assert len(children[0]) == 2
|
||||
assert len(children[1]) == 3
|
||||
assert [len(_children(row)[1]) for row in children[1]] == [2, 2, 1]
|
||||
|
||||
|
||||
def test_grid_routes_panels_without_stealing_panel_children(dpg_context: None) -> None:
|
||||
with dpg.window(label="Nested", width=520), dpgg.gauge_grid(tag="nested_grid", columns=2):
|
||||
with dpgg.gauge_panel(tag="nested_panel", height=120):
|
||||
dpgg.digital_gauge(tag="inside_panel", value=1, height=60)
|
||||
dpgg.digital_gauge(tag="beside_panel", value=2, height=60)
|
||||
|
||||
panel_cell = cast(int | str, dpg.get_item_parent("nested_panel"))
|
||||
assert dpg.get_item_type(panel_cell) == "mvAppItemType::mvTableCell"
|
||||
assert dpg.get_item_parent("inside_panel") == "nested_panel"
|
||||
beside_cell = cast(int | str, dpg.get_item_parent("beside_panel"))
|
||||
assert dpg.get_item_type(beside_cell) == "mvAppItemType::mvTableCell"
|
||||
|
||||
Reference in New Issue
Block a user