From 0cb68d97ca50d7783b5b13008934baeb6c982929 Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 5 Jul 2019 11:33:53 +1000 Subject: Add SetAppearance method to make changes to appearance settings and only perform invalidation if the setting is actually changed. --- src/Editor.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/Editor.h b/src/Editor.h index f16a46693..13e201169 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -598,6 +598,19 @@ protected: // ScintillaBase subclass needs access to much of Editor static sptr_t StringResult(sptr_t lParam, const char *val) noexcept; static sptr_t BytesResult(sptr_t lParam, const unsigned char *val, size_t len) noexcept; + // Set a variable controlling appearance to a value and invalidates the display + // if a change was made. Avoids extra text and the possibility of mistyping. + template + bool SetAppearance(T &variable, T value) { + // Using ! and == as more types have == defined than !=. + const bool changed = !(variable == value); + if (changed) { + variable = value; + InvalidateStyleRedraw(); + } + return changed; + } + public: ~Editor() override; -- cgit v1.2.3