strange behaviour StatusBar on ListViewGadget

Just starting out? Need help? Post your questions and find answers here.
lisa_beille
User
User
Posts: 24
Joined: Fri Dec 22, 2023 5:59 pm

strange behaviour StatusBar on ListViewGadget

Post by lisa_beille »

Hello
When adding a statusbar to a listviw gadget, a strange behaviour appears when scrolling the listview :

Normal statusbar
Image

When scrolling :

Image


my code :

Code: Select all

If OpenWindow(0,0,0,800,400,"", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  ListIconGadget(0,0,0,800,400,"test",800)
  For i = 1 To 500
    AddGadgetItem(0,-1, Str(i))
  Next
  If CreateStatusBar(0, GadgetID(0))
    AddStatusBarField(110)
  EndIf
  StatusBarText(0, 0, "Statusbar")
EndIf
Repeat
  event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: strange behaviour StatusBar on ListViewGadget

Post by mk-soft »

The statusbar height and menu height must be subtracted.

Code: Select all

;-TOP

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
  ; Resize Gadgets
  ResizeGadget(0, 0, 0, dx, dy)
EndProcedure

Procedure Main()
  Protected dx, dy
  Protected index
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Test Window", #WinStyle)
    ; MenuBar
    CreateMenu(0, WindowID(0))
    MenuTitle("File")
    
    ; StatusBar
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(0)
    dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    ListViewGadget(0, 0, 0, dx, dy)
    
    For index = 0 To 31
      AddGadgetItem(0, -1, "Item " + index)
    Next
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    ; Main Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0
              Break
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
spikey
Enthusiast
Enthusiast
Posts: 771
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: strange behaviour StatusBar on ListViewGadget

Post by spikey »

lisa_beille wrote: Sun Jan 07, 2024 7:49 pm When adding a statusbar to a listviw gadget, a strange behaviour appears when scrolling the listview :
Status bars are intended to be added to windows not gadgets but, as mk-soft said, you must ensure that the status bar doesn't overlap a gadget otherwise there will still be drawing irregularities.
morosh
Enthusiast
Enthusiast
Posts: 329
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: strange behaviour StatusBar on ListViewGadget

Post by morosh »

Code: Select all

If OpenWindow(0,0,0,800,400,"", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  ListIconGadget(0,0,0,800,380,"test",800)
  For i = 1 To 500
    AddGadgetItem(0,-1, Str(i))
  Next
  If CreateStatusBar(0, WindowID(0))
    AddStatusBarField(110)
  EndIf
  StatusBarText(0, 0, "Statusbar")
EndIf
Repeat
  event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
I normally always attach a status bar to a window (not to a gadget) but may be it's not your case
PureBasic: Surprisingly simple, diabolically powerful
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: strange behaviour StatusBar on ListViewGadget

Post by mk-soft »

The status bar is always at the bottom of the window. Perhaps a little misguided.
Don't just subtract 20 pixels. There is StatusBarHeight for this.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
lisa_beille
User
User
Posts: 24
Joined: Fri Dec 22, 2023 5:59 pm

Re: strange behaviour StatusBar on ListViewGadget

Post by lisa_beille »

Thank you all for your answers :D
lisa_beille
User
User
Posts: 24
Joined: Fri Dec 22, 2023 5:59 pm

Re: strange behaviour StatusBar on ListViewGadget

Post by lisa_beille »

But what if I really want the statusbar to be attached to the listview ? say for instance the listview doesn't take all the window's space ? is it possible to specify the statusbar's 'left' position and witdth ?
thanks
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: strange behaviour StatusBar on ListViewGadget

Post by mk-soft »

No,
A statusbar is always at the bottom of the window.
But you can make something yourself
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
infratec
Always Here
Always Here
Posts: 7623
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: strange behaviour StatusBar on ListViewGadget

Post by infratec »

A basic 'starter':

Code: Select all

CompilerIf #PB_Compiler_IsMainFile
  EnableExplicit
CompilerEndIf


Structure FlexStatusBarGadget_Structure
  List FieldList.i()
EndStructure



Procedure.i FlexStatusBarGadget(Gadget.i, Height.i, ParentGadget.i)
  
  Protected.i NewGadget, x, y, width
  Protected *FlexStatusBarGadget.FlexStatusBarGadget_Structure
  
  
  If IsGadget(ParentGadget)
    x = GadgetX(ParentGadget)
    y = GadgetY(ParentGadget) + GadgetHeight(ParentGadget)
    width = GadgetWidth(ParentGadget)
    NewGadget = CanvasGadget(Gadget, x, y, width, height, #PB_Canvas_Container|#PB_Canvas_Border)
    If NewGadget
      If Gadget <> #PB_Any
        NewGadget = Gadget
      EndIf
      *FlexStatusBarGadget = AllocateStructure(FlexStatusBarGadget_Structure)
      If *FlexStatusBarGadget
        SetGadgetData(NewGadget, *FlexStatusBarGadget)
;         If StartDrawing(CanvasOutput(NewGadget))
;           
;           StopDrawing()
;         EndIf
      EndIf
    EndIf
    
  EndIf
  
  ProcedureReturn NewGadget
  
EndProcedure


Procedure.i AddFlexStatusBarField(Gadget.i, Width.i)
  
  Protected.i x
  Protected *FlexStatusBarGadget.FlexStatusBarGadget_Structure
  
  
  If IsGadget(Gadget)
    *FlexStatusBarGadget = GetGadgetData(Gadget)
    OpenGadgetList(Gadget)
    ForEach *FlexStatusBarGadget\FieldList()
      x + GadgetWidth(*FlexStatusBarGadget\FieldList())
    Next
    AddElement(*FlexStatusBarGadget\FieldList())
    *FlexStatusBarGadget\FieldList() = TextGadget(#PB_Any, x, 0, Width, GadgetHeight(Gadget) - 4, "", #PB_Text_Border)
    CloseGadgetList()
  EndIf
  
  ProcedureReturn 0
  
EndProcedure


Procedure.i FlexStatusBarText(Gadget.i, Field.i, Text$)
  
  Protected *FlexStatusBarGadget.FlexStatusBarGadget_Structure
  
  
  If IsGadget(Gadget)
    *FlexStatusBarGadget = GetGadgetData(Gadget)
    If SelectElement(*FlexStatusBarGadget\FieldList(), Field)
      SetGadgetText(*FlexStatusBarGadget\FieldList(), Text$)
    EndIf
  EndIf
  
  ProcedureReturn 0
  
EndProcedure


CompilerIf #PB_Compiler_IsMainFile
  
  OpenWindow(0, 0, 0, 400, 300, "Demo", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ListViewGadget(0, 10, 10, 200, 200)
  FlexStatusBarGadget(1, 25, 0)
  AddFlexStatusBarField(1, 50)
  AddFlexStatusBarField(1, 80)
  FlexStatusBarText(1, 0, "Test")
  FlexStatusBarText(1, 1, "Test2")
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  
CompilerEndIf
lisa_beille
User
User
Posts: 24
Joined: Fri Dec 22, 2023 5:59 pm

Re: strange behaviour StatusBar on ListViewGadget

Post by lisa_beille »

infratec wrote: Mon Jan 08, 2024 11:35 pm A basic 'starter':

Code: Select all

CompilerIf #PB_Compiler_IsMainFile
  EnableExplicit
CompilerEndIf


Structure FlexStatusBarGadget_Structure
  List FieldList.i()
EndStructure



Procedure.i FlexStatusBarGadget(Gadget.i, Height.i, ParentGadget.i)
  
  Protected.i NewGadget, x, y, width
  Protected *FlexStatusBarGadget.FlexStatusBarGadget_Structure
  
  
  If IsGadget(ParentGadget)
    x = GadgetX(ParentGadget)
    y = GadgetY(ParentGadget) + GadgetHeight(ParentGadget)
    width = GadgetWidth(ParentGadget)
    NewGadget = CanvasGadget(Gadget, x, y, width, height, #PB_Canvas_Container|#PB_Canvas_Border)
    If NewGadget
      If Gadget <> #PB_Any
        NewGadget = Gadget
      EndIf
      *FlexStatusBarGadget = AllocateStructure(FlexStatusBarGadget_Structure)
      If *FlexStatusBarGadget
        SetGadgetData(NewGadget, *FlexStatusBarGadget)
;         If StartDrawing(CanvasOutput(NewGadget))
;           
;           StopDrawing()
;         EndIf
      EndIf
    EndIf
    
  EndIf
  
  ProcedureReturn NewGadget
  
EndProcedure


Procedure.i AddFlexStatusBarField(Gadget.i, Width.i)
  
  Protected.i x
  Protected *FlexStatusBarGadget.FlexStatusBarGadget_Structure
  
  
  If IsGadget(Gadget)
    *FlexStatusBarGadget = GetGadgetData(Gadget)
    OpenGadgetList(Gadget)
    ForEach *FlexStatusBarGadget\FieldList()
      x + GadgetWidth(*FlexStatusBarGadget\FieldList())
    Next
    AddElement(*FlexStatusBarGadget\FieldList())
    *FlexStatusBarGadget\FieldList() = TextGadget(#PB_Any, x, 0, Width, GadgetHeight(Gadget) - 4, "", #PB_Text_Border)
    CloseGadgetList()
  EndIf
  
  ProcedureReturn 0
  
EndProcedure


Procedure.i FlexStatusBarText(Gadget.i, Field.i, Text$)
  
  Protected *FlexStatusBarGadget.FlexStatusBarGadget_Structure
  
  
  If IsGadget(Gadget)
    *FlexStatusBarGadget = GetGadgetData(Gadget)
    If SelectElement(*FlexStatusBarGadget\FieldList(), Field)
      SetGadgetText(*FlexStatusBarGadget\FieldList(), Text$)
    EndIf
  EndIf
  
  ProcedureReturn 0
  
EndProcedure


CompilerIf #PB_Compiler_IsMainFile
  
  OpenWindow(0, 0, 0, 400, 300, "Demo", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ListViewGadget(0, 10, 10, 200, 200)
  FlexStatusBarGadget(1, 25, 0)
  AddFlexStatusBarField(1, 50)
  AddFlexStatusBarField(1, 80)
  FlexStatusBarText(1, 0, "Test")
  FlexStatusBarText(1, 1, "Test2")
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  
CompilerEndIf
thank you
Post Reply