# Path: pyglet_gui/override.py
# class Label(pyglet.text.Label):
# 
#     def update(self):
#         self._update()
# 
#     def unload(self):
#         self.delete()
# 
# Path: pyglet_gui/constants.py
# HALIGN_LEFT = -1
# 
# HALIGN_RIGHT = 1
# 
# Path: pyglet_gui/controllers.py
# class TwoStateController(Controller):
#     def __init__(self, is_pressed=False, on_press=None):
#         Controller.__init__(self)
# 
#         self._is_pressed = is_pressed
#         self._on_press = lambda y: y
#         if on_press is not None:
#             self._on_press = on_press
# 
#     @property
#     def is_pressed(self):
#         return self._is_pressed
# 
#     def change_state(self):
#         self._is_pressed = not self._is_pressed
#         self._on_press(self._is_pressed)
# 
# Path: pyglet_gui/core.py
# class Viewer(Rectangle, Managed):
#     def __init__(self, width=0, height=0):
#         super(Managed, self).__init__()
#         self._parent = None
#         self._is_loaded = False
# 
#         Rectangle.__init__(self, 0, 0, width, height)
# 
#     @property
#     def parent(self):
#         return self._parent
# 
#     @parent.setter
#     def parent(self, widget):
#         self._parent = widget
# 
#     @property
#     def is_loaded(self):
#         return self._is_loaded
# 
#     def is_expandable(self):
#         return False
# 
#     def set_position(self, x, y):
#         super(Viewer, self).set_position(x, y)
#         self.layout()
# 
#     def get_path(self):
#         raise NotImplementedError
# 
#     def load(self):
#         assert not self._is_loaded
#         self._is_loaded = True
#         self.load_graphics()
# 
#     def unload(self):
#         assert self._is_loaded
#         self._is_loaded = False
#         self.unload_graphics()
# 
#     def reload(self):
#         self.unload()
#         self.load()
# 
#     def load_graphics(self):
#         pass
# 
#     def unload_graphics(self):
#         pass
# 
#     def layout(self):
#         pass
# 
#     def compute_size(self):
#         return self.width, self.height
# 
#     def reset_size(self, reset_parent=True):
#         width, height = self.compute_size()
# 
#         # if out size changes
#         if self.width != width or self.height != height:
#             self.width, self.height = width, height
# 
#             # This will eventually call our layout
#             if reset_parent:
#                 self.parent.reset_size(reset_parent)
#         # else, the parent is never affected and thus we layout.
#         else:
#             self.layout()
# 
#     def delete(self):
#         if self.is_loaded:
#             self.unload()
#         self.parent = None
#         Managed.delete(self)
# 
# Path: pyglet_gui/mixins.py
# class FocusMixin(Controller, Viewer):
#     def __init__(self):
#         Controller.__init__(self)
#         Viewer.__init__(self)
#         self._focus = None
#         self._focus_flag = False
# 
#     def on_gain_focus(self):
#         self._focus_flag = True
#         FocusMixin.load_graphics(self)
#         FocusMixin.layout(self)
#         return True
# 
#     def on_lose_focus(self):
#         self._focus_flag = False
#         FocusMixin.unload_graphics(self)
#         return True
# 
#     def is_focus(self):
#         return self._focus_flag
# 
#     def load_graphics(self):
#         theme = self.theme[self.get_path()]
# 
#         self._focus = theme['focus']['image'].generate(theme['focus_color'], **self.get_batch('highlight'))
# 
#     def unload_graphics(self):
#         self._focus.unload()
#         self._focus = None
# 
#     def layout(self):
#         if self._focus is not None:
#             self._focus.update(self.x, self.y, self.width, self.height)
# 
#     def delete(self):
#         if self._focus is not None:
#             FocusMixin.unload_graphics(self)


import pyglet.window
from pyglet_gui.override import Label
from pyglet_gui.constants import HALIGN_LEFT, HALIGN_RIGHT
from pyglet_gui.controllers import TwoStateController
from pyglet_gui.core import Viewer
from pyglet_gui.mixins import FocusMixin
        self._label = Label(self.label,
                            font_name=theme['font'],
                            font_size=theme['font_size'],
                            color=theme['text_color'],
                            **self.get_batch('foreground'))

    def unload_graphics(self):
        self._button.unload()
        self._label.unload()

    def compute_size(self):
        # Treat the height of the label as ascent + descent
        font = self._label.document.get_font()
        height = font.ascent - font.descent

        return self._button.get_needed_size(self._label.content_width, height)

    def layout(self):
        self._button.update(self.x, self.y, self.width, self.height)

        # centers the label on the middle of the button
        x, y, width, height = self._button.get_content_region()

        font = self._label.document.get_font()
        self._label.x = x + width/2 - self._label.content_width/2
        self._label.y = y + height/2 - font.ascent/2 - font.descent
        self._label.update()

    def delete(self):
        TwoStateController.delete(self)

