void popup_text_width_to_string(ObPopup *self, gchar *text) { if (text[0] != '\0') { self->a_text->texture[0].data.text.string = text; self->textw = RrMinWidth(self->a_text); } else self->textw = 0; }
static gint theme_label_width(RrTheme *theme, gboolean active) { gint w, h; RrAppearance *label; if (active) { label = theme->a_focused_label; label->texture[0].data.text.string = "Active"; } else { label = theme->a_unfocused_label; label->texture[0].data.text.string = "Inactive"; } return RrMinWidth(label); }
void menu_frame_render(ObMenuFrame *self) { gint w = 0, h = 0; gint tw, th; /* temps */ GList *it; gboolean has_icon = FALSE; ObMenu *sub; ObMenuEntryFrame *e; /* find text dimensions */ STRUT_SET(self->item_margin, 0, 0, 0, 0); if (self->entries) { gint l, t, r, b; e = self->entries->data; ob_rr_theme->a_menu_text_normal->texture[0].data.text.string = ""; tw = RrMinWidth(ob_rr_theme->a_menu_text_normal); tw += 2*PADDING; th = ITEM_HEIGHT; RrMargins(ob_rr_theme->a_menu_normal, &l, &t, &r, &b); STRUT_SET(self->item_margin, MAX(self->item_margin.left, l), MAX(self->item_margin.top, t), MAX(self->item_margin.right, r), MAX(self->item_margin.bottom, b)); RrMargins(ob_rr_theme->a_menu_selected, &l, &t, &r, &b); STRUT_SET(self->item_margin, MAX(self->item_margin.left, l), MAX(self->item_margin.top, t), MAX(self->item_margin.right, r), MAX(self->item_margin.bottom, b)); RrMargins(ob_rr_theme->a_menu_disabled, &l, &t, &r, &b); STRUT_SET(self->item_margin, MAX(self->item_margin.left, l), MAX(self->item_margin.top, t), MAX(self->item_margin.right, r), MAX(self->item_margin.bottom, b)); RrMargins(ob_rr_theme->a_menu_disabled_selected, &l, &t, &r, &b); STRUT_SET(self->item_margin, MAX(self->item_margin.left, l), MAX(self->item_margin.top, t), MAX(self->item_margin.right, r), MAX(self->item_margin.bottom, b)); } /* render the entries */ for (it = self->entries; it; it = g_list_next(it)) { RrAppearance *text_a; e = it->data; /* if the first entry is a labeled separator, then make its border overlap with the menu's outside border */ if (it == self->entries && e->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR && e->entry->data.separator.label) { h -= ob_rr_theme->mbwidth; } if (e->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR && e->entry->data.separator.label) { e->border = ob_rr_theme->mbwidth; } RECT_SET_POINT(e->area, 0, h+e->border); XMoveWindow(obt_display, e->window, e->area.x-e->border, e->area.y-e->border); XSetWindowBorderWidth(obt_display, e->window, e->border); XSetWindowBorder(obt_display, e->window, RrColorPixel(ob_rr_theme->menu_border_color)); text_a = (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL && !e->entry->data.normal.enabled ? /* disabled */ (e == self->selected ? ob_rr_theme->a_menu_text_disabled_selected : ob_rr_theme->a_menu_text_disabled) : /* enabled */ (e == self->selected ? ob_rr_theme->a_menu_text_selected : ob_rr_theme->a_menu_text_normal)); switch (e->entry->type) { case OB_MENU_ENTRY_TYPE_NORMAL: text_a->texture[0].data.text.string = e->entry->data.normal.label; tw = RrMinWidth(text_a); tw = MIN(tw, MAX_MENU_WIDTH); th = ob_rr_theme->menu_font_height; if (e->entry->data.normal.icon || e->entry->data.normal.mask) has_icon = TRUE; break; case OB_MENU_ENTRY_TYPE_SUBMENU: sub = e->entry->data.submenu.submenu; text_a->texture[0].data.text.string = sub ? sub->title : ""; tw = RrMinWidth(text_a); tw = MIN(tw, MAX_MENU_WIDTH); th = ob_rr_theme->menu_font_height; if (e->entry->data.normal.icon || e->entry->data.normal.mask) has_icon = TRUE; tw += ITEM_HEIGHT - PADDING; break; case OB_MENU_ENTRY_TYPE_SEPARATOR: if (e->entry->data.separator.label != NULL) { ob_rr_theme->a_menu_text_title->texture[0].data.text.string = e->entry->data.separator.label; tw = RrMinWidth(ob_rr_theme->a_menu_text_title) + 2*ob_rr_theme->paddingx; tw = MIN(tw, MAX_MENU_WIDTH); th = ob_rr_theme->menu_title_height + (ob_rr_theme->mbwidth - PADDING) *2; } else { tw = 0; th = ob_rr_theme->menu_sep_width + 2*ob_rr_theme->menu_sep_paddingy - 2*PADDING; } break; default: g_assert_not_reached(); } tw += 2*PADDING; th += 2*PADDING; w = MAX(w, tw); h += th; } /* if the last entry is a labeled separator, then make its border overlap with the menu's outside border */ it = g_list_last(self->entries); e = it ? it->data : NULL; if (e && e->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR && e->entry->data.separator.label) { h -= ob_rr_theme->mbwidth; } self->text_x = PADDING; self->text_w = w; if (self->entries) { if (has_icon) { w += ITEM_HEIGHT + PADDING; self->text_x += ITEM_HEIGHT + PADDING; } } if (!w) w = 10; if (!h) h = 3; XResizeWindow(obt_display, self->window, w, h); self->inner_w = w; RrPaint(self->a_items, self->window, w, h); for (it = self->entries; it; it = g_list_next(it)) menu_entry_frame_render(it->data); w += ob_rr_theme->mbwidth * 2; h += ob_rr_theme->mbwidth * 2; RECT_SET_SIZE(self->area, w, h); XFlush(obt_display); }