Add Matrix Support by LuYifei2011 · Pull Request #573 · scratchblocks/scratchblocks · GitHub
Skip to content

Add Matrix Support#573

Open
LuYifei2011 wants to merge 2 commits into
scratchblocks:mainfrom
LuYifei2011:509-matrix
Open

Add Matrix Support#573
LuYifei2011 wants to merge 2 commits into
scratchblocks:mainfrom
LuYifei2011:509-matrix

Conversation

@LuYifei2011

Copy link
Copy Markdown
Contributor

Closes #509

This pull request adds support for matrix inputs to the block rendering and model logic for both Scratch 2 and Scratch 3 styles. It introduces a new Matrix class for representing matrix inputs, updates the rendering logic to visually display matrices in blocks, and refines the stringification and alignment logic to handle multi-line matrix values. The changes are grouped into model/data layer improvements and rendering/UI enhancements.

Model/Data Layer Improvements:

  • Added a new Matrix class to syntax/model.js to represent matrix inputs, with automatic row padding and custom stringification for alignment.
  • Updated the Input class in syntax/model.js to recognize and handle matrix inputs, including logic for label handling, stringification with alignment, and translation. [1] [2] [3]
  • Refactored the Block class stringification in syntax/model.js to pass line prefixes for proper matrix alignment in block text output.
  • Added a displayWidth utility to calculate correct alignment for mixed-language matrix input rows.

Rendering/UI Enhancements:

  • Added MatrixView rendering classes to both scratch2/blocks.js and scratch3/blocks.js for visual display of matrix inputs, including cell sizing, layout, and color logic. [1] [2]
  • Updated InputView in both scratch2/blocks.js and scratch3/blocks.js to detect matrix inputs and render them using the new MatrixView, with proper sizing, padding, and integration with other input types. [1] [2] [3] [4] [5] [6] [7] [8]

Integration and Syntax Support:

  • Exported the new Matrix class in the syntax module and updated block definitions to use matrix input types. [1] [2] [3]
  • Minor refactoring and formatting improvements in the syntax layer to ensure matrix support is integrated with existing block painting and input parsing logic. [1] [2]

See #509 for further information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Matrix Support

1 participant