void UIWidget::focusChild(const UIWidgetPtr& child, Fw::FocusReason reason) { if(m_destroyed) return; if(child == m_focusedChild) return; if(child && !hasChild(child)) { g_logger.error("attempt to focus an unknown child in a UIWidget"); return; } UIWidgetPtr oldFocused = m_focusedChild; m_focusedChild = child; if(child) { child->setLastFocusReason(reason); child->updateState(Fw::FocusState); child->updateState(Fw::ActiveState); child->onFocusChange(true, reason); } if(oldFocused) { oldFocused->setLastFocusReason(reason); oldFocused->updateState(Fw::FocusState); oldFocused->updateState(Fw::ActiveState); oldFocused->onFocusChange(false, reason); } onChildFocusChange(child, oldFocused, reason); }
bool UIManager::updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Point& clickedPos) { bool accepted = false; UIWidgetPtr oldDraggingWidget = m_draggingWidget; m_draggingWidget = nullptr; if(oldDraggingWidget) { UIWidgetPtr droppedWidget; if(!clickedPos.isNull()) { auto clickedChildren = m_rootWidget->recursiveGetChildrenByPos(clickedPos); for(const UIWidgetPtr& child : clickedChildren) { if(child->onDrop(oldDraggingWidget, clickedPos)) { droppedWidget = child; break; } } } accepted = oldDraggingWidget->onDragLeave(droppedWidget, clickedPos); oldDraggingWidget->updateState(Fw::DraggingState); } if(draggingWidget) { if(draggingWidget->onDragEnter(clickedPos)) { m_draggingWidget = draggingWidget; draggingWidget->updateState(Fw::DraggingState); accepted = true; } } return accepted; }
void UIWidget::focusChild(const UIWidgetPtr& child, Fw::FocusReason reason) { if(child == m_focusedChild) return; if(child && !hasChild(child)) { logError("attempt to focus an unknown child in a UIWidget"); return; } UIWidgetPtr oldFocused = m_focusedChild; m_focusedChild = child; if(child) { child->setLastFocusReason(reason); child->updateState(Fw::FocusState); child->updateState(Fw::ActiveState); } if(oldFocused) { oldFocused->setLastFocusReason(reason); oldFocused->updateState(Fw::FocusState); oldFocused->updateState(Fw::ActiveState); } }
void UIManager::updatePressedWidget(const UIWidgetPtr& newPressedWidget, const Point& clickedPos, bool fireClicks) { UIWidgetPtr oldPressedWidget = m_pressedWidget; m_pressedWidget = newPressedWidget; // when releasing mouse inside pressed widget area send onClick event if(fireClicks && oldPressedWidget && oldPressedWidget->isEnabled() && oldPressedWidget->containsPoint(clickedPos)) oldPressedWidget->onClick(clickedPos); if(newPressedWidget) newPressedWidget->updateState(Fw::PressedState); if(oldPressedWidget) oldPressedWidget->updateState(Fw::PressedState); }
void UIWidget::addChild(const UIWidgetPtr& child) { if(!child) { g_logger.traceWarning("attempt to add a null child into a UIWidget"); return; } if(child->isDestroyed()) { g_logger.traceWarning("attemp to add a destroyed child into a UIWidget"); return; } if(hasChild(child)) { g_logger.traceWarning("attempt to add a child again into a UIWidget"); return; } UIWidgetPtr oldLastChild = getLastChild(); m_children.push_back(child); child->setParent(static_self_cast<UIWidget>()); // create default layout if(!m_layout) m_layout = UIAnchorLayoutPtr(new UIAnchorLayout(static_self_cast<UIWidget>())); // add to layout and updates it m_layout->addWidget(child); // update new child states child->updateStates(); // update old child index states if(oldLastChild) { oldLastChild->updateState(Fw::MiddleState); oldLastChild->updateState(Fw::LastState); } g_ui.onWidgetAppear(child); }
void UIManager::updateHoveredWidget(bool now) { if(m_hoverUpdateScheduled && !now) return; auto func = [this] { if(!m_rootWidget) return; m_hoverUpdateScheduled = false; UIWidgetPtr hoveredWidget; //if(!g_window.isMouseButtonPressed(Fw::MouseLeftButton) && !g_window.isMouseButtonPressed(Fw::MouseRightButton)) { hoveredWidget = m_rootWidget->recursiveGetChildByPos(g_window.getMousePosition(), false); if(hoveredWidget && !hoveredWidget->isEnabled()) hoveredWidget = nullptr; //} if(hoveredWidget != m_hoveredWidget) { UIWidgetPtr oldHovered = m_hoveredWidget; m_hoveredWidget = hoveredWidget; if(oldHovered) { oldHovered->updateState(Fw::HoverState); oldHovered->onHoverChange(false); } if(hoveredWidget) { hoveredWidget->updateState(Fw::HoverState); hoveredWidget->onHoverChange(true); } } }; if(now) func(); else { m_hoverUpdateScheduled = true; g_dispatcher.addEvent(func); } }