Counting pixels ??

Just starting out? Need help? Post your questions and find answers here.
RogerTunnicliffe
User
User
Posts: 18
Joined: Fri Oct 17, 2025 10:10 pm

Counting pixels ??

Post by RogerTunnicliffe »

This code places 5 buttons inside a container that has a height of 28px
The buttons have a height of 26px and are located 1 pixel down from the top of the container

and yet...

they overlap the container at the bottom unless I make the container 30px deep.

What am I doing wrong ?

Code: Select all

     FullGadgetHeight = WindowHeight(Window_0) - MenuHeight() - 2
 
      Container_ExplorerButtons = ContainerGadget(#PB_Any, 1, FullGadgetHeight-28, 300, 28, #PB_Container_BorderLess)
        B_Edit = ButtonGadget(#B_Edit, 4, 1, 50, 26, "F4-Edit")
        B_Copy = ButtonGadget(#B_Copy, 56, 1, 50, 26, "F5-Copy")
        B_Move = ButtonGadget(#B_Move, 108, 1, 50, 26, "F6-Move")
        B_MkDir = ButtonGadget(#B_MkDir, 160, 1, 50, 26, "F7-Mkdir")
        B_Delete = ButtonGadget(#B_Delete, 213, 1, 50, 26, "F8-Delete")
      CloseGadgetList()

Olli
Addict
Addict
Posts: 1256
Joined: Wed May 27, 2020 12:26 pm

Re: Counting pixels ??

Post by Olli »

You select the source code line containing the container.
You delete the line.
And you write here your opinion, after this update.
RogerTunnicliffe
User
User
Posts: 18
Joined: Fri Oct 17, 2025 10:10 pm

Re: Counting pixels ??

Post by RogerTunnicliffe »

Not sure what you expect here.

I delete this line : - Container_ExplorerButtons = ContainerGadget(#PB_Any, 1, FullGadgetHeight-28, 300, 28, #PB_Container_BorderLess)
and all the buttons move to the top of the screen (1 px down) the container disappears leaving no way to tell if it has overflowed past the container ??
User avatar
kenmo
Addict
Addict
Posts: 2051
Joined: Tue Dec 23, 2003 3:54 am

Re: Counting pixels ??

Post by kenmo »

First, what PB version and especially what OS?

Second, please always post runnable example code, so anyone reading can quickly confirm and diagnose your issue.

Both of these will help you get better, faster answers from more people...
RogerTunnicliffe
User
User
Posts: 18
Joined: Fri Oct 17, 2025 10:10 pm

Re: Counting pixels ??

Post by RogerTunnicliffe »

The latest version (6.21)
Debian 11
and... You want me to post 300 lines of code ? (Happy to do it if that is what you want)

Here's another example

Editor_2 = EditorGadget(#PB_Any, 1, FullGadgetHeight-27, 592, 2)

although the editor height is 2px it overflows thru the bottom of the Form ?
Last edited by RogerTunnicliffe on Thu Oct 23, 2025 4:06 am, edited 1 time in total.
User avatar
kenmo
Addict
Addict
Posts: 2051
Joined: Tue Dec 23, 2003 3:54 am

Re: Counting pixels ??

Post by kenmo »

300 lines of code, no. Just enough to make it compile and run.
It only takes you a minute to edit it once, rather than expecting everyone reading to edit the example code to test it.
It's just friendly advice. More people will help if they can directly paste and test!


On PB 6.21 and Ubuntu-based Linux, I do see the bottom overlap :!:
But in my case, it seems to be because the Container has a visual border, despite the #PB_Container_BorderLess flag :!:
If you see a border too, perhaps that's the real bug?

Code: Select all

OpenWindow(0, 0, 0, 640, 240, "Demo", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)

FullGadgetHeight = WindowHeight(0) - 2

Container = ContainerGadget(#PB_Any, 1, FullGadgetHeight-28, 300, 28, #PB_Container_BorderLess)
  B_Edit = ButtonGadget(#PB_Any, 4, 1, 50, 26, "F4-Edit")
  B_Copy = ButtonGadget(#PB_Any, 56, 1, 50, 26, "F5-Copy")
  B_Move = ButtonGadget(#PB_Any, 108, 1, 50, 26, "F6-Move")
  B_MkDir = ButtonGadget(#PB_Any, 160, 1, 50, 26, "F7-Mkdir")
  B_Delete = ButtonGadget(#PB_Any, 213, 1, 50, 26, "F8-Delete")
  
  Debug "Requested height 28"
  Debug "Got height " + Str(GadgetHeight(Container))
  Debug ""
  Debug "Requested height 26"
  Debug "Got height " + Str(GadgetHeight(B_Delete))
  
CloseGadgetList()

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
RogerTunnicliffe
User
User
Posts: 18
Joined: Fri Oct 17, 2025 10:10 pm

Re: Counting pixels ??

Post by RogerTunnicliffe »

Thanks for that quick response.
I think your example shows exactly what I am talking about.

and yes... "#PB_Container_BorderLess" and yet we have a border

To further complicate things....
I ask for Editor_2 to have a height of 2px, it reports it as 2 pixels but it's certainly a lot bigger than that ??

Code: Select all

OpenWindow(0, 0, 0, 640, 240, "Demo", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)

FullGadgetHeight = WindowHeight(0) - 2

Editor_2 = EditorGadget(#PB_Any, 4, FullGadgetHeight-100, 300, 2)

Container = ContainerGadget(#PB_Any, 1, FullGadgetHeight-28, 300, 28, #PB_Container_BorderLess)
  B_Edit = ButtonGadget(#PB_Any, 4, 1, 50, 26, "F4-Edit")
  B_Copy = ButtonGadget(#PB_Any, 56, 1, 50, 26, "F5-Copy")
  B_Move = ButtonGadget(#PB_Any, 108, 1, 50, 26, "F6-Move")
  B_MkDir = ButtonGadget(#PB_Any, 160, 1, 50, 26, "F7-Mkdir")
  B_Delete = ButtonGadget(#PB_Any, 213, 1, 50, 26, "F8-Delete")
  
  Debug "Requested height 28"
  Debug "Got height " + Str(GadgetHeight(Container))
  Debug ""
  Debug "Requested height 26"
  Debug "Got height " + Str(GadgetHeight(B_Delete))

  Debug ""
  Debug "Requested height 2"
  Debug "Got height " + Str(GadgetHeight(Editor_2))
  
CloseGadgetList()

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
User avatar
TI-994A
Addict
Addict
Posts: 2749
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Counting pixels ??

Post by TI-994A »

Works as expected on PureBasic v6.21 running on MacOS and Windows 11.

It does not display the border, there's no overlap, and even the gadget height of 2 renders correctly. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
RogerTunnicliffe
User
User
Posts: 18
Joined: Fri Oct 17, 2025 10:10 pm

Re: Counting pixels ??

Post by RogerTunnicliffe »

and..... How does that help me ?
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Counting pixels ??

Post by infratec »

It helps, that the users know that the bug exists only in linux :wink:

And your fault diagnostig in the first post is wrong.
The problem is that the container is showing a border.

So you can place a bug report in the linux section.

You can try a CanvasGadget() with #PB_Canvas_Container set.
Maybe this solves your current problem.
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Counting pixels ??

Post by infratec »

To avoid the white background of the CanvasGadget():

Code: Select all

OpenWindow(0, 0, 0, 640, 240, "Demo", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)

FullGadgetHeight = WindowHeight(0) - 2

If StartDrawing(WindowOutput(0))
  Color = Point(0, 0)
  StopDrawing()
EndIf

Container = CanvasGadget(#PB_Any, 1, FullGadgetHeight-28, 300, 28, #PB_Canvas_Container)

  If StartDrawing(CanvasOutput(Container))
    Box(0, 0, 300, 200, Color)
    StopDrawing()
  EndIf

  B_Edit = ButtonGadget(#PB_Any, 4, 1, 50, 26, "F4-Edit")
  B_Copy = ButtonGadget(#PB_Any, 56, 1, 50, 26, "F5-Copy")
  B_Move = ButtonGadget(#PB_Any, 108, 1, 50, 26, "F6-Move")
  B_MkDir = ButtonGadget(#PB_Any, 160, 1, 50, 26, "F7-Mkdir")
  B_Delete = ButtonGadget(#PB_Any, 213, 1, 50, 26, "F8-Delete")
  
  Debug "Requested height 28"
  Debug "Got height " + Str(GadgetHeight(Container))
  Debug ""
  Debug "Requested height 26"
  Debug "Got height " + Str(GadgetHeight(B_Delete))
  
CloseGadgetList()

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
RogerTunnicliffe
User
User
Posts: 18
Joined: Fri Oct 17, 2025 10:10 pm

Re: Counting pixels ??

Post by RogerTunnicliffe »

Ok, so that does work...but does that mean that everywhere the UI is messed up I have to code that work-around.
also ... How do I have the colors in my editor gadget

Code: Select all

OpenWindow(0, 0, 0, 640, 240, "Demo", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)

  If StartDrawing(WindowOutput(0))
   Color = Point(0, 0)
   StopDrawing()
  EndIf

  FullGadgetHeight = WindowHeight(0) - 2

    Container_Editor2 = CanvasGadget(#PB_Any, 1, FullGadgetHeight-26, 592, 23, #PB_Canvas_Container)
      If StartDrawing(CanvasOutput(Container_Editor2))
        Box(1, FullGadgetHeight-26, 592, 23)
        StopDrawing()
      EndIf

      Editor_2 = EditorGadget(#PB_Any, 1, FullGadgetHeight-26, 592, 23)
        SetGadgetColor(Editor_2, #PB_Gadget_BackColor, #Black)                 <------ This no longer works
        SetGadgetColor(Editor_2, #PB_Gadget_FrontColor, #White)               <------ This no longer works

    CloseGadgetList()

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
User avatar
mk-soft
Always Here
Always Here
Posts: 6313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Counting pixels ??

Post by mk-soft »

There are minimum sizes for Linux gadgets ...
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: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Counting pixels ??

Post by infratec »

Your EditorGadget coordinates are far away from visible, so you can not see and do anything.
The Gadget is inside of the container, which is 23 pixel high, but you place the Editor Gadget at WindowHeight() - 28
User avatar
TI-994A
Addict
Addict
Posts: 2749
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Counting pixels ??

Post by TI-994A »

Here's a working POC of your code, implementing a string gadget to circumvent Linux's larger minimum height for the editor gadget.

Code: Select all

OpenWindow(0, 0, 0, 640, 500, "Demo", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)

container_width = 514
container_height = 52

If StartDrawing(WindowOutput(0))
  match_window_colour = Point(10, 10)
  StopDrawing()
EndIf

Container = CanvasGadget(#PB_Any, 1, WindowHeight(0) - 52, container_width, container_height, #PB_Canvas_Container)

  If StartDrawing(CanvasOutput(Container))
    Box(0, 0, container_width, container_height, match_window_colour)
    StopDrawing()
  EndIf

  Editor_2 = StringGadget(#PB_Any, 1, 1, 512, 23, "")
  SetGadgetColor(Editor_2, #PB_Gadget_BackColor, #Black) 
  SetGadgetColor(Editor_2, #PB_Gadget_FrontColor, #White)     
  
  B_Edit = ButtonGadget(#PB_Any, 4, 25, 100, 26, "F4-Edit")
  B_Copy = ButtonGadget(#PB_Any, 106, 25, 100, 26, "F5-Copy")
  B_Move = ButtonGadget(#PB_Any, 208, 25, 100, 26, "F6-Move")
  B_MkDir = ButtonGadget(#PB_Any, 310, 25, 100, 26, "F7-Mkdir")
  B_Delete = ButtonGadget(#PB_Any, 412, 25, 100, 26, "F8-Delete")

CloseGadgetList()

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend

Alternatively, if you don't need these gadgets to be in a container, simply render them directly onto the window itself:

Code: Select all

OpenWindow(0, 0, 0, 640, 500, "Demo", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)

editor_y = WindowHeight(0) - 52
button_y = WindowHeight(0) - 28

Editor_2 = StringGadget(#PB_Any, 1, editor_y, 512, 23, "")
SetGadgetColor(Editor_2, #PB_Gadget_BackColor, #Black) 
SetGadgetColor(Editor_2, #PB_Gadget_FrontColor, #White)     

B_Edit = ButtonGadget(#PB_Any, 4, button_y, 100, 26, "F4-Edit")
B_Copy = ButtonGadget(#PB_Any, 106, button_y, 100, 26, "F5-Copy")
B_Move = ButtonGadget(#PB_Any, 208, button_y, 100, 26, "F6-Move")
B_MkDir = ButtonGadget(#PB_Any, 310, button_y, 100, 26, "F7-Mkdir")
B_Delete = ButtonGadget(#PB_Any, 412, button_y, 100, 26, "F8-Delete")

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend

I hope it helps.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply