| 14 | { |
| 15 | |
| 16 | MessageBox::MessageBox(const UString &title, const UString &text, ButtonOptions buttons, |
| 17 | std::function<void()> callbackYes, std::function<void()> callbackNo, |
| 18 | std::function<void()> callbackCancel) |
| 19 | : Stage(), callbackYes(callbackYes), callbackNo(callbackNo), callbackCancel(callbackCancel) |
| 20 | { |
| 21 | form = mksp<Form>(); |
| 22 | form->Size = {248, 100}; |
| 23 | form->BackgroundColour = {148, 148, 148, 255}; |
| 24 | |
| 25 | const int MARGIN = 8; |
| 26 | const Vec2<int> BUTTON_SIZE = {100, 28}; |
| 27 | const Vec2<int> BUTTON_SIZE_2 = {70, 28}; |
| 28 | |
| 29 | auto lTitle = form->createChild<Label>(to_upper(title), ui().getFont("smalfont")); |
| 30 | lTitle->Size.x = form->Size.x - MARGIN * 2; |
| 31 | lTitle->Size.y = ui().getFont("smalfont")->getFontHeight(); |
| 32 | lTitle->Location = {MARGIN, MARGIN}; |
| 33 | lTitle->TextHAlign = HorizontalAlignment::Centre; |
| 34 | |
| 35 | auto lText = form->createChild<Label>(text, ui().getFont("smalfont")); |
| 36 | lText->Size.x = form->Size.x - MARGIN * 2; |
| 37 | lText->Size.y = ui().getFont("smalfont")->getFontHeight(text, lText->Size.x); |
| 38 | lText->Location = lTitle->Location; |
| 39 | lText->Location.y += lTitle->Size.y + MARGIN * 2; |
| 40 | lText->TextHAlign = HorizontalAlignment::Centre; |
| 41 | |
| 42 | switch (buttons) |
| 43 | { |
| 44 | case ButtonOptions::Ok: |
| 45 | { |
| 46 | auto bOk = form->createChild<TextButton>(tr("OK"), ui().getFont("smallset")); |
| 47 | bOk->Name = "BUTTON_OK"; |
| 48 | bOk->Size = BUTTON_SIZE; |
| 49 | bOk->RenderStyle = TextButton::ButtonRenderStyle::Bevel; |
| 50 | bOk->Location.x = (form->Size.x - bOk->Size.x) / 2; |
| 51 | bOk->Location.y = lText->Location.y + lText->Size.y + MARGIN; |
| 52 | |
| 53 | form->Size.y = bOk->Location.y + bOk->Size.y + MARGIN; |
| 54 | break; |
| 55 | } |
| 56 | case ButtonOptions::YesNo: |
| 57 | { |
| 58 | auto bYes = form->createChild<TextButton>(tr("Yes"), ui().getFont("smallset")); |
| 59 | bYes->Name = "BUTTON_YES"; |
| 60 | bYes->Size = BUTTON_SIZE; |
| 61 | bYes->RenderStyle = TextButton::ButtonRenderStyle::Bevel; |
| 62 | bYes->Location.x = MARGIN; |
| 63 | bYes->Location.y = lText->Location.y + lText->Size.y + MARGIN; |
| 64 | |
| 65 | auto bNo = form->createChild<TextButton>(tr("No"), ui().getFont("smallset")); |
| 66 | bNo->Name = "BUTTON_NO"; |
| 67 | bNo->Size = BUTTON_SIZE; |
| 68 | bNo->RenderStyle = TextButton::ButtonRenderStyle::Bevel; |
| 69 | bNo->Location.x = form->Size.x - bNo->Size.x - MARGIN; |
| 70 | bNo->Location.y = lText->Location.y + lText->Size.y + MARGIN; |
| 71 | |
| 72 | form->Size.y = bYes->Location.y + bYes->Size.y + MARGIN; |
| 73 | break; |
nothing calls this directly
no test coverage detected