Debian Codegraph @

docs/widgets/attrs.md

raw symbols SCIP
1 All widgets share a set of attributes that can be used to make things look the way you want. Here is a quick overview on them.
2
3 !!! note
4
5 This API will likely be reformed in the future to be properly controllable through YAML config files. The underlying attributes will remain the same, but the way to access/modify them will be improved.
6
7 ## Applicable to all
8
9 ### Parent align
10
11 This attribute can be used to tell a widget's parent to align it left, right or center.
12
13 Possible values:
14
15 - `HorizontalAlignment.LEFT` or `0`: Aligns to the left side.
16 - `HorizontalAlignment.CENTER` or `1`: Aligns to the center.
17 - `HorizontalAlignment.RIGHT` or `2`: Aligns to the right.
18
19 Default: `HorizontalAlignment.CENTER`
20
21 ```termage include=docs/src/widgets/attrs/parent_align.py width=60 height=10
22 ```
23
24 ### Size policy
25
26 Widget width adjustments are handled through a system of policies. The basics are:
27
28 - `SizePolicy.FILL`: The widget will take up the entire width provided by its parent.
29 - `SizePolicy.STATIC`: The widget will remain at a certain width, and its parent will never try to resize it.
30 - `SizePolicy.RELATIVE`: The widget will take up a certain percentage of its parent's width, denoted by a floating point value between 0 and 1.
31
32 While you _can_ set these manually, it's easier for the both of us if you use the helper properties instead:
33
34 <p style="padding-top: 5px"></p>
35
36 ```termage-svg chrome=false height=23 title="Size policy helpers"
37 from pytermgui import inspect, Widget
38 print(inspect(Widget.static_width.fget, show_header=False))
39 print("\n")
40 print(inspect(Widget.relative_width.fget, show_header=False))
41 ```
42
43 Default: `SizePolicy.FILL`
44
45 !!! warning
46
47 `SizePolicy.STATIC` can cause various issues if the parent widget doesn't have enough width available. If using it, _make sure to make sure_ that the parent will never be smaller than the given widget!
48
49 ```termage include=docs/src/widgets/attrs/size_policy.py width=60
50 ```
51
52 ## Applicable to Container
53
54 ### Box
55
56 The container `border` and `corner` characters can be set to a few presets, which are defined in the [boxes](/reference/pytermgui/widgets/boxes) module.
57
58 Setting the `box` attribute to either a `Box` instance or an upper-cased box name will set both the `border` and `corner` characters to those defined by the box.
59
60 Default: `SINGLE` for `Container`, `DOUBLE` for `Window`.
61
62 ```termage include=docs/src/widgets/attrs/box.py height=80
63 ```
64
65 ## Applicable to Window
66
67 !!! note
68
69 Container's [attributes](#applicable-to-container) also apply to Window.
70
71
72 ### Title
73
74 Windows can display text on the top-left corner of their borders.
75
76 !!! warning
77
78 You can only use markup in titles if the given window's `corner_style` parses TIM. This will always be the case with string-based shorthand styles, but may not be for custom callables. See the [styling](/widgets/styling#modifying-styles) section for more info!
79
80 Default: `""`
81
82 ```termage include=docs/src/widgets/attrs/title.py
83 ```