TextGadget with auto resize?

Just starting out? Need help? Post your questions and find answers here.
Dirk Geppert
Posts: 284
Joined: Fri Sep 22, 2017 7:02 am

Re: TextGadget with auto resize?

Post by Dirk Geppert »

Cool, thx Peter! :D
what do you mean by 'in some cases'? The code looks good to me
The resize works only one times. Please try to resize the first editorgadget (reduce the height).
If you then want to resize the gadget, preferably via the resize corner, the event will not react.

Because the gadget seems still to have the old size.

Code: Select all

EnableExplicit

Procedure MoveGadgets(h, gadget)
 
  Protected offset
  
  Select gadget
    Case 0
      offset = h - 180
      ResizeGadget(1, #PB_Ignore, offset + 200, #PB_Ignore, #PB_Ignore)

    Case 1
      offset = h - 30
  EndSelect
  
 
  ResizeGadget(2, #PB_Ignore, offset + 250, #PB_Ignore, #PB_Ignore)
  ResizeGadget(3, #PB_Ignore, offset + 300, #PB_Ignore, #PB_Ignore)
 
EndProcedure

Procedure BindEditorGadgetResizeEvent(EditorGadget, Callback)
 
  If GadgetType(EditorGadget) <> #PB_GadgetType_Editor : ProcedureReturn : EndIf 
 
  Protected GID = GadgetID(EditorGadget)
 
  ! $(v_gid.gadget.containerNode).resizable({ // see https://api.jqueryui.com/resizable/
  !   resize: function(event, ui) {
  !     v_callback(ui.size.height, v_editorgadget);
  !   }
  ! });
 
  ! $(v_gid.gadget.containerNode).parent().css("padding", "0");
  ! $(v_gid.gadget.containerNode).css("resize", "")
 
EndProcedure


OpenWindow(0, 0, 0, 400, 600, "Resizable EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 380, 180)
EditorGadget(1, 10, 200, 380, 30)

ButtonGadget(2, 10, 250, 380, 30, "Button 1")
ButtonGadget(3, 10, 300, 380, 30, "Button 2")

SetGadgetText(0, "This is a multiline text to edit" + #LF$ +
                 "in the EditorGadget()." + #LF$ +
                 "Third line")

BindEditorGadgetResizeEvent(0, @MoveGadgets())
BindEditorGadgetResizeEvent(1, @MoveGadgets())
Post Reply