Page 1 of 1

StatusBar: #PB_Event_LeftClick

Posted: Thu Feb 02, 2017 10:33 am
by Marc56us
I use the gadget StatusBar very much because it is simple to use and it is a basic element of Windows.
(I always think end user and especially for tools programs)

Would it be possible to add #PB_Event_LeftClick (and others) to StatusBar fields ?
Having Tooltips for fields would be good too.

Many programs (ie: editors, spreadsheets, word processing) use the click on the status bar fields for example to change the state SHIFT or NUMLOCK or the type of encoding.
I do not know if it's a simple or complicated feature to implement ?

Thanks
:wink:

Re: StatusBar: #PB_Event_LeftClick

Posted: Thu Feb 02, 2017 11:04 am
by Mesa

Re: StatusBar: #PB_Event_LeftClick

Posted: Thu Feb 02, 2017 11:36 am
by Marc56us
Thanks Mesa

I suggested a native function.
I do not know how many people this may interest ?

(Just a suggestion, a simple idea, not a request)

:wink:

Re: StatusBar: #PB_Event_LeftClick

Posted: Mon Feb 20, 2017 11:07 am
by Wolf
Marc56us wrote: I suggested a native function.
+1

Re: StatusBar: #PB_Event_LeftClick

Posted: Sun Apr 14, 2019 2:43 pm
by destiny
Marc56us wrote:I suggested a native function.
+1

Re: StatusBar: #PB_Event_LeftClick

Posted: Sun Apr 14, 2019 7:38 pm
by skywalk
I subclass the StatusBar on Windows, but it is not elegant.
A lighter, cross-platform approach is a bound container gadget that houses any gadget you require.
I made the canvasgadget width = the entire containergadget width, which should be modified to its actual width.

Code: Select all

