scroll when focusing widgets

master
Eduardo Bart 12 years ago
parent ba01909088
commit 59a80ffaf9

@ -26,8 +26,8 @@ end
function UIScrollArea:updateScrollBars()
local offset = { x = 0, y = 0 }
local scrollheight = math.max(self:getChildrenRect().height - self:getClippingRect().height, 0)
local scrollwidth = math.max(self:getChildrenRect().width - self:getClippingRect().width, 0)
local scrollheight = math.max(self:getChildrenRect().height - self:getPaddingRect().height, 0)
local scrollwidth = math.max(self:getChildrenRect().width - self:getPaddingRect().width, 0)
local scrollbar = self.verticalScrollBar
if scrollbar then
@ -83,3 +83,18 @@ function UIScrollArea:onMouseWheel(mousePos, mouseWheel)
end
return true
end
function UIScrollArea:onChildFocusChange(focusedChild, oldFocused, reason)
if focusedChild and (reason == MouseFocusReason or reason == KeyboardFocusReason) then
local paddingRect = self:getPaddingRect()
local delta = paddingRect.y - focusedChild:getY()
if delta > 0 then
self.verticalScrollBar:decrement(delta)
end
delta = (focusedChild:getY() + focusedChild:getHeight()) - (paddingRect.y + paddingRect.height)
if delta > 0 then
self.verticalScrollBar:increment(delta)
end
end
end

@ -126,11 +126,13 @@ function UIScrollBar:onStyleApply(styleName, styleNode)
end
end
function UIScrollBar:decrement()
function UIScrollBar:decrement(count)
count = count or self.step
self:setValue(self.value - self.step)
end
function UIScrollBar:increment()
function UIScrollBar:increment(count)
count = count or self.step
self:setValue(self.value + self.step)
end

@ -35,10 +35,10 @@ local function onGameQuestLine(questId, questMissions)
local missionList = questLineWindow:getChildById('missionList')
local missionDescription = questLineWindow:getChildById('missionDescription')
missionList.onChildFocusChange = function(self, focusedChild)
connect(missionList, { onChildFocusChange = function(self, focusedChild)
if focusedChild == nil then return end
missionDescription:setText(focusedChild.description)
end
end })
for i,questMission in pairs(questMissions) do
local name, description = unpack(questMission)

@ -116,7 +116,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("hasChild", &UIWidget::hasChild);
g_lua.bindClassMemberFunction<UIWidget>("getChildIndex", &UIWidget::getChildIndex);
g_lua.bindClassMemberFunction<UIWidget>("getMarginRect", &UIWidget::getMarginRect);
g_lua.bindClassMemberFunction<UIWidget>("getClippingRect", &UIWidget::getClippingRect);
g_lua.bindClassMemberFunction<UIWidget>("getPaddingRect", &UIWidget::getPaddingRect);
g_lua.bindClassMemberFunction<UIWidget>("getChildrenRect", &UIWidget::getChildrenRect);
g_lua.bindClassMemberFunction<UIWidget>("getAnchoredLayout", &UIWidget::getAnchoredLayout);
g_lua.bindClassMemberFunction<UIWidget>("getRootParent", &UIWidget::getRootParent);

@ -134,7 +134,7 @@ LONG CALLBACK ExceptionHandler(LPEXCEPTION_POINTERS e)
if(fout.is_open() && fout.good()) {
fout << ss.str();
fout.close();
g_logger.info("Crash report saved to file %s", fileName);
g_logger.info(stdext::format("Crash report saved to file %s", fileName));
} else
g_logger.error("Failed to save crash report!");

