Commit ac861cb2 authored by John van Groningen's avatar John van Groningen

only draw visible lines during update,

compute line width only for new lines when lines are added
parent 83ed9db0
...@@ -16,6 +16,7 @@ from commondef import strictSeq ...@@ -16,6 +16,7 @@ from commondef import strictSeq
, pen :: ![PenAttribute] , pen :: ![PenAttribute]
, ifilter :: !{#Char} -> Bool // the item filter , ifilter :: !{#Char} -> Bool // the item filter
, aitems :: ![String] // all items (unfiltered) , aitems :: ![String] // all items (unfiltered)
, domain :: !Rectangle
} }
:: FilteredListBoxId :: FilteredListBoxId
...@@ -98,6 +99,7 @@ where ...@@ -98,6 +99,7 @@ where
, pen = penAtts , pen = penAtts
, ifilter = const True , ifilter = const True
, aitems = items , aitems = items
, domain = domain
} }
listboxAtts = map toLBCA (filter isListBoxControlAttribute attrs) listboxAtts = map toLBCA (filter isListBoxControlAttribute attrs)
...@@ -134,7 +136,7 @@ where ...@@ -134,7 +136,7 @@ where
# listboxState = {listboxState & ifilter = filt, items = items} # listboxState = {listboxState & ifilter = filt, items = items}
// refresh... // refresh...
# (newDomain,ps) = calcControlDomain pen items ps # (newDomain,ps) = calcControlDomain pen items ps
# (newLook,listboxState)= customlook listboxState # (newLook,listboxState)= customlook {listboxState & domain=newDomain}
# ps = appPIO (seq # ps = appPIO (seq
[ setControlViewDomain customId newDomain [ setControlViewDomain customId newDomain
, setControlLooks [(customId,True,(True,newLook))] , setControlLooks [(customId,True,(True,newLook))]
...@@ -184,42 +186,41 @@ where ...@@ -184,42 +186,41 @@ where
= (FOutGetItems items,((listboxState,ls),ps)) = (FOutGetItems items,((listboxState,ls),ps))
// Append elements: // Append elements:
receiver (FInAppendItems newItems) ((listboxState=:{pen,items,aitems,ifilter,lineHeight,initHeight},ls),ps) receiver (FInAppendItems newItems) ((listboxState=:{pen,items,aitems,ifilter,lineHeight,initHeight,domain},ls),ps)
# listboxState = {listboxState & items=allItems, aitems = aitems++newItems} # listboxState = {listboxState & items=allFilteredItems, aitems = aitems++newItems}
| length newItems`==0 | isEmpty filteredNewItems
= (FOutAppendItems,((listboxState,ls),ps)) = (FOutAppendItems,((listboxState,ls),ps))
# (newDomain,ps) = calcControlDomain pen allItems ps # (newDomain,ps) = adjustControlDomain pen filteredNewItems domain ps
# (newLook,listboxState)= customlook listboxState # (newLook,listboxState)= customlook {listboxState & domain=newDomain}
# (delta,ps) = scrolltoend newDomain ps # (wdef,ps) = accPIO (getParentWindow customId) ps
# ps = appPIO (seq # delta = scrolltoend newDomain wdef
# ps = appPIO (seq
[ setControlLooks [(customId,False,(True,newLook))] [ setControlLooks [(customId,False,(True,newLook))]
, setControlViewDomain customId newDomain , setControlViewDomain customId newDomain
, moveControlViewFrame customId {vx=0, vy=delta} , if (delta==0) id (moveControlViewFrame customId {vx=0, vy=delta})
]) ps ]) ps
= (FOutAppendItems,((listboxState,ls),ps)) = (FOutAppendItems,((listboxState,ls),ps))
where where
customId = listboxState.listboxId.fcontrolId customId = listboxState.listboxId.fcontrolId
newItems` = filter ifilter newItems filteredNewItems = filter ifilter newItems
allItems = items++newItems` allFilteredItems = items++filteredNewItems
scrolltoend dom=:{corner2={y=bot}} ps scrolltoend dom=:{corner2={y=bot}} wdef
# (wdef,ps) = accPIO (getParentWindow customId) ps
| isNothing wdef | isNothing wdef
= (zero,ps) = zero
# wdef = fromJust wdef # wdef = fromJust wdef
# (exists,frame) = getControlViewFrame customId wdef # (exists,frame) = getControlViewFrame customId wdef
| not exists || isNothing frame | not exists || isNothing frame
= (zero,ps) = zero
# frame = fromJust frame # frame = fromJust frame
# delta = bot - frame.corner2.y = bot - frame.corner2.y
= (delta,ps)
// Remove elements: // Remove elements:
// Remove all: // Remove all:
receiver (FInCloseAllItems) ((listboxState=:{listboxId,pen,items,selection,lineHeight,initHeight},ls),ps) receiver (FInCloseAllItems) ((listboxState=:{listboxId,pen,items,selection,lineHeight,initHeight},ls),ps)
# listboxState = {listboxState & items=[], aitems = [], selection=[]} # listboxState = {listboxState & items=[], aitems = [], selection=[]}
# (newDomain,ps)= calcControlDomain pen [] ps # (newDomain,ps)= calcControlDomain pen [] ps
# (newLook,listboxState)= customlook listboxState # (newLook,listboxState)= customlook {listboxState & domain=newDomain}
# ps = appPIO (seq # ps = appPIO (seq
[ setControlViewDomain listboxId.fcontrolId newDomain [ setControlViewDomain listboxId.fcontrolId newDomain
, setControlLooks [(listboxId.fcontrolId,True,(True,newLook))] , setControlLooks [(listboxId.fcontrolId,True,(True,newLook))]
...@@ -231,12 +232,8 @@ where ...@@ -231,12 +232,8 @@ where
# pen = removeDupAtt (newpen++pen) # pen = removeDupAtt (newpen++pen)
# (newDomain,ps) = calcControlDomain pen items ps # (newDomain,ps) = calcControlDomain pen items ps
# ((lineHeight,initHeight),ps) = accScreenPicture (liheights pen) ps # ((lineHeight,initHeight),ps) = accScreenPicture (liheights pen) ps
# listboxState = # listboxState
{ listboxState = {listboxState & domain = newDomain, pen = pen, lineHeight = lineHeight, initHeight = initHeight }
& pen = pen
, lineHeight = lineHeight
, initHeight = initHeight
}
# (newLook,listboxState)= customlook listboxState # (newLook,listboxState)= customlook listboxState
# ps = appPIO (seq # ps = appPIO (seq
[ setControlViewDomain listboxId.fcontrolId newDomain [ setControlViewDomain listboxId.fcontrolId newDomain
...@@ -251,8 +248,7 @@ where ...@@ -251,8 +248,7 @@ where
calcControlDomain :: ![.PenAttribute] ![.{#Char}] !*(PSt .a) -> *(!.Rectangle,!*PSt .a); calcControlDomain :: ![.PenAttribute] ![.{#Char}] !*(PSt .a) -> *(!.Rectangle,!*PSt .a);
calcControlDomain pen items ps calcControlDomain pen items ps
# (newDomain,ps) = accPIO (accScreenPicture calc) ps = accPIO (accScreenPicture calc) ps
= (newDomain,ps)
where where
calc pic calc pic
# pic = setPenAttributes pen pic # pic = setPenAttributes pen pic
...@@ -265,6 +261,19 @@ where ...@@ -265,6 +261,19 @@ where
# newDomain = {corner1=zero,corner2={x=maxWidth,y=height}} // calculate new domain... # newDomain = {corner1=zero,corner2={x=maxWidth,y=height}} // calculate new domain...
= (newDomain,pic) = (newDomain,pic)
adjustControlDomain :: ![.PenAttribute] ![.{#Char}] !.Rectangle !*(PSt .a) -> *(!.Rectangle,!*PSt .a);
adjustControlDomain pen items {corner2={x=oldMaxWidth,y=oldHeight}} ps
= accPIO (accScreenPicture calc) ps
where
calc pic
# pic = setPenAttributes pen pic
# (metrics,pic) = getPenFontMetrics pic
# (itemWidths,pic) = getPenFontStringWidths items pic
# maxWidth = maxList [oldMaxWidth:itemWidths]
# nrItems = length items
# height = oldHeight + nrItems*(fontLineHeight metrics)
# newDomain = {corner1=zero,corner2={x=maxWidth,y=height}} // calculate new domain...
= (newDomain,pic)
removeDupAtt [x:xs] = [x:removeDupAtt (filter (diff x) xs)] removeDupAtt [x:xs] = [x:removeDupAtt (filter (diff x) xs)]
where where
...@@ -281,16 +290,22 @@ customlook ls=:{items,selection,pen,lineHeight,initHeight} ...@@ -281,16 +290,22 @@ customlook ls=:{items,selection,pen,lineHeight,initHeight}
= (customlook,ls) = (customlook,ls)
where where
customlook _ {newFrame} pict customlook _ {newFrame} pict
# pict = setPenAttributes pen pict # min_y = newFrame.corner1.y
# pict = unfill newFrame pict # max_y = newFrame.corner2.y
# (_,pict) = strictSeq [drawline item \\ item <- items] (initHeight,pict) # pict = setPenAttributes pen pict
# pict = strictSeq [drawsel sel \\ sel <- selection] pict # pict = unfill newFrame pict
# (_,pict) = foldl drawline (initHeight,pict) items
with
drawline (y,p) line
| y<min_y || y-lineHeight>max_y
= (y+lineHeight,p)
= (y+lineHeight,drawAt {x=0,y=y} line p)
# pict = strictSeq [drawsel sel \\ sel <- selection] pict
= pict = pict
where where
(x1,x2) = (newFrame.corner1.x,newFrame.corner2.x) x1 = newFrame.corner1.x
x2 = newFrame.corner2.x
drawsel i = hilite {corner1={x=x1,y=(i-1)*lineHeight}, corner2={x=x2,y=i*lineHeight-1}} drawsel i = hilite {corner1={x=x1,y=(i-1)*lineHeight}, corner2={x=x2,y=i*lineHeight-1}}
drawline line (y,p)
= (y+lineHeight,drawAt {x=0,y=y} line p)
//-- //--
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment