The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. //==============================================================================
  15. class CurrentActivitiesComp : public Component,
  16. private ChangeListener,
  17. private ListBoxModel,
  18. private Timer
  19. {
  20. public:
  21. CurrentActivitiesComp (ActivityList& activities)
  22. : Component ("Activities"), activityList (activities)
  23. {
  24. addAndMakeVisible (&list);
  25. list.setColour (ListBox::backgroundColourId, Colours::transparentBlack);
  26. list.setRowHeight (16);
  27. list.setModel (this);
  28. activityList.addChangeListener (this);
  29. }
  30. ~CurrentActivitiesComp() override
  31. {
  32. activityList.removeChangeListener (this);
  33. }
  34. void resized() override { list.setBounds (getLocalBounds()); }
  35. int getNumRows() override
  36. {
  37. return activityList.getNumActivities();
  38. }
  39. void paintListBoxItem (int rowNumber, Graphics& g,
  40. int width, int height, bool /*rowIsSelected*/) override
  41. {
  42. const StringArray activities (activityList.getActivities());
  43. if (rowNumber >= 0 && rowNumber < activities.size())
  44. {
  45. g.setColour (findColour (defaultTextColourId));
  46. g.setFont (height * 0.7f);
  47. g.drawText (activities [rowNumber],
  48. 4, 0, width - 5, height, Justification::centredLeft, true);
  49. }
  50. }
  51. void paint (Graphics& g) override
  52. {
  53. if (getNumRows() == 0)
  54. TreePanelBase::drawEmptyPanelMessage (*this, g, "(No activities)");
  55. }
  56. static int getMaxPanelHeight() { return 200; }
  57. private:
  58. ActivityList& activityList;
  59. ListBox list;
  60. int panelHeightToSet;
  61. void timerCallback() override
  62. {
  63. stopTimer();
  64. if (ConcertinaPanel* cp = findParentComponentOfClass<ConcertinaPanel>())
  65. cp->setPanelSize (this, panelHeightToSet, true);
  66. }
  67. void changeListenerCallback (ChangeBroadcaster*) override
  68. {
  69. list.updateContent();
  70. panelHeightToSet = jmax (3, getNumRows()) * list.getRowHeight() + 15;
  71. if (! isTimerRunning())
  72. startTimer (100);
  73. repaint();
  74. }
  75. };