# Changes 0.2.9
- Litium Chenge Static Object to set instead of add layer - Add UI7 Color Selector (Not done) - Add NoClose flag as well as a is_shown address to set to close menus completly - Add u32 input for nameless ui7 ids - Add Debug Vertex/Index counters to DrawLists and IO - Add an Anywhere Released bool to Input API to decide if object should always react or only if curser is inside its box - Add Focused Menu System to Drag API to make sure to not care about the menu input process order - Let Menus only have 1 Drawlist instead of 3 Put Close, Resize, Move, Collapse and Scroll into their own handlers - Add a DeadHeader color to make a visual diffrence between Menus and Focused Menu - Add a GetRef to Theme for Color edit - Fix DrawList Line not rendering if going out of screen - Clear All CLipRects after process DrawList - Fix SeparatorText glitch - Fix Typos - Add IO Input Support to Containers
This commit is contained in:
@ -99,12 +99,12 @@ class StaticObject : public SmartCtor<StaticObject> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the Layer by a specific number
|
||||
* @param base_layer baselayer or number to add on top of the commands layer
|
||||
* Assign a New Layer to all Objects
|
||||
* @param layer new layer to set to all its commands
|
||||
*/
|
||||
void ReLayer(int base_layer) {
|
||||
void ReLayer(int layer) {
|
||||
for (auto& it : cpy) {
|
||||
it->Layer(it->Layer() + base_layer);
|
||||
it->Layer(layer);
|
||||
}
|
||||
}
|
||||
|
||||
|
73
include/pd/ui7/container/coloredit.hpp
Normal file
73
include/pd/ui7/container/coloredit.hpp
Normal file
@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Color Editor (Creating a PopUP when clicking)
|
||||
*/
|
||||
class ColorEdit : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param label Label of the Button
|
||||
* @param pos Base Position
|
||||
* @param lr Reference to the Renderer
|
||||
*/
|
||||
ColorEdit(const std::string& label, u32* color, UI7::IO::Ref io) {
|
||||
PD::Assert(color != nullptr, "Input Color Address is null!");
|
||||
this->label = label;
|
||||
this->color_ref = color;
|
||||
this->initial_color = *color;
|
||||
this->tdim = io->Ren->GetTextDimensions(label);
|
||||
}
|
||||
~ColorEdit() = default;
|
||||
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* @param inp Reference to the Input Handler
|
||||
*/
|
||||
void HandleInput(Hid::Ref inp) override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Function to Update Size if framepadding changes */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
vec2 tdim; ///< Text size
|
||||
u32* color_ref = nullptr; ///< Color Reference
|
||||
u32 initial_color; ///< Initial Color
|
||||
std::string label; ///< Label of the Button
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -25,5 +25,6 @@ SOFTWARE.
|
||||
|
||||
#include <pd/ui7/container/button.hpp>
|
||||
#include <pd/ui7/container/checkbox.hpp>
|
||||
#include <pd/ui7/container/coloredit.hpp>
|
||||
#include <pd/ui7/container/image.hpp>
|
||||
#include <pd/ui7/container/label.hpp>
|
||||
|
@ -110,6 +110,8 @@ class DrawList : public SmartCtor<DrawList> {
|
||||
int base; ///< Base Layer
|
||||
LI::Renderer::Ref ren; ///< Renderer Reference
|
||||
std::stack<vec4> clip_rects; ///< Stack containing Scissor Areas
|
||||
u32 num_vertices; ///< Number of Vertices
|
||||
u32 num_indices; ///< Number of Indices
|
||||
// Map for Auto Static Text
|
||||
std::unordered_map<u32, LI::StaticText::Ref> static_text;
|
||||
// List of Drawcommands generated
|
||||
|
@ -42,6 +42,8 @@ enum UI7MenuFlags_ {
|
||||
UI7MenuFlags_NoCollapse = 1 << 6, ///< Disable Menu Collapse
|
||||
UI7MenuFlags_NoMove = 1 << 7, ///< Disable Menu Movement
|
||||
UI7MenuFlags_NoResize = 1 << 8, ///< Disable Menu Resize
|
||||
UI7MenuFlags_NoClose = 1 << 9, ///< Disable Close Button
|
||||
UI7MenuFlags_NoScrollbar = 1 << 10, ///< Hide the Scrollbar
|
||||
// Enable Horizontal and Vertical Scrolling
|
||||
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
|
||||
};
|
||||
|
@ -50,6 +50,10 @@ class ID {
|
||||
id = PD::Strings::FastHash(text);
|
||||
name = text;
|
||||
}
|
||||
/**
|
||||
* Use an ID as Input
|
||||
*/
|
||||
ID(u32 id) { this->id = id; }
|
||||
~ID() = default;
|
||||
|
||||
/** Get The ID Initial Name */
|
||||
|
@ -49,8 +49,7 @@ class IO : public SmartCtor<IO> {
|
||||
Ren = ren;
|
||||
Back = UI7::DrawList::New(Ren);
|
||||
Front = UI7::DrawList::New(Ren);
|
||||
DrawListRegestry["CtxBackList"] = Back;
|
||||
DrawListRegestry["CtxFrontList"] = Front;
|
||||
RegisterDrawList("CtxBackList", Back);
|
||||
DeltaStats = TimeStats::New(60);
|
||||
};
|
||||
~IO() = default;
|
||||
@ -70,9 +69,11 @@ class IO : public SmartCtor<IO> {
|
||||
vec2 MenuPadding = 5.f;
|
||||
vec2 FramePadding = 5.f;
|
||||
vec2 ItemSpace = vec2(5.f, 2.f);
|
||||
std::map<UI7::ID, DrawList::Ref> DrawListRegestry;
|
||||
std::vector<std::pair<UI7::ID, DrawList::Ref>> DrawListRegestry;
|
||||
DrawList::Ref Back;
|
||||
DrawList::Ref Front;
|
||||
u32 NumVertices = 0; ///< Debug Vertices Num
|
||||
u32 NumIndices = 0; ///< Debug Indices Num
|
||||
|
||||
// Layer Rules
|
||||
int ContextBackLayer = 10;
|
||||
@ -83,18 +84,21 @@ class IO : public SmartCtor<IO> {
|
||||
|
||||
// DrawListApi
|
||||
void RegisterDrawList(const UI7::ID& id, DrawList::Ref v) {
|
||||
DrawListRegestry[id] = v;
|
||||
DrawListRegestry.push_back(std::make_pair(id, v));
|
||||
}
|
||||
|
||||
// Input API
|
||||
|
||||
u32 FocusedMenu = 0;
|
||||
vec4 FocusedMenuRect;
|
||||
u32 CurrentMenu = 0;
|
||||
u32 DraggedObject = 0;
|
||||
vec2 DragSourcePos = 0;
|
||||
vec2 DragPosition = 0;
|
||||
vec2 DragLastPosition = 0;
|
||||
vec4 DragDestination = 0;
|
||||
Timer::Ref DragTime;
|
||||
bool DragReleased = false;
|
||||
bool DragReleased = false; ///< Drag Releaded in Box
|
||||
bool DragReleasedAW = false; ///< Drag Released Anywhere
|
||||
/** Check if an object is Dragged already */
|
||||
bool IsObjectDragged() const { return DraggedObject != 0; }
|
||||
/**
|
||||
@ -105,6 +109,9 @@ class IO : public SmartCtor<IO> {
|
||||
* @return if inputs to this objects are alowed or not
|
||||
*/
|
||||
bool DragObject(const UI7::ID& id, vec4 area) {
|
||||
if (CurrentMenu != FocusedMenu) {
|
||||
return false;
|
||||
}
|
||||
if (IsObjectDragged()) {
|
||||
// Only block if the Dragged Object has a difrent id
|
||||
if (DraggedObject != id) {
|
||||
@ -136,7 +143,10 @@ class IO : public SmartCtor<IO> {
|
||||
DragSourcePos = 0;
|
||||
DragLastPosition = 0;
|
||||
DragDestination = 0;
|
||||
DragReleased = true; // Set Drag released to true (only one frame)
|
||||
// Set Drag released to true (only one frame)
|
||||
// and Only if still in Box
|
||||
DragReleased = Ren->InBox(Inp->TouchPosLast(), area);
|
||||
DragReleasedAW = true; // Advanced
|
||||
// Ensure timer is paused
|
||||
DragTime->Pause();
|
||||
DragTime->Reset();
|
||||
|
@ -82,6 +82,12 @@ class Menu : public SmartCtor<Menu> {
|
||||
*/
|
||||
void Image(Texture::Ref img, vec2 size = 0.f);
|
||||
|
||||
/**
|
||||
* Color Edit Object that opens a popup editor if clicked
|
||||
* @param label Name of the Edit field
|
||||
* @param color Color reference to edit
|
||||
*/
|
||||
void ColorEdit(const std::string& label, u32* color);
|
||||
// Basic API
|
||||
|
||||
/**
|
||||
@ -267,20 +273,10 @@ class Menu : public SmartCtor<Menu> {
|
||||
/** Destory the parent container (if one active) */
|
||||
void DestroyParent() { tmp_parent = nullptr; }
|
||||
|
||||
// Draw Lists
|
||||
// Draw List
|
||||
|
||||
/** Background Layer Drawlist */
|
||||
DrawList::Ref BackList() { return back; }
|
||||
/** Setter for Background Layer Drawlist */
|
||||
void BackList(DrawList::Ref v) { back = v; }
|
||||
/** Main Layer Drawlist */
|
||||
DrawList::Ref MainList() { return main; }
|
||||
/** Setter for Main Layer Drawlist */
|
||||
void MainList(DrawList::Ref v) { main = v; }
|
||||
/** Foreground Layer Drawlist */
|
||||
DrawList::Ref FrontList() { return front; }
|
||||
/** Setter for Foreground Layer Drawlist */
|
||||
void FrontList(DrawList::Ref v) { front = v; }
|
||||
/** Get DrawList */
|
||||
DrawList::Ref GetDrawList() { return main; }
|
||||
|
||||
// Advanced
|
||||
|
||||
@ -349,6 +345,19 @@ class Menu : public SmartCtor<Menu> {
|
||||
/** Internal Processing */
|
||||
void Update(float delta);
|
||||
|
||||
// Put some Buttons and functionality into its own functions
|
||||
|
||||
/** Handler of the Close Button (if exists) */
|
||||
void CloseButtonHandler();
|
||||
/** Handler of the Resize Dragging (lower right corner) */
|
||||
void ResizeHandler();
|
||||
/** Logic of the Titlebar Movement */
|
||||
void MoveHandler();
|
||||
/** Menu Collapse Button Handler */
|
||||
void CollapseHandler();
|
||||
/** Scroll Handler (Includes Slider Drag) */
|
||||
void PostScrollHandler();
|
||||
|
||||
// This ability is crazy useful
|
||||
friend class Context;
|
||||
|
||||
@ -356,24 +365,25 @@ class Menu : public SmartCtor<Menu> {
|
||||
|
||||
// Default Alignment for all Objects
|
||||
UI7Align alignment = UI7Align_Default;
|
||||
UI7Align tmpalign = 0; ///< Temp Alignment [only used once]
|
||||
UI7MenuFlags flags = 0; ///< Menu Flags
|
||||
u32 id; ///< Menu ID
|
||||
std::string name; ///< Menu Name
|
||||
vec2 cursor; ///< Current Cursor Position
|
||||
vec2 icursoroff; ///< Initial Cursor Offset (Also in Newline)
|
||||
vec2 bcursor; ///< Backup Cursor
|
||||
vec2 slcursor; ///< Sameline Cursor
|
||||
vec4 view_area; ///< view Area (Position and Size)
|
||||
vec4 main_area; ///< Main Area [Input related]
|
||||
vec2 scrolling_off; ///< Scrolling Position
|
||||
bool scrolling[2]; ///< Is Hz or Vt Scrolling Enabled
|
||||
vec2 scroll_mod; ///< Scroll Modificator
|
||||
float tbh; ///< Titlebar height
|
||||
bool scrollbar[2]; ///< Is Hz or Vt Scrollbar rendered
|
||||
bool scroll_allowed[2]; ///< Is Hz or Vt Scrolling Alowed
|
||||
bool has_touch; ///< Menu has touch (depends on screen)
|
||||
bool is_open = true; ///< For Collapse Event
|
||||
UI7Align tmpalign = 0; ///< Temp Alignment [only used once]
|
||||
UI7MenuFlags flags = 0; ///< Menu Flags
|
||||
u32 id; ///< Menu ID
|
||||
std::string name; ///< Menu Name
|
||||
vec2 cursor; ///< Current Cursor Position
|
||||
vec2 icursoroff; ///< Initial Cursor Offset (Also in Newline)
|
||||
vec2 bcursor; ///< Backup Cursor
|
||||
vec2 slcursor; ///< Sameline Cursor
|
||||
vec4 view_area; ///< view Area (Position and Size)
|
||||
vec4 main_area; ///< Main Area [Input related]
|
||||
vec2 scrolling_off; ///< Scrolling Position
|
||||
bool scrolling[2]; ///< Is Hz or Vt Scrolling Enabled
|
||||
vec2 scroll_mod; ///< Scroll Modificator
|
||||
float tbh; ///< Titlebar height
|
||||
bool scrollbar[2]; ///< Is Hz or Vt Scrollbar rendered
|
||||
bool scroll_allowed[2]; ///< Is Hz or Vt Scrolling Alowed
|
||||
bool has_touch; ///< Menu has touch (depends on screen)
|
||||
bool is_open = true; ///< For Collapse Event
|
||||
bool* is_shown = nullptr; ///< For Close Button
|
||||
|
||||
Container::Ref tmp_parent; ///< Parent Container (for better alignment etc)
|
||||
|
||||
@ -385,11 +395,9 @@ class Menu : public SmartCtor<Menu> {
|
||||
int count_btn = 0; ///< Count for Button ID Prefix
|
||||
int count_cbx = 0; ///< Cound for Checkbox ID Prefix
|
||||
|
||||
// DrawLists
|
||||
// DrawList
|
||||
|
||||
DrawList::Ref back; ///< Background Drawlist
|
||||
DrawList::Ref main; ///< Main Drawlist
|
||||
DrawList::Ref front; ///< Foreground Drawlist
|
||||
DrawList::Ref main; ///< Main Drawlist
|
||||
|
||||
vec2 max; ///< Max Position
|
||||
vec2 mouse; ///< Mouse/Touch Position
|
||||
|
@ -41,6 +41,7 @@ enum UI7Color_ {
|
||||
UI7Color_Text, ///< UI7 Text Color
|
||||
UI7Color_TextDead, ///< UI7 Dead Text Color
|
||||
UI7Color_Header, ///< UI7 Menu Header Color
|
||||
UI7Color_HeaderDead, ///< Inactive Header
|
||||
UI7Color_Selector, ///< UI7 Selector Color
|
||||
UI7Color_Checkmark, ///< UI7 Checkmark Color
|
||||
UI7Color_FrameBackground, ///< UI7 Frame Background
|
||||
@ -118,6 +119,20 @@ class Theme : public SmartCtor<Theme> {
|
||||
return e->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* [UNSAFE] to use
|
||||
* Get the Color Ref of a Color ReferenceID
|
||||
* @param c ReferenceID
|
||||
*/
|
||||
u32& GetRef(UI7Color c) {
|
||||
auto e = theme.find(c);
|
||||
if (e == theme.end()) {
|
||||
static u32 noclr = 0x00000000;
|
||||
return noclr;
|
||||
}
|
||||
return e->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator wrapper for get
|
||||
* @param c Color ReferenceID
|
||||
|
@ -37,7 +37,7 @@ SOFTWARE.
|
||||
* Major Minor Patch Build
|
||||
* 0x01010000 -> 1.1.0-0
|
||||
*/
|
||||
#define UI7_VERSION 0x00020800
|
||||
#define UI7_VERSION 0x00020900
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
@ -68,7 +68,7 @@ class Context : public SmartCtor<Context> {
|
||||
* @return If the Menu was Created
|
||||
* (useless as false results in an error screen)
|
||||
*/
|
||||
bool BeginMenu(const ID& id, UI7MenuFlags flags = 0);
|
||||
bool BeginMenu(const ID& id, UI7MenuFlags flags = 0, bool* show = nullptr);
|
||||
/**
|
||||
* Get the Current Menu
|
||||
* for example for auto m = ctx->GetCurrentMenu
|
||||
@ -126,13 +126,13 @@ class Context : public SmartCtor<Context> {
|
||||
// Debugging / Demo / About
|
||||
|
||||
/** About Menu */
|
||||
void AboutMenu();
|
||||
void AboutMenu(bool* show = nullptr);
|
||||
|
||||
/** Metrics */
|
||||
void MetricsMenu();
|
||||
void MetricsMenu(bool* show = nullptr);
|
||||
|
||||
/** Style Editor Menu (Includes Theme Editor) */
|
||||
void StyleEditor();
|
||||
void StyleEditor(bool* show = nullptr);
|
||||
|
||||
private:
|
||||
// Used in Overlays
|
||||
|
Reference in New Issue
Block a user