radio-label.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #if defined(Hiro_RadioLabel)
  2. auto mRadioLabel::allocate() -> pObject* {
  3. return new pRadioLabel(*this);
  4. }
  5. //
  6. auto mRadioLabel::checked() const -> bool {
  7. return state.checked;
  8. }
  9. auto mRadioLabel::doActivate() const -> void {
  10. if(state.onActivate) return state.onActivate();
  11. }
  12. auto mRadioLabel::group() const -> Group {
  13. return state.group;
  14. }
  15. auto mRadioLabel::onActivate(const function<void ()>& callback) -> type& {
  16. state.onActivate = callback;
  17. return *this;
  18. }
  19. auto mRadioLabel::setChecked() -> type& {
  20. if(auto group = this->group()) {
  21. for(auto& weak : group->state.objects) {
  22. if(auto object = weak.acquire()) {
  23. if(auto radioLabel = dynamic_cast<mRadioLabel*>(object.data())) {
  24. radioLabel->state.checked = false;
  25. }
  26. }
  27. }
  28. }
  29. state.checked = true;
  30. signal(setChecked);
  31. return *this;
  32. }
  33. auto mRadioLabel::setGroup(sGroup group) -> type& {
  34. state.group = group ? group : Group{&instance};
  35. signal(setGroup, group);
  36. return *this;
  37. }
  38. auto mRadioLabel::setText(const string& text) -> type& {
  39. state.text = text;
  40. signal(setText, text);
  41. return *this;
  42. }
  43. auto mRadioLabel::text() const -> string {
  44. return state.text;
  45. }
  46. #endif