Skip to content

Commit

Permalink
ui/textview: Add FontSize property
Browse files Browse the repository at this point in the history
  • Loading branch information
roblillack committed May 22, 2024
1 parent fdbaee1 commit 18a4ae0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
6 changes: 3 additions & 3 deletions examples/hello-spot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ func main() {
&ui.Label{X: 210, Y: 100, Width: 180, Height: 25, Value: "Current backend:"},
&BlinkingLabel{X: 210, Y: 120, Width: 180, Height: 30, Text: ui.BackendName, Size: 20},
spot.Make(QuitButton),
&ui.TextField{
&ui.TextView{
X: 10, Y: 10, Width: 380, Height: 80,
Value: randText,
FontSize: 11,
Text: randText,
// FontSize: 11,
// Editable: false, Selectable: false, Bezeled: false, NoBackground: false,
},
},
Expand Down
13 changes: 7 additions & 6 deletions ui/textview.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package ui
import "github.com/roblillack/spot"

type TextView struct {
X int
Y int
Width int
Height int
Text string
ref nativeTypeTextView
X int
Y int
Width int
Height int
Text string
FontSize int
ref nativeTypeTextView
}

var _ spot.Component = &TextView{}
Expand Down
21 changes: 16 additions & 5 deletions ui/textview_cocoa.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/roblillack/spot"
)

type nativeTypeTextView = *gocoa.TextView
type nativeTypeTextView = *gocoa.TextField

func (w *TextView) Update(nextComponent spot.Control) bool {
next, ok := nextComponent.(*TextView)
Expand All @@ -17,7 +17,12 @@ func (w *TextView) Update(nextComponent spot.Control) bool {

if next.Text != w.Text {
w.Text = next.Text
w.ref.SetText(w.Text)
w.ref.SetStringValue(w.Text)
}

if next.FontSize != w.FontSize && w.FontSize > 0 {
w.FontSize = next.FontSize
w.ref.SetFontSize(w.FontSize)
}

return true
Expand All @@ -28,11 +33,17 @@ func (w *TextView) Mount(parent spot.Control) any {
return w.ref
}

w.ref = gocoa.NewTextView(w.X, w.Y, w.Width, w.Height)
w.ref.SetText(w.Text)
w.ref = gocoa.NewTextField(w.X, w.Y, w.Width, w.Height)
w.ref.SetStringValue(w.Text)
w.ref.SetFontFamily("Arial")
w.ref.SetEditable(false)
w.ref.SetSelectable(true)
if w.FontSize > 0 {
w.ref.SetFontSize(w.FontSize)
}

if window, ok := parent.(*Window); ok && window != nil && window.ref != nil {
window.ref.AddTextView(w.ref)
window.ref.AddTextField(w.ref)
}

return w.ref
Expand Down
2 changes: 1 addition & 1 deletion ui/textview_fltk.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (w *TextView) Mount(parent spot.Control) any {
w.ref = goFltk.NewTextDisplay(w.X, w.Y, w.Width, w.Height)
w.ref.SetBuffer(goFltk.NewTextBuffer())
w.ref.Buffer().SetText(w.Text)
w.ref.Deactivate()
// w.ref.Deactivate()
w.ref.SetWrapMode(goFltk.WRAP_AT_BOUNDS, 0)

if window, ok := parent.(*Window); ok && window != nil && window.ref != nil {
Expand Down

0 comments on commit 18a4ae0

Please sign in to comment.