1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-12 08:38:10 +00:00

Merge pull request #338 from thewhodidthis/bf#334--font

visual/Form/Slider: clean up font family handling
This commit is contained in:
Alain Pitiot 2021-05-31 13:04:16 +02:00 committed by GitHub
commit f9b9620dca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View File

@ -43,6 +43,7 @@ import {Slider} from './Slider';
* @param {number[]} [options.items= []] - the array of labels * @param {number[]} [options.items= []] - the array of labels
* @param {number} [options.itemPadding= 0.05] - the granularity * @param {number} [options.itemPadding= 0.05] - the granularity
* *
* @param {string} [options.font= 'Arial'] - the text font
* @param {string} [options.fontFamily= 'Helvetica'] - the text font * @param {string} [options.fontFamily= 'Helvetica'] - the text font
* @param {boolean} [options.bold= true] - whether or not the font of the labels is bold * @param {boolean} [options.bold= true] - whether or not the font of the labels is bold
* @param {boolean} [options.italic= false] - whether or not the font of the labels is italic * @param {boolean} [options.italic= false] - whether or not the font of the labels is italic
@ -56,7 +57,7 @@ import {Slider} from './Slider';
*/ */
export class Form extends util.mix(VisualStim).with(ColorMixin) export class Form extends util.mix(VisualStim).with(ColorMixin)
{ {
constructor({name, win, pos, size, units, borderColor, fillColor, itemColor, markerColor, responseColor, color, contrast, opacity, depth, items, randomize, itemPadding, fontFamily, bold, italic, fontSize, clipMask, autoDraw, autoLog} = {}) constructor({name, win, pos, size, units, borderColor, fillColor, itemColor, markerColor, responseColor, color, contrast, opacity, depth, items, randomize, itemPadding, font, fontFamily, bold, italic, fontSize, clipMask, autoDraw, autoLog} = {})
{ {
super({name, win, units, opacity, depth, pos, size, clipMask, autoDraw, autoLog}); super({name, win, units, opacity, depth, pos, size, clipMask, autoDraw, autoLog});
@ -119,6 +120,13 @@ export class Form extends util.mix(VisualStim).with(ColorMixin)
); );
// fonts: // fonts:
this._addAttribute(
'font',
font,
'Arial',
this._onChange(true, true)
);
// Not in use at present
this._addAttribute( this._addAttribute(
'fontFamily', 'fontFamily',
fontFamily, fontFamily,
@ -726,7 +734,7 @@ export class Form extends util.mix(VisualStim).with(ColorMixin)
const textStimOption = { const textStimOption = {
win: this._win, win: this._win,
name: 'item text', name: 'item text',
font: 'Arial', font: this.font,
units: this._units, units: this._units,
alignHoriz: 'left', alignHoriz: 'left',
alignVert: 'top', alignVert: 'top',
@ -742,7 +750,10 @@ export class Form extends util.mix(VisualStim).with(ColorMixin)
name: 'choice response', name: 'choice response',
units: this._units, units: this._units,
flip: false, flip: false,
fontFamily: 'Arial', // Not part of Slider options as things stand
fontFamily: this.fontFamily,
// As found in Slider options
font: this.font,
bold: false, bold: false,
italic: false, italic: false,
fontSize: this._fontSize * this._responseTextHeightRatio, fontSize: this._fontSize * this._responseTextHeightRatio,
@ -761,7 +772,7 @@ export class Form extends util.mix(VisualStim).with(ColorMixin)
flip: false, flip: false,
opacity: 1, opacity: 1,
depth: this._depth + 1, depth: this._depth + 1,
font: 'Arial', font: this.font,
letterHeight: this._fontSize * this._responseTextHeightRatio, letterHeight: this._fontSize * this._responseTextHeightRatio,
bold: false, bold: false,
italic: false, italic: false,

View File

@ -45,7 +45,7 @@ import {PsychoJS} from "../core/PsychoJS";
* and labels with respect to the central bar * and labels with respect to the central bar
* @param {boolean} [options.readOnly= false] - whether or not the slider is read only * @param {boolean} [options.readOnly= false] - whether or not the slider is read only
* *
* @param {string} [options.fontFamily= 'Helvetica'] - the text font * @param {string} [options.font= 'Arial'] - the text font
* @param {boolean} [options.bold= true] - whether or not the font of the labels is bold * @param {boolean} [options.bold= true] - whether or not the font of the labels is bold
* @param {boolean} [options.italic= false] - whether or not the font of the labels is italic * @param {boolean} [options.italic= false] - whether or not the font of the labels is italic
* @param {number} [options.fontSize] - the font size of the labels (in pixels), the default fontSize depends on the * @param {number} [options.fontSize] - the font size of the labels (in pixels), the default fontSize depends on the
@ -131,7 +131,7 @@ export class Slider extends util.mix(VisualStim).with(ColorMixin, WindowMixin)
this._addAttribute( this._addAttribute(
'font', 'font',
font, font,
'Helvetica', 'Arial',
this._onChange(true, true) this._onChange(true, true)
); );
this._addAttribute( this._addAttribute(