|
| 1 | +/** A general demonstration of a highly flexible list view system. */ |
| 2 | +class ListViewDemo final : public DemoBase |
| 3 | +{ |
| 4 | +public: |
| 5 | + ListViewDemo (SharedObjects& sharedObjs) : |
| 6 | + DemoBase (sharedObjs, NEEDS_TRANS ("ListView")) |
| 7 | + { |
| 8 | + scrollView = makeListView(); |
| 9 | + scrollView->setModel (&demoListModel); |
| 10 | + addAndMakeVisible (scrollView.get()); |
| 11 | + |
| 12 | + updateWithNewTranslations(); |
| 13 | + } |
| 14 | + |
| 15 | + ~ListViewDemo() override |
| 16 | + { |
| 17 | + scrollView->setModel (nullptr); |
| 18 | + } |
| 19 | + |
| 20 | + //============================================================================== |
| 21 | + void updateWithNewTranslations() override |
| 22 | + { |
| 23 | + SQUAREPINE_CRASH_TRACER |
| 24 | + repaint(); |
| 25 | + } |
| 26 | + |
| 27 | + void resized() override |
| 28 | + { |
| 29 | + auto b = getLocalBounds().reduced (margin); |
| 30 | + |
| 31 | + { |
| 32 | + auto top = b.removeFromTop (margin * 4); |
| 33 | + } |
| 34 | + |
| 35 | + b.removeFromTop (margin); |
| 36 | + scrollView->setBounds (b); |
| 37 | + } |
| 38 | + |
| 39 | +private: |
| 40 | + //===============================4=============================================== |
| 41 | + enum { margin = 8 }; |
| 42 | + |
| 43 | + class DemoListModel final : public ListModel |
| 44 | + { |
| 45 | + public: |
| 46 | + DemoListModel() = default; |
| 47 | + |
| 48 | + int getNumItems() const override { return 1000; } |
| 49 | + |
| 50 | + Component* getItemComponent (int index) override |
| 51 | + { |
| 52 | + auto* label = new Label(); |
| 53 | + label->setColour (Label::ColourIds::backgroundColourId, Colours::red); |
| 54 | + label->setText ("Item " + String(index), dontSendNotification); |
| 55 | + return label; |
| 56 | + } |
| 57 | + }; |
| 58 | + |
| 59 | + DemoListModel demoListModel; |
| 60 | + std::unique_ptr<ScrollView> scrollView; |
| 61 | + |
| 62 | + //============================================================================== |
| 63 | + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ListViewDemo) |
| 64 | +}; |
0 commit comments