Sublime Forum

set_layout reference

#1

I couldnt find any offical (or unofficial reference) on the set_layout method, so after a bit of experimentation I ended up knocking up this quick reference diagram.
Maybe it will be useful to someone in the future.

The diagram below translates to this code

        self.window.set_layout({
            "cols": [0.0, 0.5, 1.0],
            "rows": [0.0, 0.25, 0.75, 1.0],
            "cells": [0, 0, 1, 2], [1, 0, 2, 1], [0, 2, 1, 3], [1, 1, 2, 3]]
            })

cols is an array of values between 0 and 1 that represent the proportional position of each column break

rows is the same as cols

cells is an array of arrays, each inner array contains [x1,y1,x2,y2] coordinates of the cell

It is important to note that we are defining 3 rows (by specifying 4 breaks). Even though we only want 4 cells total, we require the cells to be different heights

[code] 0.0 0.5 1.0
±------------------------------>;±--------------------------->

         0,0                            1,0                             2,0
  0.0+    +-------------------------------+-----------------------------+
     |    |                               |                             |
     |    |                               |                             |
     |    |                               |                             |
     |    |                               |                             |
     |    |                               |                             |
     |    |                               |                             |
     |    |                               |                             |
     v    |                              1,1                           2,1
 0.25+    |                               +-----------------------------+
     |    |                               |                             |
     |    |                               |                             |
     |    |                               |                             |
     |    |                               |                             |
     |    |                               |                             |
     |    |                               |                             |
     |    |                               |                             |
     |  0,2                              1,2                            |
     v    +-------------------------------+                             |
 0.75+    |                               |                             |
     |    |                               |                             |
     |    |                               |                             |
     |   0,3                             1,3                           2,3
  1.0v    +-------------------------------+-----------------------------+

[/code]

asciiflow.com/#7061136993147687848

4 Likes

Sublime split layout to 3 panel
SublimeGDB: layout question
#2

Thanks dude! I have used the API before, and forgot to take notes one it. Hopefully John can add this to his API docs!

0 Likes

#3

https://tutsplus.com/lesson/configuring-and-mastering-split-windows/

0 Likes

#4

Origami uses set_layout a lot, if it’s helpful to look at example code:
github.com/SublimeText/Origami

1 Like

#5

I found this post useful however not sure how to add some other useful stuff without necro-ing. Feel free to tell me off, more usefully if you can tell me how to add useful info without necro-ing that Would be useful ! :crazy_face:.
If you don’t want to install origami, here’s some examples for four or more panes/groups so you can see the pattern

	{
		"keys": ["ctrl+space","ctrl+4"],
		"command": "set_layout",
		"args":
		{
			"cols": [0.0, 0.25, 0.5, 0.75, 1.0],
			"rows": [0.0, 1.0],
			"cells": [[0, 0, 1, 1], [1, 0, 2, 1], [2, 0, 3, 1], [3, 0, 4, 1]]
		}
	},
	{
		"keys": ["ctrl+space","ctrl+5"],
		"command": "set_layout",
		"args":
		{
			"cols": [0.0, 0.2, 0.4, 0.6, 0.8, 1],
			"rows": [0.0, 1.0],
// 2nd and 4th are y1 & y2 so 0 an 1 for a column then x1 is the preceding x2
// (1st and 3rd)
			"cells":
			[
				[0, 0, 1, 1], [1, 0, 2, 1], [2, 0, 3, 1], [3, 0, 4, 1], [4, 0, 5, 1]
			]
		}
	},
	{
		"keys": ["ctrl+space","ctrl+6"],
		"command": "set_layout",
		"args":
		{
			"cols": [0.0, 0.16, 0.33, 0.49, 0.66, 0.83, 1],
			"rows": [0.0, 1.0],
// 2nd and 4th are y1 & y2 so 0 an 1 for a column then x1 is the preceding x2
// (1st and 3rd)
			"cells":
			[
				[0, 0, 1, 1], [1, 0, 2, 1], [2, 0, 3, 1], [3, 0, 4, 1], [4, 0, 5, 1], [5, 0, 6, 1]
			]
		}
	},

I’m using ctrl+space","ctrl+NUMBER_OF_PANES as the key binding.
This may also be handy (thanks to @OdatNurd) :

	"keys": ["shift+alt+m","shift+alt+c"],
	    "command": "set_max_columns",
	    "args": {"columns": 10}
	},

:unicorn: :skull_and_crossbones:

0 Likes