# Path: pyglet_gui/override.py
# class Label(pyglet.text.Label):
# 
#     def update(self):
#         self._update()
# 
#     def unload(self):
#         self.delete()
# 
# Path: pyglet_gui/constants.py
# HALIGN_LEFT = -1
# 
# HALIGN_RIGHT = 1
# 
# Path: pyglet_gui/controllers.py
# class TwoStateController(Controller):
#     def __init__(self, is_pressed=False, on_press=None):
#         Controller.__init__(self)
# 
#         self._is_pressed = is_pressed
#         self._on_press = lambda y: y
#         if on_press is not None:
#             self._on_press = on_press
# 
#     @property
#     def is_pressed(self):
#         return self._is_pressed
# 
#     def change_state(self):
#         self._is_pressed = not self._is_pressed
#         self._on_press(self._is_pressed)
# 
# Path: pyglet_gui/core.py
# class Viewer(Rectangle, Managed):
#     def __init__(self, width=0, height=0):
#         super(Managed, self).__init__()
#         self._parent = None
#         self._is_loaded = False
# 
#         Rectangle.__init__(self, 0, 0, width, height)
# 
#     @property
#     def parent(self):
#         return self._parent
# 
#     @parent.setter
#     def parent(self, widget):
#         self._parent = widget
# 
#     @property
#     def is_loaded(self):
#         return self._is_loaded
# 
#     def is_expandable(self):
#         return False
# 
#     def set_position(self, x, y):
#         super(Viewer, self).set_position(x, y)
#         self.layout()
# 
#     def get_path(self):
#         raise NotImplementedError
# 
#     def load(self):
#         assert not self._is_loaded
#         self._is_loaded = True
#         self.load_graphics()
# 
#     def unload(self):
#         assert self._is_loaded
#         self._is_loaded = False
#         self.unload_graphics()
# 
#     def reload(self):
#         self.unload()
#         self.load()
# 
#     def load_graphics(self):
#         pass
# 
#     def unload_graphics(self):
#         pass
# 
#     def layout(self):
#         pass
# 
#     def compute_size(self):
#         return self.width, self.height
# 
#     def reset_size(self, reset_parent=True):
#         width, height = self.compute_size()
# 
#         # if out size changes
#         if self.width != width or self.height != height:
#             self.width, self.height = width, height
# 
#             # This will eventually call our layout
#             if reset_parent:
#                 self.parent.reset_size(reset_parent)
#         # else, the parent is never affected and thus we layout.
#         else:
#             self.layout()
# 
#     def delete(self):
#         if self.is_loaded:
#             self.unload()
#         self.parent = None
#         Managed.delete(self)
# 
# Path: pyglet_gui/mixins.py
# class FocusMixin(Controller, Viewer):
#     def __init__(self):
#         Controller.__init__(self)
#         Viewer.__init__(self)
#         self._focus = None
#         self._focus_flag = False
# 
#     def on_gain_focus(self):
#         self._focus_flag = True
#         FocusMixin.load_graphics(self)
#         FocusMixin.layout(self)
#         return True
# 
#     def on_lose_focus(self):
#         self._focus_flag = False
#         FocusMixin.unload_graphics(self)
#         return True
# 
#     def is_focus(self):
#         return self._focus_flag
# 
#     def load_graphics(self):
#         theme = self.theme[self.get_path()]
# 
#         self._focus = theme['focus']['image'].generate(theme['focus_color'], **self.get_batch('highlight'))
# 
#     def unload_graphics(self):
#         self._focus.unload()
#         self._focus = None
# 
#     def layout(self):
#         if self._focus is not None:
#             self._focus.update(self.x, self.y, self.width, self.height)
# 
#     def delete(self):
#         if self._focus is not None:
#             FocusMixin.unload_graphics(self)


# Path: pyglet_gui/buttons.py
import pyglet.window
from pyglet_gui.override import Label
from pyglet_gui.constants import HALIGN_LEFT, HALIGN_RIGHT
from pyglet_gui.controllers import TwoStateController
from pyglet_gui.core import Viewer
from pyglet_gui.mixins import FocusMixin

        self._label = Label(self.label,
                            font_name=theme['font'],
                            font_size=theme['font_size'],
                            color=theme['text_color'],
                            **self.get_batch('foreground'))

    def unload_graphics(self):
        self._button.unload()
        self._label.unload()

    def compute_size(self):
        # Treat the height of the label as ascent + descent
        font = self._label.document.get_font()
        height = font.ascent - font.descent

        return self._button.get_needed_size(self._label.content_width, height)

    def layout(self):
        self._button.update(self.x, self.y, self.width, self.height)

        # centers the label on the middle of the button
        x, y, width, height = self._button.get_content_region()

        font = self._label.document.get_font()
        self._label.x = x + width/2 - self._label.content_width/2
        self._label.y = y + height/2 - font.ascent/2 - font.descent
        self._label.update()

    def delete(self):
        TwoStateController.delete(self)

        Viewer.delete(self)