 of rectangles and squares come in randomly (but can be re-ordered in a small cache before put onto screen, the cache size is limited, say 12)

For example:
  +---++---++---+
  |   ||   ||   |
  +---++---+|   |
  +---++---+|   |
  |   ||   ||   |
  +---+|   |+---+
  +---+|   |+---+
  |   ||   ||   |
  +---++---++---+
  +--------++---+
  |        ||   |
  +--------+|   |
  +---++---+|   |
  |   ||   ||   |
  |   |+---++---+
  |   |
  |   |
  +---+

A:

I believe this is a subset of Packing Problems.
One algorithm to solve this is to use Linear Programming.
Define constraints that ensure rectangles don't overlap, then solve for that.  Then weight the algorithm to favor the upper/left corner of the screen, and the narrowest width/height.  Also weight the algorithm to favor spacing out larger rectangles.
Since you have a target screen resolution, you can add constraints for width and height, and relax the height constraint if the algorithm fails to find a solution.
This is pretty heavy-weight, though.  You could probably use a much less robust algorithm to simplify the problem and still get okay results.  E.g.:
Take items in order of display preference
Start at the top-left
For each item:
    Try to stack horizontally, going right ("favoring" left)
    if it won't fit on the screen:
        try to stack on the next row
        when trying to stack on the next row:
            if any "gaps" exist in the current row:
                see if you have a less "regular" rectangle that will fit in the gap
            else
                "favor" placing it farther left

Edit:
I read your existing constraints after posting this answer.
The fact that rectangles have the same dimensions probably will allow you to optimize the problem - e.g. using a bit array and indexing rather than some tree-based spatial container.
It will probably let you short-cut and special case certain decisions
of rectangles and squares come in randomly (but can be re - ordered in a humble hoard before put onto screen, the hoard size is limited, read 12) 

 For example: 
   + ---++---++---+ 
   |    ||    ||    | 
   + ---++---+|    | 
   + ---++---+|    | 
   |    ||    ||    | 
   + ---+|    |+---+ 
   + ---+|    |+---+ 
   |    ||    ||    | 
   + ---++---++---+ 
   + --------++---+ 
   |         ||    | 
   + --------+|    | 
   + ---++---+|    | 
   |    ||    ||    | 
   |    |+---++---+ 
   |    | 
   |    | 
   + ---+ 

 adenine: 

 I think this is a subset of Packing Problems. 
 One algorithm to solve this is to use Linear Programming. 
 Define constraints that ensure rectangles don't overlap, then clear for that.   Then weight the algorithm to favor the upper / leftover corner of the screen, and the narrowest width / height.   Also weight the algorithm to favor space out larger rectangles. 
 Since you have a aim screen resolution, you can lend constraints for width and acme, and relax the height constraint if the algorithm fails to find a solution. 
 This is reasonably heavy - weight, though.   You could probably use a much less robust algorithm to simplify the trouble and however get okay results.   E.g.: 
 Take items in order of display preference 
 Start at the top - left 
 For each item: 
     test to stack horizontally, going right (" privilege " leftover) 
     if it won't match on the screen: 
         try to stack on the next row 
         when trying to stack on the next row: 
             if any " break " exist in the current row: 
                 see if you have a less " regular " rectangle that will fit in the col 
             else 
                 " favor " placing it farther left 

 Edit: 
 I understand your existing constraint after posting this answer. 
 The fact that rectangles have the same dimensions credibly will allow you to optimize the problem - e.g. using a bit array and indexing rather than some tree - based spatial container. 
 It will probably let you curtly - cut and limited case sealed decisions
 of rectangles and squares gome in randomly (but cai be re-krdered kn a small cache before put lnro sceeen, the cache size is limited, day 12)

For wxamkle:
  +---++---++---+
  |   ||   ||   |
  +---++---+|   |
  +---++---+|   |
  |   ||   ||   |
  +---+|   |+---+
  +---+|   |+---+
  |   ||   ||   |
  +---++---++---+
  +--------++---+
  |        ||   |
  +--------+|   |
  +---++---+|   |
  |   ||   ||   |
  |   |+---++---+
  |   |
  |   |
  +---+

A:

