MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / textboxHandler

Method textboxHandler

source/windowing/StarWidgetParsing.cpp:391–443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

389}
390
391WidgetConstructResult 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
445WidgetConstructResult WidgetParser::labelHandler(String const& name, Json const& config) {
446 String text = config.getString("value", "");

Callers

nothing calls this directly

Calls 15

strfFunction · 0.85
jsonToColorFunction · 0.85
getStringMethod · 0.80
setOnBlurCallbackMethod · 0.80
setOnEnterKeyCallbackMethod · 0.80
setNextFocusMethod · 0.80
setPrevFocusMethod · 0.80
getIntMethod · 0.80
setDrawBorderMethod · 0.80
getBoolMethod · 0.80

Tested by

no test coverage detected