Merge lp:~thumper/unity/hud-text into lp:unity

Proposed by Tim Penhey
Status: Rejected
Rejected by: Andrea Azzarone
Proposed branch: lp:~thumper/unity/hud-text
Merge into: lp:unity
Diff against target: 150 lines (+83/-3)
4 files modified
UnityCore/Hud.cpp (+52/-2)
UnityCore/Hud.h (+2/-1)
tests/CMakeLists.txt (+1/-0)
tests/test_hud_text.cpp (+28/-0)
To merge this branch: bzr merge lp:~thumper/unity/hud-text
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+106550@code.launchpad.net

Description of the change

= The problem =

The initial work on the hud had the results from the hud service being shown directly. The hud service uses the <b> tag to indicate search matches.

The design, https://launchpadlibrarian.net/93965245/Pangolin_matrix_v1-3e.png had transparent text for not match parts.

= The solution =

Unfortunately we are not able to render transparency in the text at this stage due to limitations in the cairo methods we use. So what we do is to reformat the query strings in the hud service to use grey for the non-match parts.

= Tests =

./tests/test-gtest-xless --gtest_filter=TestHudText*

Screenshot: http://ubuntuone.com/2Zo5aiVDbZM5XooJyx0TKp

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Hmm... I'm really not convinced that this is the best solution.

Perhaps we should refactor the display of the HudButton code to use a combination of StaticCairoText objects to render the text to get proper transparency.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Yes, I agree... We should improve the View, or it won't look as it should.
However this look fine for now, even if I'd maybe use a lighter gray color.

Unmerged revisions

2367. By Tim Penhey

More tests, and the implementation.

2366. By Tim Penhey

And a failing test.

2365. By Tim Penhey

Step one.

2364. By Tim Penhey

Add the base function.

2363. By Tim Penhey

Added a bare test.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/Hud.cpp'
2--- UnityCore/Hud.cpp 2012-04-16 12:11:01 +0000
3+++ UnityCore/Hud.cpp 2012-05-20 22:40:25 +0000
4@@ -19,6 +19,8 @@
5 //
6 #include "Hud.h"
7
8+#include <sstream>
9+
10 #include <gio/gio.h>
11 #include <glib.h>
12 #include <NuxCore/Logger.h>
13@@ -33,13 +35,58 @@
14 {
15 namespace hud
16 {
17-
18 namespace
19 {
20 nux::logging::Logger logger("unity.hud.hud");
21 const int request_number_of_results = 6;
22 }
23
24+std::string reformat_hud_text(std::string const& text,
25+ std::string const& colour)
26+{
27+ static const std::string bold_start("<b>");
28+ static const std::string bold_end("</b>");
29+ static const std::string span_end("</span>");
30+ const std::string span_start("<span color=\"" + colour + "\">");
31+
32+ std::ostringstream sout;
33+ std::string::size_type last = 0;
34+ std::string::size_type len = text.length();
35+ std::string::size_type pos = text.find(bold_start);
36+
37+ while (pos != std::string::npos)
38+ {
39+ if (pos != last)
40+ {
41+ sout << span_start << text.substr(last, pos - last) << span_end;
42+ }
43+ // Look for the end
44+ std::string::size_type end_pos = text.find(bold_end, pos);
45+ // We hope we find it, if we don't, just output everything...
46+ if (end_pos != std::string::npos)
47+ {
48+ pos += 3; // to skip the "<b>"
49+ sout << text.substr(pos, end_pos - pos);
50+ last = end_pos + 4; // the length of "</b>"
51+ pos = text.find(bold_start, last);
52+ }
53+ else
54+ {
55+ sout << text.substr(pos);
56+ pos = std::string::npos;
57+ last = len;
58+ }
59+ }
60+
61+ if (last < len)
62+ {
63+ sout << span_start << text.substr(last) << span_end;
64+ }
65+
66+ return sout.str();
67+}
68+
69+
70 // Impl classes
71 class HudImpl
72 {
73@@ -157,6 +204,8 @@
74
75 void HudImpl::BuildQueries(GVariant* query_array)
76 {
77+ static const std::string GREY("#AAAAAA");
78+
79 GVariantIter iter;
80 g_variant_iter_init(&iter, query_array);
81 gchar* formatted_text;
82@@ -169,7 +218,8 @@
83 while (g_variant_iter_loop(&iter, "(sssssv)",
84 &formatted_text, &icon, &item_icon, &completion_text, &shortcut, &key))
85 {
86- queries_.push_back(Query::Ptr(new Query(formatted_text,
87+ std::string invert_bold(reformat_hud_text(formatted_text, GREY));
88+ queries_.push_back(Query::Ptr(new Query(invert_bold,
89 icon,
90 item_icon,
91 completion_text,
92
93=== modified file 'UnityCore/Hud.h'
94--- UnityCore/Hud.h 2012-03-06 09:51:29 +0000
95+++ UnityCore/Hud.h 2012-05-20 22:40:25 +0000
96@@ -30,7 +30,8 @@
97 {
98 namespace hud
99 {
100-
101+std::string reformat_hud_text(std::string const& text,
102+ std::string const& colour);
103
104 class Query
105 {
106
107=== modified file 'tests/CMakeLists.txt'
108--- tests/CMakeLists.txt 2012-05-15 18:54:33 +0000
109+++ tests/CMakeLists.txt 2012-05-20 22:40:25 +0000
110@@ -140,6 +140,7 @@
111 test_favorite_store_gsettings.cpp
112 test_favorite_store_private.cpp
113 test_home_lens.cpp
114+ test_hud_text.cpp
115 test_launcher_entry_remote.cpp
116 test_shortcut_model.cpp
117 test_shortcut_private.cpp
118
119=== added file 'tests/test_hud_text.cpp'
120--- tests/test_hud_text.cpp 1970-01-01 00:00:00 +0000
121+++ tests/test_hud_text.cpp 2012-05-20 22:40:25 +0000
122@@ -0,0 +1,28 @@
123+#include <gmock/gmock.h>
124+
125+#include <UnityCore/Hud.h>
126+
127+using namespace testing;
128+
129+using unity::hud::reformat_hud_text;
130+
131+namespace
132+{
133+
134+TEST(TestHudText, TestFoo)
135+{
136+ std::string colour("blue");
137+
138+ ASSERT_THAT(reformat_hud_text("test", colour),
139+ Eq("<span color=\"blue\">test</span>"));
140+ ASSERT_THAT(reformat_hud_text("<b>test</b>", colour),
141+ Eq("test"));
142+ ASSERT_THAT(reformat_hud_text("<b>te</b>st", colour),
143+ Eq("te<span color=\"blue\">st</span>"));
144+ ASSERT_THAT(reformat_hud_text("te<b>st</b>", colour),
145+ Eq("<span color=\"blue\">te</span>st"));
146+ ASSERT_THAT(reformat_hud_text("<b>te</b><b>st</b>", colour),
147+ Eq("test"));
148+}
149+
150+}