elcritch / cssgrid

Pure Nim CSS Grid layout engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implicit lines created too late or not at all

curioussavage opened this issue · comments

commented

gridTemplate.computeTracks(node.box.UiBox)

I read in the spec that it should implicitly create a in each direction. This seems to be done in this proc but it's called too late.

results in

value out of range: -1 notin 0 .. 9223372036854775807
/Users/me/projects/cssgrid/src/cssgrid/layout.nim(301) computeNodeLayout
/Users/me/projects/cssgrid/src/cssgrid/layout.nim(151) setGridSpans
/Users/me/projects/cssgrid/src/cssgrid/layout.nim(132) setSpan
/Users/me/projects/cssgrid/src/cssgrid/layout.nim(126) gridAutoInsert

or if I add a call to computeTracks at the start it still fails at.

/Users/me/projects/cssgrid/tests/tlayout.nim(88) tlayout
/Users/me/projects/cssgrid/src/cssgrid/layout.nim(327) computeNodeLayout
/Users/me/projects/cssgrid/src/cssgrid/layout.nim(166) computeBox
/Users/me/projects/cssgrid/src/cssgrid/layout.nim(118) getGrid
/Users/me/.choosenim/toolchains/nim-1.6.6/lib/system/fatal.nim(53) sysFatal

    Unhandled exception: index 1 not in 0 .. 0 [IndexDefect]

This last exception was using:

  test "compute layout with no explicit lines":
    var gt = newGridTemplate()
    var nodes = newSeq[GridNode](2)

    var parent = GridNode()
    parent.box = uiBox(0, 0, 100.0, 100.0)

    var itema = newGridItem()
    nodes[0] = GridNode(id: "a", gridItem: itema)
    var iteme = newGridItem()
    nodes[1] = GridNode(id: "e", gridItem: iteme)
    gt.computeNodeLayout(parent, nodes)

I know you are still working on this so apologies if this is known and just something in progress still. It looks like apart from not creating initial lines that it also is not adding new lines when needed.

I'm assuming that is because of the defaults in newGridTemplate of

  result.autos[dcol] = csFixed(0)
  result.autos[drow] = csFixed(0)

so is that just the expected behavior?

Thanks, this is great! It should implicitly create the rows or columns according to the spec. There's unit tests for auto-insert or auto-flow but not together. My guess is this is what's happening when trying to do both.

Could you make a PR to add this test case? I'll definitely take a look at this, but its helpful to have test cases.

Also, I wasn't sure in the spec if it should create rows and columns, or just in the direction? There was some details about needing to set auto-flow direction.

At least it'd be nice to have explicit errors regarding the minimum settings needed. There's an example that works here as well:

gridTemplate.computeNodeLayout(parent, nodes)

Just fixed this (finally). Any implicit lines should be created now. They should also be create whether it's by a user setting a child grid beyond the grid template, or with unassigned children.

Also, it now returns the size of the "expanded box" when you call computeNodeLayout so you can decide to resize your parent box or not.