static void LayoutCell(txt_table_t *table, int x, int y, int draw_x, int draw_y) { txt_widget_t *widget; int col_width; widget = table->widgets[y * table->columns + x]; col_width = widget->w; // Adjust x position based on alignment property switch (widget->align) { case TXT_HORIZ_LEFT: widget->w = col_width; break; case TXT_HORIZ_CENTER: TXT_CalcWidgetSize(widget); // Separators are always drawn left-aligned. if (widget->widget_class != &txt_separator_class) { draw_x += (col_width - widget->w) / 2; } break; case TXT_HORIZ_RIGHT: TXT_CalcWidgetSize(widget); if (widget->widget_class != &txt_separator_class) { draw_x += col_width - widget->w; } break; } // Set the position for this widget widget->x = draw_x; widget->y = draw_y; // Recursively lay out any widgets contained in the widget TXT_LayoutWidget(widget); }
static void TXT_ScrollPaneLayout(TXT_UNCAST_ARG(scrollpane)) { TXT_CAST_ARG(txt_scrollpane_t, scrollpane); SanityCheckScrollbars(scrollpane); // The child widget takes the same position as the scroll pane // itself, but is offset by the scroll position. if (scrollpane->child != NULL) { scrollpane->child->x = scrollpane->widget.x - scrollpane->x; scrollpane->child->y = scrollpane->widget.y - scrollpane->y; TXT_LayoutWidget(scrollpane->child); } }
void TXT_LayoutWindow(txt_window_t *window) { txt_widget_t *widgets = (txt_widget_t *) window; unsigned int widgets_w; unsigned int actionarea_w, actionarea_h; // Calculate size of table TXT_CalcWidgetSize(window); // Widgets area: add one character of padding on each side widgets_w = widgets->w + 2; // Calculate the size of the action area // Make window wide enough to action area CalcActionAreaSize(window, &actionarea_w, &actionarea_h); if (actionarea_w > widgets_w) widgets_w = actionarea_w; // Set the window size based on widgets_w window->window_w = widgets_w + 2; window->window_h = widgets->h + 1; // If the window has a title, add an extra two lines if (window->title != NULL) { window->window_h += 2; } // If the window has an action area, add extra lines if (actionarea_h > 0) { window->window_h += actionarea_h + 1; } // Use the x,y position as the centerpoint and find the location to // draw the window. CalcWindowPosition(window); // Set the table size and position widgets->w = widgets_w - 2; // widgets->h (already set) widgets->x = window->window_x + 2; widgets->y = window->window_y; if (window->title != NULL) { widgets->y += 2; } // Layout the table and action area LayoutActionArea(window); TXT_LayoutWidget(widgets); }