/* * Item-menu connection make/break functions - menu_items(3X) man page */ static VALUE rbncurs_c_set_menu_items(VALUE rb_menu, VALUE rb_item_array) { long n = rbncurs_array_length(rb_item_array); /* If ncurses does not free memory used by the previous array of strings, */ /* we will have to do it now. */ ITEM **items = ALLOC_N(ITEM*, (n+1)); long i; MENU *menu = NULL; for (i=0; i<n; i++) items[i] = get_item(rb_ary_entry(rb_item_array, i)); items[n] = NULL; menu = get_menu(rb_menu); return INT2NUM(set_menu_items(menu, items)); }
void column_select_update_menu(ui_t *ui) { // Get panel information column_select_info_t *info = column_select_info(ui); ITEM *current = current_item(info->menu); int top_idx = top_row(info->menu); // Remove the menu from the subwindow unpost_menu(info->menu); // Set menu items set_menu_items(info->menu, info->items); // Put the menu agin into its subwindow post_menu(info->menu); // Move until the current position is set set_top_row(info->menu, top_idx); set_current_item(info->menu, current); }
/** * Fills in the text to be displayed in the dialog. * This also updates the scenario/campaign toggle button. * * @param[in] campaign Indicates whether or not the campaign stats are to * be displayed. */ void statistics_dialog::display_stats(bool campaign) { // Record which stats we will display. use_campaign_ = campaign; const statistics::stats & stats = current_stats(); const bool show_this_turn = use_campaign_ || scenario_index_ + 1 == scenarios_.size(); int n, cost; std::vector<std::string> items; // The heading for the menu items: { std::stringstream str; str << HEADING_PREFIX << COLUMN_SEPARATOR << font::BOLD_TEXT << (use_campaign_ ? _("Campaign") : _("Scenario")); items.push_back(str.str()); } // Prepare the menu items { std::stringstream str; n = statistics::sum_str_int_map(stats.recruits); cost = stats.recruit_cost; unit_count_[0] = n; str << _("Recruits") << COLUMN_SEPARATOR << n << COLUMN_SEPARATOR << COLUMN_SEPARATOR << IMAGE_PREFIX << "themes/gold.png" << COLUMN_SEPARATOR << cost; items.push_back(str.str()); } { std::stringstream str; n = statistics::sum_str_int_map(stats.recalls); cost = stats.recall_cost; unit_count_[1] = n; str << _("Recalls") << COLUMN_SEPARATOR << n << COLUMN_SEPARATOR << COLUMN_SEPARATOR << IMAGE_PREFIX << "themes/gold.png" << COLUMN_SEPARATOR << cost; items.push_back(str.str()); } { std::stringstream str; n = statistics::sum_str_int_map(stats.advanced_to); unit_count_[2] = n; str << _("Advancements") << COLUMN_SEPARATOR << n; items.push_back(str.str()); } { std::stringstream str; n = statistics::sum_str_int_map(stats.deaths); unit_count_[3] = n; cost = statistics::sum_cost_str_int_map(stats.deaths); str << _("Losses") << COLUMN_SEPARATOR << n << COLUMN_SEPARATOR << COLUMN_SEPARATOR << IMAGE_PREFIX << "themes/gold.png" << COLUMN_SEPARATOR << cost; items.push_back(str.str()); } { std::stringstream str; n = statistics::sum_str_int_map(stats.killed); unit_count_[4] = n; cost = statistics::sum_cost_str_int_map(stats.killed); str << _("Kills") << COLUMN_SEPARATOR << n << COLUMN_SEPARATOR << COLUMN_SEPARATOR << IMAGE_PREFIX << "themes/gold.png" << COLUMN_SEPARATOR << cost; items.push_back(str.str()); } items.push_back(""); { std::stringstream str; str << font::BOLD_TEXT << _("Damage") << COLUMN_SEPARATOR << _("Overall"); if ( show_this_turn ) { str << COLUMN_SEPARATOR << COLUMN_SEPARATOR << COLUMN_SEPARATOR << _("This Turn"); } items.push_back(str.str()); } make_damage_line(items, _("Inflicted"), stats.damage_inflicted, stats.expected_damage_inflicted, stats.turn_damage_inflicted, stats.turn_expected_damage_inflicted, show_this_turn); make_damage_line(items, _("Taken"), stats.damage_taken, stats.expected_damage_taken, stats.turn_damage_taken, stats.turn_expected_damage_taken, show_this_turn); set_menu_items(items, true); toggle_btn_->set_label(use_campaign_ ? _("Scenario") : _("Campaign")); scene_btn_->enable(!use_campaign_); }
static void cui_boot_editor_on_exit(struct cui *cui, struct pmenu_item *item, struct pb_boot_data *bd) { struct pmenu *menu = cui->main; struct cui_opt_data *cod; int idx, top, rows, cols; static int user_idx = 0; /* Was the edit cancelled? */ if (!bd) { cui_set_current(cui, &cui->main->scr); talloc_free(cui->boot_editor); cui->boot_editor = NULL; return; } /* Is this was a new item, we'll need to update the menu */ if (!item) { int insert_pt; cod = talloc_zero(NULL, struct cui_opt_data); cod->name = talloc_asprintf(cod, _("User item %u"), ++user_idx); item = pmenu_item_create(menu, cod->name); if (!item) { talloc_free(cod); goto out; } item->on_edit = cui_item_edit; item->on_execute = cui_boot; item->data = cod; talloc_steal(item, cod); /* Detach the items array. */ set_menu_items(menu->ncm, NULL); /* Insert new item at insert_pt. */ insert_pt = pmenu_grow(menu, 1); pmenu_item_insert(menu, item, insert_pt); /* Re-attach the items array. */ set_menu_items(menu->ncm, menu->items); /* If our index is above the current top row, align * us to the new top. Otherwise, align us to the new * bottom */ menu_format(cui->main->ncm, &rows, &cols); top = top_row(cui->main->ncm); idx = item_index(item->nci); if (top >= idx) top = idx; else top = idx < rows ? 0 : idx - rows + 1; set_top_row(cui->main->ncm, top); set_current_item(item->pmenu->ncm, item->nci); nc_scr_post(&menu->scr); } else {