@ -140,7 +140,7 @@ bool UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anch
// determine hooked widget edge point
Rect hookedWidgetRect = hookedWidget->getRect();
if(hookedWidget == parentWidget)
hookedWidgetRect = parentWidget->getClippingRect();
hookedWidgetRect = parentWidget->getPaddingRect();
int point = 0;
switch(anchor.getHookedEdge()) {

@ -79,7 +79,7 @@ bool UIGridLayout::internalUpdate()
UIWidgetList widgets = parentWidget->getChildren();
Rect clippingRect = parentWidget->getClippingRect();
Rect clippingRect = parentWidget->getPaddingRect();
Point topLeft = clippingRect.topLeft();
int numColumns = m_numColumns;

@ -46,7 +46,7 @@ bool UIHorizontalLayout::internalUpdate()
std::reverse(widgets.begin(), widgets.end());
bool changed = false;
Rect clippingRect = parentWidget->getClippingRect();
Rect clippingRect = parentWidget->getPaddingRect();
Point pos = (m_alignRight) ? clippingRect.topRight() : clippingRect.topLeft();
int preferredWidth = 0;
int gap;

@ -47,7 +47,7 @@ bool UIVerticalLayout::internalUpdate()
if(m_alignBottom)
std::reverse(widgets.begin(), widgets.end());
Rect clippingRect = parentWidget->getClippingRect();
Rect clippingRect = parentWidget->getPaddingRect();
Point pos = (m_alignBottom) ? clippingRect.bottomLeft() : clippingRect.topLeft();
int preferredHeight = 0;
int gap;

@ -61,7 +61,7 @@ void UIWidget::draw(const Rect& visibleRect, bool foregroundPane)
if(m_children.size() > 0) {
if(m_clipping)
g_painter->setClipRect(visibleRect.intersection(getClippingRect()));
g_painter->setClipRect(visibleRect.intersection(getPaddingRect()));
drawChildren(visibleRect, foregroundPane);
}
@ -683,7 +683,7 @@ void UIWidget::bindRectToParent()
Rect boundRect = m_rect;
UIWidgetPtr parent = getParent();
if(parent) {
Rect parentRect = parent->getClippingRect();
Rect parentRect = parent->getPaddingRect();
boundRect.bind(parentRect);
}
@ -980,7 +980,7 @@ int UIWidget::getChildIndex(const UIWidgetPtr& child)
return -1;
}
Rect UIWidget::getClippingRect()
Rect UIWidget::getPaddingRect()
{
Rect rect = m_rect;
rect.expand(-m_padding.top, -m_padding.right, -m_padding.bottom, -m_padding.left);
@ -1007,7 +1007,7 @@ Rect UIWidget::getChildrenRect()
childrenRect = childrenRect.united(marginRect);
}
Rect myClippingRect = getClippingRect();
Rect myClippingRect = getPaddingRect();
if(!childrenRect.isValid())
childrenRect = myClippingRect;
else {

@ -137,7 +137,7 @@ public:
bool isChildLocked(const UIWidgetPtr& child);
bool hasChild(const UIWidgetPtr& child);
int getChildIndex(const UIWidgetPtr& child);
Rect getClippingRect();
Rect getPaddingRect();
Rect getMarginRect();
Rect getChildrenRect();
UIAnchorLayoutPtr getAnchoredLayout();
@ -243,7 +243,7 @@ public:
bool isDestroyed() { return m_destroyed; }
bool hasChildren() { return m_children.size() > 0; }
bool containsChildPoint(const Point& point) { return getClippingRect().contains(point); }
bool containsChildPoint(const Point& point) { return getPaddingRect().contains(point); }
bool containsPoint(const Point& point) { return m_rect.contains(point); }
std::string getId() { return m_id; }

@ -33,7 +33,7 @@ void UICreature::drawSelf(bool foregroundPane)
if(m_creature) {
g_painter->setColor(Color::white);
Rect drawRect = getClippingRect();
Rect drawRect = getPaddingRect();
m_creature->drawOutfit(drawRect, !m_fixedCreatureSize);
}
}

@ -38,7 +38,7 @@ void UIItem::drawSelf(bool foregroundPane)
UIWidget::drawSelf(foregroundPane);
if(m_item) {
Rect drawRect = getClippingRect();
Rect drawRect = getPaddingRect();
Point dest = drawRect.topLeft();
int exactSize = m_item->getExactSize();

@ -159,7 +159,7 @@ void UIMap::updateVisibleDimension()
void UIMap::updateMapSize()
{
Rect clippingRect = getClippingRect();
Rect clippingRect = getPaddingRect();
Size mapSize;
if(m_aspectRatio != 0.0f) {
Rect mapRect = clippingRect.expanded(-1);

Loading…
Cancel
Save