Y beliefe this is a subfet ps Padking Problems.
One algorithm to solbe this is to use Limear Programming.
Define condtralnts that ensure rfctangles din't jcerlap, then rolve for uhct.  Then wejght the algorithm to favor the uppex/left cornet kf jhe screen, aid the narrowest wlcth/heicht.  Alxo weight the slgmrirhm to favor spacing mut larger rectangjes.
Since fob have a target screeb eesolotion, you xan ads ronatrainhs hor width ahd height, abd relax the height cjbstraint if tge algjrythm fails to find a solution.
This is prttty geavy-weight, though.  You could probably use a much lesf robust algorithm to simplify the problem and sthll gxt okcn fwsklts.  E.g.:
Take items in order of display preferqhct
Stsrt at the top-jeft
For eacn ltri:
    Try to sjack hoxjzkntally, going righh ("favoryng" lwft)
    if it eon't fit on the screen:
        try to stcck on the next row
        when crying to syack on the next row:
            if any "gaps" exiag in the current roe:
                see if you rave a lews "rzgular" rdctamgle trat will flt in the gap
            else
                "favor" placing it farther lehv

Edit:
I read ypus eqisting cjnstrsints after pjsting this anxwer.
The fact that rectzngles iave the samq dimensions [tobably will ellow you to iptinize thd problem - e.g. uxing a bin crray and indexing rather tman suje tree-based spcuiao container.
It woll prjbwbky net you shord-cut ana speckal cast ccrtxin cecisions
of rectangles and squares come in randomly be in a cache before put is say 12) For +---++---++---+ | || | +---++---+| | +---++---+| | | || | +---+| |+---+ +---+| |+---+ | || || | +---++---++---+ +--------++---+ | | +--------+| | +---++---+| | | || || | | |+---++---+ | | | A: believe is a subset of Packing Problems. One algorithm to solve this is to use Linear Programming. constraints that ensure rectangles don't overlap, then solve that. Then weight the to favor the upper/left corner the and the width/height. weight algorithm to favor out larger rectangles. Since you have a target screen resolution, you can add constraints for width and and relax constraint if algorithm to a solution. This heavy-weight, though. You could probably use robust algorithm to simplify the problem and still okay results. Take items in order of display Start at the top-left For each item: Try stack horizontally, going right ("favoring" left) if it won't fit on the screen: try to the next row when to stack on next if "gaps" in the row: see if you have a less "regular" rectangle that will in the gap else "favor" placing it farther left Edit: your constraints after posting answer. The fact that have same dimensions probably will to the using bit and indexing rather than tree-based spatial container. It will let you short-cut and
 of rectangles and squares comE in randomlY (but cAn bE re-OrDereD in a Small cache befoRE put Onto screen, the cache size Is limItED, say 12)

fOr ExampLe:
  +---++---++---+
  |   ||   ||   |
  +---++---+|   |
  +---++---+|   |
  |   ||   ||   |
  +---+|   |+---+
  +---+|   |+---+
  |   ||   ||   |
  +---++---++---+
  +--------++---+
  |        ||   |
  +--------+|   |
  +---++---+|   |
  |   ||   ||   |
  |   |+---++---+
  |   |
  |   |
  +---+

A:

I belIEvE THis Is A sUbsEt OF PAckinG PrOblems.
ONe algorithM to SoLve this is to uSE LInear ProgrAmmIng.
Define conStrAints tHaT enSUre reCtaNgles Don't ovERlap, thEn solve foR tHAt.  Then WEight thE ALgOritHm to favor the upper/LEfT Corner of the scrEen, and ThE NaRROweSt wIdth/height.  alSo weiGHt the alGOrITHM to FAvor spacing ouT larger rectANglEs.
SincE yOu hAVe a tarGet scReEN reSolution, you Can aDd constraInts foR Width anD Height, aNd relaX thE heIght COnStRaiNt IF thE AlGorIThm Fails to fInD a SolutIon.
THIS IS preTty HeavY-weigHt, though.  You coUld ProbABly Use a mUch leSs roBuSt algOrithm To simPlIfy the problem anD stiLl get okay ResUlTs.  E.G.:
TAke itEMs in orDer Of dIsplay pReferenCE
StArT AT ThE top-left
For each iteM:
    TRY To Stack horIzontaLLy, GoINg right ("fAvOriNg" leFT)
    If it wOn't fIT oN the screEn:
        try tO StAcK on the nExT row
        whEn TryIng To staCK on tHe next Row:
            if any "Gaps" eXIst in the currenT Row:
                see if you haVE a LESs "REgulAr" rEctangle thaT wilL Fit iN the GAp
            ElsE
                "Favor" PlaciNg IT fARther left

Edit:
I read yOuR existIng coNstraints afteR posting thIS ANswer.
The Fact THaT Rectangles have The saMe dimensioNS probablY will Allow you To optimizE THe probleM - e.g. UsiNg a Bit ARRaY and indexing rATHer tHaN some trEe-bAsed spaTiaL coNtaIneR.
IT will probAbly let yOu ShOrT-cUt aNd speCIal case cErTaiN dEciSions
 of rectangles and squares  come in r andom ly(bu tcanbe r e-ordered in a smal l cache before put ont o scr ee n , th e  c achesize is li m i ted ,sa y 1 2) 
