Skip to content

Commit

Permalink
Inset the text area morph content.
Browse files Browse the repository at this point in the history
  • Loading branch information
ronsaldo committed Nov 30, 2023
1 parent a64d596 commit 1001a42
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions package-sources/Morphic.Core/AbstractTextAreaMorph.sysmel
Expand Up @@ -183,18 +183,23 @@ public class AbstractTextAreaMorph superclass: BorderedMorph; definition: {
##printLine("AbstractTextAreaMorph onTextEditing ", event text, " ", event start, " ", event length).
}.

public method textAreaLocalBounds => RectangleF32
:= self localBounds insetBy: 2f32x2.

public override method buildSceneGraphWith: (builder: FormSGBuilder) ::=> FormSGNode := {
let nodes := OrderedCollection new.
nodes add: (builder rectangle: self localBounds color: self backgroundColorToUse).

let textAreaLocalBounds := self textAreaLocalBounds.

let fontFace := self fontFaceToUse.
let textColor := self colorToUse.
let fontWidth := fontFace width.
let fontHeight := fontFace height.
let textBuffer := model textBuffer.

let minXPosition := self localBounds min x.
let maxXPosition := self localBounds max x.
let minXPosition := textAreaLocalBounds min x.
let maxXPosition := textAreaLocalBounds max x.

let cursorColor := Color cyan.
let cursorBackgroundColor := Color cyan.
Expand All @@ -217,8 +222,8 @@ public class AbstractTextAreaMorph superclass: BorderedMorph; definition: {
textBuffer forIndex: minIndex computeLine: startLine andColumn: startColumn.
textBuffer forIndex: maxIndex computeLine: endLine andColumn: endColumn.

let startPosition := (startColumn asFloat32*fontWidth) @ (startLine asFloat32*fontHeight).
let endPosition := (endColumn asFloat32*fontWidth) @ ((endLine + 1sz) asFloat32*fontHeight).
let startPosition := textAreaLocalBounds min + ((startColumn asFloat32*fontWidth) @ (startLine asFloat32*fontHeight)).
let endPosition := textAreaLocalBounds min + ((endColumn asFloat32*fontWidth) @ ((endLine + 1sz) asFloat32*fontHeight)).

startLine = endLine ifTrue: {
nodes add: (builder rectangle: (RectangleF32 min: startPosition max: endPosition) color: cursorBackgroundColor)
Expand All @@ -231,7 +236,7 @@ public class AbstractTextAreaMorph superclass: BorderedMorph; definition: {

model textBuffer stringSpansDo: {:(String)string :(Size)startIndex :(Size)endIndex :: Void |
nodes add: (builder string: string from: startIndex until: endIndex
in: self localBounds
in: textAreaLocalBounds
fontFace: fontFace color: textColor
)
}.
Expand All @@ -243,7 +248,7 @@ public class AbstractTextAreaMorph superclass: BorderedMorph; definition: {
let column mutable := 0sz.
textBuffer forIndex: each endIndex computeLine: line andColumn: column.

let cursorPosition := (column asFloat32*fontFace width)@(line asFloat32*fontHeight).
let cursorPosition := textAreaLocalBounds min + ((column asFloat32*fontFace width)@(line asFloat32*fontHeight)).
nodes add: (builder rectangle: (cursorPosition extent: cursorExtent) color: cursorColor)
}.

Expand Down

0 comments on commit 1001a42

Please sign in to comment.