dl
dl_ui_button_text_color.h
浏览该文件的文档.
1
12#pragma once
13
14#ifndef DL_DISABLE_RENDER
16#include "render/dl_sprite.h"
17#include "render/dl_text.h"
18
19namespace dl::UI
20{
21
23class ButtonTextColor : public Button
24{
25public:
32 static ButtonTextColor* Create(gcText txt, const std::vector<Color>& mul_col, const std::vector<Position>& mul_offset)
33 {
34 ButtonTextColor* ret = new ButtonTextColor;
35 ret->_create(txt, mul_col, mul_offset);
37 return ret;
38 }
39
40 virtual ButtonTextColor* Clone() override;
41
42 void SetString(std::string_view str)
43 {
44 _txt->SetString(str);
45 }
46
47
48 virtual bool IsPickup() override
49 {
50 return _txt->IsPickup();
51 }
52 virtual void SetOrder(float order) override
53 {
54 _txt->SetOrder(Math::OffsetOrder(order, 0, 0, 0));
55 }
56 virtual float GetOrder() override
57 {
58 return _txt->GetOrder();
59 }
60 virtual Position GetSize() override { return toPosition(_txt->GetSize()); }
61 virtual Position GetAnchor() override { return {}; }
62 virtual void RenderDebug() override {}
63
65 {
66
67 }
68private:
70 _col{ColorDef::WHITE, ColorDef::GREEN, ColorDef::BLUE, ColorDef::GRAY, ColorDef::GRAY },
71 _offset{}
72 {}
73
74 void _create(gcText txt, const std::vector<Color>& mul_col, const std::vector<Position>& mul_offset);
75
76 gcText _txt;
77 std::array<Color, 5> _col;
78 std::array<Position, 5> _offset;
79
80 virtual void UpdateChild(State state_pre, State state) override
81 {
82 size_t index = GetIndex(state);
83 _txt->SetColor(_col[index]);
84 _txt->SetCenter(_offset[index]);
85 }
86 virtual void RenderChild(State state_pre, State state) override
87 {
88 _txt->Render();
89 }
90
91 void _update_coor()
92 {
93 _txt->GetCoor()->SetParent(_coor);
94 }
95};
96
97}
98
99#endif
void Render()
绘制
void SetColor(const Color &col, TextParam type=TextParam::NORMAL)
设置颜色
void SetCenter(const Position &pos={})
设置Coor位置,并根据整体大小居中
std::size_t GetIndex(State state)
返回索引
void SetString(std::string_view str)
virtual Position GetAnchor() override
virtual ButtonTextColor * Clone() override
必须实现的函数
virtual void SetOrder(float order) override
static ButtonTextColor * Create(gcText txt, const std::vector< Color > &mul_col, const std::vector< Position > &mul_offset)
文本按钮,可变色
virtual Position GetSize() override
2d绘图元素
文本绘制
UI系统之按钮基类
颜色预定义
constexpr float OffsetOrder(float order, int u=1, int v=0, int w=0)
偏移order
Position2 Position
constexpr Array< Position::value_type, N > toPosition(const Array< T, N > &a)
转换到Position,已知长度
constexpr float Z_DEFAULT_UI
GC< Text > gcText