ui/motif/Grid.c

changeset 901
884d70e847a3
parent 900
6e1485d5451a
child 913
3012ec57d84a
equal deleted inserted replaced
900:6e1485d5451a 901:884d70e847a3
73 mywidget.rowspacing), 73 mywidget.rowspacing),
74 XmRImmediate, 74 XmRImmediate,
75 (XtPointer) 0 75 (XtPointer) 0
76 }, 76 },
77 { 77 {
78 gridMargin, 78 gridPaddingLeft,
79 gridMargin, 79 gridPaddingLeft,
80 XmRDimension, 80 XmRDimension,
81 sizeof (Dimension), 81 sizeof (Dimension),
82 XtOffsetOf( GridRec, 82 XtOffsetOf( GridRec,
83 mywidget.margin), 83 mywidget.padding_left),
84 XmRImmediate,
85 (XtPointer) 0
86 },
87 {
88 gridPaddingRight,
89 gridPaddingRight,
90 XmRDimension,
91 sizeof (Dimension),
92 XtOffsetOf( GridRec,
93 mywidget.padding_right),
94 XmRImmediate,
95 (XtPointer) 0
96 },
97 {
98 gridPaddingTop,
99 gridPaddingTop,
100 XmRDimension,
101 sizeof (Dimension),
102 XtOffsetOf( GridRec,
103 mywidget.padding_top),
104 XmRImmediate,
105 (XtPointer) 0
106 },
107 {
108 gridPaddingBottom,
109 gridPaddingBottom,
110 XmRDimension,
111 sizeof (Dimension),
112 XtOffsetOf( GridRec,
113 mywidget.padding_bottom),
84 XmRImmediate, 114 XmRImmediate,
85 (XtPointer) 0 115 (XtPointer) 0
86 } 116 }
87 }; 117 };
88 118
404 int nrows = w->mywidget.max_row+1; 434 int nrows = w->mywidget.max_row+1;
405 GridDef *cols = calloc(ncols, sizeof(GridDef)); 435 GridDef *cols = calloc(ncols, sizeof(GridDef));
406 GridDef *rows = calloc(nrows, sizeof(GridDef)); 436 GridDef *rows = calloc(nrows, sizeof(GridDef));
407 int num_cols_expanding = 0; 437 int num_cols_expanding = 0;
408 int num_rows_expanding = 0; 438 int num_rows_expanding = 0;
409 int req_width = 0; 439 int req_width = w->mywidget.padding_left + w->mywidget.padding_right;
410 int req_height = 0; 440 int req_height = w->mywidget.padding_top + w->mywidget.padding_bottom;
411 441
412 //printf("container width: %d\n", (int)w->core.width); 442 //printf("container width: %d\n", (int)w->core.width);
413 443
414 // calculate the minimum size requirements for all columns and rows 444 // calculate the minimum size requirements for all columns and rows
415 // we need to run this 2 times: for widgets without colspan/rowspan first 445 // we need to run this 2 times: for widgets without colspan/rowspan first
426 constraints->grid.pref_height = child->core.height; 456 constraints->grid.pref_height = child->core.height;
427 } 457 }
428 if(constraints->grid.pref_width < constraints->grid.min_width) { 458 if(constraints->grid.pref_width < constraints->grid.min_width) {
429 constraints->grid.pref_width = constraints->grid.min_width; 459 constraints->grid.pref_width = constraints->grid.min_width;
430 } 460 }
461 int elm_width = constraints->grid.pref_width + constraints->grid.margin_left + constraints->grid.margin_right;
462 int elm_height = constraints->grid.pref_height + constraints->grid.margin_top + constraints->grid.margin_bottom;
431 463
432 if(constraints->grid.colspan > span_max || constraints->grid.rowspan > span_max) { 464 if(constraints->grid.colspan > span_max || constraints->grid.rowspan > span_max) {
433 continue; 465 continue;
434 } 466 }
435 467
487 for(int s=x+1;s<ncols;s++) { 519 for(int s=x+1;s<ncols;s++) {
488 last_col = &cols[s]; 520 last_col = &cols[s];
489 span_width = last_col->size; 521 span_width = last_col->size;
490 522
491 } 523 }
492 int diff = constraints->grid.pref_width - span_width; 524 int diff = elm_width - span_width;
493 if(diff > 0) { 525 if(diff > 0) {
494 last_col->size += diff; 526 last_col->size += diff;
495 } 527 }
496 } else if(constraints->grid.pref_width > col->size) { 528 } else if(elm_width > col->size) {
497 col->size = constraints->grid.pref_width; 529 col->size = elm_width;
498 } 530 }
499 // row size 531 // row size
500 if(constraints->grid.rowspan > 1) { 532 if(constraints->grid.rowspan > 1) {
501 Dimension span_height = row->size; 533 Dimension span_height = row->size;
502 GridDef *last_row = row; 534 GridDef *last_row = row;
503 for(int s=x+1;s<nrows;s++) { 535 for(int s=x+1;s<nrows;s++) {
504 last_row = &rows[s]; 536 last_row = &rows[s];
505 span_height = last_row->size; 537 span_height = last_row->size;
506 538
507 } 539 }
508 int diff = constraints->grid.pref_height - span_height; 540 int diff = elm_height - span_height;
509 if(diff > 0) { 541 if(diff > 0) {
510 last_row->size += diff; 542 last_row->size += diff;
511 } 543 }
512 } else if(constraints->grid.pref_height > row->size) { 544 } else if(elm_height > row->size) {
513 row->size = constraints->grid.pref_height; 545 row->size = elm_height;
514 } 546 }
515 } 547 }
516 span_max = 50000; // not sure if this is unreasonable low or high 548 span_max = 50000; // not sure if this is unreasonable low or high
517 } 549 }
518 550
572 int hexpand2 = 0; 604 int hexpand2 = 0;
573 if(width_diff > 0 && num_cols_expanding > 0) { 605 if(width_diff > 0 && num_cols_expanding > 0) {
574 hexpand = width_diff / num_cols_expanding; 606 hexpand = width_diff / num_cols_expanding;
575 hexpand2 = width_diff-hexpand*num_cols_expanding; 607 hexpand2 = width_diff-hexpand*num_cols_expanding;
576 } 608 }
577 int x = 0; 609 int x = w->mywidget.padding_left;
578 for(int i=0;i<ncols;i++) { 610 for(int i=0;i<ncols;i++) {
579 cols[i].pos = x; 611 cols[i].pos = x;
580 if(cols[i].expand) { 612 if(cols[i].expand) {
581 cols[i].size += hexpand + hexpand2; 613 cols[i].size += hexpand + hexpand2;
582 } 614 }
590 int vexpand2 = 0; 622 int vexpand2 = 0;
591 if(height_diff > 0 && num_rows_expanding > 0) { 623 if(height_diff > 0 && num_rows_expanding > 0) {
592 vexpand = height_diff / num_rows_expanding; 624 vexpand = height_diff / num_rows_expanding;
593 vexpand2 = height_diff-vexpand*num_rows_expanding; 625 vexpand2 = height_diff-vexpand*num_rows_expanding;
594 } 626 }
595 int y = 0; 627 int y = w->mywidget.padding_bottom;
596 for(int i=0;i<nrows;i++) { 628 for(int i=0;i<nrows;i++) {
597 rows[i].pos = y; 629 rows[i].pos = y;
598 if(rows[i].expand) { 630 if(rows[i].expand) {
599 rows[i].size += vexpand + vexpand2; 631 rows[i].size += vexpand + vexpand2;
600 } 632 }
606 for(int i=0;i<w->composite.num_children;i++) { 638 for(int i=0;i<w->composite.num_children;i++) {
607 Widget child = w->composite.children[i]; 639 Widget child = w->composite.children[i];
608 GridConstraintRec *constraints = child->core.constraints; 640 GridConstraintRec *constraints = child->core.constraints;
609 GridDef c = cols[constraints->grid.x]; 641 GridDef c = cols[constraints->grid.x];
610 GridDef r = rows[constraints->grid.y]; 642 GridDef r = rows[constraints->grid.y];
611 int x = c.pos; 643 int x = c.pos + constraints->grid.margin_left;
612 int y = r.pos; 644 int y = r.pos + constraints->grid.margin_top;
613 int width = constraints->grid.pref_width; 645 int width = constraints->grid.pref_width;
614 int height = constraints->grid.pref_height; 646 int height = constraints->grid.pref_height;
615 if(constraints->grid.hfill) { 647 if(constraints->grid.hfill) {
616 if(constraints->grid.colspan > 1) { 648 if(constraints->grid.colspan > 1) {
617 Dimension cwidth = 0; 649 Dimension cwidth = 0;

mercurial