Page 1 of 1

EditorGadget() placeholder text

Posted: Wed Apr 17, 2024 3:58 pm
by dige
hi guys,

does anyone know how I can assign a placeholder text to the editor gadget?
I have not found anything with the forum search.

Chat GPT has suggested an interesting, working solution - but isn't there a simpler way?

Code: Select all

; Created by ChatGPT4


; Konstanten für die Gadget-IDs
Enumeration
  #Editor
EndEnumeration

; Initialer Platzhaltertext
Global Placeholder$ = "Bitte Text eingeben..."

; Fenster und EditorGadget erstellen
If OpenWindow(0, 100, 100, 300, 100, "Editor mit Platzhalter", #PB_Window_SystemMenu)
  EditorGadget(#Editor, 10, 10, 280, 80)
  SetGadgetText(#Editor, Placeholder$)
  
  ; Ereignisschleife
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Editor
            If EventType() = #PB_EventType_Focus
              If GetGadgetText(#Editor) = Placeholder$
                SetGadgetText(#Editor, "")
              EndIf
            ElseIf EventType() = #PB_EventType_LostFocus
              If Len(GetGadgetText(#Editor)) = 0
                SetGadgetText(#Editor, Placeholder$)
              EndIf
            EndIf
        EndSelect
    EndSelect
  Until Event() = #PB_Event_CloseWindow
EndIf


Re: EditorGadget() placeholder text

Posted: Wed Apr 17, 2024 5:42 pm
by RASHAD
Hi dige
I tried to use #EM_SETCUEBANNER with the editor but I failed :)
Try
#1 :

Code: Select all

Enumeration
  #Editor
  #Text
EndEnumeration

; Initialer Platzhaltertext
Global Placeholder$ = "  Bitte Text eingeben..."

; Fenster und EditorGadget erstellen
If OpenWindow(0, 100, 100, 300, 200, "Editor mit Platzhalter", #PB_Window_SystemMenu)
  TextGadget(#Text,12,12,250,24,Placeholder$,#WS_CLIPSIBLINGS)
  SetGadgetColor(#Text,#PB_Gadget_BackColor,$FFFFFF)
  EditorGadget(#Editor, 10, 10, 280, 80,#WS_CLIPSIBLINGS)
  DisableGadget(#Text,1)
  ; Ereignisschleife
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Editor
            If EventType() = #PB_EventType_Focus
              HideGadget(#Text,1)
            ElseIf EventType() = #PB_EventType_LostFocus
              HideGadget(#Text,0)
            EndIf
        EndSelect
    EndSelect
  Until Event() = #PB_Event_CloseWindow
EndIf
#2 :

Code: Select all

Enumeration
  #Editor
  #string
EndEnumeration

; Initialer Platzhaltertext
Global Placeholder$ = "  Bitte Text eingeben..."

; Fenster und EditorGadget erstellen
If OpenWindow(0, 100, 100, 300, 200, "Editor mit Platzhalter", #PB_Window_SystemMenu)
  EditorGadget(#Editor, 10, 10, 280, 80)
  StringGadget(#string,11,11,250,24,"")
  SendMessage_(GadgetID(#string),#EM_SETCUEBANNER,1,Placeholder$)
  SetWindowLongPtr_(GadgetID(#string), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(0), #GWL_EXSTYLE)  &~ #WS_EX_CLIENTEDGE)
  SetWindowPos_(GadgetID(#string), 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)
  ; Ereignisschleife
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Editor
            If EventType() = #PB_EventType_Focus
              HideGadget(#string,1)
            ElseIf EventType() = #PB_EventType_LostFocus
              HideGadget(#string,0)
            EndIf
        EndSelect
    EndSelect
  Until Event() = #PB_Event_CloseWindow
EndIf

Re: EditorGadget() placeholder text

Posted: Thu Apr 18, 2024 12:38 am
by BarryG
dige wrote: Wed Apr 17, 2024 3:58 pm

Code: Select all

; Created by ChatGPT4

; Konstanten für die Gadget-IDs
Enumeration
  #Editor
EndEnumeration

; Initialer Platzhaltertext
Global Placeholder$ = "Bitte Text eingeben..."

; Fenster und EditorGadget erstellen
If OpenWindow(0, 100, 100, 300, 100, "Editor mit Platzhalter", #PB_Window_SystemMenu)
  EditorGadget(#Editor, 10, 10, 280, 80)
  SetGadgetText(#Editor, Placeholder$)
  
  ; Ereignisschleife
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Editor
            If EventType() = #PB_EventType_Focus
              If GetGadgetText(#Editor) = Placeholder$
                SetGadgetText(#Editor, "")
              EndIf
            ElseIf EventType() = #PB_EventType_LostFocus
              If Len(GetGadgetText(#Editor)) = 0
                SetGadgetText(#Editor, Placeholder$)
              EndIf
            EndIf
        EndSelect
    EndSelect
  Until Event() = #PB_Event_CloseWindow
EndIf
ChatGPT wrote that? That's pretty impressive! :shock: I've never seen it create compilable PureBasic code before, but you used ChatGPT 4 and I'm only on 3.5 (can't afford to pay for 4), so maybe that's why.

Re: EditorGadget() placeholder text

Posted: Thu Apr 18, 2024 12:58 am
by Quin
BarryG wrote: Thu Apr 18, 2024 12:38 am ChatGPT wrote that? That's pretty impressive! :shock: I've never seen it create compilable PureBasic code before, but you used ChatGPT 4 and I'm only on 3.5 (can't afford to pay for 4), so maybe that's why.
Yeah, GPT4 can actually generate compilable PB code. I don't pay for it myself either ($20.00 a month is incredibly steep considering how much I'd use it), but it's impressive.

Re: EditorGadget() placeholder text

Posted: Thu Apr 18, 2024 7:19 pm
by dige
RASHAD wrote: Wed Apr 17, 2024 5:42 pm Hi dige
I tried to use #EM_SETCUEBANNER with the editor but I failed :)
[..]
Nevertheless, thanks RASHAD, it looks better :-)

Re: EditorGadget() placeholder text

Posted: Thu Apr 18, 2024 9:41 pm
by jacdelad
dige wrote: Thu Apr 18, 2024 7:19 pm Nevertheless, thanks RASHAD, it looks better :-)
You can always trust in RASHAD-GPT! :mrgreen:

Re: EditorGadget() placeholder text

Posted: Thu Apr 18, 2024 10:44 pm
by RASHAD
Hi jacdelad
Is that mean he should pay me $20 per month :mrgreen:

Re: EditorGadget() placeholder text

Posted: Fri Apr 19, 2024 12:19 am
by jacdelad
RASHAD wrote: Thu Apr 18, 2024 10:44 pm Hi jacdelad
Is that mean he should pay me $20 per month :mrgreen:
$20 well invested. I'll think about that. :wink:

Re: EditorGadget() placeholder text

Posted: Fri Apr 19, 2024 7:07 am
by dige
RASHAD wrote: Thu Apr 18, 2024 10:44 pm Hi jacdelad
Is that mean he should pay me $20 per month :mrgreen:
RASHAD my friend! What is your bank account? :D :mrgreen: