Class BoxCaption
java.lang.Object
org.inspirenxe.strata.core.control.BoxCaption
The layout a checkbox, a radio button and a toggle switch share: a box at the left edge, vertically centered, and
a caption a gap to its right, centered on the box's middle. Right to left, the box is at the right edge and the
caption a gap to its left. Each control keeps one, measures its caption and sizes
its box through it, and draws its own box in the rectangle
box gives.
The caption is resolved in the normal and disabled styles, and the wider and taller of the two count, so enabling or disabling the control needs no new layout. Its mnemonic marker is taken out, and each is also kept with the mnemonic underlined, for drawing while mnemonics show. An empty caption leaves the gap out. The box's rectangle is kept from one frame to the next while the control's bounds and the box size stay the same, so the same rectangle comes back and painting allocates nothing.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloatbaseline(float height) Returns the caption's baseline in a control of a given height, aspaintCaption(Painter, Rect, boolean, boolean, boolean)places the caption.org.inspirenxe.strata.api.geometry.Rectbox(org.inspirenxe.strata.api.geometry.Rect bounds, boolean rightToLeft) Returns the box's rectangle in a control's bounds: at the left edge, or the right edge right to left, centered vertically.floatmeasureCaption(org.inspirenxe.strata.api.text.Text text, org.inspirenxe.strata.api.text.TextStyle style, org.inspirenxe.strata.api.text.TextStyle disabledStyle, org.inspirenxe.strata.api.text.TextMetrics metrics) Resolves and measures the caption in the normal and disabled styles.intmnemonic()Returns the caption's mnemonic as of the last measure.voidpaintCaption(org.inspirenxe.strata.api.extension.Painter painter, org.inspirenxe.strata.api.geometry.Rect bounds, boolean enabled, boolean showMnemonic, boolean rightToLeft) Draws the caption the gap beside the box, right of it or left of it right to left, centered on the bounds' middle, in the normal or disabled style.org.inspirenxe.strata.api.geometry.Sizesize(float width, float height) Sets the box's size and returns the control's desired size: the box, plus the gap and the caption unless the caption is empty, and as tall as the taller of the box and the caption.
-
Constructor Details
-
BoxCaption
public BoxCaption(float gap) Creates the layout with no caption and an empty box.- Parameters:
gap- the space between the box and the caption, in UI units
-
-
Method Details
-
measureCaption
public float measureCaption(org.inspirenxe.strata.api.text.Text text, org.inspirenxe.strata.api.text.TextStyle style, org.inspirenxe.strata.api.text.TextStyle disabledStyle, org.inspirenxe.strata.api.text.TextMetrics metrics) Resolves and measures the caption in the normal and disabled styles.- Parameters:
text- the captionstyle- the normal styledisabledStyle- the style while the control is disabledmetrics- the text metrics- Returns:
- the taller of the two captions' heights
-
mnemonic
public int mnemonic()Returns the caption's mnemonic as of the last measure.- Returns:
- the mnemonic in lower case, or
Mnemonics.NONE
-
size
public org.inspirenxe.strata.api.geometry.Size size(float width, float height) Sets the box's size and returns the control's desired size: the box, plus the gap and the caption unless the caption is empty, and as tall as the taller of the box and the caption.- Parameters:
width- the box's widthheight- the box's height- Returns:
- the desired size
-
box
public org.inspirenxe.strata.api.geometry.Rect box(org.inspirenxe.strata.api.geometry.Rect bounds, boolean rightToLeft) Returns the box's rectangle in a control's bounds: at the left edge, or the right edge right to left, centered vertically.- Parameters:
bounds- the control's boundsrightToLeft- whether the control runs right to left- Returns:
- the box, the same rectangle as last time while it did not move or change size
-
baseline
public float baseline(float height) Returns the caption's baseline in a control of a given height, aspaintCaption(Painter, Rect, boolean, boolean, boolean)places the caption.- Parameters:
height- the control's height- Returns:
- the baseline below the control's top, or NaN for an empty caption
-
paintCaption
public void paintCaption(org.inspirenxe.strata.api.extension.Painter painter, org.inspirenxe.strata.api.geometry.Rect bounds, boolean enabled, boolean showMnemonic, boolean rightToLeft) Draws the caption the gap beside the box, right of it or left of it right to left, centered on the bounds' middle, in the normal or disabled style. Draws nothing for an empty caption.- Parameters:
painter- what to draw withbounds- the control's boundsenabled- false for the disabled styleshowMnemonic- true to underline the mnemonicrightToLeft- whether the control runs right to left
-