Widget

class tanmatsu.widgets.Widget(w: ~tanmatsu.size.SizeResolver = <tanmatsu.size.ParentRequested object>, h: ~tanmatsu.size.SizeResolver = <tanmatsu.size.ParentRequested object>, theme: ~tanmatsu.theme.Theme = <tanmatsu.theme.DefaultTheme object>)

Bases: ABC

Abstract base class. Parent class of all widgets.

Parameters
get_min_size(parent_size: Dimensions) Dimensions
Returns the minimum possible size that the widget could resolve to

when layout() is called.

get_max_size(parent_size: Dimensions) Dimensions
Returns the maximum possible size that the widget could resolve to

when layout() is called.

get_actual_size(parent_size: Dimensions, requested_size: Dimensions) Dimensions
Returns the actual size that the widget will resolve to

when layout() is called.

layout(position: Point, parent_size: Dimensions, requested_size: Dimensions)

Calculates the widget layout. Will be called before every draw().

Parameters
  • position (Point) – The location of this widget in space.

  • parent_size (Dimensions) – The size of the parent widget. Used when resolving sizes. See the classes in module size.

  • requested_size (Dimensions) – The size that the parent widget requests this widget to be. Used when resolving sizes. See the classes in module size.

abstract draw(s: Screenbuffer, clip: tanmatsu.geometry.Rectangle | None = None)

Draws the widget to the given screenbuffer.

Parameters
  • screenbuffer (Screenbuffer) – The Screenbuffer to draw to.

  • clip (Rectangle) – An area, outside of which, this widget should not be drawn.

Note

If a widget has child widgets, it must make sure to pass the correct clip to them when drawing.

The widget must pass self._Widget__available_space to the geometry.Rectangle.__and__() method of the clip it receives, and then pass the resulting clip to the child widget when calling draw() on it, so that the clips correctly combine and propogate down the chain.

mouse_event(button: Mouse_button, modifier: Mouse_modifier, state: Mouse_state, position: Point) bool

Process a mouse event.

Returns

True: Treat the mouse event as consumed. Do not pass the mouse event to other widgets after this one.

False: Treat the mouse event as ignored. Pass the mouse event to other widgets after this one.

keyboard_event(key: tanmatsu.input.Keyboard_key | str, modifier: Keyboard_modifier) bool

Process a keyboard event.

Parameters
Returns

True: Treat the keyboard event as consumed. Do not pass the keyboard event to other widgets after this one.

False: Treat the keyboard event as ignored. Pass the keyboard event to other widgets after this one.