# 0.3.1-1
- Add Deltatime usage for Overscroll as well as a config value for ids multiplier - Add Function to Layout to remove all ID Objects - Add step and precision to DragData as well as setting min and max to their type limits - Use the Address for now for the id of the DragData (cause with tree nodes opened backwars all DragData will share the same data reference) - Add a fix to MaxPosition in Layout to be actually the max Position on X axis
This commit is contained in:
parent
35272687f6
commit
6738fda55c
@ -38,17 +38,26 @@ class DragData : public Container {
|
||||
/**
|
||||
* Constructor
|
||||
* @param label Label of the Button
|
||||
* @param pos Base Position
|
||||
* @param lr Reference to the Renderer
|
||||
* @param data Data reference (Supported types can be seen in dragdata.cpp)
|
||||
* @param num_elms Number of Array elements (for exaple with use ofvec4)
|
||||
* @param io IO Reference
|
||||
* @param min minimum number using Minimum limit
|
||||
* @param max Maximum number set by max limit by default
|
||||
* @param step To set the modifier for drag movement
|
||||
* @param precision for float and double to set precision
|
||||
*/
|
||||
DragData(const std::string& label, T* data, size_t num_elms, UI7::IO::Ref io,
|
||||
T min = 0, T max = 100) {
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max(), T step = 1,
|
||||
int precision = 1) {
|
||||
PD::Assert(data != nullptr, "Input Data Address is null!");
|
||||
this->label = label;
|
||||
this->data = data;
|
||||
this->elm_count = num_elms;
|
||||
this->min = min;
|
||||
this->max = max;
|
||||
this->step = step;
|
||||
this->precision = precision;
|
||||
this->tdim = io->Ren->GetTextDimensions(label);
|
||||
}
|
||||
~DragData() = default;
|
||||
@ -74,6 +83,8 @@ class DragData : public Container {
|
||||
size_t elm_count = 0;
|
||||
T min;
|
||||
T max;
|
||||
T step;
|
||||
int precision = 1;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -71,7 +71,8 @@ class IO : public SmartCtor<IO> {
|
||||
vec2 FramePadding = 5.f;
|
||||
vec2 ItemSpace = vec2(5.f, 2.f);
|
||||
vec2 MinSliderDragSize = 10.f; // Min height (Vt) and Min Width (Hz)
|
||||
u64 DoubleClickTime = 500; // Milliseconds
|
||||
float OverScrollMod = 0.15f;
|
||||
u64 DoubleClickTime = 500; // Milliseconds
|
||||
std::vector<std::pair<UI7::ID, DrawList::Ref>> DrawListRegestry;
|
||||
DrawList::Ref Back;
|
||||
DrawList::Ref Front;
|
||||
|
@ -63,6 +63,7 @@ class Layout : public PD::SmartCtor<Layout> {
|
||||
|
||||
void AddObject(Container::Ref obj);
|
||||
Container::Ref FindObject(u32 id);
|
||||
void ClearIDObjects() { IDObjects.clear(); }
|
||||
|
||||
vec2 AlignPosition(vec2 pos, vec2 size, vec4 area, UI7Align alignment);
|
||||
|
||||
|
@ -92,11 +92,14 @@ class Menu : public SmartCtor<Menu> {
|
||||
void DragFloat(const std::string& label, float* data, size_t num_elms);
|
||||
template <typename T>
|
||||
void DragData(const std::string& label, T* data, size_t num_elms = 1,
|
||||
T min = 0, T max = 100) {
|
||||
u32 id = Strings::FastHash("dfl" + label + std::to_string(count_btn++));
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max(), T step = 1,
|
||||
int precision = 1) {
|
||||
u32 id = Strings::FastHash("drd" + label + std::to_string((u32)data));
|
||||
Container::Ref r = Layout->FindObject(id);
|
||||
if (!r) {
|
||||
r = PD::New<UI7::DragData<T>>(label, data, num_elms, io, min, max);
|
||||
r = PD::New<UI7::DragData<T>>(label, data, num_elms, io, min, max, step,
|
||||
precision);
|
||||
r->SetID(id);
|
||||
}
|
||||
Layout->AddObject(r);
|
||||
|
@ -37,7 +37,7 @@ SOFTWARE.
|
||||
* Major Minor Patch Build
|
||||
* 0x01010000 -> 1.1.0-0
|
||||
*/
|
||||
#define UI7_VERSION 0x00030100
|
||||
#define UI7_VERSION 0x00030101
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
|
@ -48,7 +48,7 @@ void DragData<T>::HandleInput() {
|
||||
for (size_t i = 0; i < elm_count; i++) {
|
||||
std::string p;
|
||||
if constexpr (std::is_floating_point_v<T>) {
|
||||
p = std::format("{:.1f}", data[i]);
|
||||
p = std::format("{:.{}f}", data[i], precision);
|
||||
} else {
|
||||
p = std::format("{}", data[i]);
|
||||
}
|
||||
@ -57,9 +57,9 @@ void DragData<T>::HandleInput() {
|
||||
if (io->DragObject(
|
||||
this->GetID() + i + 1,
|
||||
vec4(FinalPos() + vec2(off_x, 0), tdim + io->FramePadding))) {
|
||||
data[i] = std::clamp(
|
||||
T(data[i] + (io->DragPosition[0] - io->DragLastPosition[0])),
|
||||
this->min, this->max);
|
||||
data[i] = std::clamp(T(data[i] + (step * (io->DragPosition[0] -
|
||||
io->DragLastPosition[0]))),
|
||||
this->min, this->max);
|
||||
}
|
||||
off_x += tdim.x() + io->ItemSpace.x() + io->FramePadding.x();
|
||||
}
|
||||
@ -75,7 +75,7 @@ void DragData<T>::Draw() {
|
||||
for (size_t i = 0; i < elm_count; i++) {
|
||||
std::string p;
|
||||
if constexpr (std::is_floating_point_v<T>) {
|
||||
p = std::format("{:.1f}", data[i]);
|
||||
p = std::format("{:.{}f}", data[i], precision);
|
||||
} else {
|
||||
p = std::format("{}", data[i]);
|
||||
}
|
||||
@ -88,14 +88,26 @@ void DragData<T>::Draw() {
|
||||
list->Layer(list->Layer() - 1);
|
||||
off_x += td.x() + io->ItemSpace.x() + io->FramePadding.x();
|
||||
}
|
||||
list->AddText(FinalPos() + vec2(off_x, 0), label,
|
||||
list->AddText(FinalPos() + vec2(off_x, io->FramePadding.y() * 0.5), label,
|
||||
io->Theme->Get(UI7Color_Text));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DragData<T>::Update() {
|
||||
Assert(io.get(), "Did you run Container::Init correctly?");
|
||||
this->SetSize(vec2(tdim.x() + io->ItemSpace.x() + 20, 20));
|
||||
// Probably need to find a faster solution (caching sizes calculated here)
|
||||
float off_x = 0;
|
||||
for (size_t i = 0; i < elm_count; i++) {
|
||||
std::string p;
|
||||
if constexpr (std::is_floating_point_v<T>) {
|
||||
p = std::format("{:.{}f}", data[i], precision);
|
||||
} else {
|
||||
p = std::format("{}", data[i]);
|
||||
}
|
||||
vec2 tdim = io->Ren->GetTextDimensions(p);
|
||||
off_x += tdim.x() + io->ItemSpace.x() + io->FramePadding.x();
|
||||
}
|
||||
this->SetSize(vec2(tdim.x() + off_x, tdim.y() + io->FramePadding.y()));
|
||||
}
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -44,7 +44,7 @@ void Layout::CursorMove(const vec2& size) {
|
||||
Cursor[1] + size[1] + IO->ItemSpace[1]);
|
||||
}
|
||||
// Logical Issue here as x should use a max check
|
||||
MaxPosition = vec2(SamelineCursor[0], Cursor[1]);
|
||||
MaxPosition = vec2(std::max(MaxPosition[0], SamelineCursor[0]), Cursor[1]);
|
||||
}
|
||||
|
||||
bool Layout::ObjectWorkPos(vec2& movpos) {
|
||||
|
@ -249,7 +249,7 @@ void UI7::Menu::PostHandler() {
|
||||
if (Layout->ScrollOffset[1] > Layout->MaxPosition[1] - Layout->Size.y() &&
|
||||
Layout->MaxPosition[1] != 0.f &&
|
||||
Layout->MaxPosition[1] >= Layout->Size.y() - io->MenuPadding[1]) {
|
||||
Layout->ScrollOffset[1] -= 3.f;
|
||||
Layout->ScrollOffset[1] -= io->OverScrollMod * io->Delta;
|
||||
if (Layout->ScrollOffset[1] <
|
||||
Layout->MaxPosition[1] - Layout->Size.y()) {
|
||||
Layout->ScrollOffset[1] = Layout->MaxPosition[1] - Layout->Size.y();
|
||||
@ -258,7 +258,7 @@ void UI7::Menu::PostHandler() {
|
||||
|
||||
/// Do the Same as above just for Overscroll back to the top
|
||||
if (Layout->ScrollOffset[1] < 0) {
|
||||
Layout->ScrollOffset[1] += 3.f;
|
||||
Layout->ScrollOffset[1] += io->OverScrollMod * io->Delta;
|
||||
if (Layout->ScrollOffset[1] > 0) {
|
||||
Layout->ScrollOffset[1] = 0;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ namespace UI7 {
|
||||
void Theme::Default(Theme& theme) {
|
||||
theme.Set(UI7Color_Text, Color("#FFFFFFFF"));
|
||||
theme.Set(UI7Color_TextDead, Color("#AAAAAAFF"));
|
||||
theme.Set(UI7Color_Background, Color("#222222aa"));
|
||||
theme.Set(UI7Color_Background, Color("#222222ff"));
|
||||
theme.Set(UI7Color_Button, Color("#111111FF"));
|
||||
theme.Set(UI7Color_ButtonDead, Color("#080808FF"));
|
||||
theme.Set(UI7Color_ButtonActive, Color("#2A2A2AFF"));
|
||||
@ -52,7 +52,7 @@ void Theme::Flashbang(Theme& theme) {
|
||||
theme.Set(UI7Color_Button, Color("#ccccccFF"));
|
||||
theme.Set(UI7Color_ButtonDead, Color("#bbbbbbFF"));
|
||||
theme.Set(UI7Color_ButtonActive, Color("#ccccccFF"));
|
||||
theme.Set(UI7Color_ButtonHovered, Color("#cbcbcbFF"));
|
||||
theme.Set(UI7Color_ButtonHovered, Color("#acacacFF"));
|
||||
theme.Set(UI7Color_Header, Color("#ddddddFF"));
|
||||
theme.Set(UI7Color_HeaderDead, Color("#cdcdcdFF"));
|
||||
theme.Set(UI7Color_Selector, Color("#222222FF"));
|
||||
|
@ -260,6 +260,8 @@ void UI7::Context::StyleEditor(bool* show) {
|
||||
m->DragData("FramePadding", (float*)&io->FramePadding, 2, 0.f, 100.f);
|
||||
m->DragData("ItemSpace", (float*)&io->ItemSpace, 2, 0.f, 100.f);
|
||||
m->DragData("MinSliderSize", (float*)&io->MinSliderDragSize, 2, 1.f, 100.f);
|
||||
m->DragData("OverScroll Modifier", &io->OverScrollMod, 1, 0.01f,
|
||||
std::numeric_limits<float>::max(), 0.01f, 2);
|
||||
m->SeparatorText("Theme");
|
||||
if (m->Button("Dark")) {
|
||||
UI7::Theme::Default(*io->Theme.get());
|
||||
@ -270,8 +272,9 @@ void UI7::Context::StyleEditor(bool* show) {
|
||||
}
|
||||
/// Small trick to print without prefix
|
||||
#define ts(x) m->ColorEdit(std::string(#x).substr(9), &io->Theme->GetRef(x));
|
||||
#define ts2(x) \
|
||||
m->DragData(std::string(#x).substr(9), (u8*)&io->Theme->GetRef(x), 4, (u8)0, (u8)255);
|
||||
#define ts2(x) \
|
||||
m->DragData(std::string(#x).substr(9), (u8*)&io->Theme->GetRef(x), 4, (u8)0, \
|
||||
(u8)255);
|
||||
ts2(UI7Color_Background);
|
||||
ts2(UI7Color_Button);
|
||||
ts2(UI7Color_ButtonDead);
|
||||
|
Loading…
Reference in New Issue
Block a user