NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
reflow.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stddef.h>
31#include "mutt/lib.h"
32#include "reflow.h"
33#include "mutt_window.h"
34
39static void window_reflow_horiz(struct MuttWindow *win)
40{
41 if (!win)
42 return;
43
44 int max_count = 0;
45 int space = win->state.cols;
46
47 // Pass one - minimal allocation
48 struct MuttWindow **wp = NULL;
49 ARRAY_FOREACH(wp, &win->children)
50 {
51 if (!(*wp)->state.visible)
52 continue;
53
54 switch ((*wp)->size)
55 {
57 {
58 const int avail = MIN(space, (*wp)->req_cols);
59 (*wp)->state.cols = avail;
60 (*wp)->state.rows = win->state.rows;
61 space -= avail;
62 break;
63 }
65 {
66 (*wp)->state.cols = 1;
67 (*wp)->state.rows = win->state.rows;
68 max_count++;
69 space -= 1;
70 break;
71 }
73 {
74 (*wp)->state.rows = win->state.rows;
75 (*wp)->state.cols = win->state.cols;
76 (*wp)->state.row_offset = win->state.row_offset;
77 (*wp)->state.col_offset = win->state.col_offset;
78 window_reflow(*wp);
79 space -= (*wp)->state.cols;
80 break;
81 }
82 }
83 }
84
85 // Pass two - sharing
86 if ((max_count > 0) && (space > 0))
87 {
88 int alloc = (space + max_count - 1) / max_count;
89 ARRAY_FOREACH(wp, &win->children)
90 {
91 if (space == 0)
92 break;
93 if (!(*wp)->state.visible)
94 continue;
95 if ((*wp)->size != MUTT_WIN_SIZE_MAXIMISE)
96 continue;
97
98 alloc = MIN(space, alloc);
99 (*wp)->state.cols += alloc;
100 space -= alloc;
101 }
102 }
103
104 // Pass three - position and recursion
105 int col = win->state.col_offset;
106 ARRAY_FOREACH(wp, &win->children)
107 {
108 if (!(*wp)->state.visible)
109 continue;
110
111 (*wp)->state.col_offset = col;
112 (*wp)->state.row_offset = win->state.row_offset;
113 col += (*wp)->state.cols;
114
115 window_reflow(*wp);
116 }
117
118 if ((space > 0) && (win->size == MUTT_WIN_SIZE_MINIMISE))
119 {
120 win->state.cols -= space;
121 }
122}
123
128static void window_reflow_vert(struct MuttWindow *win)
129{
130 if (!win)
131 return;
132
133 int max_count = 0;
134 int space = win->state.rows;
135
136 // Pass one - minimal allocation
137 struct MuttWindow **wp = NULL;
138 ARRAY_FOREACH(wp, &win->children)
139 {
140 if (!(*wp)->state.visible)
141 continue;
142
143 switch ((*wp)->size)
144 {
146 {
147 const int avail = MIN(space, (*wp)->req_rows);
148 (*wp)->state.rows = avail;
149 (*wp)->state.cols = win->state.cols;
150 space -= avail;
151 break;
152 }
154 {
155 (*wp)->state.rows = 1;
156 (*wp)->state.cols = win->state.cols;
157 max_count++;
158 space -= 1;
159 break;
160 }
162 {
163 (*wp)->state.rows = win->state.rows;
164 (*wp)->state.cols = win->state.cols;
165 (*wp)->state.row_offset = win->state.row_offset;
166 (*wp)->state.col_offset = win->state.col_offset;
167 window_reflow(*wp);
168 space -= (*wp)->state.rows;
169 break;
170 }
171 }
172 }
173
174 // Pass two - sharing
175 if ((max_count > 0) && (space > 0))
176 {
177 int alloc = (space + max_count - 1) / max_count;
178 ARRAY_FOREACH(wp, &win->children)
179 {
180 if (space == 0)
181 break;
182 if (!(*wp)->state.visible)
183 continue;
184 if ((*wp)->size != MUTT_WIN_SIZE_MAXIMISE)
185 continue;
186
187 alloc = MIN(space, alloc);
188 (*wp)->state.rows += alloc;
189 space -= alloc;
190 }
191 }
192
193 // Pass three - position and recursion
194 int row = win->state.row_offset;
195 ARRAY_FOREACH(wp, &win->children)
196 {
197 if (!(*wp)->state.visible)
198 continue;
199
200 (*wp)->state.row_offset = row;
201 (*wp)->state.col_offset = win->state.col_offset;
202 row += (*wp)->state.rows;
203
204 window_reflow(*wp);
205 }
206
207 if ((space > 0) && (win->size == MUTT_WIN_SIZE_MINIMISE))
208 {
209 win->state.rows -= space;
210 }
211}
212
220void window_reflow(struct MuttWindow *win)
221{
222 if (!win)
223 return;
226 else
228}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define MIN(a, b)
Return the minimum of two values.
Definition memory.h:40
Convenience wrapper for the library headers.
Window management.
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition mutt_window.h:38
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition mutt_window.h:47
@ MUTT_WIN_SIZE_MINIMISE
Window size depends on its children.
Definition mutt_window.h:49
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition mutt_window.h:48
static void window_reflow_vert(struct MuttWindow *win)
Reflow Windows using all the available vertical space.
Definition reflow.c:128
static void window_reflow_horiz(struct MuttWindow *win)
Reflow Windows using all the available horizontal space.
Definition reflow.c:39
void window_reflow(struct MuttWindow *win)
Reflow Windows.
Definition reflow.c:220
Window management.
struct MuttWindowArray children
Children Windows.
struct WindowState state
Current state of the Window.
enum MuttWindowOrientation orient
Which direction the Window will expand.
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition mutt_window.h:60
short row_offset
Absolute on-screen row.
Definition mutt_window.h:63
short col_offset
Absolute on-screen column.
Definition mutt_window.h:62
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition mutt_window.h:61