UI7 Add Containers to Layout
- Hotfix in CommandPool - Add UI7 ItemRowHeight (Universal Item Size/Height) - Add Containers to Layout - Add ColorEdit to Menu - Switch Back to COlorEdit in UI7::StyleEditor - Add DrawList Layer Sorting to UI7 (Not working as expected) - STart Work at ColorEdit container
This commit is contained in:
@@ -61,6 +61,7 @@ PD_UI7_API void Checkbox::Draw() {
|
||||
|
||||
PD_UI7_API void Checkbox::Update() {
|
||||
// Assert(io.get(), "Did you run Container::Init correctly?");
|
||||
cbs = io->ItemRowHeight;
|
||||
this->SetSize(cbs + fvec2(tdim.x + io->ItemSpace.x, 0));
|
||||
}
|
||||
} // namespace UI7
|
||||
|
||||
@@ -22,7 +22,7 @@ SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/container/coloredit.hpp>
|
||||
#include <pd/ui7/container/label.hpp>
|
||||
#include <pd/ui7/containers.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
@@ -33,8 +33,9 @@ PD_UI7_API void ColorEdit::HandleInput() {
|
||||
}
|
||||
// Assert(screen.get(), "Screen is not set up!");
|
||||
// if (screen->ScreenType() == Screen::Bottom) {
|
||||
if (io->InputHandler->DragObject(this->GetID(), fvec4(FinalPos(), size))) {
|
||||
if (io->InputHandler->DragReleased) {
|
||||
if (io->InputHandler->DragObject(this->GetID() + 2,
|
||||
fvec4(FinalPos(), size))) {
|
||||
if (io->InputHandler->DragReleasedAW) {
|
||||
is_shown = !is_shown;
|
||||
}
|
||||
}
|
||||
@@ -44,15 +45,45 @@ PD_UI7_API void ColorEdit::HandleInput() {
|
||||
PD_UI7_API void ColorEdit::Draw() {
|
||||
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
|
||||
// io->Ren->OnScreen(screen);
|
||||
list->PathRect(FinalPos(), FinalPos() + 18, io->FrameRounding);
|
||||
list->PathRect(FinalPos(), FinalPos() + io->ItemRowHeight, io->FrameRounding);
|
||||
list->PathFill(*color_ref);
|
||||
list->DrawText(FinalPos() + fvec2(io->ItemSpace.x + 18, 0), label,
|
||||
io->Theme->Get(UI7Color_Text));
|
||||
list->DrawText(FinalPos() + fvec2(io->ItemSpace.x + io->ItemRowHeight, 0),
|
||||
label, io->Theme->Get(UI7Color_Text));
|
||||
if (is_shown) {
|
||||
if (!layout) {
|
||||
layout = Layout::New(GetID(), io);
|
||||
}
|
||||
layout->AddObject(Label::New("Hello World!", io));
|
||||
layout->SetPosition(FinalPos());
|
||||
layout->AddObjectEx(
|
||||
DynObj::New(
|
||||
[=, this](UI7::IO::Ref io, Li::DrawList::Ref l, Container* thiz) {
|
||||
thiz->SetSize(layout->GetSize());
|
||||
l->Layer(30);
|
||||
l->PathRect(thiz->GetPos(), thiz->GetPos() + thiz->GetSize(),
|
||||
io->FrameRounding);
|
||||
l->PathFill(io->Theme->Get(UI7Color_FrameBackground));
|
||||
}),
|
||||
UI7LytAdd_Front | UI7LytAdd_NoCursorUpdate | UI7LytAdd_NoScrollHandle);
|
||||
auto obj = DynObj::New(
|
||||
[=, this](UI7::IO::Ref io, Li::DrawList::Ref l, Container* thiz) {
|
||||
l->PathRect(thiz->FinalPos(), thiz->FinalPos() + io->ItemRowHeight,
|
||||
io->FrameRounding);
|
||||
l->PathFill(*color_ref);
|
||||
l->DrawText(
|
||||
thiz->FinalPos() + fvec2(io->ItemSpace.x + io->ItemRowHeight, 0),
|
||||
label, io->Theme->Get(UI7Color_Text));
|
||||
});
|
||||
obj->SetSize(PD::fvec2(200, io->ItemRowHeight));
|
||||
layout->AddObject(obj);
|
||||
layout->Label("RGBA: ({}, {}, {}, {})", *((u8*)color_ref),
|
||||
*(((u8*)color_ref) + 1), *(((u8*)color_ref) + 2),
|
||||
*(((u8*)color_ref) + 3));
|
||||
layout->Label("Hex: {}", PD::Color(*color_ref).Hex(true));
|
||||
|
||||
layout->Slider<u8>("R", ((u8*)color_ref));
|
||||
layout->Slider<u8>("G", ((u8*)color_ref) + 1);
|
||||
layout->Slider<u8>("B", ((u8*)color_ref) + 2);
|
||||
layout->Slider<u8>("A", ((u8*)color_ref) + 3);
|
||||
layout->Update();
|
||||
list->Merge(layout->GetDrawList());
|
||||
// io->RegisterDrawList(GetID(), layout->GetDrawList());
|
||||
@@ -61,7 +92,8 @@ PD_UI7_API void ColorEdit::Draw() {
|
||||
|
||||
PD_UI7_API void ColorEdit::Update() {
|
||||
// Assert(io.get(), "Did you run Container::Init correctly?");
|
||||
this->SetSize(fvec2(tdim.x + io->ItemSpace.x + 18, 18));
|
||||
this->SetSize(
|
||||
fvec2(tdim.x + io->ItemSpace.x + io->ItemRowHeight, io->ItemRowHeight));
|
||||
}
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -36,6 +36,7 @@ PD_UI7_API void UI7::IO::Update() {
|
||||
Framerate = 1000.f / Delta;
|
||||
DrawListRegestry.clear();
|
||||
DrawListRegestry.push_front(std::make_pair("CtxBackList", Back));
|
||||
if (Font) ItemRowHeight = FontScale * Font->PixelHeight;
|
||||
// RegisterDrawList("CtxBackList", Back);
|
||||
NumIndices = FDL->pNumIndices;
|
||||
NumVertices = FDL->pNumVertices;
|
||||
|
||||
@@ -21,6 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/containers.hpp>
|
||||
#include <pd/ui7/layout.hpp>
|
||||
|
||||
namespace PD {
|
||||
@@ -114,7 +115,7 @@ PD_UI7_API fvec2 Layout::AlignPosition(fvec2 pos, fvec2 size, fvec4 area,
|
||||
|
||||
PD_UI7_API void Layout::Update() {
|
||||
if (Size == fvec2(0.f)) {
|
||||
Size = fvec2(MaxPosition);
|
||||
Size = fvec2(MaxPosition) + IO->MenuPadding * 2;
|
||||
}
|
||||
for (auto& it : Objects) {
|
||||
if (it->GetID() != 0 && !FindObject(it->GetID())) {
|
||||
@@ -140,5 +141,45 @@ PD_UI7_API void Layout::Update() {
|
||||
WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO->MenuPadding);
|
||||
CursorInit();
|
||||
}
|
||||
|
||||
/** SECTION CONTAINERS (STOLEN FROM FORMER MENU) */
|
||||
|
||||
PD_UI7_API void Layout::Label(const std::string& label) {
|
||||
// Layout API
|
||||
auto r = Label::New(label, IO);
|
||||
r->SetClipRect(fvec4(GetPosition(), GetPosition() + GetSize()));
|
||||
AddObject(r);
|
||||
}
|
||||
|
||||
PD_UI7_API bool Layout::Button(const std::string& label) {
|
||||
bool ret = false;
|
||||
u32 id = Strings::FastHash("btn" + label + std::to_string(Objects.size()));
|
||||
Container::Ref r = FindObject(id);
|
||||
if (!r) {
|
||||
r = Button::New(label, IO);
|
||||
r->SetID(id);
|
||||
}
|
||||
AddObject(r);
|
||||
if (!r->Skippable()) {
|
||||
ret = std::static_pointer_cast<UI7::Button>(r)->IsPressed();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
PD_UI7_API void Layout::Checkbox(const std::string& label, bool& v) {
|
||||
u32 id = Strings::FastHash("cbx" + label + std::to_string(Objects.size()));
|
||||
Container::Ref r = FindObject(id);
|
||||
if (!r) {
|
||||
r = Checkbox::New(label, v, IO);
|
||||
r->SetID(id);
|
||||
}
|
||||
AddObject(r);
|
||||
}
|
||||
|
||||
PD_UI7_API void Layout::Image(Li::Texture::Ref img, fvec2 size, Li::Rect uv) {
|
||||
Container::Ref r = Image::New(img, size, uv);
|
||||
AddObject(r);
|
||||
}
|
||||
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -29,7 +29,7 @@ namespace PD {
|
||||
namespace UI7 {
|
||||
Menu::Menu(const ID& id, IO::Ref io) : pIO(io), pID(id) {
|
||||
pLayout = Layout::New(id, io);
|
||||
TitleBarHeight = io->FontScale * 30.f;
|
||||
TitleBarHeight = pIO->FontScale * pIO->Font->PixelHeight + pIO->MenuPadding.y;
|
||||
pLayout->WorkRect.y += TitleBarHeight;
|
||||
pLayout->CursorInit();
|
||||
}
|
||||
@@ -74,6 +74,16 @@ PD_UI7_API void Menu::Image(Li::Texture::Ref img, fvec2 size, Li::Rect uv) {
|
||||
pLayout->AddObject(r);
|
||||
}
|
||||
|
||||
PD_UI7_API void Menu::ColorEdit(const std::string& label, u32& clr) {
|
||||
u32 id = Strings::FastHash("drd" + label);
|
||||
Container::Ref r = pLayout->FindObject(id);
|
||||
if (!r) {
|
||||
r = UI7::ColorEdit::New(label, &clr, pIO);
|
||||
r->SetID(id);
|
||||
}
|
||||
pLayout->AddObject(r);
|
||||
}
|
||||
|
||||
PD_UI7_API void Menu::Separator() {
|
||||
// Dynamic Objects are very simple...
|
||||
Container::Ref r = DynObj::New(
|
||||
|
||||
@@ -151,6 +151,7 @@ PD_UI7_API void Context::Update() {
|
||||
}
|
||||
pCurrentMenus.clear();
|
||||
pIO->Update();
|
||||
pIO->FDL->pPool.Sort();
|
||||
}
|
||||
|
||||
PD_UI7_API void Context::AboutMenu(bool *show) {
|
||||
@@ -322,27 +323,27 @@ PD_UI7_API void UI7::Context::StyleEditor(bool *show) {
|
||||
UI7::Theme::Flashbang(*pIO->Theme.get());
|
||||
}
|
||||
/// Small trick to print without prefix
|
||||
#define ts(x) m->ColorEdit(std::string(#x).substr(9), &pIO->Theme->GetRef(x));
|
||||
#define ts(x) m->ColorEdit(std::string(#x).substr(9), pIO->Theme->GetRef(x));
|
||||
#define ts2(x) \
|
||||
m->DragData(std::string(#x).substr(9), (u8 *)&pIO->Theme->GetRef(x), 4, \
|
||||
(u8)0, (u8)255);
|
||||
ts2(UI7Color_Background);
|
||||
ts2(UI7Color_Border);
|
||||
ts2(UI7Color_Button);
|
||||
ts2(UI7Color_ButtonDead);
|
||||
ts2(UI7Color_ButtonActive);
|
||||
ts2(UI7Color_ButtonHovered);
|
||||
ts2(UI7Color_Text);
|
||||
ts2(UI7Color_TextDead);
|
||||
ts2(UI7Color_Header);
|
||||
ts2(UI7Color_HeaderDead);
|
||||
ts2(UI7Color_Selector);
|
||||
ts2(UI7Color_Checkmark);
|
||||
ts2(UI7Color_FrameBackground);
|
||||
ts2(UI7Color_FrameBackgroundHovered);
|
||||
ts2(UI7Color_Progressbar);
|
||||
ts2(UI7Color_ListEven);
|
||||
ts2(UI7Color_ListOdd);
|
||||
ts(UI7Color_Background);
|
||||
ts(UI7Color_Border);
|
||||
ts(UI7Color_Button);
|
||||
ts(UI7Color_ButtonDead);
|
||||
ts(UI7Color_ButtonActive);
|
||||
ts(UI7Color_ButtonHovered);
|
||||
ts(UI7Color_Text);
|
||||
ts(UI7Color_TextDead);
|
||||
ts(UI7Color_Header);
|
||||
ts(UI7Color_HeaderDead);
|
||||
ts(UI7Color_Selector);
|
||||
ts(UI7Color_Checkmark);
|
||||
ts(UI7Color_FrameBackground);
|
||||
ts(UI7Color_FrameBackgroundHovered);
|
||||
ts(UI7Color_Progressbar);
|
||||
ts(UI7Color_ListEven);
|
||||
ts(UI7Color_ListOdd);
|
||||
this->EndMenu();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user