@@ -37,8 +37,10 @@ void style_provider::set(utki::shared_ref<style_sheet> ss)
3737
3838 std::vector<std::string_view> keys_to_remove;
3939
40+ // TODO: reload standard cache
41+
4042 // reload cache
41- for (auto & pair : this ->cache ) {
43+ for (auto & pair : this ->user_cache ) {
4244 auto sv = pair.second .lock ();
4345 if (!sv) {
4446 // the weak reference has expired
@@ -65,34 +67,55 @@ void style_provider::set(utki::shared_ref<style_sheet> ss)
6567
6668 // remove unused cache entries
6769 for (const auto & k : keys_to_remove) {
68- auto i = this ->cache .find (k);
69- this ->cache .erase (i);
70+ auto i = this ->user_cache .find (k);
71+ this ->user_cache .erase (i);
72+ }
73+ }
74+
75+ std::shared_ptr<const style_provider::style_value_base> style_provider::get_from_cache (style id) const
76+ {
77+ auto & w = this ->standard_cache [id];
78+ auto p = w.lock ();
79+ if (!p) {
80+ return nullptr ;
7081 }
82+
83+ return p;
7184}
7285
7386std::shared_ptr<const style_provider::style_value_base> style_provider::get_from_cache (std::string_view id) const
7487{
75- auto i = this ->cache .find (id);
76- if (i == this ->cache .end ()) {
88+ auto i = this ->user_cache .find (id);
89+ if (i == this ->user_cache .end ()) {
7790 return nullptr ;
7891 }
7992
8093 auto p = i->second .lock ();
8194 if (!p) {
82- this ->cache .erase (i);
95+ this ->user_cache .erase (i);
8396 }
8497
8598 return p;
8699}
87100
101+ void style_provider::store_to_cache (
102+ style id, //
103+ std::weak_ptr<style_value_base> v
104+ ) const
105+ {
106+ utki::assert (this ->standard_cache [id].expired ());
107+
108+ this ->standard_cache [id] = std::move (v);
109+ }
110+
88111void style_provider::store_to_cache (
89112 std::string_view id, //
90113 std::weak_ptr<style_value_base> v
91114) const
92115{
93- utki::assert (!utki::contains (this ->cache , id));
116+ utki::assert (!utki::contains (this ->user_cache , id));
94117
95- [[maybe_unused]] auto res = this ->cache .insert (std::make_pair (
118+ [[maybe_unused]] auto res = this ->user_cache .insert (std::make_pair (
96119 std::string (id), //
97120 std::move (v)
98121 ));
@@ -103,45 +126,45 @@ void style_provider::store_to_cache(
103126
104127styled<color> style_provider::get_color_background () const
105128{
106- return this ->get <color>(" color_background" sv );
129+ return this ->get <color>(style:: color_background);
107130}
108131
109132styled<color> style_provider::get_color_middleground () const
110133{
111- return this ->get <color>(" color_middleground" sv );
134+ return this ->get <color>(style:: color_middleground);
112135}
113136
114137styled<color> style_provider::get_color_foreground () const
115138{
116- return this ->get <color>(" color_foreground" sv );
139+ return this ->get <color>(style:: color_foreground);
117140}
118141
119142styled<color> style_provider::get_color_text_normal () const
120143{
121- return this ->get <color>(" color_text_normal" sv );
144+ return this ->get <color>(style:: color_text_normal);
122145}
123146
124147styled<color> style_provider::get_color_highlight () const
125148{
126- return this ->get <color>(" color_highlight" sv );
149+ return this ->get <color>(style:: color_highlight);
127150}
128151
129152styled<color> style_provider::get_color_cursor () const
130153{
131- return this ->get <color>(" color_cursor" sv );
154+ return this ->get <color>(style:: color_cursor);
132155}
133156
134157styled<layout::dimension> style_provider::get_dim_indent_tree_view_item () const
135158{
136- return this ->get <layout::dimension>(" dim_tree_view_item_indent" sv );
159+ return this ->get <layout::dimension>(style:: dim_tree_view_item_indent);
137160}
138161
139162styled<length> style_provider::get_font_size_normal () const
140163{
141- return this ->get <length>(" font_size_normal" sv );
164+ return this ->get <length>(style:: font_size_normal);
142165}
143166
144167styled<res::font> style_provider::get_font_face_normal () const
145168{
146- return this ->get <res::font>(" font_face_normal" sv );
169+ return this ->get <res::font>(style:: font_face_normal);
147170}
0 commit comments