Separate general GUI managing code and global configuration from toolbar UI code
This commit is contained in:
parent
2abe7271a8
commit
ea35397326
53 changed files with 859 additions and 788 deletions
|
|
@ -32,7 +32,7 @@ template <typename T> class DropDown : public Element {
|
|||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) },
|
||||
.padding = {.left = 4, .right = 4},
|
||||
.childGap = gui.io->theme->childGap1,
|
||||
.childGap = gui.io.theme->childGap1,
|
||||
.childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER},
|
||||
.layoutDirection = CLAY_LEFT_TO_RIGHT,
|
||||
}
|
||||
|
|
@ -55,13 +55,13 @@ template <typename T> class DropDown : public Element {
|
|||
Clay_ElementData dropdownElemData = Clay_GetElementData(localID);
|
||||
float calculatedDropdownMaxHeight = 0.0f;
|
||||
if(dropdownElemData.found)
|
||||
calculatedDropdownMaxHeight = std::max(gui.io->windowSize.y() - dropdownElemData.boundingBox.y - 2.0f, 0.0f);
|
||||
calculatedDropdownMaxHeight = std::max(gui.io.windowSize.y() - dropdownElemData.boundingBox.y - 2.0f, 0.0f);
|
||||
CLAY(localID, {
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_FIXED(opts.width), .height = CLAY_SIZING_FIT(0, calculatedDropdownMaxHeight)},
|
||||
.childGap = 0
|
||||
},
|
||||
.backgroundColor = convert_vec4<Clay_Color>(gui.io->theme->backColor1),
|
||||
.backgroundColor = convert_vec4<Clay_Color>(gui.io.theme->backColor1),
|
||||
.cornerRadius = CLAY_CORNER_RADIUS(4),
|
||||
.floating = {
|
||||
.offset = {
|
||||
|
|
@ -74,7 +74,7 @@ template <typename T> class DropDown : public Element {
|
|||
.attachTo = CLAY_ATTACH_TO_PARENT
|
||||
},
|
||||
.border = {
|
||||
.color = convert_vec4<Clay_Color>(gui.io->theme->fillColor2),
|
||||
.color = convert_vec4<Clay_Color>(gui.io.theme->fillColor2),
|
||||
.width = CLAY_BORDER_OUTSIDE(1)
|
||||
}
|
||||
}) {
|
||||
|
|
@ -96,11 +96,11 @@ template <typename T> class DropDown : public Element {
|
|||
}) {
|
||||
SkColor4f entryColor;
|
||||
if(selectedEntry)
|
||||
entryColor = gui.io->theme->backColor2;
|
||||
entryColor = gui.io.theme->backColor2;
|
||||
else if(hoveringOver.has_value() && hoveringOver.value() == i)
|
||||
entryColor = gui.io->theme->backColor2;
|
||||
entryColor = gui.io.theme->backColor2;
|
||||
else
|
||||
entryColor = gui.io->theme->backColor1;
|
||||
entryColor = gui.io.theme->backColor1;
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ struct Theme {
|
|||
std::shared_ptr<Theme> get_default_dark_mode();
|
||||
|
||||
struct UpdateInputData {
|
||||
InputManager* input;
|
||||
InputManager* input = nullptr;
|
||||
std::function<void()> layoutRun;
|
||||
|
||||
SkFont get_font(float fSize) const;
|
||||
|
|
@ -84,7 +84,6 @@ struct UpdateInputData {
|
|||
std::shared_ptr<FontData> fonts;
|
||||
sk_sp<SkTypeface> textTypeface;
|
||||
|
||||
DefaultStringArena* strArena;
|
||||
std::shared_ptr<Theme> theme;
|
||||
std::unordered_map<std::string, sk_sp<SkSVGDOM>> svgData;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ PositionAdjustingPopupMenu::PositionAdjustingPopupMenu(GUIManager& gui): Element
|
|||
void PositionAdjustingPopupMenu::layout(Vector2f popupPos, const std::function<void()>& innerContent) {
|
||||
if(layoutElement && layoutElement->get_bb().has_value()) {
|
||||
auto& bb = layoutElement->get_bb().value();
|
||||
if((popupPos.y() + bb.height()) > gui.io->windowSize.y())
|
||||
if((popupPos.y() + bb.height()) > gui.io.windowSize.y())
|
||||
popupPos.y() -= bb.height();
|
||||
if((popupPos.x() + bb.width()) > gui.io->windowSize.x())
|
||||
if((popupPos.x() + bb.width()) > gui.io.windowSize.x())
|
||||
popupPos.x() -= bb.width();
|
||||
}
|
||||
|
||||
|
|
@ -18,13 +18,13 @@ void PositionAdjustingPopupMenu::layout(Vector2f popupPos, const std::function<v
|
|||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_FIT(100), .height = CLAY_SIZING_FIT(0)},
|
||||
.padding = CLAY_PADDING_ALL(gui.io->theme->padding1),
|
||||
.padding = CLAY_PADDING_ALL(gui.io.theme->padding1),
|
||||
.childGap = 1,
|
||||
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP},
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM
|
||||
},
|
||||
.backgroundColor = convert_vec4<Clay_Color>(gui.io->theme->backColor1),
|
||||
.cornerRadius = CLAY_CORNER_RADIUS(gui.io->theme->windowCorners1),
|
||||
.backgroundColor = convert_vec4<Clay_Color>(gui.io.theme->backColor1),
|
||||
.cornerRadius = CLAY_CORNER_RADIUS(gui.io.theme->windowCorners1),
|
||||
.floating = {
|
||||
.offset = {popupPos.x(), popupPos.y()},
|
||||
.zIndex = gui.zIndex,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ SVGIcon::SVGIcon(GUIManager& gui):
|
|||
Element(gui) {}
|
||||
|
||||
void SVGIcon::layout(const std::string& newSvgPath, bool newIsHighlighted) {
|
||||
auto& io = *gui.io;
|
||||
auto& io = gui.io;
|
||||
auto findSVGData = io.svgData.find(newSvgPath);
|
||||
if(findSVGData == io.svgData.end())
|
||||
throw std::runtime_error("[SVGIcon::update] Could not load icon " + newSvgPath);
|
||||
|
|
|
|||
|
|
@ -46,15 +46,15 @@ void ScrollArea::layout(const Options& options) {
|
|||
// .childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP},
|
||||
// .layoutDirection = CLAY_TOP_TO_BOTTOM
|
||||
// },
|
||||
// .backgroundColor = convert_vec4<Clay_Color>(io->theme->backColor2)
|
||||
// .backgroundColor = convert_vec4<Clay_Color>(io.theme->backColor2)
|
||||
// }) {
|
||||
// SkColor4f scrollerColor;
|
||||
// if(sD.isMoving)
|
||||
// scrollerColor = io->theme->fillColor1;
|
||||
// scrollerColor = io.theme->fillColor1;
|
||||
// else if(Clay_Hovered())
|
||||
// scrollerColor = io->theme->fillColor1;
|
||||
// scrollerColor = io.theme->fillColor1;
|
||||
// else
|
||||
// scrollerColor = io->theme->fillColor2;
|
||||
// scrollerColor = io.theme->fillColor2;
|
||||
|
||||
// bool isHoveringOverScroller = false;
|
||||
// CLAY_AUTO_ID({
|
||||
|
|
@ -71,19 +71,19 @@ void ScrollArea::layout(const Options& options) {
|
|||
// isHoveringOverScroller = true;
|
||||
// }
|
||||
// CLAY_AUTO_ID({ .layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {}
|
||||
// if(Clay_Hovered() && io->mouse.leftClick) {
|
||||
// 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();
|
||||
// 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)
|
||||
// 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);
|
||||
// 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);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ SelectableButton::SelectableButton(GUIManager& gui):
|
|||
Element(gui) {}
|
||||
|
||||
void SelectableButton::layout(const Data& d) {
|
||||
auto& io = *gui.io;
|
||||
auto& io = gui.io;
|
||||
|
||||
SkColor4f borderColor;
|
||||
SkColor4f backgroundColorHighlight;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace GUIStuff {
|
|||
template <typename T> TextBox<T>::TextBox(GUIManager& gui): Element(gui) {}
|
||||
|
||||
template <typename T> void TextBox<T>::layout(const TextBoxData<T>& userInfo) {
|
||||
auto& io = *gui.io;
|
||||
auto& io = gui.io;
|
||||
this->userInfo = userInfo;
|
||||
init_textbox(io);
|
||||
CLAY_AUTO_ID({
|
||||
|
|
@ -59,26 +59,26 @@ template <typename T> void TextBox<T>::clay_draw(SkCanvas* canvas, UpdateInputDa
|
|||
}
|
||||
|
||||
template <typename T> bool TextBox<T>::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
||||
auto& io = *gui.io;
|
||||
auto& io = gui.io;
|
||||
|
||||
if(button.button == InputManager::MouseButton::LEFT && boundingBox.has_value()) {
|
||||
if(button.down) {
|
||||
if(mouseHovering) {
|
||||
*rect = {(boundingBox.value().min + io.windowPos) * io.guiScaleMultiplier, (boundingBox.value().max + io.windowPos) * io.guiScaleMultiplier};
|
||||
gui.io->input->set_rich_text_box_input_front(textbox, cur, false, rect, userInfo.textInputProps, nullptr);
|
||||
textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, button.clicks, true, gui.io->input->key(InputManager::KEY_TEXT_SHIFT).held);
|
||||
gui.io.input->set_rich_text_box_input_front(textbox, cur, false, rect, userInfo.textInputProps, nullptr);
|
||||
textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, button.clicks, true, gui.io.input->key(InputManager::KEY_TEXT_SHIFT).held);
|
||||
isSelected = true;
|
||||
}
|
||||
else {
|
||||
gui.io->input->remove_rich_text_box_input(textbox);
|
||||
gui.io.input->remove_rich_text_box_input(textbox);
|
||||
if(update_data())
|
||||
gui.set_post_callback_func(userInfo.onEdit);
|
||||
init_textbox(*gui.io);
|
||||
init_textbox(gui.io);
|
||||
isSelected = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, 0, false, gui.io->input->key(InputManager::KEY_TEXT_SHIFT).held);
|
||||
textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, 0, false, gui.io.input->key(InputManager::KEY_TEXT_SHIFT).held);
|
||||
}
|
||||
}
|
||||
return Element::input_mouse_button_callback(button, mouseHovering);
|
||||
|
|
@ -86,7 +86,7 @@ template <typename T> bool TextBox<T>::input_mouse_button_callback(const InputMa
|
|||
|
||||
template <typename T> bool TextBox<T>::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
||||
if(boundingBox.has_value())
|
||||
textbox->process_mouse_left_button(*cur, motion.pos - boundingBox.value().min, 0, gui.io->input->mouse.leftDown, gui.io->input->key(InputManager::KEY_TEXT_SHIFT).held);
|
||||
textbox->process_mouse_left_button(*cur, motion.pos - boundingBox.value().min, 0, gui.io.input->mouse.leftDown, gui.io.input->key(InputManager::KEY_TEXT_SHIFT).held);
|
||||
return Element::input_mouse_motion_callback(motion, mouseHovering);
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ template <typename T> bool TextBox<T>::update_data() {
|
|||
}
|
||||
|
||||
template <typename T> TextBox<T>::~TextBox() {
|
||||
gui.io->input->remove_rich_text_box_input(textbox);
|
||||
gui.io.input->remove_rich_text_box_input(textbox);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue