Compare commits
4
Commits
9e27dfb0eb
...
7e0f3a6bf6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e0f3a6bf6
|
||
|
|
1ae4d0cd46
|
||
|
|
420edd0677
|
||
|
|
e8a9055090
|
@@ -42,6 +42,10 @@ class PD_API Drawlist {
|
|||||||
void Copy(Drawlist& other);
|
void Copy(Drawlist& other);
|
||||||
void Optimize();
|
void Optimize();
|
||||||
void Clear();
|
void Clear();
|
||||||
|
void SetLayer(int layer) { pCurrentLayer = layer; }
|
||||||
|
void LayerUp() { pCurrentLayer++; }
|
||||||
|
void LayerDown() { pCurrentLayer--; }
|
||||||
|
int GetLayer() const { return pCurrentLayer; }
|
||||||
|
|
||||||
size_t GetNumVertices() const {
|
size_t GetNumVertices() const {
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
@@ -126,6 +130,7 @@ class PD_API Drawlist {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Texture pCurrentTexture;
|
Texture pCurrentTexture;
|
||||||
|
int pCurrentLayer = 0;
|
||||||
Pool<Command> pCommands;
|
Pool<Command> pCommands;
|
||||||
Pool<fvec2> pPath;
|
Pool<fvec2> pPath;
|
||||||
Pool<Vertex> pVertices;
|
Pool<Vertex> pVertices;
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ class PD_API Container {
|
|||||||
void Init(UI7::IO* io, Li::Drawlist* l) {
|
void Init(UI7::IO* io, Li::Drawlist* l) {
|
||||||
list = l;
|
list = l;
|
||||||
this->io = io;
|
this->io = io;
|
||||||
|
pFont = io->Font;
|
||||||
// this->screen = io->Ren->CurrentScreen();
|
// this->screen = io->Ren->CurrentScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +76,7 @@ class PD_API Container {
|
|||||||
fvec2 GetPos() { return pos; }
|
fvec2 GetPos() { return pos; }
|
||||||
/** Getter for Size */
|
/** Getter for Size */
|
||||||
fvec2 GetSize() { return size; }
|
fvec2 GetSize() { return size; }
|
||||||
|
Li::Font* GetFont() { return pFont; }
|
||||||
/**
|
/**
|
||||||
* Get the Containers Final Position
|
* Get the Containers Final Position
|
||||||
* for Rendering and Input (if it has a parent Object)
|
* for Rendering and Input (if it has a parent Object)
|
||||||
@@ -193,6 +195,7 @@ class PD_API Container {
|
|||||||
fvec4 pClipRect;
|
fvec4 pClipRect;
|
||||||
/** Clip Rect used */
|
/** Clip Rect used */
|
||||||
bool pCLipRectUsed = false;
|
bool pCLipRectUsed = false;
|
||||||
|
Li::Font* pFont = nullptr;
|
||||||
};
|
};
|
||||||
} // namespace UI7
|
} // namespace UI7
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ enum UI7MenuFlags_ {
|
|||||||
enum UI7LayoutFlags_ {
|
enum UI7LayoutFlags_ {
|
||||||
UI7LayoutFlags_None = 0, ///< No Flags used
|
UI7LayoutFlags_None = 0, ///< No Flags used
|
||||||
UI7LayoutFlags_UseClipRect = 1 << 0, ///< Enable ClipRect
|
UI7LayoutFlags_UseClipRect = 1 << 0, ///< Enable ClipRect
|
||||||
|
UI7LayoutFlags_HzScrolling = 1 << 1, ///< Scrolling Horizontal
|
||||||
|
UI7LayoutFlags_VtScrolling = 1 << 2, ///< Scrolling Vertical
|
||||||
};
|
};
|
||||||
|
|
||||||
/** UI7 Context Flags */
|
/** UI7 Context Flags */
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ class PD_API IO {
|
|||||||
u32 NumVertices = 0; ///< Debug Vertices Num
|
u32 NumVertices = 0; ///< Debug Vertices Num
|
||||||
u32 NumIndices = 0; ///< Debug Indices Num
|
u32 NumIndices = 0; ///< Debug Indices Num
|
||||||
std::vector<u32> MenuOrder;
|
std::vector<u32> MenuOrder;
|
||||||
|
std::vector<Li::Font*> FontStack;
|
||||||
|
|
||||||
// Pools
|
// Pools
|
||||||
PD::Pool<UI7::Label> LabelPool;
|
PD::Pool<UI7::Label> LabelPool;
|
||||||
@@ -107,6 +108,18 @@ class PD_API IO {
|
|||||||
return ViewPorts[id.RawID()];
|
return ViewPorts[id.RawID()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PushFont(Li::Font* f) {
|
||||||
|
FontStack.push_back(Font);
|
||||||
|
Font = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PopFont() {
|
||||||
|
if (!FontStack.empty()) {
|
||||||
|
Font = FontStack.back();
|
||||||
|
FontStack.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UI7::InputHandler InputHandler;
|
UI7::InputHandler InputHandler;
|
||||||
};
|
};
|
||||||
} // namespace UI7
|
} // namespace UI7
|
||||||
|
|||||||
@@ -127,6 +127,8 @@ class PD_API Layout {
|
|||||||
void CursorInit();
|
void CursorInit();
|
||||||
void SameLine();
|
void SameLine();
|
||||||
void CursorMove(const fvec2& size);
|
void CursorMove(const fvec2& size);
|
||||||
|
void PushFont(Li::Font* f) { IO.PushFont(f); }
|
||||||
|
void PopFont() { IO.PopFont(); }
|
||||||
|
|
||||||
bool ObjectWorkPos(fvec2& movpos);
|
bool ObjectWorkPos(fvec2& movpos);
|
||||||
|
|
||||||
@@ -163,6 +165,8 @@ class PD_API Layout {
|
|||||||
void SetAlign(UI7Align a) { Alignment = a; }
|
void SetAlign(UI7Align a) { Alignment = a; }
|
||||||
void NextAlign(UI7Align a) { TempAlign = a; }
|
void NextAlign(UI7Align a) { TempAlign = a; }
|
||||||
|
|
||||||
|
void HandleScrolling();
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
fvec2 DbgScrollOffset() { return ScrollOffset; }
|
fvec2 DbgScrollOffset() { return ScrollOffset; }
|
||||||
|
|||||||
@@ -110,7 +110,6 @@ class PD_API Menu {
|
|||||||
void EndTreeNode();
|
void EndTreeNode();
|
||||||
|
|
||||||
void HandleFocus();
|
void HandleFocus();
|
||||||
void HandleScrolling();
|
|
||||||
void HandleTitlebarActions();
|
void HandleTitlebarActions();
|
||||||
void DrawBaseLayout();
|
void DrawBaseLayout();
|
||||||
|
|
||||||
@@ -120,6 +119,9 @@ class PD_API Menu {
|
|||||||
}
|
}
|
||||||
Container* FindObject(u32 id) { return pLayout.FindObject(id); }
|
Container* FindObject(u32 id) { return pLayout.FindObject(id); }
|
||||||
|
|
||||||
|
void PushFont(Li::Font* f) { pIO.PushFont(f); }
|
||||||
|
void PopFont() { pIO.PopFont(); }
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
void SetSize(PD::fvec2 size) { pLayout.SetSize(size); }
|
void SetSize(PD::fvec2 size) { pLayout.SetSize(size); }
|
||||||
|
|||||||
@@ -12,12 +12,20 @@ PD_API Drawlist::Drawlist() { Clear(); }
|
|||||||
PD_API Drawlist::~Drawlist() { Clear(); }
|
PD_API Drawlist::~Drawlist() { Clear(); }
|
||||||
|
|
||||||
PD_API void Drawlist::Merge(Drawlist& other) {
|
PD_API void Drawlist::Merge(Drawlist& other) {
|
||||||
|
size_t start = pCommands.size();
|
||||||
pCommands.AppendMove(other.pCommands);
|
pCommands.AppendMove(other.pCommands);
|
||||||
|
for (size_t i = start; i < pCommands.size(); i++) {
|
||||||
|
pCommands[i].Layer += this->pCurrentLayer;
|
||||||
|
}
|
||||||
other.Clear();
|
other.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_API void Drawlist::Copy(Drawlist& other) {
|
PD_API void Drawlist::Copy(Drawlist& other) {
|
||||||
|
int start = pCommands.size();
|
||||||
pCommands.AppendCopy(other.pCommands);
|
pCommands.AppendCopy(other.pCommands);
|
||||||
|
for (size_t i = start; i < pCommands.size(); i++) {
|
||||||
|
pCommands[i].Layer += this->pCurrentLayer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_API void Drawlist::Optimize() {
|
PD_API void Drawlist::Optimize() {
|
||||||
@@ -34,12 +42,14 @@ PD_API void Drawlist::Clear() {
|
|||||||
UnbindTexture();
|
UnbindTexture();
|
||||||
pPath.ResetFast();
|
pPath.ResetFast();
|
||||||
pCommands.NoReset();
|
pCommands.NoReset();
|
||||||
|
pCurrentLayer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Command Allocation */
|
/** Command Allocation */
|
||||||
PD_API Command& Drawlist::NewCommand() {
|
PD_API Command& Drawlist::NewCommand() {
|
||||||
auto cmd = pCommands.Allocate(1);
|
auto cmd = pCommands.Allocate(1);
|
||||||
cmd->Reset();
|
cmd->Reset();
|
||||||
|
cmd->Layer = pCurrentLayer;
|
||||||
cmd->Tex = pCurrentTexture.GetID();
|
cmd->Tex = pCurrentTexture.GetID();
|
||||||
return *cmd;
|
return *cmd;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -288,7 +288,8 @@ PD_API void Font::CmdTextEx(Drawlist& dl, const fvec2& pos, u32 color,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cp.Size.x > 0 && cp.Size.y > 0) {
|
if (cp.Size.x > 0 && cp.Size.y > 0) {
|
||||||
if (cmd == nullptr || cmd->Tex != Textures[cp.Tex]) {
|
if (cmd == nullptr || cmd->Tex != Textures[cp.Tex] ||
|
||||||
|
cmd->Layer != dl.GetLayer()) {
|
||||||
if (cp.Tex >= Textures.size()) continue;
|
if (cp.Tex >= Textures.size()) continue;
|
||||||
cmd = &dl.NewCommand();
|
cmd = &dl.NewCommand();
|
||||||
cmd->Tex = Textures[cp.Tex];
|
cmd->Tex = Textures[cp.Tex];
|
||||||
|
|||||||
@@ -49,12 +49,13 @@ PD_API void Button::HandleInput() {
|
|||||||
PD_API void Button::Draw() {
|
PD_API void Button::Draw() {
|
||||||
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
|
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
|
||||||
// io->Ren->OnScreen(screen);
|
// io->Ren->OnScreen(screen);
|
||||||
|
list->SetFont(GetFont());
|
||||||
list->PathRect(FinalPos(), FinalPos() + size, io->FrameRounding);
|
list->PathRect(FinalPos(), FinalPos() + size, io->FrameRounding);
|
||||||
list->PathFill(io->Theme.Get(color));
|
list->PathFill(io->Theme.Get(color));
|
||||||
// list->LayerUp();
|
list->LayerUp();
|
||||||
list->DrawText(FinalPos() + size * 0.5 - tdim * 0.5, label.c_str(),
|
list->DrawText(FinalPos() + size * 0.5 - tdim * 0.5, label.c_str(),
|
||||||
io->Theme.Get(UI7Color_Text));
|
io->Theme.Get(UI7Color_Text));
|
||||||
// list->LayerDown();
|
list->LayerDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_API void Button::Update() {
|
PD_API void Button::Update() {
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ PD_API void Checkbox::HandleInput() {
|
|||||||
PD_API void Checkbox::Draw() {
|
PD_API void Checkbox::Draw() {
|
||||||
// Assert(list.get() && io.get(), "Did you run Container::Init correctly?");
|
// Assert(list.get() && io.get(), "Did you run Container::Init correctly?");
|
||||||
// io->Ren->OnScreen(screen);
|
// io->Ren->OnScreen(screen);
|
||||||
|
list->SetFont(GetFont());
|
||||||
list->PathRect(FinalPos(), FinalPos() + cbs, io->FrameRounding);
|
list->PathRect(FinalPos(), FinalPos() + cbs, io->FrameRounding);
|
||||||
list->PathFill(io->Theme.Get(color));
|
list->PathFill(io->Theme.Get(color));
|
||||||
if (usr_ref) {
|
if (usr_ref) {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ PD_API void ColorEdit::HandleInput() {
|
|||||||
PD_API void ColorEdit::Draw() {
|
PD_API void ColorEdit::Draw() {
|
||||||
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
|
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
|
||||||
// io->Ren->OnScreen(screen);
|
// io->Ren->OnScreen(screen);
|
||||||
|
list->SetFont(GetFont());
|
||||||
list->PathRect(FinalPos(), FinalPos() + io->ItemRowHeight, io->FrameRounding);
|
list->PathRect(FinalPos(), FinalPos() + io->ItemRowHeight, io->FrameRounding);
|
||||||
list->PathFill(*color_ref);
|
list->PathFill(*color_ref);
|
||||||
list->DrawText(FinalPos() + fvec2(io->ItemSpace.x + io->ItemRowHeight, 0),
|
list->DrawText(FinalPos() + fvec2(io->ItemSpace.x + io->ItemRowHeight, 0),
|
||||||
@@ -55,16 +56,19 @@ PD_API void ColorEdit::Draw() {
|
|||||||
layout->SetPosition(FinalPos());
|
layout->SetPosition(FinalPos());
|
||||||
DynObj* r = io->DynObjPool.Allocate();
|
DynObj* r = io->DynObjPool.Allocate();
|
||||||
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
|
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
|
||||||
|
list->SetFont(thiz->GetFont());
|
||||||
thiz->SetSize(layout->GetSize());
|
thiz->SetSize(layout->GetSize());
|
||||||
// l->Layer(30);
|
// l->Layer(30);
|
||||||
l->PathRect(thiz->GetPos(), thiz->GetPos() + thiz->GetSize(),
|
l->PathRect(thiz->GetPos(), thiz->GetPos() + thiz->GetSize(),
|
||||||
io->FrameRounding);
|
io->FrameRounding);
|
||||||
l->PathFill(io->Theme.Get(UI7Color_FrameBackground));
|
l->PathFill(io->Theme.Get(UI7Color_FrameBackground));
|
||||||
|
l->SetLayer(0);
|
||||||
});
|
});
|
||||||
layout->AddObjectEx(r, UI7LytAdd_Front | UI7LytAdd_NoCursorUpdate |
|
layout->AddObjectEx(r, UI7LytAdd_Front | UI7LytAdd_NoCursorUpdate |
|
||||||
UI7LytAdd_NoScrollHandle);
|
UI7LytAdd_NoScrollHandle);
|
||||||
r = io->DynObjPool.Allocate();
|
r = io->DynObjPool.Allocate();
|
||||||
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
|
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
|
||||||
|
list->SetFont(thiz->GetFont());
|
||||||
l->PathRect(thiz->FinalPos(), thiz->FinalPos() + io->ItemRowHeight,
|
l->PathRect(thiz->FinalPos(), thiz->FinalPos() + io->ItemRowHeight,
|
||||||
io->FrameRounding);
|
io->FrameRounding);
|
||||||
l->PathFill(*color_ref);
|
l->PathFill(*color_ref);
|
||||||
@@ -84,7 +88,9 @@ PD_API void ColorEdit::Draw() {
|
|||||||
layout->Slider<u8>("B", ((u8*)color_ref) + 2);
|
layout->Slider<u8>("B", ((u8*)color_ref) + 2);
|
||||||
layout->Slider<u8>("A", ((u8*)color_ref) + 3);
|
layout->Slider<u8>("A", ((u8*)color_ref) + 3);
|
||||||
layout->Update();
|
layout->Update();
|
||||||
|
list->SetLayer(50);
|
||||||
list->Merge(layout->GetDrawList());
|
list->Merge(layout->GetDrawList());
|
||||||
|
list->SetLayer(0);
|
||||||
// io->RegisterDrawList(GetID(), layout->GetDrawList());
|
// io->RegisterDrawList(GetID(), layout->GetDrawList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,11 +86,11 @@ PD_API void DragData<T>::Draw() {
|
|||||||
FinalPos() + fvec2(off_x, 0) + td + io->FramePadding,
|
FinalPos() + fvec2(off_x, 0) + td + io->FramePadding,
|
||||||
io->FrameRounding);
|
io->FrameRounding);
|
||||||
list->PathFill(io->Theme.Get(UI7Color_Button));
|
list->PathFill(io->Theme.Get(UI7Color_Button));
|
||||||
// list->LayerUp();
|
list->LayerUp();
|
||||||
list->DrawTextEx(FinalPos() + fvec2(off_x, 0), p.c_str(),
|
list->DrawTextEx(FinalPos() + fvec2(off_x, 0), p.c_str(),
|
||||||
io->Theme.Get(UI7Color_Text), LiTextFlags_AlignMid,
|
io->Theme.Get(UI7Color_Text), LiTextFlags_AlignMid,
|
||||||
td + io->FramePadding);
|
td + io->FramePadding);
|
||||||
// list->LayerDown();
|
list->LayerDown();
|
||||||
off_x += td.x + io->ItemSpace.x + io->FramePadding.x;
|
off_x += td.x + io->ItemSpace.x + io->FramePadding.x;
|
||||||
}
|
}
|
||||||
list->DrawText(FinalPos() + fvec2(off_x, io->FramePadding.y * 0.5),
|
list->DrawText(FinalPos() + fvec2(off_x, io->FramePadding.y * 0.5),
|
||||||
@@ -101,6 +101,7 @@ template <typename T>
|
|||||||
PD_API void DragData<T>::Update() {
|
PD_API void DragData<T>::Update() {
|
||||||
// Assert(io.get(), "Did you run Container::Init correctly?");
|
// Assert(io.get(), "Did you run Container::Init correctly?");
|
||||||
// Probably need to find a faster solution (caching sizes calculated here)
|
// Probably need to find a faster solution (caching sizes calculated here)
|
||||||
|
list->SetFont(GetFont());
|
||||||
float off_x = 0;
|
float off_x = 0;
|
||||||
for (size_t i = 0; i < elm_count; i++) {
|
for (size_t i = 0; i < elm_count; i++) {
|
||||||
std::string p;
|
std::string p;
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ PD_API void Image::Draw() {
|
|||||||
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
|
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
|
||||||
// Assert(img.get(), "Image is nullptr!");
|
// Assert(img.get(), "Image is nullptr!");
|
||||||
// io->Ren->OnScreen(screen);
|
// io->Ren->OnScreen(screen);
|
||||||
// list->LayerUp();
|
list->LayerUp();
|
||||||
list->BindTexture(img);
|
list->BindTexture(img);
|
||||||
list->DrawRectFilled(FinalPos(), newsize, 0xffffffff);
|
list->DrawRectFilled(FinalPos(), newsize, 0xffffffff);
|
||||||
list->UnbindTexture();
|
list->UnbindTexture();
|
||||||
// list->LayerDown();
|
list->LayerDown();
|
||||||
}
|
}
|
||||||
} // namespace UI7
|
} // namespace UI7
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -28,6 +28,7 @@ namespace UI7 {
|
|||||||
PD_API void Label::Draw() {
|
PD_API void Label::Draw() {
|
||||||
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
|
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
|
||||||
// io->Ren->OnScreen(screen);
|
// io->Ren->OnScreen(screen);
|
||||||
|
list->SetFont(GetFont());
|
||||||
list->DrawTextEx(FinalPos(), label.c_str(), io->Theme.Get(UI7Color_Text),
|
list->DrawTextEx(FinalPos(), label.c_str(), io->Theme.Get(UI7Color_Text),
|
||||||
LiTextFlags_NoOOS,
|
LiTextFlags_NoOOS,
|
||||||
PD::fvec2(0, io->CurrentViewPort.pSize.w));
|
PD::fvec2(0, io->CurrentViewPort.pSize.w));
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ template <typename T>
|
|||||||
PD_API void Slider<T>::Draw() {
|
PD_API void Slider<T>::Draw() {
|
||||||
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
|
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
|
||||||
// io->Ren->OnScreen(screen);
|
// io->Ren->OnScreen(screen);
|
||||||
|
list->SetFont(GetFont());
|
||||||
std::string p;
|
std::string p;
|
||||||
if constexpr (std::is_floating_point_v<T>) {
|
if constexpr (std::is_floating_point_v<T>) {
|
||||||
p = std::format("{:.{}f}", *data, precision);
|
p = std::format("{:.{}f}", *data, precision);
|
||||||
@@ -84,10 +85,10 @@ PD_API void Slider<T>::Draw() {
|
|||||||
FinalPos() + fvec2(slp + slw - 2, td.y - 2) + io->FramePadding,
|
FinalPos() + fvec2(slp + slw - 2, td.y - 2) + io->FramePadding,
|
||||||
io->FrameRounding);
|
io->FrameRounding);
|
||||||
list->PathFill(io->Theme.Get(UI7Color_ButtonActive));
|
list->PathFill(io->Theme.Get(UI7Color_ButtonActive));
|
||||||
// list->LayerUp();
|
list->LayerUp();
|
||||||
list->DrawTextEx(FinalPos(), p.c_str(), io->Theme.Get(UI7Color_Text),
|
list->DrawTextEx(FinalPos(), p.c_str(), io->Theme.Get(UI7Color_Text),
|
||||||
LiTextFlags_AlignMid, fvec2(width, td.y) + io->FramePadding);
|
LiTextFlags_AlignMid, fvec2(width, td.y) + io->FramePadding);
|
||||||
// list->LayerDown();
|
list->LayerDown();
|
||||||
list->DrawText(FinalPos() + fvec2(width + io->FramePadding.x * 2.f,
|
list->DrawText(FinalPos() + fvec2(width + io->FramePadding.x * 2.f,
|
||||||
io->FramePadding.y * 0.5),
|
io->FramePadding.y * 0.5),
|
||||||
label.c_str(), io->Theme.Get(UI7Color_Text));
|
label.c_str(), io->Theme.Get(UI7Color_Text));
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <pd/ui7/containers.hpp>
|
#include <pd/ui7/containers.hpp>
|
||||||
#include <pd/ui7/layout.hpp>
|
#include <pd/ui7/layout.hpp>
|
||||||
|
|
||||||
@@ -122,6 +123,42 @@ PD_API fvec2 Layout::AlignPosition(fvec2 pos, fvec2 size, fvec4 area,
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PD_API void Layout::HandleScrolling() {
|
||||||
|
if (Flags & UI7LayoutFlags_VtScrolling) {
|
||||||
|
bool allowed = MaxPosition.y > WorkRect.w;
|
||||||
|
if (allowed) {
|
||||||
|
if (PD::Hid::IsEvent(Hid::Event::Down, PD::Hid::Gamepad::Touch) ||
|
||||||
|
PD::Hid::IsEvent(Hid::Event::Down, PD::Hid::Keyboard::MouseLeft)) {
|
||||||
|
ScrollStart = ScrollOffset;
|
||||||
|
}
|
||||||
|
if (IO.InputHandler.DragObject(UI7::ID("sbg" + ID.GetName()),
|
||||||
|
fvec4(Pos, fvec2(0.f)) + WorkRect)) {
|
||||||
|
if (!IO.InputHandler.DragReleasedAW) {
|
||||||
|
ScrollOffset.y =
|
||||||
|
std::clamp(ScrollStart.y + IO.InputHandler.DragSourcePos.y -
|
||||||
|
IO.InputHandler.DragPosition.y,
|
||||||
|
-20.f, MaxPosition.y - WorkRect.w + 20.f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ScrollOffset.y = 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ScrollOffset.y > MaxPosition.y - WorkRect.w) {
|
||||||
|
ScrollOffset.y -= 1.5f;
|
||||||
|
if (ScrollOffset.y < MaxPosition.y - WorkRect.w) {
|
||||||
|
ScrollOffset.y = MaxPosition.y - WorkRect.w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ScrollOffset.y < 0) {
|
||||||
|
ScrollOffset.y += 1.5f;
|
||||||
|
if (ScrollOffset.y > 0) {
|
||||||
|
ScrollOffset.y = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PD_API void Layout::Update() {
|
PD_API void Layout::Update() {
|
||||||
if (Size == fvec2(0.f)) {
|
if (Size == fvec2(0.f)) {
|
||||||
Size = fvec2(MaxPosition) + IO.MenuPadding * 2;
|
Size = fvec2(MaxPosition) + IO.MenuPadding * 2;
|
||||||
@@ -155,6 +192,7 @@ PD_API void Layout::Update() {
|
|||||||
Objects.clear();
|
Objects.clear();
|
||||||
WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO.MenuPadding);
|
WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO.MenuPadding);
|
||||||
CursorInit();
|
CursorInit();
|
||||||
|
HandleScrolling();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** SECTION CONTAINERS (STOLEN FROM FORMER MENU) */
|
/** SECTION CONTAINERS (STOLEN FROM FORMER MENU) */
|
||||||
|
|||||||
+15
-47
@@ -104,6 +104,7 @@ PD_API void Menu::SeparatorText(const std::string& label) {
|
|||||||
DynObj* r = pIO.DynObjPool.Allocate();
|
DynObj* r = pIO.DynObjPool.Allocate();
|
||||||
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
|
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
|
||||||
UI7::Container* self) {
|
UI7::Container* self) {
|
||||||
|
l->SetFont(self->GetFont());
|
||||||
fvec2 size = self->GetSize();
|
fvec2 size = self->GetSize();
|
||||||
fvec2 tdim = io->Font->GetTextBounds(label.c_str(), io->FontScale);
|
fvec2 tdim = io->Font->GetTextBounds(label.c_str(), io->FontScale);
|
||||||
fvec2 pos = self->FinalPos();
|
fvec2 pos = self->FinalPos();
|
||||||
@@ -147,45 +148,6 @@ PD_API void Menu::HandleFocus() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Todo: (func name is self describing) */
|
|
||||||
PD_API void Menu::HandleScrolling() {
|
|
||||||
if (Flags & UI7MenuFlags_VtScrolling) {
|
|
||||||
bool allowed =
|
|
||||||
pLayout.MaxPosition.y > (pLayout.WorkRect.w - pLayout.WorkRect.y);
|
|
||||||
if (allowed) {
|
|
||||||
if (PD::Hid::IsEvent(Hid::Event::Down, PD::Hid::Gamepad::Touch)) {
|
|
||||||
pLayout.ScrollStart = pLayout.ScrollOffset;
|
|
||||||
}
|
|
||||||
if (pIO.InputHandler.DragObject(
|
|
||||||
"sbg" + pID.GetName(),
|
|
||||||
fvec4(pLayout.Pos, fvec2(0.f)) + pLayout.WorkRect)) {
|
|
||||||
if (pIO.InputHandler.DragReleasedAW) {
|
|
||||||
} else {
|
|
||||||
pLayout.ScrollOffset.y = std::clamp(
|
|
||||||
pLayout.ScrollStart.y + pIO.InputHandler.DragSourcePos.y -
|
|
||||||
pIO.InputHandler.DragPosition.y,
|
|
||||||
-20.f, pLayout.MaxPosition.y - 220);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pLayout.ScrollOffset.y = 0.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pLayout.ScrollOffset.y > pLayout.MaxPosition.y - 240) {
|
|
||||||
pLayout.ScrollOffset.y -= 1.5;
|
|
||||||
if (pLayout.ScrollOffset.y < pLayout.MaxPosition.y - 240) {
|
|
||||||
pLayout.ScrollOffset.y = pLayout.MaxPosition.y - 240;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pLayout.ScrollOffset.y < 0) {
|
|
||||||
pLayout.ScrollOffset.y += 1.5;
|
|
||||||
if (pLayout.ScrollOffset.y > 0) {
|
|
||||||
pLayout.ScrollOffset.y = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PD_API void Menu::HandleTitlebarActions() {
|
PD_API void Menu::HandleTitlebarActions() {
|
||||||
// Collapse
|
// Collapse
|
||||||
if (!(Flags & UI7MenuFlags_NoCollapse)) {
|
if (!(Flags & UI7MenuFlags_NoCollapse)) {
|
||||||
@@ -257,11 +219,12 @@ PD_API void Menu::DrawBaseLayout() {
|
|||||||
if (!(Flags & UI7MenuFlags_NoResize)) {
|
if (!(Flags & UI7MenuFlags_NoResize)) {
|
||||||
DynObj* r = pIO.DynObjPool.Allocate();
|
DynObj* r = pIO.DynObjPool.Allocate();
|
||||||
*r = UI7::DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) {
|
*r = UI7::DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) {
|
||||||
// //l->Layer(1);
|
l->SetLayer(1);
|
||||||
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(0, 20));
|
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(0, 20));
|
||||||
l->PathAdd(self->FinalPos() + self->GetSize());
|
l->PathAdd(self->FinalPos() + self->GetSize());
|
||||||
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(20, 0));
|
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(20, 0));
|
||||||
l->PathFill(io->Theme.Get(UI7Color_Button));
|
l->PathFill(io->Theme.Get(UI7Color_Button));
|
||||||
|
l->SetLayer(0);
|
||||||
});
|
});
|
||||||
r->SetSize(
|
r->SetSize(
|
||||||
fvec2(pLayout.GetSize().x, pLayout.GetSize().y - TitleBarHeight));
|
fvec2(pLayout.GetSize().x, pLayout.GetSize().y - TitleBarHeight));
|
||||||
@@ -273,7 +236,7 @@ PD_API void Menu::DrawBaseLayout() {
|
|||||||
/** Background */
|
/** Background */
|
||||||
DynObj* r = pIO.DynObjPool.Allocate();
|
DynObj* r = pIO.DynObjPool.Allocate();
|
||||||
*r = UI7::DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) {
|
*r = UI7::DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) {
|
||||||
// l->Layer(0);
|
l->SetLayer(0);
|
||||||
l->PathRectEx(self->FinalPos(), self->FinalPos() + self->GetSize(), 10.f,
|
l->PathRectEx(self->FinalPos(), self->FinalPos() + self->GetSize(), 10.f,
|
||||||
LiPathRectFlags_KeepTop | LiPathRectFlags_KeepBot);
|
LiPathRectFlags_KeepTop | LiPathRectFlags_KeepBot);
|
||||||
l->PathFill(io->Theme.Get(UI7Color_Background));
|
l->PathFill(io->Theme.Get(UI7Color_Background));
|
||||||
@@ -291,11 +254,12 @@ PD_API void Menu::DrawBaseLayout() {
|
|||||||
DynObj* r = pIO.DynObjPool.Allocate();
|
DynObj* r = pIO.DynObjPool.Allocate();
|
||||||
*r = UI7::DynObj(
|
*r = UI7::DynObj(
|
||||||
[=, this](UI7::IO* io, Li::Drawlist* l, UI7::Container* self) {
|
[=, this](UI7::IO* io, Li::Drawlist* l, UI7::Container* self) {
|
||||||
// l->Layer(20);
|
l->SetFont(self->GetFont());
|
||||||
|
l->SetLayer(20);
|
||||||
/** Header Bar */
|
/** Header Bar */
|
||||||
l->DrawRectFilled(self->FinalPos(), self->GetSize(),
|
l->DrawRectFilled(self->FinalPos(), self->GetSize(),
|
||||||
io->Theme.Get(UI7Color_Header));
|
io->Theme.Get(UI7Color_Header));
|
||||||
// l->Layer(21);
|
l->SetLayer(21);
|
||||||
/** Inline if statement to shift the Text if collapse sym is shown */
|
/** Inline if statement to shift the Text if collapse sym is shown */
|
||||||
/** What the hell is this code btw (didn't found a better way) */
|
/** What the hell is this code btw (didn't found a better way) */
|
||||||
l->DrawText(self->FinalPos() +
|
l->DrawText(self->FinalPos() +
|
||||||
@@ -305,6 +269,7 @@ PD_API void Menu::DrawBaseLayout() {
|
|||||||
(io->FramePadding.x * 2)),
|
(io->FramePadding.x * 2)),
|
||||||
2),
|
2),
|
||||||
pID.GetName().c_str(), io->Theme.Get(UI7Color_Text));
|
pID.GetName().c_str(), io->Theme.Get(UI7Color_Text));
|
||||||
|
l->SetLayer(0);
|
||||||
});
|
});
|
||||||
r->SetSize(fvec2(pLayout.GetSize().x, TitleBarHeight));
|
r->SetSize(fvec2(pLayout.GetSize().x, TitleBarHeight));
|
||||||
r->SetPos(0);
|
r->SetPos(0);
|
||||||
@@ -316,7 +281,7 @@ PD_API void Menu::DrawBaseLayout() {
|
|||||||
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
|
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
|
||||||
UI7::Container* self) {
|
UI7::Container* self) {
|
||||||
/** This sym actually requires layer 21 (i dont know why) */
|
/** This sym actually requires layer 21 (i dont know why) */
|
||||||
// l->Layer(21);
|
l->SetLayer(21);
|
||||||
/**
|
/**
|
||||||
* Symbol (Position Swapping set by pIsOpen ? openpos : closepos;)
|
* Symbol (Position Swapping set by pIsOpen ? openpos : closepos;)
|
||||||
*/
|
*/
|
||||||
@@ -327,6 +292,7 @@ PD_API void Menu::DrawBaseLayout() {
|
|||||||
self->FinalPos() +
|
self->FinalPos() +
|
||||||
fvec2(pIsOpen ? self->GetSize().x * 0.5 : 0, self->GetSize().y),
|
fvec2(pIsOpen ? self->GetSize().x * 0.5 : 0, self->GetSize().y),
|
||||||
io->Theme.Get(UI7Color_FrameBackground));
|
io->Theme.Get(UI7Color_FrameBackground));
|
||||||
|
l->SetLayer(0);
|
||||||
});
|
});
|
||||||
r->SetSize(TitleBarHeight - pIO.FramePadding.y * 2);
|
r->SetSize(TitleBarHeight - pIO.FramePadding.y * 2);
|
||||||
r->SetPos(pIO.FramePadding);
|
r->SetPos(pIO.FramePadding);
|
||||||
@@ -358,6 +324,10 @@ PD_API void Menu::Update() {
|
|||||||
if (pLayout.Size == fvec2(0.f) || Flags & UI7MenuFlags_AlwaysAutoSize) {
|
if (pLayout.Size == fvec2(0.f) || Flags & UI7MenuFlags_AlwaysAutoSize) {
|
||||||
pLayout.Size = fvec2(pLayout.MaxPosition) + pIO.MenuPadding * 2;
|
pLayout.Size = fvec2(pLayout.MaxPosition) + pIO.MenuPadding * 2;
|
||||||
}
|
}
|
||||||
|
if (Flags & UI7MenuFlags_VtScrolling)
|
||||||
|
pLayout.Flags |= UI7LayoutFlags_VtScrolling;
|
||||||
|
if (Flags & UI7MenuFlags_HzScrolling)
|
||||||
|
pLayout.Flags |= UI7LayoutFlags_HzScrolling;
|
||||||
if (!(Flags & UI7MenuFlags_NoTitlebar)) {
|
if (!(Flags & UI7MenuFlags_NoTitlebar)) {
|
||||||
TitleBarHeight = pIO.FontScale * pIO.Font->PixelHeight + pIO.MenuPadding.y;
|
TitleBarHeight = pIO.FontScale * pIO.Font->PixelHeight + pIO.MenuPadding.y;
|
||||||
pLayout.WorkRect.y = 5.f + TitleBarHeight;
|
pLayout.WorkRect.y = 5.f + TitleBarHeight;
|
||||||
@@ -368,9 +338,6 @@ PD_API void Menu::Update() {
|
|||||||
}
|
}
|
||||||
DrawBaseLayout();
|
DrawBaseLayout();
|
||||||
pLayout.Update();
|
pLayout.Update();
|
||||||
if (Flags & UI7MenuFlags_VtScrolling || Flags & UI7MenuFlags_HzScrolling) {
|
|
||||||
HandleScrolling();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_API bool Menu::BeginTreeNode(const ID& id) {
|
PD_API bool Menu::BeginTreeNode(const ID& id) {
|
||||||
@@ -391,6 +358,7 @@ PD_API bool Menu::BeginTreeNode(const ID& id) {
|
|||||||
// Object
|
// Object
|
||||||
DynObj* r = pIO.DynObjPool.Allocate();
|
DynObj* r = pIO.DynObjPool.Allocate();
|
||||||
*r = UI7::DynObj([=, this](IO* io, Li::Drawlist* l, Container* self) {
|
*r = UI7::DynObj([=, this](IO* io, Li::Drawlist* l, Container* self) {
|
||||||
|
l->SetFont(self->GetFont());
|
||||||
fvec2 ts = self->FinalPos() + fvec2(0, 7);
|
fvec2 ts = self->FinalPos() + fvec2(0, 7);
|
||||||
fvec2 pl[2] = {fvec2(10, 5), fvec2(0, 10)};
|
fvec2 pl[2] = {fvec2(10, 5), fvec2(0, 10)};
|
||||||
if (n->second) {
|
if (n->second) {
|
||||||
|
|||||||
@@ -143,8 +143,11 @@ PD_API void Context::Update() {
|
|||||||
pMenus[it]->Update(); /** Render */
|
pMenus[it]->Update(); /** Render */
|
||||||
this->pIO.InputHandler.CurrentMenu = 0;
|
this->pIO.InputHandler.CurrentMenu = 0;
|
||||||
}
|
}
|
||||||
|
int base_layer = 0;
|
||||||
for (int i = (int)FinalList.size() - 1; i >= 0; i--) {
|
for (int i = (int)FinalList.size() - 1; i >= 0; i--) {
|
||||||
|
pIO.FDL.SetLayer(base_layer);
|
||||||
pIO.FDL.Merge(pMenus[FinalList[i]]->pLayout.GetDrawList());
|
pIO.FDL.Merge(pMenus[FinalList[i]]->pLayout.GetDrawList());
|
||||||
|
base_layer += 100;
|
||||||
}
|
}
|
||||||
pCurrentMenus.clear();
|
pCurrentMenus.clear();
|
||||||
pIO.Update();
|
pIO.Update();
|
||||||
|
|||||||
@@ -304,6 +304,7 @@ int main(int argc, char** argv) {
|
|||||||
ui7.EndMenu();
|
ui7.EndMenu();
|
||||||
}
|
}
|
||||||
if (auto m = ui7.BeginMenu("LI DBG INFO")) {
|
if (auto m = ui7.BeginMenu("LI DBG INFO")) {
|
||||||
|
m->PushFont(&debug_font);
|
||||||
m->Label("Gfx Driver: {}", PD::Gfx::GetDriverName());
|
m->Label("Gfx Driver: {}", PD::Gfx::GetDriverName());
|
||||||
m->Separator();
|
m->Separator();
|
||||||
m->Label("LI Draw Comamnds: {}", PD::Gfx::GetNumCommands());
|
m->Label("LI Draw Comamnds: {}", PD::Gfx::GetNumCommands());
|
||||||
@@ -311,6 +312,7 @@ int main(int argc, char** argv) {
|
|||||||
m->Label("GFX Vertices: {}", PD::Gfx::GetNumVertices());
|
m->Label("GFX Vertices: {}", PD::Gfx::GetNumVertices());
|
||||||
m->Label("GFX Triangles: {}", PD::Gfx::GetNumVertices() / 3);
|
m->Label("GFX Triangles: {}", PD::Gfx::GetNumVertices() / 3);
|
||||||
m->Label("GFX Indices: {}", PD::Gfx::GetNumIndices());
|
m->Label("GFX Indices: {}", PD::Gfx::GetNumIndices());
|
||||||
|
m->PopFont();
|
||||||
ui7.EndMenu();
|
ui7.EndMenu();
|
||||||
}
|
}
|
||||||
ui7.MetricsMenu();
|
ui7.MetricsMenu();
|
||||||
|
|||||||
Reference in New Issue
Block a user