[Module] StringEx (all OS)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] StringEx (all OS)

Post by Thorsten1867 »

Update: Background text added

Code: Select all

StringEx::SetText(#String, "Background Text", StringEx::#Background)
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: [Module] StringEx (all OS)

Post by davido »

@ Thorsten1867,
Excellent. :D
Thank you, very much.
DE AA EB
ozzie
Enthusiast
Enthusiast
Posts: 429
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: [Module] StringEx (all OS)

Post by ozzie »

Brilliant! Many thanks.
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] StringEx (all OS)

Post by Thorsten1867 »

Update: Input masks optimized

Code: Select all

; Floats:  "0.00" or "0,000"
; Time:    "00:00"
; Date:    "0000/00/00" or "00.00.0000")
; Cash:    "0,00€" or "$ 0.00"
; License number: "____:____:____:____"
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
ozzie
Enthusiast
Enthusiast
Posts: 429
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: [Module] StringEx (all OS)

Post by ozzie »

I can't get the tab key to skip to the next field. In the example code I've added calls to ModuleEx::AddWindow and ModuleEx::AddGadget as shown here:

Code: Select all

  	If ModuleEx::AddWindow(#Window, ModuleEx::#Tabulator|ModuleEx::#CursorEvent)
  	  Debug "AddWindow(#Window, ...) OK"
  	  If ModuleEx::AddGadget(#String, #Window, ModuleEx::#UseTabulator) : Debug "AddGadget(#String, ...) OK" : EndIf
  	  If ModuleEx::AddGadget(#StringEx, #Window, ModuleEx::#UseTabulator) : Debug "AddGadget(#StringEx, ...) OK" : EndIf
  	  If ModuleEx::AddGadget(#StringPW, #Window, ModuleEx::#UseTabulator) : Debug "AddGadget(#StringPW, ...) OK" : EndIf
  	  If ModuleEx::AddGadget(#StringDel, #Window, ModuleEx::#UseTabulator) : Debug "AddGadget(#StringDel, ...) OK" : EndIf
  	Else
      Debug "AddWindow(#Window, ...) Failed"
    EndIf
and the function calls are all successful. However, the tab key does not go to the next gadget but focus stays on the current string gadget. (BTW, I changed the #String gadget from a PB gadget to a StringEx gadget.)

Am I missing something? Here's the complete example with the above mods:

Code: Select all

CompilerIf #PB_Compiler_IsMainFile
  XIncludeFile "ModuleEx.pbi"
CompilerEndIf

; (Then the full DeclareModule StringEx code)

;- ========  Module - Example ========

CompilerIf #PB_Compiler_IsMainFile
  
  UsePNGImageDecoder()
  
  #Window  = 0
  
  Enumeration 1
    #String
    #StringEx
    #StringPW
    #StringDel
    #Font
    #Popup
    #Image
    #Menu_Item1
    #Menu_Item2
    #Menu_Item3
    #Menu_Item4
    #Menu_Item5
  EndEnumeration
  
  LoadImage(#Image, "Delete.png")
  
  If OpenWindow(#Window, 0, 0, 460, 60, "Window", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
    
    If CreatePopupMenu(#Popup)
      MenuItem(#Menu_Item1, "Undo")
      MenuBar()
      MenuItem(#Menu_Item2, "Copy")
      MenuItem(#Menu_Item3, "Cut")
      MenuItem(#Menu_Item4, "Paste")
      MenuBar()
      MenuItem(#Menu_Item5, "Delete")
    EndIf
    
    ;StringGadget(#String, 15, 19, 90, 20, "")
    ;SetGadgetAttribute(#String, #PB_String_MaximumLength, 5)
    StringEx::Gadget(#String, 15, 19, 90, 20, "")
    
    StringEx::Gadget(#StringEx, 120, 19, 90, 20, "AutoComplete", StringEx::#AutoComplete, #Window) ; StringEx::#ShowButton / StringEx::#Numeric / StringEx::#LowerCase / StringEx::#UpperCase / StringEx::#NotEditable / StringEx::#BorderLess
    StringEx::AttachPopupMenu(#StringEx, #Popup)
    ;StringEx::SetAttribute(#StringEx, StringEx::#MaximumLength, 5)

    StringEx::AddWords(#StringEx, "Default Define Declare Degree Debug AutoComplete")
    
    StringEx::Gadget(#StringPW, 225, 19, 100, 20, "Password", StringEx::#Password|StringEx::#ShowButton, #Window)
    ;StringEx::SetAttribute(#StringPW, StringEx::#Padding, 6)
    ;StringEx::SetAttribute(#StringPW, StringEx::#MaximumLength, 10)
    
    StringEx::Gadget(#StringDel, 340, 19, 100, 20, "", StringEx::#AutoResize|StringEx::#Right, #Window) ; 
    StringEx::AddButton(#StringDel, #Image)
    StringEx::SetAutoResizeFlags(#StringDel, StringEx::#Width)
    
    StringEx::SetText(#StringDel, "Delete Button", StringEx::#Background)
    
    StringEx::SetInputMask(#StringDel, "0.00")
    ;StringEx::SetInputMask(#StringDel, "*.__$")
    ;StringEx::SetInputMask(#StringDel, "*,__ €")
    ;StringEx::SetInputMask(#StringDel, "__.__.____")
    
    CompilerIf Defined(ModuleEx, #PB_Module)
	
  	  StringEx::SetDynamicFont(#StringDel, "Arial", 8)
  	  StringEx::FitText(#StringDel, 3, 3)
  	  
  	  StringEx::SetAutoResizeFlags(#StringDel, StringEx::#Width|StringEx::#FitText)
  	  
  	  ;ModuleEx::SetTheme(ModuleEx::#Theme_Green)
  	  
  	CompilerEndIf
    
    ;DisableGadget(#String, #True)
    ;StringEx::Disable(#StringEx, #True)
    
    ;StringEx::SetAttribute(#StringPW, StringEx::#Corner, 4)
    
  	If ModuleEx::AddWindow(#Window, ModuleEx::#Tabulator|ModuleEx::#CursorEvent)
  	  Debug "AddWindow(#Window, ...) OK"
  	  If ModuleEx::AddGadget(#String, #Window, ModuleEx::#UseTabulator) : Debug "AddGadget(#String, ...) OK" : EndIf
  	  If ModuleEx::AddGadget(#StringEx, #Window, ModuleEx::#UseTabulator) : Debug "AddGadget(#StringEx, ...) OK" : EndIf
  	  If ModuleEx::AddGadget(#StringPW, #Window, ModuleEx::#UseTabulator) : Debug "AddGadget(#StringPW, ...) OK" : EndIf
  	  If ModuleEx::AddGadget(#StringDel, #Window, ModuleEx::#UseTabulator) : Debug "AddGadget(#StringDel, ...) OK" : EndIf
  	Else
      Debug "AddWindow(#Window, ...) Failed"
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
      Select Event
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #StringEx
              Select EventType()
                Case #PB_EventType_Focus
                  Debug ">>> Focus"
                Case #PB_EventType_LostFocus
                  Debug ">>> LostFocus"
                Case StringEx::#EventType_Change
                  Debug ">>> Changed"
              EndSelect    
            Case #StringDel
              If EventType() = StringEx::#EventType_Button
                StringEx::Clear(#StringDel)
              EndIf
          EndSelect
        Case #PB_Event_Menu
          Select EventMenu()
            Case #Menu_Item1
              StringEx::Undo(#StringEx)
            Case #Menu_Item2
              StringEx::Copy(#StringEx)
            Case #Menu_Item3
              StringEx::Cut(#StringEx)
            Case #Menu_Item4
              StringEx::Paste(#StringEx)
            Case #Menu_Item5
              StringEx::Delete(#StringEx)
          EndSelect
      EndSelect        
    Until Event = #PB_Event_CloseWindow
    
    CloseWindow(#Window)
  EndIf
  
CompilerEndIf
Compiling with PB 5.71 under Windows 10, 64-bit.
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] StringEx (all OS)

Post by Thorsten1867 »

Update:
  • #Style_Win11 added
  • InsertText()
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: [Module] StringEx (all OS)

Post by tatanas »

Hi Thorsten1867,
Again, you made a great module !

I was looking for a way to add an image/icon inside a string gadget like this :

Image

Could you consider adding this functionality (like the "AddButton" procedure) ?

Thanks !
Windows 10 Pro x64
PureBasic 6.04 x64
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: [Module] StringEx (all OS)

Post by tatanas »

I know this module is Dpi wise but i've got a problem (the code example included in the module works fine).
In my code, when I scale from 100% to 125% the image of the button goes outside and the button isn't inside the Input String field anymore.
I don't undestand why.

Any idea ?

PS : "Enable DPI aware executable" is checked

EDIT : Nevermind. The problem appears only when I run the code from IDE. The compiled exe is fine.
Last edited by tatanas on Thu Jun 16, 2022 2:53 pm, edited 1 time in total.
Windows 10 Pro x64
PureBasic 6.04 x64
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] StringEx (all OS)

Post by Thorsten1867 »

When I have some time, I'll take a look.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] StringEx (all OS)

Post by Thorsten1867 »

Update:
  • Bild als Button hinzufügen
  • #Search & #ShowImage (for entering search terms)
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: [Module] StringEx (all OS)

Post by tatanas »

Thank you very much.
I noticed that the text can overlap the image. It should stop before.
Windows 10 Pro x64
PureBasic 6.04 x64
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] StringEx (all OS)

Post by Thorsten1867 »

Fixed
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: [Module] StringEx (all OS)

Post by tatanas »

Thank you again.

I found a new bug : when you select the text you wrote inside the "#StringDel" gadget in the example, it triggers the delete event even if you didn't click the delete button.
Windows 10 Pro x64
PureBasic 6.04 x64
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] StringEx (all OS)

Post by Thorsten1867 »

Do you use #Event_Gadget or EventType() with #PB_EventGadget?
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: [Module] StringEx (all OS)

Post by tatanas »

I'm referring to your example :

Code: Select all

   Repeat
      Event = WaitWindowEvent()
      Select Event
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #StringEx
              Select EventType()
                Case #PB_EventType_Focus
                  Debug ">>> Focus"
                Case #PB_EventType_LostFocus
                  Debug ">>> LostFocus"
                Case StringEx::#EventType_Change
                  Debug ">>> Changed"
              EndSelect    
            Case #StringDel
              If EventType() = StringEx::#EventType_Button
                StringEx::Clear(#StringDel)
              EndIf
          EndSelect
Windows 10 Pro x64
PureBasic 6.04 x64
Post Reply