diff options
-rw-r--r-- | demos/CMakeLists.txt | 2 | ||||
-rw-r--r-- | demos/scroll_view/CMakeLists.txt | 2 | ||||
-rw-r--r-- | demos/scroll_view/main.cpp | 85 | ||||
-rw-r--r-- | include/cru/ui/controls/ScrollView.hpp | 32 | ||||
-rw-r--r-- | src/ui/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/ui/controls/ScrollView.cpp | 19 |
6 files changed, 142 insertions, 0 deletions
diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index cf27d408..f3b4afde 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -6,6 +6,8 @@ endif() if(WIN32) # Currently only enable tests on Windows. add_subdirectory(main) + add_subdirectory(scroll_view) + add_subdirectory(input_method) endif() diff --git a/demos/scroll_view/CMakeLists.txt b/demos/scroll_view/CMakeLists.txt new file mode 100644 index 00000000..e9efe7d2 --- /dev/null +++ b/demos/scroll_view/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(demo_scroll_view main.cpp) +target_link_libraries(demo_scroll_view PRIVATE cru_demo_base cru_ui) diff --git a/demos/scroll_view/main.cpp b/demos/scroll_view/main.cpp new file mode 100644 index 00000000..f6b29934 --- /dev/null +++ b/demos/scroll_view/main.cpp @@ -0,0 +1,85 @@ +#include "cru/platform/gui/UiApplication.hpp" +#include "cru/ui/controls/ScrollView.hpp" +#include "cru/ui/controls/TextBlock.hpp" +#include "cru/ui/controls/Window.hpp" + +using cru::ui::controls::ScrollView; +using cru::ui::controls::TextBlock; +using cru::ui::controls::Window; + +int main() { + auto application = cru::platform::gui::CreateUiApplication(); + + auto window = Window::Create(); + + auto scroll_view = ScrollView::Create(); + + window->AddChild(scroll_view, 0); + + auto text_block = TextBlock::Create( + uR"([Verse 1] +The snow glows white on the mountain tonight +Not a footprint to be seen +A kingdom of isolation +And it looks like I'm the queen +The wind is howling like this swirling storm inside +Couldn't keep it in, Heaven knows I tried + +[Pre-Chorus] +Don't let them in, don't let them see +Be the good girl you always have to be +Conceal, don't feel, don't let them know +Well, now they know + +[Chorus] +Let it go, let it go +Can't hold it back anymore +Let it go, let it go +Turn away and slam the door +I don't care what they're going to say +Let the storm rage on +The cold never bothered me anyway + +[Verse 2] +It's funny how some distance +Makes everything seem small +And the fears that once controlled me +Can't get to me at all + +[Pre-Chorus] +It's time to see what I can do +To test the limits and break through +No right, no wrong, no rules for me +I'm free + +[Chorus] +Let it go, let it go +I'm one with the wind and sky +Let it go, let it go +You'll never see me cry +Here I stand, and here I'll stay +Let the storm rage on... + +[Bridge] +My power flurries through the air into the ground +My soul is spiraling in frozen fractals all around +And one thought crystallizes like an icy blast: +I'm never going back, the past is in the past! + +[Chorus] +Let it go, let it go +And I'll rise like the break of dawn +Let it go, let it go +That perfect girl is gone +Here I stand in the light of day +Let the storm rage on! +The cold never bothered me anyway)"); + + text_block->SetSelectable(true); + + scroll_view->SetChild(text_block); + + window->Show(); + + return application->Run(); +} diff --git a/include/cru/ui/controls/ScrollView.hpp b/include/cru/ui/controls/ScrollView.hpp new file mode 100644 index 00000000..93fd1712 --- /dev/null +++ b/include/cru/ui/controls/ScrollView.hpp @@ -0,0 +1,32 @@ +#pragma once +#include "ContentControl.hpp" +#include "cru/common/Base.hpp" +#include "cru/ui/render/RenderObject.hpp" +#include "cru/ui/render/ScrollRenderObject.hpp" + +#include <memory> +#include <string_view> + +namespace cru::ui::controls { +class ScrollView : public ContentControl { + public: + static ScrollView* Create() { return new ScrollView(); } + + static constexpr std::u16string_view control_type = u"ScrollView"; + + ScrollView(); + + CRU_DELETE_COPY(ScrollView) + CRU_DELETE_MOVE(ScrollView) + + ~ScrollView() override = default; + + public: + std::u16string_view GetControlType() const override { return control_type; } + + render::RenderObject* GetRenderObject() const override; + + private: + std::unique_ptr<render::ScrollRenderObject> scroll_render_object_; +}; +} // namespace cru::ui::controls diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index c8476acf..5d813911 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -18,6 +18,7 @@ add_library(cru_ui STATIC controls/NoChildControl.cpp controls/Popup.cpp controls/RootControl.cpp + controls/ScrollView.cpp controls/StackLayout.cpp controls/TextBlock.cpp controls/TextBox.cpp @@ -62,6 +63,7 @@ target_sources(cru_ui PUBLIC ${CRU_UI_INCLUDE_DIR}/controls/NoChildControl.hpp ${CRU_UI_INCLUDE_DIR}/controls/Popup.hpp ${CRU_UI_INCLUDE_DIR}/controls/RootControl.hpp + ${CRU_UI_INCLUDE_DIR}/controls/ScrollView.hpp ${CRU_UI_INCLUDE_DIR}/controls/StackLayout.hpp ${CRU_UI_INCLUDE_DIR}/controls/TextBlock.hpp ${CRU_UI_INCLUDE_DIR}/controls/TextBox.hpp diff --git a/src/ui/controls/ScrollView.cpp b/src/ui/controls/ScrollView.cpp new file mode 100644 index 00000000..66c1d620 --- /dev/null +++ b/src/ui/controls/ScrollView.cpp @@ -0,0 +1,19 @@ +#include "cru/ui/controls/ScrollView.hpp" + +#include "cru/ui/render/RenderObject.hpp" +#include "cru/ui/render/ScrollRenderObject.hpp" + +#include <memory> + +namespace cru::ui::controls { +ScrollView::ScrollView() { + scroll_render_object_ = std::make_unique<render::ScrollRenderObject>(); + scroll_render_object_->SetAttachedControl(this); + + SetContainerRenderObject(scroll_render_object_.get()); +} + +render::RenderObject* ScrollView::GetRenderObject() const { + return scroll_render_object_.get(); +} +} // namespace cru::ui::controls |