# Stage 1.8

- Renderer now vould use more screen Objects
- Register default Top and Bottom Screens (for Overlays and UI7)
- Make ToHex an Inline header func
- Add GetCompilerVersion
- Add Library Compile And Version Info to common
- Remove z of vertex object and shader in position
- Add Container base and SubContainers to UI7
- Add abillity to Join Multiple Objects in Same Line and Center them
- Fix LayerOrder Bug for updating texts in DrawList
This commit is contained in:
2025-02-02 20:32:07 +01:00
parent 055588ce8b
commit f87c103d8d
32 changed files with 619 additions and 293 deletions

View File

@ -0,0 +1,30 @@
#pragma once
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
class Button : public Container {
public:
Button(const std::string& label, vec2 pos, LI::Renderer::Ref lr) {
this->screen = lr->CurrentScreen();
this->label = label;
this->SetPos(pos);
this->tdim = lr->GetTextDimensions(label);
color = UI7Color_Button;
this->SetSize(tdim + vec2(8, 4));
}
~Button() {}
bool IsPressed() { return pressed; }
void HandleInput(Hid::Ref inp) override;
void Draw() override;
private:
vec2 tdim;
UI7Color color;
std::string label;
bool pressed = false;
};
} // namespace UI7
} // namespace PD

View File

@ -0,0 +1,32 @@
#pragma once
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
class Checkbox : public Container {
public:
Checkbox(const std::string& label, vec2 pos, bool& usr_ref,
LI::Renderer::Ref lr)
: usr_ref(usr_ref) {
this->screen = lr->CurrentScreen();
this->label = label;
this->SetPos(pos);
this->tdim = lr->GetTextDimensions(label);
color = UI7Color_FrameBackground;
this->SetSize(cbs + vec2(tdim.x() + 5, 0));
}
~Checkbox() {}
void HandleInput(Hid::Ref inp) override;
void Draw() override;
private:
vec2 tdim;
vec2 cbs = vec2(18);
UI7Color color;
std::string label;
bool& usr_ref;
};
} // namespace UI7
} // namespace PD

View File

@ -0,0 +1,54 @@
#pragma once
#include <pd/common/common.hpp>
#include <pd/common/strings.hpp>
#include <pd/controls/hid.hpp>
#include <pd/maths/vec.hpp>
#include <pd/ui7/drawlist.hpp>
namespace PD {
namespace UI7 {
class Container : public SmartCtor<Container> {
public:
Container() {}
Container(const vec2& pos, const vec2& size) : pos(pos), size(size) {}
Container(const vec4& box) : pos(box.xy()), size(box.zw()) {}
~Container() {}
void Init(LI::Renderer::Ref r, UI7::DrawList::Ref l, UI7::Theme* lt) {
list = l;
linked_theme = lt;
ren = r;
}
void SetPos(const vec2& pos) { this->pos = pos; }
void SetSize(const vec2& size) { this->size = size; }
vec2 GetPos() { return pos; }
vec2 GetSize() { return size; }
bool Skippable() const { return skippable; }
void HandleScrolling(vec2 scrolling, vec4 viewport);
virtual void HandleInput(Hid::Ref inp) {}
virtual void Draw() {}
void UnlockInput() { inp_done = false; }
u32 GetID() const { return id; }
void SetID(u32 id) { this->id = id; }
protected:
/// used to skip Input/Render preocessing ot not
bool skippable = false;
bool inp_done = false;
Screen::Ref screen;
vec2 pos;
vec2 size;
UI7::DrawList::Ref list;
UI7::Theme* linked_theme;
LI::Renderer::Ref ren;
u32 id = 0;
};
} // namespace UI7
} // namespace PD

View File

@ -0,0 +1,27 @@
#pragma once
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
class Image : public Container {
public:
Image(Texture::Ref img, vec2 pos, LI::Renderer::Ref lr, vec2 size = 0.f) {
this->screen = lr->CurrentScreen();
this->img = img;
this->SetPos(pos);
if (size.x() != 0 || size.y() != 0) {
this->SetSize(size);
} else {
this->SetSize(img->GetSize());
}
}
~Image() {}
void Draw() override;
private:
Texture::Ref img;
};
} // namespace UI7
} // namespace PD

View File

@ -0,0 +1,27 @@
#pragma once
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
class Label : public Container {
public:
Label(const std::string& label, vec2 pos, LI::Renderer::Ref lr) {
this->screen = lr->CurrentScreen();
this->label = label;
this->SetPos(pos);
this->tdim = lr->GetTextDimensions(label);
color = UI7Color_Text;
this->SetSize(tdim);
}
~Label() {}
void Draw() override;
private:
vec2 tdim;
UI7Color color;
std::string label;
};
} // namespace UI7
} // namespace PD

View File

@ -0,0 +1,6 @@
#pragma once
#include <pd/ui7/container/button.hpp>
#include <pd/ui7/container/checkbox.hpp>
#include <pd/ui7/container/image.hpp>
#include <pd/ui7/container/label.hpp>

View File

@ -24,6 +24,7 @@ SOFTWARE.
*/
#include <pd/controls/hid.hpp>
#include <pd/ui7/containers.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/id.hpp>
@ -56,6 +57,10 @@ class Menu : public SmartCtor<Menu> {
void SameLine();
void Separator();
void SeparatorText(const std::string& label);
void Join();
/// @brief Horizontal Center Joined objects
void JoinOpHzCenter();
void AfterAlignCenter();
/// API for Custom Objects
bool HandleScrolling(vec2& pos, const vec2& size);
@ -106,6 +111,10 @@ class Menu : public SmartCtor<Menu> {
/// Internal Processing
void Update(float delta);
/// Objects API
Container::Ref ObjectPush(Container::Ref obj);
Container::Ref FindIDObj(u32 id);
/// This ability is crazy useful
friend class Context;
@ -127,6 +136,11 @@ class Menu : public SmartCtor<Menu> {
Menu::Ref submenu;
/// Objects API
std::vector<Container::Ref> objects;
std::vector<Container::Ref> idobjs;
std::vector<Container*> join;
// DrawLists
DrawList::Ref back;
DrawList::Ref main;