Defined in Viewable.Def Mixes in with Viewable BackgroundWithBorder HasBorder
Mixin BackgroundWithBorder provides the framework for a group of viewable objects that have borders and a filled-in background.
Remember that if the documentation and the software (especially the definition files) disagree, always trust the software.
Classes that inherit from mixin BackgroundWithBorder include HasBorder, Shelf, and Coupon. You will most often interact with class HasBorder, which is mixed in with many subclasses of class Viewable.
You will never work directly with objects of class BackgroundWithBorder. Instead, you will work with existing subclasses of Viewable that inherit from BackgroundWithBorder, or you will mix in BackgroundWithBorder with your own viewable subclasses.
You are also likely to use the most popular subclass of the BackgroundWithBorder mixin: the HasBorder mixin. Class HasBorder adds a border field and attribute, which allows instances of its implementors to have individualized borders. Mix in BackgroundWithBorder with your class instead of HasBorder when all members of your class will have the same border. For example, coupons all have the same dotted border. So class Coupon inherits from BackgroundWithBorder instead of from the more common HasBorder.
Instantiate: never Subclass: always Call its methods: rarely
You will rarely call the methods provided by the BackgroundWithBorder mixin directly. Instead, you will create a new class, mix in BackgroundWithBorder, override methods as appropriate, then put the objects of your subclass in place. The system makes calls to the border management methods as necessary.
The BackgroundWithBorder mixin has the following methods you might Call:
Method | Description |
---|---|
Drawing | |
Draw | Overridden to call drawbackground |
DrawBackground | Fill content with content color, draw border, and shadow |
Geometry and hit testing | |
CalcBorderBox | Return outer edge of border (border inside box outset by border thickness) |
CalcInsidePart | Return partcontent if probe is in the content, partborder if probe is on the border |
CalcOpaqueBox | Return content if opaque |
The BackgroundWithBorder mixin has the following methods you might Override:
Method | When to override |
---|---|
Border | To return the border of the viewable, if any, instead of defaulting to return nilobject |
BorderInsideBox | To control where border is drawn |
The BackgroundWithBorder mixin defines no fields.
attribute Border: Border, readOnly; // operation Border(): Object Call: sometimes Override: always
Call Border to get the border of the viewable.
This method returns nilObject by default. Override whenever you create a subclass to return the border used by members of your subclass.
operation BorderInsideBox(VAR bordered: Box) Call: sometimes Override: sometimes
Call BorderInsideBox to get the box that the border should be drawn around.
BorderInsideBox returns the content box of the bordered parameter. Override if you require different results. For example, you might want to inset the border if your viewable has portions that shouldn't be inside the border. Class TitledWindow does just this, to move the top of the border to just below the window's title bar.
overrides CalcBorderBox(VAR borderBox: Box) Call: sometimes Override: rarely
Call CalcBorderBox to get the outer edge of the border, which is the border inside box outset by the border thickness. CalcBorderBox returns this box in the borderBox parameter.
overrides CalcInsidePart(probe: Dot): Signed Call: rarely Override: rarely
Call CalcInsidePart to return the location of the probe. BackgroundWithBorder overrides CalcInsidePart to define a new part location: partBorder. It returns partContent if the probe is in the content of the viewable, and partBorder if the probe is on the border.
overrides CalcOpaqueBox(VAR opaque: Box) Call: rarely Override: rarely
Call CalcOpaqueBox to get the bordered object's opaque box.
BackgroundWithBorder overrides CalcOpaqueBox to test the alpha component of the object's color. If the content of the viewable isn't opaque, CalcOpaqueBox returns an empty box in opaque. Otherwise, it sets opaque by calling BorderInsideBox. If the viewable has a border, CalcOpaqueBox increases the box size by the thickness of the border.
overrides Draw Call: rarely Override: sometimes
BackgroundWithBorder overrides Draw to call DrawBackground. It does this so that the opaque box can be calculated properly. If you override the Draw method of a class that mixes in BackgroundWithBorder, you should make sure to include a call to DrawBackground.
operation DrawBackground(canvas: Canvas; clip: Path) Call: sometimes Override: often
Call DrawBackground to draw the border and the background of a bordered viewable object. DrawBackground draws a shadow if necessary, draws a border if necessary, fills the BorderInsideBox of the viewable, and draws a special highlight for unbordered viewables.