-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,060 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
cmake_minimum_required(VERSION 3.9.6...3.15.0) | ||
project(DynamicLists LANGUAGES C CXX VERSION "1.0.0") | ||
|
||
if (NOT ELEMENTS_ROOT) | ||
message(FATAL_ERROR "ELEMENTS_ROOT is not set") | ||
endif() | ||
|
||
# Make sure ELEMENTS_ROOT is an absolute path to add to the CMake module path | ||
get_filename_component(ELEMENTS_ROOT "${ELEMENTS_ROOT}" ABSOLUTE) | ||
set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${ELEMENTS_ROOT}/cmake") | ||
|
||
# If we are building outside the project, you need to set ELEMENTS_ROOT: | ||
if (NOT ELEMENTS_BUILD_EXAMPLES) | ||
include(ElementsConfigCommon) | ||
set(ELEMENTS_BUILD_EXAMPLES OFF) | ||
add_subdirectory(${ELEMENTS_ROOT} elements) | ||
endif() | ||
|
||
set(ELEMENTS_APP_PROJECT "SelectionList") | ||
set(ELEMENTS_APP_TITLE "Selection List") | ||
set(ELEMENTS_APP_COPYRIGHT "Copyright (c) 2016-2024 Joel de Guzman") | ||
set(ELEMENTS_APP_ID "com.cycfi.selection_list") | ||
set(ELEMENTS_APP_VERSION "1.0") | ||
|
||
set(ELEMENTS_APP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) | ||
|
||
# For your custom application icon on macOS or Windows see cmake/AppIcon.cmake module | ||
include(AppIcon) | ||
include(ElementsConfigApp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/*================================================================================================= | ||
Copyright (c) 2016-2024 Joel de Guzman | ||
Distributed under the MIT License (https://opensource.org/licenses/MIT) | ||
=================================================================================================*/ | ||
#include <elements.hpp> | ||
|
||
using namespace cycfi::elements; | ||
using namespace cycfi::artist; | ||
|
||
// Main window background color | ||
auto constexpr bkd_color = rgba(35, 35, 37, 255); | ||
auto background = box(bkd_color); | ||
|
||
struct my_element : element, selectable | ||
{ | ||
my_element(int n) | ||
: _n{n} | ||
{} | ||
|
||
void draw(context const& ctx) override | ||
{ | ||
auto& cnv = ctx.canvas; | ||
auto state = cnv.new_state(); | ||
auto const& theme_ = get_theme(); | ||
|
||
if (_is_selected) | ||
{ | ||
cnv.begin_path(); | ||
cnv.add_rect(ctx.bounds); | ||
cnv.fill_style(theme_.indicator_color.opacity(0.6)); | ||
cnv.fill(); | ||
} | ||
|
||
auto middle = ctx.bounds.top + (ctx.bounds.height()/2); | ||
cnv.fill_style(theme_.label_font_color); | ||
cnv.font(theme_.label_font); | ||
cnv.text_align(cnv.left | cnv.middle); | ||
cnv.fill_text(std::string{"Item "} + std::to_string(_n), point{ctx.bounds.left+10, middle}); | ||
} | ||
|
||
bool is_selected() const override | ||
{ | ||
return _is_selected; | ||
} | ||
|
||
void select(bool state) override | ||
{ | ||
_is_selected = state; | ||
} | ||
|
||
int _n; | ||
bool _is_selected = false; | ||
}; | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
app _app(argc, argv, "Selection Lists", "com.cycfi.selection_lists"); | ||
window _win(_app.name()); | ||
_win.on_close = [&_app]() { _app.stop(); }; | ||
|
||
view view_(_win); | ||
|
||
auto&& draw_cell = | ||
[](std::size_t index) | ||
{ | ||
return share( | ||
margin({20, 0, 20, 0}, | ||
align_left( | ||
vsize(25, my_element(index+1)) | ||
) | ||
) | ||
); | ||
}; | ||
|
||
auto my_composer = | ||
basic_cell_composer( | ||
200, // size (number of rows) | ||
draw_cell // Composer function | ||
); | ||
|
||
auto content = share( | ||
selection_list( | ||
list{my_composer, false} | ||
) | ||
); | ||
|
||
view_.content( | ||
vscroller(hold(content)), | ||
background | ||
); | ||
|
||
_app.run(); | ||
return 0; | ||
} |
Oops, something went wrong.