Mercurial > projects > mde
comparison mde/gui/widget/layout.d @ 130:c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Ifaces.IParentWidget.SIZABILITY controlling parent sizability.
TextWidget no longer vertically resizable (since multi-line editing is not supported).
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 17 Jan 2009 16:11:26 +0000 |
parents | ad91de8867a0 |
children | 9cff74f68b84 |
comparison
equal
deleted
inserted
replaced
129:ad91de8867a0 | 130:c5c38eaadb64 |
---|---|
348 } | 348 } |
349 } | 349 } |
350 | 350 |
351 // Find which cols/rows are resizable: | 351 // Find which cols/rows are resizable: |
352 // AlignColumns initializes sizable, and sets first and last sizables. | 352 // AlignColumns initializes sizable, and sets first and last sizables. |
353 static if (!(SIZABILITY & SIZABILITY_ENUM.SUBWIDGETS)) return; | |
353 forCols: | 354 forCols: |
354 for (size_t i = 0; i < cols; ++i) { // for each column | 355 for (size_t i = 0; i < cols; ++i) { // for each column |
355 for (size_t j = 0; j < subWidgets.length; j += cols) // for each row | 356 for (size_t j = 0; j < subWidgets.length; j += cols) { // for each row |
356 if (!subWidgets[i+j].isWSizable) // column not resizable | 357 static if (SIZABILITY == SIZABILITY_ENUM.ALL_SUBWIDGETS) { |
357 continue forCols; // continue the outer for loop | 358 if (!subWidgets[i+j].isWSizable) { // column not resizable |
358 | 359 col.sizable[i] = false; |
359 // column is resizable if we get to here | 360 continue forCols; // no point checking more |
360 col.sizable[i] = true; | 361 } |
362 } else { | |
363 if (subWidgets[i+j].isWSizable) { // column is resizable | |
364 col.sizable[i] = true; | |
365 continue forCols; | |
366 } | |
367 } | |
368 } | |
361 } | 369 } |
362 | 370 |
363 forRows: | 371 forRows: |
364 for (size_t i = 0; i < subWidgets.length; i += cols) { // for each row | 372 for (size_t i = 0; i < subWidgets.length; i += cols) { // for each row |
365 for (size_t j = 0; j < cols; ++j) // for each column | 373 for (size_t j = 0; j < cols; ++j) { // for each column |
366 if (!subWidgets[i+j].isHSizable) | 374 static if (SIZABILITY == SIZABILITY_ENUM.ALL_SUBWIDGETS) { |
367 continue forRows; | 375 if (!subWidgets[i+j].isHSizable) { |
368 | 376 row.sizable[i / cols] = false; |
369 row.sizable[i / cols] = true; | 377 continue forRows; |
378 } | |
379 } else { | |
380 if (subWidgets[i+j].isHSizable) { | |
381 row.sizable[i / cols] = true; | |
382 continue forRows; | |
383 } | |
384 } | |
385 } | |
370 } | 386 } |
371 } | 387 } |
372 | 388 |
373 private: | 389 private: |
374 override void setColWidth (size_t i, wdim w, int dir) { | 390 override void setColWidth (size_t i, wdim w, int dir) { |
483 this (size_t columns) { | 499 this (size_t columns) { |
484 if (columns < 1) | 500 if (columns < 1) |
485 throw new GuiException("AlignColumns: created with <1 column (code error)"); | 501 throw new GuiException("AlignColumns: created with <1 column (code error)"); |
486 minWidth.length = columns; | 502 minWidth.length = columns; |
487 sizable.length = columns; | 503 sizable.length = columns; |
504 static if (SIZABILITY & SIZABILITY_ENUM.START_TRUE) | |
505 sizable[] = true; | |
488 cols = columns; | 506 cols = columns; |
489 } | 507 } |
490 | 508 |
491 /** Like IChildWidget's setup; calls sADD delegates. */ | 509 /** Like IChildWidget's setup; calls sADD delegates. */ |
492 void setup (uint n, uint flags) { | 510 void setup (uint n, uint flags) { |
502 | 520 |
503 /** Reset all column information (only keep set callbacks). | 521 /** Reset all column information (only keep set callbacks). |
504 * | 522 * |
505 * Widths should be set after calling, as on creation. */ | 523 * Widths should be set after calling, as on creation. */ |
506 void reset (size_t columns) { | 524 void reset (size_t columns) { |
525 assert (columns == cols, "no support for changing number of columns for now"); | |
507 minWidth[] = 0; | 526 minWidth[] = 0; |
508 sizable[] = false; | 527 static if (SIZABILITY & SIZABILITY_ENUM.START_TRUE) |
528 sizable[] = true; | |
529 else | |
530 sizable[] = false; | |
509 firstSizable = -1; | 531 firstSizable = -1; |
510 lastSizable = -1; | 532 lastSizable = -1; |
511 } | 533 } |
512 | 534 |
513 /** Add num "rows" to the aligner. They start at the returned index r, thus the values in | 535 /** Add num "rows" to the aligner. They start at the returned index r, thus the values in |
827 static HashMap!(widgetID,AlignColumns) instances; | 849 static HashMap!(widgetID,AlignColumns) instances; |
828 static this () { | 850 static this () { |
829 instances = new HashMap!(widgetID,AlignColumns); | 851 instances = new HashMap!(widgetID,AlignColumns); |
830 } | 852 } |
831 | 853 |
854 alias IChildWidget.SIZABILITY SIZABILITY; | |
855 alias IChildWidget.SIZABILITY_ENUM SIZABILITY_ENUM; | |
856 | |
832 debug invariant() | 857 debug invariant() |
833 { | 858 { |
834 if (setupWidths) { | 859 if (setupWidths) { |
835 assert (width.length == cols, "invariant: bad width length"); | 860 assert (width.length == cols, "invariant: bad width length"); |
836 wdim x = 0; | 861 wdim x = 0; |