aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/Split.hx
blob: 102fbc6cc017606a6ec4406035fc3ae1692a0541 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package client;

import client.Main.getEl;
import js.Browser.document;

@:native("Split")
private extern class JsSplit {
	function new(options:Any):Void;
	function destroy(?immediate:Bool = true):Void;
}

class Split {
	static inline var CHAT_MIN_SIZE = 200;

	final settings:ClientSettings;
	final split:JsSplit;

	public function new(settings:ClientSettings) {
		this.settings = settings;
		split = new JsSplit({
			columnGutters: [{
				element: getEl(".gutter"),
				track: 1,
			}],
			minSize: CHAT_MIN_SIZE,
			snapOffset: 0,
			onDragEnd: saveSize
		});
	}

	public function setSize(chatSize:Float):Void {
		if (chatSize < CHAT_MIN_SIZE) return;
		final sizes = document.body.style.gridTemplateColumns.split(" ");
		final chatId = settings.isSwapped ? 0 : sizes.length - 1;
		sizes[chatId] = '${chatSize}px';
		document.body.style.gridTemplateColumns = sizes.join(" ");
	}

	function saveSize():Void {
		final sizes = document.body.style.gridTemplateColumns.split(" ");
		if (settings.isSwapped) sizes.reverse();
		settings.chatSize = Std.parseFloat(sizes[sizes.length - 1]);
		Settings.write(settings);
	}

	public function destroy():Void {
		split.destroy();
	}
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage