void ScrollView::parseAttr(std::vector<std::string>* keys, std::vector<std::string>* values) { Widget::parseAttr(keys, values); for (auto i = 0; i < keys->size(); ++i) { const auto& _key = keys->at(i); const auto& _value = values->at(i); if (_key == "sorption") { setSorption(ParamUtil::readVec2(_value)); } else if (_key == "direction" || _key == "scrolldirection") { setScrollDirection(ParamUtil::readScrollDirection(_value)); } else if (_key == "scrollenabled" || _key == "scrollenable" || _key == "scroll") { setScrollEnabled(ParamUtil::readBool(_value)); } else if (_key == "bounceenabled" || _key == "bounceenable" || _key == "bounce") { setBounceEnabled(ParamUtil::readBool(_value)); } } }
ExpandTree::ExpandTree(const std::string& name, const AUnit2D& pos, const AUnit2D& dims) : Composite(name, pos, dims), selectedItem(nullptr), dirty(true) { setScrollEnabled(true); setAlwaysShowVerticalScrollBar(true); drawRegion = DrawPtr( new Draw("Tree Region", CoordPX(0.0f, 0.0f), CoordPercent(1.0f, 1.0f))); drawRegion->onDraw = [this](AlloyContext* context, const box2px& bounds) { root.draw(this, context, bounds.position); }; drawRegion->onMouseOver = [this](AlloyContext* context, const InputEvent& e) { box2px box = drawRegion->getBounds(); overArrow = false; selectedItem = root.locate(context, e.cursor - box.position,overArrow); return false; }; drawRegion->onMouseDown = [this](AlloyContext* context, const InputEvent& e) { if (e.button == GLFW_MOUSE_BUTTON_LEFT) { if (selectedItem != nullptr) { if ((isOverArrow()|| !selectedItem->onSelect)&&(selectedItem->onExpand || selectedItem->hasChildren())) { selectedItem->setExpanded(!selectedItem->isExpanded()); } else { if (selectedItem->onSelect) { selectedItem->onSelect(selectedItem, e); } } setDirty(true); update(context); return true; } } return false; }; Composite::add(drawRegion); }