Redraw window when the face definition changed
Hash the current face state and store that hash to check for changes.
This commit is contained in:
parent
9c82f6586c
commit
d846400279
|
@ -44,6 +44,11 @@ constexpr bool operator!=(const Face& lhs, const Face& rhs)
|
|||
return not (lhs == rhs);
|
||||
}
|
||||
|
||||
constexpr size_t hash_value(const Face& val)
|
||||
{
|
||||
return hash_values(val.fg, val.bg, val.attributes);
|
||||
}
|
||||
|
||||
constexpr Face merge_faces(const Face& base, const Face& face)
|
||||
{
|
||||
return face.attributes & Attribute::Exclusive ?
|
||||
|
|
|
@ -20,6 +20,13 @@ public:
|
|||
void add_face(StringView name, StringView facedesc, bool override = false);
|
||||
void remove_face(StringView name);
|
||||
|
||||
struct FaceOrAlias
|
||||
{
|
||||
Face face = {};
|
||||
String alias = {};
|
||||
};
|
||||
using FaceMap = HashMap<String, FaceOrAlias, MemoryDomain::Faces>;
|
||||
|
||||
auto flatten_faces() const
|
||||
{
|
||||
auto merge = [](auto&& first, const FaceMap& second) {
|
||||
|
@ -33,19 +40,11 @@ public:
|
|||
return merge(merge(grand_parent, parent), m_faces);
|
||||
}
|
||||
|
||||
struct FaceOrAlias
|
||||
{
|
||||
Face face = {};
|
||||
String alias = {};
|
||||
};
|
||||
|
||||
private:
|
||||
friend class Scope;
|
||||
FaceRegistry();
|
||||
|
||||
SafePtr<FaceRegistry> m_parent;
|
||||
|
||||
using FaceMap = HashMap<String, FaceOrAlias, MemoryDomain::Faces>;
|
||||
FaceMap m_faces;
|
||||
};
|
||||
|
||||
|
|
|
@ -75,6 +75,14 @@ void Window::center_column(ColumnCount buffer_column)
|
|||
display_column_at(buffer_column, m_dimensions.column/2_col);
|
||||
}
|
||||
|
||||
static uint32_t compute_faces_hash(const FaceRegistry& faces)
|
||||
{
|
||||
uint32_t hash = 0;
|
||||
for (auto&& face : faces.flatten_faces() | transform(&FaceRegistry::FaceMap::Item::value))
|
||||
hash = combine_hash(hash, face.alias.empty() ? hash_value(face.face) : hash_value(face.alias));
|
||||
return hash;
|
||||
}
|
||||
|
||||
Window::Setup Window::build_setup(const Context& context) const
|
||||
{
|
||||
Vector<BufferRange, MemoryDomain::Display> selections;
|
||||
|
@ -83,6 +91,7 @@ Window::Setup Window::build_setup(const Context& context) const
|
|||
|
||||
return { m_position, m_dimensions,
|
||||
context.buffer().timestamp(),
|
||||
compute_faces_hash(context.faces()),
|
||||
context.selections().main_index(),
|
||||
std::move(selections) };
|
||||
}
|
||||
|
@ -95,7 +104,8 @@ bool Window::needs_redraw(const Context& context) const
|
|||
m_dimensions != m_last_setup.dimensions or
|
||||
context.buffer().timestamp() != m_last_setup.timestamp or
|
||||
selections.main_index() != m_last_setup.main_selection or
|
||||
selections.size() != m_last_setup.selections.size())
|
||||
selections.size() != m_last_setup.selections.size() or
|
||||
compute_faces_hash(context.faces()) != m_last_setup.faces_hash)
|
||||
return true;
|
||||
|
||||
for (int i = 0; i < selections.size(); ++i)
|
||||
|
|
|
@ -72,6 +72,7 @@ private:
|
|||
DisplayCoord position;
|
||||
DisplayCoord dimensions;
|
||||
size_t timestamp;
|
||||
size_t faces_hash;
|
||||
size_t main_selection;
|
||||
Vector<BufferRange, MemoryDomain::Display> selections;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user