Y scrollbar added to scroll area
This commit is contained in:
parent
732261b58c
commit
fcdf1944f7
4 changed files with 321 additions and 275 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include "ScrollArea.hpp"
|
||||
#include "../GUIManager.hpp"
|
||||
#include "LayoutElement.hpp"
|
||||
|
||||
namespace GUIStuff {
|
||||
|
||||
|
|
@ -13,12 +14,18 @@ void ScrollArea::layout(const Clay_ElementId& id, const Options& options) {
|
|||
Clay_ElementId localID = CLAY_ID_LOCAL("SCROLL_AREA");
|
||||
|
||||
Clay_ScrollContainerData scrollData = Clay_GetScrollContainerData(localID);
|
||||
Clay_ElementData elemData = Clay_GetElementData(localID);
|
||||
|
||||
Vector2f bbPos = {0.0f, 0.0f};
|
||||
|
||||
if(scrollData.found) {
|
||||
contentDimensions = {scrollData.contentDimensions.width, scrollData.contentDimensions.height};
|
||||
containerDimensions = {scrollData.scrollContainerDimensions.width, scrollData.scrollContainerDimensions.height};
|
||||
}
|
||||
|
||||
if(elemData.found)
|
||||
bbPos = {elemData.boundingBox.x, elemData.boundingBox.y};
|
||||
|
||||
clamp_scroll();
|
||||
|
||||
CLAY(localID, {
|
||||
|
|
@ -32,68 +39,98 @@ void ScrollArea::layout(const Clay_ElementId& id, const Options& options) {
|
|||
opts.innerContent({.contentDimensions = contentDimensions, .containerDimensions = containerDimensions, .scrollOffset = scrollOffset});
|
||||
}
|
||||
|
||||
//if(scrollData.contentDimensions.height > scrollData.scrollContainerDimensions.height) {
|
||||
// float sAreaDim = scrollData.scrollContainerDimensions.height;
|
||||
// float contDim = scrollData.contentDimensions.height;
|
||||
// float scrollerSize = (sAreaDim / contDim) * sAreaDim;
|
||||
// float scrollPosMax = contDim - sAreaDim;
|
||||
// float scrollerPos = std::fabs(scrollData.scrollPosition->y / scrollPosMax);
|
||||
// float areaAboveScrollerSize = scrollerPos * (sAreaDim - scrollerSize);
|
||||
if(scrollData.contentDimensions.height > scrollData.scrollContainerDimensions.height) {
|
||||
float sAreaDim = containerDimensions.y();
|
||||
float sAreaStart = bbPos.y();
|
||||
float contDim = contentDimensions.y();
|
||||
float scrollerSize = (sAreaDim / contDim) * sAreaDim;
|
||||
float scrollPosMax = contDim - sAreaDim;
|
||||
float scrollerPos = std::fabs(scrollOffset.y() / scrollPosMax);
|
||||
float areaAboveScrollerSize = scrollerPos * (sAreaDim - scrollerSize);
|
||||
|
||||
// currentScrollPos = scrollData.scrollPosition->y;
|
||||
gui.element<LayoutElement>("scroll bar", [&] (const Clay_ElementId& lId) {
|
||||
CLAY(lId, {
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_FIXED(12), .height = CLAY_SIZING_GROW(0)},
|
||||
.childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP},
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM
|
||||
},
|
||||
.backgroundColor = convert_vec4<Clay_Color>(gui.io.theme->backColor2)
|
||||
}) {
|
||||
SkColor4f scrollerColor;
|
||||
if(isScrollbarHeldY)
|
||||
scrollerColor = gui.io.theme->fillColor1;
|
||||
else if(isScrollbarHoveredY)
|
||||
scrollerColor = gui.io.theme->fillColor1;
|
||||
else
|
||||
scrollerColor = gui.io.theme->fillColor2;
|
||||
|
||||
// CLAY_AUTO_ID({
|
||||
// .layout = {
|
||||
// .sizing = {.width = CLAY_SIZING_FIXED(12), .height = CLAY_SIZING_GROW(0)},
|
||||
// .childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP},
|
||||
// .layoutDirection = CLAY_TOP_TO_BOTTOM
|
||||
// },
|
||||
// .backgroundColor = convert_vec4<Clay_Color>(io.theme->backColor2)
|
||||
// }) {
|
||||
// SkColor4f scrollerColor;
|
||||
// if(sD.isMoving)
|
||||
// scrollerColor = io.theme->fillColor1;
|
||||
// else if(Clay_Hovered())
|
||||
// scrollerColor = io.theme->fillColor1;
|
||||
// else
|
||||
// scrollerColor = io.theme->fillColor2;
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(areaAboveScrollerSize)}
|
||||
}
|
||||
}) {}
|
||||
|
||||
// bool isHoveringOverScroller = false;
|
||||
// CLAY_AUTO_ID({
|
||||
// .layout = {
|
||||
// .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(areaAboveScrollerSize)}
|
||||
// }
|
||||
// }) {}
|
||||
// CLAY_AUTO_ID({
|
||||
// .layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(scrollerSize)}},
|
||||
// .backgroundColor = convert_vec4<Clay_Color>(scrollerColor),
|
||||
// .cornerRadius = CLAY_CORNER_RADIUS(3),
|
||||
// }) {
|
||||
// if(Clay_Hovered())
|
||||
// isHoveringOverScroller = true;
|
||||
// }
|
||||
// CLAY_AUTO_ID({ .layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {}
|
||||
// if(Clay_Hovered() && io.mouse.leftClick) {
|
||||
// isMoving = true;
|
||||
// if(isHoveringOverScroller)
|
||||
// scrollerStartPos = scrollAreaBB.y + areaAboveScrollerSize + scrollerSize * 0.5f;
|
||||
// else
|
||||
// scrollerStartPos = std::clamp(io.mouse.pos.y(), scrollAreaBB.y + scrollerSize * 0.5f, scrollAreaBB.y + scrollAreaBB.height - scrollerSize * 0.5f);
|
||||
// mouseStartPos = io.mouse.pos.y();
|
||||
// }
|
||||
// if(!io.mouse.leftHeld)
|
||||
// isMoving = false;
|
||||
// if(isMoving) {
|
||||
// float newScrollPosFrac;
|
||||
// newScrollPosFrac = std::clamp((scrollerStartPos - (mouseStartPos - io.mouse.pos.y()) - scrollAreaBB.y - scrollerSize * 0.5f) / (scrollAreaBB.height - scrollerSize), 0.0f, 1.0f);
|
||||
// currentScrollPos = newScrollPosFrac * (-scrollPosMax);
|
||||
// }
|
||||
// currentScrollPos = std::clamp(currentScrollPos, -scrollPosMax, 0.0f);
|
||||
// scrollData.scrollPosition->y = currentScrollPos;
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
// sD.currentScrollPos = 0.0f;
|
||||
gui.element<LayoutElement>("scroller", [&] (const Clay_ElementId& lId2) {
|
||||
CLAY(lId2, {
|
||||
.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(scrollerSize)}},
|
||||
.backgroundColor = convert_vec4<Clay_Color>(scrollerColor),
|
||||
.cornerRadius = CLAY_CORNER_RADIUS(3),
|
||||
}) {}
|
||||
}, LayoutElement::Callbacks{
|
||||
.mouseMotion = [&] (const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
||||
if(isHoveringOverScrollerY != mouseHovering) {
|
||||
isHoveringOverScrollerY = mouseHovering;
|
||||
gui.set_to_layout();
|
||||
}
|
||||
return mouseHovering;
|
||||
}
|
||||
});
|
||||
|
||||
CLAY_AUTO_ID({ .layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {}
|
||||
}
|
||||
}, LayoutElement::Callbacks{
|
||||
.mouseButton = [&, scrollPosMax, sAreaStart, sAreaDim, scrollerSize, areaAboveScrollerSize](const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
||||
if(button.button == InputManager::MouseButton::LEFT) {
|
||||
if(button.down && mouseHovering) {
|
||||
isScrollbarHeldY = true;
|
||||
if(isHoveringOverScrollerY)
|
||||
scrollerStartPosY = sAreaStart + areaAboveScrollerSize + scrollerSize * 0.5f;
|
||||
else
|
||||
scrollerStartPosY = std::clamp(button.pos.y(), sAreaStart + scrollerSize * 0.5f, sAreaStart + sAreaDim - scrollerSize * 0.5f);
|
||||
mouseStartPosY = button.pos.y();
|
||||
|
||||
float newScrollPosFrac;
|
||||
newScrollPosFrac = std::clamp((scrollerStartPosY - (mouseStartPosY - button.pos.y()) - sAreaStart - scrollerSize * 0.5f) / (sAreaDim - scrollerSize), 0.0f, 1.0f);
|
||||
scrollOffset.y() = newScrollPosFrac * (-scrollPosMax);
|
||||
|
||||
clamp_scroll();
|
||||
gui.set_to_layout();
|
||||
}
|
||||
else if(isScrollbarHeldY) {
|
||||
isScrollbarHeldY = false;
|
||||
gui.set_to_layout();
|
||||
}
|
||||
}
|
||||
return mouseHovering;
|
||||
},
|
||||
.mouseMotion = [&, scrollPosMax, sAreaStart, sAreaDim, scrollerSize](const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
||||
if(isScrollbarHoveredY != mouseHovering) {
|
||||
isScrollbarHoveredY = mouseHovering;
|
||||
gui.set_to_layout();
|
||||
}
|
||||
if(isScrollbarHeldY) {
|
||||
float newScrollPosFrac;
|
||||
newScrollPosFrac = std::clamp((scrollerStartPosY - (mouseStartPosY - motion.pos.y()) - sAreaStart - scrollerSize * 0.5f) / (sAreaDim - scrollerSize), 0.0f, 1.0f);
|
||||
scrollOffset.y() = newScrollPosFrac * (-scrollPosMax);
|
||||
|
||||
clamp_scroll();
|
||||
gui.set_to_layout();
|
||||
}
|
||||
return mouseHovering;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,8 +32,12 @@ class ScrollArea : public Element {
|
|||
virtual bool input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) override;
|
||||
private:
|
||||
Options opts;
|
||||
bool isScrollbarXHeld = false;
|
||||
bool isScrollbarYHeld = false;
|
||||
bool isScrollbarHeldY = false;
|
||||
bool isScrollbarHoveredY = false;
|
||||
bool isHoveringOverScrollerY = false;
|
||||
float scrollerStartPosY;
|
||||
float mouseStartPosY;
|
||||
|
||||
Vector2f contentDimensions = {0.0f, 0.0f};
|
||||
Vector2f containerDimensions = {0.0f, 0.0f};
|
||||
Vector2f scrollOffset = {0.0f, 0.0f};
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ void GUIManager::layout_if_necessary() {
|
|||
}
|
||||
|
||||
void GUIManager::layout() {
|
||||
constexpr int LAYOUT_RUN_COUNT = 2;
|
||||
constexpr int LAYOUT_RUN_COUNT = 3;
|
||||
for(int i = 0; i < LAYOUT_RUN_COUNT; i++)
|
||||
single_layout_run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1679,12 +1679,13 @@ void Toolbar::general_settings_inner_gui() {
|
|||
.layoutDirection = CLAY_TOP_TO_BOTTOM
|
||||
}
|
||||
}) {
|
||||
auto general_scroll_area = [&](const char* id, const std::function<void()>& innerContent) {
|
||||
gui.element<ScrollArea>("general settings scroll area", ScrollArea::Options{
|
||||
.scrollVertical = true,
|
||||
.clipHorizontal = false,
|
||||
.clipVertical = true,
|
||||
.showScrollbarY = true,
|
||||
.innerContent = [&](const ScrollArea::InnerContentParameters&) {
|
||||
.innerContent = [&, innerContent](const ScrollArea::InnerContentParameters&) {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) },
|
||||
|
|
@ -1694,9 +1695,14 @@ void Toolbar::general_settings_inner_gui() {
|
|||
.layoutDirection = CLAY_TOP_TO_BOTTOM
|
||||
}
|
||||
}) {
|
||||
innerContent();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
switch(generalSettingsOptions) {
|
||||
case GSETTINGS_GENERAL: {
|
||||
gui.new_id("general settings", [&] {
|
||||
general_scroll_area("general settings", [&] {
|
||||
input_text_field(gui, "display name input", "Display name", &main.conf.displayName);
|
||||
main.update_display_names();
|
||||
color_picker_button_field(gui, "defaultCanvasBackgroundColor", "Default canvas background color", &main.conf.defaultCanvasBackgroundColor, { .hasAlpha = false });
|
||||
|
|
@ -1737,7 +1743,7 @@ void Toolbar::general_settings_inner_gui() {
|
|||
break;
|
||||
}
|
||||
case GSETTINGS_TABLET: {
|
||||
gui.new_id("tablet settings", [&] {
|
||||
general_scroll_area("tablet settings", [&] {
|
||||
checkbox_boolean_field(gui, "pen pressure width", "Pen pressure affects brush size", &main.conf.tabletOptions.pressureAffectsBrushWidth);
|
||||
slider_scalar_field(gui, "smoothing time", "Smoothing sampling time", &main.conf.tabletOptions.smoothingSamplingTime, 0.001f, 1.0f, {.decimalPrecision = 3});
|
||||
input_scalar_field<uint8_t>(gui, "middle click", "Middle click pen button", &main.conf.tabletOptions.middleClickButton, 1, 255);
|
||||
|
|
@ -1751,7 +1757,7 @@ void Toolbar::general_settings_inner_gui() {
|
|||
break;
|
||||
}
|
||||
case GSETTINGS_THEME: {
|
||||
gui.new_id("theme", [&] {
|
||||
general_scroll_area("theme", [&] {
|
||||
if(!themeData.selectedThemeIndex)
|
||||
reload_theme_list();
|
||||
|
||||
|
|
@ -1806,14 +1812,16 @@ void Toolbar::general_settings_inner_gui() {
|
|||
}
|
||||
text_label(gui, "Edit theme:");
|
||||
text_label_light(gui, "Note: Changes only remain if theme is saved");
|
||||
color_picker_button_field<SkColor4f>(gui, "fillColor1", "Fill Color 1", &io.theme->fillColor1);
|
||||
color_picker_button_field<SkColor4f>(gui, "fillColor2", "Fill Color 2", &io.theme->fillColor2);
|
||||
color_picker_button_field<SkColor4f>(gui, "backColor1", "Back Color 1", &io.theme->backColor1);
|
||||
color_picker_button_field<SkColor4f>(gui, "backColor2", "Back Color 2", &io.theme->backColor2);
|
||||
color_picker_button_field<SkColor4f>(gui, "frontColor1", "Front Color 1", &io.theme->frontColor1);
|
||||
color_picker_button_field<SkColor4f>(gui, "frontColor2", "Front Color 2", &io.theme->frontColor2);
|
||||
color_picker_button_field<SkColor4f>(gui, "warningColor", "Warning Color", &io.theme->warningColor);
|
||||
color_picker_button_field<SkColor4f>(gui, "errorColor", "Error Color", &io.theme->errorColor);
|
||||
auto theme_color_field = [&](const char* id, const char* name, SkColor4f* c) {
|
||||
color_picker_button_field<SkColor4f>(gui, id, name, c, {});
|
||||
};
|
||||
theme_color_field("fillColor2", "Fill Color 2", &io.theme->fillColor2);
|
||||
theme_color_field("backColor1", "Back Color 1", &io.theme->backColor1);
|
||||
theme_color_field("backColor2", "Back Color 2", &io.theme->backColor2);
|
||||
theme_color_field("frontColor1", "Front Color 1", &io.theme->frontColor1);
|
||||
theme_color_field("frontColor2", "Front Color 2", &io.theme->frontColor2);
|
||||
theme_color_field("warningColor", "Warning Color", &io.theme->warningColor);
|
||||
theme_color_field("errorColor", "Error Color", &io.theme->errorColor);
|
||||
//gui.slider_scalar_field("hoverExpandTime", "Hover Expand Time", &io.theme->hoverExpandTime, 0.001f, 1.0f);
|
||||
input_scalar_field<uint16_t>(gui, "childGap1", "Gap between child elements", &io.theme->childGap1, 0, 30);
|
||||
input_scalar_field<uint16_t>(gui, "padding1", "Window padding", &io.theme->padding1, 0, 30);
|
||||
|
|
@ -1839,7 +1847,7 @@ void Toolbar::general_settings_inner_gui() {
|
|||
}
|
||||
}
|
||||
|
||||
gui.new_id("keybind entries", [&] {
|
||||
general_scroll_area("keybind entries", [&] {
|
||||
for(unsigned i = 0; i < InputManager::KEY_ASSIGNABLE_COUNT; i++) {
|
||||
gui.new_id(i, [&] {
|
||||
CLAY_AUTO_ID({
|
||||
|
|
@ -1870,7 +1878,7 @@ void Toolbar::general_settings_inner_gui() {
|
|||
break;
|
||||
}
|
||||
case GSETTINGS_DEBUG: {
|
||||
gui.new_id("debug settings menu", [&] {
|
||||
general_scroll_area("debug settings menu", [&] {
|
||||
checkbox_boolean_field(gui, "show performance metrics", "Show metrics", &showPerformance);
|
||||
input_scalars_field(gui, "jump transition easing", "Jump easing", &main.conf.jumpTransitionEasing, 4, -10.0f, 10.0f, { .decimalPrecision = 2 });
|
||||
#ifndef __EMSCRIPTEN__
|
||||
|
|
@ -1893,9 +1901,6 @@ void Toolbar::general_settings_inner_gui() {
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
text_button_wide("done menu", "Done", [&] {
|
||||
main.save_config();
|
||||
main.g.load_theme(main.configPath, main.conf.themeCurrentlyLoaded);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue