webview zoom linux macos

Just starting out? Need help? Post your questions and find answers here.
Mesa
Enthusiast
Enthusiast
Posts: 446
Joined: Fri Feb 24, 2012 10:19 am

webview zoom linux macos

Post by Mesa »

Could you tell me if this code works on linux and macos ?

With Windows, the webview gadget doesn't show the horizontal scroller, is that a bug ?

Thanks.

Code: Select all

EnableExplicit

Enumeration CustomEvent #PB_Event_FirstCustomValue
  #MyEvent_DataReceived
EndEnumeration

; ----

Procedure AllocateString(String.s) ; Result = Pointer
  Protected *mem.string = AllocateStructure(String)
  If *mem
    *mem\s = String
  EndIf
  ProcedureReturn *mem
EndProcedure

Procedure.s FreeString(*mem.string) ; Result String
  Protected r1.s
  If *mem
    r1 = *mem\s
    FreeStructure(*mem)
  EndIf
  ProcedureReturn r1
EndProcedure

; ----

Procedure GetDataJS(JsonParameters$)
  
  PostEvent(#MyEvent_DataReceived, EventWindow(), EventGadget(), 0, AllocateString(JsonParameters$))
  
  ProcedureReturn #Null
  
EndProcedure

Procedure resizeW()
  ResizeGadget(0, #PB_Ignore, #PB_Ignore, WindowWidth(0), WindowHeight(0)-50)
EndProcedure

; ----

Define Html$, Result$, Zoom0$, Zoom$

Html$ = ~"<input type=\"text\" id=\"userInput\" name=\"userInput\" value=\"Hello World\">\n"

OpenWindow(0, 100, 100, 800, 600, "Hello", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget |#PB_Window_MaximizeGadget |#PB_Window_SizeGadget)

WebViewGadget(0, 0, 50, 800, 500, #PB_WebView_Debug)
SetGadgetText(0, "https:\\www.purebasic.com")
BindEvent(#PB_Event_SizeWindow,@resizeW())

ButtonGadget(1, 10, 10, 120, 25, "100%")
TrackBarGadget(2,130,10,600,30,10,400)
SetGadgetState(2, 100)
TextGadget(3,750,10,60,30,"100%")
BindWebViewCallback(0, "100%", @GetDataJS())

Repeat 
  Select WaitWindowEvent()
    Case #MyEvent_DataReceived
      Result$ = FreeString(EventData())
      Debug Result$
      
    Case #PB_Event_Gadget
      Select  EventGadget() 
        Case 1
          WebViewExecuteScript(0, ~"window.getData(\"userInput\", document.getElementById(\"userInput\").value)")
          WebViewExecuteScript(0, ~"document.body.style.zoom=\"100%\"")
          SetGadgetState(2, 100)
          SetGadgetText(3,"100%")
        Case 2
          zoom0$=Str(GetGadgetState(2))
          zoom$=~"document.body.style.zoom=\""+zoom0$+~"%\""
          WebViewExecuteScript(0, zoom$)
          SetGadgetText(3,zoom0$)
      EndSelect
      
    Case #PB_Event_CloseWindow
      Break
      
  EndSelect
ForEver

M.
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 205
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: webview zoom linux macos

Post by moulder61 »

Hi Mesa,

It doesn't show the horizontal scroll bar on my Debian 13 Linux install using PB6.21.

Moulder.
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
Mesa
Enthusiast
Enthusiast
Posts: 446
Joined: Fri Feb 24, 2012 10:19 am

Re: webview zoom linux macos

Post by Mesa »

@moulder61: thank you, and i suppose that the zoom works correctly ?

M.
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 205
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: webview zoom linux macos

Post by moulder61 »

Hi Mesa,

The zoom works perfectly, as does the vertical scroll bar.

It did occur to me that the contents of the webpage resize to fit the window, so maybe you wouldn't ever get a horizontal scroll bar?

But then there is a condition where the page would require it i.e. if you make the window small and/or zoom in, the word INTRODUCTION doesn't split over two lines, but that doesn't seem to make any difference?

Well, not on Linux anyway.

Something occurred to me as I write this. Could it be the PB website that's causing the issue? I tried going to www.purebasic.com in Firefox and I don't get a horizontal scroll bar there either?

I changed the link in your code to https://distrowatch.com and that seems to work OK.

Moulder.
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
Post Reply