Skip to content

Commit

Permalink
Align the table header to the table when labels are used
Browse files Browse the repository at this point in the history
The table header is now also indented
if the table is given labels.
Regenerated table output in tests.
  • Loading branch information
evalott100 committed Nov 22, 2023
1 parent 93d6046 commit 12a44e5
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 116 deletions.
22 changes: 17 additions & 5 deletions src/pvi/_format/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def generate_component_formatters(
self,
c: Union[Group[Component], Component],
bounds: Bounds,
add_label=True,
add_label=False,
) -> Iterator[WidgetFormatter[T]]:
"""Convert a component into its WidgetFormatter equivalents
Expand Down Expand Up @@ -417,18 +417,30 @@ def generate_component_formatters(
c.children
), "Header length does not match number of elements"

if add_label:
# Scale the headers by the width with the label then
# indent them
original_width = len(c.layout.header) * (
component_bounds.w + self.layout.spacing
)
label_width = self.layout.label_width + self.layout.spacing

scaling_factor = (original_width - label_width) / original_width
component_bounds.w = int(component_bounds.w * scaling_factor)

component_bounds.indent(label_width)

# Create column headers
for column_header in c.layout.header:
yield self.widget_formatter_factory.header_formatter_cls(
component_bounds.copy(), column_header
)
component_bounds.x += component_bounds.w + self.layout.spacing

# Reset x and shift down y
component_bounds.x = bounds.x
# Reset x and w and shift down y
component_bounds = bounds.copy()
component_bounds.y += self.layout.widget_height + self.layout.spacing

add_label = False # Don't add a row label
row_components = c.children # Create a widget for each row of Group
# Allow given component width for each column, plus spacing
component_bounds = component_bounds.tile(
Expand Down Expand Up @@ -465,7 +477,7 @@ def generate_component_formatters(

if isinstance(c, SignalRef):
yield from self.generate_component_formatters(
self.components[c.name], row_bounds, add_label
self.components[c.name], row_bounds, add_label=add_label
)
return

Expand Down
130 changes: 91 additions & 39 deletions tests/format/output/static_table_BigTable.adl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ display {
object {
x=0
y=0
width=1652
width=1650
height=150
}
clr=14
Expand Down Expand Up @@ -91,7 +91,7 @@ rectangle {
object {
x=0
y=0
width=1652
width=1650
height=26
}
"basic attribute" {
Expand All @@ -102,7 +102,7 @@ text {
object {
x=0
y=0
width=1652
width=1650
height=26
}
"basic attribute" {
Expand All @@ -113,9 +113,9 @@ text {
}
text {
object {
x=4
x=158
y=30
width=408
width=369
height=20
}
"basic attribute" {
Expand All @@ -126,9 +126,9 @@ text {
}
text {
object {
x=416
x=531
y=30
width=408
width=369
height=20
}
"basic attribute" {
Expand All @@ -139,9 +139,9 @@ text {
}
text {
object {
x=828
x=904
y=30
width=408
width=369
height=20
}
"basic attribute" {
Expand All @@ -152,9 +152,9 @@ text {
}
text {
object {
x=1240
x=1277
y=30
width=408
width=369
height=20
}
"basic attribute" {
Expand All @@ -163,9 +163,22 @@ text {
textix="String Column"
align="horiz. centered"
}
text {
object {
x=4
y=54
width=150
height=20
}
"basic attribute" {
clr=14
}
textix="Row 1"
align="horiz. right"
}
byte {
object {
x=198
x=332
y=54
width=20
height=20
Expand All @@ -179,9 +192,9 @@ byte {
}
"text update" {
object {
x=416
x=531
y=54
width=408
width=369
height=20
}
monitor {
Expand All @@ -194,9 +207,9 @@ byte {
}
"text update" {
object {
x=828
x=904
y=54
width=408
width=369
height=20
}
monitor {
Expand All @@ -209,9 +222,9 @@ byte {
}
"text update" {
object {
x=1240
x=1277
y=54
width=408
width=369
height=20
}
monitor {
Expand All @@ -222,9 +235,22 @@ byte {
limits {
}
}
text {
object {
x=4
y=78
width=150
height=20
}
"basic attribute" {
clr=14
}
textix="Row 2"
align="horiz. right"
}
byte {
object {
x=198
x=332
y=78
width=20
height=20
Expand All @@ -238,9 +264,9 @@ byte {
}
"text update" {
object {
x=416
x=531
y=78
width=408
width=369
height=20
}
monitor {
Expand All @@ -253,9 +279,9 @@ byte {
}
"text update" {
object {
x=828
x=904
y=78
width=408
width=369
height=20
}
monitor {
Expand All @@ -268,9 +294,9 @@ byte {
}
"text update" {
object {
x=1240
x=1277
y=78
width=408
width=369
height=20
}
monitor {
Expand All @@ -281,9 +307,22 @@ byte {
limits {
}
}
text {
object {
x=4
y=102
width=150
height=20
}
"basic attribute" {
clr=14
}
textix="Row 3"
align="horiz. right"
}
byte {
object {
x=198
x=332
y=102
width=20
height=20
Expand All @@ -297,9 +336,9 @@ byte {
}
"text update" {
object {
x=416
x=531
y=102
width=408
width=369
height=20
}
monitor {
Expand All @@ -312,9 +351,9 @@ byte {
}
"text update" {
object {
x=828
x=904
y=102
width=408
width=369
height=20
}
monitor {
Expand All @@ -327,9 +366,9 @@ byte {
}
"text update" {
object {
x=1240
x=1277
y=102
width=408
width=369
height=20
}
monitor {
Expand All @@ -340,9 +379,22 @@ byte {
limits {
}
}
text {
object {
x=4
y=126
width=150
height=20
}
"basic attribute" {
clr=14
}
textix="Row 4"
align="horiz. right"
}
byte {
object {
x=198
x=332
y=126
width=20
height=20
Expand All @@ -356,9 +408,9 @@ byte {
}
"text update" {
object {
x=416
x=531
y=126
width=408
width=369
height=20
}
monitor {
Expand All @@ -371,9 +423,9 @@ byte {
}
"text update" {
object {
x=828
x=904
y=126
width=408
width=369
height=20
}
monitor {
Expand All @@ -386,9 +438,9 @@ byte {
}
"text update" {
object {
x=1240
x=1277
y=126
width=408
width=369
height=20
}
monitor {
Expand Down
Loading

0 comments on commit 12a44e5

Please sign in to comment.