MCPcopy Create free account
hub / github.com/Tablecruncher/tablecruncher / myFlChoice

Method myFlChoice

src/csvapplication.cpp:3059–3157  ·  view source on GitHub ↗

* Generic styled alert method, displays up to three answer buttons. * Button 0 is the highlighted button. Gets returned when pressed Enter. * * @return int -1: ESC pressed, 0,1,2: for the button that was pressed */

Source from the content-addressed store, hash-verified

3057 * @return int -1: ESC pressed, 0,1,2: for the button that was pressed
3058 */
3059int CsvApplication::myFlChoice(std::string title, std::string message, std::vector<std::string> options, int buttonWidth, int windowHeight) {
3060 My_Fl_Small_Window *choiceWin;
3061 Fl_Help_View *messageLabel;
3062 std::vector<My_Fl_Button *> buttons;
3063 Fl_Box *iconBox;
3064 Fl_RGB_Image *symbol;
3065 int optionsSize = options.size();
3066 int ret = -1;
3067
3068 struct My_Fl_Button::buttonColorStruct colorsDefaultButton;
3069 colorsDefaultButton.background = ColorThemes::getColor(app.getTheme(), "button_bg");
3070 colorsDefaultButton.label = ColorThemes::getColor(app.getTheme(), "button_text");
3071 colorsDefaultButton.border = ColorThemes::getColor(app.getTheme(), "button_border");
3072 colorsDefaultButton.windowBg = ColorThemes::getColor(app.getTheme(), "win_bg");
3073 colorsDefaultButton.borderWidth = ColorThemes::getColor(app.getTheme(), "button_border_width");
3074 struct My_Fl_Button::buttonColorStruct colorsHighlightButton;
3075 colorsHighlightButton.background = ColorThemes::getColor(app.getTheme(), "hightlight_button_bg");
3076 colorsHighlightButton.label = ColorThemes::getColor(app.getTheme(), "hightlight_button_text");
3077 colorsHighlightButton.border = ColorThemes::getColor(app.getTheme(), "hightlight_button_border");
3078 colorsHighlightButton.windowBg = ColorThemes::getColor(app.getTheme(), "win_bg");
3079 colorsHighlightButton.borderWidth = ColorThemes::getColor(app.getTheme(), "highlight_button_border_width");
3080
3081 // just use the first three options
3082 if( optionsSize > 3 )
3083 optionsSize = 3;
3084
3085 // buttonData stores which button has been called: initially it gets its own index; when the callback is called,
3086 // it's filled with TCRUNCHER_MYFLCHOICE_MAGICAL, which has to be larger than the largest possible index (2).
3087 int32_t buttonData[3];
3088 buttonData[0] = 0;
3089 buttonData[1] = 1;
3090 buttonData[2] = 2;
3091
3092 // Load icon
3093 if( optionsSize <= 1 )
3094 symbol = xpmResizer(ui_icons::icon_alert, 48);
3095 else
3096 symbol = xpmResizer(ui_icons::icon_question, 48);
3097
3098 choiceWin = new My_Fl_Small_Window(500,windowHeight);
3099 choiceWin->copy_label(title.c_str());
3100 choiceWin->color(ColorThemes::getColor(app.getTheme(), "win_bg"));
3101 choiceWin->callback(myFlChoiceWin_CB);
3102 choiceWin->dataExchange = -1;
3103
3104 iconBox = new Fl_Box(10,20,48,48);
3105 iconBox->image(symbol);
3106
3107 messageLabel = new Fl_Help_View(80,20,400,windowHeight-80);
3108 messageLabel->textsize(14);
3109 messageLabel->textfont(FL_HELVETICA);
3110 messageLabel->textcolor(ColorThemes::getColor(app.getTheme(), "win_text"));
3111 messageLabel->box(FL_FLAT_BOX);
3112 messageLabel->color(ColorThemes::getColor(app.getTheme(), "win_bg"));
3113 messageLabel->value( message.c_str() );
3114
3115 for( int i = 0; i < optionsSize; ++i ) {
3116 int x = 380 - i * (buttonWidth+20); // calculate x pixels of button

Callers

nothing calls this directly

Calls 5

checkFunction · 0.85
getThemeMethod · 0.80
push_backMethod · 0.80
sizeMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected