Wrong number of grid columns

Started by Maurizio, March 23, 2016, 08:15:57 AM

Previous topic - Next topic

Maurizio

The following program shows a frame with only 4 columns instead of 5.

Is this a bug ?

I'm trying with the last NewLisp version and java (jdk) 1.8.0_74.



Best regards.

Maurizio.


(set-locale "C")
(load (append (env "NEWLISPDIR") "/guiserver.lsp"))

(gs:init)

(gs:frame 'window 100 100 400 300 "my test")
(gs:set-grid-layout 'window 3 5)

(dolist (btn '("one" "two" "three" "four" "five" "six" "seven" "height" "nine" "ten"  "eleven"))
  (gs:button (sym btn) 'gs:no-action btn 75 25)
  (gs:add-to 'window (sym btn)))
   
(gs:set-visible 'window true)

(gs:listen)

Lutz

#1
Populate the frame first with panels then add other elements into each panel. The following example creates a window with a rows x cols grid:


#!/usr/bin/newlisp

(set-locale "C")
(load (append (env "NEWLISPDIR") "/guiserver.lsp"))

(gs:init)

(gs:frame 'GridDemo 100 100 300 200 "panels in a grid")
(set 'rows 4 'cols 8)
(gs:set-grid-layout 'GridDemo rows cols)

(dotimes (i rows) (dotimes (j cols)
(set 'id (sym (string "P" i j)))
(gs:panel id)
(gs:set-background id (list (random) (random) (random)))
(gs:add-to 'GridDemo id)
))

(gs:set-visible 'GridDemo true)
(gs:listen)



PS: the following demo files use gs:set-grid-layout



allfonts-demo.lsp

cursor-demo.lsp

font-demo.lsp

guiserver.lsp

newlisp-edit.lsp

table-demo.lsp

widgets-demo-jp.lsp

widgets-demo-ru.lsp

widgets-demo.lsp



Not all are using panels, not sure what exactly caused the problem in your example, but try with creating panels first.

maurizio.ferreira

#2
The problem seems related to the number of items, and appears if them don't fill completely the grid or if

its number exceed the grid capacity.

It seems that the layout ignores the number of colums you specify while it respects the number of rows,

and that it adjust the number of colums so that it's able to display all the added elements.



In the following program, e.g. if you set 'number to a value below 13 or above 15, the grid becomes, rispectively of 3 * 4 and 3 * 6

If you set the number as 100, the grid becomes of 34 columns, with 2 empty cells.

If you set rows 7 and num 8, you get two columns, with the first 4 rows filled, and other 3 rows empty.



In other words it seems that cols becomes (/ (+ num rows -1 ) rows )



I'm not trying to dispraise NewLisp, (it's wonderful !)

I'm just experimenting with its layout capabilities.



Best regards.

Maurizio.




(set-locale "C")
(load (append (env "NEWLISPDIR") "/guiserver.lsp"))

(gs:init)

(gs:frame 'GridDemo 100 100 300 200 "panels in a grid")
(set 'rows 3 'cols 5 'num 16)
(gs:set-grid-layout 'GridDemo rows cols)

(dotimes (i num)
   (set 'id (sym (string "P" i)))
   (gs:panel id)
   (gs:set-background id (list (random) (random) (random)))
   (gs:add-to 'GridDemo id)
)

(gs:set-visible 'GridDemo true)
(gs:listen)

Lutz

#3
Thanks for the thorough analysis.



This seems to be a peculiarity with the Java API. I am currently running JDK 1.8.0_40 on Windows 7. As I am currently travelling, I only have access to a Windows computer, but can test Mac OSX when I am back home by the end of April. I assume it will be the same picture on OSX. Fortunately there is a workaround.