Skip to content

Commit 0f34ca3

Browse files
committed
Merge branch 'skia_2024'
1 parent 9241c8f commit 0f34ca3

File tree

10 files changed

+375
-15
lines changed

10 files changed

+375
-15
lines changed

examples/child_window/main.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ auto background = box(bkd_color);
1313

1414
auto make_child_window(rect bounds, char const* title)
1515
{
16-
return closable_child_window(
16+
using cycfi::elements::image;
17+
return standard_child_window(
1718
title,
1819
bounds,
19-
scroller(image{"deep_space.jpg"})
20+
hmin_size(250,
21+
scroller(image{"deep_space.jpg"})
22+
)
2023
);
2124
}
2225

lib/host/gtk3/base_view.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ namespace cycfi::elements
530530

531531
std::filesystem::path get_app_path()
532532
{
533-
char result[PATH_MAX];
533+
char result[PATH_MAX + 1];
534534
// get the full path to the executable file of the current process.
535535
if (auto count = readlink("/proc/self/exe", result, PATH_MAX); count != -1)
536536
{

lib/include/elements/element/child_window.hpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,41 @@ namespace cycfi::elements
110110
return {std::forward<Subject>(subject)};
111111
}
112112

113+
struct resizable_tracker_info : tracker_info
114+
{
115+
using tracker_info::tracker_info;
116+
117+
enum handle : unsigned char
118+
{
119+
top = 1,
120+
left = 2,
121+
bottom = 4,
122+
right = 8
123+
};
124+
125+
unsigned char _handle = 0;
126+
};
127+
128+
class resizable_base : public tracker<proxy_base, resizable_tracker_info>
129+
{
130+
public:
131+
132+
using tracker = tracker<proxy_base, resizable_tracker_info>;
133+
134+
bool cursor(context const& ctx, point p, cursor_tracking status) override;
135+
element* hit_test(context const& ctx, point p, bool leaf, bool control) override;
136+
bool click(context const& ctx, mouse_button btn) override;
137+
void drag(context const& ctx, mouse_button btn) override;
138+
void keep_tracking(context const& ctx, tracker_info& track_info) override;
139+
};
140+
141+
template <concepts::Element Subject>
142+
inline proxy<remove_cvref_t<Subject>, resizable_base>
143+
resizable(Subject&& subject)
144+
{
145+
return {std::forward<Subject>(subject)};
146+
}
147+
113148
/**
114149
* \class closable_element
115150
*
@@ -174,6 +209,76 @@ namespace cycfi::elements
174209
};
175210
}
176211
}
212+
213+
template <concepts::Element Subject>
214+
class minimizable_element : public proxy<Subject>
215+
{
216+
public:
217+
218+
using proxy<Subject>::proxy;
219+
220+
void prepare_subject(context& ctx) override;
221+
};
222+
223+
template <concepts::Element Subject>
224+
inline minimizable_element<remove_cvref_t<Subject>>
225+
minimizable(Subject&& subject)
226+
{
227+
return {std::forward<Subject>(subject)};
228+
}
229+
230+
void minimize_floating_element(context& ctx, floating_element* cw);
231+
232+
template <concepts::Element Subject>
233+
inline void minimizable_element<Subject>::prepare_subject(context& ctx)
234+
{
235+
auto btn = find_subject<basic_button*>(this);
236+
if (btn)
237+
{
238+
btn->on_click =
239+
[&ctx](bool)
240+
{
241+
auto fl = find_parent<floating_element*>(ctx);
242+
if (fl)
243+
minimize_floating_element(ctx, fl);
244+
};
245+
}
246+
}
247+
248+
template <concepts::Element Subject>
249+
class maximizable_element : public proxy<Subject>
250+
{
251+
public:
252+
253+
using proxy<Subject>::proxy;
254+
255+
void prepare_subject(context& ctx) override;
256+
};
257+
258+
template <concepts::Element Subject>
259+
inline maximizable_element<remove_cvref_t<Subject>>
260+
maximizable(Subject&& subject)
261+
{
262+
return {std::forward<Subject>(subject)};
263+
}
264+
265+
void maximize_floating_element(context& ctx, floating_element* cw);
266+
267+
template <concepts::Element Subject>
268+
inline void maximizable_element<Subject>::prepare_subject(context& ctx)
269+
{
270+
auto btn = find_subject<basic_button*>(this);
271+
if (btn)
272+
{
273+
btn->on_click =
274+
[&ctx](bool)
275+
{
276+
auto fl = find_parent<floating_element*>(ctx);
277+
if (fl)
278+
maximize_floating_element(ctx, fl);
279+
};
280+
}
281+
}
177282
}
178283

179284
#endif

lib/include/elements/element/floating.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ namespace cycfi::elements
3131
rect bounds() const;
3232
void bounds(rect bounds_);
3333

34+
void minimize(context& ctx);
35+
void maximize(context& ctx);
36+
3437
private:
3538

3639
rect _bounds;

lib/include/elements/element/status_bar.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,14 @@ namespace cycfi::elements
9797
busy_bar_base(
9898
double init_value = 0.0
9999
, double start_pos = 0.0
100-
)
101-
: status_bar_base(init_value)
102-
, _start_pos(start_pos)
103-
, _status(-0.2)
104-
{}
100+
);
105101

106102
void start_pos(double val);
107103
double start_pos() const { return _start_pos; }
108104

105+
void animation_width(double val);
106+
double animation_width() const { return _animation_width; }
107+
109108
void start(view& view_, duration time);
110109
void stop(view& view_);
111110
bool is_stopped() const { return _time == _time.zero(); }
@@ -117,6 +116,7 @@ namespace cycfi::elements
117116
void animate(view& view_);
118117

119118
double _start_pos;
119+
double _animation_width;
120120
double _status;
121121
duration _time;
122122
};

lib/include/elements/element/style/child_window.hpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define ELEMENTS_STYLE_CHILD_WINDOW_JANUARY_19_2021
88

99
#include <elements/element/child_window.hpp>
10+
#include <elements/element/tile.hpp>
1011
#include <elements/element/style/pane.hpp>
1112
#include <elements/element/style/icon_button.hpp>
1213

@@ -43,6 +44,7 @@ namespace cycfi::elements
4344
// Closable Child Window (movable and closable)
4445
////////////////////////////////////////////////////////////////////////////
4546
template <typename Content>
47+
[[deprecated("Use standard_child_window(...) instead")]]
4648
auto closable_child_window(std::string title, rect bounds, Content&& content)
4749
{
4850
return child_window(bounds,
@@ -66,6 +68,7 @@ namespace cycfi::elements
6668
}
6769

6870
template <typename Content>
71+
[[deprecated("Use standard_child_window(...) instead")]]
6972
auto closable_child_window(std::string title, point pos, Content&& content)
7073
{
7174
return closable_child_window(
@@ -74,6 +77,67 @@ namespace cycfi::elements
7477
std::forward<Content>(content)
7578
);
7679
}
80+
81+
enum : unsigned char
82+
{
83+
window_closable = 1,
84+
window_minimizable = 2,
85+
window_maximizable = 4,
86+
};
87+
88+
template <typename Content>
89+
auto standard_child_window(
90+
std::string title,
91+
rect bounds, Content&& content,
92+
unsigned char options = window_closable | window_minimizable | window_maximizable
93+
)
94+
{
95+
auto buttons = htile_composite{};
96+
if (options & window_minimizable)
97+
{
98+
buttons.push_back(
99+
share(minimizable(plain_icon_button(icons::angle_down, 0.8)))
100+
);
101+
}
102+
if (options & window_maximizable)
103+
{
104+
buttons.push_back(
105+
share(maximizable(plain_icon_button(icons::angle_up, 0.8)))
106+
);
107+
}
108+
if (options & window_closable)
109+
{
110+
buttons.push_back(
111+
share(closable(plain_icon_button(icons::cancel, 0.8)))
112+
);
113+
}
114+
return child_window(bounds,
115+
resizable(
116+
pane_ex(
117+
movable(
118+
layer(
119+
align_right(buttons),
120+
title_bar{}
121+
)
122+
),
123+
title,
124+
std::forward<Content>(content),
125+
get_theme().child_window_title_size,
126+
get_theme().child_window_opacity
127+
)
128+
)
129+
);
130+
}
131+
132+
template <typename Content>
133+
auto standard_child_window(std::string title, point pos, Content&& content)
134+
{
135+
return standard_child_window(
136+
title,
137+
rect{pos.x, pos.y, pos.x, pos.y},
138+
std::forward<Content>(content)
139+
);
140+
}
77141
}
78142

79143
#endif

0 commit comments

Comments
 (0)