Slight changes to phone color selector UI
This commit is contained in:
parent
c0474690f7
commit
45aa5ed1b4
3 changed files with 71 additions and 55 deletions
|
|
@ -65,14 +65,14 @@ template <typename T> class DropDown : public Element {
|
||||||
gui.element<LayoutElement>("DROPDOWN", [&](LayoutElement* l, const Clay_ElementId& lId) {
|
gui.element<LayoutElement>("DROPDOWN", [&](LayoutElement* l, const Clay_ElementId& lId) {
|
||||||
float dropdownHeight = ENTRY_HEIGHT * selections.size() + DROPDOWN_OFFSET;
|
float dropdownHeight = ENTRY_HEIGHT * selections.size() + DROPDOWN_OFFSET;
|
||||||
Clay_FloatingElementConfig floatConfig;
|
Clay_FloatingElementConfig floatConfig;
|
||||||
float maxHeight = gui.io.windowSize.y();
|
float maxHeight = gui.io.safeWindowRect.height();
|
||||||
if(buttonBB.max.y() + dropdownHeight > gui.io.windowSize.y()) {
|
if(buttonBB.max.y() + dropdownHeight > gui.io.safeWindowRect.max.y()) {
|
||||||
float rightSideWidth = gui.io.windowSize.x() - buttonBB.max.x();
|
float rightSideWidth = gui.io.safeWindowRect.max.x() - buttonBB.max.x();
|
||||||
float leftSideWidth = buttonBB.min.x();
|
float leftSideWidth = buttonBB.min.x() - gui.io.safeWindowRect.min.x();
|
||||||
if(rightSideWidth > buttonBB.width() || leftSideWidth > buttonBB.width())
|
if(rightSideWidth > buttonBB.width() || leftSideWidth > buttonBB.width())
|
||||||
vertical_offset_setup(dropdownHeight, floatConfig, maxHeight, rightSideWidth >= leftSideWidth);
|
vertical_offset_setup(dropdownHeight, floatConfig, maxHeight, rightSideWidth >= leftSideWidth);
|
||||||
else {
|
else {
|
||||||
if(gui.io.windowSize.y() - buttonBB.max.y() >= buttonBB.min.y())
|
if(gui.io.safeWindowRect.max.y() - buttonBB.max.y() >= buttonBB.min.y() - gui.io.safeWindowRect.min.y())
|
||||||
bottom_offset_setup(dropdownHeight, floatConfig, maxHeight);
|
bottom_offset_setup(dropdownHeight, floatConfig, maxHeight);
|
||||||
else
|
else
|
||||||
top_offset_setup(dropdownHeight, floatConfig, maxHeight);
|
top_offset_setup(dropdownHeight, floatConfig, maxHeight);
|
||||||
|
|
@ -132,7 +132,7 @@ template <typename T> class DropDown : public Element {
|
||||||
.attachTo = CLAY_ATTACH_TO_PARENT
|
.attachTo = CLAY_ATTACH_TO_PARENT
|
||||||
};
|
};
|
||||||
// This function might be used even when boundingBox isnt determined yet
|
// This function might be used even when boundingBox isnt determined yet
|
||||||
maxHeight = boundingBox.has_value() ? std::max(gui.io.windowSize.y() - boundingBox.value().max.y() - DROPDOWN_OFFSET, 0.0f) : 0.0f;
|
maxHeight = boundingBox.has_value() ? std::max(gui.io.safeWindowRect.max.y() - boundingBox.value().max.y() - DROPDOWN_OFFSET, 0.0f) : 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void top_offset_setup(float dropdownHeight, Clay_FloatingElementConfig& floatConfig, float& maxHeight) {
|
void top_offset_setup(float dropdownHeight, Clay_FloatingElementConfig& floatConfig, float& maxHeight) {
|
||||||
|
|
@ -147,16 +147,16 @@ template <typename T> class DropDown : public Element {
|
||||||
},
|
},
|
||||||
.attachTo = CLAY_ATTACH_TO_PARENT
|
.attachTo = CLAY_ATTACH_TO_PARENT
|
||||||
};
|
};
|
||||||
maxHeight = std::max(boundingBox.value().min.y() - DROPDOWN_OFFSET, 0.0f);
|
maxHeight = std::max(boundingBox.value().min.y() - gui.io.safeWindowRect.min.y() - DROPDOWN_OFFSET, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vertical_offset_setup(float dropdownHeight, Clay_FloatingElementConfig& floatConfig, float& maxHeight, bool isRightSide) {
|
void vertical_offset_setup(float dropdownHeight, Clay_FloatingElementConfig& floatConfig, float& maxHeight, bool isRightSide) {
|
||||||
auto& bb = boundingBox.value();
|
auto& bb = boundingBox.value();
|
||||||
float offsetY = bb.center().y() - dropdownHeight * 0.5f;
|
float offsetY = bb.center().y() - dropdownHeight * 0.5f;
|
||||||
if(dropdownHeight >= gui.io.windowSize.y() || offsetY < 0.0f)
|
if(dropdownHeight >= gui.io.safeWindowRect.height() || offsetY < gui.io.safeWindowRect.min.y())
|
||||||
offsetY = 0.0f;
|
offsetY = gui.io.safeWindowRect.min.y();
|
||||||
else if(offsetY + dropdownHeight > gui.io.windowSize.y())
|
else if(offsetY + dropdownHeight > gui.io.safeWindowRect.max.y())
|
||||||
offsetY -= (offsetY + dropdownHeight) - gui.io.windowSize.y();
|
offsetY -= (offsetY + dropdownHeight) - gui.io.safeWindowRect.max.y();
|
||||||
floatConfig = {
|
floatConfig = {
|
||||||
.offset = {
|
.offset = {
|
||||||
.x = isRightSide ? bb.max.x() + DROPDOWN_OFFSET : bb.min.x() - bb.width() - DROPDOWN_OFFSET,
|
.x = isRightSide ? bb.max.x() + DROPDOWN_OFFSET : bb.min.x() - bb.width() - DROPDOWN_OFFSET,
|
||||||
|
|
@ -169,7 +169,7 @@ template <typename T> class DropDown : public Element {
|
||||||
},
|
},
|
||||||
.attachTo = CLAY_ATTACH_TO_ROOT
|
.attachTo = CLAY_ATTACH_TO_ROOT
|
||||||
};
|
};
|
||||||
maxHeight = gui.io.windowSize.y();
|
maxHeight = gui.io.safeWindowRect.height();
|
||||||
}
|
}
|
||||||
|
|
||||||
void text_transparent_option_button(const char* id, const char* text, const std::function<void()>& onClick) {
|
void text_transparent_option_button(const char* id, const char* text, const std::function<void()>& onClick) {
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,8 @@ void TreeListing::layout(const Clay_ElementId& id, const Data& newDisplayData) {
|
||||||
}
|
}
|
||||||
}, LayoutElement::Callbacks {
|
}, LayoutElement::Callbacks {
|
||||||
.onClick = [&, i] (LayoutElement* l, const InputManager::MouseButtonCallbackArgs& button) {
|
.onClick = [&, i] (LayoutElement* l, const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
if(l->mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down) {
|
bool hovering = l->mouseHovering || (l->childMouseHovering && button.deviceType == InputManager::MouseDeviceType::TOUCH);
|
||||||
|
if(hovering && button.button == InputManager::MouseButton::LEFT && button.down) {
|
||||||
gui.set_post_callback_func([&, i, button, l]{
|
gui.set_post_callback_func([&, i, button, l]{
|
||||||
auto& objIndex = flattenedIndexList[i].objIndex;
|
auto& objIndex = flattenedIndexList[i].objIndex;
|
||||||
if(d.selectedIndices) {
|
if(d.selectedIndices) {
|
||||||
|
|
@ -149,7 +150,7 @@ void TreeListing::layout(const Clay_ElementId& id, const Data& newDisplayData) {
|
||||||
d.selectedIndices->emplace(objIndex);
|
d.selectedIndices->emplace(objIndex);
|
||||||
if(d.onSelectChange) d.onSelectChange();
|
if(d.onSelectChange) d.onSelectChange();
|
||||||
}
|
}
|
||||||
isDragging = true;
|
isDragging = button.deviceType != InputManager::MouseDeviceType::TOUCH || l->childMouseHovering;
|
||||||
dragIndexStart = dragIndexEnd = i;
|
dragIndexStart = dragIndexEnd = i;
|
||||||
dragFromTop = button.pos.y() - l->get_bb().value().min.y() < ENTRY_HEIGHT * 0.5f;
|
dragFromTop = button.pos.y() - l->get_bb().value().min.y() < ENTRY_HEIGHT * 0.5f;
|
||||||
}
|
}
|
||||||
|
|
@ -161,7 +162,7 @@ void TreeListing::layout(const Clay_ElementId& id, const Data& newDisplayData) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.onMotion = [&, i] (LayoutElement* l, const InputManager::MouseMotionCallbackArgs& motion) {
|
.onMotion = [&, i] (LayoutElement* l, const InputManager::MouseMotionCallbackArgs& motion) {
|
||||||
if(isDragging && l->mouseHovering) {
|
if(isDragging && (l->mouseHovering || l->childMouseHovering)) {
|
||||||
size_t newDragIndexEnd = i;
|
size_t newDragIndexEnd = i;
|
||||||
bool newDragFromTop = motion.pos.y() - l->get_bb().value().min.y() < ENTRY_HEIGHT * 0.5f;
|
bool newDragFromTop = motion.pos.y() - l->get_bb().value().min.y() < ENTRY_HEIGHT * 0.5f;
|
||||||
if(dragIndexEnd != newDragIndexEnd || dragFromTop != newDragFromTop) {
|
if(dragIndexEnd != newDragIndexEnd || dragFromTop != newDragFromTop) {
|
||||||
|
|
|
||||||
|
|
@ -257,15 +257,8 @@ void PhoneDrawingProgramScreen::color_settings_popup(Vector4f* color) {
|
||||||
|
|
||||||
bool extraSettingsOpen = colorPickerPopupData.screenType == ColorPickerPopupData::ScreenType::EXTRA;
|
bool extraSettingsOpen = colorPickerPopupData.screenType == ColorPickerPopupData::ScreenType::EXTRA;
|
||||||
bool extraColorButtons = extraSettingsOpen && colorPickerPopupData.selectedPalette != 0;
|
bool extraColorButtons = extraSettingsOpen && colorPickerPopupData.selectedPalette != 0;
|
||||||
auto paletteColorPickerGrid = [&] {
|
|
||||||
gui.element<GridScrollArea>("color selector grid", GridScrollArea::Options{
|
auto paletteColorPickerGridColorButton = [&](size_t i){
|
||||||
.entryWidth = BIG_BUTTON_SIZE,
|
|
||||||
.childAlignmentX = CLAY_ALIGN_X_CENTER,
|
|
||||||
.entryHeight = BIG_BUTTON_SIZE,
|
|
||||||
.entryCount = palette.colors.size() + (extraColorButtons ? 3 : 1),
|
|
||||||
.scrollbar = ScrollArea::ScrollbarType::NORMAL,
|
|
||||||
.elementContent = [&](size_t i) {
|
|
||||||
if(i < palette.colors.size()) {
|
|
||||||
auto newC = std::make_shared<Vector3f>(palette.colors[i].x(), palette.colors[i].y(), palette.colors[i].z());
|
auto newC = std::make_shared<Vector3f>(palette.colors[i].x(), palette.colors[i].y(), palette.colors[i].z());
|
||||||
color_button(gui, "c", newC.get(), {
|
color_button(gui, "c", newC.get(), {
|
||||||
.isSelected = newC->x() == color->x() && newC->y() == color->y() && newC->z() == color->z(),
|
.isSelected = newC->x() == color->x() && newC->y() == color->y() && newC->z() == color->z(),
|
||||||
|
|
@ -277,12 +270,44 @@ void PhoneDrawingProgramScreen::color_settings_popup(Vector4f* color) {
|
||||||
color->z() = newC->z();
|
color->z() = newC->z();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
auto paletteColorPickerGrid = [&] {
|
||||||
|
gui.element<GridScrollArea>("color selector grid", GridScrollArea::Options{
|
||||||
|
.entryWidth = BIG_BUTTON_SIZE,
|
||||||
|
.childAlignmentX = CLAY_ALIGN_X_CENTER,
|
||||||
|
.entryHeight = BIG_BUTTON_SIZE,
|
||||||
|
.entryCount = palette.colors.size() + (extraColorButtons ? 3 : 1),
|
||||||
|
.scrollbar = ScrollArea::ScrollbarType::NORMAL,
|
||||||
|
.elementContent = [&](size_t i) {
|
||||||
|
if(colorPickerPopupData.screenType == ColorPickerPopupData::ScreenType::NORMAL) {
|
||||||
|
if(i < palette.colors.size())
|
||||||
|
paletteColorPickerGridColorButton(i);
|
||||||
|
else {
|
||||||
|
svg_icon_button(gui, "extra color settings", "data/icons/RemixIcon/more-fill.svg", {
|
||||||
|
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
|
||||||
|
.onClick = [&] {
|
||||||
|
colorPickerPopupData.screenType = ColorPickerPopupData::ScreenType::EXTRA;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(extraColorButtons) {
|
if(i == 0) {
|
||||||
switch(i - palette.colors.size()) {
|
svg_icon_button(gui, "extra color settings", "data/icons/RemixIcon/arrow-left-s-line.svg", {
|
||||||
|
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
|
||||||
|
.onClick = [&] {
|
||||||
|
colorPickerPopupData.screenType = ColorPickerPopupData::ScreenType::NORMAL;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if((i - 1) < palette.colors.size())
|
||||||
|
paletteColorPickerGridColorButton(i - 1);
|
||||||
|
else if(extraColorButtons) {
|
||||||
|
switch(i - palette.colors.size() - 1) {
|
||||||
case 0:
|
case 0:
|
||||||
svg_icon_button(gui, "addcolor", "data/icons/plus.svg", {
|
svg_icon_button(gui, "addcolor", "data/icons/plus.svg", {
|
||||||
|
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
|
||||||
.onClick = [&, color] {
|
.onClick = [&, color] {
|
||||||
std::erase(palette.colors, Vector3f{color->x(), color->y(), color->z()});
|
std::erase(palette.colors, Vector3f{color->x(), color->y(), color->z()});
|
||||||
palette.colors.emplace_back(color->x(), color->y(), color->z());
|
palette.colors.emplace_back(color->x(), color->y(), color->z());
|
||||||
|
|
@ -291,36 +316,13 @@ void PhoneDrawingProgramScreen::color_settings_popup(Vector4f* color) {
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
svg_icon_button(gui, "deletecolor", "data/icons/close.svg", {
|
svg_icon_button(gui, "deletecolor", "data/icons/close.svg", {
|
||||||
|
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
|
||||||
.onClick = [&, color] {
|
.onClick = [&, color] {
|
||||||
std::erase(palette.colors, Vector3f{color->x(), color->y(), color->z()});
|
std::erase(palette.colors, Vector3f{color->x(), color->y(), color->z()});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 2:
|
|
||||||
svg_icon_button(gui, "extra color settings", "data/icons/RemixIcon/more-fill.svg", {
|
|
||||||
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
|
|
||||||
.isSelected = extraSettingsOpen,
|
|
||||||
.onClick = [&] {
|
|
||||||
if(colorPickerPopupData.screenType == ColorPickerPopupData::ScreenType::NORMAL)
|
|
||||||
colorPickerPopupData.screenType = ColorPickerPopupData::ScreenType::EXTRA;
|
|
||||||
else
|
|
||||||
colorPickerPopupData.screenType = ColorPickerPopupData::ScreenType::NORMAL;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
svg_icon_button(gui, "extra color settings", "data/icons/RemixIcon/more-fill.svg", {
|
|
||||||
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
|
|
||||||
.isSelected = extraSettingsOpen,
|
|
||||||
.onClick = [&] {
|
|
||||||
if(colorPickerPopupData.screenType == ColorPickerPopupData::ScreenType::NORMAL)
|
|
||||||
colorPickerPopupData.screenType = ColorPickerPopupData::ScreenType::EXTRA;
|
|
||||||
else
|
|
||||||
colorPickerPopupData.screenType = ColorPickerPopupData::ScreenType::NORMAL;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -336,7 +338,11 @@ void PhoneDrawingProgramScreen::color_settings_popup(Vector4f* color) {
|
||||||
},
|
},
|
||||||
.aspectRatio = {1.0f}
|
.aspectRatio = {1.0f}
|
||||||
}) {
|
}) {
|
||||||
gui.element<ColorPicker<Vector4f>>("color picker element", color, true);
|
gui.element<ColorPicker<Vector4f>>("color picker element", color, true, ColorPickerData{
|
||||||
|
.onChange = [&] {
|
||||||
|
gui.set_to_layout();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
CLAY_AUTO_ID({
|
CLAY_AUTO_ID({
|
||||||
.layout = {
|
.layout = {
|
||||||
|
|
@ -350,7 +356,7 @@ void PhoneDrawingProgramScreen::color_settings_popup(Vector4f* color) {
|
||||||
for(auto& p : main.conf.palettes)
|
for(auto& p : main.conf.palettes)
|
||||||
paletteNames.emplace_back(p.name);
|
paletteNames.emplace_back(p.name);
|
||||||
gui.element<DropDown<size_t>>("paletteselector", &colorPickerPopupData.selectedPalette, paletteNames);
|
gui.element<DropDown<size_t>>("paletteselector", &colorPickerPopupData.selectedPalette, paletteNames);
|
||||||
svg_icon_button(gui, "paletteadd", "data/icons/RemixIcon/more-fill.svg", {
|
svg_icon_button(gui, "paletteadd", "data/icons/pencil.svg", {
|
||||||
.onClick = [&] {
|
.onClick = [&] {
|
||||||
reset_color_picker_popup_data();
|
reset_color_picker_popup_data();
|
||||||
colorPickerPopupData.screenType = ColorPickerPopupData::ScreenType::PALETTES;
|
colorPickerPopupData.screenType = ColorPickerPopupData::ScreenType::PALETTES;
|
||||||
|
|
@ -406,6 +412,15 @@ void PhoneDrawingProgramScreen::color_settings_popup(Vector4f* color) {
|
||||||
}) {
|
}) {
|
||||||
text_label(gui, main.conf.palettes[objIndex.back()].name);
|
text_label(gui, main.conf.palettes[objIndex.back()].name);
|
||||||
}
|
}
|
||||||
|
if(gui.io.isTouchDevice) {
|
||||||
|
gui.set_z_index_keep_clipping_region(gui.get_z_index() + 1, [&] {
|
||||||
|
CLAY_AUTO_ID({
|
||||||
|
.layout = {.sizing = {.width = CLAY_SIZING_FIXED(TreeListing::ENTRY_HEIGHT), .height = CLAY_SIZING_FIXED(TreeListing::ENTRY_HEIGHT)}}
|
||||||
|
}) {
|
||||||
|
gui.element<SVGIcon>("touch screen holder", "data/icons/menu.svg");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
gui.set_z_index_keep_clipping_region(gui.get_z_index() + 1, [&] {
|
gui.set_z_index_keep_clipping_region(gui.get_z_index() + 1, [&] {
|
||||||
svg_icon_button(gui, "edit button", "data/icons/pencil.svg", {
|
svg_icon_button(gui, "edit button", "data/icons/pencil.svg", {
|
||||||
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
|
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue