Created
March 9, 2022 09:14
-
-
Save estebanlm/632bc74928b380b72065e7df09e18f57 to your computer and use it in GitHub Desktop.
example usage of submit, reset and text changed events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app := SpApplication new. | |
"If using Morphic" | |
app addStyleSheetFromString: '.application [ | |
.dirty [ Container { #borderColor: #red, #borderWidth: 1 } ], | |
.notDirty [ Container { #borderColor: #transparent, #borderWidth: 1 } ] | |
]'. | |
"If using GTK (you need to choose one, both options are not possible at the same time)" | |
app useBackend: #Gtk. | |
app addCSSProviderFromString: ' | |
.dirty { | |
border-color: red; | |
border-width: 1px; } | |
'. | |
presenter := SpPresenter new. | |
presenter application: app. | |
presenter layout: (SpBoxLayout newTopToBottom | |
add: (textPresenter := presenter newTextInput) expand: false; | |
yourself). | |
text := ''. | |
textPresenter | |
text: text; | |
whenTextChangedDo: [ :aString | | |
aString = text | |
ifTrue: [ textPresenter removeStyle: 'dirty'; addStyle: 'notDirty' ] | |
ifFalse: [ textPresenter removeStyle: 'notDirty'; addStyle: 'dirty' ] ]; | |
whenSubmitDo: [ | |
text := textPresenter text. | |
('Submitted ', text) crTrace. | |
textPresenter | |
removeStyle: 'dirty'; | |
addStyle: 'notDirty' ]; | |
whenResetDo: [ | |
textPresenter | |
text: text; | |
removeStyle: 'dirty'; | |
addStyle: 'notDirty' ]. | |
presenter asWindow | |
title: 'Example submit/reset text component'; | |
open |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is how it looks when you type :
(one day I will learn how to record a gif to show the transition ;) )