Skip to content

Commit d61a5f6

Browse files
committed
Merge branch 'skia_2024'
2 parents 34c7410 + faa4109 commit d61a5f6

24 files changed

+1747
-506
lines changed

examples/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ add_subdirectory(table_list)
2727
add_subdirectory(range_slider)
2828
add_subdirectory(model)
2929
add_subdirectory(selection_list)
30+
add_subdirectory(status_bars)

examples/buttons/main.cpp

-17
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ auto make_buttons(view& view_)
8686
auto lbutton = share(latching_button("Latching Button", 1.0, bgreen));
8787
auto reset = share(button("Clear Latch", icons::lock_open, 1.0, bblue));
8888
auto note = button(icons::cog, "Setup", 1.0, brblue);
89-
auto prog_bar = share(progress_bar(rbox(colors::black), rbox(pgold)));
90-
auto prog_advance = icon_button(icons::plus);
9189
auto disabled_button = button("Disabled Button");
9290

9391
// This is the new way of making buttons that is consistent with the label
@@ -178,17 +176,6 @@ auto make_buttons(view& view_)
178176
}
179177
};
180178

181-
prog_advance.on_click =
182-
[prog_bar, &view_](bool) mutable
183-
{
184-
auto val = prog_bar->value();
185-
if (val > 0.9)
186-
prog_bar->value(0.0);
187-
else
188-
prog_bar->value(val + 0.125);
189-
view_.refresh(*prog_bar);
190-
};
191-
192179
static auto const grid = make_equal_grid<3>();
193180
auto disabled_label = label("Disabled");
194181
disabled_label.enable(false);
@@ -201,10 +188,6 @@ auto make_buttons(view& view_)
201188
margin_top(20, hold(lbutton)),
202189
margin_top(20, hold(reset)),
203190
margin_top(20, note),
204-
margin_top(20, htile(
205-
margin_right(3, valign(0.5, prog_advance)),
206-
vsize(27, hold(prog_bar))
207-
)),
208191
margin_top(20, disabled_button),
209192
margin_top(20,
210193
htile(

examples/icons_list/main.cpp

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

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

3724
int main(int argc, char* argv[])
@@ -129,12 +116,13 @@ int main(int argc, char* argv[])
129116
comp.push_back(make_icon_label("unlink", icons::unlink));
130117
comp.push_back(make_icon_label("folder_open", icons::folder_empty));
131118
comp.push_back(make_icon_label("folder_open_empty", icons::folder_open_empty));
119+
132120
view_.content(
133-
margin({10, 10, 10, 10},
134-
vscroller(margin({40, 20, 40, 20}, comp))),
135-
// Add more content layers here. The order
136-
// specifies the layering. The lowest layer
137-
// is at the bottom of this list.
121+
margin({10, 10, 10, 10},
122+
vscroller(margin({10, 10, 30, 10}, comp))),
123+
// Add more content layers here. The order
124+
// specifies the layering. The lowest layer
125+
// is at the bottom of this list.
138126

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

examples/status_bars/CMakeLists.txt

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
cmake_minimum_required(VERSION 3.16.0)
2+
project(DynamicLists LANGUAGES C CXX VERSION "1.0.0")
3+
4+
if (NOT ELEMENTS_ROOT)
5+
message(FATAL_ERROR "ELEMENTS_ROOT is not set")
6+
endif()
7+
8+
# Make sure ELEMENTS_ROOT is an absolute path to add to the CMake module path
9+
get_filename_component(ELEMENTS_ROOT "${ELEMENTS_ROOT}" ABSOLUTE)
10+
set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${ELEMENTS_ROOT}/cmake")
11+
12+
# If we are building outside the project, you need to set ELEMENTS_ROOT:
13+
if (NOT ELEMENTS_BUILD_EXAMPLES)
14+
include(ElementsConfigCommon)
15+
set(ELEMENTS_BUILD_EXAMPLES OFF)
16+
add_subdirectory(${ELEMENTS_ROOT} elements)
17+
endif()
18+
19+
set(ELEMENTS_APP_PROJECT "StatusBars")
20+
set(ELEMENTS_APP_TITLE "Status Bars")
21+
set(ELEMENTS_APP_COPYRIGHT "Copyright (c) 2024 Flole")
22+
set(ELEMENTS_APP_ID "com.cycfi.status_bars")
23+
set(ELEMENTS_APP_VERSION "1.0")
24+
25+
set(ELEMENTS_APP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
26+
27+
# For your custom application icon on macOS or Windows see cmake/AppIcon.cmake module
28+
include(AppIcon)
29+
include(ElementsConfigApp)

examples/status_bars/main.cpp

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*=============================================================================
2+
Copyright (c) 2024 Flole
3+
4+
Distributed under the MIT License (https://opensource.org/licenses/MIT)
5+
=============================================================================*/
6+
#include <elements.hpp>
7+
8+
using namespace cycfi::elements;
9+
using namespace std::chrono_literals;
10+
11+
constexpr auto bgreen = colors::green.level(0.7).opacity(0.8);
12+
constexpr auto pgold = colors::gold.opacity(0.8);
13+
14+
// Main window background color
15+
auto constexpr bkd_color = rgba(35, 35, 37, 255);
16+
auto background = box(bkd_color);
17+
18+
bool run = false;
19+
template <typename ProgressBar>
20+
void prog_incr(ProgressBar& prog_bar, view& view_)
21+
{
22+
auto val = prog_bar.value();
23+
if (val > 1.0)
24+
{
25+
prog_bar.value(1.0);
26+
run = false;
27+
}
28+
else
29+
{
30+
prog_bar.value(val + 0.005);
31+
}
32+
view_.refresh(prog_bar);
33+
}
34+
35+
template <typename ProgressBar>
36+
void prog_animate(ProgressBar& prog_bar, view& view_)
37+
{
38+
if (run)
39+
{
40+
prog_incr(prog_bar, view_);
41+
view_.post(10ms,
42+
[&]()
43+
{
44+
prog_animate(prog_bar, view_);
45+
}
46+
);
47+
}
48+
}
49+
50+
auto make_bars(view& view_)
51+
{
52+
auto prog_bar = share(progress_bar(rbox(colors::black), rbox(pgold)));
53+
auto bsy_bar = share(busy_bar(rbox(colors::black), rbox(bgreen)));
54+
auto start_stop = toggle_icon_button(icons::play, icons::stop, 2.0);
55+
56+
start_stop.on_click =
57+
[prog_bar, bsy_bar, &view_](bool state) mutable
58+
{
59+
if (state)
60+
{
61+
bsy_bar->start(view_, 10ms);
62+
run = true;
63+
prog_bar->value(0.0);
64+
prog_animate(*prog_bar, view_);
65+
}
66+
else
67+
{
68+
bsy_bar->stop(view_);
69+
run = false;
70+
}
71+
};
72+
73+
return
74+
margin({20, 20, 20, 20},
75+
htile(
76+
start_stop,
77+
hspace(10),
78+
vtile(
79+
vsize(27, hold(prog_bar)),
80+
vspace(10),
81+
vsize(27, hold(bsy_bar))
82+
)
83+
)
84+
);
85+
}
86+
87+
int main(int argc, char* argv[])
88+
{
89+
app _app("Status Bars");
90+
window _win(_app.name());
91+
_win.on_close = [&_app]() { _app.stop(); };
92+
93+
view view_(_win);
94+
95+
view_.content(
96+
make_bars(view_),
97+
background
98+
);
99+
100+
_app.run();
101+
return 0;
102+
}

lib/CMakeLists.txt

+28-25
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ set(ELEMENTS_SOURCES
2020
src/element/element.cpp
2121
src/element/floating.cpp
2222
src/element/flow.cpp
23-
src/element/style/button.cpp
24-
src/element/style/check_box.cpp
25-
src/element/style/icon_button.cpp
26-
src/element/style/menu.cpp
27-
src/element/style/radio_button.cpp
28-
src/element/style/slide_switch.cpp
29-
src/element/style/slider.cpp
30-
src/element/style/thumbwheel.cpp
3123
src/element/grid.cpp
3224
src/element/image.cpp
3325
src/element/label.cpp
@@ -37,11 +29,19 @@ set(ELEMENTS_SOURCES
3729
src/element/misc.cpp
3830
src/element/popup.cpp
3931
src/element/port.cpp
40-
src/element/progress_bar.cpp
4132
src/element/proxy.cpp
4233
src/element/range_slider.cpp
4334
src/element/selection.cpp
4435
src/element/slider.cpp
36+
src/element/status_bar.cpp
37+
src/element/style/button.cpp
38+
src/element/style/check_box.cpp
39+
src/element/style/icon_button.cpp
40+
src/element/style/menu.cpp
41+
src/element/style/radio_button.cpp
42+
src/element/style/slide_switch.cpp
43+
src/element/style/slider.cpp
44+
src/element/style/thumbwheel.cpp
4545
src/element/text.cpp
4646
src/element/thumbwheel.cpp
4747
src/element/tile.cpp
@@ -58,6 +58,9 @@ set(ELEMENTS_SOURCES
5858
src/support/text_utils.cpp
5959
src/support/theme.cpp
6060
src/support/payload.cpp
61+
src/support/receiver.cpp
62+
src/support/text_utils.cpp
63+
src/support/theme.cpp
6164
src/view.cpp
6265
)
6366

@@ -74,21 +77,6 @@ set(ELEMENTS_HEADERS
7477
include/elements/element/element.hpp
7578
include/elements/element/floating.hpp
7679
include/elements/element/flow.hpp
77-
include/elements/element/style.hpp
78-
include/elements/element/style/button.hpp
79-
include/elements/element/style/caption.hpp
80-
include/elements/element/style/check_box.hpp
81-
include/elements/element/style/thumbwheel.hpp
82-
include/elements/element/style/dialog.hpp
83-
include/elements/element/style/group.hpp
84-
include/elements/element/style/icon_button.hpp
85-
include/elements/element/style/menu.hpp
86-
include/elements/element/style/message_box.hpp
87-
include/elements/element/style/notebook.hpp
88-
include/elements/element/style/pane.hpp
89-
include/elements/element/style/radio_button.hpp
90-
include/elements/element/style/tab.hpp
91-
include/elements/element/style/text_entry.hpp
9280
include/elements/element/grid.hpp
9381
include/elements/element/image.hpp
9482
include/elements/element/indirect.hpp
@@ -100,12 +88,27 @@ set(ELEMENTS_HEADERS
10088
include/elements/element/misc.hpp
10189
include/elements/element/popup.hpp
10290
include/elements/element/port.hpp
103-
include/elements/element/progress_bar.hpp
10491
include/elements/element/proxy.hpp
10592
include/elements/element/range_slider.hpp
10693
include/elements/element/selection.hpp
10794
include/elements/element/size.hpp
10895
include/elements/element/slider.hpp
96+
include/elements/element/status_bar.hpp
97+
include/elements/element/style.hpp
98+
include/elements/element/style/button.hpp
99+
include/elements/element/style/caption.hpp
100+
include/elements/element/style/check_box.hpp
101+
include/elements/element/style/dialog.hpp
102+
include/elements/element/style/group.hpp
103+
include/elements/element/style/icon_button.hpp
104+
include/elements/element/style/menu.hpp
105+
include/elements/element/style/message_box.hpp
106+
include/elements/element/style/notebook.hpp
107+
include/elements/element/style/pane.hpp
108+
include/elements/element/style/radio_button.hpp
109+
include/elements/element/style/tab.hpp
110+
include/elements/element/style/text_entry.hpp
111+
include/elements/element/style/thumbwheel.hpp
109112
include/elements/element/text.hpp
110113
include/elements/element/thumbwheel.hpp
111114
include/elements/element/tile.hpp

lib/include/elements/element.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
#include <elements/element/misc.hpp>
2626
#include <elements/element/popup.hpp>
2727
#include <elements/element/port.hpp>
28-
#include <elements/element/progress_bar.hpp>
2928
#include <elements/element/proxy.hpp>
3029
#include <elements/element/range_slider.hpp>
3130
#include <elements/element/size.hpp>
3231
#include <elements/element/slider.hpp>
32+
#include <elements/element/status_bar.hpp>
3333
#include <elements/element/text.hpp>
3434
#include <elements/element/thumbwheel.hpp>
3535
#include <elements/element/tile.hpp>

0 commit comments

Comments
 (0)