; ts-soft, https://www.purebasic.fr/english/viewtopic.php?p=343795#p343795
#aWhite       = $FFFFFFFF   ; RGBA(255, 255, 255, 255)
#aBlack       = $FF000000   ; RGBA(0, 0, 0, 255)
#YellowLight  = $C0FFFF     ; RGB(255, 255, 192)
#GrayLight    = $E4E4E4     ; RGB(228, 228, 228)
#aRedLight    = $FF513CED   ; RGBA(237, 60, 81, 255)
#aGreenLight  = $FFC0FFC0   ; RGBA(192, 255, 192, 255)
Global.i fntC = FontID(LoadFont(#PB_Any, "Consolas", 14, #PB_Font_HighQuality))
Global.i evWW, evG, fntC
Macro waf_CLR_Fill(CLR=#aWhite)
  ; Default = RGBA(255, 255, 255, 255), erases all content.
  VectorSourceColor(CLR)    ; Set BG color and now the default color until changed.
  FillVectorOutput()        ; Apply BG color.
EndMacro
Procedure gad_ProgressBarTextV(gN.i, show_pc.i, txt$=#Empty$, pbHt_px.i=20, BGColor.i=#aGreenLight)
  ; Draw progress bar text to canvasgadget.
  ; '_px' -> units = pixels
  ; '_pc' -> units = %
  ; pbHt_px, pbWd_px -> progressbar Ht & Wd in pixels.
  Protected.i pbX_px, pbWd_px, tW, tH, Font
  Protected.s s$ =  "... " + Str(show_pc) + "% " + txt$ + " ..."
  show_pc = Abs(show_pc)
  If show_pc >= 100
    show_pc = 100
    s$ =  "... Done ..."
  EndIf
  StartVectorDrawing(CanvasVectorOutput(gN))
  pbX_px = GadgetX(gN, #PB_Gadget_ActualSize)
  pbWd_px = GadgetWidth(gN, #PB_Gadget_ActualSize)
  waf_CLR_Fill()
  VectorFont(fntC, pbHt_px-8)
  tW = VectorTextWidth(s$)
  tH = VectorTextHeight(s$)
  If tH > pbHt_px
    pbHt_px = tH * 1.2
  EndIf
  pbWd_px - pbX_px  ; Reduce CanvasGadgetWidth by its X position.
  ; Foreground progress amount
  VectorSourceColor(BGColor)
  AddPathBox(0, GadgetHeight(gN) - pbHt_px, show_pc*pbWd_px/100, pbHt_px)
  FillPath()
  ; Centered progress text
  MovePathCursor(pbWd_px/2-tW/2, (pbHt_px-tH)/2)
  VectorSourceColor(#aBlack)
  DrawVectorText(s$)
  StopVectorDrawing()
EndProcedure
Procedure.i gad_BGclr(gN.i, txt$, Show_pc.i=100, BGColor.i=#aGreenLight)
  Protected.i gWd = GadgetWidth(gN)
  Protected.i gHt = GadgetHeight(gN)
  Static.i imgN
  If IsImage(imgN)
    FreeImage(imgN)
  EndIf
  imgN = CreateImage(#PB_Any, gWd+2, gHt)
  StartDrawing(ImageOutput(ImgN))
  Box(0, 0, gWd, gHt, GetGadgetColor(gN, #PB_Gadget_FrontColor)) ; Background
  Box(0, 0, gWd, gHt, #GrayLight)                                ; Background
  Box(0, 0, gWd*Show_pc/100, gHt, BGColor)                       ; Foreground Progress Amount
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawingFont(fntC)
  Protected.i tW = TextWidth(txt$)
  Protected.i tH = TextHeight(txt$)
  DrawText(gWd/2 - tW/2, (gHt-tH)/2, txt$, #Black)
  StopDrawing()
  ProcedureReturn ImageID(imgN)
EndProcedure
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 640, 480, "Not StatusbarGadget", #PB_Window_SizeGadget | #PB_Window_SystemMenu)
  ContainerGadget(0, 0, 0, 350, 28, #PB_Container_Single)
  StringGadget(1, 0, 0, 180, 24, "Status", #PB_String_BorderLess | #PB_Text_Center)
  SetGadgetColor(1, #PB_Gadget_BackColor, #GrayLight)
  ButtonImageGadget(2, 184, 0, 48, 24, 0)
  CanvasGadget(3, 184 + 48 + 4, 0, 350, 24)
  CloseGadgetList()
  SetGadgetFont(1, fntC)
  SetGadgetFont(2, fntC)
  GadgetToolTip(3, "Statusbar progress")
  GadgetToolTip(1, "Editable Statusbar")
  ButtonGadget(4, 405, 10, 50, 25, "Done")
  SetGadgetAttribute(3, #PB_Canvas_Cursor, #PB_Cursor_Cross)
  SetGadgetFont(4, fntC)
  ResizeGadget(0, 0, WindowHeight(0) - 24, WindowWidth(0)-8, 24)  ; Force repaint to show container.
  ResizeGadget(3, #PB_Ignore, #PB_Ignore, GadgetWidth(0), #PB_Ignore)
  SetGadgetAttribute(2, #PB_Button_Image, gad_BGclr(2, "OK?", 100, #YellowLight))
  Repeat
    Select WaitWindowEvent(10)
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      evG = EventGadget()
      If evG = 0
      ElseIf evg = 2
        If Random(1,0)
          SetGadgetAttribute(2, #PB_Button_Image, gad_BGclr(2, "OK?", 100, #aGreenLight))
          gad_ProgressBarTextV(3, Random(100),"",24, #aGreenLight)
        Else
          SetGadgetAttribute(2, #PB_Button_Image, gad_BGclr(2, "OK?", 100, #aRedLight))
          gad_ProgressBarTextV(3, Random(100),"",24, #aRedLight)
        EndIf
      ElseIf evG = 3
        gad_ProgressBarTextV(3, Random(100),"",24, #aGreenLight)
      ElseIf evG = 4
        gad_ProgressBarTextV(3, 100, "Done",24, #aGreenLight)
      EndIf
    Case #PB_Event_SizeWindow
      ResizeGadget(0, 0, WindowHeight(0) - 24, WindowWidth(0)-8, 24)
      ResizeGadget(3, #PB_Ignore, #PB_Ignore, GadgetWidth(0), #PB_Ignore)
    EndSelect
  ForEver
EndIf

Re: StatusBar: #PB_Event_LeftClick

Posted: Sun Apr 14, 2019 7:52 pm
by Gérard
Hello

Put all your gadgets in a CanvasGadget ()

Code: Select all

CanvasGadget (#canvas, 0, 0, #appWidth, #appWidth, #PB_Canvas_Container)
StartDrawing (CanvasOutput (#canvas))
    FillArea (0, 0,-1, #bgcolor)
StopDrawing ()

; Add gadgets here

CloseGadgetList ()

Re: StatusBar: #PB_Event_LeftClick

Posted: Sun Apr 14, 2019 10:12 pm
by Dude
Marc56us wrote:I suggested a native function.
+1