SideBarGadget

Share your advanced PureBasic knowledge/code with the community.
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: SideBarGadget

Post by idle »

Updated fixed some bugs, blocking event or other gadgets open/close gadget list.

see code 1st post
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: SideBarGadget

Post by BarryG »

First post doesn't say "Edited" ? Also, from MSDN: "It is only necessary to call DestroyIcon for icons created with the CreateIconIndirect function."
Last edited by BarryG on Fri May 26, 2023 3:37 am, edited 1 time in total.
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: SideBarGadget

Post by idle »

BarryG wrote: Fri May 26, 2023 3:22 am First post doesn't say "Edited" ?

Also, from MSDN: "It is only necessary to call DestroyIcon for icons created with the CreateIconIndirect function."
Thanks for the info,
Do you want me to change the title?
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: SideBarGadget

Post by BarryG »

No, what I mean is see how my post above says "Lasted edited..." on it? Your first post doesn't, so I can't tell when it's edited/updated. Is that a forum bug, or because you're a moderator?
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: SideBarGadget

Post by idle »

BarryG wrote: Fri May 26, 2023 3:38 am No, what I mean is see how my post above says "Lasted edited..." on it? Your first post doesn't, so I can't tell when it's edited/updated. Is that a forum bug, or because you're a moderator?
No it show the edit count as I'm a Mod, which is a good thing in my case as I often don't see mistakes until I post a message
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: SideBarGadget

Post by idle »

Ok I've almost got it working on osx

In the SideBar_Draw() ive added a compiler ifs for OSX lines 103 and 151

code 1st post.

drag and drop doesn't seem to work osx?

Image
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: SideBarGadget

Post by mk-soft »

idle wrote: Fri May 26, 2023 5:36 am drag and drop doesn't seem to work osx?
On macOS, drag and drop has not worked properly for some time. Something has been changed in the OS that makes it very complicated. But it is on the to-do list
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
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: SideBarGadget

Post by Caronte3D »

Feature request:
Would be nice if we can show/hide the menu clicking on an empty area instead of only on the little arrow.
An option to auto-hide after click on a menu item would be nice too.
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: SideBarGadget

Post by idle »

Caronte3D wrote: Fri May 26, 2023 9:23 am Feature request:
Would be nice if we can show/hide the menu clicking on an empty area instead of only on the little arrow.
An option to auto-hide after click on a menu item would be nice too.
Yes hover and click will be easy to add.

I need to figure out the oddities on osx it was hard to click the arrow.
I have no idea how to do the zorder yet, hopefully there's an easy enough api
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: SideBarGadget

Post by idle »

mk-soft wrote: Fri May 26, 2023 8:36 am
idle wrote: Fri May 26, 2023 5:36 am drag and drop doesn't seem to work osx?
On macOS, drag and drop has not worked properly for some time. Something has been changed in the OS that makes it very complicated. But it is on the to-do list
I found a work around but wasn't sure if it was a bug or not.
Thanks for confirming.
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: SideBarGadget

Post by idle »

Caronte3D wrote: Fri May 26, 2023 9:23 am Feature request:
Would be nice if we can show/hide the menu clicking on an empty area instead of only on the little arrow.
An option to auto-hide after click on a menu item would be nice too.
Added Auto show hide activated by mouse enter leave and timed dwell, I still need to test how it works dpi scaled and on osx
the target area is a rect 25px wide by sidebar height-arrow size

next will be footer text and a background image.

I'm also thinking about adding pages with tabs on the side, It requires a bit more thought on implementation and I also have to work out how to make the rotated text work with a screen reader, replace with image gadgets perhaps.
I want to avoid API's if possible.

latest version 1.0.1.4a
changed font to Tahoma

There may still be a bug on osx or maybe it needs thread safe enabled, I got an IMA in SideBar_Event() while repeatedly activating the slide.

Also I've fixed bug when you resize the window width smaller than the gadget width, next update
and I'm adding adjustment to handle windows status bar
need to fix hover for dpi scaling
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: SideBarGadget

Post by Caronte3D »

I think auto-hide would be better with a timer starting at mouse leave (or something like that), because now the auto-hide doesn't work if you move the mouse out fast

At least on Windows, It flicker very much when window is scaled on the height dimension.
If you lock the window update on the SideBar_Draw() procedure, you can get rid of almost all the flicker:

