A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat: Add Dropdown widget and EnumEditor for enum properties
esengine71d071f0cc28
diff --git a/CMakeLists.txt b/CMakeLists.txtindex c4340ff17..a97050f5f 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -63,6 +63,7 @@ set(ESENGINE_SOURCESsrc/esengine/ui/widgets/Checkbox.cppsrc/esengine/ui/widgets/Slider.cppsrc/esengine/ui/widgets/ContextMenu.cpp+ src/esengine/ui/widgets/Dropdown.cpp# Docking Systemsrc/esengine/ui/docking/DockNode.cppsrc/esengine/ui/docking/DockPanel.cpp@@ -144,6 +145,7 @@ set(ESENGINE_HEADERSsrc/esengine/ui/widgets/Checkbox.hppsrc/esengine/ui/widgets/Slider.hppsrc/esengine/ui/widgets/ContextMenu.hpp+ src/esengine/ui/widgets/Dropdown.hpp# Docking Systemsrc/esengine/ui/docking/DockTypes.hppsrc/esengine/ui/docking/DockNode.hppdiff --git a/src/esengine/editor/CMakeLists.txt b/src/esengine/editor/CMakeLists.txtindex 8a686bdf8..a05ce7e3e 100644--- a/src/esengine/editor/CMakeLists.txt+++ b/src/esengine/editor/CMakeLists.txt@@ -21,6 +21,7 @@ set(EDITOR_SOURCESproperty/editors/IntEditor.cppproperty/editors/StringEditor.cppproperty/editors/ColorEditor.cpp+ property/editors/EnumEditor.cpp# Cameracamera/EditorCamera.cpp@@ -77,6 +78,7 @@ set(EDITOR_HEADERSproperty/editors/IntEditor.hppproperty/editors/StringEditor.hppproperty/editors/ColorEditor.hpp+ property/editors/EnumEditor.hpp# Cameracamera/EditorCamera.hppdiff --git a/src/esengine/editor/panels/InspectorPanel.cpp b/src/esengine/editor/panels/InspectorPanel.cppindex 13e72044b..b628228c5 100644--- a/src/esengine/editor/panels/InspectorPanel.cpp+++ b/src/esengine/editor/panels/InspectorPanel.cpp@@ -528,6 +528,32 @@ void InspectorPanel::addCameraEditor(Entity entity) {content->setHeight(ui::SizeValue::autoSize());content->setPadding(ui::Insets(8.0f, 12.0f, 8.0f, 12.0f));+ auto projTypeEditor = makeUnique<EnumEditor>(+ ui::WidgetId(content->getId().path + "_projType"),+ "projectionType");+ projTypeEditor->setLabel("Projection");+ projTypeEditor->addOption(EnumOption::create(+ static_cast<i32>(ecs::ProjectionType::Perspective), "Perspective"));+ projTypeEditor->addOption(EnumOption::create(+ static_cast<i32>(ecs::ProjectionType::Orthographic), "Orthographic"));+ projTypeEditor->setValue(static_cast<i32>(camera.projectionType));+ projTypeEditor->setCommandHistory(&history_);++ editorConnections_.add(sink(projTypeEditor->onValueChanged).connect(+ [this, entity](const std::any& value) {+ if (registry_.valid(entity) && registry_.has<ecs::Camera>(entity)) {+ auto& c = registry_.get<ecs::Camera>(entity);+ try {+ c.projectionType = static_cast<ecs::ProjectionType>(std::any_cast<i32>(value));+ } catch (const std::bad_any_cast&) {+ ES_LOG_ERROR("Failed to cast projectionType value");+ }+ }+ }+ ));++ content->addChild(std::move(projTypeEditor));+auto fovEditor = makeUnique<FloatEditor>(ui::WidgetId(content->getId().path + "_fov"),"fov");diff --git a/src/esengine/editor/panels/InspectorPanel.hpp b/src/esengine/editor/panels/InspectorPanel.hppindex ae361f0e9..5effc6196 100644--- a/src/esengine/editor/panels/InspectorPanel.hpp+++ b/src/esengine/editor/panels/InspectorPanel.hpp@@ -31,6 +31,7 @@#include "../property/editors/IntEditor.hpp"#include "../property/editors/StringEditor.hpp"#include "../property/editors/ColorEditor.hpp"+#include "../property/editors/EnumEditor.hpp"#include "../../events/Connection.hpp"#include <unordered_set>diff --git a/src/esengine/editor/property/editors/EnumEditor.cpp b/src/esengine/editor/property/editors/EnumEditor.cppnew file mode 100644index 000000000..d718d9fe8--- /dev/null+++ b/src/esengine/editor/property/editors/EnumEditor.cpp@@ -0,0 +1,187 @@+/**+ * @file EnumEditor.cpp+ * @brief EnumEditor implementation+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */++#include "EnumEditor.hpp"+#include "../../command/PropertyCommand.hpp"+#include "../../../ui/UIContext.hpp"+#include "../../../ui/rendering/UIBatchRenderer.hpp"+#include "../../../events/Sink.hpp"++namespace esengine::editor {++// =============================================================================+// Constructor+// =============================================================================++EnumEditor::EnumEditor(const ui::WidgetId& id, const std::string& propertyName)+ : PropertyEditor(id, propertyName) {++ if (showLabel_) {+ auto labelWidget = makeUnique<ui::Label>(ui::WidgetId(getId().path + "_label"));+ labelWidget->setText(label_);+ labelWidget->setFontSize(12.0f);+ labelWidget_ = labelWidget.get();+ addChild(std::move(labelWidget));+ }++ auto dropdownWidget = makeUnique<ui::Dropdown>(ui::WidgetId(getId().path + "_dropdown"));+ dropdownWidget->setFontSize(12.0f);+ dropdown_ = dropdownWidget.get();+ addChild(std::move(dropdownWidget));++ connections_.add(sink(dropdown_->onSelectionChanged).connect(+ [this](i32 value) { onDropdownChanged(value); }+ ));+}++// =============================================================================+// Options+// =============================================================================++void EnumEditor::addOption(const EnumOption& option) {+ options_.push_back(option);+ rebuildDropdown();+}++void EnumEditor::addOptions(const std::vector<EnumOption>& options) {+ options_.insert(options_.end(), options.begin(), options.end());+ rebuildDropdown();+}++void EnumEditor::clearOptions() {+ options_.clear();+ rebuildDropdown();+}++void EnumEditor::rebuildDropdown() {+ if (!dropdown_) return;++ dropdown_->clearItems();+ for (const auto& opt : options_) {+ dropdown_->addItem(ui::DropdownItem::create(opt.value, opt.label));+ }+ dropdown_->setSelectedValue(value_);+}++// =============================================================================+// PropertyEditor Interface+// =============================================================================++void EnumEditor::setValue(const std::any& value) {+ try {+ i32 newValue = std::any_cast<i32>(value);+ if (value_ == newValue) {+ return;+ }++ value_ = newValue;++ updatingFromExternal_ = true;+ if (dropdown_) {+ dropdown_->setSelectedValue(value_);+ }+ updatingFromExternal_ = false;+ } catch (const std::bad_any_cast&) {+ }+}++std::any EnumEditor::getValue() const {+ return value_;+}++// =============================================================================+// Widget Interface+// =============================================================================++glm::vec2 EnumEditor::measure(f32 availableWidth, f32 availableHeight) {+ (void)availableHeight;++ f32 width = 0.0f;+ f32 height = 24.0f;++ if (labelWidget_ && showLabel_) {+ width += LABEL_WIDTH + SPACING;+ }++ f32 dropdownWidth = availableWidth - width;+ if (dropdownWidth < DROPDOWN_WIDTH) {+ dropdownWidth = DROPDOWN_WIDTH;+ }+ width += dropdownWidth;++ return glm::vec2(width, height);+}++void EnumEditor::render(ui::UIBatchRenderer& renderer) {+ const ui::Rect& bounds = getBounds();+ f32 x = bounds.x;+ f32 remainingWidth = bounds.width;++ constexpr glm::vec4 labelColor{0.686f, 0.686f, 0.686f, 1.0f};++ if (labelWidget_ && showLabel_) {+ labelWidget_->setColor(labelColor);+ ui::Rect labelBounds{x, bounds.y, LABEL_WIDTH, bounds.height};+ labelWidget_->layout(labelBounds);+ labelWidget_->renderTree(renderer);+ x += LABEL_WIDTH + SPACING;+ remainingWidth -= LABEL_WIDTH + SPACING;+ }++ if (dropdown_) {+ ui::Rect dropdownBounds{x, bounds.y, remainingWidth, bounds.height};+ dropdown_->layout(dropdownBounds);+ dropdown_->renderTree(renderer);+ }+}++// =============================================================================+// Protected Methods+// =============================================================================++Unique<Command> EnumEditor::createCommand(const std::any& oldValue,+ const std::any& newValue) {+ try {+ i32 oldInt = std::any_cast<i32>(oldValue);+ i32 newInt = std::any_cast<i32>(newValue);++ return makeUnique<LambdaCommand>(+ "Modify " + propertyName_,+ [this, newInt]() {+ setValue(newInt);+ return CommandResult::Success;+ },+ [this, oldInt]() {+ setValue(oldInt);+ }+ );+ } catch (const std::bad_any_cast&) {+ return nullptr;+ }+}++// =============================================================================+// Private Methods+// =============================================================================++void EnumEditor::onDropdownChanged(i32 value) {+ if (updatingFromExternal_) {+ return;+ }++ i32 oldValue = value_;+ if (oldValue != value) {+ value_ = value;+ notifyValueChanged(oldValue, value);+ }+}++} // namespace esengine::editordiff --git a/src/esengine/editor/property/editors/EnumEditor.hpp b/src/esengine/editor/property/editors/EnumEditor.hppnew file mode 100644index 000000000..45b9ff60d--- /dev/null+++ b/src/esengine/editor/property/editors/EnumEditor.hpp@@ -0,0 +1,108 @@+/**+ * @file EnumEditor.hpp+ * @brief Property editor for enum values using dropdown+ * @details A dropdown-based editor for selecting from a list of enum options.+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++// =============================================================================+// Includes+// =============================================================================++#include "../PropertyEditor.hpp"+#include "../../../ui/widgets/Dropdown.hpp"+#include "../../../ui/widgets/Label.hpp"+#include "../../../events/Connection.hpp"++#include <vector>++namespace esengine::editor {++// =============================================================================+// EnumOption+// =============================================================================++struct EnumOption {+ i32 value = 0;+ std::string label;++ static EnumOption create(i32 value, const std::string& label) {+ return EnumOption{value, label};+ }+};++// =============================================================================+// EnumEditor Class+// =============================================================================++/**+ * @brief Property editor for enum values+ *+ * @details Displays a dropdown with labeled options for enum selection.+ * Uses i32 values internally to support any enum type.+ *+ * @code+ * auto editor = makeUnique<EnumEditor>(WidgetId("projType"), "Projection Type");+ * editor->addOption(EnumOption::create(0, "Perspective"));+ * editor->addOption(EnumOption::create(1, "Orthographic"));+ * editor->setValue(static_cast<i32>(camera.projectionType));+ * @endcode+ */+class EnumEditor : public PropertyEditor {+public:+ static constexpr f32 LABEL_WIDTH = 80.0f;+ static constexpr f32 DROPDOWN_WIDTH = 100.0f;+ static constexpr f32 SPACING = 8.0f;++ EnumEditor(const ui::WidgetId& id, const std::string& propertyName);++ // =========================================================================+ // Options+ // =========================================================================++ void addOption(const EnumOption& option);+ void addOptions(const std::vector<EnumOption>& options);+ void clearOptions();++ const std::vector<EnumOption>& getOptions() const { return options_; }++ // =========================================================================+ // PropertyEditor Interface+ // =========================================================================++ void setValue(const std::any& value) override;+ std::any getValue() const override;++ // =========================================================================+ // Widget Interface+ // =========================================================================++ glm::vec2 measure(f32 availableWidth, f32 availableHeight) override;+ void render(ui::UIBatchRenderer& renderer) override;++protected:+ Unique<Command> createCommand(const std::any& oldValue,+ const std::any& newValue) override;++private:+ void onDropdownChanged(i32 value);+ void rebuildDropdown();++ i32 value_ = 0;+ std::vector<EnumOption> options_;++ ui::Label* labelWidget_ = nullptr;+ ui::Dropdown* dropdown_ = nullptr;++ ConnectionHolder connections_;++ bool updatingFromExternal_ = false;+};++} // namespace esengine::editordiff --git a/src/esengine/ui/widgets/Dropdown.cpp b/src/esengine/ui/widgets/Dropdown.cppnew file mode 100644index 000000000..eba04211c--- /dev/null+++ b/src/esengine/ui/widgets/Dropdown.cpp@@ -0,0 +1,452 @@+/**+ * @file Dropdown.cpp+ * @brief Dropdown widget implementation+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */++#include "Dropdown.hpp"+#include "../UIContext.hpp"+#include "../icons/Icons.hpp"+#include "../rendering/UIBatchRenderer.hpp"++#if ES_FEATURE_SDF_FONT+#include "../font/MSDFFont.hpp"+#endif++#if ES_FEATURE_BITMAP_FONT+#include "../font/BitmapFont.hpp"+#endif++namespace esengine::ui {++// =============================================================================+// Constructor+// =============================================================================++Dropdown::Dropdown(const WidgetId& id) : Widget(id) {}++// =============================================================================+// Items+// =============================================================================++void Dropdown::addItem(const DropdownItem& item) {+ items_.push_back(item);+ textSizeDirty_ = true;+ invalidateLayout();+}++void Dropdown::addItems(const std::vector<DropdownItem>& items) {+ items_.insert(items_.end(), items.begin(), items.end());+ textSizeDirty_ = true;+ invalidateLayout();+}++void Dropdown::clearItems() {+ items_.clear();+ selectedIndex_ = -1;+ textSizeDirty_ = true;+ invalidateLayout();+}++// =============================================================================+// Selection+// =============================================================================++void Dropdown::setSelectedIndex(i32 index) {+ if (index < -1 || index >= static_cast<i32>(items_.size())) {+ return;+ }++ if (selectedIndex_ != index) {+ selectedIndex_ = index;+ textSizeDirty_ = true;+ invalidateLayout();+ }+}++void Dropdown::setSelectedValue(i32 value) {+ for (i32 i = 0; i < static_cast<i32>(items_.size()); ++i) {+ if (items_[i].value == value) {+ setSelectedIndex(i);+ return;+ }+ }+}++i32 Dropdown::getSelectedValue() const {+ if (selectedIndex_ >= 0 && selectedIndex_ < static_cast<i32>(items_.size())) {+ return items_[selectedIndex_].value;+ }+ return -1;+}++const DropdownItem* Dropdown::getSelectedItem() const {+ if (selectedIndex_ >= 0 && selectedIndex_ < static_cast<i32>(items_.size())) {+ return &items_[selectedIndex_];+ }+ return nullptr;+}++// =============================================================================+// Layout+// =============================================================================++glm::vec2 Dropdown::measure(f32 availableWidth, f32 availableHeight) {+ (void)availableHeight;++ UIContext* ctx = getContext();+ if (!ctx) {+ return Widget::measure(availableWidth, availableHeight);+ }++ f32 maxTextWidth = 0.0f;++#if ES_FEATURE_SDF_FONT+ MSDFFont* font = ctx->getDefaultMSDFFont();+ if (font) {+ for (const auto& item : items_) {+ f32 textWidth = font->measureText(item.label, fontSize_).x;+ maxTextWidth = glm::max(maxTextWidth, textWidth);+ }+ }+#elif ES_FEATURE_BITMAP_FONT+ BitmapFont* font = ctx->getDefaultBitmapFont();+ if (font) {+ for (const auto& item : items_) {+ f32 textWidth = font->measureText(item.label, fontSize_).x;+ maxTextWidth = glm::max(maxTextWidth, textWidth);+ }+ }+#endif++ f32 contentWidth = PADDING_X * 2 + maxTextWidth + ARROW_WIDTH;+ contentWidth = glm::max(contentWidth, MIN_WIDTH);++ f32 width = getWidth().resolve(availableWidth, contentWidth);+ f32 height = getHeight().resolve(availableHeight, 24.0f);++ width = getConstraints().constrainWidth(width);+ height = getConstraints().constrainHeight(height);++ return {width, height};+}++// =============================================================================+// Rendering+// =============================================================================++void Dropdown::render(UIBatchRenderer& renderer) {+ UIContext* ctx = getContext();+ if (!ctx) return;++ const Rect& bounds = getBounds();+ const WidgetState& state = getState();++ constexpr glm::vec4 bgColor{0.165f, 0.165f, 0.165f, 1.0f}; // #2a2a2a+ constexpr glm::vec4 bgHoverColor{0.2f, 0.2f, 0.2f, 1.0f}; // #333333+ constexpr glm::vec4 borderColor{0.275f, 0.275f, 0.275f, 1.0f}; // #464646+ constexpr glm::vec4 textColor{0.878f, 0.878f, 0.878f, 1.0f}; // #e0e0e0+ constexpr glm::vec4 arrowColor{0.6f, 0.6f, 0.6f, 1.0f};+ constexpr glm::vec4 popupBgColor{0.188f, 0.188f, 0.188f, 1.0f}; // #303030+ constexpr glm::vec4 hoverBgColor{0.094f, 0.420f, 0.788f, 1.0f}; // #186cb9++ glm::vec4 currentBg = (state.hovered || isOpen_) ? bgHoverColor : bgColor;+ renderer.drawRoundedRect(bounds, currentBg, CornerRadii::all(3.0f));+ renderer.drawRoundedRectOutline(bounds, borderColor, CornerRadii::all(3.0f), 1.0f);++#if ES_FEATURE_SDF_FONT+ MSDFFont* textFont = ctx->getDefaultMSDFFont();+ MSDFFont* iconFont = ctx->getIconMSDFFont();++ if (textFont) {+ const DropdownItem* selected = getSelectedItem();+ std::string displayText = selected ? selected->label : "";++ f32 textX = bounds.x + PADDING_X;+ f32 textY = bounds.y + (bounds.height - fontSize_) * 0.5f;+ renderer.drawText(displayText, {textX, textY}, *textFont, fontSize_, textColor);+ }++ if (iconFont) {+ f32 arrowX = bounds.x + bounds.width - ARROW_WIDTH;+ Rect arrowBounds{arrowX, bounds.y, ARROW_WIDTH, bounds.height};+ std::string arrowIcon = isOpen_ ? icons::ChevronUp : icons::ChevronDown;+ renderer.drawTextInBounds(arrowIcon, arrowBounds, *iconFont, 12.0f, arrowColor,+ HAlign::Center, VAlign::Center);+ }+#elif ES_FEATURE_BITMAP_FONT+ BitmapFont* textFont = ctx->getDefaultBitmapFont();++ if (textFont) {+ const DropdownItem* selected = getSelectedItem();+ std::string displayText = selected ? selected->label : "";++ f32 textX = bounds.x + PADDING_X;+ f32 textY = bounds.y + (bounds.height - fontSize_) * 0.5f;+ renderer.drawText(displayText, {textX, textY}, *textFont, fontSize_, textColor);+ }+#endif++ if (isOpen_) {+ Rect popupBounds = getPopupBounds();++ renderer.drawRoundedRect(popupBounds, popupBgColor, CornerRadii::all(3.0f));+ renderer.drawRoundedRectOutline(popupBounds, borderColor, CornerRadii::all(3.0f), 1.0f);++#if ES_FEATURE_SDF_FONT+ if (textFont) {+ f32 itemY = popupBounds.y + PADDING_Y;++ for (i32 i = 0; i < static_cast<i32>(items_.size()); ++i) {+ const DropdownItem& item = items_[i];+ Rect itemBounds{popupBounds.x + 4.0f, itemY, popupBounds.width - 8.0f, ITEM_HEIGHT};++ bool isHovered = (i == hoveredIndex_) && item.enabled;+ bool isSelected = (i == selectedIndex_);++ if (isHovered || isSelected) {+ glm::vec4 highlightColor = isHovered ? hoverBgColor : glm::vec4{0.25f, 0.25f, 0.25f, 1.0f};+ renderer.drawRoundedRect(itemBounds, highlightColor, CornerRadii::all(2.0f));+ }++ glm::vec4 itemTextColor = item.enabled ? textColor : glm::vec4{0.5f, 0.5f, 0.5f, 1.0f};+ f32 textX = popupBounds.x + PADDING_X;+ f32 textY = itemY + (ITEM_HEIGHT - fontSize_) * 0.5f;+ renderer.drawText(item.label, {textX, textY}, *textFont, fontSize_, itemTextColor);++ itemY += ITEM_HEIGHT;+ }+ }+#elif ES_FEATURE_BITMAP_FONT+ if (textFont) {+ f32 itemY = popupBounds.y + PADDING_Y;++ for (i32 i = 0; i < static_cast<i32>(items_.size()); ++i) {+ const DropdownItem& item = items_[i];+ Rect itemBounds{popupBounds.x + 4.0f, itemY, popupBounds.width - 8.0f, ITEM_HEIGHT};++ bool isHovered = (i == hoveredIndex_) && item.enabled;+ bool isSelected = (i == selectedIndex_);++ if (isHovered || isSelected) {+ glm::vec4 highlightColor = isHovered ? hoverBgColor : glm::vec4{0.25f, 0.25f, 0.25f, 1.0f};+ renderer.drawRoundedRect(itemBounds, highlightColor, CornerRadii::all(2.0f));+ }++ glm::vec4 itemTextColor = item.enabled ? textColor : glm::vec4{0.5f, 0.5f, 0.5f, 1.0f};+ f32 textX = popupBounds.x + PADDING_X;+ f32 textY = itemY + (ITEM_HEIGHT - fontSize_) * 0.5f;+ renderer.drawText(item.label, {textX, textY}, *textFont, fontSize_, itemTextColor);++ itemY += ITEM_HEIGHT;+ }+ }+#endif+ }+}++// =============================================================================+// Event Handling+// =============================================================================++bool Dropdown::onMouseDown(const MouseButtonEvent& event) {+ if (event.button != MouseButton::Left) {+ return false;+ }++ const Rect& bounds = getBounds();++ if (isOpen_) {+ Rect popupBounds = getPopupBounds();+ if (popupBounds.contains(event.x, event.y)) {+ if (hoveredIndex_ >= 0) {+ selectItem(hoveredIndex_);+ }+ return true;+ } else if (bounds.contains(event.x, event.y)) {+ closePopup();+ return true;+ } else {+ closePopup();+ return false;+ }+ }++ if (bounds.contains(event.x, event.y)) {+ openPopup();+ return true;+ }++ return false;+}++bool Dropdown::onMouseUp(const MouseButtonEvent& event) {+ (void)event;+ return false;+}++bool Dropdown::onMouseEnter(const MouseEnterEvent& event) {+ (void)event;+ if (getState().isInteractive()) {+ setState(true, getState().pressed);+ return true;+ }+ return false;+}++bool Dropdown::onMouseLeave(const MouseLeaveEvent& event) {+ (void)event;+ if (!isOpen_) {+ setState(false, getState().pressed);+ }+ return true;+}++bool Dropdown::onMouseMove(const MouseMoveEvent& event) {+ if (!isOpen_) return false;++ Rect popupBounds = getPopupBounds();+ if (popupBounds.contains(event.x, event.y)) {+ hoveredIndex_ = getItemAtY(event.y - popupBounds.y);+ } else {+ hoveredIndex_ = -1;+ }++ return false;+}++bool Dropdown::onKeyDown(const KeyEvent& event) {+ if (!isOpen_) {+ if (event.key == KeyCode::Space || event.key == KeyCode::Enter) {+ openPopup();+ return true;+ }+ return false;+ }++ if (event.key == KeyCode::Escape) {+ closePopup();+ return true;+ }++ if (event.key == KeyCode::Enter && hoveredIndex_ >= 0) {+ selectItem(hoveredIndex_);+ return true;+ }++ if (event.key == KeyCode::Up) {+ i32 start = hoveredIndex_ < 0 ? static_cast<i32>(items_.size()) : hoveredIndex_;+ for (i32 i = start - 1; i >= 0; --i) {+ if (items_[i].enabled) {+ hoveredIndex_ = i;+ break;+ }+ }+ return true;+ }++ if (event.key == KeyCode::Down) {+ i32 start = hoveredIndex_;+ for (i32 i = start + 1; i < static_cast<i32>(items_.size()); ++i) {+ if (items_[i].enabled) {+ hoveredIndex_ = i;+ break;+ }+ }+ return true;+ }++ return false;+}++Widget* Dropdown::hitTest(f32 x, f32 y) {+ if (isOpen_) {+ Rect popupBounds = getPopupBounds();+ if (popupBounds.contains(x, y)) {+ return this;+ }+ }++ const Rect& bounds = getBounds();+ if (bounds.contains(x, y)) {+ return this;+ }++ if (isOpen_) {+ return this;+ }++ return nullptr;+}++// =============================================================================+// Private Methods+// =============================================================================++void Dropdown::openPopup() {+ isOpen_ = true;+ hoveredIndex_ = selectedIndex_;+}++void Dropdown::closePopup() {+ isOpen_ = false;+ hoveredIndex_ = -1;+}++void Dropdown::selectItem(i32 index) {+ if (index < 0 || index >= static_cast<i32>(items_.size())) {+ return;+ }++ const DropdownItem& item = items_[index];+ if (!item.enabled) {+ return;+ }++ i32 oldValue = getSelectedValue();+ selectedIndex_ = index;+ closePopup();++ if (oldValue != item.value) {+ onSelectionChanged.publish(item.value);+ }+}++f32 Dropdown::calculatePopupHeight() const {+ return PADDING_Y * 2 + static_cast<f32>(items_.size()) * ITEM_HEIGHT;+}++i32 Dropdown::getItemAtY(f32 y) const {+ f32 itemY = PADDING_Y;++ for (i32 i = 0; i < static_cast<i32>(items_.size()); ++i) {+ if (y >= itemY && y < itemY + ITEM_HEIGHT) {+ return i;+ }+ itemY += ITEM_HEIGHT;+ }++ return -1;+}++Rect Dropdown::getPopupBounds() const {+ const Rect& bounds = getBounds();+ f32 popupHeight = calculatePopupHeight();++ UIContext* ctx = getContext();+ glm::vec2 viewportSize = ctx ? ctx->getViewportSize() : glm::vec2(9999.0f);++ f32 popupY = bounds.y + bounds.height + 2.0f;+ if (popupY + popupHeight > viewportSize.y) {+ popupY = bounds.y - popupHeight - 2.0f;+ }++ return Rect{bounds.x, popupY, bounds.width, popupHeight};+}++} // namespace esengine::uidiff --git a/src/esengine/ui/widgets/Dropdown.hpp b/src/esengine/ui/widgets/Dropdown.hppnew file mode 100644index 000000000..23ca368fa--- /dev/null+++ b/src/esengine/ui/widgets/Dropdown.hpp@@ -0,0 +1,148 @@+/**+ * @file Dropdown.hpp+ * @brief Dropdown selection widget+ * @details A dropdown/combobox widget that displays a list of selectable items.+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++// =============================================================================+// Includes+// =============================================================================++#include "Widget.hpp"+#include "../../events/Signal.hpp"++#include <functional>+#include <string>+#include <vector>++namespace esengine::ui {++// =============================================================================+// DropdownItem+// =============================================================================++struct DropdownItem {+ i32 value = 0;+ std::string label;+ std::string icon;+ bool enabled = true;++ static DropdownItem create(i32 value, const std::string& label, const std::string& icon = "") {+ DropdownItem item;+ item.value = value;+ item.label = label;+ item.icon = icon;+ return item;+ }+};++// =============================================================================+// Dropdown Class+// =============================================================================++/**+ * @brief Dropdown selection widget+ *+ * @details Displays a button showing the current selection. When clicked,+ * shows a popup list of options for selection.+ *+ * @code+ * auto dropdown = makeUnique<Dropdown>(WidgetId("type"));+ * dropdown->addItem(DropdownItem::create(0, "Perspective"));+ * dropdown->addItem(DropdownItem::create(1, "Orthographic"));+ * dropdown->setSelectedIndex(0);+ * dropdown->onSelectionChanged.connect([](i32 value) {+ * ES_LOG_INFO("Selected: {}", value);+ * });+ * @endcode+ */+class Dropdown : public Widget {+public:+ static constexpr f32 ITEM_HEIGHT = 24.0f;+ static constexpr f32 PADDING_X = 8.0f;+ static constexpr f32 PADDING_Y = 4.0f;+ static constexpr f32 ARROW_WIDTH = 20.0f;+ static constexpr f32 MIN_WIDTH = 80.0f;++ explicit Dropdown(const WidgetId& id);++ // =========================================================================+ // Signals+ // =========================================================================++ Signal<void(i32)> onSelectionChanged;++ // =========================================================================+ // Items+ // =========================================================================++ void addItem(const DropdownItem& item);+ void addItems(const std::vector<DropdownItem>& items);+ void clearItems();++ const std::vector<DropdownItem>& getItems() const { return items_; }++ // =========================================================================+ // Selection+ // =========================================================================++ void setSelectedIndex(i32 index);+ i32 getSelectedIndex() const { return selectedIndex_; }++ void setSelectedValue(i32 value);+ i32 getSelectedValue() const;++ const DropdownItem* getSelectedItem() const;++ // =========================================================================+ // Appearance+ // =========================================================================++ void setFontSize(f32 size) { fontSize_ = size; invalidateLayout(); }+ f32 getFontSize() const { return fontSize_; }++ // =========================================================================+ // Widget Overrides+ // =========================================================================++ bool isFocusable() const override { return true; }++ glm::vec2 measure(f32 availableWidth, f32 availableHeight) override;+ void render(UIBatchRenderer& renderer) override;++ bool onMouseDown(const MouseButtonEvent& event) override;+ bool onMouseUp(const MouseButtonEvent& event) override;+ bool onMouseEnter(const MouseEnterEvent& event) override;+ bool onMouseLeave(const MouseLeaveEvent& event) override;+ bool onMouseMove(const MouseMoveEvent& event) override;+ bool onKeyDown(const KeyEvent& event) override;++ Widget* hitTest(f32 x, f32 y) override;++private:+ void openPopup();+ void closePopup();+ void selectItem(i32 index);++ f32 calculatePopupHeight() const;+ i32 getItemAtY(f32 y) const;+ Rect getPopupBounds() const;++ std::vector<DropdownItem> items_;+ i32 selectedIndex_ = -1;+ i32 hoveredIndex_ = -1;+ f32 fontSize_ = 12.0f;+ bool isOpen_ = false;++ glm::vec2 cachedTextSize_{0.0f};+ bool textSizeDirty_ = true;+};++} // namespace esengine::ui