diff --git a/README.md b/README.md index 643f919..de4f136 100644 --- a/README.md +++ b/README.md @@ -185,22 +185,22 @@ Explanation of the status column: \ ⚠️ Partially implemented / ✅ Done -| Name | Description | Native controls used | Status | -| --------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ----------- | -| [Button](https://pkg.go.dev/github.com/roblillack/spot/ui#Button) | Simple button to initiate an action | [Fl_Button](https://www.fltk.org/doc-1.4/classFl__Button.html)
NSButton | ✅ | -| [Checkbox](https://pkg.go.dev/github.com/roblillack/spot/ui#Checkbox) | Control offering the user a choice between two mutually exclusive options | [Fl_Check_Button](https://www.fltk.org/doc-1.4/classFl__Check__Button.html)
NSButton | ✅ | -| ComboBox | A combined dropdown menu with text input | ComboBox
NSComboBox | Not started | -| [Dial](https://pkg.go.dev/github.com/roblillack/spot/ui#Dial) | Circular status control | [Fl_Dial](https://www.fltk.org/doc-1.4/classFl__Dial.html)
NSProgressIndicator (with `NSCircular` style) | ⚠️ | -| [Dropdown](https://pkg.go.dev/github.com/roblillack/spot/ui#Dropdown) | Drop-down menu to select a single item out of multiple options | [Fl_Choice](https://www.fltk.org/doc-1.4/classFl__Choice.html)
NSPopUpButton | ✅ | -| Image | An image control | Image
NSImageView | Not started | -| [Label](https://pkg.go.dev/github.com/roblillack/spot/ui#Label) | Simple, non-editable text label | [Fl_Box](https://www.fltk.org/doc-1.4/classFl__Box.html)
[NSTextField](https://developer.apple.com/documentation/appkit/nstextfield) | ✅ | -| ListBox | A list control | List
NSTableView | 🚧 | -| [ProgressBar](https://pkg.go.dev/github.com/roblillack/spot/ui#ProgressBar) | Progress bar control to visualize the progression of a long-running operation | Progress
NSProgress | ✅ | -| [Slider](https://pkg.go.dev/github.com/roblillack/spot/ui#Slider) | Horizontal slider input control | [Fl_Slider](https://www.fltk.org/doc-1.4/classFl__Slider.html)
NSSlider | ✅ | -| [Spinner](https://pkg.go.dev/github.com/roblillack/spot/ui#Spinner) | Number input control with up/down buttons | [Fl_Spinner](https://www.fltk.org/doc-1.4/classFl__Spinner.html)
NSStepper | ⚠️ | -| [TextField](https://pkg.go.dev/github.com/roblillack/spot/ui#TextField) | Control for single-line text input | [Fl_Input](https://www.fltk.org/doc-1.4/classFl__Input.html)
NSTextField | ✅ | -| TextView/TextEditor | General-purpose text box to view/edit multi-line text content | Text
NSTextView | 🚧 | -| [Window](https://pkg.go.dev/github.com/roblillack/spot/ui#Window) | Control representing a (top-level) window on the screen | [Fl_Window](https://www.fltk.org/doc-1.4/classFl__Window.html)
NSWindow | ✅ | +| Name | Description | Native controls used | Status | +| --------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | +| [Button](https://pkg.go.dev/github.com/roblillack/spot/ui#Button) | Simple button to initiate an action | [Fl_Button](https://www.fltk.org/doc-1.4/classFl__Button.html)
NSButton | ✅ | +| [Checkbox](https://pkg.go.dev/github.com/roblillack/spot/ui#Checkbox) | Control offering the user a choice between two mutually exclusive options | [Fl_Check_Button](https://www.fltk.org/doc-1.4/classFl__Check__Button.html)
NSButton | ✅ | +| ComboBox | A combined dropdown menu with text input | ComboBox
NSComboBox | Not started | +| [Dial](https://pkg.go.dev/github.com/roblillack/spot/ui#Dial) | Circular status control | [Fl_Dial](https://www.fltk.org/doc-1.4/classFl__Dial.html)
NSProgressIndicator (with `NSCircular` style) | ⚠️ | +| [Dropdown](https://pkg.go.dev/github.com/roblillack/spot/ui#Dropdown) | Drop-down menu to select a single item out of multiple options | [Fl_Choice](https://www.fltk.org/doc-1.4/classFl__Choice.html)
NSPopUpButton | ✅ | +| Image | An image control | Image
NSImageView | Not started | +| [Label](https://pkg.go.dev/github.com/roblillack/spot/ui#Label) | Simple, non-editable text label | [Fl_Box](https://www.fltk.org/doc-1.4/classFl__Box.html)
[NSTextField](https://developer.apple.com/documentation/appkit/nstextfield) | ✅ | +| ListBox | A list control | List
NSTableView | 🚧 | +| [ProgressBar](https://pkg.go.dev/github.com/roblillack/spot/ui#ProgressBar) | Progress bar control to visualize the progression of a long-running operation | Progress
NSProgress | ✅ | +| [Slider](https://pkg.go.dev/github.com/roblillack/spot/ui#Slider) | Horizontal slider input control | [Fl_Slider](https://www.fltk.org/doc-1.4/classFl__Slider.html)
NSSlider | ✅ | +| [Spinner](https://pkg.go.dev/github.com/roblillack/spot/ui#Spinner) | Number input control with up/down buttons | [Fl_Spinner](https://www.fltk.org/doc-1.4/classFl__Spinner.html)
NSStepper | ⚠️ | +| [TextField](https://pkg.go.dev/github.com/roblillack/spot/ui#TextField) | Control for single-line text input | [Fl_Input](https://www.fltk.org/doc-1.4/classFl__Input.html)
[NSTextField](https://developer.apple.com/documentation/appkit/nstextfield) | ✅ | +| TextView/TextEditor | General-purpose text box to view/edit multi-line text content | Text
NSTextView | 🚧 | +| [Window](https://pkg.go.dev/github.com/roblillack/spot/ui#Window) | Control representing a (top-level) window on the screen | [Fl_Window](https://www.fltk.org/doc-1.4/classFl__Window.html)
NSWindow | ✅ | ## Potential future backends to look at diff --git a/ui/textfield.go b/ui/textfield.go index 2062e7b..5eed76a 100644 --- a/ui/textfield.go +++ b/ui/textfield.go @@ -5,12 +5,13 @@ import ( ) type TextField struct { - X int - Y int - Width int - Height int - Value string - FontSize int + X int + Y int + Width int + Height int + Value string + // FontSize int + OnChange func(value string) // Editable bool // Bezeled bool // Selectable bool diff --git a/ui/textfield_cocoa.go b/ui/textfield_cocoa.go index 7510a0b..079deda 100644 --- a/ui/textfield_cocoa.go +++ b/ui/textfield_cocoa.go @@ -43,12 +43,12 @@ func (w *TextField) Update(nextComponent spot.Control) bool { // } // } - if next.FontSize != w.FontSize { - w.FontSize = next.FontSize - if w.ref != nil { - w.ref.SetFontSize(w.FontSize) - } - } + // if next.FontSize != w.FontSize { + // w.FontSize = next.FontSize + // if w.ref != nil { + // w.ref.SetFontSize(w.FontSize) + // } + // } // if next.NoBackground != w.NoBackground { // w.NoBackground = next.NoBackground @@ -57,6 +57,9 @@ func (w *TextField) Update(nextComponent spot.Control) bool { // } // } + w.OnChange = next.OnChange + w.ref.OnChange(w.OnChange) + return true } @@ -71,7 +74,8 @@ func (w *TextField) Mount(parent spot.Control) any { // w.ref.SetSelectable(w.Selectable) w.ref.SetStringValue(w.Value) w.ref.SetFontFamily("Arial") - w.ref.SetFontSize(w.FontSize) + w.ref.OnChange(w.OnChange) + // w.ref.SetFontSize(w.FontSize) // w.ref.SetDrawsBackground(!w.NoBackground) if window, ok := parent.(*Window); ok && window != nil && window.ref != nil { diff --git a/ui/textfield_fltk.go b/ui/textfield_fltk.go index ebc5d44..26a1dd0 100644 --- a/ui/textfield_fltk.go +++ b/ui/textfield_fltk.go @@ -7,7 +7,7 @@ import ( "github.com/roblillack/spot" ) -type nativeTypeTextField = *goFltk.TextEditor +type nativeTypeTextField = *goFltk.Input func (w *TextField) Update(nextComponent spot.Control) bool { next, ok := nextComponent.(*TextField) @@ -22,19 +22,22 @@ func (w *TextField) Update(nextComponent spot.Control) bool { if next.Value != w.Value { w.Value = next.Value if w.ref != nil { - if w.ref.Buffer() == nil { - w.ref.SetBuffer(goFltk.NewTextBuffer()) - } - w.ref.Buffer().SetText(w.Value) + // if w.ref.Buffer() == nil { + // w.ref.SetBuffer(goFltk.NewTextBuffer()) + // } + // w.ref.Buffer().SetText(w.Value) + w.ref.SetValue(w.Value) } } - if next.FontSize != w.FontSize { - w.FontSize = next.FontSize - if w.ref != nil && w.FontSize > 0 { - w.ref.SetTextSize(w.FontSize) - } - } + // if next.FontSize != w.FontSize { + // w.FontSize = next.FontSize + // if w.ref != nil && w.FontSize > 0 { + // w.ref.SetTextSize(w.FontSize) + // } + // } + + w.OnChange = next.OnChange return true } @@ -44,14 +47,17 @@ func (w *TextField) Mount(parent spot.Control) any { return w.ref } - w.ref = goFltk.NewTextEditor(w.X, w.Y, w.Width, w.Height) - w.ref.SetBuffer(goFltk.NewTextBuffer()) - w.ref.Buffer().SetText(w.Value) + w.ref = goFltk.NewInput(w.X, w.Y, w.Width, w.Height) + // w.ref.SetBuffer(goFltk.NewTextBuffer()) + // w.ref.Buffer().SetText(w.Value) + w.ref.SetValue(w.Value) // w.ref.Deactivate() - w.ref.SetWrapMode(goFltk.WRAP_AT_BOUNDS, 0) - if w.FontSize > 0 { - w.ref.SetTextSize(w.FontSize) - } + // w.ref.SetWrapMode(goFltk.WRAP_AT_BOUNDS, 0) + // if w.FontSize > 0 { + // w.ref.SetTextSize(w.FontSize) + // } + w.ref.SetCallback(w.callback) + w.ref.SetCallbackCondition(goFltk.WhenChanged) if window, ok := parent.(*Window); ok && window != nil && window.ref != nil { window.ref.Add(w.ref) @@ -60,4 +66,14 @@ func (w *TextField) Mount(parent spot.Control) any { return w.ref } +func (w *TextField) callback() { + if w.OnChange != nil { + val := w.ref.Value() + if val != w.Value { + w.Value = val + w.OnChange(val) + } + } +} + var _ spot.Control = &TextField{}