shithub: neindaw

Download patch

ref: 6a58ae5ab75215d4f5a9ceda07bb02ca8f4f67d6
parent: e63eebc7d9edd09fddd84cf1b59ecbf4ad5d980b
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Jan 16 06:56:14 EST 2020

automatically resize and align windows on start

--- a/cfg/cfg.c
+++ b/cfg/cfg.c
@@ -46,6 +46,7 @@
 static char **dirs;
 static UI **top;
 static int numtop;
+static int winopt;
 
 static int
 readmeta(UI *ui, char *path)
@@ -170,33 +171,16 @@
 }
 
 static void
-printui(UI *ui, int indent)
-{
-	static char *tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
-	int i;
-
-	print("%.*sui (%s)\n", indent, tabs, ui->path);
-	if (ui->group != nil)
-		print("%.*sgroup: %s\n", indent+1, tabs, ui->group);
-	if (ui->name != nil)
-		print("%.*sname: %s\n", indent+1, tabs, ui->name);
-	print("%.*slabel: %s\n", indent+1, tabs, ui->label);
-	print("%.*sindex: %d\n", indent+1, tabs, ui->index);
-	if (ui->type >= 0)
-		print("%.*stype: %s\n", indent+1, tabs, uitypenames[ui->type]);
-	for (i = 0; i < ui->numchild; i++)
-		printui(ui->child[i], indent+1);
-}
-
-static void
 process_ui(UI *w)
 {
 	UI *c, *slider;
 	double v;
 	mu_Id id;
-	int i, state, n, widths[32], maxwidth, x;
+	int i, state, n, widths[32], maxwidth, x, dt;
 	char tmp[256];
 
+	dt = stringwidth(mu_style.font, ": ");
+
 	slider = nil;
 	for (i = 0; i < w->numchild; i++) {
 		c = w->child[i];
@@ -242,7 +226,7 @@
 					if ((x = stringwidth(mu_style.font, w->child[n]->label)) > maxwidth)
 						maxwidth = x;
 				}
-				widths[0] = maxwidth + stringwidth(mu_style.font, ": ");
+				widths[0] = maxwidth + dt;
 				widths[1] = -1;
 				mu_layout_row(2, widths, 0);
 			}
@@ -271,17 +255,28 @@
 static void
 process_frame(void)
 {
-	UI *ui, *ch;
+	UI *prev, *ui, *ch;
 	char tmp[128], *s;
 	int i, j;
 
 	mu_begin();
-	for (i = 0; i < numtop; i++) {
+	for (i = 0, prev = nil; i < numtop; i++) {
 		ui = top[i];
+		if ((ui->flags & Hasclone) == 0) {
+			if (mu_begin_window_ex(ui->win, ui->label, winopt)) {
+				if (prev != nil && (winopt & MU_OPT_AUTOSIZE))
+					ui->win->rect.x = prev->win->rect.x + prev->win->rect.w;
+				prev = ui;
+				process_ui(ui);
+				mu_end_window();
+				continue;
+			}
+		}
+
 		for (j = 0; j < ui->numchild; j++) {
+			s = ui->child[j]->path;
 			ch = ui->child[j]->child[0];
 
-			s = ui->child[j]->path;
 			/* remove the annoying "./" if current dir was used */
 			/* FIXME perhaps a prefix common for all dirs should be removed too */
 			if (s[0] == '.' && s[1] == '/')
@@ -288,10 +283,13 @@
 				s += 2;
 			snprint(tmp, sizeof(tmp), "[%s] %s", s, ch->label);
 
-			if (mu_begin_window(ch->win, tmp)) {
+			if (mu_begin_window_ex(ch->win, tmp, winopt)) {
+				if (prev != nil && (winopt & MU_OPT_AUTOSIZE))
+					ch->win->rect.x = prev->win->rect.x + prev->win->rect.w;
 				process_ui(ch);
 				mu_end_window();
 			}
+			prev = ch;
 		}
 	}
 	mu_end();
@@ -307,6 +305,13 @@
 	top = realloc(top, (numtop+1) * sizeof(*top));
 	ui = newui(path);
 	top[numtop++] = ui;
+	if ((ui->flags & Hasclone) == 0) {
+		ui->win = w = calloc(1, sizeof(*w));
+		mu_init_window(w, 0);
+		w->rect = mu_rect(10 + 210, 10, 200, 400);
+		return;
+	}
+
 	for (i = 0; i < ui->numchild; i++) {
 		if (ui->child[i]->numchild < 1)
 			continue;
@@ -373,7 +378,12 @@
 	mu_style.font = font;
 	mu_style.size.y = font->height;
 	mu_style.title_height = mu_style.size.y + 6;
-	process_frame();
+
+	winopt = MU_OPT_AUTOSIZE_H;
+	/* FIXME that's how much it takes for the sizing to kick in :( */
+	for (i = 0; i < 3; i++)
+		process_frame();
+	winopt &= ~MU_OPT_AUTOSIZE_H;
 
 	oldbuttons = 0;
 	for (;;) {
--- a/kick_drum.c
+++ b/kick_drum.c
@@ -1,6 +1,6 @@
 /* ------------------------------------------------------------
 name: "Kick Drum"
-Code generated with Faust 2.20.2 (https://faust.grame.fr)
+Code generated with Faust 2.21.5 (https://faust.grame.fr)
 Compilation options: -lang c -scal -ftz 0
 ------------------------------------------------------------ */
 
--- a/math.h
+++ b/math.h
@@ -1,8 +1,8 @@
-#define sinf sin
 #define cosf cos
-#define floorf floor
 #define expf exp
+#define fabsf fabs
+#define floorf floor
+#define powf pow
+#define sinf sin
 #define sqrtf sqrt
 #define tanf tan
-#define powf pow
-#define fabsf fabs