Skip to content

Commit 3e5f211

Browse files
committed
Updated example for "best practice"
1 parent 56faaa6 commit 3e5f211

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

examples/icons_list/main.cpp

+13-25
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,14 @@ using cycfi::artist::rgba;
1212
auto constexpr bkd_color = rgba(35, 35, 37, 255);
1313
auto background = box(bkd_color);
1414

15-
template<size_t Size>
16-
struct fixed_size_base : default_label
15+
inline auto make_icon_label(std::string name, int i)
1716
{
18-
view_limits limits(const basic_context &ctx) const override
19-
{
20-
point size = measure_text(ctx.canvas, "9" ,get_font());
21-
size.x *= Size;
22-
return {{size.x, size.y}, {size.x, size.y}};
23-
}
24-
};
25-
26-
template<size_t Size>
27-
using basic_fixed_size = basic_label_base<fixed_size_base<Size>>;
28-
29-
template<size_t Size>
30-
using fixed_size_label = label_gen<basic_fixed_size<Size>>;
31-
32-
inline auto make_icon_label(std::string name, int i)
33-
{
34-
auto h = htile(fixed_size_label<10>(name), hspace(50), icon_button(i,1));
35-
return share(h);
17+
auto h =
18+
htile(
19+
label(name),
20+
align_right(hsize(64, icon(i)))
21+
);
22+
return share(h);
3623
}
3724

3825
int main(int argc, char* argv[])
@@ -130,12 +117,13 @@ int main(int argc, char* argv[])
130117
comp.push_back(make_icon_label("unlink", icons::unlink));
131118
comp.push_back(make_icon_label("folder_open", icons::folder_empty));
132119
comp.push_back(make_icon_label("folder_open_empty", icons::folder_open_empty));
120+
133121
view_.content(
134-
margin({10, 10, 10, 10},
135-
vscroller(margin({40, 20, 40, 20}, comp))),
136-
// Add more content layers here. The order
137-
// specifies the layering. The lowest layer
138-
// is at the bottom of this list.
122+
margin({10, 10, 10, 10},
123+
vscroller(margin({10, 10, 30, 10}, comp))),
124+
// Add more content layers here. The order
125+
// specifies the layering. The lowest layer
126+
// is at the bottom of this list.
139127

140128
background // Replace background with your main element,
141129
// or keep it and add another layer on top of it.

0 commit comments

Comments
 (0)