Make all dropdowns scrollable at a specified maxHeight

This commit is contained in:
Yousef Khadadeh 2025-11-08 23:19:05 +03:00
parent d4492807fe
commit c956ab7230
4 changed files with 37 additions and 36 deletions

View file

@ -562,7 +562,7 @@ bool GUIManager::font_picker(const std::string& id, std::string* fontName) {
return toRet; return toRet;
} }
void GUIManager::dropdown_select(const std::string& id, size_t* val, const std::vector<std::string>& selections, float width, const std::function<void()>& hoverboxElemUpdate) { void GUIManager::dropdown_select(const std::string& id, size_t* val, const std::vector<std::string>& selections, float width, float maxHeight, const std::function<void()>& hoverboxElemUpdate) {
push_id(id); push_id(id);
bool& dropDownOpen = insert_any_with_id(0, false); bool& dropDownOpen = insert_any_with_id(0, false);
left_to_right_layout(CLAY_SIZING_FIXED(width), CLAY_SIZING_FIT(0), [&]() { left_to_right_layout(CLAY_SIZING_FIXED(width), CLAY_SIZING_FIT(0), [&]() {
@ -590,7 +590,8 @@ void GUIManager::dropdown_select(const std::string& id, size_t* val, const std::
if(dropDownOpen) { if(dropDownOpen) {
CLAY({ CLAY({
.layout = { .layout = {
.sizing = {.width = CLAY_SIZING_FIXED(width), .height = CLAY_SIZING_FIT(0)}, .sizing = {.width = CLAY_SIZING_FIXED(width), .height = CLAY_SIZING_FIT(0, maxHeight)},
.childGap = 0
}, },
.backgroundColor = convert_vec4<Clay_Color>(io->theme->backColor1), .backgroundColor = convert_vec4<Clay_Color>(io->theme->backColor1),
.cornerRadius = CLAY_CORNER_RADIUS(4), .cornerRadius = CLAY_CORNER_RADIUS(4),
@ -610,44 +611,42 @@ void GUIManager::dropdown_select(const std::string& id, size_t* val, const std::
} }
}) { }) {
obstructing_window(); obstructing_window();
CLAY({ scroll_bar_many_entries_area("dropdown scroll area", 18.0f, selections.size(), [&](size_t i, bool) {
.layout = { bool selectedEntry = *val == i;
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)},
.childGap = 1, CLAY({
.childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP}, .layout = {
.layoutDirection = CLAY_TOP_TO_BOTTOM .sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIXED(18)},
} .padding = CLAY_PADDING_ALL(0),
}) { .childGap = 0,
for(size_t i = 0; i < selections.size(); i++) { .childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER},
bool selectedEntry = *val == i; .layoutDirection = CLAY_TOP_TO_BOTTOM
}
}) {
SkColor4f entryColor;
if(selectedEntry)
entryColor = io->theme->backColor2;
else if(Clay_Hovered())
entryColor = io->theme->backColor2;
else
entryColor = io->theme->backColor1;
CLAY({ CLAY({
.layout = { .layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)} .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
.padding = {.left = 2, .right = 2, .top = 0, .bottom = 0},
.childGap = 0,
.childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}
}, },
.backgroundColor = convert_vec4<Clay_Color>(entryColor)
}) { }) {
SkColor4f entryColor; text_label(selections[i]);
if(selectedEntry) if(io->mouse.leftClick && Clay_Hovered()) {
entryColor = io->theme->backColor2; *val = i;
else if(Clay_Hovered()) dropDownOpen = false;
entryColor = io->theme->backColor2;
else
entryColor = io->theme->backColor1;
CLAY({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)},
.padding = {.left = 2, .right = 2},
},
.backgroundColor = convert_vec4<Clay_Color>(entryColor)
}) {
text_label(selections[i]);
if(io->mouse.leftClick && Clay_Hovered()) {
*val = i;
dropDownOpen = false;
}
} }
} }
} }
} });
if(hoverboxElemUpdate) if(hoverboxElemUpdate)
hoverboxElemUpdate(); hoverboxElemUpdate();
} }

View file

@ -97,7 +97,7 @@ class GUIManager {
void input_path(const std::string& id, std::filesystem::path* val, std::filesystem::file_type fileTypeRestriction, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr); void input_path(const std::string& id, std::filesystem::path* val, std::filesystem::file_type fileTypeRestriction, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr);
void input_path_field(const std::string& id, const std::string& name, std::filesystem::path* val, std::filesystem::file_type fileTypeRestriction, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr); void input_path_field(const std::string& id, const std::string& name, std::filesystem::path* val, std::filesystem::file_type fileTypeRestriction, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr);
void dropdown_select(const std::string& id, size_t* val, const std::vector<std::string>& selections, float width = 200.0f, const std::function<void()>& hoverboxElemUpdate = nullptr); void dropdown_select(const std::string& id, size_t* val, const std::vector<std::string>& selections, float width = 200.0f, float maxHeight = 0.0f, const std::function<void()>& hoverboxElemUpdate = nullptr);
void paint_circle_popup_menu(const std::string& id, const Vector2f& centerPos, const PaintCircleMenu::Data& val, const std::function<void()>& elemUpdate = nullptr); void paint_circle_popup_menu(const std::string& id, const Vector2f& centerPos, const PaintCircleMenu::Data& val, const std::function<void()>& elemUpdate = nullptr);

View file

@ -181,7 +181,9 @@ void FontFamiliesTextStyleModifier::load(cereal::PortableBinaryInputArchive& a)
} }
void FontFamiliesTextStyleModifier::modify_text_style(skia::textlayout::TextStyle& style) const { void FontFamiliesTextStyleModifier::modify_text_style(skia::textlayout::TextStyle& style) const {
style.setFontFamilies(families); auto familiesToPush = families;
familiesToPush.emplace_back("Roboto");
style.setFontFamilies(familiesToPush);
} }
bool FontFamiliesTextStyleModifier::equivalent_data(TextStyleModifier& modifier) const { bool FontFamiliesTextStyleModifier::equivalent_data(TextStyleModifier& modifier) const {

View file

@ -1136,7 +1136,7 @@ bool Toolbar::color_palette(const std::string& id, Vector4f* color, bool& hoveri
std::vector<std::string> paletteNames; std::vector<std::string> paletteNames;
for(auto& p : paletteData.palettes) for(auto& p : paletteData.palettes)
paletteNames.emplace_back(p.name); paletteNames.emplace_back(p.name);
gui.dropdown_select("paletteselector", &paletteData.selectedPalette, paletteNames, 200.0f, [&]() { gui.dropdown_select("paletteselector", &paletteData.selectedPalette, paletteNames, 200.0f, 90.0f, [&]() {
hoveringOnDropdown = Clay_Hovered(); hoveringOnDropdown = Clay_Hovered();
}); });
if(gui.svg_icon_button("paletteadd", "data/icons/plus.svg", paletteData.addingPalette, 25.0f)) paletteData.addingPalette = !paletteData.addingPalette; if(gui.svg_icon_button("paletteadd", "data/icons/plus.svg", paletteData.addingPalette, 25.0f)) paletteData.addingPalette = !paletteData.addingPalette;