forked from hugoam/two
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Frame.h
121 lines (88 loc) · 3.53 KB
/
Frame.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright (c) 2019 Hugo Amiard [email protected]
// This software is provided 'as-is' under the zlib License, see the LICENSE.txt file.
// This notice and the license may not be removed or altered from any source distribution.
#pragma once
#ifndef TWO_MODULES
#include <stl/string.h>
#include <stl/memory.h>
#endif
#include <ui/Forward.h>
#include <ui/Frame/UiRect.h>
namespace two
{
using cstring = const char*;
enum DirtyLayout : unsigned int
{
CLEAN, // Frame doesn't need update
DIRTY_REDRAW, // The parent layout has changed
DIRTY_PARENT, // The parent layout has changed
DIRTY_LAYOUT, // The frame layout has changed
DIRTY_FORCE_LAYOUT // The frame layout has changed
};
export_ class refl_ TWO_UI_EXPORT Frame : public UiRect
{
public:
Frame(Frame* parent, Widget& widget);
virtual ~Frame();
bool empty() const;
inline bool opaque() const { return m_opacity == Opacity::Opaque; }
inline bool hollow() const { return m_opacity == Opacity::Hollow; }
void set_caption(cstring text);
void set_icon(Image* image);
Image* icon() const;
cstring caption() const;
void size_caption();
Frame& root();
Layer& layer();
FrameSolver& solver(Style& style, Axis length = Axis::None, v2<uint> index = { 0, 0 });
DirtyLayout clearDirty() { DirtyLayout dirty = d_dirty; d_dirty = CLEAN; return dirty; }
void set_dirty(DirtyLayout dirty) { if(dirty > d_dirty) d_dirty = dirty; }
void mark_dirty(DirtyLayout dirty);
void update_style(bool reset = false);
void update_state(WidgetState state);
void update_inkstyle(InkStyle& inkstyle, bool reset = false);
void set_size(Axis dim, float size);
void set_span(Axis dim, float span);
void set_position(Axis dim, float position);
inline void set_position(const vec2& pos) { set_position(Axis::X, pos.x), set_position(Axis::Y, pos.y); }
inline void set_size(const vec2& size) { set_size(Axis::X, size.x); set_size(Axis::Y, size.y); }
// global to local
void integrate_position(Frame& root, vec2& global);
inline vec2 integrate_position(const vec2& pos, Frame& root) { vec2 local = pos; integrate_position(root, local); return local; }
inline vec2 local_position(const vec2& pos) { return integrate_position(pos, root()); }
// local to global
void derive_position(Frame& root, vec2& local);
inline vec2 derive_position(const vec2& pos, Frame& root) { vec2 local = pos; derive_position(root, local); return local; }
inline vec2 derive_position(const vec2& pos) { return derive_position(pos, root()); }
inline vec2 absolute_position() { return derive_position({ 0.f, 0.f }); }
float derive_scale(Frame& root);
inline float absolute_scale() { return this->derive_scale(root()); }
void clamp_to_parent();
vec4 content_rect() const;
bool inside(const vec2& pos);
bool inside_abs(const vec2& pos) { return this->inside(local_position(pos)); }
bool first(const Frame& frame);
bool last(const Frame& frame);
void transfer_pixel_span(Frame& prev, Frame& next, Axis dim, float pixelSpan);
void relayout();
void sync_solver(FrameSolver& solver);
void read_solver(FrameSolver& solver);
void debug_print(bool commit);
public:
Widget& d_widget;
Frame* d_parent;
DirtyLayout d_dirty = DIRTY_FORCE_LAYOUT;
v2<uint> d_index = { 0, 0 };
Opacity m_opacity = Opacity::Clear;
Style* d_style = nullptr;
Layout* d_layout = nullptr;
InkStyle* d_inkstyle = nullptr;
public:
string d_caption = "";
Image* d_icon = nullptr;
unique<FrameSolver> m_solver;
unique<Layer> m_layer;
unique<Text> m_text;
static Vg* s_vg;
};
}