GigaPasjans
Loading...
Searching...
No Matches
SelectionTextComponent.h
1// Plik utworzony przez Piotra ChudziƄskiego w dniu 11.04.2025
2#pragma once
3
4#include <phosphorus/Languages.h>
5#include "andromenda/Component.h"
6
7namespace Andromenda
8{
13 class SelectionTextComponent : public Component
14 {
15 protected:
17 Int2 getSize() override { return Int2{Text.GetLength(), 2}; }
18
19 public:
25
26 explicit SelectionTextComponent(const WideString &text) : Text(text) {}
27
29 bool IsSelectable() const override { return true; }
30
32 void ProvideActions(ActionRegistry &registry) override
33 {
34 registry.Register(Keycode::Enter, _TW("select"), [this] { m_Callback(m_Id); }, MouseButton::Left);
35 }
36
38 void Draw(DrawContext &context) override
39 {
40 context.StyleStack.Push(TerminalStyle{Color::White, m_IsActive ? Color::Green : Color::Black});
41 context.Put(Text, GetBounds().GetPosition());
42 context.StyleStack.Pop();
43 }
44 };
45} // namespace Andromenda
Represent registry of Action objects.
Definition ActionRegistry.h:74
void Register(const Keycode &keycode, const WideString &actionText, const Callback &callback, MouseButton button=MouseButton::None)
Registers given text and callback to given key.
Definition ActionRegistry.cpp:18
Represents a renderable identified object.
Definition Component.h:23
ComponentCallback m_Callback
Action component callback.
Definition Component.h:50
bool m_IsActive
A value indicating, whether object is being pointed by pointer.
Definition Component.h:32
Box GetBounds()
Returns Component bounds. Position is already aligned.
Definition Components.cpp:27
String m_Id
Object identifier, that is unique per ComponentRegistry.
Definition Component.h:44
bool IsSelectable() const override
Returns value indicating, whether component is selectable.
Definition SelectionTextComponent.h:29
void ProvideActions(ActionRegistry &registry) override
Provides own actions to the ActionRegistry.
Definition SelectionTextComponent.h:32
Int2 getSize() override
Returns size of a component.
Definition SelectionTextComponent.h:17
void Draw(DrawContext &context) override
Draws self.
Definition SelectionTextComponent.h:38
WideString Text
Text that should be drawed on screen.
Definition SelectionTextComponent.h:24
void Pop()
Pops style at the top.
Definition TerminalBase.cpp:45
void Push(const TerminalStyle &style)
Pushes given style to the top.
Definition TerminalBase.cpp:43
Represents a mutable sequence of utf-16 characters, providing various member functions for string man...
Definition WideString.h:14
A utility which contains all essential class instances and functions for rendering objects.
Definition DrawContext.h:14
void Put(const String &text, Int2 position)
Puts a UTF-8 text at given position and with given text.
Definition DrawContext.cpp:7
StyleStack StyleStack
Style stack.
Definition DrawContext.h:31
Represents terminal text style, described by background and foreground color.
Definition Terminal.h:20
Represents a two component vector. Components are 32-bit and they are signed.
Definition Int2.h:11