Code: Select all

  Procedure SideBar_Draw()   
    
    
    ;Disable updates
    Protected ew = WindowID(EventWindow())
    LockWindowUpdate_(ew)
    
    Protected timg,w,h,x,y,cy,ph =10
    Protected gadget,*sidebar.SideBar_Gadget=0
    Protected menuid,bfirst=1  
    
    gadget = EventGadget() 
    
    If IsGadget(gadget) 
      *sidebar = GetGadgetData(gadget)
      If *sidebar <> 0  
        ForEach *sidebar\MenuItems() 
          If Not IsGadget(*sidebar\MenuItems()\ID)
            timg = CreateImage(#PB_Any,1,1)            
            StartDrawing(ImageOutput(timg))
            DrawingFont(FontID(*sidebar\MenuItems()\font))  
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS 
              w = DesktopUnscaledX(TextWidth(*sidebar\MenuItems()\lable)) *1.5
              h = DesktopUnscaledY(TextHeight(*sidebar\MenuItems()\lable)) * 1.5 
            CompilerElse 
              w = DesktopUnscaledX(TextWidth(*sidebar\MenuItems()\lable)) 
              h = DesktopUnscaledY(TextHeight(*sidebar\MenuItems()\lable))
            CompilerEndIf 
            
            StopDrawing()  
            FreeImage(timg)
            
            OpenGadgetList(*sidebar\gadgetID) 
            *sidebar\MenuItems()\ID = HyperLinkGadget(#PB_Any,10,ph,w,h,*sidebar\MenuItems()\lable,*sidebar\MenuItems()\activecolor)
            CloseGadgetList() 
            If  *sidebar\MenuItems()\ID 
              If *sidebar\MenuItems()\tooltip <> "" 
                GadgetToolTip(*sidebar\MenuItems()\ID, *sidebar\MenuItems()\tooltip) 
              EndIf   
              ph+h*1.5
              If w >= *sidebar\maxwidth 
                *sidebar\maxwidth = w 
              EndIf   
              SetGadgetColor(*sidebar\MenuItems()\ID,#PB_Gadget_FrontColor,*sidebar\MenuItems()\frontcolor)   
              SetGadgetColor(*sidebar\MenuItems()\ID,#PB_Gadget_BackColor,*sidebar\MenuItems()\BackColor)   
              SetGadgetFont(*sidebar\MenuItems()\ID,FontID(*sidebar\MenuItems()\font))
              SetGadgetData(*sidebar\MenuItems()\ID,*sidebar\MenuItems()) 
              BindEvent(#PB_Event_Gadget,@SideBar_EventMenu(),*sidebar\PID,*sidebar\MenuItems()\ID)  
            EndIf  
          Else 
            w =  GadgetWidth(*sidebar\MenuItems()\id) * 1.5
            If w >= *sidebar\maxwidth 
              *sidebar\maxwidth = w 
            EndIf  
            SetGadgetText(*sidebar\MenuItems()\ID,*sidebar\MenuItems()\lable)
          EndIf 
        Next 
        
        If Not IsGadget(*sidebar\ShowHideGad) 
          timg = CreateImage(#PB_Any,1,1)            
          StartDrawing(ImageOutput(timg))
          DrawingFont(FontID(*sidebar\fonts\font[1]))  
          
          If *sidebar\ShowArrow = "" 
            *sidebar\ShowArrow = strchr($25B6) 
          EndIf  
          If *sidebar\HideArrow = "" 
            *sidebar\HideArrow = strchr($25C0) 
          EndIf 
          
          CompilerIf #PB_Compiler_OS = #PB_OS_MacOS 
            w = TextWidth(*sidebar\ShowArrow) * 1.5
            h = TextHeight(*sidebar\ShowArrow)  * 1.5 
          CompilerElse 
            w = TextWidth(*sidebar\ShowArrow) 
            h = TextHeight(*sidebar\ShowArrow)  
          CompilerEndIf 
          
          StopDrawing()  
          FreeImage(timg)
          
          If bfirst  
            *sidebar\titlesize = h 
            bfirst = 0 
          EndIf   
          
          OpenGadgetList(*sidebar\gadgetID) 
          *sidebar\ShowHideGad = HyperLinkGadget(-1,*sidebar\maxwidth-w-5,0,w,h,*sidebar\HideArrow,*sidebar\ActiveColor)
          CloseGadgetList() 
          SetGadgetColor(*sidebar\ShowHideGad,#PB_Gadget_FrontColor,*sidebar\FrontColor)   
          SetGadgetColor(*sidebar\ShowHideGad,#PB_Gadget_BackColor,*sidebar\BackColor)   
          SetGadgetFont(*sidebar\ShowHideGad,FontID(*sidebar\fonts\font[1]))
          SetGadgetData(*sidebar\ShowHideGad,*sidebar) 
          GadgetToolTip(*sidebar\ShowHideGad, "Close Sidebar")
          BindGadgetEvent(*sidebar\ShowHideGad,@Sidebar_StartSlide(),#PB_EventType_LeftClick)
        Else 
          *sidebar\minLeft = -(*sidebar\maxwidth-GadgetWidth(*sidebar\ShowHideGad)-10)
          ResizeGadget(*sidebar\ShowHideGad,*sidebar\maxwidth-GadgetWidth(*sidebar\ShowHideGad)-5,0,GadgetWidth(*sidebar\ShowHideGad),GadgetHeight(*sidebar\ShowHideGad))
          
        EndIf  
        
        Protected sh
        
        sh = *sidebar\WinhasStatus 
             
        ResizeGadget(*sidebar\gadgetID,*sidebar\left,0,*sidebar\maxwidth,WindowHeight(*sidebar\PID)-sh)
        
        
        If *sidebar\SideMessage <> "" 
          If StartDrawing(CanvasOutput(*sidebar\gadgetID)) 
            DrawingFont(FontID(*sidebar\fonts\font[0]))  
            w = TextWidth(*sidebar\SideMessage) 
            h = TextHeight(*sidebar\SideMessage)
            cy = ((WindowHeight(*sidebar\PID)-sh) - DesktopUnscaledX(w)) * 0.5  
            If IsGadget(*sidebar\ShowHideGad) 
              y = GadgetY(*sidebar\ShowHideGad) + GadgetHeight(*sidebar\ShowHideGad) 
            EndIf    
            
            DrawingFont(FontID(*sidebar\fonts\font[0]))  
            x = DesktopScaledX(*sidebar\maxwidth-h)
            y = DesktopScaledY(y)
            h = DesktopScaledY(h) 
            w = DesktopScaledX(GadgetHeight(*sidebar\gadgetID))-y
            
            Box(x-5,y,h+5,w,*sidebar\BackColor)
            
            x = DesktopScaledX(*sidebar\maxwidth)
            y = DesktopScaledY(cy)  
            DrawRotatedText(x,y,*sidebar\SideMessage,-90,*sidebar\SideMessageColor) 
            
            StopDrawing() 
          EndIf 
        EndIf 
      EndIf 
    EndIf 
    
  ;Restore updates      
  LockWindowUpdate_(0)
  UpdateWindow_(ew)
  
    Delay(1)

  EndProcedure  
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: SideBarGadget

Post by idle »

Yes that should be ok thanks.

The problem I was trying to address with the slide is that the mouse enter and leave events fire within the gadget if you touch the hyperlinks. The dpi scaling is still confusing

There's still a bug in the draw on osx, I will pay more attention to that when I plan to use it.
At least zorder isn't a problem on OSX, one thing less to worry about :D
benubi
Enthusiast
Enthusiast
Posts: 113
Joined: Tue Mar 29, 2005 4:01 pm

Re: SideBarGadget

Post by benubi »

Very useful, had to grab it.
Nice work!

It seems the Mac Version looks so much better. I haven't fully tested it or gone through the code, but I suppose it could be a help for a Raspberry app or so, or when working with touchscreens maybe (?)

If you want to make it "perfect" you could also include:

- Real images / icons per item (optionally of course)

- LTR+RTL text direction (not for me personally, but you can never know)

- additional anchoring points/slides for the gadgets if not already implemented (right, top, bottom)


This could make a very interactive/responsive GUI with the more important "action" taking place in the middle, and the images/icons would make it look the same on all machines and add more possibilities. Well I hope this won't make too much work but I guess it does. :oops:
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: SideBarGadget

Post by idle »

@benube

Thanks and yes there's still a lot to do, I'm still at the stage of playing with it to see how it can be used.
Slide in/out, pin open closed. I will also add a layout grid eventually so you can also add other gadgets.
Post Reply