Fix up all menu components to integrate with new view port system.

This commit is contained in:
2023-12-14 05:53:46 -06:00
parent 44fcbc80cd
commit 38729877b8
9 changed files with 30 additions and 28 deletions
+6 -4
View File
@@ -63,7 +63,6 @@ public:
:MenuComponent(rect,"",[](MenuFuncData data){return true;},ButtonAttr::UNSELECTABLE|ButtonAttr::UNSELECTABLE_VIA_KEYBOARD){
background=attributes&ComponentAttr::BACKGROUND;
border=attributes&ComponentAttr::OUTLINE;
subWindow=ViewPort::rectViewPort({},rect.size,rect.pos);
}
virtual inline void RemoveAllComponents(){
while(components.size()>0){
@@ -99,6 +98,9 @@ protected:
//Let's use the internal name of this component to add unique names for sub-components.
upButton=Menu::menus[parentMenu]->ADD(name+vf2d(rect.pos+vf2d{rect.size.x-12,0}).str()+"_"+vf2d(12,12).str(),MenuComponent)({rect.pos+vf2d{rect.size.x-12,0},{12,12}},"^",[&](MenuFuncData dat){V(A::SCROLL_OFFSET).y+="ThemeGlobal.MenuButtonScrollSpeed"_I;return true;},ButtonAttr::UNSELECTABLE_VIA_KEYBOARD)DEPTH -1 END;
downButton=Menu::menus[parentMenu]->ADD(name+vf2d(rect.pos+rect.size-vf2d{12,12}).str()+"_"+vf2d(12,12).str(),MenuComponent)({rect.pos+rect.size-vf2d{12,12},{12,12}},"v",[&](MenuFuncData dat){V(A::SCROLL_OFFSET).y-="ThemeGlobal.MenuButtonScrollSpeed"_I;return true;},ButtonAttr::UNSELECTABLE_VIA_KEYBOARD)DEPTH -1 END;
subWindow=ViewPort::rectViewPort({},rect.size,Menu::menus[parentMenu]->pos+rect.pos);
if(upButton){upButton->Enable(!disabled);}
if(downButton){downButton->Enable(!disabled);}
}
virtual inline void BeforeUpdate(Crawler*game)override{
for(MenuComponent*component:components){
@@ -181,12 +183,12 @@ protected:
virtual inline void DrawDecal(ViewPort&window,vf2d parentPos,bool focused)override{
MenuComponent::DrawDecal(window,parentPos,focused);
if(border){
game->DrawRectDecal(rect.pos+Menu::menus[parentMenu]->pos,rect.size);
window.DrawRectDecal(rect.pos,rect.size);
}
for(MenuComponent*component:components){
component->_DrawDecal(subWindow,rect.pos+Menu::menus[parentMenu]->pos+V(A::SCROLL_OFFSET),focused);
component->_DrawDecal(subWindow,V(A::SCROLL_OFFSET),focused);
}
DrawScrollbar(window,Menu::menus[parentMenu]->pos,focused);
DrawScrollbar(window,{},focused);
}
virtual bool GetHoverState(Crawler*game,MenuComponent*child)override{
return geom2d::overlaps(geom2d::rect<float>{Menu::menus[parentMenu]->pos+rect.pos+child->rect.pos+V(A::SCROLL_OFFSET),child->rect.size},game->GetMousePos());