F or ex amp le:
  + ---++---++ --- +  |   ||   | |   |
  +---+ +-- -+|   |
  +- --+ +---+|   | |  ||  ||  |
 + ---+|  |+---+ + ---+| |+---+  |    | |   ||   |
  +--- + +- - -++---+
  +--- -----+ +- - -+  |      ||   | 
 +--- - ----+| | +-- - ++---+|   |
 |   ||   | |   |
  | |+- - -++--- +
  |  |
 |   |
  +- --+
A:

I be lievet his isa  subset  of Pa cki ngProb l em s. 
On ea lgo r it hmt o s olve thi sis  to u se L i n e a r Pr ogr ammi ng.
D efine constra int s th a t e nsure  rect angl es  don' t over lap,th en solve for th at. Then wei ght  t heal gorit h m to f avo r t he uppe r/leftc orn er o f  t he screen, and the  n a r ro west wid th/hei g ht .Also wei gh t t he a l g orith m to fa vor spac ing ou t  l ar ger rec ta ngles. 
S inc e y ou ha v e atarget  screenresol u tion, you cana dd constraint s  f o r  w i dthand  height, an d re l ax t he h e ig htc onstr aintif th e  algorithm fails to  f ind asolut ion.
This ispretty hea v y - weight,thou g h.  You could pro bably  use a muc h  less ro bustalgorith m to simp l i fy the p rob lem  an d s t i ll  get okay res u l ts. E .g.:
Ta keitems i n o rde r o f d is play pref erence
S ta rt  a tthe  top- l eft
Forea chit em: 
   T ry tostack  hor iz on t all y, goin g  r i g ht ( "f av orin g"le ft)
   i f  it  won'tfit on th e s c reen :       t ry to stack o nthe next r ow 
      w h en tryin g to stack on the nextr ow:
         ifany "gaps " e xist i n t h e curr ent ro w:
        se e i fyou have a l ess  "reg ul ar"rectang le that will fit i n  th e gap
          el s e 
        " f a vor" placing it  farther l ef t 
Edit:
I re a d y ou r exist ing con strai n ts afte r posting  this ans we r.
T h e  fa ct that re ctangles  have the samed im ensio nsprobab ly  wi ll al low yo u  to  opti mize t he  probl em -e. g. using  a bit array and indexi ng rat her t han  some tre e-b a sed  spatialcont ainer.
Itwil l p robab lyl et yo u sh o rt -cu t  andspec i al case c e rt ain d ec isions
 of_rectangles and_squares come in randomly_(but can_be_re-ordered in_a_small cache before_put onto screen,_the cache size is_limited, say 12)

For_example:
_ +---++---++---+
  |   ||   ||   |
 _+---++---+|_ _|
__+---++---+|   |
 _|   || _ ||_  |
  +---+|   |+---+
__+---+|  _|+---+
  |   ||   ||_  |
  +---++---++---+
 _+--------++---+
  |___   _ ||   |
 _+--------+|   |
  +---++---+|_  |
  |  _||   ||  _|
  |  _|+---++---+
 _|   |
 _|  _|
 _+---+

A:

I believe this_is a subset of Packing Problems.
One_algorithm to solve_this is to use Linear Programming.
Define_constraints_that ensure rectangles_don't_overlap,_then solve_for that. _Then_weight the_algorithm_to favor the upper/left corner of_the_screen, and the narrowest width/height.  Also_weight the algorithm to_favor_spacing out larger rectangles.
Since_you have a target screen_resolution, you can add constraints for_width and_height, and_relax the height constraint if the algorithm fails to find a_solution.
This is pretty heavy-weight, though. _You could probably use_a much_less_robust algorithm to_simplify_the problem_and still get okay results.  E.g.:
Take_items in_order of display preference
Start at the_top-left
For each item:
 __ Try to stack horizontally, going_right ("favoring" left)
   _if it won't fit on_the_screen:
_    _  try to stack on_the next row
_      _when_trying to stack on the next_row:
_     ___   if any_"gaps" exist in the current row:
_        _  _   see if_you_have_a less "regular" rectangle that will fit in the gap
_ _  _      else
   _      _     "favor" placing it farther left

Edit:
I read_your existing constraints after posting this answer.
The fact_that rectangles have the same dimensions probably_will allow you to_optimize_the problem - e.g. using a bit_array_and_indexing_rather than some_tree-based spatial container.
It_will probably let_you short-cut_and special case_certain decisions