[Mono-winforms-list] Button 2.0 Patch
Jonathan Pobst
monkey at jpobst.com
Tue Feb 27 13:19:50 EST 2007
Hey everyone,
I've finished up an initial implementation of all the new layout changes
to Button 2.0. Since the method I ended up going with is a departure
from what we had, I thought I would run it by people before I commit.
In the current way our theming works for Button, drawing is done by one
call from ButtonBase: DrawButtonBase, which calculates and draws every
permutation of FlatStyle [4 options] for Button, CheckBox, and
RadioButton. Each theme must fully reimplement this do-all function to
draw a button. For 2.0, there are many more permutations: AutoEllipsis
[2 options], TextImageRelation [5 options], UseMnemonic [2 options], and
UseCompatibleTextRendering [2 options]. Also, there are 5 new options
in FlatAppearance used when FlatStyle = Flat.
Therefore, I have tried to break it down a bit. There is a new class
called ThemeElements that solely handles painting an element, such as a
standard button or a checkbox. The elements will be broken down along
roughly the same lines as what is used in the VisualStyle namespace, as
it is extremely granular. Additionally, it should make a XP/Vista Theme
trivial to implement, and make it easy for the VisualStyle namespace to
support drawing on other platforms.
For example, here are the 3 functions currently in ThemeElements:
public static void DrawButton (Graphics g, Rectangle bounds,
ButtonThemeState state, Color backColor, Color foreColor)
public static void DrawFlatButton (Graphics g, Rectangle bounds,
ButtonThemeState state, Color backColor, Color foreColor,
FlatButtonAppearance appearance)
public static void DrawPopupButton (Graphics g, Rectangle
bounds, ButtonThemeState state, Color backColor, Color foreColor)
(state is an enum of Normal, Entered, Pressed, Disabled, Default)
These functions ONLY draw the button graphic in a given rectangle.
Things like text and image layout and drawing is still handled in Theme,
as it is much more likely to be reused across all themes, though it is
overridable as well.
By breaking things down this way, it should greatly reduce the work
required for each theme. Each theme will generally need to override a
function that simply draws the button graphic in a rectangle, instead of
calculate and draw every permutation of button.
I made the changes for Win32. It's backwards compatibile, so Nice and
Clearlooks will draw the 1.1 button still, ignoring the 2.0 options.
Also, only Button will currently draw the 2.0 features, RadioButton and
CheckBox are not updated even though the properties will be settable in
ButtonBase.
Thoughts? Concerns? Suggestions? Anyone read past the first paragraph?
Jon
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: theme.patch
Url: http://lists.ximian.com/pipermail/mono-winforms-list/attachments/20070227/0311b953/attachment-0001.pl
More information about the Mono-winforms-list
mailing list