~unity-team/unity/trusty-1066971

« back to all changes in this revision

Viewing changes to dash/previews/SocialPreviewComments.cpp

  • Committer: Chris Townsend
  • Author(s): Marco Trevisan (Treviño), Eleni Maria Stea
  • Date: 2014-07-24 13:49:53 UTC
  • mto: This revision was merged to the branch mainline in revision 3802.
  • Revision ID: christopher.townsend@canonical.com-20140724134953-x8gokrnrm3ypo5kx
Previews: scale the dash preview contents to match current monitor scaling
  
Improved also the scaling of search-bar, spinner, categories and many other components.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
namespace
42
42
{
43
 
const int layout_spacing = 12;
 
43
const RawPixel LAYOUT_SPACING = 12_em;
 
44
const RawPixel CHILDREN_SPACE = 6_em;
44
45
}
45
46
 
46
47
NUX_IMPLEMENT_OBJECT_TYPE(SocialPreviewComments);
47
48
 
48
49
SocialPreviewComments::SocialPreviewComments(dash::Preview::Ptr preview_model, NUX_FILE_LINE_DECL)
49
50
: View(NUX_FILE_LINE_PARAM)
 
51
, scale(1.0)
50
52
, preview_model_(preview_model)
51
53
{
52
54
  SetupViews();
53
 
}
54
 
 
55
 
SocialPreviewComments::~SocialPreviewComments()
56
 
{
 
55
  scale.changed.connect(sigc::hide(sigc::mem_fun(this, &SocialPreviewComments::SetupViews)));
57
56
}
58
57
 
59
58
void SocialPreviewComments::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
85
84
  nux::Geometry const& geo = GetGeometry();
86
85
 
87
86
  int comment_width = 0;
 
87
  int minimum_detail_width = style.GetDetailsPanelMinimumWidth().CP(scale);
 
88
 
88
89
  for (Comment const& comment : comments_)
89
90
  {
90
 
    int width = style.GetDetailsPanelMinimumWidth();
 
91
    int width = minimum_detail_width;
 
92
 
91
93
    if (comment.first)
92
 
    {
93
 
      width = comment.first->GetTextExtents().width;
94
 
 
95
 
      if (width < style.GetDetailsPanelMinimumWidth())
96
 
        width = style.GetDetailsPanelMinimumWidth();
97
 
    }
 
94
      width = std::max(minimum_detail_width, comment.first->GetTextExtents().width);
98
95
 
99
96
    if (comment_width < width)
100
 
    {
101
97
      comment_width = width;
102
 
    }
103
98
  }
104
99
 
105
 
  int comment_value_width = MAX(0, geo.width - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin());
 
100
  int comment_value_width = MAX(0, geo.width - style.GetDetailsLeftMargin().CP(scale) - style.GetDetailsRightMargin().CP(scale));
106
101
 
107
102
  for (Comment const& comment : comments_)
108
103
  {
122
117
{
123
118
  dash::SocialPreview* social_preview_model = dynamic_cast<dash::SocialPreview*>(preview_model_.get());
124
119
 
125
 
 
126
120
  RemoveLayout();
127
121
  comments_.clear();
128
122
 
131
125
  auto on_mouse_down = [this](int x, int y, unsigned long button_flags, unsigned long key_flags) { this->preview_container_.OnMouseDown(x, y, button_flags, key_flags); };
132
126
 
133
127
  nux::VLayout* layout = new nux::VLayout();
134
 
  layout->SetSpaceBetweenChildren(6);
 
128
  layout->SetSpaceBetweenChildren(CHILDREN_SPACE.CP(scale));
135
129
 
136
130
  for (dash::SocialPreview::CommentPtr comment : social_preview_model->GetComments())
137
131
  {
138
 
 
139
132
    nux::HLayout* name_layout = new nux::HLayout();
140
 
    name_layout->SetSpaceBetweenChildren(layout_spacing);
 
133
    name_layout->SetSpaceBetweenChildren(LAYOUT_SPACING.CP(scale));
141
134
 
142
135
    StaticCairoTextPtr comment_name;
143
136
    if (!comment->display_name.empty())
145
138
      comment_name = new StaticCairoText(comment->display_name, true, NUX_TRACKER_LOCATION);
146
139
      comment_name->SetFont(style.info_hint_bold_font());
147
140
      comment_name->SetLines(-1);
 
141
      comment_name->SetScale(scale);
148
142
      comment_name->SetTextAlignment(StaticCairoText::NUX_ALIGN_LEFT);
149
143
      comment_name->mouse_click.connect(on_mouse_down);
150
144
      name_layout->AddView(comment_name.GetPointer(), 0, nux::MINOR_POSITION_START);
156
150
      comment_time = new StaticCairoText(comment->time, true, NUX_TRACKER_LOCATION);
157
151
      comment_time->SetFont(style.info_hint_font());
158
152
      comment_time->SetLines(-1);
 
153
      comment_time->SetScale(scale);
159
154
      comment_time->SetTextAlignment(StaticCairoText::NUX_ALIGN_RIGHT);
160
155
      comment_time->mouse_click.connect(on_mouse_down);
161
156
      name_layout->AddView(comment_time.GetPointer(), 0, nux::MINOR_POSITION_START);
162
157
    }
163
158
 
164
 
 
165
159
    nux::HLayout* comment_layout = new nux::HLayout();
166
 
    comment_layout->SetSpaceBetweenChildren(layout_spacing);
 
160
    comment_layout->SetSpaceBetweenChildren(LAYOUT_SPACING.CP(scale));
167
161
 
168
162
    StaticCairoTextPtr comment_value(new StaticCairoText(comment->content, false, NUX_TRACKER_LOCATION));
169
163
 
170
164
    comment_value->SetFont(style.info_hint_font());
171
165
    comment_value->SetLines(-7);
 
166
    comment_value->SetScale(scale);
172
167
    comment_value->SetTextAlignment(StaticCairoText::NUX_ALIGN_LEFT);
173
168
    comment_value->mouse_click.connect(on_mouse_down);
174
169
    comment_layout->AddView(comment_value.GetPointer(), 1, nux::MINOR_POSITION_START);
182
177
  mouse_click.connect(on_mouse_down);
183
178
 
184
179
  SetLayout(layout);
185
 
 
186
180
}
187
181
 
188
182
std::string SocialPreviewComments::GetName() const