Each widget should have a separate View class which defines how the widget should be displayed, and contains the images and theming options.
A rough initial design:
Created with, MyView(size).
View(size):
flags = 0 # Can use custom flags for Surface, such as SRCALPHA
states = ("state1", "state2")
elements = {"extra1": (2,2)} # ID: initial position
fonts = {"label": Font["widget"]} # This should allow for flexible fonts.
def set_image(id, image, resize): Set the image to the given Surface or image file. Specify if the widget size should be changed to the image's size, or the image resized to widget size, or image should be clipped.
def add_text(id, text, pos): Adds text to be rendered at pos (pos should support dynamic rect positioning).
def change_text(id, text=None, pos=None): Change the text and/or position of a piece of text.
def remove_text(id): Remove a piece of text.
def dotted_rect(rect): Draw dotted rect around rect area to show focus, remove dotted rect if False.
def switch(state): Switch to given state.
def render: Renders any changes since last render, and returns the image. Can use custom blit flags etc. in here.
def _prerender: Draw the base images for each state and extra element. Will have access to size, font size etc. Elements need access to widget size, font size and other element sizes. Will be called on render() if not already done, or after a resize. Will likely be broken up into further methods, one for each image.
# Need to be able to move and show/hide elements
view["extra1"].pos = (45, 2)
view["extra1"].show = True
# Maybe use full class for each image, to theme:
view["state1"].set_image(image, resize)
# Or:
for id, image in zip(ids, images): view[id].set_image(image, resize)
# Should also be able to create View with no size, then update size later, this can also be used for dynamic resizing.
view = View()
view.set_size(200, 20)
The widget can call these things to update the view, which caches the changes to be made. When the toolkit wants to blit everything, it calls render() on each widget, which will render the cached changes and return the updated image.
Each widget should have a separate View class which defines how the widget should be displayed, and contains the images and theming options.
A rough initial design:
Created with, MyView(size).
View(size):
flags = 0 # Can use custom flags for Surface, such as SRCALPHA
states = ("state1", "state2")
elements = {"extra1": (2,2)} # ID: initial position
fonts = {"label": Font["widget"]} # This should allow for flexible fonts.
def set_image(id, image, resize): Set the image to the given Surface or image file. Specify if the widget size should be changed to the image's size, or the image resized to widget size, or image should be clipped.
def add_text(id, text, pos): Adds text to be rendered at pos (pos should support dynamic rect positioning).
def change_text(id, text=None, pos=None): Change the text and/or position of a piece of text.
def remove_text(id): Remove a piece of text.
def dotted_rect(rect): Draw dotted rect around rect area to show focus, remove dotted rect if False.
def switch(state): Switch to given state.
def render: Renders any changes since last render, and returns the image. Can use custom blit flags etc. in here.
def _prerender: Draw the base images for each state and extra element. Will have access to size, font size etc. Elements need access to widget size, font size and other element sizes. Will be called on render() if not already done, or after a resize. Will likely be broken up into further methods, one for each image.
# Need to be able to move and show/hide elements ].set_image( image, resize) .set_image( image, resize)
view["extra1"].pos = (45, 2)
view["extra1"].show = True
# Maybe use full class for each image, to theme:
view["state1"
# Or:
for id, image in zip(ids, images): view[id]
# Should also be able to create View with no size, then update size later, this can also be used for dynamic resizing.
view = View()
view.set_size(200, 20)
The widget can call these things to update the view, which caches the changes to be made. When the toolkit wants to blit everything, it calls render() on each widget, which will render the cached changes and return the updated image.