theRAPTLab / gsgo

GEM-STEP Foundation repo migrated from GitLab June 2023
1 stars 1 forks source link

Feature: Text Styles (Partial Implementation) #800

Closed benloh closed 7 months ago

benloh commented 7 months ago

Addresses #783

This partially implements styling for character text.

Due to the complexity of implementing selection menu options for wizards, it is not possible at this time to use a selection menu to select alignment and justification values. Instead, you'll have to use a bitwise flags to combine settings.

The Graphing feature now has three feature properties:

To set text alignment:

addFeature Graphing
featProp character.Graphing.text setTo "Fish Under The Seam"
featProp character.Graphing.textAlign setTo 18
featProp character.Graphing.textJustification setTo 1
featProp character.Graphing.textColor setToColor 16768256 

Notes

Alignment

Alignments are set via bitwise flags that you can combine to determine the position. e.g. to set TOP use 1; e.g. to use TOP + CENTER add CENTER: 16 to TOP: 1 or 17. Use the table below for convenience.

featProp character.Graphing.textAlign setTo 18

Labels are set to appear just outside of the sprite bounding box so they don't cover the sprite. The exception is the MIDDLE + CENTER value which will appear in the middle of the sprite.

The default alignment is BOTTOM + CENTER.

TOP: 1         
MIDDLE: 2   // vertical
BOTTOM: 4
LEFT: 8
CENTER: 16  // horizontal
RIGHT: 32
alignment values
TOP LEFT: 9 TOP CENTER: 17 TOP RIGHT: 33
MIDDLE LEFT: 10 MIDDLE CENTER: 18 MIDDLE RIGHT: 34
BOTTOM LEFT: 12 BOTTOM CENTER: 20 BOTTOM RIGHT: 36

Justification

Justification only works for multiline text.

featProp character.Graphing.textJustification setTo 1

The default justification is CENTER.

LEFT: 1
CENTER: 2
RIGHT: 4

Color

Use the setToColor method to enable the color picker. Previously we applied a slightly transparent alpha to the text to soften the text, but the color picker does not allow alphas.

featProp character.Graphing.textColor setToColor 16768256 

Note to Future Ben for reference: See 2023-01107-wip-text-styles c86cae8 stash for how SlotEditor_Block might handle options in built-in features gvar options.

jdanish commented 7 months ago

I added in the help text for textAlign and textJustify and moved those to advanced.

I tested with a character that did and did not display a graph. All seems to work.

The one minor issue I found was that text color doesn't re-set. That is, if you have a call that changes the color to say red, it will stay red on reset. However, you can just explicitly set the color to white in init and this resolves it. So ... not a big deal. Otherwise, looks good to me!

benloh commented 7 months ago

The one minor issue I found was that text color doesn't re-set. That is, if you have a call that changes the color to say red, it will stay red on reset. However, you can just explicitly set the color to white in init and this resolves it. So ... not a big deal.

Yeah that one's harder to fix elegantly. Since we try to avoid setting/changing the color unnecessarily, the color will be retained. There are probably other feature props that are not being reset either.

Going to merge for now.