Module albow.widgets.ValueDisplay
Source code
from pygame import Surface
from albow.core.ui.Widget import Widget
from albow.widgets.Control import Control
from albow.utils import blit_in_rect
class ValueDisplay(Control, Widget):
"""
A ValueDisplay is a Control that provides a read-only textual display of a value.
"""
format = "%s"
"""
Format string to be used when displaying the value. Also see the format_value() method below.
"""
align = 'l'
"""
How to align the value. Default is 'l'
"""
def __init__(self, width=100, **kwds):
Widget.__init__(self, **kwds)
self.set_size_for_text(width)
def draw(self, surface: Surface):
value = self.value
text = self.format_value(value)
buf = self.font.render(text, True, self.fg_color)
frame = surface.get_rect()
blit_in_rect(surface, buf, frame, self.align, self.margin)
def format_value(self, value):
if value is not None:
return self.format % value
else:
return ""
Classes
class ValueDisplay (width=100, **kwds)-
A ValueDisplay is a Control that provides a read-only textual display of a value.
Source code
class ValueDisplay(Control, Widget): """ A ValueDisplay is a Control that provides a read-only textual display of a value. """ format = "%s" """ Format string to be used when displaying the value. Also see the format_value() method below. """ align = 'l' """ How to align the value. Default is 'l' """ def __init__(self, width=100, **kwds): Widget.__init__(self, **kwds) self.set_size_for_text(width) def draw(self, surface: Surface): value = self.value text = self.format_value(value) buf = self.font.render(text, True, self.fg_color) frame = surface.get_rect() blit_in_rect(surface, buf, frame, self.align, self.margin) def format_value(self, value): if value is not None: return self.format % value else: return ""Ancestors
Class variables
var align-
How to align the value. Default is 'l'
var format-
Format string to be used when displaying the value. Also see the format_value() method below.
Methods
def format_value(self, value)-
Source code
def format_value(self, value): if value is not None: return self.format % value else: return ""
Inherited members
Control:Widget:Widget:addadd_anchoradd_centeredanchorattention_lostaugment_mouse_eventbg_colorbg_imageborder_colorborder_widthcall_handlercall_parent_handlerdefer_drawingdismissdraw_overfg_colorfocusfocus_switchfontget_cursorget_focusget_margin_rectget_rootget_top_widgetget_visibleglobal_to_localhas_focusinheritedinvalidateis_gl_containerkey_downkey_uplocal_to_globalmarginmenu_barparentparent_resizedpresentrectrelative_moderemoveremove_anchorresizedscale_bgsel_colorset_parentset_size_for_texttab_stopvisible