Source code for simvx.core.ui.enums
"""UI enums: FocusMode, FocusDirection, PointerFilter, AcceptsPointers, Anchor, SizeFlags, HAlign, VAlign."""
from enum import IntFlag, StrEnum
from ..alignment import HAlign, VAlign
from ..input.enums import FocusMode
__all__ = ["FocusMode", "FocusDirection", "PointerFilter", "AcceptsPointers", "Anchor", "SizeFlags", "HAlign", "VAlign"]
[docs]
class FocusDirection(StrEnum):
"""Which way a directional focus move goes.
Tab order is a list and moves along it; a pad's D-pad and stick move on
screen, so a direction is a geometric question answered from the controls'
rects rather than from their order in the tree.
"""
UP = "up"
DOWN = "down"
LEFT = "left"
RIGHT = "right"
[docs]
class PointerFilter(StrEnum):
"""How a control takes part in the pointer hit test.
A hit-testing policy, not a handler one: it decides who is *under* the
pointer, while ``consume`` decides who stops the broadcast, so the two never
arbitrate the same decision.
Members:
IGNORE: Invisible to the hit test. The pointer passes through as though
the control were not there. What a widget that is only looked at
declares: ``Label``, ``ProgressBar``.
PASS: Hit-testable, and does not stop the pointer reaching what is
behind it. Both the control and whatever sits under it are offered
the event, nearest first. The default, so a panel or a container
over a game viewport never eats a click meant for the game.
STOP: Hit-testable, and blocks. Nothing behind it sees the pointer.
What a widget the player operates declares: a button, a slider, a
text field, a dialog.
A property takes the member or its plain string: ``panel.pointer_filter =
"ignore"`` and ``panel.pointer_filter = PointerFilter.IGNORE`` are the same
assignment.
"""
IGNORE = "ignore"
PASS = "pass"
STOP = "stop"
[docs]
class AcceptsPointers(StrEnum):
"""Which pointers a control takes, once the hit test has found it.
A separate question from :class:`PointerFilter`, which decides whether the
control is under the pointer at all. This one decides how many pointers it
can hold at once, and only a widget built for several fingers answers
anything but the default.
Members:
PRIMARY: The primary pointer only, which is the mouse and the finger
standing in for it. Every ordinary widget wants this: a button
pressed by two fingers at once is one press.
ALL: Every pointer, each tracked on its own, for a widget that means
something different under two fingers: an on-screen pad, a pinch
surface, a drawing canvas.
"""
PRIMARY = "primary"
ALL = "all"
[docs]
class Anchor(StrEnum):
"""Where a control sits in its parent's rect, for :attr:`Control.anchor`.
Each member fixes the control on both axes, and on each axis it is one of
three kinds. A *side* (left, right, top, bottom) holds the control against
that edge of the parent, :attr:`Control.inset` pixels in from it. A *centre*
centres it between the two insets. A *wide* axis stretches it from one inset
to the other, and its size on that axis is ignored.
``BOTTOM_WIDE`` with ``size=(0, 48)`` is a full-width strip 48 tall along
the bottom; ``FULL_RECT`` with ``inset=10`` fills the parent less 10 all round.
"""
TOP_LEFT = "top_left"
TOP_RIGHT = "top_right"
BOTTOM_LEFT = "bottom_left"
BOTTOM_RIGHT = "bottom_right"
CENTER_LEFT = "center_left"
CENTER_RIGHT = "center_right"
CENTER_TOP = "center_top"
CENTER_BOTTOM = "center_bottom"
CENTER = "center"
LEFT_WIDE = "left_wide"
RIGHT_WIDE = "right_wide"
TOP_WIDE = "top_wide"
BOTTOM_WIDE = "bottom_wide"
FULL_RECT = "full_rect"
[docs]
class SizeFlags(IntFlag):
"""Controls how a widget behaves inside a container layout.
Composable via bitwise OR: ``SizeFlags.EXPAND | SizeFlags.FILL``.
"""
SHRINK_BEGIN = 0
FILL = 1
EXPAND = 2
EXPAND_FILL = 3 # EXPAND | FILL
SHRINK_CENTER = 4
SHRINK_END = 8