{-# LANGUAGE ExistentialQuantification #-}-- |This module provides wrapper widgets for enforcing an upper bound-- on the size of child widgets in one or more dimensions in rows or-- columns, respectively. This differs from the ''fixed'' widgets in-- the Fixed module in that Fixed widgets enforce a fixed size-- regardless of how big or small the child widget is, and add padding-- to guarantee that the fixed size is honored.moduleGraphics.Vty.Widgets.Limits(VLimit,HLimit,hLimit,vLimit,boxLimit,setVLimit,setHLimit,addToVLimit,addToHLimit,getVLimit,getHLimit)whereimportControl.MonadimportGraphics.VtyimportGraphics.Vty.Widgets.CoreimportGraphics.Vty.Widgets.UtildataHLimita=(Showa)=>HLimitInt(Widgeta)instanceShow(HLimita)whereshow(HLimiti_)="HLimit { width = "++showi++", ... }"-- |Impose a maximum horizontal size, in columns, on a 'Widget'.hLimit::(Showa)=>Int->Widgeta->IO(Widget(HLimita))hLimitmaxWidthchild=dowRef<-newWidget$\w->w{state=HLimitmaxWidthchild,growHorizontal_=const$returnFalse,growVertical_=const$growVerticalchild,render_=\thissctx->doHLimitwidthch<-getStatethisletregion=s`withWidth`fromIntegral(min(toEnumwidth)(region_widths))renderchregionctx,setCurrentPosition_=\thispos->doHLimit_ch<-getStatethissetCurrentPositionchpos}wRef`relayKeyEvents`childwRef`relayFocusEvents`childreturnwRefdataVLimita=(Showa)=>VLimitInt(Widgeta)instanceShow(VLimita)whereshow(VLimiti_)="VLimit { height = "++showi++", ... }"-- |Impose a maximum vertical size, in columns, on a 'Widget'.vLimit::(Showa)=>Int->Widgeta->IO(Widget(VLimita))vLimitmaxHeightchild=dowRef<-newWidget$\w->w{state=VLimitmaxHeightchild,growHorizontal_=const$growHorizontalchild,growVertical_=const$returnFalse,render_=\thissctx->doVLimitheightch<-getStatethisletregion=s`withHeight`fromIntegral(min(toEnumheight)(region_heights))renderchregionctx,setCurrentPosition_=\thispos->doVLimit_ch<-getStatethissetCurrentPositionchpos}wRef`relayKeyEvents`childwRef`relayFocusEvents`childreturnwRef-- |Set the vertical limit of a child widget's size.setVLimit::Widget(VLimita)->Int->IO()setVLimitwReflim=when(lim>=1)$updateWidgetStatewRef$\(VLimit_ch)->VLimitlimch-- |Set the horizontal limit of a child widget's size.setHLimit::Widget(HLimita)->Int->IO()setHLimitwReflim=when(lim>=1)$updateWidgetStatewRef$\(HLimit_ch)->HLimitlimch-- |Add to the vertical limit of a child widget's size.addToVLimit::Widget(VLimita)->Int->IO()addToVLimitwRefdelta=dolim<-getVLimitwRefsetVLimitwRef$lim+delta-- |Add to the horizontal limit of a child widget's size.addToHLimit::Widget(HLimita)->Int->IO()addToHLimitwRefdelta=dolim<-getHLimitwRefsetHLimitwRef$lim+delta-- |Get the vertical limit of a child widget's size.getVLimit::Widget(VLimita)->IOIntgetVLimitwRef=do(VLimitlim_)<-state<~wRefreturnlim-- |Get the horizontal limit of a child widget's size.getHLimit::Widget(HLimita)->IOIntgetHLimitwRef=do(HLimitlim_)<-state<~wRefreturnlim-- |Impose a horizontal and vertical upper bound on the size of a-- widget.boxLimit::(Showa)=>Int-- ^Maximum width in columns->Int-- ^Maximum height in rows->Widgeta->IO(Widget(VLimit(HLimita)))boxLimitmaxWidthmaxHeightw=doch<-hLimitmaxWidthwvLimitmaxHeightch