Page 1 of 1

Windows with lot of TextGadget

Posted: Fri Feb 16, 2024 12:45 pm
by ALAN-MHz
Dear all, i've coded a windows full of single textgadget that change text and colour a lot at runtime, so the windows refresh seems really unwatchable with text that disappear, reappear and change colour continuosly, i want to know if i can optimize this solution (with single textgadget or editorgadget or anything else).

The main problem is that every single line can have a different colour, because the tool report the status of some sensors selectable from a ComboBoxGadget, this is the reason of why i'm currently using a lot of single line textgadget.

Any suggestions ? Thanks in advance!

Re: Windows with lot of TextGadget

Posted: Fri Feb 16, 2024 1:08 pm
by mk-soft
I Thing its better to use a ListIconGadget.

Example

Update 4

Code: Select all

;-TOP

#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.2"

Enumeration Windows
  #Main
EndEnumeration

Enumeration MenuBar
  #MainMenu
EndEnumeration

Enumeration MenuItems
  #MainMenuAbout
  #MainMenuExit
EndEnumeration

Enumeration Gadgets
  #MainList
EndEnumeration

Enumeration StatusBar
  #MainStatusBar
EndEnumeration

; ----

Procedure FillList(Gadget, Count)
  Protected i
  
  For i = 0 To count - 1
    AddGadgetItem(Gadget, i, "Sensor Number " + i)
  Next
  
EndProcedure

Procedure UpdateList(Gadget, Count)
  Protected value, item, color
  item = Random(Count - 1)
  value = Random(100)
  Select value
    Case 0 To 19
      color = #Red
    Case 20 To 39
      color = #Yellow
    Case 40 To 59
      color = #Green
    Case 60 To 79
      color = #Yellow
    Case 80 To 100
      color = #Red
  EndSelect
  SetGadgetItemText(Gadget, item, "" + value, 1)
  SetGadgetItemColor(Gadget, Item, #PB_Gadget_BackColor, color, 1)
EndProcedure

; ----

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
  ; Resize gadgets
  ResizeGadget(#MainList, 5, 5, dx - 10, dy - 10)
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    MenuTitle("&File")
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      MenuItem(#PB_Menu_About, "")
    CompilerElse
      MenuItem(#MainMenuAbout, "About")
    CompilerEndIf
    ; Menu File Items
    
    CompilerIf Not #PB_Compiler_OS = #PB_OS_MacOS
      MenuBar()
      MenuItem(#MainMenuExit, "E&xit")
    CompilerEndIf
    
    ; StatusBar
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
    ListIconGadget(#MainList, 5, 5, dx - 10, dy - 10, "Sensor", 200)
    AddGadgetColumn(#MainList, 1, "Value", 100)
    AddGadgetColumn(#MainList, 2, "Min", 100)
    AddGadgetColumn(#MainList, 3, "Max", 100)
    AddGadgetColumn(#MainList, 4, "", 100)
    
    CompilerIf #PB_Compiler_Version >= 610
      SetGadgetItemAttribute(#MainList, 0, #PB_ListIcon_ColumnAlignment, #PB_ListIcon_Center, 1)
      SetGadgetItemAttribute(#MainList, 0, #PB_ListIcon_ColumnAlignment, #PB_ListIcon_Center, 2)
      SetGadgetItemAttribute(#MainList, 0, #PB_ListIcon_ColumnAlignment, #PB_ListIcon_Center, 3)
    CompilerEndIf
    
    FillList(#MainList, 20)
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    AddWindowTimer(#Main, 1, 100)
    
    ; Event Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              Break
              
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                
            CompilerEndIf
            
          Case #MainMenuAbout
            MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
              
          Case #MainMenuExit
            PostEvent(#PB_Event_CloseWindow, #Main, #Null)
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
        Case #PB_Event_Timer
          UpdateList(#MainList, 20)
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()

Re: Windows with lot of TextGadget

Posted: Fri Feb 16, 2024 1:16 pm
by spikey
mk-soft wrote: Fri Feb 16, 2024 1:08 pm I Thing its better to use a ListIconGadget.
... or drawing all the text onto a CanvasGadget instead. But you should do proofs of concept before such a radical change because you may still not like the results...

Re: Windows with lot of TextGadget

Posted: Fri Feb 16, 2024 1:56 pm
by AZJIO
Scintilla + SCI_INDICATOR

Re: Windows with lot of TextGadget

Posted: Fri Feb 16, 2024 2:38 pm
by ALAN-MHz
Thanks to all, i'll check one by one to see which works better for my tool!