1 Reply Latest reply on Nov 18, 2013 8:44 AM by philmodjunk

    Change font size using a script

    layotte

      Title

      Change font size using a script

      Post

           I am using the FTS Meetings file to add text editing to my solution. In addition to the plain, italics, bold, red and bullet they already have I would like to add the ability for the user to change the font size on Filemaker Go.  I have done this by adding a Small, Medium and Large button to the layout and setting the TextSize as shown below.  Instead of using multiple buttons I would like to use a dropdown where the user can select the size then select the text and use a button to make the changes.  I have tried adding a GetField in the script to the area where the font size is listed but can't get it to work.  Any suggestions?

           Let ( [
               allText = Get (ActiveFieldContents) ;
               start = Get ( ActiveSelectionStart) ;
               size = Get (ActiveSelectionSize) ;
               selectedText = Middle ( Get ( ActiveFieldContents ) ; start ; size ) ;
               style = Get ( ScriptParameter )  ;

               replacementText = Case (
                                                 style = "Small"; TextSize ( selectedText ; 10 ) ;
                                                 style = "Medium"; TextSize ( selectedText ; 12 ) ;
                                                 style = "Large"; TextSize ( selectedText ; 18 ) ;
                                                 TextStyleAdd ( selectedText ; Evaluate (style) )
                                             )
            ] ;

              Left ( allText ; start - 1 ) &  replacementText &   Right ( allText ; Length ( allText ) - (start + size -1))
           )

        • 1. Re: Change font size using a script
          philmodjunk

               I have tried adding a GetField in the script to the area where the font size is listed but can't get it to work.  Any suggestions?

               Don't see getfield anywhere in your calculation and it may not be needed as you can also directly refer to the field instead of using getField indirectly.

               Am I corrrect that you use with either set field or an "insert" step in your script? And that your three size buttons pass different script parameters "small", "medium" or "large"?

               If you replace your buttons with a field where you select the size in a value list, you could modify the code like this: (I'll name the field "Table::StyleField")

               Let ( [
                   allText = Get (ActiveFieldContents) ;
                   start = Get ( ActiveSelectionStart) ;
                   size = Get (ActiveSelectionSize) ;
                   selectedText = Middle ( Get ( ActiveFieldContents ) ; start ; size ) ;
                   style = Get ( ScriptParameter )  ;

                   replacementText = Case (
                                                     Table::StyleField = "Small"; TextSize ( selectedText ; 10 ) ;
                                                     Table::StyleField = "Medium"; TextSize ( selectedText ; 12 ) ;
                                                     Table::StyleField = "Large"; TextSize ( selectedText ; 18 ) ;
                                                     TextStyleAdd ( selectedText ; Evaluate (style) )
                                                 )
                ] ;

                  Left ( allText ; start - 1 ) &  replacementText &   Right ( allText ; Length ( allText ) - (start + size -1))
               )

               But you'll have a "focus" problem. Selecting the style in the style field puts the focus in the style field and now

               allText = Get (ActiveFieldContents) ;
                   start = Get ( ActiveSelectionStart) ;
                   size = Get (ActiveSelectionSize) ;

               will refer to your style field instead of your text field where you want to apply the selected style.

               If you are trying to get away from buttons as a way to better use the space on your layout, you may want to use a single button that "cycles" through the size options. Tap the button to increase the size, when you tap the button with Large already selected, reset to "small". This can be done if your script updates and checks the value of a field or global variable each time that it is performed.