setting-editor.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. SettingEditor::SettingEditor(View* view) : PanelItem(view, Size{~0, ~0}) {
  2. setCollapsible().setVisible(false);
  3. nameLabel.setFont(Font().setBold());
  4. latchedLayout.setCollapsible();
  5. latchedLabel.setText("Latched:");
  6. valueList.onChange([&] { eventChange(); });
  7. }
  8. auto SettingEditor::show() -> void {
  9. setVisible(true);
  10. }
  11. auto SettingEditor::hide() -> void {
  12. setVisible(false);
  13. setting = {};
  14. }
  15. auto SettingEditor::refresh(higan::Node::Setting setting) -> void {
  16. if(setting) {
  17. this->setting = setting; //assigning a new setting to the editor
  18. } else {
  19. setting = this->setting; //refreshing an existing setting in the editor
  20. }
  21. nameLabel.setText(setting->name());
  22. latchedLayout.setVisible(!setting->dynamic());
  23. latchedValue.setText(setting->readLatch());
  24. valueList.reset();
  25. for(auto& value : setting->readAllowedValues()) {
  26. ListViewItem item{&valueList};
  27. item.setText(value);
  28. if(value == setting->readValue()) item.setSelected();
  29. }
  30. resize();
  31. }
  32. auto SettingEditor::eventChange() -> void {
  33. if(auto item = valueList.selected()) {
  34. setting->writeValue(item.text());
  35. latchedValue.setText(setting->readLatch());
  36. nodeManager.refreshSettings();
  37. } else {
  38. //the current value should always be selected
  39. //if the user deselects all item, reselect the current value
  40. for(auto& item : valueList.items()) {
  41. if(item.text() == setting->readValue()) {
  42. item.setSelected();
  43. break;
  44. }
  45. }
  46. }
  47. }