Something went wrong. Try again.
art software for the rest of us
drawing paint image sdl art
Something went wrong. Try again.
C++
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110#include "ProjectsScreen.h"#include "MaterialIcons.h"#include "../Widgets/IconButton.h"#include "../Widgets/Panel.h"#include "../Widgets/ArtworkCard.h"#include "../ManagementContext/ArtworkManagementContext.h"#include "../Widgets/ScrollArea.h"#include "../UserInterface/Layout/StackLayout.h"#include "../UserInterface/Layout/VirtualizingGridLayout.h"#include "../UserInterface/Layout/VirtualizingStackLayout.h"#include "../AppLayers/ScreenLayer.h"#include "Widgets/Widget.h"#include <memory>
ProjectsScreen::ProjectsScreen() : Screen(nullptr), currentArtwork(nullptr) { rootWidget = CreateRoot(); dirtyManager.SetRootWidget(rootWidget.get()); inputRouter.SetRootWidget(rootWidget.get());}
ProjectsScreen::ProjectsScreen(Artwork* openTarget) : Screen(nullptr), currentArtwork(openTarget) { rootWidget = CreateRoot(); dirtyManager.SetRootWidget(rootWidget.get()); inputRouter.SetRootWidget(rootWidget.get());}
ProjectsScreen::~ProjectsScreen() { rootWidget.reset();}
std::unique_ptr<UI::Widget> ProjectsScreen::CreateRoot() { auto root = std::make_unique<UI::StackLayout>(UI::Orientation::Vertical, 0.0f); root->AddChild(CreateHeader()); root->AddChild(CreateProjects()); return root;}
std::unique_ptr<UI::Widget> ProjectsScreen::CreateHeader() { auto panel = std::make_unique<UI::Panel>(); panel->SetBgColor(UI::Color(0, 0, 0, 1.0f)); panel->SetVerticalAlignment(UI::VerticalAlignment::Center); panel->SetPadding(UI::Thickness(24.0f, 12.0f));
auto layout = std::make_unique<UI::StackLayout>(UI::Orientation::Horizontal, 0.0f); layout->SetVerticalAlignment(UI::VerticalAlignment::Center); auto spacer = std::make_unique<UI::Widget>(); spacer->SetHorizontalAlignment(UI::HorizontalAlignment::Stretch); spacer->SetMaxSize(UI::Size(1000000.0f, 1000000.0f)); layout->AddChild(std::make_unique<UI::IconButton>(ICON_MS_ARROW_BACK, "Back", [](){ ScreenLayer::CloseScreen(); } )); layout->AddChild(std::move(spacer)); layout->AddChild(std::make_unique<UI::IconButton>(ICON_MS_ADD, "Create")); layout->AddChild(std::make_unique<UI::IconButton>(ICON_MS_PUBLISH, "Publish")); // profesional sharing, integrates with atproto, also can share multiple artworks as once serverside artwork? unsure on design, REVISIT: once we go networking if (currentArtwork) { layout->AddChild(std::make_unique<UI::IconButton>(ICON_MS_SHARE, "Share")); // simple sharing, copy as png or open system share sheet layout->AddChild(std::make_unique<UI::IconButton>(ICON_MS_PLAY_ARROW, "Replay")); // implemented, eventually™ } layout->AddChild(std::make_unique<UI::IconButton>(ICON_MS_MORE_HORIZ, "Menu")); // manage importing and location layout->AddChild(std::make_unique<UI::IconButton>(ICON_MS_INFO, "Info")); // show full gallery information/artwork information if (currentArtwork) { layout->AddChild(std::make_unique<UI::IconButton>(ICON_MS_EDIT_SQUARE, "Edit")); } panel->AddChild(std::move(layout)); return panel;}
std::unique_ptr<UI::Widget> ProjectsScreen::CreateProjects() { const auto artworks = ArtworkManagementContext::GetAll(); if (!currentArtwork) { auto layout = std::make_unique<UI::VirtualizingGridLayout>( artworks.size(), 220.0f, 24.0f, 164.0f, 240.0f, [artworks](std::size_t index) { return UI::ArtworkCard::GetSizeForArtwork(artworks[index], true); }, [artworks](std::size_t index) { return std::make_unique<UI::ArtworkCard>(artworks[index], true, UI::ArtworkCardSizeMode::Fill); } ); auto scrollable = std::make_unique<UI::ScrollArea>(UI::OverflowFlags::Vertical); scrollable->SetPadding(UI::Thickness(32.0f, 24.0f)); scrollable->AddChild(std::move(layout)); return scrollable; }
auto layout = std::make_unique<UI::VirtualizingStackLayout>( artworks.size(), 0.0f, 200.0f, nullptr, // PERCHANCE: maybe we use nullptr as a signal for fill instead? [artworks](std::size_t index) { return std::make_unique<UI::ArtworkCard>(artworks[index], true, UI::ArtworkCardSizeMode::FillExtra); }, UI::VirtualizingStackSizing::Fill ); auto scrollable = std::make_unique<UI::ScrollArea>(UI::OverflowFlags::Horizontal, artworks.size() - 1); scrollable->SetPadding(UI::Thickness(0.0f, 24.0f)); // 32 scrollable->AddChild(std::move(layout)); auto it = std::find(artworks.begin(), artworks.end(), currentArtwork); scrollable->SetPage(it - artworks.begin()); return scrollable;}