I currently have ImageButtons implemented in my working copy, but I would like to get some feedback on some details. Here is the constructor and theme options for the new class:
class ImageButton(Widget): """A clickable image-based button.""" theme_section = 'ImageButton' theme_options = {'DefaultImage': (None, 0, 0, 1, 1), 'Default2Image': (None, 0, 0, 1, 1), 'HoverImage': (None, 0, 0, 1, 1), 'ClickImage': (None, 0, 0, 1, 1) } def __init__(self, parent, name, default_image=None, default2_image=None, hover_image=None, click_image=None, aspect=None, size=[1,1], pos=[0,0], sub_theme='', options=BGUI_DEFAULT): """ :param parent: the widget's parent :param name: the name of the widget :param default_image: list containing image data for the default state ('image', xcoord, ycoord, xsize, ysize) :param default2_image: list containing image data for a second default state, which is used for toggling ('image', xcoord, ycoord, xsize, ysize) :param hover_image: list containing image data for the hover state ('image', xcoord, ycoord, xsize, ysize) :param click_image: list containing image data for the click state ('image', xcoord, ycoord, xsize, ysize) :param aspect: constrain the widget size to a specified aspect ratio :param size: a tuple containing the width and height :param pos: a tuple containing the x and y position :param sub_theme: name of a sub_theme defined in the theme file (similar to CSS classes) :param options: various other options """
And here is an example of how to use the new class:
self.audio_button = bgui.ImageButton(self.win, 'ab', sub_theme='Audio', size=[0.05, 0.05], pos=[0.75, 0.05])
And the relevant theme data:
[ImageButton:Audio] DefaultImage=img:audio.png, 0, 0, 0.5, 1 Default2Image=img:audio.png, 0.5, 0, 0.5, 1
Now time for some questions. First off, the theme file is formated as img:filename, x, y, height, width. Should this instead be img:filename, x1, y1, x2, y2? If I changed this, I would also change the *_image arguments in the constructor. Also, should some sort of mechanism be added for user defined states? Currently things are kind of limited, but I’d think users could subclass if they wanted more flexibility. Any other feedback?
Cheers,
Moguri
If you forced the user to give the x1, x2 etc coordinates, it breaks the workflow from your previous examples.
I would (for continuity’s sake) use the x, y and width, height arguments, as they are the traditional method for BGUI.
I can see the similarity between the former method and CSS, but in this instance you should be fine.
This is a nice system by the way; it seems very professional in comparison to other Blender Libraries.