Nux

Merge lp:~gordallott/nux/completion into lp:nux/2.0

Proposed by Gord Allott
Status: Merged
Approved by: Tim Penhey
Approved revision: 557
Merged at revision: 557
Proposed branch: lp:~gordallott/nux/completion
Merge into: lp:nux/2.0
Diff against target: 126 lines (+59/-1)
3 files modified
Nux/TextEntry.cpp (+46/-1)
Nux/TextEntry.h (+12/-0)
examples/text_entry_focus.cpp (+1/-0)
To merge this branch: bzr merge lp:~gordallott/nux/completion
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+91650@code.launchpad.net

Description of the change

Adds very basic completion support to nux,
Essentially just adds text to the end of the TextEntry widget without any real logic as the logic we want for unity is
different from what we want for a toolkit

Basically just a visual change to allow hud to offer completion

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

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Nux/TextEntry.cpp'
2--- Nux/TextEntry.cpp 2012-01-10 10:31:22 +0000
3+++ Nux/TextEntry.cpp 2012-02-06 13:36:36 +0000
4@@ -116,6 +116,7 @@
5 , canvas_(nullptr)
6 , cached_layout_(nullptr)
7 , preedit_attrs_(nullptr)
8+ , completion_color_(color::Gray)
9 , last_dblclick_time_(0)
10 , cursor_(0)
11 , preedit_cursor_(0)
12@@ -576,6 +577,34 @@
13 return text_;
14 }
15
16+ void TextEntry::SetCompletion(const char *text)
17+ {
18+ const char *end = NULL;
19+ g_utf8_validate(text, -1, &end);
20+ std::string txt((text && *text && end > text) ? std::string(text, end) : "");
21+ if (txt == completion_)
22+ return;
23+
24+ completion_ = txt;
25+ QueueRefresh(true, true);
26+ }
27+
28+ std::string const& TextEntry::GetCompletion() const
29+ {
30+ return completion_;
31+ }
32+
33+ void TextEntry::SetCompletionColor(const Color &color)
34+ {
35+ completion_color_ = color;
36+ QueueRefresh(true, true);
37+ }
38+
39+ Color const& TextEntry::GetCompletionColor() const
40+ {
41+ return completion_color_;
42+ }
43+
44 void TextEntry::SetTextColor(const Color &text_color)
45 {
46 if (_text_color != text_color)
47@@ -1163,6 +1192,13 @@
48 }
49 }
50
51+ int pre_completion_length = tmp_string.length();
52+
53+ if (!completion_.empty() && !wrap_)
54+ {
55+ tmp_string = text_ + completion_;
56+ }
57+
58 pango_layout_set_text(layout, tmp_string.c_str(),
59 static_cast<int>(tmp_string.length()));
60
61@@ -1172,13 +1208,22 @@
62 {
63 attr = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
64 attr->start_index = 0;
65- attr->end_index = static_cast<guint>(tmp_string.length());
66+ attr->end_index = static_cast<guint>(pre_completion_length);
67 pango_attr_list_insert(tmp_attrs, attr);
68 }
69 if (strikeout_)
70 {
71 attr = pango_attr_strikethrough_new(TRUE);
72 attr->start_index = 0;
73+ attr->end_index = static_cast<guint>(pre_completion_length);
74+ pango_attr_list_insert(tmp_attrs, attr);
75+ }
76+ if (!completion_.empty() && !wrap_)
77+ {
78+ attr = pango_attr_foreground_new(65535 * completion_color_.red,
79+ 65535 * completion_color_.green,
80+ 65535 * completion_color_.blue);
81+ attr->start_index = static_cast<guint>(pre_completion_length);
82 attr->end_index = static_cast<guint>(tmp_string.length());
83 pango_attr_list_insert(tmp_attrs, attr);
84 }
85
86=== modified file 'Nux/TextEntry.h'
87--- Nux/TextEntry.h 2012-01-10 10:27:09 +0000
88+++ Nux/TextEntry.h 2012-02-06 13:36:36 +0000
89@@ -132,6 +132,12 @@
90 void SetText(const char *text);
91 std::string const& GetText() const;
92
93+ void SetCompletion(const char *text); // Should use std::string, does not for consistancy
94+ std::string const& GetCompletion() const;
95+
96+ void SetCompletionColor(const Color &color);
97+ Color const& GetCompletionColor() const;
98+
99 void SetTextColor(const Color &color);
100 Color const& GetTextColor() const;
101 void SetFontFamily(const char *font);
102@@ -294,6 +300,12 @@
103 */
104 std::string password_char_;
105
106+ /** The completion string */
107+ std::string completion_;
108+
109+ /** The completion colour */
110+ Color completion_color_;
111+
112 /** Last time of mouse double click event. */
113 unsigned long long last_dblclick_time_;
114
115
116=== modified file 'examples/text_entry_focus.cpp'
117--- examples/text_entry_focus.cpp 2011-10-12 04:42:24 +0000
118+++ examples/text_entry_focus.cpp 2012-02-06 13:36:36 +0000
119@@ -36,6 +36,7 @@
120
121 text_entry_0->SetMaximumWidth(300);
122 text_entry_0->SetMinimumHeight (20);
123+ text_entry_0->SetCompletion("test completion");
124
125 text_entry_1->SetMaximumWidth(300);
126 text_entry_1->SetMinimumHeight (20);

Subscribers

People subscribed via source and target branches

to all changes: