mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-30 12:10:03 +02:00
[escher] ScrollView: fix Decorators contructor/destructors
This commit is contained in:
committed by
EmilieNumworks
parent
f18a55defe
commit
3487547f16
@@ -33,6 +33,9 @@ public:
|
||||
Bars,
|
||||
Arrows
|
||||
};
|
||||
/* We want (Decorator *)->~Decorator() to call ~BarDecorator() or ~ArrowDecorator()
|
||||
* when required. */
|
||||
virtual ~Decorator() = default;
|
||||
virtual int numberOfIndicators() const { return 0; }
|
||||
virtual View * indicatorAtIndex(int index) { assert(false); return nullptr; }
|
||||
virtual KDRect layoutIndicators(KDSize content, KDPoint offset, KDRect frame) { return frame; }
|
||||
@@ -132,9 +135,8 @@ private:
|
||||
Decorator::Type m_decoratorType;
|
||||
union Decorators {
|
||||
public:
|
||||
/* Enforce trivial constructor and destructor that just leaves the memory unmodified. */
|
||||
Decorators() {}
|
||||
~Decorators() {}
|
||||
Decorators();
|
||||
~Decorators();
|
||||
Decorator * activeDecorator() { return &m_none; }
|
||||
void setActiveDecorator(Decorator::Type t);
|
||||
private:
|
||||
|
||||
@@ -198,8 +198,20 @@ void ScrollView::ArrowDecorator::setBackgroundColor(KDColor c) {
|
||||
}
|
||||
}
|
||||
|
||||
ScrollView::Decorators::Decorators() {
|
||||
/* We need to initiate the Union at construction to avoid destructing an
|
||||
* uninitialized object when changing the decorator type. */
|
||||
new (this) Decorator();
|
||||
}
|
||||
|
||||
ScrollView::Decorators::~Decorators() {
|
||||
activeDecorator()->~Decorator();
|
||||
}
|
||||
|
||||
void ScrollView::Decorators::setActiveDecorator(Decorator::Type t) {
|
||||
/* We do NOT need to destroy the previous decorator because they don't have a destructor */
|
||||
/* Decorator destructor is virtual so calling ~Decorator() on a Decorator
|
||||
* pointer will call the appropriate destructor. */
|
||||
activeDecorator()->~Decorator();
|
||||
switch (t) {
|
||||
case Decorator::Type::Bars:
|
||||
new (&m_bars) BarDecorator();
|
||||
|
||||
Reference in New Issue
Block a user