Skip to content

Commit

Permalink
Develop document.
Browse files Browse the repository at this point in the history
  • Loading branch information
crupest committed Dec 16, 2023
1 parent e1061e0 commit 8f7505d
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 5 deletions.
12 changes: 10 additions & 2 deletions include/cru/ui/document/DocumentElementType.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
#pragma once

#include "../Base.h"
#include "cru/common/String.h"

#include "../Base.h"
#include <vector>

namespace cru::ui::document {
class CRU_UI_API DocumentElementType : public Object {
public:
explicit DocumentElementType(String name);
explicit DocumentElementType(String name,
std::vector<DocumentElementType*> parents);

~DocumentElementType() override;

public:
String GetName() const { return name_; }
const std::vector<DocumentElementType*>& GetParents() const {
return parents_;
}

private:
String name_;
std::vector<DocumentElementType*> parents_;
};

struct CRU_UI_API DocumentElementTypes {
static DocumentElementType* const kBaseElementType;
static DocumentElementType* const kRootElementType;
static DocumentElementType* const kTextElementType;
};

} // namespace cru::ui::document
45 changes: 45 additions & 0 deletions include/cru/ui/document/TextDocumentElement.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include "../Base.h"
#include "DocumentElement.h"
#include "cru/common/Base.h"
#include "cru/common/Bitmask.h"

namespace cru::ui::document {
namespace details {
struct TextStyleTag {};
} // namespace details

using TextStyle = Bitmask<details::TextStyleTag>;

struct TextStyles {
static constexpr TextStyle Normal;
static constexpr TextStyle Bold{0x1};
static constexpr TextStyle Italic{0x2};
};

struct IDocumentLink : virtual Interface {
virtual void Open() = 0;
};

class CRU_UI_API TextDocumentElement : public DocumentElement {
public:
TextDocumentElement(String text, TextStyle style, IDocumentLink* link);

~TextDocumentElement() override;

String GetText() const { return text_; }
void SetText(String text);

TextStyle GetStyle() const { return style_; }
void SetStyle(TextStyle style);

IDocumentLink* GetLink() const { return link_; }
void SetLink(IDocumentLink link);

private:
String text_;
TextStyle style_;
IDocumentLink* link_;
};
} // namespace cru::ui::document
1 change: 1 addition & 0 deletions src/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_library(CruUi
controls/Window.cpp
document/DocumentElement.cpp
document/DocumentElementType.cpp
document/TextDocumentElement.cpp
events/MouseEventArgs.cpp
helper/ClickDetector.cpp
helper/ShortcutHub.cpp
Expand Down
14 changes: 11 additions & 3 deletions src/ui/document/DocumentElementType.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#include "cru/ui/document/DocumentElementType.h"

#include <utility>
#include <vector>

namespace cru::ui::document {
DocumentElementType::DocumentElementType(String name)
: name_(std::move(name)) {}
DocumentElementType::DocumentElementType(
String name, std::vector<DocumentElementType*> parents)
: name_(std::move(name)), parents_(std::move(parents)) {}

DocumentElementType::~DocumentElementType() {}

DocumentElementType* const DocumentElementTypes::kBaseElementType =
new DocumentElementType(u"Base", {});

DocumentElementType* const DocumentElementTypes::kRootElementType =
new DocumentElementType(u"Root");
new DocumentElementType(u"Root", {kBaseElementType});

DocumentElementType* const DocumentElementTypes::kTextElementType =
new DocumentElementType(u"Text", {kBaseElementType});
} // namespace cru::ui::document
17 changes: 17 additions & 0 deletions src/ui/document/TextDocumentElement.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "cru/ui/document/TextDocumentElement.h"
#include "cru/common/String.h"
#include "cru/ui/document/DocumentElement.h"
#include "cru/ui/document/DocumentElementType.h"

namespace cru::ui::document {
TextDocumentElement::TextDocumentElement(String text, TextStyle style,
IDocumentLink* link)
: DocumentElement(DocumentElementTypes::kTextElementType),
text_(std::move(text)),
style_(style),
link_(link) {}

TextDocumentElement::~TextDocumentElement() {}

void TextDocumentElement::SetText(String text) { text_ = std::move(text); }
} // namespace cru::ui::document

0 comments on commit 8f7505d

Please sign in to comment.