| 389 | } |
| 390 | |
| 391 | WidgetConstructResult WidgetParser::textboxHandler(String const& name, Json const& config) { |
| 392 | String callback = config.getString("callback", name); |
| 393 | |
| 394 | if (!m_callbacks.contains(callback)) |
| 395 | throw WidgetParserException::format("Failed to find textbox callback named: '{}'", name); |
| 396 | |
| 397 | WidgetCallbackFunc callbackFunc = m_callbacks.get(callback); |
| 398 | |
| 399 | String initialText = config.getString("value", ""); |
| 400 | String hintText = config.getString("hint", ""); |
| 401 | auto textbox = make_shared<TextBoxWidget>(initialText, hintText, callbackFunc); |
| 402 | |
| 403 | if (config.contains("blur")) |
| 404 | textbox->setOnBlurCallback(m_callbacks.get(config.getString("blur"))); |
| 405 | if (config.contains("enterKey")) |
| 406 | textbox->setOnEnterKeyCallback(m_callbacks.get(config.getString("enterKey"))); |
| 407 | if (config.contains("escapeKey")) |
| 408 | textbox->setOnEscapeKeyCallback(m_callbacks.get(config.getString("escapeKey"))); |
| 409 | |
| 410 | if (config.contains("nextFocus")) |
| 411 | textbox->setNextFocus(config.getString("nextFocus")); |
| 412 | if (config.contains("prevFocus")) |
| 413 | textbox->setPrevFocus(config.getString("prevFocus")); |
| 414 | |
| 415 | String hAnchor = config.getString("textAlign", "left"); |
| 416 | if (hAnchor == "right") { |
| 417 | textbox->setTextAlign(HorizontalAnchor::RightAnchor); |
| 418 | } else if (hAnchor == "center") { |
| 419 | textbox->setTextAlign(HorizontalAnchor::HMidAnchor); |
| 420 | } else if (hAnchor != "left") { |
| 421 | throw WidgetParserException(strf( |
| 422 | "Malformed gui json, expected textAlign to be one of \"left\", \"right\", or \"center\", got {}", hAnchor)); |
| 423 | } |
| 424 | |
| 425 | if (config.contains("fontSize")) |
| 426 | textbox->setFontSize(config.getInt("fontSize")); |
| 427 | if (config.contains("color")) |
| 428 | textbox->setColor(jsonToColor(config.get("color"))); |
| 429 | if (config.contains("directives")) |
| 430 | textbox->setDirectives(config.getString("directives")); |
| 431 | if (config.contains("border")) |
| 432 | textbox->setDrawBorder(config.getBool("border")); |
| 433 | if (config.contains("maxWidth")) |
| 434 | textbox->setMaxWidth(config.getInt("maxWidth")); |
| 435 | if (config.contains("regex")) |
| 436 | textbox->setRegex(config.getString("regex")); |
| 437 | if (config.contains("hidden")) |
| 438 | textbox->setHidden(config.getBool("hidden")); |
| 439 | |
| 440 | common(textbox, config); |
| 441 | |
| 442 | return WidgetConstructResult(textbox, name, config.getFloat("zlevel", 0)); |
| 443 | } |
| 444 | |
| 445 | WidgetConstructResult WidgetParser::labelHandler(String const& name, Json const& config) { |
| 446 | String text = config.getString("value", ""); |
nothing calls this directly
no test coverage detected