Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

imgui.cpp 452KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981
  1. // ImGui library v1.37
  2. // See ImGui::ShowTestWindow() for sample code.
  3. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
  4. // Get latest version at https://github.com/ocornut/imgui
  5. // Developed by Omar Cornut and contributors.
  6. /*
  7. Index
  8. - MISSION STATEMENT
  9. - END-USER GUIDE
  10. - PROGRAMMER GUIDE (read me!)
  11. - API BREAKING CHANGES (read me when you update!)
  12. - FREQUENTLY ASKED QUESTIONS (FAQ), TIPS
  13. - Can I have multiple widgets with the same label? (Yes)
  14. - Why is my text output blurry?
  15. - How can I load a different font than the default?
  16. - How can I load multiple fonts?
  17. - How can I display and input Chinese, Japanese, Korean characters?
  18. - ISSUES & TODO-LIST
  19. - CODE
  20. - SAMPLE CODE
  21. - FONT DATA
  22. MISSION STATEMENT
  23. =================
  24. - easy to use to create code-driven and data-driven tools
  25. - easy to use to create ad hoc short-lived tools and long-lived, more elaborate tools
  26. - easy to hack and improve
  27. - minimize screen real-estate usage
  28. - minimize setup and maintenance
  29. - minimize state storage on user side
  30. - portable, minimize dependencies, run on target (consoles, phones, etc.)
  31. - efficient runtime (NB- we do allocate when "growing" content - creating a window / opening a tree node for the first time, etc. - but a typical frame won't allocate anything)
  32. - read about immediate-mode gui principles @ http://mollyrocket.com/861, http://mollyrocket.com/forums/index.html
  33. Designed for developers and content-creators, not the typical end-user! Some of the weaknesses includes:
  34. - doesn't look fancy, doesn't animate
  35. - limited layout features, intricate layouts are typically crafted in code
  36. - occasionally uses statically sized buffers for string manipulations - won't crash, but some very long pieces of text may be clipped. functions like ImGui::TextUnformatted() don't have such restriction.
  37. END-USER GUIDE
  38. ==============
  39. - double-click title bar to collapse window
  40. - click upper right corner to close a window, available when 'bool* p_opened' is passed to ImGui::Begin()
  41. - click and drag on lower right corner to resize window
  42. - click and drag on any empty space to move window
  43. - double-click/double-tap on lower right corner grip to auto-fit to content
  44. - TAB/SHIFT+TAB to cycle through keyboard editable fields
  45. - use mouse wheel to scroll
  46. - use CTRL+mouse wheel to zoom window contents (if IO.FontAllowScaling is true)
  47. - CTRL+Click on a slider to input value as text
  48. - text editor:
  49. - Hold SHIFT or use mouse to select text.
  50. - CTRL+Left/Right to word jump
  51. - CTRL+Shift+Left/Right to select words
  52. - CTRL+A our Double-Click to select all
  53. - CTRL+X,CTRL+C,CTRL+V to use OS clipboard
  54. - CTRL+Z,CTRL+Y to undo/redo
  55. - ESCAPE to revert text to its original value
  56. - You can apply arithmetic operators +,*,/ on numerical values. Use +- to subtract (because - would set a negative value!)
  57. PROGRAMMER GUIDE
  58. ================
  59. - read the FAQ below this section!
  60. - your code creates the UI, if your code doesn't run the UI is gone! == very dynamic UI, no construction/destructions steps, less data retention on your side, no state duplication, less sync, less bugs.
  61. - call and read ImGui::ShowTestWindow() for sample code demonstrating most features.
  62. - see examples/ folder for standalone sample applications. e.g. examples/opengl_example/
  63. - customization: PushStyleColor()/PushStyleVar() or the style editor to tweak the look of the interface (e.g. if you want a more compact UI or a different color scheme).
  64. - getting started:
  65. - initialisation: call ImGui::GetIO() to retrieve the ImGuiIO structure and fill the 'Settings' data.
  66. - every frame:
  67. 1/ in your mainloop or right after you got your keyboard/mouse info, call ImGui::GetIO() and fill the 'Input' data, then call ImGui::NewFrame().
  68. 2/ use any ImGui function you want between NewFrame() and Render()
  69. 3/ ImGui::Render() to render all the accumulated command-lists. it will call your RenderDrawListFn handler that you set in the IO structure.
  70. - all rendering information are stored into command-lists until ImGui::Render() is called.
  71. - ImGui never touches or know about your GPU state. the only function that knows about GPU is the RenderDrawListFn handler that you must provide.
  72. - effectively it means you can create widgets at any time in your code, regardless of "update" vs "render" considerations.
  73. - refer to the examples applications in the examples/ folder for instruction on how to setup your code.
  74. - a typical application skeleton may be:
  75. // Application init
  76. ImGuiIO& io = ImGui::GetIO();
  77. io.DisplaySize.x = 1920.0f;
  78. io.DisplaySize.y = 1280.0f;
  79. io.DeltaTime = 1.0f/60.0f;
  80. io.IniFilename = "imgui.ini";
  81. // TODO: Fill others settings of the io structure
  82. // Load texture
  83. unsigned char* pixels;
  84. int width, height, bytes_per_pixels;
  85. io.Fonts->GetTexDataAsRGBA32(pixels, &width, &height, &bytes_per_pixels);
  86. // TODO: copy texture to graphics memory.
  87. // TODO: store your texture pointer/identifier in 'io.Fonts->TexID'
  88. // Application main loop
  89. while (true)
  90. {
  91. // 1) get low-level input
  92. // e.g. on Win32, GetKeyboardState(), or poll your events, etc.
  93. // 2) TODO: fill all fields of IO structure and call NewFrame
  94. ImGuiIO& io = ImGui::GetIO();
  95. io.MousePos = mouse_pos;
  96. io.MouseDown[0] = mouse_button_0;
  97. io.KeysDown[i] = ...
  98. ImGui::NewFrame();
  99. // 3) most of your application code here - you can use any of ImGui::* functions at any point in the frame
  100. ImGui::Begin("My window");
  101. ImGui::Text("Hello, world.");
  102. ImGui::End();
  103. GameUpdate();
  104. GameRender();
  105. // 4) render & swap video buffers
  106. ImGui::Render();
  107. // swap video buffer, etc.
  108. }
  109. - after calling ImGui::NewFrame() you can read back 'io.WantCaptureMouse' and 'io.WantCaptureKeyboard' to tell if ImGui
  110. wants to use your inputs. if it does you can discard/hide the inputs from the rest of your application.
  111. API BREAKING CHANGES
  112. ====================
  113. Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix.
  114. Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code.
  115. - 2015/03/17 (1.36) - renamed GetItemRectMin()/GetItemRectMax()/IsMouseHoveringBox() to GetItemRectMin()/GetItemRectMax()/IsMouseHoveringRect(). Kept inline redirection function (will obsolete).
  116. - 2015/03/15 (1.36) - renamed style.TreeNodeSpacing to style.IndentSpacing, ImGuiStyleVar_TreeNodeSpacing to ImGuiStyleVar_IndentSpacing
  117. - 2015/03/13 (1.36) - renamed GetWindowIsFocused() to IsWindowFocused(). Kept inline redirection function (will obsolete).
  118. - 2015/03/08 (1.35) - renamed style.ScrollBarWidth to style.ScrollbarWidth
  119. - 2015/02/27 (1.34) - renamed OpenNextNode(bool) to SetNextTreeNodeOpened(bool, ImGuiSetCond). Kept inline redirection function (will obsolete).
  120. - 2015/02/27 (1.34) - renamed ImGuiSetCondition_*** to ImGuiSetCond_***, and _FirstUseThisSession becomes _Once.
  121. - 2015/02/11 (1.32) - changed text input callback ImGuiTextEditCallback return type from void-->int. reserved for future use, return 0 for now.
  122. - 2015/02/10 (1.32) - renamed GetItemWidth() to CalcItemWidth() to clarify its evolving behavior
  123. - 2015/02/08 (1.31) - renamed GetTextLineSpacing() to GetTextLineHeightWithSpacing()
  124. - 2015/02/01 (1.31) - removed IO.MemReallocFn (unused)
  125. - 2015/01/19 (1.30) - renamed ImGuiStorage::GetIntPtr()/GetFloatPtr() to GetIntRef()/GetIntRef() because Ptr was conflicting with actual pointer storage functions.
  126. - 2015/01/11 (1.30) - big font/image API change! now loads TTF file. allow for multiple fonts. no need for a PNG loader.
  127. (1.30) - removed GetDefaultFontData(). uses io.Fonts->GetTextureData*() API to retrieve uncompressed pixels.
  128. this sequence:
  129. const void* png_data;
  130. unsigned int png_size;
  131. ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
  132. // <Copy to GPU>
  133. became:
  134. unsigned char* pixels;
  135. int width, height;
  136. io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
  137. // <Copy to GPU>
  138. io.Fonts->TexID = (your_texture_identifier);
  139. you now have much more flexibility to load multiple TTF fonts and manage the texture buffer for internal needs.
  140. it is now recommended your sample the font texture with bilinear interpolation.
  141. (1.30) - added texture identifier in ImDrawCmd passed to your render function (we can now render images). make sure to set io.Fonts->TexID.
  142. (1.30) - removed IO.PixelCenterOffset (unnecessary, can be handled in user projection matrix)
  143. (1.30) - removed ImGui::IsItemFocused() in favor of ImGui::IsItemActive() which handles all widgets
  144. - 2014/12/10 (1.18) - removed SetNewWindowDefaultPos() in favor of new generic API SetNextWindowPos(pos, ImGuiSetCondition_FirstUseEver)
  145. - 2014/11/28 (1.17) - moved IO.Font*** options to inside the IO.Font-> structure (FontYOffset, FontTexUvForWhite, FontBaseScale, FontFallbackGlyph)
  146. - 2014/11/26 (1.17) - reworked syntax of IMGUI_ONCE_UPON_A_FRAME helper macro to increase compiler compatibility
  147. - 2014/11/07 (1.15) - renamed IsHovered() to IsItemHovered()
  148. - 2014/10/02 (1.14) - renamed IMGUI_INCLUDE_IMGUI_USER_CPP to IMGUI_INCLUDE_IMGUI_USER_INL and imgui_user.cpp to imgui_user.inl (more IDE friendly)
  149. - 2014/09/25 (1.13) - removed 'text_end' parameter from IO.SetClipboardTextFn (the string is now always zero-terminated for simplicity)
  150. - 2014/09/24 (1.12) - renamed SetFontScale() to SetWindowFontScale()
  151. - 2014/09/24 (1.12) - moved IM_MALLOC/IM_REALLOC/IM_FREE preprocessor defines to IO.MemAllocFn/IO.MemReallocFn/IO.MemFreeFn
  152. - 2014/08/30 (1.09) - removed IO.FontHeight (now computed automatically)
  153. - 2014/08/30 (1.09) - moved IMGUI_FONT_TEX_UV_FOR_WHITE preprocessor define to IO.FontTexUvForWhite
  154. - 2014/08/28 (1.09) - changed the behavior of IO.PixelCenterOffset following various rendering fixes
  155. FREQUENTLY ASKED QUESTIONS (FAQ), TIPS
  156. ======================================
  157. Q: Can I have multiple widgets with the same label?
  158. A: Yes. A primer on the use of labels/IDs in ImGui..
  159. - Interactive widgets require state to be carried over multiple frames (most typically ImGui often needs to remember what is the "active" widget).
  160. to do so they need an unique ID. unique ID are typically derived from a string label, an integer index or a pointer.
  161. Button("OK"); // Label = "OK", ID = hash of "OK"
  162. Button("Cancel"); // Label = "Cancel", ID = hash of "Cancel"
  163. - Elements that are not clickable, such as Text() items don't need an ID.
  164. - ID are uniquely scoped within windows, tree nodes, etc. so no conflict can happen if you have two buttons called "OK" in two different windows
  165. or in two different locations of a tree.
  166. - if you have a same ID twice in the same location, you'll have a conflict:
  167. Button("OK");
  168. Button("OK"); // ID collision! Both buttons will be treated as the same.
  169. Fear not! this is easy to solve and there are many ways to solve it!
  170. - when passing a label you can optionally specify extra unique ID information within string itself. This helps solving the simpler collision cases.
  171. use "##" to pass a complement to the ID that won't be visible to the end-user:
  172. Button("Play##0"); // Label = "Play", ID = hash of "Play##0"
  173. Button("Play##1"); // Label = "Play", ID = hash of "Play##1" (different from above)
  174. - occasionally (rarely) you might want change a label while preserving a constant ID. This allows you to animate labels.
  175. use "###" to pass a label that isn't part of ID:
  176. Button("Hello###ID"; // Label = "Hello", ID = hash of "ID"
  177. Button("World###ID"; // Label = "World", ID = hash of "ID" (same as above)
  178. - use PushID() / PopID() to create scopes and avoid ID conflicts within the same Window.
  179. this is the most convenient way of distinguish ID if you are iterating and creating many UI elements.
  180. you can push a pointer, a string or an integer value. remember that ID are formed from the addition of everything in the ID stack!
  181. for (int i = 0; i < 100; i++)
  182. {
  183. PushID(i);
  184. Button("Click"); // Label = "Click", ID = hash of integer + "label" (unique)
  185. PopID();
  186. }
  187. for (int i = 0; i < 100; i++)
  188. {
  189. MyObject* obj = Objects[i];
  190. PushID(obj);
  191. Button("Click"); // Label = "Click", ID = hash of pointer + "label" (unique)
  192. PopID();
  193. }
  194. for (int i = 0; i < 100; i++)
  195. {
  196. MyObject* obj = Objects[i];
  197. PushID(obj->Name);
  198. Button("Click"); // Label = "Click", ID = hash of string + "label" (unique)
  199. PopID();
  200. }
  201. - more example showing that you can stack multiple prefixes into the ID stack:
  202. Button("Click"); // Label = "Click", ID = hash of "Click"
  203. PushID("node");
  204. Button("Click"); // Label = "Click", ID = hash of "node" + "Click"
  205. PushID(my_ptr);
  206. Button("Click"); // Label = "Click", ID = hash of "node" + ptr + "Click"
  207. PopID();
  208. PopID();
  209. - tree nodes implicitly creates a scope for you by calling PushID().
  210. Button("Click"); // Label = "Click", ID = hash of "Click"
  211. if (TreeNode("node"))
  212. {
  213. Button("Click"); // Label = "Click", ID = hash of "node" + "Click"
  214. TreePop();
  215. }
  216. - when working with trees, ID are used to preserve the opened/closed state of each tree node.
  217. depending on your use cases you may want to use strings, indices or pointers as ID.
  218. e.g. when displaying a single object that may change over time (1-1 relationship), using a static string as ID will preserve your node open/closed state when the targeted object change.
  219. e.g. when displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state differently. experiment and see what makes more sense!
  220. Q: Why is my text output blurry?
  221. A: In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
  222. Q: How can I load a different font than the default? (default is an embedded version of ProggyClean.ttf, rendered at size 13)
  223. A: Use the font atlas to load the TTF file you want:
  224. io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
  225. io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
  226. Q: How can I load multiple fonts?
  227. A: Use the font atlas to pack them into a single texture:
  228. ImFont* font0 = io.Fonts->AddFontDefault();
  229. ImFont* font1 = io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
  230. ImFont* font2 = io.Fonts->AddFontFromFileTTF("myfontfile2.ttf", size_in_pixels);
  231. io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
  232. // the first loaded font gets used by default
  233. // use ImGui::PushFont()/ImGui::PopFont() to change the font at runtime
  234. Q: How can I render and input Chinese, Japanese, Korean characters?
  235. A: When loading a font, pass custom Unicode ranges to specify the glyphs to load. ImGui will support UTF-8 encoding across the board.
  236. Character input depends on you passing the right character code to io.AddInputCharacter(). The example applications do that.
  237. io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, io.Fonts->GetGlyphRangesJapanese()); // Load Japanese characters
  238. io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
  239. io.ImeWindowHandle = MY_HWND; // To input using Microsoft IME, give ImGui the hwnd of your application
  240. - tip: the construct 'IMGUI_ONCE_UPON_A_FRAME { ... }' will run the block of code only once a frame. You can use it to quickly add custom UI in the middle of a deep nested inner loop in your code.
  241. - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug"
  242. - tip: you can call Begin() multiple times with the same name during the same frame, it will keep appending to the same window.
  243. - tip: you can call Render() multiple times (e.g for VR renders).
  244. - tip: call and read the ShowTestWindow() code for more example of how to use ImGui!
  245. ISSUES & TODO-LIST
  246. ==================
  247. - misc: merge or clarify ImVec4 vs ImRect?
  248. - window: add horizontal scroll
  249. - window: fix resize grip rendering scaling along with Rounding style setting
  250. - window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit?
  251. - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list.
  252. - window: allow resizing of child windows (possibly given min/max for each axis?)
  253. - window: background options for child windows, border option (disable rounding)
  254. - window: resizing from any sides? + mouse cursor directives for app.
  255. - widgets: display mode: widget-label, label-widget (aligned on column or using fixed size), label-newline-tab-widget etc.
  256. - widgets: clean up widgets internal toward exposing everything.
  257. - main: considering adding EndFrame()/Init(). some constructs are awkward in the implementation because of the lack of them.
  258. - main: IsItemHovered() make it more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes
  259. - main: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode?
  260. !- input number: large int not reliably supported because of int<>float conversions.
  261. - input number: optional range min/max for Input*() functions
  262. - input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled)
  263. - input number: use mouse wheel to step up/down
  264. - input number: non-decimal input.
  265. - text: proper alignment options
  266. - layout: horizontal layout helper (github issue #97)
  267. - layout: more generic alignment state (left/right/centered) for single items?
  268. - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding.
  269. - columns: separator function or parameter that works within the column (currently Separator() bypass all columns)
  270. - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills)
  271. - columns: columns header to act as button (~sort op) and allow resize/reorder
  272. - columns: user specify columns size
  273. - columns: tree node example, removing the last NextColumn() makes a padding difference (it should not)
  274. - combo: turn child handling code into pop up helper
  275. - combo: contents should extends to fit label if combo widget is small
  276. - listbox: multiple selection
  277. - listbox: user may want to initial scroll to focus on the one selected value?
  278. ! menubar, menus
  279. - tabs
  280. - gauge: various forms of gauge/loading bars widgets
  281. - color: better color editor.
  282. - plot: make it easier for user to draw extra stuff into the graph (e.g: draw basis, highlight certain points, 2d plots, multiple plots)
  283. - plot: "smooth" automatic scale over time, user give an input 0.0(full user scale) 1.0(full derived from value)
  284. - plot: add a helper e.g. Plot(char* label, float value, float time_span=2.0f) that stores values and Plot them for you - probably another function name. and/or automatically allow to plot ANY displayed value (more reliance on stable ID)
  285. - file selection widget -> build the tool in our codebase to improve model-dialog idioms
  286. - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt()
  287. - slider: initial absolute click is imprecise. change to relative movement slider (same as scrollbar).
  288. - slider: add dragging-based widgets to edit values with mouse (on 2 axises), saving screen real-estate.
  289. - text edit: clean up the mess caused by converting UTF-8 <> wchar. the code is rather inefficient right now.
  290. - text edit: centered text for slider as input text so it matches typical positioning.
  291. - text edit: flag to disable live update of the user buffer.
  292. - text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text?
  293. - text edit: add multi-line text edit
  294. - tree: add treenode/treepush int variants? because (void*) cast from int warns on some platforms/settings
  295. - settings: write more decent code to allow saving/loading new fields
  296. - settings: api for per-tool simple persistent data (bool,int,float,columns sizes,etc.) in .ini file
  297. ! style: store rounded corners in texture to use 1 quad per corner (filled and wireframe). so rounding have minor cost.
  298. - style: checkbox: padding for "active" color should be a multiplier of the
  299. - style: colorbox not always square?
  300. - text: simple markup language for color change?
  301. - log: LogButtons() options for specifying depth and/or hiding depth slider
  302. - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope)
  303. - log: be able to log anything (e.g. right-click on a window/tree-node, shows context menu? log into tty/file/clipboard)
  304. - log: let user copy any window content to clipboard easily (CTRL+C on windows? while moving it? context menu?). code is commented because it fails with multiple Begin/End pairs.
  305. - filters: set a current filter that tree node can automatically query to hide themselves
  306. - filters: handle wildcards (with implicit leading/trailing *), regexps
  307. - shortcuts: add a shortcut api, e.g. parse "&Save" and/or "Save (CTRL+S)", pass in to widgets or provide simple ways to use (button=activate, input=focus)
  308. ! keyboard: tooltip & combo boxes are messing up / not honoring keyboard tabbing
  309. - keyboard: full keyboard navigation and focus.
  310. - input: rework IO to be able to pass actual events to fix temporal aliasing issues.
  311. - input: support track pad style scrolling & slider edit.
  312. - tooltip: move to fit within screen (e.g. when mouse cursor is right of the screen).
  313. - portability: big-endian test/support (github issue #81)
  314. - misc: mark printf compiler attributes on relevant functions
  315. - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL)
  316. - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon?
  317. - style editor: have a more global HSV setter (e.g. alter hue on all elements). consider replacing active/hovered by offset in HSV space?
  318. - style editor: color child window height expressed in multiple of line height.
  319. - optimization/render: use indexed rendering to reduce vertex data cost (e.g. for remote/networked imgui)
  320. - optimization/render: merge command-lists with same clip-rect into one even if they aren't sequential? (as long as in-between clip rectangle don't overlap)?
  321. - optimization: turn some the various stack vectors into statically-sized arrays
  322. - optimization: better clipping for multi-component widgets
  323. */
  324. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  325. #define _CRT_SECURE_NO_WARNINGS
  326. #endif
  327. #include "imgui.h"
  328. #include <ctype.h> // toupper, isprint
  329. #include <math.h> // sqrtf, fabsf, fmodf, powf, cosf, sinf, floorf, ceilf
  330. #include <stdint.h> // intptr_t
  331. #include <stdio.h> // vsnprintf, sscanf
  332. #include <new> // new (ptr)
  333. #ifdef _MSC_VER
  334. #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
  335. #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
  336. #endif
  337. // Clang warnings with -Weverything
  338. #ifdef __clang__
  339. #pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
  340. #pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants ok.
  341. #pragma clang diagnostic ignored "-Wformat-nonliteral" // warning : format string is not a string literal // passing non-literal to vsnformat(). yes, user passing incorrect format strings can crash the code.
  342. #pragma clang diagnostic ignored "-Wexit-time-destructors" // warning : declaration requires an exit-time destructor // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals.
  343. #pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it.
  344. #pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness //
  345. #pragma clang diagnostic ignored "-Wmissing-noreturn" // warning : function xx could be declared with attribute 'noreturn' warning // GetDefaultFontData() asserts which some implementation makes it never return.
  346. #endif
  347. #ifdef __GNUC__
  348. #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
  349. #endif
  350. //-------------------------------------------------------------------------
  351. // STB libraries implementation
  352. //-------------------------------------------------------------------------
  353. struct ImGuiTextEditState;
  354. //#define IMGUI_STB_NAMESPACE ImStb
  355. //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
  356. //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
  357. #ifdef IMGUI_STB_NAMESPACE
  358. namespace IMGUI_STB_NAMESPACE
  359. {
  360. #endif
  361. #ifdef __clang__
  362. #pragma clang diagnostic push
  363. #pragma clang diagnostic ignored "-Wunused-function"
  364. #pragma clang diagnostic ignored "-Wmissing-prototypes"
  365. #endif
  366. #define STBRP_ASSERT(x) IM_ASSERT(x)
  367. #ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
  368. #define STBRP_STATIC
  369. #define STB_RECT_PACK_IMPLEMENTATION
  370. #endif
  371. #include "stb_rect_pack.h"
  372. #define STBTT_malloc(x,u) ((void)(u), ImGui::MemAlloc(x))
  373. #define STBTT_free(x,u) ((void)(u), ImGui::MemFree(x))
  374. #define STBTT_assert(x) IM_ASSERT(x)
  375. #ifndef IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
  376. #define STBTT_STATIC
  377. #define STB_TRUETYPE_IMPLEMENTATION
  378. #endif
  379. #include "stb_truetype.h"
  380. #undef STB_TEXTEDIT_STRING
  381. #undef STB_TEXTEDIT_CHARTYPE
  382. #define STB_TEXTEDIT_STRING ImGuiTextEditState
  383. #define STB_TEXTEDIT_CHARTYPE ImWchar
  384. #include "stb_textedit.h"
  385. #ifdef __clang__
  386. #pragma clang diagnostic pop
  387. #endif
  388. #ifdef IMGUI_STB_NAMESPACE
  389. } // namespace ImStb
  390. using namespace IMGUI_STB_NAMESPACE;
  391. #endif
  392. //-------------------------------------------------------------------------
  393. // Forward Declarations
  394. //-------------------------------------------------------------------------
  395. struct ImRect;
  396. struct ImGuiColMod;
  397. struct ImGuiStyleMod;
  398. struct ImGuiDrawContext;
  399. struct ImGuiTextEditState;
  400. struct ImGuiIniData;
  401. struct ImGuiState;
  402. struct ImGuiWindow;
  403. static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false, bool pressed_on_click = false);
  404. static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL);
  405. static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true);
  406. static void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width);
  407. static void RenderTextClipped(ImVec2 pos, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& clip_max);
  408. static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
  409. static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false);
  410. static void SetFont(ImFont* font);
  411. static bool ItemAdd(const ImRect& bb, const ImGuiID* id);
  412. static void ItemSize(ImVec2 size, float text_offset_y = 0.0f);
  413. static void ItemSize(const ImRect& bb, float text_offset_y = 0.0f);
  414. static void PushColumnClipRect(int column_index = -1);
  415. static bool IsClipped(const ImRect& bb);
  416. static bool IsMouseHoveringRect(const ImRect& bb);
  417. static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true);
  418. static void Scrollbar(ImGuiWindow* window);
  419. static bool CloseWindowButton(bool* p_opened = NULL);
  420. static void FocusWindow(ImGuiWindow* window);
  421. static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs);
  422. // Helpers: String
  423. static int ImStricmp(const char* str1, const char* str2);
  424. static int ImStrnicmp(const char* str1, const char* str2, int count);
  425. static char* ImStrdup(const char *str);
  426. static size_t ImStrlenW(const ImWchar* str);
  427. static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end);
  428. static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...);
  429. static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args);
  430. // Helpers: Misc
  431. static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed);
  432. static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes = 0);
  433. static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; }
  434. static inline bool ImCharIsSpace(int c) { return c == ' ' || c == '\t' || c == 0x3000; }
  435. // Helpers: UTF-8 <> wchar
  436. static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int in_char); // return output UTF-8 bytes count
  437. static ptrdiff_t ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count
  438. static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count
  439. static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end, const char** in_remaining = NULL); // return input UTF-8 bytes count
  440. static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count)
  441. static int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points
  442. //-----------------------------------------------------------------------------
  443. // Platform dependent default implementations
  444. //-----------------------------------------------------------------------------
  445. static const char* GetClipboardTextFn_DefaultImpl();
  446. static void SetClipboardTextFn_DefaultImpl(const char* text);
  447. static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y);
  448. //-----------------------------------------------------------------------------
  449. // User facing structures
  450. //-----------------------------------------------------------------------------
  451. ImGuiStyle::ImGuiStyle()
  452. {
  453. Alpha = 1.0f; // Global alpha applies to everything in ImGui
  454. WindowPadding = ImVec2(8,8); // Padding within a window
  455. WindowMinSize = ImVec2(32,32); // Minimum window size
  456. WindowRounding = 9.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
  457. ChildWindowRounding = 0.0f; // Radius of child window corners rounding. Set to 0.0f to have rectangular windows
  458. FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets)
  459. FrameRounding = 0.0f; // Radius of frame corners rounding. Set to 0.0f to have rectangular frames (used by most widgets).
  460. ItemSpacing = ImVec2(8,4); // Horizontal and vertical spacing between widgets/lines
  461. ItemInnerSpacing = ImVec2(4,4); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
  462. TouchExtraPadding = ImVec2(0,0); // Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much!
  463. AutoFitPadding = ImVec2(8,8); // Extra space after auto-fit (double-clicking on resize grip)
  464. WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin()
  465. IndentSpacing = 22.0f; // Horizontal spacing when e.g. entering a tree node
  466. ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns
  467. ScrollbarWidth = 16.0f; // Width of the vertical scrollbar
  468. GrabMinSize = 10.0f; // Minimum width/height of a slider or scrollbar grab
  469. DisplaySafeAreaPadding = ImVec2(22,22); // Window positions are clamped to be visible within the display area. If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding
  470. Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
  471. Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
  472. Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  473. Colors[ImGuiCol_Border] = ImVec4(0.70f, 0.70f, 0.70f, 1.00f);
  474. Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.60f);
  475. Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f); // Background of checkbox, radio button, plot, slider, text input
  476. Colors[ImGuiCol_TitleBg] = ImVec4(0.50f, 0.50f, 1.00f, 0.45f);
  477. Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.40f, 0.40f, 0.80f, 0.20f);
  478. Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.40f, 0.40f, 0.80f, 0.15f);
  479. Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.80f, 0.30f);
  480. Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f);
  481. Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 0.40f);
  482. Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f);
  483. Colors[ImGuiCol_CheckHovered] = ImVec4(0.60f, 0.40f, 0.40f, 0.45f);
  484. Colors[ImGuiCol_CheckActive] = ImVec4(0.65f, 0.50f, 0.50f, 0.55f);
  485. Colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f);
  486. Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
  487. Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  488. Colors[ImGuiCol_Button] = ImVec4(0.67f, 0.40f, 0.40f, 0.60f);
  489. Colors[ImGuiCol_ButtonHovered] = ImVec4(0.67f, 0.40f, 0.40f, 1.00f);
  490. Colors[ImGuiCol_ButtonActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  491. Colors[ImGuiCol_Header] = ImVec4(0.40f, 0.40f, 0.90f, 0.45f);
  492. Colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.90f, 0.80f);
  493. Colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.87f, 0.80f);
  494. Colors[ImGuiCol_Column] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
  495. Colors[ImGuiCol_ColumnHovered] = ImVec4(0.70f, 0.60f, 0.60f, 1.00f);
  496. Colors[ImGuiCol_ColumnActive] = ImVec4(0.90f, 0.70f, 0.70f, 1.00f);
  497. Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
  498. Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.00f, 1.00f, 1.00f, 0.60f);
  499. Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.90f);
  500. Colors[ImGuiCol_CloseButton] = ImVec4(0.50f, 0.50f, 0.90f, 0.50f);
  501. Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.70f, 0.70f, 0.90f, 0.60f);
  502. Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.70f, 0.70f, 0.70f, 1.00f);
  503. Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  504. Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  505. Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  506. Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
  507. Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
  508. Colors[ImGuiCol_TooltipBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
  509. }
  510. // Statically allocated font atlas. This is merely a maneuver to keep ImFontAtlas definition at the bottom of the .h file (otherwise it'd be inside ImGuiIO)
  511. // Also we wouldn't be able to new() one at this point, before users may define IO.MemAllocFn.
  512. static ImFontAtlas GDefaultFontAtlas;
  513. ImGuiIO::ImGuiIO()
  514. {
  515. // Most fields are initialized with zero
  516. memset(this, 0, sizeof(*this));
  517. DisplaySize = ImVec2(-1.0f, -1.0f);
  518. DeltaTime = 1.0f/60.0f;
  519. IniSavingRate = 5.0f;
  520. IniFilename = "imgui.ini";
  521. LogFilename = "imgui_log.txt";
  522. Fonts = &GDefaultFontAtlas;
  523. FontGlobalScale = 1.0f;
  524. MousePos = ImVec2(-1,-1);
  525. MousePosPrev = ImVec2(-1,-1);
  526. MouseDoubleClickTime = 0.30f;
  527. MouseDoubleClickMaxDist = 6.0f;
  528. MouseDragThreshold = 6.0f;
  529. UserData = NULL;
  530. // User functions
  531. RenderDrawListsFn = NULL;
  532. MemAllocFn = malloc;
  533. MemFreeFn = free;
  534. GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations
  535. SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
  536. ImeSetInputScreenPosFn = ImeSetInputScreenPosFn_DefaultImpl;
  537. }
  538. // Pass in translated ASCII characters for text input.
  539. // - with glfw you can get those from the callback set in glfwSetCharCallback()
  540. // - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message
  541. void ImGuiIO::AddInputCharacter(ImWchar c)
  542. {
  543. const size_t n = ImStrlenW(InputCharacters);
  544. if (n + 1 < sizeof(InputCharacters) / sizeof(InputCharacters[0]))
  545. {
  546. InputCharacters[n] = c;
  547. InputCharacters[n+1] = 0;
  548. }
  549. }
  550. //-----------------------------------------------------------------------------
  551. // Helpers
  552. //-----------------------------------------------------------------------------
  553. #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
  554. #undef PI
  555. const float PI = 3.14159265358979323846f;
  556. #ifdef INT_MAX
  557. #define IM_INT_MAX INT_MAX
  558. #else
  559. #define IM_INT_MAX 2147483647
  560. #endif
  561. // Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n.
  562. #ifdef _MSC_VER
  563. #define STR_NEWLINE "\r\n"
  564. #else
  565. #define STR_NEWLINE "\n"
  566. #endif
  567. // Math bits
  568. // We are keeping those static in the .cpp file so as not to leak them outside, in the case the user has implicit cast operators between ImVec2 and its own types.
  569. static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); }
  570. //static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); }
  571. static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); }
  572. static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); }
  573. static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); }
  574. static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); }
  575. static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; }
  576. static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; }
  577. static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; }
  578. //static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; }
  579. static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; }
  580. static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; }
  581. static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; }
  582. static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; }
  583. static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); }
  584. static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); }
  585. static inline int ImClamp(int v, int mn, int mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
  586. static inline float ImClamp(float v, float mn, float mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
  587. static inline ImVec2 ImClamp(const ImVec2& f, const ImVec2& mn, ImVec2 mx) { return ImVec2(ImClamp(f.x,mn.x,mx.x), ImClamp(f.y,mn.y,mx.y)); }
  588. static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; }
  589. static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; }
  590. static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, const ImVec2& t) { return ImVec2(a.x + (b.x - a.x) * t.x, a.y + (b.y - a.y) * t.y); }
  591. static inline float ImLengthSqr(const ImVec2& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y; }
  592. static int ImStricmp(const char* str1, const char* str2)
  593. {
  594. int d;
  595. while ((d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; }
  596. return d;
  597. }
  598. static int ImStrnicmp(const char* str1, const char* str2, int count)
  599. {
  600. int d = 0;
  601. while (count > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; count--; }
  602. return d;
  603. }
  604. static char* ImStrdup(const char *str)
  605. {
  606. char *buff = (char*)ImGui::MemAlloc(strlen(str) + 1);
  607. IM_ASSERT(buff);
  608. strcpy(buff, str);
  609. return buff;
  610. }
  611. static size_t ImStrlenW(const ImWchar* str)
  612. {
  613. size_t n = 0;
  614. while (*str++) n++;
  615. return n;
  616. }
  617. static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end)
  618. {
  619. if (!needle_end)
  620. needle_end = needle + strlen(needle);
  621. const char un0 = (char)toupper(*needle);
  622. while (*haystack)
  623. {
  624. if (toupper(*haystack) == un0)
  625. {
  626. const char* b = needle + 1;
  627. for (const char* a = haystack + 1; b < needle_end; a++, b++)
  628. if (toupper(*a) != toupper(*b))
  629. break;
  630. if (b == needle_end)
  631. return haystack;
  632. }
  633. haystack++;
  634. }
  635. return NULL;
  636. }
  637. // Pass data_size==0 for zero-terminated string
  638. // Try to replace with FNV1a hash?
  639. static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed = 0)
  640. {
  641. static ImU32 crc32_lut[256] = { 0 };
  642. if (!crc32_lut[1])
  643. {
  644. const ImU32 polynomial = 0xEDB88320;
  645. for (ImU32 i = 0; i < 256; i++)
  646. {
  647. ImU32 crc = i;
  648. for (ImU32 j = 0; j < 8; j++)
  649. crc = (crc >> 1) ^ (ImU32(-int(crc & 1)) & polynomial);
  650. crc32_lut[i] = crc;
  651. }
  652. }
  653. seed = ~seed;
  654. ImU32 crc = seed;
  655. const unsigned char* current = (const unsigned char*)data;
  656. if (data_size > 0)
  657. {
  658. // Known size
  659. while (data_size--)
  660. crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++];
  661. }
  662. else
  663. {
  664. // Zero-terminated string
  665. while (unsigned char c = *current++)
  666. {
  667. // We support a syntax of "label###id" where only "###id" is included in the hash, and only "label" gets displayed.
  668. // Because this syntax is rarely used we are optimizing for the common case.
  669. // - If we reach ### in the string we discard the hash so far and reset to the seed.
  670. // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller.
  671. if (c == '#' && current[0] == '#' && current[1] == '#')
  672. crc = seed;
  673. crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
  674. }
  675. }
  676. return ~crc;
  677. }
  678. static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...)
  679. {
  680. va_list args;
  681. va_start(args, fmt);
  682. int w = vsnprintf(buf, buf_size, fmt, args);
  683. va_end(args);
  684. buf[buf_size-1] = 0;
  685. return (w == -1) ? buf_size : (size_t)w;
  686. }
  687. static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args)
  688. {
  689. int w = vsnprintf(buf, buf_size, fmt, args);
  690. buf[buf_size-1] = 0;
  691. return (w == -1) ? buf_size : (size_t)w;
  692. }
  693. ImU32 ImGui::ColorConvertFloat4ToU32(const ImVec4& in)
  694. {
  695. ImU32 out = ((ImU32)(ImSaturate(in.x)*255.f));
  696. out |= ((ImU32)(ImSaturate(in.y)*255.f) << 8);
  697. out |= ((ImU32)(ImSaturate(in.z)*255.f) << 16);
  698. out |= ((ImU32)(ImSaturate(in.w)*255.f) << 24);
  699. return out;
  700. }
  701. // Convert rgb floats ([0-1],[0-1],[0-1]) to hsv floats ([0-1],[0-1],[0-1]), from Foley & van Dam p592
  702. // Optimized http://lolengine.net/blog/2013/01/13/fast-rgb-to-hsv
  703. void ImGui::ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v)
  704. {
  705. float K = 0.f;
  706. if (g < b)
  707. {
  708. const float tmp = g; g = b; b = tmp;
  709. K = -1.f;
  710. }
  711. if (r < g)
  712. {
  713. const float tmp = r; r = g; g = tmp;
  714. K = -2.f / 6.f - K;
  715. }
  716. const float chroma = r - (g < b ? g : b);
  717. out_h = fabsf(K + (g - b) / (6.f * chroma + 1e-20f));
  718. out_s = chroma / (r + 1e-20f);
  719. out_v = r;
  720. }
  721. // Convert hsv floats ([0-1],[0-1],[0-1]) to rgb floats ([0-1],[0-1],[0-1]), from Foley & van Dam p593
  722. // also http://en.wikipedia.org/wiki/HSL_and_HSV
  723. void ImGui::ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b)
  724. {
  725. if (s == 0.0f)
  726. {
  727. // gray
  728. out_r = out_g = out_b = v;
  729. return;
  730. }
  731. h = fmodf(h, 1.0f) / (60.0f/360.0f);
  732. int i = (int)h;
  733. float f = h - (float)i;
  734. float p = v * (1.0f - s);
  735. float q = v * (1.0f - s * f);
  736. float t = v * (1.0f - s * (1.0f - f));
  737. switch (i)
  738. {
  739. case 0: out_r = v; out_g = t; out_b = p; break;
  740. case 1: out_r = q; out_g = v; out_b = p; break;
  741. case 2: out_r = p; out_g = v; out_b = t; break;
  742. case 3: out_r = p; out_g = q; out_b = v; break;
  743. case 4: out_r = t; out_g = p; out_b = v; break;
  744. case 5: default: out_r = v; out_g = p; out_b = q; break;
  745. }
  746. }
  747. // Load file content into memory
  748. // Memory allocated with ImGui::MemAlloc(), must be freed by user using ImGui::MemFree()
  749. static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes)
  750. {
  751. IM_ASSERT(filename && file_open_mode && out_file_data && out_file_size);
  752. *out_file_data = NULL;
  753. *out_file_size = 0;
  754. FILE* f;
  755. if ((f = fopen(filename, file_open_mode)) == NULL)
  756. return false;
  757. long file_size_signed;
  758. if (fseek(f, 0, SEEK_END) || (file_size_signed = ftell(f)) == -1 || fseek(f, 0, SEEK_SET))
  759. {
  760. fclose(f);
  761. return false;
  762. }
  763. size_t file_size = (size_t)file_size_signed;
  764. void* file_data = ImGui::MemAlloc(file_size + padding_bytes);
  765. if (file_data == NULL)
  766. {
  767. fclose(f);
  768. return false;
  769. }
  770. if (fread(file_data, 1, file_size, f) != file_size)
  771. {
  772. fclose(f);
  773. ImGui::MemFree(file_data);
  774. return false;
  775. }
  776. if (padding_bytes > 0)
  777. memset((void *)(((char*)file_data) + file_size), 0, padding_bytes);
  778. fclose(f);
  779. *out_file_data = file_data;
  780. *out_file_size = file_size;
  781. return true;
  782. }
  783. //-----------------------------------------------------------------------------
  784. struct ImGuiColMod // Color modifier, backup of modified data so we can restore it
  785. {
  786. ImGuiCol Col;
  787. ImVec4 PreviousValue;
  788. };
  789. struct ImGuiStyleMod // Style modifier, backup of modified data so we can restore it
  790. {
  791. ImGuiStyleVar Var;
  792. ImVec2 PreviousValue;
  793. };
  794. struct ImRect // 2D axis aligned bounding-box
  795. {
  796. ImVec2 Min;
  797. ImVec2 Max;
  798. ImRect() { Min = ImVec2(FLT_MAX,FLT_MAX); Max = ImVec2(-FLT_MAX,-FLT_MAX); }
  799. ImRect(const ImVec2& min, const ImVec2& max) { Min = min; Max = max; }
  800. ImRect(const ImVec4& v) { Min.x = v.x; Min.y = v.y; Max.x = v.z; Max.y = v.w; }
  801. ImRect(float x1, float y1, float x2, float y2) { Min.x = x1; Min.y = y1; Max.x = x2; Max.y = y2; }
  802. ImVec2 GetCenter() const { return Min + (Max-Min)*0.5f; }
  803. ImVec2 GetSize() const { return Max-Min; }
  804. float GetWidth() const { return (Max-Min).x; }
  805. float GetHeight() const { return (Max-Min).y; }
  806. ImVec2 GetTL() const { return Min; }
  807. ImVec2 GetTR() const { return ImVec2(Max.x,Min.y); }
  808. ImVec2 GetBL() const { return ImVec2(Min.x,Max.y); }
  809. ImVec2 GetBR() const { return Max; }
  810. bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x < Max.x && p.y < Max.y; }
  811. bool Contains(const ImRect& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x < Max.x && r.Max.y < Max.y; }
  812. bool Overlaps(const ImRect& r) const { return r.Min.y < Max.y && r.Max.y > Min.y && r.Min.x < Max.x && r.Max.x > Min.x; }
  813. void Add(const ImVec2& rhs) { Min.x = ImMin(Min.x, rhs.x); Min.y = ImMin(Min.y, rhs.y); Max.x = ImMax(Max.x, rhs.x); Max.y = ImMax(Max.x, rhs.x); }
  814. void Add(const ImRect& rhs) { Min.x = ImMin(Min.x, rhs.Min.x); Min.y = ImMin(Min.y, rhs.Min.y); Max.x = ImMax(Max.x, rhs.Max.x); Max.y = ImMax(Max.y, rhs.Max.y); }
  815. void Expand(const float amount) { Min.x -= amount; Min.y -= amount; Max.x += amount; Max.y += amount; }
  816. void Expand(const ImVec2& amount) { Min -= amount; Max += amount; }
  817. void Clip(const ImRect& clip) { Min.x = ImMax(Min.x, clip.Min.x); Min.y = ImMax(Min.y, clip.Min.y); Max.x = ImMin(Max.x, clip.Max.x); Max.y = ImMin(Max.y, clip.Max.y); }
  818. ImVec2 GetClosestPoint(ImVec2 p, bool on_edge) const
  819. {
  820. if (!on_edge && Contains(p))
  821. return p;
  822. if (p.x > Max.x) p.x = Max.x;
  823. else if (p.x < Min.x) p.x = Min.x;
  824. if (p.y > Max.y) p.y = Max.y;
  825. else if (p.y < Min.y) p.y = Min.y;
  826. return p;
  827. }
  828. };
  829. typedef ImRect ImGuiAabb; // FIXME-OBSOLETE
  830. struct ImGuiGroupData
  831. {
  832. ImVec2 BackupCursorPos;
  833. ImVec2 BackupCursorMaxPos;
  834. float BackupColumnsStartX;
  835. float BackupCurrentLineHeight;
  836. float BackupCurrentLineTextBaseOffset;
  837. float BackupLogLinePosY;
  838. };
  839. // Temporary per-window data, reset at the beginning of the frame
  840. struct ImGuiDrawContext
  841. {
  842. ImVec2 CursorPos;
  843. ImVec2 CursorPosPrevLine;
  844. ImVec2 CursorStartPos;
  845. ImVec2 CursorMaxPos; // Implicitly calculate the size of our contents, always extending. Saved into window->SizeContents at the end of the frame
  846. float CurrentLineHeight;
  847. float CurrentLineTextBaseOffset;
  848. float PrevLineHeight;
  849. float PrevLineTextBaseOffset;
  850. float LogLinePosY;
  851. int TreeDepth;
  852. ImGuiID LastItemID;
  853. ImRect LastItemRect;
  854. bool LastItemHoveredAndUsable;
  855. bool LastItemHoveredRect;
  856. ImVector<ImGuiWindow*> ChildWindows;
  857. ImVector<bool> AllowKeyboardFocus;
  858. ImVector<float> ItemWidth; // 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window
  859. ImVector<float> TextWrapPos;
  860. ImVector<ImGuiGroupData> GroupStack;
  861. ImGuiColorEditMode ColorEditMode;
  862. ImGuiStorage* StateStorage;
  863. float ColumnsStartX; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.)
  864. float ColumnsOffsetX; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API.
  865. int ColumnsCurrent;
  866. int ColumnsCount;
  867. ImVec2 ColumnsStartPos;
  868. float ColumnsCellMinY;
  869. float ColumnsCellMaxY;
  870. bool ColumnsShowBorders;
  871. ImGuiID ColumnsSetID;
  872. ImVector<float> ColumnsOffsetsT; // Columns offset normalized 0.0 (far left) -> 1.0 (far right)
  873. ImGuiDrawContext()
  874. {
  875. CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f);
  876. CurrentLineHeight = PrevLineHeight = 0.0f;
  877. CurrentLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f;
  878. LogLinePosY = -1.0f;
  879. TreeDepth = 0;
  880. LastItemID = 0;
  881. LastItemRect = ImRect(0.0f,0.0f,0.0f,0.0f);
  882. LastItemHoveredAndUsable = LastItemHoveredRect = false;
  883. StateStorage = NULL;
  884. ColumnsStartX = 0.0f;
  885. ColumnsOffsetX = 0.0f;
  886. ColumnsCurrent = 0;
  887. ColumnsCount = 1;
  888. ColumnsStartPos = ImVec2(0.0f, 0.0f);
  889. ColumnsCellMinY = ColumnsCellMaxY = 0.0f;
  890. ColumnsShowBorders = true;
  891. ColumnsSetID = 0;
  892. }
  893. };
  894. // Internal state of the currently focused/edited text input box
  895. struct ImGuiTextEditState
  896. {
  897. ImGuiID Id; // widget id owning the text state
  898. ImWchar Text[1024]; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer.
  899. char InitialText[1024*3+1]; // backup of end-user buffer at the time of focus (in UTF-8, unaltered)
  900. size_t CurLenA, CurLenW; // we need to maintain our buffer length in both UTF-8 and wchar format.
  901. size_t BufSizeA; // end-user buffer size, <= 1024 (or increase above)
  902. float Width; // widget width
  903. float ScrollX;
  904. STB_TexteditState StbState;
  905. float CursorAnim;
  906. ImVec2 InputCursorScreenPos; // Cursor position in screen space to be used by IME callback.
  907. bool SelectedAllMouseLock;
  908. ImFont* Font;
  909. float FontSize;
  910. ImGuiTextEditState() { memset(this, 0, sizeof(*this)); }
  911. void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking
  912. bool CursorIsVisible() const { return CursorAnim <= 0.0f || fmodf(CursorAnim, 1.20f) <= 0.80f; } // Blinking
  913. bool HasSelection() const { return StbState.select_start != StbState.select_end; }
  914. void SelectAll() { StbState.select_start = 0; StbState.select_end = (int)ImStrlenW(Text); StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; }
  915. void OnKeyPressed(int key);
  916. void UpdateScrollOffset();
  917. ImVec2 CalcDisplayOffsetFromCharIdx(int i) const;
  918. // Static functions because they are used to render non-focused instances of a text input box
  919. static const char* GetTextPointerClippedA(ImFont* font, float font_size, const char* text, float width, ImVec2* out_text_size = NULL);
  920. static const ImWchar* GetTextPointerClippedW(ImFont* font, float font_size, const ImWchar* text, float width, ImVec2* out_text_size = NULL);
  921. static void RenderTextScrolledClipped(ImFont* font, float font_size, const char* text, ImVec2 pos_base, float width, float scroll_x);
  922. };
  923. // Data saved in imgui.ini file
  924. struct ImGuiIniData
  925. {
  926. char* Name;
  927. ImGuiID ID;
  928. ImVec2 Pos;
  929. ImVec2 Size;
  930. bool Collapsed;
  931. ImGuiIniData() { memset(this, 0, sizeof(*this)); }
  932. ~ImGuiIniData() { if (Name) { ImGui::MemFree(Name); Name = NULL; } }
  933. };
  934. struct ImGuiMouseCursorData
  935. {
  936. ImGuiMouseCursor Type;
  937. ImVec2 Offset;
  938. ImVec2 Size;
  939. ImVec2 TexUvMin[2];
  940. ImVec2 TexUvMax[2];
  941. };
  942. // Main state for ImGui
  943. struct ImGuiState
  944. {
  945. bool Initialized;
  946. ImGuiIO IO;
  947. ImGuiStyle Style;
  948. ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
  949. float FontSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters.
  950. ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvForWhite
  951. float Time;
  952. int FrameCount;
  953. int FrameCountRendered;
  954. ImVector<ImGuiWindow*> Windows;
  955. ImVector<ImGuiWindow*> WindowsSortBuffer;
  956. ImGuiWindow* CurrentWindow; // Being drawn into
  957. ImVector<ImGuiWindow*> CurrentWindowStack;
  958. ImGuiWindow* FocusedWindow; // Will catch keyboard inputs
  959. ImGuiWindow* HoveredWindow; // Will catch mouse inputs
  960. ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only)
  961. ImGuiID HoveredId;
  962. ImGuiID ActiveId;
  963. ImGuiID ActiveIdPreviousFrame;
  964. bool ActiveIdIsAlive;
  965. bool ActiveIdIsFocusedOnly; // Set only by active widget. Denote focus but no active interaction.
  966. ImGuiWindow* MovedWindow; // Track the child window we clicked on to move a window. Only valid if ActiveID is the "#MOVE" identifier of a window.
  967. float SettingsDirtyTimer;
  968. ImVector<ImGuiIniData*> Settings;
  969. ImVector<ImGuiColMod> ColorModifiers;
  970. ImVector<ImGuiStyleMod> StyleModifiers;
  971. ImVector<ImFont*> FontStack;
  972. ImVec2 SetNextWindowPosVal;
  973. ImGuiSetCond SetNextWindowPosCond;
  974. ImVec2 SetNextWindowSizeVal;
  975. ImGuiSetCond SetNextWindowSizeCond;
  976. bool SetNextWindowCollapsedVal;
  977. ImGuiSetCond SetNextWindowCollapsedCond;
  978. bool SetNextWindowFocus;
  979. bool SetNextTreeNodeOpenedVal;
  980. ImGuiSetCond SetNextTreeNodeOpenedCond;
  981. // Render
  982. ImVector<ImDrawList*> RenderDrawLists[3];
  983. // Mouse cursor
  984. ImGuiMouseCursor MouseCursor;
  985. ImDrawList MouseCursorDrawList; // Optional software render of mouse cursors, if io.MouseDrawCursor is set
  986. ImGuiMouseCursorData MouseCursorData[ImGuiMouseCursor_Count_];
  987. // Widget state
  988. ImGuiTextEditState InputTextState;
  989. ImGuiID SliderAsInputTextId;
  990. ImGuiStorage ColorEditModeStorage; // for user selection
  991. ImGuiID ActiveComboID;
  992. float ScrollbarClickDeltaToGrabCenter; // distance between mouse and center of grab box, normalized in parent space
  993. char Tooltip[1024];
  994. char* PrivateClipboard; // if no custom clipboard handler is defined
  995. // Logging
  996. bool LogEnabled;
  997. FILE* LogFile;
  998. ImGuiTextBuffer* LogClipboard; // pointer so our GImGui static constructor doesn't call heap allocators.
  999. int LogStartDepth;
  1000. int LogAutoExpandMaxDepth;
  1001. // Misc
  1002. float FramerateSecPerFrame[120]; // calculate estimate of framerate for user
  1003. int FramerateSecPerFrameIdx;
  1004. float FramerateSecPerFrameAccum;
  1005. char TempBuffer[1024*3+1]; // temporary text buffer
  1006. ImGuiState()
  1007. {
  1008. Initialized = false;
  1009. Font = NULL;
  1010. FontSize = 0.0f;
  1011. FontTexUvWhitePixel = ImVec2(0.0f, 0.0f);
  1012. Time = 0.0f;
  1013. FrameCount = 0;
  1014. FrameCountRendered = -1;
  1015. CurrentWindow = NULL;
  1016. FocusedWindow = NULL;
  1017. HoveredWindow = NULL;
  1018. HoveredRootWindow = NULL;
  1019. HoveredId = 0;
  1020. ActiveId = 0;
  1021. ActiveIdPreviousFrame = 0;
  1022. ActiveIdIsAlive = false;
  1023. ActiveIdIsFocusedOnly = false;
  1024. MovedWindow = NULL;
  1025. SettingsDirtyTimer = 0.0f;
  1026. SetNextWindowPosVal = ImVec2(0.0f, 0.0f);
  1027. SetNextWindowPosCond = 0;
  1028. SetNextWindowSizeVal = ImVec2(0.0f, 0.0f);
  1029. SetNextWindowSizeCond = 0;
  1030. SetNextWindowCollapsedVal = false;
  1031. SetNextWindowCollapsedCond = 0;
  1032. SetNextWindowFocus = false;
  1033. SetNextTreeNodeOpenedVal = false;
  1034. SetNextTreeNodeOpenedCond = 0;
  1035. SliderAsInputTextId = 0;
  1036. ActiveComboID = 0;
  1037. ScrollbarClickDeltaToGrabCenter = 0.0f;
  1038. memset(Tooltip, 0, sizeof(Tooltip));
  1039. PrivateClipboard = NULL;
  1040. LogEnabled = false;
  1041. LogFile = NULL;
  1042. LogClipboard = NULL;
  1043. LogStartDepth = 0;
  1044. LogAutoExpandMaxDepth = 2;
  1045. memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame));
  1046. FramerateSecPerFrameIdx = 0;
  1047. FramerateSecPerFrameAccum = 0.0f;
  1048. }
  1049. };
  1050. static ImGuiState GImDefaultState; // Internal state storage
  1051. static ImGuiState* GImGui = &GImDefaultState; // We access everything through this pointer. NB: this pointer is always assumed to be != NULL
  1052. struct ImGuiWindow
  1053. {
  1054. char* Name;
  1055. ImGuiID ID;
  1056. ImGuiWindowFlags Flags;
  1057. ImVec2 PosFloat;
  1058. ImVec2 Pos; // Position rounded-up to nearest pixel
  1059. ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
  1060. ImVec2 SizeFull; // Size when non collapsed
  1061. ImVec2 SizeContents; // Size of contents (== extents reach of the drawing cursor) from previous frame
  1062. ImGuiID MoveID; // == window->GetID("#MOVE")
  1063. float ScrollY;
  1064. float NextScrollY;
  1065. bool ScrollbarY;
  1066. bool Visible; // Set to true on Begin()
  1067. bool WasVisible;
  1068. bool Accessed; // Set to true when any widget access the current window
  1069. bool Collapsed; // Set when collapsing window to become only title-bar
  1070. bool SkipItems; // == Visible && !Collapsed
  1071. int AutoFitFrames;
  1072. bool AutoFitOnlyGrows;
  1073. int SetWindowPosAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowPos() call will succeed with this particular flag.
  1074. int SetWindowSizeAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowSize() call will succeed with this particular flag.
  1075. int SetWindowCollapsedAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowCollapsed() call will succeed with this particular flag.
  1076. ImGuiDrawContext DC; // Temporary per-window data, reset at the beginning of the frame
  1077. ImVector<ImGuiID> IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack
  1078. ImVector<ImVec4> ClipRectStack; // Scissoring / clipping rectangle. x1, y1, x2, y2.
  1079. ImRect ClippedRect; // = ClipRectStack.front() after setup in Begin()
  1080. int LastFrameDrawn;
  1081. float ItemWidthDefault;
  1082. ImGuiStorage StateStorage;
  1083. float FontWindowScale; // Scale multiplier per-window
  1084. ImDrawList* DrawList;
  1085. ImGuiWindow* RootWindow;
  1086. // Focus
  1087. int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister()
  1088. int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through)
  1089. int FocusIdxAllRequestCurrent; // Item being requested for focus
  1090. int FocusIdxTabRequestCurrent; // Tab-able item being requested for focus
  1091. int FocusIdxAllRequestNext; // Item being requested for focus, for next update (relies on layout to be stable between the frame pressing TAB and the next frame)
  1092. int FocusIdxTabRequestNext; // "
  1093. public:
  1094. ImGuiWindow(const char* name);
  1095. ~ImGuiWindow();
  1096. ImGuiID GetID(const char* str);
  1097. ImGuiID GetID(const void* ptr);
  1098. bool FocusItemRegister(bool is_active, bool tab_stop = true); // Return true if focus is requested
  1099. void FocusItemUnregister();
  1100. ImRect Rect() const { return ImRect(Pos, Pos+Size); }
  1101. ImFont* Font() const { return GImGui->Font; }
  1102. float FontSize() const { return GImGui->FontSize * FontWindowScale; }
  1103. ImVec2 CursorPos() const { return DC.CursorPos; }
  1104. float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui->Style.FramePadding.y * 2.0f; }
  1105. ImRect TitleBarRect() const { return ImRect(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); }
  1106. ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(0,0) : GImGui->Style.WindowPadding; }
  1107. ImU32 Color(ImGuiCol idx, float a=1.f) const { ImVec4 c = GImGui->Style.Colors[idx]; c.w *= GImGui->Style.Alpha * a; return ImGui::ColorConvertFloat4ToU32(c); }
  1108. ImU32 Color(const ImVec4& col) const { ImVec4 c = col; c.w *= GImGui->Style.Alpha; return ImGui::ColorConvertFloat4ToU32(c); }
  1109. };
  1110. static inline ImGuiWindow* GetCurrentWindow()
  1111. {
  1112. // If this ever crash it probably means that ImGui::NewFrame() hasn't been called. We should always have a CurrentWindow in the stack (there is an implicit "Debug" window)
  1113. ImGuiState& g = *GImGui;
  1114. g.CurrentWindow->Accessed = true;
  1115. return g.CurrentWindow;
  1116. }
  1117. static inline ImGuiWindow* GetParentWindow()
  1118. {
  1119. ImGuiState& g = *GImGui;
  1120. IM_ASSERT(g.CurrentWindowStack.size() >= 2);
  1121. return g.CurrentWindowStack[g.CurrentWindowStack.size() - 2];
  1122. }
  1123. static void SetActiveId(ImGuiID id)
  1124. {
  1125. ImGuiState& g = *GImGui;
  1126. g.ActiveId = id;
  1127. g.ActiveIdIsFocusedOnly = false;
  1128. }
  1129. static void RegisterAliveId(ImGuiID id)
  1130. {
  1131. ImGuiState& g = *GImGui;
  1132. if (g.ActiveId == id)
  1133. g.ActiveIdIsAlive = true;
  1134. }
  1135. //-----------------------------------------------------------------------------
  1136. // Helper: Key->value storage
  1137. void ImGuiStorage::Clear()
  1138. {
  1139. Data.clear();
  1140. }
  1141. // std::lower_bound but without the bullshit
  1142. static ImVector<ImGuiStorage::Pair>::iterator LowerBound(ImVector<ImGuiStorage::Pair>& data, ImU32 key)
  1143. {
  1144. ImVector<ImGuiStorage::Pair>::iterator first = data.begin();
  1145. ImVector<ImGuiStorage::Pair>::iterator last = data.end();
  1146. int count = (int)(last - first);
  1147. while (count > 0)
  1148. {
  1149. int count2 = count / 2;
  1150. ImVector<ImGuiStorage::Pair>::iterator mid = first + count2;
  1151. if (mid->key < key)
  1152. {
  1153. first = ++mid;
  1154. count -= count2 + 1;
  1155. }
  1156. else
  1157. {
  1158. count = count2;
  1159. }
  1160. }
  1161. return first;
  1162. }
  1163. int ImGuiStorage::GetInt(ImU32 key, int default_val) const
  1164. {
  1165. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  1166. if (it == Data.end() || it->key != key)
  1167. return default_val;
  1168. return it->val_i;
  1169. }
  1170. float ImGuiStorage::GetFloat(ImU32 key, float default_val) const
  1171. {
  1172. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  1173. if (it == Data.end() || it->key != key)
  1174. return default_val;
  1175. return it->val_f;
  1176. }
  1177. void* ImGuiStorage::GetVoidPtr(ImGuiID key) const
  1178. {
  1179. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  1180. if (it == Data.end() || it->key != key)
  1181. return NULL;
  1182. return it->val_p;
  1183. }
  1184. // References are only valid until a new value is added to the storage. Calling a Set***() function or a Get***Ref() function invalidates the pointer.
  1185. int* ImGuiStorage::GetIntRef(ImGuiID key, int default_val)
  1186. {
  1187. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1188. if (it == Data.end() || it->key != key)
  1189. it = Data.insert(it, Pair(key, default_val));
  1190. return &it->val_i;
  1191. }
  1192. float* ImGuiStorage::GetFloatRef(ImGuiID key, float default_val)
  1193. {
  1194. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1195. if (it == Data.end() || it->key != key)
  1196. it = Data.insert(it, Pair(key, default_val));
  1197. return &it->val_f;
  1198. }
  1199. // FIXME-OPT: Wasting CPU because all SetInt() are preceeded by GetInt() calls so we should have the result from lower_bound already in place.
  1200. // However we only use SetInt() on explicit user action (so that's maximum once a frame) so the optimisation isn't much needed.
  1201. void ImGuiStorage::SetInt(ImU32 key, int val)
  1202. {
  1203. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1204. if (it == Data.end() || it->key != key)
  1205. {
  1206. Data.insert(it, Pair(key, val));
  1207. return;
  1208. }
  1209. it->val_i = val;
  1210. }
  1211. void ImGuiStorage::SetFloat(ImU32 key, float val)
  1212. {
  1213. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1214. if (it == Data.end() || it->key != key)
  1215. {
  1216. Data.insert(it, Pair(key, val));
  1217. return;
  1218. }
  1219. it->val_f = val;
  1220. }
  1221. void ImGuiStorage::SetVoidPtr(ImU32 key, void* val)
  1222. {
  1223. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1224. if (it == Data.end() || it->key != key)
  1225. {
  1226. Data.insert(it, Pair(key, val));
  1227. return;
  1228. }
  1229. it->val_p = val;
  1230. }
  1231. void ImGuiStorage::SetAllInt(int v)
  1232. {
  1233. for (size_t i = 0; i < Data.size(); i++)
  1234. Data[i].val_i = v;
  1235. }
  1236. //-----------------------------------------------------------------------------
  1237. // Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
  1238. ImGuiTextFilter::ImGuiTextFilter(const char* default_filter)
  1239. {
  1240. if (default_filter)
  1241. {
  1242. ImFormatString(InputBuf, IM_ARRAYSIZE(InputBuf), "%s", default_filter);
  1243. Build();
  1244. }
  1245. else
  1246. {
  1247. InputBuf[0] = 0;
  1248. CountGrep = 0;
  1249. }
  1250. }
  1251. void ImGuiTextFilter::Draw(const char* label, float width)
  1252. {
  1253. if (width > 0.0f)
  1254. ImGui::PushItemWidth(width);
  1255. ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf));
  1256. if (width > 0.0f)
  1257. ImGui::PopItemWidth();
  1258. Build();
  1259. }
  1260. void ImGuiTextFilter::TextRange::split(char separator, ImVector<TextRange>& out)
  1261. {
  1262. out.resize(0);
  1263. const char* wb = b;
  1264. const char* we = wb;
  1265. while (we < e)
  1266. {
  1267. if (*we == separator)
  1268. {
  1269. out.push_back(TextRange(wb, we));
  1270. wb = we + 1;
  1271. }
  1272. we++;
  1273. }
  1274. if (wb != we)
  1275. out.push_back(TextRange(wb, we));
  1276. }
  1277. void ImGuiTextFilter::Build()
  1278. {
  1279. Filters.resize(0);
  1280. TextRange input_range(InputBuf, InputBuf+strlen(InputBuf));
  1281. input_range.split(',', Filters);
  1282. CountGrep = 0;
  1283. for (size_t i = 0; i != Filters.size(); i++)
  1284. {
  1285. Filters[i].trim_blanks();
  1286. if (Filters[i].empty())
  1287. continue;
  1288. if (Filters[i].front() != '-')
  1289. CountGrep += 1;
  1290. }
  1291. }
  1292. bool ImGuiTextFilter::PassFilter(const char* val) const
  1293. {
  1294. if (Filters.empty())
  1295. return true;
  1296. if (val == NULL)
  1297. val = "";
  1298. for (size_t i = 0; i != Filters.size(); i++)
  1299. {
  1300. const TextRange& f = Filters[i];
  1301. if (f.empty())
  1302. continue;
  1303. if (f.front() == '-')
  1304. {
  1305. // Subtract
  1306. if (ImStristr(val, f.begin()+1, f.end()) != NULL)
  1307. return false;
  1308. }
  1309. else
  1310. {
  1311. // Grep
  1312. if (ImStristr(val, f.begin(), f.end()) != NULL)
  1313. return true;
  1314. }
  1315. }
  1316. // Implicit * grep
  1317. if (CountGrep == 0)
  1318. return true;
  1319. return false;
  1320. }
  1321. //-----------------------------------------------------------------------------
  1322. // On some platform vsnprintf() takes va_list by reference and modifies it.
  1323. // va_copy is the 'correct' way to copy a va_list but Visual Studio prior to 2013 doesn't have it.
  1324. #ifndef va_copy
  1325. #define va_copy(dest, src) (dest = src)
  1326. #endif
  1327. // Helper: Text buffer for logging/accumulating text
  1328. void ImGuiTextBuffer::appendv(const char* fmt, va_list args)
  1329. {
  1330. va_list args_copy;
  1331. va_copy(args_copy, args);
  1332. int len = vsnprintf(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass.
  1333. if (len <= 0)
  1334. return;
  1335. const size_t write_off = Buf.size();
  1336. const size_t needed_sz = write_off + (size_t)len;
  1337. if (write_off + (size_t)len >= Buf.capacity())
  1338. {
  1339. const size_t double_capacity = Buf.capacity() * 2;
  1340. Buf.reserve(needed_sz > double_capacity ? needed_sz : double_capacity);
  1341. }
  1342. Buf.resize(needed_sz);
  1343. ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args_copy);
  1344. }
  1345. void ImGuiTextBuffer::append(const char* fmt, ...)
  1346. {
  1347. va_list args;
  1348. va_start(args, fmt);
  1349. appendv(fmt, args);
  1350. va_end(args);
  1351. }
  1352. //-----------------------------------------------------------------------------
  1353. ImGuiWindow::ImGuiWindow(const char* name)
  1354. {
  1355. Name = ImStrdup(name);
  1356. ID = ImHash(name, 0);
  1357. IDStack.push_back(ID);
  1358. MoveID = GetID("#MOVE");
  1359. Flags = 0;
  1360. PosFloat = Pos = ImVec2(0.0f, 0.0f);
  1361. Size = SizeFull = ImVec2(0.0f, 0.0f);
  1362. SizeContents = ImVec2(0.0f, 0.0f);
  1363. ScrollY = 0.0f;
  1364. NextScrollY = 0.0f;
  1365. ScrollbarY = false;
  1366. Visible = WasVisible = false;
  1367. Accessed = false;
  1368. Collapsed = false;
  1369. SkipItems = false;
  1370. AutoFitFrames = -1;
  1371. AutoFitOnlyGrows = false;
  1372. SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCond_Always | ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver;
  1373. LastFrameDrawn = -1;
  1374. ItemWidthDefault = 0.0f;
  1375. FontWindowScale = 1.0f;
  1376. DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
  1377. new(DrawList) ImDrawList();
  1378. RootWindow = NULL;
  1379. FocusIdxAllCounter = FocusIdxTabCounter = -1;
  1380. FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX;
  1381. FocusIdxAllRequestNext = FocusIdxTabRequestNext = IM_INT_MAX;
  1382. }
  1383. ImGuiWindow::~ImGuiWindow()
  1384. {
  1385. DrawList->~ImDrawList();
  1386. ImGui::MemFree(DrawList);
  1387. DrawList = NULL;
  1388. ImGui::MemFree(Name);
  1389. Name = NULL;
  1390. }
  1391. ImGuiID ImGuiWindow::GetID(const char* str)
  1392. {
  1393. ImGuiID seed = IDStack.back();
  1394. const ImGuiID id = ImHash(str, 0, seed);
  1395. RegisterAliveId(id);
  1396. return id;
  1397. }
  1398. ImGuiID ImGuiWindow::GetID(const void* ptr)
  1399. {
  1400. ImGuiID seed = IDStack.back();
  1401. const ImGuiID id = ImHash(&ptr, sizeof(void*), seed);
  1402. RegisterAliveId(id);
  1403. return id;
  1404. }
  1405. bool ImGuiWindow::FocusItemRegister(bool is_active, bool tab_stop)
  1406. {
  1407. ImGuiState& g = *GImGui;
  1408. ImGuiWindow* window = GetCurrentWindow();
  1409. const bool allow_keyboard_focus = window->DC.AllowKeyboardFocus.back();
  1410. FocusIdxAllCounter++;
  1411. if (allow_keyboard_focus)
  1412. FocusIdxTabCounter++;
  1413. // Process keyboard input at this point: TAB, Shift-TAB switch focus
  1414. // We can always TAB out of a widget that doesn't allow tabbing in.
  1415. if (tab_stop && FocusIdxAllRequestNext == IM_INT_MAX && FocusIdxTabRequestNext == IM_INT_MAX && is_active && IsKeyPressedMap(ImGuiKey_Tab))
  1416. {
  1417. // Modulo on index will be applied at the end of frame once we've got the total counter of items.
  1418. FocusIdxTabRequestNext = FocusIdxTabCounter + (g.IO.KeyShift ? (allow_keyboard_focus ? -1 : 0) : +1);
  1419. }
  1420. if (FocusIdxAllCounter == FocusIdxAllRequestCurrent)
  1421. return true;
  1422. if (allow_keyboard_focus)
  1423. if (FocusIdxTabCounter == FocusIdxTabRequestCurrent)
  1424. return true;
  1425. return false;
  1426. }
  1427. void ImGuiWindow::FocusItemUnregister()
  1428. {
  1429. FocusIdxAllCounter--;
  1430. FocusIdxTabCounter--;
  1431. }
  1432. static inline void AddDrawListToRenderList(ImVector<ImDrawList*>& out_render_list, ImDrawList* draw_list)
  1433. {
  1434. if (!draw_list->commands.empty() && !draw_list->vtx_buffer.empty())
  1435. {
  1436. if (draw_list->commands.back().vtx_count == 0)
  1437. draw_list->commands.pop_back();
  1438. out_render_list.push_back(draw_list);
  1439. }
  1440. }
  1441. static void AddWindowToRenderList(ImVector<ImDrawList*>& out_render_list, ImGuiWindow* window)
  1442. {
  1443. AddDrawListToRenderList(out_render_list, window->DrawList);
  1444. for (size_t i = 0; i < window->DC.ChildWindows.size(); i++)
  1445. {
  1446. ImGuiWindow* child = window->DC.ChildWindows[i];
  1447. if (child->Visible) // clipped children may have been marked not Visible
  1448. AddWindowToRenderList(out_render_list, child);
  1449. }
  1450. }
  1451. //-----------------------------------------------------------------------------
  1452. void* ImGui::MemAlloc(size_t sz)
  1453. {
  1454. return GImGui->IO.MemAllocFn(sz);
  1455. }
  1456. void ImGui::MemFree(void* ptr)
  1457. {
  1458. return GImGui->IO.MemFreeFn(ptr);
  1459. }
  1460. static ImGuiIniData* FindWindowSettings(const char* name)
  1461. {
  1462. ImGuiState& g = *GImGui;
  1463. ImGuiID id = ImHash(name, 0);
  1464. for (size_t i = 0; i != g.Settings.size(); i++)
  1465. {
  1466. ImGuiIniData* ini = g.Settings[i];
  1467. if (ini->ID == id)
  1468. return ini;
  1469. }
  1470. return NULL;
  1471. }
  1472. static ImGuiIniData* AddWindowSettings(const char* name)
  1473. {
  1474. ImGuiIniData* ini = (ImGuiIniData*)ImGui::MemAlloc(sizeof(ImGuiIniData));
  1475. new(ini) ImGuiIniData();
  1476. ini->Name = ImStrdup(name);
  1477. ini->ID = ImHash(name, 0);
  1478. ini->Collapsed = false;
  1479. ini->Pos = ImVec2(FLT_MAX,FLT_MAX);
  1480. ini->Size = ImVec2(0,0);
  1481. GImGui->Settings.push_back(ini);
  1482. return ini;
  1483. }
  1484. // Zero-tolerance, poor-man .ini parsing
  1485. // FIXME: Write something less rubbish
  1486. static void LoadSettings()
  1487. {
  1488. ImGuiState& g = *GImGui;
  1489. const char* filename = g.IO.IniFilename;
  1490. if (!filename)
  1491. return;
  1492. char* file_data;
  1493. size_t file_size;
  1494. if (!ImLoadFileToMemory(filename, "rb", (void**)&file_data, &file_size, 1))
  1495. return;
  1496. ImGuiIniData* settings = NULL;
  1497. const char* buf_end = file_data + file_size;
  1498. for (const char* line_start = file_data; line_start < buf_end; )
  1499. {
  1500. const char* line_end = line_start;
  1501. while (line_end < buf_end && *line_end != '\n' && *line_end != '\r')
  1502. line_end++;
  1503. if (line_start[0] == '[' && line_end > line_start && line_end[-1] == ']')
  1504. {
  1505. char name[64];
  1506. ImFormatString(name, IM_ARRAYSIZE(name), "%.*s", line_end-line_start-2, line_start+1);
  1507. settings = FindWindowSettings(name);
  1508. if (!settings)
  1509. settings = AddWindowSettings(name);
  1510. }
  1511. else if (settings)
  1512. {
  1513. float x, y;
  1514. int i;
  1515. if (sscanf(line_start, "Pos=%f,%f", &x, &y) == 2)
  1516. settings->Pos = ImVec2(x, y);
  1517. else if (sscanf(line_start, "Size=%f,%f", &x, &y) == 2)
  1518. settings->Size = ImMax(ImVec2(x, y), g.Style.WindowMinSize);
  1519. else if (sscanf(line_start, "Collapsed=%d", &i) == 1)
  1520. settings->Collapsed = (i != 0);
  1521. }
  1522. line_start = line_end+1;
  1523. }
  1524. ImGui::MemFree(file_data);
  1525. }
  1526. static void SaveSettings()
  1527. {
  1528. ImGuiState& g = *GImGui;
  1529. const char* filename = g.IO.IniFilename;
  1530. if (!filename)
  1531. return;
  1532. // Gather data from windows that were active during this session
  1533. for (size_t i = 0; i != g.Windows.size(); i++)
  1534. {
  1535. ImGuiWindow* window = g.Windows[i];
  1536. if (window->Flags & ImGuiWindowFlags_NoSavedSettings)
  1537. continue;
  1538. ImGuiIniData* settings = FindWindowSettings(window->Name);
  1539. settings->Pos = window->Pos;
  1540. settings->Size = window->SizeFull;
  1541. settings->Collapsed = window->Collapsed;
  1542. }
  1543. // Write .ini file
  1544. // If a window wasn't opened in this session we preserve its settings
  1545. FILE* f = fopen(filename, "wt");
  1546. if (!f)
  1547. return;
  1548. for (size_t i = 0; i != g.Settings.size(); i++)
  1549. {
  1550. const ImGuiIniData* settings = g.Settings[i];
  1551. if (settings->Pos.x == FLT_MAX)
  1552. continue;
  1553. const char* name = settings->Name;
  1554. if (const char* p = strstr(name, "###")) // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID()
  1555. name = p;
  1556. fprintf(f, "[%s]\n", name);
  1557. fprintf(f, "Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y);
  1558. fprintf(f, "Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y);
  1559. fprintf(f, "Collapsed=%d\n", settings->Collapsed);
  1560. fprintf(f, "\n");
  1561. }
  1562. fclose(f);
  1563. }
  1564. static void MarkSettingsDirty()
  1565. {
  1566. ImGuiState& g = *GImGui;
  1567. if (g.SettingsDirtyTimer <= 0.0f)
  1568. g.SettingsDirtyTimer = g.IO.IniSavingRate;
  1569. }
  1570. const char* ImGui::GetVersion()
  1571. {
  1572. return IMGUI_VERSION;
  1573. }
  1574. // Internal state access - if you want to share ImGui state between modules (e.g. DLL) or allocate it yourself
  1575. // Note that we still point to some static data and members (such as GFontAtlas), so the state instance you end up using will point to the static data within its module
  1576. void* ImGui::GetInternalState()
  1577. {
  1578. return GImGui;
  1579. }
  1580. size_t ImGui::GetInternalStateSize()
  1581. {
  1582. return sizeof(ImGuiState);
  1583. }
  1584. void ImGui::SetInternalState(void* state, bool construct)
  1585. {
  1586. if (construct)
  1587. new (state) ImGuiState();
  1588. GImGui = (ImGuiState*)state;
  1589. }
  1590. ImGuiIO& ImGui::GetIO()
  1591. {
  1592. return GImGui->IO;
  1593. }
  1594. ImGuiStyle& ImGui::GetStyle()
  1595. {
  1596. return GImGui->Style;
  1597. }
  1598. void ImGui::NewFrame()
  1599. {
  1600. ImGuiState& g = *GImGui;
  1601. // Check user data
  1602. IM_ASSERT(g.IO.DeltaTime > 0.0f);
  1603. IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f);
  1604. IM_ASSERT(g.IO.RenderDrawListsFn != NULL); // Must be implemented
  1605. IM_ASSERT(g.IO.Fonts->Fonts.size() > 0); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
  1606. IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded()); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
  1607. if (!g.Initialized)
  1608. {
  1609. // Initialize on first frame
  1610. g.LogClipboard = (ImGuiTextBuffer*)ImGui::MemAlloc(sizeof(ImGuiTextBuffer));
  1611. new(g.LogClipboard) ImGuiTextBuffer();
  1612. IM_ASSERT(g.Settings.empty());
  1613. LoadSettings();
  1614. g.Initialized = true;
  1615. }
  1616. SetFont(g.IO.Fonts->Fonts[0]);
  1617. g.Time += g.IO.DeltaTime;
  1618. g.FrameCount += 1;
  1619. g.Tooltip[0] = '\0';
  1620. // Update inputs state
  1621. if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
  1622. g.IO.MousePos = ImVec2(-9999.0f, -9999.0f);
  1623. if ((g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0) || (g.IO.MousePosPrev.x < 0 && g.IO.MousePosPrev.y < 0)) // if mouse just appeared or disappeared (negative coordinate) we cancel out movement in MouseDelta
  1624. g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
  1625. else
  1626. g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
  1627. g.IO.MousePosPrev = g.IO.MousePos;
  1628. for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
  1629. {
  1630. g.IO.MouseDownTime[i] = g.IO.MouseDown[i] ? (g.IO.MouseDownTime[i] < 0.0f ? 0.0f : g.IO.MouseDownTime[i] + g.IO.DeltaTime) : -1.0f;
  1631. g.IO.MouseClicked[i] = (g.IO.MouseDownTime[i] == 0.0f);
  1632. g.IO.MouseDoubleClicked[i] = false;
  1633. if (g.IO.MouseClicked[i])
  1634. {
  1635. if (g.Time - g.IO.MouseClickedTime[i] < g.IO.MouseDoubleClickTime)
  1636. {
  1637. if (ImLengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist)
  1638. g.IO.MouseDoubleClicked[i] = true;
  1639. g.IO.MouseClickedTime[i] = -FLT_MAX; // so the third click isn't turned into a double-click
  1640. }
  1641. else
  1642. {
  1643. g.IO.MouseClickedTime[i] = g.Time;
  1644. }
  1645. g.IO.MouseClickedPos[i] = g.IO.MousePos;
  1646. g.IO.MouseDragMaxDistanceSqr[i] = 0.0f;
  1647. }
  1648. else if (g.IO.MouseDown[i])
  1649. {
  1650. g.IO.MouseDragMaxDistanceSqr[i] = ImMax(g.IO.MouseDragMaxDistanceSqr[i], ImLengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]));
  1651. }
  1652. }
  1653. for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
  1654. g.IO.KeysDownTime[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownTime[i] < 0.0f ? 0.0f : g.IO.KeysDownTime[i] + g.IO.DeltaTime) : -1.0f;
  1655. // Calculate frame-rate for the user, as a purely luxurious feature
  1656. g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx];
  1657. g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx] = g.IO.DeltaTime;
  1658. g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % IM_ARRAYSIZE(g.FramerateSecPerFrame);
  1659. g.IO.Framerate = 1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame));
  1660. // Clear reference to active widget if the widget isn't alive anymore
  1661. g.HoveredId = 0;
  1662. if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0)
  1663. SetActiveId(0);
  1664. g.ActiveIdPreviousFrame = g.ActiveId;
  1665. g.ActiveIdIsAlive = false;
  1666. if (!g.ActiveId)
  1667. g.MovedWindow = NULL;
  1668. // Delay saving settings so we don't spam disk too much
  1669. if (g.SettingsDirtyTimer > 0.0f)
  1670. {
  1671. g.SettingsDirtyTimer -= g.IO.DeltaTime;
  1672. if (g.SettingsDirtyTimer <= 0.0f)
  1673. SaveSettings();
  1674. }
  1675. // Find the window we are hovering. Child windows can extend beyond the limit of their parent so we need to derive HoveredRootWindow from HoveredWindow
  1676. g.HoveredWindow = FindHoveredWindow(g.IO.MousePos, false);
  1677. if (g.HoveredWindow && (g.HoveredWindow->Flags & ImGuiWindowFlags_ChildWindow))
  1678. g.HoveredRootWindow = g.HoveredWindow->RootWindow;
  1679. else
  1680. g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true);
  1681. // Are we using inputs? Tell user so they can capture/discard the inputs away from the rest of their application.
  1682. // When clicking outside of a window we assume the click is owned by the application and won't request capture.
  1683. int mouse_earliest_button_down = -1;
  1684. for (int i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
  1685. {
  1686. if (g.IO.MouseClicked[i])
  1687. g.IO.MouseDownOwned[i] = (g.HoveredWindow != NULL);
  1688. if (g.IO.MouseDown[i])
  1689. if (mouse_earliest_button_down == -1 || g.IO.MouseClickedTime[mouse_earliest_button_down] > g.IO.MouseClickedTime[i])
  1690. mouse_earliest_button_down = i;
  1691. }
  1692. bool mouse_owned_by_application = mouse_earliest_button_down != -1 && !g.IO.MouseDownOwned[mouse_earliest_button_down];
  1693. g.IO.WantCaptureMouse = (!mouse_owned_by_application && g.HoveredWindow != NULL) || (g.ActiveId != 0);
  1694. g.IO.WantCaptureKeyboard = (g.ActiveId != 0);
  1695. g.MouseCursor = ImGuiMouseCursor_Arrow;
  1696. // If mouse was first clicked outside of ImGui bounds we also cancel out hovering.
  1697. if (mouse_owned_by_application)
  1698. g.HoveredWindow = g.HoveredRootWindow = NULL;
  1699. // Scale & Scrolling
  1700. if (g.HoveredWindow && g.IO.MouseWheel != 0.0f)
  1701. {
  1702. ImGuiWindow* window = g.HoveredWindow;
  1703. if (g.IO.KeyCtrl)
  1704. {
  1705. if (g.IO.FontAllowUserScaling)
  1706. {
  1707. // Zoom / Scale window
  1708. float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
  1709. float scale = new_font_scale / window->FontWindowScale;
  1710. window->FontWindowScale = new_font_scale;
  1711. const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
  1712. window->Pos += offset;
  1713. window->PosFloat += offset;
  1714. window->Size *= scale;
  1715. window->SizeFull *= scale;
  1716. }
  1717. }
  1718. else
  1719. {
  1720. // Scroll
  1721. if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse))
  1722. {
  1723. const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5;
  1724. window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines;
  1725. }
  1726. }
  1727. }
  1728. // Pressing TAB activate widget focus
  1729. // NB: Don't discard FocusedWindow if it isn't active, so that a window that go on/off programatically won't lose its keyboard focus.
  1730. if (g.ActiveId == 0 && g.FocusedWindow != NULL && g.FocusedWindow->Visible && IsKeyPressedMap(ImGuiKey_Tab, false))
  1731. {
  1732. g.FocusedWindow->FocusIdxTabRequestNext = 0;
  1733. }
  1734. // Mark all windows as not visible
  1735. for (size_t i = 0; i != g.Windows.size(); i++)
  1736. {
  1737. ImGuiWindow* window = g.Windows[i];
  1738. window->WasVisible = window->Visible;
  1739. window->Visible = false;
  1740. window->Accessed = false;
  1741. }
  1742. // No window should be open at the beginning of the frame.
  1743. // But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear.
  1744. g.CurrentWindowStack.resize(0);
  1745. // Create implicit window - we will only render it if the user has added something to it.
  1746. ImGui::SetNextWindowSize(ImVec2(400,400), ImGuiSetCond_FirstUseEver);
  1747. ImGui::Begin("Debug");
  1748. }
  1749. // NB: behavior of ImGui after Shutdown() is not tested/guaranteed at the moment. This function is merely here to free heap allocations.
  1750. void ImGui::Shutdown()
  1751. {
  1752. ImGuiState& g = *GImGui;
  1753. if (!g.Initialized)
  1754. return;
  1755. SaveSettings();
  1756. for (size_t i = 0; i < g.Windows.size(); i++)
  1757. {
  1758. g.Windows[i]->~ImGuiWindow();
  1759. ImGui::MemFree(g.Windows[i]);
  1760. }
  1761. g.Windows.clear();
  1762. g.WindowsSortBuffer.clear();
  1763. g.CurrentWindowStack.clear();
  1764. g.FocusedWindow = NULL;
  1765. g.HoveredWindow = NULL;
  1766. g.HoveredRootWindow = NULL;
  1767. for (size_t i = 0; i < g.Settings.size(); i++)
  1768. {
  1769. g.Settings[i]->~ImGuiIniData();
  1770. ImGui::MemFree(g.Settings[i]);
  1771. }
  1772. g.Settings.clear();
  1773. g.ColorModifiers.clear();
  1774. g.StyleModifiers.clear();
  1775. g.FontStack.clear();
  1776. for (size_t i = 0; i < IM_ARRAYSIZE(g.RenderDrawLists); i++)
  1777. g.RenderDrawLists[i].clear();
  1778. g.MouseCursorDrawList.ClearFreeMemory();
  1779. g.ColorEditModeStorage.Clear();
  1780. if (g.PrivateClipboard)
  1781. {
  1782. ImGui::MemFree(g.PrivateClipboard);
  1783. g.PrivateClipboard = NULL;
  1784. }
  1785. if (g.LogFile && g.LogFile != stdout)
  1786. {
  1787. fclose(g.LogFile);
  1788. g.LogFile = NULL;
  1789. }
  1790. if (g.LogClipboard)
  1791. {
  1792. g.LogClipboard->~ImGuiTextBuffer();
  1793. ImGui::MemFree(g.LogClipboard);
  1794. }
  1795. g.IO.Fonts->Clear();
  1796. g.Initialized = false;
  1797. }
  1798. // FIXME: Add a more explicit sort order in the window structure.
  1799. static int ChildWindowComparer(const void* lhs, const void* rhs)
  1800. {
  1801. const ImGuiWindow* a = *(const ImGuiWindow**)lhs;
  1802. const ImGuiWindow* b = *(const ImGuiWindow**)rhs;
  1803. if (int d = (a->Flags & ImGuiWindowFlags_Popup) - (b->Flags & ImGuiWindowFlags_Popup))
  1804. return d;
  1805. if (int d = (a->Flags & ImGuiWindowFlags_Tooltip) - (b->Flags & ImGuiWindowFlags_Tooltip))
  1806. return d;
  1807. if (int d = (a->Flags & ImGuiWindowFlags_ComboBox) - (b->Flags & ImGuiWindowFlags_ComboBox))
  1808. return d;
  1809. return 0;
  1810. }
  1811. static void AddWindowToSortedBuffer(ImVector<ImGuiWindow*>& out_sorted_windows, ImGuiWindow* window)
  1812. {
  1813. out_sorted_windows.push_back(window);
  1814. if (window->Visible)
  1815. {
  1816. const size_t count = window->DC.ChildWindows.size();
  1817. if (count > 1)
  1818. qsort(window->DC.ChildWindows.begin(), count, sizeof(ImGuiWindow*), ChildWindowComparer);
  1819. for (size_t i = 0; i < count; i++)
  1820. {
  1821. ImGuiWindow* child = window->DC.ChildWindows[i];
  1822. if (child->Visible)
  1823. AddWindowToSortedBuffer(out_sorted_windows, child);
  1824. }
  1825. }
  1826. }
  1827. static void PushClipRect(const ImVec4& clip_rect, bool clipped = true)
  1828. {
  1829. ImGuiWindow* window = GetCurrentWindow();
  1830. ImVec4 cr = clip_rect;
  1831. if (clipped && !window->ClipRectStack.empty())
  1832. {
  1833. // Clip with existing clip rect
  1834. const ImVec4 cur_cr = window->ClipRectStack.back();
  1835. cr = ImVec4(ImMax(cr.x, cur_cr.x), ImMax(cr.y, cur_cr.y), ImMin(cr.z, cur_cr.z), ImMin(cr.w, cur_cr.w));
  1836. }
  1837. cr.z = ImMax(cr.x, cr.z);
  1838. cr.w = ImMax(cr.y, cr.w);
  1839. IM_ASSERT(cr.x <= cr.z && cr.y <= cr.w);
  1840. window->ClipRectStack.push_back(cr);
  1841. window->DrawList->PushClipRect(cr);
  1842. }
  1843. static void PopClipRect()
  1844. {
  1845. ImGuiWindow* window = GetCurrentWindow();
  1846. window->ClipRectStack.pop_back();
  1847. window->DrawList->PopClipRect();
  1848. }
  1849. void ImGui::Render()
  1850. {
  1851. ImGuiState& g = *GImGui;
  1852. IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
  1853. const bool first_render_of_the_frame = (g.FrameCountRendered != g.FrameCount);
  1854. g.FrameCountRendered = g.FrameCount;
  1855. if (first_render_of_the_frame)
  1856. {
  1857. // Hide implicit window if it hasn't been used
  1858. IM_ASSERT(g.CurrentWindowStack.size() == 1); // Mismatched Begin/End
  1859. if (g.CurrentWindow && !g.CurrentWindow->Accessed)
  1860. g.CurrentWindow->Visible = false;
  1861. ImGui::End();
  1862. // Select window for move/focus when we're done with all our widgets (we use the root window ID here)
  1863. if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredRootWindow != NULL && g.IO.MouseClicked[0])
  1864. {
  1865. IM_ASSERT(g.MovedWindow == NULL);
  1866. g.MovedWindow = g.HoveredWindow;
  1867. SetActiveId(g.HoveredRootWindow->MoveID);
  1868. }
  1869. // Sort the window list so that all child windows are after their parent
  1870. // We cannot do that on FocusWindow() because childs may not exist yet
  1871. g.WindowsSortBuffer.resize(0);
  1872. g.WindowsSortBuffer.reserve(g.Windows.size());
  1873. for (size_t i = 0; i != g.Windows.size(); i++)
  1874. {
  1875. ImGuiWindow* window = g.Windows[i];
  1876. if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is visible its parent will add it
  1877. if (window->Visible)
  1878. continue;
  1879. AddWindowToSortedBuffer(g.WindowsSortBuffer, window);
  1880. }
  1881. IM_ASSERT(g.Windows.size() == g.WindowsSortBuffer.size()); // we done something wrong
  1882. g.Windows.swap(g.WindowsSortBuffer);
  1883. // Clear data for next frame
  1884. g.IO.MouseWheel = 0.0f;
  1885. memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
  1886. }
  1887. // Skip render altogether if alpha is 0.0
  1888. // Note that vertex buffers have been created, so it is best practice that you don't call Begin/End in the first place.
  1889. if (g.Style.Alpha > 0.0f)
  1890. {
  1891. // Render tooltip
  1892. if (g.Tooltip[0])
  1893. {
  1894. // Use a dummy window to render the tooltip
  1895. ImGui::BeginTooltip();
  1896. ImGui::TextUnformatted(g.Tooltip);
  1897. ImGui::EndTooltip();
  1898. }
  1899. // Gather windows to render
  1900. for (size_t i = 0; i < IM_ARRAYSIZE(g.RenderDrawLists); i++)
  1901. g.RenderDrawLists[i].resize(0);
  1902. for (size_t i = 0; i != g.Windows.size(); i++)
  1903. {
  1904. ImGuiWindow* window = g.Windows[i];
  1905. if (window->Visible && (window->Flags & (ImGuiWindowFlags_ChildWindow)) == 0)
  1906. {
  1907. // FIXME: Generalize this with a proper layering system so we can stack.
  1908. if (window->Flags & ImGuiWindowFlags_Popup)
  1909. AddWindowToRenderList(g.RenderDrawLists[1], window);
  1910. else if (window->Flags & ImGuiWindowFlags_Tooltip)
  1911. AddWindowToRenderList(g.RenderDrawLists[2], window);
  1912. else
  1913. AddWindowToRenderList(g.RenderDrawLists[0], window);
  1914. }
  1915. }
  1916. // Flatten layers
  1917. size_t n = g.RenderDrawLists[0].size();
  1918. size_t flattened_size = n;
  1919. for (size_t i = 1; i < IM_ARRAYSIZE(g.RenderDrawLists); i++)
  1920. flattened_size += g.RenderDrawLists[i].size();
  1921. g.RenderDrawLists[0].resize(flattened_size);
  1922. for (size_t i = 1; i < IM_ARRAYSIZE(g.RenderDrawLists); i++)
  1923. {
  1924. ImVector<ImDrawList*>& layer = g.RenderDrawLists[i];
  1925. if (!layer.empty())
  1926. {
  1927. memcpy(&g.RenderDrawLists[0][n], &layer[0], layer.size() * sizeof(ImDrawList*));
  1928. n += layer.size();
  1929. }
  1930. }
  1931. if (g.IO.MouseDrawCursor)
  1932. {
  1933. const ImGuiMouseCursorData& cursor_data = g.MouseCursorData[g.MouseCursor];
  1934. const ImVec2 pos = g.IO.MousePos - cursor_data.Offset;
  1935. const ImVec2 size = cursor_data.Size;
  1936. const ImTextureID tex_id = g.IO.Fonts->TexID;
  1937. g.MouseCursorDrawList.Clear();
  1938. g.MouseCursorDrawList.PushTextureID(tex_id);
  1939. g.MouseCursorDrawList.AddImage(tex_id, pos+ImVec2(1,0), pos+ImVec2(1,0) + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], 0x30000000); // Shadow
  1940. g.MouseCursorDrawList.AddImage(tex_id, pos+ImVec2(2,0), pos+ImVec2(2,0) + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], 0x30000000); // Shadow
  1941. g.MouseCursorDrawList.AddImage(tex_id, pos, pos + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], 0xFF000000); // Black border
  1942. g.MouseCursorDrawList.AddImage(tex_id, pos, pos + size, cursor_data.TexUvMin[0], cursor_data.TexUvMax[0], 0xFFFFFFFF); // White fill
  1943. g.MouseCursorDrawList.PopTextureID();
  1944. AddDrawListToRenderList(g.RenderDrawLists[0], &g.MouseCursorDrawList);
  1945. }
  1946. // Render
  1947. if (!g.RenderDrawLists[0].empty())
  1948. g.IO.RenderDrawListsFn(&g.RenderDrawLists[0][0], (int)g.RenderDrawLists[0].size());
  1949. }
  1950. }
  1951. // Find the optional ## from which we stop displaying text.
  1952. static const char* FindTextDisplayEnd(const char* text, const char* text_end = NULL)
  1953. {
  1954. const char* text_display_end = text;
  1955. if (!text_end)
  1956. text_end = (const char*)-1;
  1957. while (text_display_end < text_end && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#'))
  1958. text_display_end++;
  1959. return text_display_end;
  1960. }
  1961. // Pass text data straight to log (without being displayed)
  1962. void ImGui::LogText(const char* fmt, ...)
  1963. {
  1964. ImGuiState& g = *GImGui;
  1965. if (!g.LogEnabled)
  1966. return;
  1967. va_list args;
  1968. va_start(args, fmt);
  1969. if (g.LogFile)
  1970. {
  1971. vfprintf(g.LogFile, fmt, args);
  1972. }
  1973. else
  1974. {
  1975. g.LogClipboard->appendv(fmt, args);
  1976. }
  1977. va_end(args);
  1978. }
  1979. // Internal version that takes a position to decide on newline placement and pad items according to their depth.
  1980. // We split text into individual lines to add current tree level padding
  1981. static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end)
  1982. {
  1983. ImGuiState& g = *GImGui;
  1984. ImGuiWindow* window = GetCurrentWindow();
  1985. if (!text_end)
  1986. text_end = FindTextDisplayEnd(text, text_end);
  1987. const bool log_new_line = ref_pos.y > window->DC.LogLinePosY+1;
  1988. window->DC.LogLinePosY = ref_pos.y;
  1989. const char* text_remaining = text;
  1990. if (g.LogStartDepth > window->DC.TreeDepth) // Re-adjust padding if we have popped out of our starting depth
  1991. g.LogStartDepth = window->DC.TreeDepth;
  1992. const int tree_depth = (window->DC.TreeDepth - g.LogStartDepth);
  1993. for (;;)
  1994. {
  1995. // Split the string. Each new line (after a '\n') is followed by spacing corresponding to the current depth of our log entry.
  1996. const char* line_end = text_remaining;
  1997. while (line_end < text_end)
  1998. if (*line_end == '\n')
  1999. break;
  2000. else
  2001. line_end++;
  2002. if (line_end >= text_end)
  2003. line_end = NULL;
  2004. const bool is_first_line = (text == text_remaining);
  2005. bool is_last_line = false;
  2006. if (line_end == NULL)
  2007. {
  2008. is_last_line = true;
  2009. line_end = text_end;
  2010. }
  2011. if (line_end != NULL && !(is_last_line && (line_end - text_remaining)==0))
  2012. {
  2013. const int char_count = (int)(line_end - text_remaining);
  2014. if (log_new_line || !is_first_line)
  2015. ImGui::LogText(STR_NEWLINE "%*s%.*s", tree_depth*4, "", char_count, text_remaining);
  2016. else
  2017. ImGui::LogText(" %.*s", char_count, text_remaining);
  2018. }
  2019. if (is_last_line)
  2020. break;
  2021. text_remaining = line_end + 1;
  2022. }
  2023. }
  2024. static float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
  2025. {
  2026. if (wrap_pos_x < 0.0f)
  2027. return 0.0f;
  2028. ImGuiWindow* window = GetCurrentWindow();
  2029. if (wrap_pos_x == 0.0f)
  2030. wrap_pos_x = ImGui::GetContentRegionMax().x;
  2031. if (wrap_pos_x > 0.0f)
  2032. wrap_pos_x += window->Pos.x; // wrap_pos_x is provided is window local space
  2033. const float wrap_width = wrap_pos_x > 0.0f ? ImMax(wrap_pos_x - pos.x, 0.00001f) : 0.0f;
  2034. return wrap_width;
  2035. }
  2036. // Internal ImGui functions to render text
  2037. // RenderText***() functions calls ImDrawList::AddText() calls ImBitmapFont::RenderText()
  2038. static void RenderText(ImVec2 pos, const char* text, const char* text_end, bool hide_text_after_hash)
  2039. {
  2040. ImGuiState& g = *GImGui;
  2041. ImGuiWindow* window = GetCurrentWindow();
  2042. // Hide anything after a '##' string
  2043. const char* text_display_end;
  2044. if (hide_text_after_hash)
  2045. {
  2046. text_display_end = FindTextDisplayEnd(text, text_end);
  2047. }
  2048. else
  2049. {
  2050. if (!text_end)
  2051. text_end = text + strlen(text); // FIXME-OPT
  2052. text_display_end = text_end;
  2053. }
  2054. const int text_len = (int)(text_display_end - text);
  2055. if (text_len > 0)
  2056. {
  2057. // Render
  2058. window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text_display_end);
  2059. // Log as text
  2060. if (g.LogEnabled)
  2061. LogText(pos, text, text_display_end);
  2062. }
  2063. }
  2064. static void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width)
  2065. {
  2066. ImGuiState& g = *GImGui;
  2067. ImGuiWindow* window = GetCurrentWindow();
  2068. if (!text_end)
  2069. text_end = text + strlen(text); // FIXME-OPT
  2070. const int text_len = (int)(text_end - text);
  2071. if (text_len > 0)
  2072. {
  2073. // Render
  2074. window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text_end, wrap_width);
  2075. // Log as text
  2076. if (g.LogEnabled)
  2077. LogText(pos, text, text_end);
  2078. }
  2079. }
  2080. static void RenderTextClipped(ImVec2 pos, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& clip_max)
  2081. {
  2082. ImGuiState& g = *GImGui;
  2083. ImGuiWindow* window = GetCurrentWindow();
  2084. // Hide anything after a '##' string
  2085. const char* text_display_end = FindTextDisplayEnd(text, text_end);
  2086. const int text_len = (int)(text_display_end - text);
  2087. if (text_len > 0)
  2088. {
  2089. const ImVec2 text_size = text_size_if_known ? *text_size_if_known : ImGui::CalcTextSize(text, text_display_end, false, 0.0f);
  2090. // Perform CPU side clipping for single clipped element to avoid using scissor state
  2091. const bool need_clipping = (pos.x + text_size.x >= clip_max.x) || (pos.y + text_size.y >= clip_max.y);
  2092. // Render
  2093. window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text_display_end, 0.0f, need_clipping ? &clip_max : NULL);
  2094. // Log as text
  2095. if (g.LogEnabled)
  2096. LogText(pos, text, text_display_end);
  2097. }
  2098. }
  2099. // Render a rectangle shaped with optional rounding and borders
  2100. static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding)
  2101. {
  2102. ImGuiWindow* window = GetCurrentWindow();
  2103. window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding);
  2104. if (border && (window->Flags & ImGuiWindowFlags_ShowBorders))
  2105. {
  2106. // FIXME: This is the best I've found that works on multiple renderer/back ends. Bit dodgy.
  2107. window->DrawList->AddRect(p_min+ImVec2(1.5f,1.5f), p_max+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding);
  2108. window->DrawList->AddRect(p_min+ImVec2(0.5f,0.5f), p_max+ImVec2(0,0), window->Color(ImGuiCol_Border), rounding);
  2109. }
  2110. }
  2111. // Render a triangle to denote expanded/collapsed state
  2112. static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale, bool shadow)
  2113. {
  2114. ImGuiWindow* window = GetCurrentWindow();
  2115. const float h = window->FontSize() * 1.00f;
  2116. const float r = h * 0.40f * scale;
  2117. ImVec2 center = p_min + ImVec2(h*0.50f, h*0.50f*scale);
  2118. ImVec2 a, b, c;
  2119. if (opened)
  2120. {
  2121. center.y -= r*0.25f;
  2122. a = center + ImVec2(0,1)*r;
  2123. b = center + ImVec2(-0.866f,-0.5f)*r;
  2124. c = center + ImVec2(0.866f,-0.5f)*r;
  2125. }
  2126. else
  2127. {
  2128. a = center + ImVec2(1,0)*r;
  2129. b = center + ImVec2(-0.500f,0.866f)*r;
  2130. c = center + ImVec2(-0.500f,-0.866f)*r;
  2131. }
  2132. if (shadow && (window->Flags & ImGuiWindowFlags_ShowBorders) != 0)
  2133. window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow));
  2134. window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Text));
  2135. }
  2136. // Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
  2137. // CalcTextSize("") should return ImVec2(0.0f, GImGui->FontSize)
  2138. ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width)
  2139. {
  2140. ImGuiWindow* window = GetCurrentWindow();
  2141. const char* text_display_end;
  2142. if (hide_text_after_double_hash)
  2143. text_display_end = FindTextDisplayEnd(text, text_end); // Hide anything after a '##' string
  2144. else
  2145. text_display_end = text_end;
  2146. ImFont* font = window->Font();
  2147. const float font_size = window->FontSize();
  2148. ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL);
  2149. // Cancel out character spacing for the last character of a line (it is baked into glyph->XAdvance field)
  2150. const float font_scale = font_size / font->FontSize;
  2151. const float character_spacing_x = 1.0f * font_scale;
  2152. if (text_size.x > 0.0f)
  2153. text_size.x -= character_spacing_x;
  2154. return text_size;
  2155. }
  2156. // Helper to calculate coarse clipping of large list of evenly sized items.
  2157. // If you are displaying thousands of items and you have a random access to the list, you can perform clipping yourself to save on CPU.
  2158. // {
  2159. // float item_height = ImGui::GetTextLineHeightWithSpacing();
  2160. // int display_start, display_end;
  2161. // ImGui::CalcListClipping(count, item_height, &display_start, &display_end); // calculate how many to clip/display
  2162. // ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (display_start) * item_height); // advance cursor
  2163. // for (int i = display_start; i < display_end; i++) // display only visible items
  2164. // // TODO: display visible item
  2165. // ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (count - display_end) * item_height); // advance cursor
  2166. // }
  2167. void ImGui::CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end)
  2168. {
  2169. ImGuiState& g = *GImGui;
  2170. ImGuiWindow* window = GetCurrentWindow();
  2171. if (g.LogEnabled)
  2172. {
  2173. // If logging is active, do not perform any clipping
  2174. *out_items_display_start = 0;
  2175. *out_items_display_end = items_count;
  2176. return;
  2177. }
  2178. const ImVec2 pos = window->DC.CursorPos;
  2179. const ImVec4 clip_rect = window->ClipRectStack.back();
  2180. const float clip_y1 = clip_rect.y;
  2181. const float clip_y2 = clip_rect.w;
  2182. int start = (int)((clip_y1 - pos.y) / items_height);
  2183. int end = (int)((clip_y2 - pos.y) / items_height);
  2184. start = ImClamp(start, 0, items_count);
  2185. end = ImClamp(end + 1, start, items_count);
  2186. *out_items_display_start = start;
  2187. *out_items_display_end = end;
  2188. }
  2189. // Find window given position, search front-to-back
  2190. static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs)
  2191. {
  2192. ImGuiState& g = *GImGui;
  2193. for (int i = (int)g.Windows.size()-1; i >= 0; i--)
  2194. {
  2195. ImGuiWindow* window = g.Windows[(size_t)i];
  2196. if (!window->Visible)
  2197. continue;
  2198. if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
  2199. continue;
  2200. // Using the clipped AABB so a child window will typically be clipped by its parent.
  2201. ImRect bb(window->ClippedRect.Min - g.Style.TouchExtraPadding, window->ClippedRect.Max + g.Style.TouchExtraPadding);
  2202. if (bb.Contains(pos))
  2203. return window;
  2204. }
  2205. return NULL;
  2206. }
  2207. // Test if mouse cursor is hovering given rectangle
  2208. // NB- Rectangle is clipped by our current clip setting
  2209. // NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
  2210. static bool IsMouseHoveringRect(const ImRect& rect)
  2211. {
  2212. ImGuiState& g = *GImGui;
  2213. ImGuiWindow* window = GetCurrentWindow();
  2214. // Clip
  2215. ImRect rect_clipped = rect;
  2216. if (!window->ClipRectStack.empty())
  2217. {
  2218. const ImVec4 clip_rect = window->ClipRectStack.back();
  2219. rect_clipped.Clip(ImRect(ImVec2(clip_rect.x, clip_rect.y), ImVec2(clip_rect.z, clip_rect.w)));
  2220. }
  2221. // Expand for touch input
  2222. const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding);
  2223. return rect_for_touch.Contains(g.IO.MousePos);
  2224. }
  2225. bool ImGui::IsMouseHoveringRect(const ImVec2& rect_min, const ImVec2& rect_max)
  2226. {
  2227. return IsMouseHoveringRect(ImRect(rect_min, rect_max));
  2228. }
  2229. bool ImGui::IsMouseHoveringWindow()
  2230. {
  2231. ImGuiState& g = *GImGui;
  2232. ImGuiWindow* window = GetCurrentWindow();
  2233. return g.HoveredWindow == window;
  2234. }
  2235. bool ImGui::IsMouseHoveringAnyWindow()
  2236. {
  2237. ImGuiState& g = *GImGui;
  2238. return g.HoveredWindow != NULL;
  2239. }
  2240. bool ImGui::IsPosHoveringAnyWindow(const ImVec2& pos)
  2241. {
  2242. return FindHoveredWindow(pos, false) != NULL;
  2243. }
  2244. static bool IsKeyPressedMap(ImGuiKey key, bool repeat)
  2245. {
  2246. ImGuiState& g = *GImGui;
  2247. const int key_index = g.IO.KeyMap[key];
  2248. return ImGui::IsKeyPressed(key_index, repeat);
  2249. }
  2250. bool ImGui::IsKeyPressed(int key_index, bool repeat)
  2251. {
  2252. ImGuiState& g = *GImGui;
  2253. IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
  2254. const float t = g.IO.KeysDownTime[key_index];
  2255. if (t == 0.0f)
  2256. return true;
  2257. // FIXME: Repeat rate should be provided elsewhere?
  2258. const float KEY_REPEAT_DELAY = 0.250f;
  2259. const float KEY_REPEAT_RATE = 0.020f;
  2260. if (repeat && t > KEY_REPEAT_DELAY)
  2261. if ((fmodf(t - KEY_REPEAT_DELAY, KEY_REPEAT_RATE) > KEY_REPEAT_RATE*0.5f) != (fmodf(t - KEY_REPEAT_DELAY - g.IO.DeltaTime, KEY_REPEAT_RATE) > KEY_REPEAT_RATE*0.5f))
  2262. return true;
  2263. return false;
  2264. }
  2265. bool ImGui::IsMouseClicked(int button, bool repeat)
  2266. {
  2267. ImGuiState& g = *GImGui;
  2268. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2269. const float t = g.IO.MouseDownTime[button];
  2270. if (t == 0.0f)
  2271. return true;
  2272. // FIXME: Repeat rate should be provided elsewhere?
  2273. const float MOUSE_REPEAT_DELAY = 0.250f;
  2274. const float MOUSE_REPEAT_RATE = 0.020f;
  2275. if (repeat && t > MOUSE_REPEAT_DELAY)
  2276. if ((fmodf(t - MOUSE_REPEAT_DELAY, MOUSE_REPEAT_RATE) > MOUSE_REPEAT_RATE*0.5f) != (fmodf(t - MOUSE_REPEAT_DELAY - g.IO.DeltaTime, MOUSE_REPEAT_RATE) > MOUSE_REPEAT_RATE*0.5f))
  2277. return true;
  2278. return false;
  2279. }
  2280. bool ImGui::IsMouseDoubleClicked(int button)
  2281. {
  2282. ImGuiState& g = *GImGui;
  2283. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2284. return g.IO.MouseDoubleClicked[button];
  2285. }
  2286. bool ImGui::IsMouseDragging(int button, float lock_threshold)
  2287. {
  2288. ImGuiState& g = *GImGui;
  2289. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2290. if (lock_threshold < 0.0f)
  2291. lock_threshold = g.IO.MouseDragThreshold;
  2292. return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold;
  2293. }
  2294. ImVec2 ImGui::GetMousePos()
  2295. {
  2296. return GImGui->IO.MousePos;
  2297. }
  2298. ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold)
  2299. {
  2300. ImGuiState& g = *GImGui;
  2301. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2302. if (lock_threshold < 0.0f)
  2303. lock_threshold = g.IO.MouseDragThreshold;
  2304. if (g.IO.MouseDown[button])
  2305. if (g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold)
  2306. return g.IO.MousePos - g.IO.MouseClickedPos[button]; // Assume we can only get active with left-mouse button (at the moment).
  2307. return ImVec2(0.0f, 0.0f);
  2308. }
  2309. ImGuiMouseCursor ImGui::GetMouseCursor()
  2310. {
  2311. return GImGui->MouseCursor;
  2312. }
  2313. void ImGui::SetMouseCursor(ImGuiMouseCursor cursor_type)
  2314. {
  2315. GImGui->MouseCursor = cursor_type;
  2316. }
  2317. bool ImGui::IsItemHovered()
  2318. {
  2319. ImGuiWindow* window = GetCurrentWindow();
  2320. return window->DC.LastItemHoveredAndUsable;
  2321. }
  2322. bool ImGui::IsItemHoveredRect()
  2323. {
  2324. ImGuiWindow* window = GetCurrentWindow();
  2325. return window->DC.LastItemHoveredRect;
  2326. }
  2327. bool ImGui::IsItemActive()
  2328. {
  2329. ImGuiState& g = *GImGui;
  2330. if (g.ActiveId)
  2331. {
  2332. ImGuiWindow* window = GetCurrentWindow();
  2333. return g.ActiveId == window->DC.LastItemID;
  2334. }
  2335. return false;
  2336. }
  2337. bool ImGui::IsAnyItemActive()
  2338. {
  2339. ImGuiState& g = *GImGui;
  2340. return g.ActiveId != 0;
  2341. }
  2342. ImVec2 ImGui::GetItemRectMin()
  2343. {
  2344. ImGuiWindow* window = GetCurrentWindow();
  2345. return window->DC.LastItemRect.Min;
  2346. }
  2347. ImVec2 ImGui::GetItemRectMax()
  2348. {
  2349. ImGuiWindow* window = GetCurrentWindow();
  2350. return window->DC.LastItemRect.Max;
  2351. }
  2352. ImVec2 ImGui::GetItemRectSize()
  2353. {
  2354. ImGuiWindow* window = GetCurrentWindow();
  2355. return window->DC.LastItemRect.GetSize();
  2356. }
  2357. ImVec2 ImGui::CalcItemRectClosestPoint(const ImVec2& pos, bool on_edge, float outward)
  2358. {
  2359. ImGuiWindow* window = GetCurrentWindow();
  2360. ImRect rect = window->DC.LastItemRect;
  2361. rect.Expand(outward);
  2362. return rect.GetClosestPoint(pos, on_edge);
  2363. }
  2364. // Tooltip is stored and turned into a BeginTooltip()/EndTooltip() sequence at the end of the frame. Each call override previous value.
  2365. void ImGui::SetTooltipV(const char* fmt, va_list args)
  2366. {
  2367. ImGuiState& g = *GImGui;
  2368. ImFormatStringV(g.Tooltip, IM_ARRAYSIZE(g.Tooltip), fmt, args);
  2369. }
  2370. void ImGui::SetTooltip(const char* fmt, ...)
  2371. {
  2372. va_list args;
  2373. va_start(args, fmt);
  2374. SetTooltipV(fmt, args);
  2375. va_end(args);
  2376. }
  2377. float ImGui::GetTime()
  2378. {
  2379. return GImGui->Time;
  2380. }
  2381. int ImGui::GetFrameCount()
  2382. {
  2383. return GImGui->FrameCount;
  2384. }
  2385. void ImGui::BeginTooltip()
  2386. {
  2387. ImGuiState& g = *GImGui;
  2388. ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize;
  2389. ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), g.Style.Colors[ImGuiCol_TooltipBg].w, flags);
  2390. }
  2391. void ImGui::EndTooltip()
  2392. {
  2393. IM_ASSERT(GetCurrentWindow()->Flags & ImGuiWindowFlags_Tooltip);
  2394. ImGui::End();
  2395. }
  2396. void ImGui::BeginPopup(bool* p_opened)
  2397. {
  2398. IM_ASSERT(p_opened != NULL); // Must provide a bool at the moment
  2399. ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
  2400. ImGuiWindowFlags flags = ImGuiWindowFlags_Popup|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize;
  2401. ImGui::Begin("##Popup", p_opened, flags);
  2402. }
  2403. void ImGui::EndPopup()
  2404. {
  2405. IM_ASSERT(GetCurrentWindow()->Flags & ImGuiWindowFlags_Popup);
  2406. ImGui::End();
  2407. ImGui::PopStyleVar();
  2408. }
  2409. bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags)
  2410. {
  2411. ImGuiState& g = *GImGui;
  2412. ImGuiWindow* window = GetCurrentWindow();
  2413. ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow;
  2414. const ImVec2 content_max = window->Pos + ImGui::GetContentRegionMax();
  2415. const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos();
  2416. ImVec2 size = size_arg;
  2417. if (size.x <= 0.0f)
  2418. {
  2419. if (size.x == 0.0f)
  2420. flags |= ImGuiWindowFlags_ChildWindowAutoFitX;
  2421. size.x = ImMax(content_max.x - cursor_pos.x, g.Style.WindowMinSize.x) - fabsf(size.x);
  2422. }
  2423. if (size.y <= 0.0f)
  2424. {
  2425. if (size.y == 0.0f)
  2426. flags |= ImGuiWindowFlags_ChildWindowAutoFitY;
  2427. size.y = ImMax(content_max.y - cursor_pos.y, g.Style.WindowMinSize.y) - fabsf(size.y);
  2428. }
  2429. if (border)
  2430. flags |= ImGuiWindowFlags_ShowBorders;
  2431. flags |= extra_flags;
  2432. char title[256];
  2433. ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s", window->Name, str_id);
  2434. const float alpha = 1.0f;
  2435. bool ret = ImGui::Begin(title, NULL, size, alpha, flags);
  2436. if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
  2437. g.CurrentWindow->Flags &= ~ImGuiWindowFlags_ShowBorders;
  2438. return ret;
  2439. }
  2440. bool ImGui::BeginChild(ImGuiID id, const ImVec2& size, bool border, ImGuiWindowFlags extra_flags)
  2441. {
  2442. char str_id[32];
  2443. ImFormatString(str_id, IM_ARRAYSIZE(str_id), "child_%x", id);
  2444. bool ret = ImGui::BeginChild(str_id, size, border, extra_flags);
  2445. return ret;
  2446. }
  2447. void ImGui::EndChild()
  2448. {
  2449. ImGuiWindow* window = GetCurrentWindow();
  2450. IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow);
  2451. if (window->Flags & ImGuiWindowFlags_ComboBox)
  2452. {
  2453. ImGui::End();
  2454. }
  2455. else
  2456. {
  2457. // When using auto-filling child window, we don't provide full width/height to ItemSize so that it doesn't feed back into automatic size-fitting.
  2458. ImGuiState& g = *GImGui;
  2459. ImVec2 sz = ImGui::GetWindowSize();
  2460. if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitX)
  2461. sz.x = ImMax(g.Style.WindowMinSize.x, sz.x - g.Style.AutoFitPadding.x);
  2462. if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitY)
  2463. sz.y = ImMax(g.Style.WindowMinSize.y, sz.y - g.Style.AutoFitPadding.y);
  2464. ImGui::End();
  2465. window = GetCurrentWindow();
  2466. ImRect bb(window->DC.CursorPos, window->DC.CursorPos + sz);
  2467. ItemSize(sz);
  2468. ItemAdd(bb, NULL);
  2469. }
  2470. }
  2471. // Helper to create a child window / scrolling region that looks like a normal widget frame.
  2472. void ImGui::BeginChildFrame(ImGuiID id, const ImVec2& size)
  2473. {
  2474. ImGuiState& g = *GImGui;
  2475. const ImGuiStyle& style = g.Style;
  2476. ImGui::PushStyleColor(ImGuiCol_ChildWindowBg, style.Colors[ImGuiCol_FrameBg]);
  2477. ImGui::PushStyleVar(ImGuiStyleVar_ChildWindowRounding, style.FrameRounding);
  2478. ImGui::BeginChild(id, size);
  2479. }
  2480. void ImGui::EndChildFrame()
  2481. {
  2482. ImGui::EndChild();
  2483. ImGui::PopStyleVar();
  2484. ImGui::PopStyleColor();
  2485. }
  2486. static ImGuiWindow* FindWindowByName(const char* name)
  2487. {
  2488. // FIXME-OPT: Store sorted hashes -> pointers.
  2489. ImGuiState& g = *GImGui;
  2490. ImGuiID id = ImHash(name, 0);
  2491. for (size_t i = 0; i < g.Windows.size(); i++)
  2492. if (g.Windows[i]->ID == id)
  2493. return g.Windows[i];
  2494. return NULL;
  2495. }
  2496. static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags)
  2497. {
  2498. ImGuiState& g = *GImGui;
  2499. // Create window the first time
  2500. ImGuiWindow* window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow));
  2501. new(window) ImGuiWindow(name);
  2502. window->Flags = flags;
  2503. if (flags & ImGuiWindowFlags_NoSavedSettings)
  2504. {
  2505. // User can disable loading and saving of settings. Tooltip and child windows also don't store settings.
  2506. window->Size = window->SizeFull = size;
  2507. }
  2508. else
  2509. {
  2510. // Retrieve settings from .ini file
  2511. // Use SetWindowPos() or SetNextWindowPos() with the appropriate condition flag to change the initial position of a window.
  2512. window->PosFloat = ImVec2(60, 60);
  2513. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  2514. ImGuiIniData* settings = FindWindowSettings(name);
  2515. if (!settings)
  2516. {
  2517. settings = AddWindowSettings(name);
  2518. }
  2519. else
  2520. {
  2521. window->SetWindowPosAllowFlags &= ~ImGuiSetCond_FirstUseEver;
  2522. window->SetWindowSizeAllowFlags &= ~ImGuiSetCond_FirstUseEver;
  2523. window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCond_FirstUseEver;
  2524. }
  2525. if (settings->Pos.x != FLT_MAX)
  2526. {
  2527. window->PosFloat = settings->Pos;
  2528. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  2529. window->Collapsed = settings->Collapsed;
  2530. }
  2531. if (ImLengthSqr(settings->Size) > 0.00001f && !(flags & ImGuiWindowFlags_NoResize))
  2532. size = settings->Size;
  2533. window->Size = window->SizeFull = size;
  2534. }
  2535. if (ImLengthSqr(window->Size) < 0.00001f)
  2536. {
  2537. window->AutoFitFrames = 2;
  2538. window->AutoFitOnlyGrows = true;
  2539. }
  2540. g.Windows.push_back(window);
  2541. return window;
  2542. }
  2543. // Push a new ImGui window to add widgets to.
  2544. // - 'size' for a regular window denote the initial size for first-time creation (no saved data) and isn't that useful. Use SetNextWindowSize() prior to calling Begin() for more flexible window manipulation.
  2545. // - A default window called "Debug" is automatically stacked at the beginning of every frame so you can use widgets without explicitly calling a Begin/End pair.
  2546. // - Begin/End can be called multiple times during the frame with the same window name to append content.
  2547. // - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file).
  2548. // You can use the "##" or "###" markers to use the same label with different id, or same id with different label. See documentation at the top of this file.
  2549. // - Return false when window is collapsed, so you can early out in your code. You always need to call ImGui::End() even if false is returned.
  2550. // - Passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed.
  2551. // - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCond_FirstUseEver) prior to calling Begin().
  2552. bool ImGui::Begin(const char* name, bool* p_opened, ImGuiWindowFlags flags)
  2553. {
  2554. return ImGui::Begin(name, p_opened, ImVec2(0.f, 0.f), -1.0f, flags);
  2555. }
  2556. bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_use, float bg_alpha, ImGuiWindowFlags flags)
  2557. {
  2558. ImGuiState& g = *GImGui;
  2559. const ImGuiStyle& style = g.Style;
  2560. IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
  2561. IM_ASSERT(name != NULL); // Must pass a name
  2562. // Find or create
  2563. bool window_is_new = false;
  2564. ImGuiWindow* window = FindWindowByName(name);
  2565. if (!window)
  2566. {
  2567. window = CreateNewWindow(name, size_on_first_use, flags);
  2568. window_is_new = true;
  2569. }
  2570. window->Flags = (ImGuiWindowFlags)flags;
  2571. // Add to stack
  2572. g.CurrentWindowStack.push_back(window);
  2573. g.CurrentWindow = window;
  2574. // Process SetNextWindow***() calls
  2575. bool window_pos_set_by_api = false;
  2576. if (g.SetNextWindowPosCond)
  2577. {
  2578. const ImVec2 backup_cursor_pos = window->DC.CursorPos; // FIXME: not sure of the exact reason of this anymore :( need to look into that.
  2579. ImGui::SetWindowPos(g.SetNextWindowPosVal, g.SetNextWindowPosCond);
  2580. window->DC.CursorPos = backup_cursor_pos;
  2581. window_pos_set_by_api = true;
  2582. g.SetNextWindowPosCond = 0;
  2583. }
  2584. if (g.SetNextWindowSizeCond)
  2585. {
  2586. ImGui::SetWindowSize(g.SetNextWindowSizeVal, g.SetNextWindowSizeCond);
  2587. g.SetNextWindowSizeCond = 0;
  2588. }
  2589. if (g.SetNextWindowCollapsedCond)
  2590. {
  2591. ImGui::SetWindowCollapsed(g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond);
  2592. g.SetNextWindowCollapsedCond = 0;
  2593. }
  2594. if (g.SetNextWindowFocus)
  2595. {
  2596. ImGui::SetWindowFocus();
  2597. g.SetNextWindowFocus = false;
  2598. }
  2599. // Find parent
  2600. ImGuiWindow* parent_window = (flags & ImGuiWindowFlags_ChildWindow) != 0 ? g.CurrentWindowStack[g.CurrentWindowStack.size()-2] : NULL;
  2601. // Update known root window (if we are a child window, otherwise window == window->RootWindow)
  2602. size_t root_idx = g.CurrentWindowStack.size() - 1;
  2603. while (root_idx > 0)
  2604. {
  2605. if ((g.CurrentWindowStack[root_idx]->Flags & ImGuiWindowFlags_ChildWindow) == 0)
  2606. break;
  2607. root_idx--;
  2608. }
  2609. window->RootWindow = g.CurrentWindowStack[root_idx];
  2610. // Default alpha
  2611. if (bg_alpha < 0.0f)
  2612. bg_alpha = style.WindowFillAlphaDefault;
  2613. // When reusing window again multiple times a frame, just append content (don't need to setup again)
  2614. const int current_frame = ImGui::GetFrameCount();
  2615. const bool first_begin_of_the_frame = (window->LastFrameDrawn != current_frame);
  2616. if (first_begin_of_the_frame)
  2617. {
  2618. window->DrawList->Clear();
  2619. window->Visible = true;
  2620. // New windows appears in front
  2621. if (!(flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Tooltip))
  2622. {
  2623. if (window->LastFrameDrawn < current_frame - 1)
  2624. {
  2625. FocusWindow(window);
  2626. // Popup position themselves when they first appear
  2627. if (flags & ImGuiWindowFlags_Popup)
  2628. {
  2629. if (!window_pos_set_by_api)
  2630. window->PosFloat = g.IO.MousePos;
  2631. }
  2632. }
  2633. }
  2634. window->LastFrameDrawn = current_frame;
  2635. window->ClipRectStack.resize(0);
  2636. // Reset contents size for auto-fitting
  2637. window->SizeContents = window_is_new ? ImVec2(0.0f, 0.0f) : window->DC.CursorMaxPos - window->Pos;
  2638. window->SizeContents.y += window->ScrollY;
  2639. if (flags & ImGuiWindowFlags_ChildWindow)
  2640. {
  2641. parent_window->DC.ChildWindows.push_back(window);
  2642. window->Pos = window->PosFloat = parent_window->DC.CursorPos;
  2643. window->SizeFull = size_on_first_use;
  2644. }
  2645. }
  2646. // Setup texture
  2647. window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID);
  2648. // Setup outer clipping rectangle
  2649. if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox))
  2650. PushClipRect(parent_window->ClipRectStack.back());
  2651. else if (g.IO.DisplayVisibleMin.x != g.IO.DisplayVisibleMax.x && g.IO.DisplayVisibleMin.y != g.IO.DisplayVisibleMax.y)
  2652. PushClipRect(ImVec4(g.IO.DisplayVisibleMin.x, g.IO.DisplayVisibleMin.y, g.IO.DisplayVisibleMax.x, g.IO.DisplayVisibleMax.y));
  2653. else
  2654. PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y));
  2655. // Setup and draw window
  2656. if (first_begin_of_the_frame)
  2657. {
  2658. // Reset ID stack
  2659. window->IDStack.resize(1);
  2660. // Move window (at the beginning of the frame to avoid input lag or sheering). Only valid for root windows.
  2661. RegisterAliveId(window->MoveID);
  2662. if (g.ActiveId == window->MoveID)
  2663. {
  2664. if (g.IO.MouseDown[0])
  2665. {
  2666. if (!(window->Flags & ImGuiWindowFlags_NoMove))
  2667. {
  2668. window->PosFloat += g.IO.MouseDelta;
  2669. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2670. MarkSettingsDirty();
  2671. }
  2672. IM_ASSERT(g.MovedWindow != NULL);
  2673. FocusWindow(g.MovedWindow);
  2674. }
  2675. else
  2676. {
  2677. SetActiveId(0);
  2678. g.MovedWindow = NULL; // Not strictly necessary but doing it for sanity.
  2679. }
  2680. }
  2681. // Tooltips always follows mouse
  2682. if (!window_pos_set_by_api && (window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2683. {
  2684. window->PosFloat = g.IO.MousePos + ImVec2(32,16) - style.FramePadding*2;
  2685. }
  2686. // Clamp into view
  2687. if (!(window->Flags & ImGuiWindowFlags_ChildWindow) && !(window->Flags & ImGuiWindowFlags_Tooltip))
  2688. {
  2689. if (window->AutoFitFrames == 0 && g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing.
  2690. {
  2691. ImVec2 clip_min = style.DisplaySafeAreaPadding;
  2692. ImVec2 clip_max = g.IO.DisplaySize - style.DisplaySafeAreaPadding;
  2693. window->PosFloat = ImMax(window->PosFloat + window->Size, clip_min) - window->Size;
  2694. window->PosFloat = ImMin(window->PosFloat, clip_max);
  2695. }
  2696. window->SizeFull = ImMax(window->SizeFull, style.WindowMinSize);
  2697. }
  2698. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  2699. // Default item width. Make it proportional to window size if window manually resizes
  2700. if (window->Size.x > 0.0f && !(window->Flags & ImGuiWindowFlags_Tooltip) && !(window->Flags & ImGuiWindowFlags_AlwaysAutoResize))
  2701. window->ItemWidthDefault = (float)(int)(window->Size.x * 0.65f);
  2702. else
  2703. window->ItemWidthDefault = 200.0f;
  2704. // Prepare for focus requests
  2705. if (window->FocusIdxAllRequestNext == IM_INT_MAX || window->FocusIdxAllCounter == -1)
  2706. window->FocusIdxAllRequestCurrent = IM_INT_MAX;
  2707. else
  2708. window->FocusIdxAllRequestCurrent = (window->FocusIdxAllRequestNext + (window->FocusIdxAllCounter+1)) % (window->FocusIdxAllCounter+1);
  2709. if (window->FocusIdxTabRequestNext == IM_INT_MAX || window->FocusIdxTabCounter == -1)
  2710. window->FocusIdxTabRequestCurrent = IM_INT_MAX;
  2711. else
  2712. window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext + (window->FocusIdxTabCounter+1)) % (window->FocusIdxTabCounter+1);
  2713. window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1;
  2714. window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = IM_INT_MAX;
  2715. ImRect title_bar_rect = window->TitleBarRect();
  2716. // Apply and ImClamp scrolling
  2717. window->ScrollY = window->NextScrollY;
  2718. window->ScrollY = ImMax(window->ScrollY, 0.0f);
  2719. if (!window->Collapsed && !window->SkipItems)
  2720. window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, window->SizeContents.y - window->SizeFull.y));
  2721. window->NextScrollY = window->ScrollY;
  2722. // At this point we don't have a clipping rectangle setup yet, so we can test and draw in title bar
  2723. // Collapse window by double-clicking on title bar
  2724. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2725. {
  2726. if (!(window->Flags & ImGuiWindowFlags_NoCollapse) && g.HoveredWindow == window && IsMouseHoveringRect(title_bar_rect) && g.IO.MouseDoubleClicked[0])
  2727. {
  2728. window->Collapsed = !window->Collapsed;
  2729. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2730. MarkSettingsDirty();
  2731. FocusWindow(window);
  2732. }
  2733. }
  2734. else
  2735. {
  2736. window->Collapsed = false;
  2737. }
  2738. // Calculate auto-fit size
  2739. ImVec2 size_auto_fit;
  2740. if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2741. {
  2742. // Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose.
  2743. size_auto_fit = window->SizeContents + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y);
  2744. }
  2745. else
  2746. {
  2747. size_auto_fit = ImClamp(window->SizeContents + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding));
  2748. if (size_auto_fit.y < window->SizeContents.y + style.AutoFitPadding.y)
  2749. size_auto_fit.x += style.ScrollbarWidth;
  2750. }
  2751. const float window_rounding = (window->Flags & ImGuiWindowFlags_ChildWindow) ? style.ChildWindowRounding : style.WindowRounding;
  2752. if (window->Collapsed)
  2753. {
  2754. // We still process initial auto-fit on collapsed windows to get a window width
  2755. // But otherwise we don't honor ImGuiWindowFlags_AlwaysAutoResize when collapsed.
  2756. if (window->AutoFitFrames > 0)
  2757. {
  2758. window->SizeFull = window->AutoFitOnlyGrows ? ImMax(window->SizeFull, size_auto_fit) : size_auto_fit;
  2759. title_bar_rect = window->TitleBarRect();
  2760. }
  2761. // Draw title bar only
  2762. window->Size = title_bar_rect.GetSize();
  2763. window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), window_rounding);
  2764. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  2765. {
  2766. window->DrawList->AddRect(title_bar_rect.GetTL()+ImVec2(1,1), title_bar_rect.GetBR()+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), window_rounding);
  2767. window->DrawList->AddRect(title_bar_rect.GetTL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_Border), window_rounding);
  2768. }
  2769. }
  2770. else
  2771. {
  2772. ImU32 resize_col = 0;
  2773. if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2774. {
  2775. window->Size = window->SizeFull = size_auto_fit;
  2776. }
  2777. else
  2778. {
  2779. if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
  2780. {
  2781. // Don't continuously mark settings as dirty, the size of the window doesn't need to be stored.
  2782. window->SizeFull = size_auto_fit;
  2783. }
  2784. else if (window->AutoFitFrames > 0)
  2785. {
  2786. // Auto-fit only grows during the first few frames
  2787. window->SizeFull = window->AutoFitOnlyGrows ? ImMax(window->SizeFull, size_auto_fit) : size_auto_fit;
  2788. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2789. MarkSettingsDirty();
  2790. }
  2791. else if (!(window->Flags & ImGuiWindowFlags_NoResize))
  2792. {
  2793. // Manual resize grip
  2794. const ImRect resize_rect(window->Rect().GetBR()-ImVec2(14,14), window->Rect().GetBR());
  2795. const ImGuiID resize_id = window->GetID("#RESIZE");
  2796. bool hovered, held;
  2797. ButtonBehavior(resize_rect, resize_id, &hovered, &held, true);
  2798. resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
  2799. if (hovered || held)
  2800. g.MouseCursor = ImGuiMouseCursor_ResizeNWSE;
  2801. if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0])
  2802. {
  2803. // Manual auto-fit when double-clicking
  2804. window->SizeFull = size_auto_fit;
  2805. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2806. MarkSettingsDirty();
  2807. SetActiveId(0);
  2808. }
  2809. else if (held)
  2810. {
  2811. // Resize
  2812. window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize);
  2813. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2814. MarkSettingsDirty();
  2815. }
  2816. }
  2817. // Update rectangle immediately so that rendering right below us isn't one frame late
  2818. window->Size = window->SizeFull;
  2819. title_bar_rect = window->TitleBarRect();
  2820. }
  2821. // Scrollbar
  2822. window->ScrollbarY = (window->SizeContents.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar);
  2823. // Window background
  2824. if (bg_alpha > 0.0f)
  2825. {
  2826. if ((window->Flags & ImGuiWindowFlags_ComboBox) != 0)
  2827. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, bg_alpha), window_rounding);
  2828. else if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2829. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_TooltipBg, bg_alpha), window_rounding);
  2830. else if ((window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
  2831. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size-ImVec2(window->ScrollbarY?style.ScrollbarWidth:0.0f,0.0f), window->Color(ImGuiCol_ChildWindowBg, bg_alpha), window_rounding, window->ScrollbarY ? (1|8) : (0xF));
  2832. else
  2833. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, bg_alpha), window_rounding);
  2834. }
  2835. // Title bar
  2836. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2837. window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_TitleBg), window_rounding, 1|2);
  2838. // Borders
  2839. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  2840. {
  2841. window->DrawList->AddRect(window->Pos+ImVec2(1,1), window->Pos+window->Size+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), window_rounding);
  2842. window->DrawList->AddRect(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_Border), window_rounding);
  2843. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2844. window->DrawList->AddLine(title_bar_rect.GetBL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_Border));
  2845. }
  2846. // Scrollbar
  2847. if (window->ScrollbarY)
  2848. Scrollbar(window);
  2849. // Render resize grip
  2850. // (after the input handling so we don't have a frame of latency)
  2851. if (!(window->Flags & ImGuiWindowFlags_NoResize))
  2852. {
  2853. const float r = window_rounding;
  2854. const ImVec2 br = window->Rect().GetBR();
  2855. if (r == 0.0f)
  2856. {
  2857. window->DrawList->AddTriangleFilled(br, br-ImVec2(0,14), br-ImVec2(14,0), resize_col);
  2858. }
  2859. else
  2860. {
  2861. // FIXME: We should draw 4 triangles and decide on a size that's not dependent on the rounding size (previously used 18)
  2862. window->DrawList->AddArc(br - ImVec2(r,r), r, resize_col, 6, 9, true);
  2863. window->DrawList->AddTriangleFilled(br+ImVec2(0,-2*r),br+ImVec2(0,-r),br+ImVec2(-r,-r), resize_col);
  2864. window->DrawList->AddTriangleFilled(br+ImVec2(-r,-r), br+ImVec2(-r,0),br+ImVec2(-2*r,0), resize_col);
  2865. }
  2866. }
  2867. }
  2868. // Setup drawing context
  2869. window->DC.ColumnsStartX = window->WindowPadding().x;
  2870. window->DC.ColumnsOffsetX = 0.0f;
  2871. window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.ColumnsStartX + window->DC.ColumnsOffsetX, window->TitleBarHeight() + window->WindowPadding().y) - ImVec2(0.0f, window->ScrollY);
  2872. window->DC.CursorPos = window->DC.CursorStartPos;
  2873. window->DC.CursorPosPrevLine = window->DC.CursorPos;
  2874. window->DC.CursorMaxPos = window->DC.CursorStartPos;
  2875. window->DC.CurrentLineHeight = window->DC.PrevLineHeight = 0.0f;
  2876. window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f;
  2877. window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f;
  2878. window->DC.ChildWindows.resize(0);
  2879. window->DC.ItemWidth.resize(0);
  2880. window->DC.ItemWidth.push_back(window->ItemWidthDefault);
  2881. window->DC.AllowKeyboardFocus.resize(0);
  2882. window->DC.AllowKeyboardFocus.push_back(true);
  2883. window->DC.TextWrapPos.resize(0);
  2884. window->DC.TextWrapPos.push_back(-1.0f); // disabled
  2885. window->DC.ColorEditMode = ImGuiColorEditMode_UserSelect;
  2886. window->DC.ColumnsCurrent = 0;
  2887. window->DC.ColumnsCount = 1;
  2888. window->DC.ColumnsStartPos = window->DC.CursorPos;
  2889. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.ColumnsStartPos.y;
  2890. window->DC.TreeDepth = 0;
  2891. window->DC.StateStorage = &window->StateStorage;
  2892. window->DC.GroupStack.resize(0);
  2893. if (window->AutoFitFrames > 0)
  2894. window->AutoFitFrames--;
  2895. // Title bar
  2896. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2897. {
  2898. if (p_opened != NULL)
  2899. CloseWindowButton(p_opened);
  2900. ImVec2 text_min = window->Pos + style.FramePadding;
  2901. if (!(window->Flags & ImGuiWindowFlags_NoCollapse))
  2902. {
  2903. RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true);
  2904. text_min.x += window->FontSize() + style.ItemInnerSpacing.x;
  2905. }
  2906. const ImVec2 text_size = CalcTextSize(name, NULL, true);
  2907. const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (p_opened ? (title_bar_rect.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y*2 + text_size.y);
  2908. RenderTextClipped(text_min, name, NULL, &text_size, text_max);
  2909. }
  2910. if (window->Flags & ImGuiWindowFlags_Popup)
  2911. {
  2912. if (p_opened)
  2913. {
  2914. if (g.IO.MouseClicked[0] && (!g.HoveredWindow || g.HoveredWindow->RootWindow != window))
  2915. *p_opened = false;
  2916. else if (!g.FocusedWindow)
  2917. *p_opened = false;
  2918. else if (g.FocusedWindow->RootWindow != window)// && !(g.FocusedWindow->RootWindow->Flags & ImGuiWindowFlags_Tooltip))
  2919. *p_opened = false;
  2920. }
  2921. }
  2922. // Save clipped aabb so we can access it in constant-time in FindHoveredWindow()
  2923. window->ClippedRect = window->Rect();
  2924. window->ClippedRect.Clip(window->ClipRectStack.front());
  2925. // Pressing CTRL+C while holding on a window copy its content to the clipboard
  2926. // This works but 1. doesn't handle multiple Begin/End pairs, 2. recursing into another Begin/End pair - so we need to work that out and add better logging scope.
  2927. // Maybe we can support CTRL+C on every element?
  2928. /*
  2929. if (g.ActiveId == move_id)
  2930. if (g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_C))
  2931. ImGui::LogToClipboard();
  2932. */
  2933. }
  2934. // Inner clipping rectangle
  2935. // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame
  2936. // Note that if our window is collapsed we will end up with a null clipping rectangle which is the correct behavior.
  2937. const ImRect title_bar_rect = window->TitleBarRect();
  2938. ImVec4 clip_rect(title_bar_rect.Min.x+0.5f+window->WindowPadding().x*0.5f, title_bar_rect.Max.y+0.5f, window->Rect().Max.x+0.5f-window->WindowPadding().x*0.5f, window->Rect().Max.y-1.5f);
  2939. if (window->ScrollbarY)
  2940. clip_rect.z -= style.ScrollbarWidth;
  2941. PushClipRect(clip_rect);
  2942. // Clear 'accessed' flag last thing
  2943. if (first_begin_of_the_frame)
  2944. window->Accessed = false;
  2945. // Child window can be out of sight and have "negative" clip windows.
  2946. // Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar).
  2947. if (flags & ImGuiWindowFlags_ChildWindow)
  2948. {
  2949. IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0);
  2950. window->Collapsed = parent_window && parent_window->Collapsed;
  2951. const ImVec4 clip_rect_t = window->ClipRectStack.back();
  2952. window->Collapsed |= (clip_rect_t.x >= clip_rect_t.z || clip_rect_t.y >= clip_rect_t.w);
  2953. // We also hide the window from rendering because we've already added its border to the command list.
  2954. // (we could perform the check earlier in the function but it is simpler at this point)
  2955. if (window->Collapsed)
  2956. window->Visible = false;
  2957. }
  2958. if (style.Alpha <= 0.0f)
  2959. window->Visible = false;
  2960. // Return false if we don't intend to display anything to allow user to perform an early out optimization
  2961. window->SkipItems = (window->Collapsed || !window->Visible) && window->AutoFitFrames == 0;
  2962. return !window->SkipItems;
  2963. }
  2964. void ImGui::End()
  2965. {
  2966. ImGuiState& g = *GImGui;
  2967. ImGuiWindow* window = g.CurrentWindow;
  2968. ImGui::Columns(1, "#CloseColumns");
  2969. PopClipRect(); // inner window clip rectangle
  2970. PopClipRect(); // outer window clip rectangle
  2971. window->DrawList->PopTextureID();
  2972. // Stop logging
  2973. if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of logging
  2974. ImGui::LogFinish();
  2975. // Pop
  2976. // NB: we don't clear 'window->RootWindow'. The pointer is allowed to live until the next call to Begin().
  2977. g.CurrentWindowStack.pop_back();
  2978. g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back();
  2979. }
  2980. // Vertical scrollbar
  2981. // The entire piece of code below is rather confusing because:
  2982. // - We handle absolute seeking (when first clicking outside the grab) and relative manipulation (afterward or when clicking inside the grab)
  2983. // - We store values as ratio and in a form that allows the window content to change while we are holding on a scrollbar
  2984. static void Scrollbar(ImGuiWindow* window)
  2985. {
  2986. ImGuiState& g = *GImGui;
  2987. const ImGuiStyle& style = g.Style;
  2988. const ImGuiID id = window->GetID("#SCROLLY");
  2989. // Render background
  2990. ImRect bb(window->Rect().Max.x - style.ScrollbarWidth, window->Pos.y + window->TitleBarHeight()+1, window->Rect().Max.x, window->Rect().Max.y-1);
  2991. window->DrawList->AddRectFilled(bb.Min, bb.Max, window->Color(ImGuiCol_ScrollbarBg));
  2992. bb.Expand(-3.0f);
  2993. const float scrollbar_height = bb.GetHeight();
  2994. // The grabable box size generally represent the amount visible (vs the total scrollable amount)
  2995. // But we maintain a minimum size in pixel to allow for the user to still aim inside.
  2996. const float grab_h_pixels = ImMax(style.GrabMinSize, scrollbar_height * ImSaturate(window->Size.y / ImMax(window->SizeContents.y, window->Size.y)));
  2997. const float grab_h_norm = grab_h_pixels / scrollbar_height;
  2998. // Handle input right away. None of the code of Begin() is relying on scrolling position before calling Scrollbar().
  2999. bool held = false;
  3000. bool hovered = false;
  3001. const bool previously_held = (g.ActiveId == id);
  3002. ButtonBehavior(bb, id, &hovered, &held, true);
  3003. const float scroll_max = ImMax(1.0f, window->SizeContents.y - window->Size.y);
  3004. float scroll_ratio = ImSaturate(window->ScrollY / scroll_max);
  3005. float grab_y_norm = scroll_ratio * (scrollbar_height - grab_h_pixels) / scrollbar_height;
  3006. if (held)
  3007. {
  3008. const float clicked_y_norm = ImSaturate((g.IO.MousePos.y - bb.Min.y) / scrollbar_height); // Click position in scrollbar space (0.0f->1.0f)
  3009. g.HoveredId = id;
  3010. bool seek_absolute = false;
  3011. if (!previously_held)
  3012. {
  3013. // On initial click calculate the distance between mouse and the center of the grab
  3014. if (clicked_y_norm >= grab_y_norm && clicked_y_norm <= grab_y_norm + grab_h_norm)
  3015. {
  3016. g.ScrollbarClickDeltaToGrabCenter = clicked_y_norm - grab_y_norm - grab_h_norm*0.5f;
  3017. }
  3018. else
  3019. {
  3020. seek_absolute = true;
  3021. g.ScrollbarClickDeltaToGrabCenter = 0;
  3022. }
  3023. }
  3024. // Apply scroll
  3025. const float scroll_y_norm = ImSaturate((clicked_y_norm - g.ScrollbarClickDeltaToGrabCenter - grab_h_norm*0.5f) / (1.0f - grab_h_norm));
  3026. window->ScrollY = (float)(int)(0.5f + scroll_y_norm * (window->SizeContents.y - window->Size.y));
  3027. window->NextScrollY = window->ScrollY;
  3028. // Update values for rendering
  3029. scroll_ratio = ImSaturate(window->ScrollY / scroll_max);
  3030. grab_y_norm = scroll_ratio * (scrollbar_height - grab_h_pixels) / scrollbar_height;
  3031. // Update distance to grab now that we have seeked and saturated
  3032. if (seek_absolute)
  3033. g.ScrollbarClickDeltaToGrabCenter = clicked_y_norm - grab_y_norm - grab_h_norm*0.5f;
  3034. }
  3035. // Render
  3036. const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab);
  3037. window->DrawList->AddRectFilled(ImVec2(bb.Min.x, ImLerp(bb.Min.y, bb.Max.y, grab_y_norm)), ImVec2(bb.Max.x, ImLerp(bb.Min.y, bb.Max.y, grab_y_norm) + grab_h_pixels), grab_col);
  3038. }
  3039. // Moving window to front of display (which happens to be back of our sorted list)
  3040. static void FocusWindow(ImGuiWindow* window)
  3041. {
  3042. ImGuiState& g = *GImGui;
  3043. // Always mark the window we passed as focused. This is used for keyboard interactions such as tabbing.
  3044. g.FocusedWindow = window;
  3045. // And move its root window to the top of the pile
  3046. if (window->RootWindow)
  3047. window = window->RootWindow;
  3048. if (g.Windows.back() == window)
  3049. return;
  3050. for (size_t i = 0; i < g.Windows.size(); i++)
  3051. if (g.Windows[i] == window)
  3052. {
  3053. g.Windows.erase(g.Windows.begin() + i);
  3054. break;
  3055. }
  3056. g.Windows.push_back(window);
  3057. }
  3058. void ImGui::PushItemWidth(float item_width)
  3059. {
  3060. ImGuiWindow* window = GetCurrentWindow();
  3061. window->DC.ItemWidth.push_back(item_width == 0.0f ? window->ItemWidthDefault : item_width);
  3062. }
  3063. void ImGui::PopItemWidth()
  3064. {
  3065. ImGuiWindow* window = GetCurrentWindow();
  3066. window->DC.ItemWidth.pop_back();
  3067. }
  3068. float ImGui::CalcItemWidth()
  3069. {
  3070. ImGuiWindow* window = GetCurrentWindow();
  3071. float w = window->DC.ItemWidth.back();
  3072. if (w < 0.0f)
  3073. {
  3074. // Align to a right-side limit. We include 1 frame padding in the calculation because this is how the width is always used (we add 2 frame padding to it), but we could move that responsibility to the widget as well.
  3075. ImGuiState& g = *GImGui;
  3076. w = -w;
  3077. float width_to_right_edge = window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x;
  3078. w = ImMax(1.0f, width_to_right_edge - w - g.Style.FramePadding.x * 2.0f);
  3079. }
  3080. w = (float)(int)w;
  3081. return w;
  3082. }
  3083. static void SetFont(ImFont* font)
  3084. {
  3085. ImGuiState& g = *GImGui;
  3086. IM_ASSERT(font && font->IsLoaded());
  3087. IM_ASSERT(font->Scale > 0.0f);
  3088. g.Font = font;
  3089. g.FontSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale;
  3090. g.FontTexUvWhitePixel = g.Font->ContainerAtlas->TexUvWhitePixel;
  3091. }
  3092. void ImGui::PushFont(ImFont* font)
  3093. {
  3094. ImGuiState& g = *GImGui;
  3095. if (!font)
  3096. font = g.IO.Fonts->Fonts[0];
  3097. SetFont(font);
  3098. g.FontStack.push_back(font);
  3099. g.CurrentWindow->DrawList->PushTextureID(font->ContainerAtlas->TexID);
  3100. }
  3101. void ImGui::PopFont()
  3102. {
  3103. ImGuiState& g = *GImGui;
  3104. g.CurrentWindow->DrawList->PopTextureID();
  3105. g.FontStack.pop_back();
  3106. SetFont(g.FontStack.empty() ? g.IO.Fonts->Fonts[0] : g.FontStack.back());
  3107. }
  3108. void ImGui::PushAllowKeyboardFocus(bool allow_keyboard_focus)
  3109. {
  3110. ImGuiWindow* window = GetCurrentWindow();
  3111. window->DC.AllowKeyboardFocus.push_back(allow_keyboard_focus);
  3112. }
  3113. void ImGui::PopAllowKeyboardFocus()
  3114. {
  3115. ImGuiWindow* window = GetCurrentWindow();
  3116. window->DC.AllowKeyboardFocus.pop_back();
  3117. }
  3118. void ImGui::PushTextWrapPos(float wrap_x)
  3119. {
  3120. ImGuiWindow* window = GetCurrentWindow();
  3121. window->DC.TextWrapPos.push_back(wrap_x);
  3122. }
  3123. void ImGui::PopTextWrapPos()
  3124. {
  3125. ImGuiWindow* window = GetCurrentWindow();
  3126. window->DC.TextWrapPos.pop_back();
  3127. }
  3128. void ImGui::PushStyleColor(ImGuiCol idx, const ImVec4& col)
  3129. {
  3130. ImGuiState& g = *GImGui;
  3131. ImGuiColMod backup;
  3132. backup.Col = idx;
  3133. backup.PreviousValue = g.Style.Colors[idx];
  3134. g.ColorModifiers.push_back(backup);
  3135. g.Style.Colors[idx] = col;
  3136. }
  3137. void ImGui::PopStyleColor(int count)
  3138. {
  3139. ImGuiState& g = *GImGui;
  3140. while (count > 0)
  3141. {
  3142. ImGuiColMod& backup = g.ColorModifiers.back();
  3143. g.Style.Colors[backup.Col] = backup.PreviousValue;
  3144. g.ColorModifiers.pop_back();
  3145. count--;
  3146. }
  3147. }
  3148. static float* GetStyleVarFloatAddr(ImGuiStyleVar idx)
  3149. {
  3150. ImGuiState& g = *GImGui;
  3151. switch (idx)
  3152. {
  3153. case ImGuiStyleVar_Alpha: return &g.Style.Alpha;
  3154. case ImGuiStyleVar_WindowRounding: return &g.Style.WindowRounding;
  3155. case ImGuiStyleVar_ChildWindowRounding: return &g.Style.ChildWindowRounding;
  3156. case ImGuiStyleVar_FrameRounding: return &g.Style.FrameRounding;
  3157. case ImGuiStyleVar_IndentSpacing: return &g.Style.IndentSpacing;
  3158. case ImGuiStyleVar_GrabMinSize: return &g.Style.GrabMinSize;
  3159. }
  3160. return NULL;
  3161. }
  3162. static ImVec2* GetStyleVarVec2Addr(ImGuiStyleVar idx)
  3163. {
  3164. ImGuiState& g = *GImGui;
  3165. switch (idx)
  3166. {
  3167. case ImGuiStyleVar_WindowPadding: return &g.Style.WindowPadding;
  3168. case ImGuiStyleVar_FramePadding: return &g.Style.FramePadding;
  3169. case ImGuiStyleVar_ItemSpacing: return &g.Style.ItemSpacing;
  3170. case ImGuiStyleVar_ItemInnerSpacing: return &g.Style.ItemInnerSpacing;
  3171. }
  3172. return NULL;
  3173. }
  3174. void ImGui::PushStyleVar(ImGuiStyleVar idx, float val)
  3175. {
  3176. ImGuiState& g = *GImGui;
  3177. float* pvar = GetStyleVarFloatAddr(idx);
  3178. IM_ASSERT(pvar != NULL); // Called function with wrong-type? Variable is not a float.
  3179. ImGuiStyleMod backup;
  3180. backup.Var = idx;
  3181. backup.PreviousValue = ImVec2(*pvar, 0.0f);
  3182. g.StyleModifiers.push_back(backup);
  3183. *pvar = val;
  3184. }
  3185. void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
  3186. {
  3187. ImGuiState& g = *GImGui;
  3188. ImVec2* pvar = GetStyleVarVec2Addr(idx);
  3189. IM_ASSERT(pvar != NULL); // Called function with wrong-type? Variable is not a ImVec2.
  3190. ImGuiStyleMod backup;
  3191. backup.Var = idx;
  3192. backup.PreviousValue = *pvar;
  3193. g.StyleModifiers.push_back(backup);
  3194. *pvar = val;
  3195. }
  3196. void ImGui::PopStyleVar(int count)
  3197. {
  3198. ImGuiState& g = *GImGui;
  3199. while (count > 0)
  3200. {
  3201. ImGuiStyleMod& backup = g.StyleModifiers.back();
  3202. if (float* pvar_f = GetStyleVarFloatAddr(backup.Var))
  3203. *pvar_f = backup.PreviousValue.x;
  3204. else if (ImVec2* pvar_v = GetStyleVarVec2Addr(backup.Var))
  3205. *pvar_v = backup.PreviousValue;
  3206. g.StyleModifiers.pop_back();
  3207. count--;
  3208. }
  3209. }
  3210. const char* ImGui::GetStyleColName(ImGuiCol idx)
  3211. {
  3212. // Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1";
  3213. switch (idx)
  3214. {
  3215. case ImGuiCol_Text: return "Text";
  3216. case ImGuiCol_WindowBg: return "WindowBg";
  3217. case ImGuiCol_ChildWindowBg: return "ChildWindowBg";
  3218. case ImGuiCol_Border: return "Border";
  3219. case ImGuiCol_BorderShadow: return "BorderShadow";
  3220. case ImGuiCol_FrameBg: return "FrameBg";
  3221. case ImGuiCol_TitleBg: return "TitleBg";
  3222. case ImGuiCol_TitleBgCollapsed: return "TitleBgCollapsed";
  3223. case ImGuiCol_ScrollbarBg: return "ScrollbarBg";
  3224. case ImGuiCol_ScrollbarGrab: return "ScrollbarGrab";
  3225. case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered";
  3226. case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive";
  3227. case ImGuiCol_ComboBg: return "ComboBg";
  3228. case ImGuiCol_CheckHovered: return "CheckHovered";
  3229. case ImGuiCol_CheckActive: return "CheckActive";
  3230. case ImGuiCol_CheckMark: return "CheckMark";
  3231. case ImGuiCol_SliderGrab: return "SliderGrab";
  3232. case ImGuiCol_SliderGrabActive: return "SliderGrabActive";
  3233. case ImGuiCol_Button: return "Button";
  3234. case ImGuiCol_ButtonHovered: return "ButtonHovered";
  3235. case ImGuiCol_ButtonActive: return "ButtonActive";
  3236. case ImGuiCol_Header: return "Header";
  3237. case ImGuiCol_HeaderHovered: return "HeaderHovered";
  3238. case ImGuiCol_HeaderActive: return "HeaderActive";
  3239. case ImGuiCol_Column: return "Column";
  3240. case ImGuiCol_ColumnHovered: return "ColumnHovered";
  3241. case ImGuiCol_ColumnActive: return "ColumnActive";
  3242. case ImGuiCol_ResizeGrip: return "ResizeGrip";
  3243. case ImGuiCol_ResizeGripHovered: return "ResizeGripHovered";
  3244. case ImGuiCol_ResizeGripActive: return "ResizeGripActive";
  3245. case ImGuiCol_CloseButton: return "CloseButton";
  3246. case ImGuiCol_CloseButtonHovered: return "CloseButtonHovered";
  3247. case ImGuiCol_CloseButtonActive: return "CloseButtonActive";
  3248. case ImGuiCol_PlotLines: return "PlotLines";
  3249. case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered";
  3250. case ImGuiCol_PlotHistogram: return "PlotHistogram";
  3251. case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered";
  3252. case ImGuiCol_TextSelectedBg: return "TextSelectedBg";
  3253. case ImGuiCol_TooltipBg: return "TooltipBg";
  3254. }
  3255. IM_ASSERT(0);
  3256. return "Unknown";
  3257. }
  3258. bool ImGui::IsWindowFocused()
  3259. {
  3260. ImGuiState& g = *GImGui;
  3261. ImGuiWindow* window = GetCurrentWindow();
  3262. return g.FocusedWindow == window;
  3263. }
  3264. bool ImGui::IsRootWindowFocused()
  3265. {
  3266. ImGuiState& g = *GImGui;
  3267. ImGuiWindow* root_window = GetCurrentWindow()->RootWindow;
  3268. return g.FocusedWindow == root_window;
  3269. }
  3270. bool ImGui::IsRootWindowOrAnyChildFocused()
  3271. {
  3272. ImGuiState& g = *GImGui;
  3273. ImGuiWindow* root_window = GetCurrentWindow()->RootWindow;
  3274. return g.FocusedWindow->RootWindow == root_window;
  3275. }
  3276. float ImGui::GetWindowWidth()
  3277. {
  3278. ImGuiWindow* window = GetCurrentWindow();
  3279. return window->Size.x;
  3280. }
  3281. ImVec2 ImGui::GetWindowPos()
  3282. {
  3283. ImGuiWindow* window = GetCurrentWindow();
  3284. return window->Pos;
  3285. }
  3286. static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiSetCond cond)
  3287. {
  3288. // Test condition (NB: bit 0 is always true) and clear flags for next time
  3289. if (cond && (window->SetWindowPosAllowFlags & cond) == 0)
  3290. return;
  3291. window->SetWindowPosAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver);
  3292. // Set
  3293. const ImVec2 old_pos = window->Pos;
  3294. window->PosFloat = pos;
  3295. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  3296. window->DC.CursorPos += (window->Pos - old_pos); // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor
  3297. window->DC.CursorMaxPos += (window->Pos - old_pos); // And more importantly we need to adjust this so size calculation doesn't get affected.
  3298. }
  3299. void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCond cond)
  3300. {
  3301. ImGuiWindow* window = GetCurrentWindow();
  3302. SetWindowPos(window, pos, cond);
  3303. }
  3304. void ImGui::SetWindowPos(const char* name, const ImVec2& pos, ImGuiSetCond cond)
  3305. {
  3306. ImGuiWindow* window = FindWindowByName(name);
  3307. if (window)
  3308. SetWindowPos(window, pos, cond);
  3309. }
  3310. ImVec2 ImGui::GetWindowSize()
  3311. {
  3312. ImGuiWindow* window = GetCurrentWindow();
  3313. return window->Size;
  3314. }
  3315. static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiSetCond cond)
  3316. {
  3317. // Test condition (NB: bit 0 is always true) and clear flags for next time
  3318. if (cond && (window->SetWindowSizeAllowFlags & cond) == 0)
  3319. return;
  3320. window->SetWindowSizeAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver);
  3321. // Set
  3322. if (ImLengthSqr(size) > 0.00001f)
  3323. {
  3324. window->SizeFull = size;
  3325. window->AutoFitFrames = 0;
  3326. }
  3327. else
  3328. {
  3329. // Autofit
  3330. window->AutoFitFrames = 2;
  3331. window->AutoFitOnlyGrows = false;
  3332. }
  3333. }
  3334. void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCond cond)
  3335. {
  3336. ImGuiWindow* window = GetCurrentWindow();
  3337. SetWindowSize(window, size, cond);
  3338. }
  3339. void ImGui::SetWindowSize(const char* name, const ImVec2& size, ImGuiSetCond cond)
  3340. {
  3341. ImGuiWindow* window = FindWindowByName(name);
  3342. if (window)
  3343. SetWindowSize(window, size, cond);
  3344. }
  3345. static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiSetCond cond)
  3346. {
  3347. // Test condition (NB: bit 0 is always true) and clear flags for next time
  3348. if (cond && (window->SetWindowCollapsedAllowFlags & cond) == 0)
  3349. return;
  3350. window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver);
  3351. // Set
  3352. window->Collapsed = collapsed;
  3353. }
  3354. void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCond cond)
  3355. {
  3356. ImGuiWindow* window = GetCurrentWindow();
  3357. SetWindowCollapsed(window, collapsed, cond);
  3358. }
  3359. bool ImGui::GetWindowCollapsed()
  3360. {
  3361. ImGuiWindow* window = GetCurrentWindow();
  3362. return window->Collapsed;
  3363. }
  3364. void ImGui::SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCond cond)
  3365. {
  3366. ImGuiWindow* window = FindWindowByName(name);
  3367. if (window)
  3368. SetWindowCollapsed(window, collapsed, cond);
  3369. }
  3370. void ImGui::SetWindowFocus()
  3371. {
  3372. ImGuiWindow* window = GetCurrentWindow();
  3373. FocusWindow(window);
  3374. }
  3375. void ImGui::SetWindowFocus(const char* name)
  3376. {
  3377. ImGuiWindow* window = FindWindowByName(name);
  3378. if (window)
  3379. FocusWindow(window);
  3380. }
  3381. void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond)
  3382. {
  3383. ImGuiState& g = *GImGui;
  3384. g.SetNextWindowPosVal = pos;
  3385. g.SetNextWindowPosCond = cond ? cond : ImGuiSetCond_Always;
  3386. }
  3387. void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond)
  3388. {
  3389. ImGuiState& g = *GImGui;
  3390. g.SetNextWindowSizeVal = size;
  3391. g.SetNextWindowSizeCond = cond ? cond : ImGuiSetCond_Always;
  3392. }
  3393. void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond)
  3394. {
  3395. ImGuiState& g = *GImGui;
  3396. g.SetNextWindowCollapsedVal = collapsed;
  3397. g.SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCond_Always;
  3398. }
  3399. void ImGui::SetNextWindowFocus()
  3400. {
  3401. ImGuiState& g = *GImGui;
  3402. g.SetNextWindowFocus = true;
  3403. }
  3404. ImVec2 ImGui::GetContentRegionMax()
  3405. {
  3406. ImGuiWindow* window = GetCurrentWindow();
  3407. ImVec2 window_padding = window->WindowPadding();
  3408. ImVec2 mx = window->Size - window_padding;
  3409. if (window->DC.ColumnsCount != 1)
  3410. {
  3411. mx.x = ImGui::GetColumnOffset(window->DC.ColumnsCurrent + 1);
  3412. mx.x -= window_padding.x;
  3413. }
  3414. else
  3415. {
  3416. if (window->ScrollbarY)
  3417. mx.x -= GImGui->Style.ScrollbarWidth;
  3418. }
  3419. return mx;
  3420. }
  3421. ImVec2 ImGui::GetWindowContentRegionMin()
  3422. {
  3423. ImGuiWindow* window = GetCurrentWindow();
  3424. return ImVec2(0, window->TitleBarHeight()) + window->WindowPadding();
  3425. }
  3426. ImVec2 ImGui::GetWindowContentRegionMax()
  3427. {
  3428. ImGuiWindow* window = GetCurrentWindow();
  3429. ImVec2 m = window->Size - window->WindowPadding();
  3430. if (window->ScrollbarY)
  3431. m.x -= GImGui->Style.ScrollbarWidth;
  3432. return m;
  3433. }
  3434. float ImGui::GetTextLineHeight()
  3435. {
  3436. ImGuiWindow* window = GetCurrentWindow();
  3437. return window->FontSize();
  3438. }
  3439. float ImGui::GetTextLineHeightWithSpacing()
  3440. {
  3441. ImGuiState& g = *GImGui;
  3442. ImGuiWindow* window = GetCurrentWindow();
  3443. return window->FontSize() + g.Style.ItemSpacing.y;
  3444. }
  3445. ImDrawList* ImGui::GetWindowDrawList()
  3446. {
  3447. ImGuiWindow* window = GetCurrentWindow();
  3448. return window->DrawList;
  3449. }
  3450. ImFont* ImGui::GetWindowFont()
  3451. {
  3452. ImGuiWindow* window = GetCurrentWindow();
  3453. return window->Font();
  3454. }
  3455. float ImGui::GetWindowFontSize()
  3456. {
  3457. ImGuiWindow* window = GetCurrentWindow();
  3458. return window->FontSize();
  3459. }
  3460. void ImGui::SetWindowFontScale(float scale)
  3461. {
  3462. ImGuiWindow* window = GetCurrentWindow();
  3463. window->FontWindowScale = scale;
  3464. }
  3465. // NB: internally we store CursorPos in absolute screen coordinates because it is more convenient.
  3466. // Conversion happens as we pass the value to user, but it makes our naming convention dodgy. May want to rename 'DC.CursorPos'.
  3467. ImVec2 ImGui::GetCursorPos()
  3468. {
  3469. ImGuiWindow* window = GetCurrentWindow();
  3470. return window->DC.CursorPos - window->Pos;
  3471. }
  3472. float ImGui::GetCursorPosX()
  3473. {
  3474. return ImGui::GetCursorPos().x;
  3475. }
  3476. float ImGui::GetCursorPosY()
  3477. {
  3478. return ImGui::GetCursorPos().y;
  3479. }
  3480. void ImGui::SetCursorPos(const ImVec2& pos)
  3481. {
  3482. ImGuiWindow* window = GetCurrentWindow();
  3483. window->DC.CursorPos = window->Pos + pos;
  3484. window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos);
  3485. }
  3486. void ImGui::SetCursorPosX(float x)
  3487. {
  3488. ImGuiWindow* window = GetCurrentWindow();
  3489. window->DC.CursorPos.x = window->Pos.x + x;
  3490. window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPos.x);
  3491. }
  3492. void ImGui::SetCursorPosY(float y)
  3493. {
  3494. ImGuiWindow* window = GetCurrentWindow();
  3495. window->DC.CursorPos.y = window->Pos.y + y;
  3496. window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y);
  3497. }
  3498. ImVec2 ImGui::GetCursorScreenPos()
  3499. {
  3500. ImGuiWindow* window = GetCurrentWindow();
  3501. return window->DC.CursorPos;
  3502. }
  3503. void ImGui::SetCursorScreenPos(const ImVec2& screen_pos)
  3504. {
  3505. ImGuiWindow* window = GetCurrentWindow();
  3506. window->DC.CursorPos = screen_pos;
  3507. }
  3508. float ImGui::GetScrollPosY()
  3509. {
  3510. ImGuiWindow* window = GetCurrentWindow();
  3511. return window->ScrollY;
  3512. }
  3513. float ImGui::GetScrollMaxY()
  3514. {
  3515. ImGuiWindow* window = GetCurrentWindow();
  3516. return window->SizeContents.y - window->SizeFull.y;
  3517. }
  3518. void ImGui::SetScrollPosHere()
  3519. {
  3520. ImGuiWindow* window = GetCurrentWindow();
  3521. window->NextScrollY = (window->DC.CursorPos.y + window->ScrollY) - (window->Pos.y + window->SizeFull.y * 0.5f) - (window->TitleBarHeight() + window->WindowPadding().y);
  3522. }
  3523. void ImGui::SetKeyboardFocusHere(int offset)
  3524. {
  3525. ImGuiWindow* window = GetCurrentWindow();
  3526. window->FocusIdxAllRequestNext = window->FocusIdxAllCounter + 1 + offset;
  3527. window->FocusIdxTabRequestNext = IM_INT_MAX;
  3528. }
  3529. void ImGui::SetStateStorage(ImGuiStorage* tree)
  3530. {
  3531. ImGuiWindow* window = GetCurrentWindow();
  3532. window->DC.StateStorage = tree ? tree : &window->StateStorage;
  3533. }
  3534. ImGuiStorage* ImGui::GetStateStorage()
  3535. {
  3536. ImGuiWindow* window = GetCurrentWindow();
  3537. return window->DC.StateStorage;
  3538. }
  3539. void ImGui::TextV(const char* fmt, va_list args)
  3540. {
  3541. ImGuiState& g = *GImGui;
  3542. ImGuiWindow* window = GetCurrentWindow();
  3543. if (window->SkipItems)
  3544. return;
  3545. const char* text_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  3546. TextUnformatted(g.TempBuffer, text_end);
  3547. }
  3548. void ImGui::Text(const char* fmt, ...)
  3549. {
  3550. va_list args;
  3551. va_start(args, fmt);
  3552. TextV(fmt, args);
  3553. va_end(args);
  3554. }
  3555. void ImGui::TextColoredV(const ImVec4& col, const char* fmt, va_list args)
  3556. {
  3557. ImGui::PushStyleColor(ImGuiCol_Text, col);
  3558. TextV(fmt, args);
  3559. ImGui::PopStyleColor();
  3560. }
  3561. void ImGui::TextColored(const ImVec4& col, const char* fmt, ...)
  3562. {
  3563. va_list args;
  3564. va_start(args, fmt);
  3565. TextColoredV(col, fmt, args);
  3566. va_end(args);
  3567. }
  3568. void ImGui::TextWrappedV(const char* fmt, va_list args)
  3569. {
  3570. ImGui::PushTextWrapPos(0.0f);
  3571. TextV(fmt, args);
  3572. ImGui::PopTextWrapPos();
  3573. }
  3574. void ImGui::TextWrapped(const char* fmt, ...)
  3575. {
  3576. va_list args;
  3577. va_start(args, fmt);
  3578. TextWrappedV(fmt, args);
  3579. va_end(args);
  3580. }
  3581. void ImGui::TextUnformatted(const char* text, const char* text_end)
  3582. {
  3583. ImGuiState& g = *GImGui;
  3584. ImGuiWindow* window = GetCurrentWindow();
  3585. if (window->SkipItems)
  3586. return;
  3587. IM_ASSERT(text != NULL);
  3588. const char* text_begin = text;
  3589. if (text_end == NULL)
  3590. text_end = text + strlen(text); // FIXME-OPT
  3591. const float wrap_pos_x = window->DC.TextWrapPos.back();
  3592. const bool wrap_enabled = wrap_pos_x >= 0.0f;
  3593. if (text_end - text > 2000 && !wrap_enabled)
  3594. {
  3595. // Long text!
  3596. // Perform manual coarse clipping to optimize for long multi-line text
  3597. // From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled.
  3598. // We also don't vertically center the text within the line full height, which is unlikely to matter because we are likely the biggest and only item on the line.
  3599. const char* line = text;
  3600. const float line_height = ImGui::GetTextLineHeight();
  3601. const ImVec2 text_pos = window->DC.CursorPos + ImVec2(0.0f, window->DC.CurrentLineTextBaseOffset);
  3602. const ImVec4 clip_rect = window->ClipRectStack.back();
  3603. ImVec2 text_size(0,0);
  3604. if (text_pos.y <= clip_rect.w)
  3605. {
  3606. ImVec2 pos = text_pos;
  3607. // Lines to skip (can't skip when logging text)
  3608. if (!g.LogEnabled)
  3609. {
  3610. int lines_skippable = (int)((clip_rect.y - text_pos.y) / line_height) - 1;
  3611. if (lines_skippable > 0)
  3612. {
  3613. int lines_skipped = 0;
  3614. while (line < text_end && lines_skipped <= lines_skippable)
  3615. {
  3616. const char* line_end = strchr(line, '\n');
  3617. line = line_end + 1;
  3618. lines_skipped++;
  3619. }
  3620. pos.y += lines_skipped * line_height;
  3621. }
  3622. }
  3623. // Lines to render
  3624. if (line < text_end)
  3625. {
  3626. ImRect line_rect(pos, pos + ImVec2(ImGui::GetWindowWidth(), line_height));
  3627. while (line < text_end)
  3628. {
  3629. const char* line_end = strchr(line, '\n');
  3630. if (IsClipped(line_rect))
  3631. break;
  3632. const ImVec2 line_size = CalcTextSize(line, line_end, false);
  3633. text_size.x = ImMax(text_size.x, line_size.x);
  3634. RenderText(pos, line, line_end, false);
  3635. if (!line_end)
  3636. line_end = text_end;
  3637. line = line_end + 1;
  3638. line_rect.Min.y += line_height;
  3639. line_rect.Max.y += line_height;
  3640. pos.y += line_height;
  3641. }
  3642. // Count remaining lines
  3643. int lines_skipped = 0;
  3644. while (line < text_end)
  3645. {
  3646. const char* line_end = strchr(line, '\n');
  3647. if (!line_end)
  3648. line_end = text_end;
  3649. line = line_end + 1;
  3650. lines_skipped++;
  3651. }
  3652. pos.y += lines_skipped * line_height;
  3653. }
  3654. text_size.y += (pos - text_pos).y;
  3655. }
  3656. ImRect bb(text_pos, text_pos + text_size);
  3657. ItemSize(bb);
  3658. ItemAdd(bb, NULL);
  3659. }
  3660. else
  3661. {
  3662. const float wrap_width = wrap_enabled ? CalcWrapWidthForPos(window->DC.CursorPos, wrap_pos_x) : 0.0f;
  3663. const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width);
  3664. // Account of baseline offset
  3665. ImVec2 text_pos = window->DC.CursorPos;
  3666. text_pos.y += window->DC.CurrentLineTextBaseOffset;
  3667. ImRect bb(text_pos, text_pos + text_size);
  3668. ItemSize(bb.GetSize());
  3669. if (!ItemAdd(bb, NULL))
  3670. return;
  3671. // Render (we don't hide text after ## in this end-user function)
  3672. RenderTextWrapped(bb.Min, text_begin, text_end, wrap_width);
  3673. }
  3674. }
  3675. void ImGui::AlignFirstTextHeightToWidgets()
  3676. {
  3677. ImGuiState& g = *GImGui;
  3678. ImGuiWindow* window = GetCurrentWindow();
  3679. if (window->SkipItems)
  3680. return;
  3681. // Declare a dummy item size to that upcoming items that are smaller will center-align on the newly expanded line height.
  3682. ItemSize(ImVec2(0, window->FontSize() + g.Style.FramePadding.y*2), g.Style.FramePadding.y);
  3683. ImGui::SameLine(0, 0);
  3684. }
  3685. // Add a label+text combo aligned to other label+value widgets
  3686. void ImGui::LabelTextV(const char* label, const char* fmt, va_list args)
  3687. {
  3688. ImGuiState& g = *GImGui;
  3689. ImGuiWindow* window = GetCurrentWindow();
  3690. if (window->SkipItems)
  3691. return;
  3692. const ImGuiStyle& style = g.Style;
  3693. const float w = ImGui::CalcItemWidth();
  3694. const char* value_text_begin = &g.TempBuffer[0];
  3695. const char* value_text_end = value_text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  3696. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  3697. const ImRect value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, label_size.y + style.FramePadding.y*2));
  3698. const ImRect total_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + (label_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), style.FramePadding.y*2) + label_size);
  3699. ItemSize(total_bb, style.FramePadding.y);
  3700. if (!ItemAdd(total_bb, NULL))
  3701. return;
  3702. // Render
  3703. RenderTextClipped(ImVec2(value_bb.Min.x, value_bb.Min.y + style.FramePadding.y), value_text_begin, value_text_end, NULL, value_bb.Max);
  3704. RenderText(ImVec2(value_bb.Max.x + style.ItemInnerSpacing.x, value_bb.Min.y + style.FramePadding.y), label);
  3705. }
  3706. void ImGui::LabelText(const char* label, const char* fmt, ...)
  3707. {
  3708. va_list args;
  3709. va_start(args, fmt);
  3710. LabelTextV(label, fmt, args);
  3711. va_end(args);
  3712. }
  3713. static inline bool IsWindowContentHoverable(ImGuiWindow* window)
  3714. {
  3715. ImGuiState& g = *GImGui;
  3716. ImGuiWindow* focused_window = g.FocusedWindow;
  3717. if (focused_window && (focused_window->Flags & ImGuiWindowFlags_Popup) != 0 && focused_window->WasVisible && focused_window != window)
  3718. return false;
  3719. return true;
  3720. }
  3721. static bool IsHovered(const ImRect& bb, ImGuiID id)
  3722. {
  3723. ImGuiState& g = *GImGui;
  3724. if (g.HoveredId == 0)
  3725. {
  3726. ImGuiWindow* window = GetCurrentWindow();
  3727. if (g.HoveredRootWindow == window->RootWindow)
  3728. {
  3729. if ((g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdIsFocusedOnly) && IsMouseHoveringRect(bb))
  3730. if (IsWindowContentHoverable(g.HoveredRootWindow))
  3731. return true;
  3732. }
  3733. }
  3734. return false;
  3735. }
  3736. static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat, bool pressed_on_click)
  3737. {
  3738. ImGuiState& g = *GImGui;
  3739. ImGuiWindow* window = GetCurrentWindow();
  3740. const bool hovered = IsHovered(bb, id);
  3741. bool pressed = false;
  3742. if (hovered)
  3743. {
  3744. g.HoveredId = id;
  3745. if (allow_key_modifiers || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt))
  3746. {
  3747. if (g.IO.MouseClicked[0])
  3748. {
  3749. if (pressed_on_click)
  3750. {
  3751. pressed = true;
  3752. SetActiveId(0);
  3753. }
  3754. else
  3755. {
  3756. SetActiveId(id);
  3757. }
  3758. FocusWindow(window);
  3759. }
  3760. else if (repeat && g.ActiveId && ImGui::IsMouseClicked(0, true))
  3761. {
  3762. pressed = true;
  3763. }
  3764. }
  3765. }
  3766. bool held = false;
  3767. if (g.ActiveId == id)
  3768. {
  3769. if (g.IO.MouseDown[0])
  3770. {
  3771. held = true;
  3772. }
  3773. else
  3774. {
  3775. if (hovered)
  3776. pressed = true;
  3777. SetActiveId(0);
  3778. }
  3779. }
  3780. if (out_hovered) *out_hovered = hovered;
  3781. if (out_held) *out_held = held;
  3782. return pressed;
  3783. }
  3784. bool ImGui::Button(const char* label, const ImVec2& size_arg, bool repeat_when_held)
  3785. {
  3786. ImGuiState& g = *GImGui;
  3787. ImGuiWindow* window = GetCurrentWindow();
  3788. if (window->SkipItems)
  3789. return false;
  3790. const ImGuiStyle& style = g.Style;
  3791. const ImGuiID id = window->GetID(label);
  3792. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  3793. const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : (label_size.x + style.FramePadding.x*2), size_arg.y != 0.0f ? size_arg.y : (label_size.y + style.FramePadding.y*2));
  3794. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
  3795. ItemSize(bb, style.FramePadding.y);
  3796. if (!ItemAdd(bb, &id))
  3797. return false;
  3798. bool hovered, held;
  3799. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true, repeat_when_held);
  3800. // Render
  3801. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  3802. RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
  3803. const ImVec2 off = ImVec2(ImMax(0.0f, size.x - label_size.x) * 0.5f, ImMax(0.0f, size.y - label_size.y) * 0.5f); // Center (only applies if we explicitly gave a size bigger than the text size, which isn't the common path)
  3804. RenderTextClipped(bb.Min + off, label, NULL, &label_size, bb.Max); // Render clip (only applies if we explicitly gave a size smaller than the text size, which isn't the commmon path)
  3805. return pressed;
  3806. }
  3807. // Small buttons fits within text without additional spacing.
  3808. bool ImGui::SmallButton(const char* label)
  3809. {
  3810. ImGuiState& g = *GImGui;
  3811. ImGuiWindow* window = GetCurrentWindow();
  3812. if (window->SkipItems)
  3813. return false;
  3814. const ImGuiStyle& style = g.Style;
  3815. const ImGuiID id = window->GetID(label);
  3816. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  3817. ImVec2 text_pos = window->DC.CursorPos;
  3818. text_pos.y += window->DC.CurrentLineTextBaseOffset;
  3819. ImRect bb(text_pos, text_pos + label_size + ImVec2(style.FramePadding.x*2,0));
  3820. ItemSize(bb);
  3821. if (!ItemAdd(bb, &id))
  3822. return false;
  3823. bool hovered, held;
  3824. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  3825. // Render
  3826. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  3827. RenderFrame(bb.Min, bb.Max, col);
  3828. RenderText(bb.Min + ImVec2(style.FramePadding.x,0), label);
  3829. return pressed;
  3830. }
  3831. // Tip: use ImGui::PushID()/PopID() to push indices or pointers in the ID stack.
  3832. // Then you can keep 'str_id' empty or the same for all your buttons (instead of creating a string based on a non-string id)
  3833. bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size)
  3834. {
  3835. ImGuiWindow* window = GetCurrentWindow();
  3836. if (window->SkipItems)
  3837. return false;
  3838. const ImGuiID id = window->GetID(str_id);
  3839. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
  3840. ItemSize(bb);
  3841. if (!ItemAdd(bb, &id))
  3842. return false;
  3843. bool hovered, held;
  3844. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  3845. return pressed;
  3846. }
  3847. // Upper-right button to close a window.
  3848. static bool CloseWindowButton(bool* p_opened)
  3849. {
  3850. ImGuiWindow* window = GetCurrentWindow();
  3851. const ImGuiID id = window->GetID("#CLOSE");
  3852. const float size = window->TitleBarHeight() - 4.0f;
  3853. const ImRect bb(window->Rect().GetTR() + ImVec2(-3.0f-size,2.0f), window->Rect().GetTR() + ImVec2(-3.0f,2.0f+size));
  3854. bool hovered, held;
  3855. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  3856. // Render
  3857. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton);
  3858. const ImVec2 center = bb.GetCenter();
  3859. window->DrawList->AddCircleFilled(center, ImMax(2.0f,size*0.5f), col, 16);
  3860. const float cross_extent = (size * 0.5f * 0.7071f) - 1.0f;
  3861. if (hovered)
  3862. {
  3863. window->DrawList->AddLine(center + ImVec2(+cross_extent,+cross_extent), center + ImVec2(-cross_extent,-cross_extent), window->Color(ImGuiCol_Text));
  3864. window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), window->Color(ImGuiCol_Text));
  3865. }
  3866. if (p_opened != NULL && pressed)
  3867. *p_opened = !*p_opened;
  3868. return pressed;
  3869. }
  3870. void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col)
  3871. {
  3872. ImGuiWindow* window = GetCurrentWindow();
  3873. if (window->SkipItems)
  3874. return;
  3875. ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
  3876. if (border_col.w > 0.0f)
  3877. bb.Max += ImVec2(2,2);
  3878. ItemSize(bb);
  3879. if (!ItemAdd(bb, NULL))
  3880. return;
  3881. if (border_col.w > 0.0f)
  3882. {
  3883. window->DrawList->AddRect(bb.Min, bb.Max, window->Color(border_col), 0.0f);
  3884. window->DrawList->AddImage(user_texture_id, bb.Min+ImVec2(1,1), bb.Max-ImVec2(1,1), uv0, uv1, window->Color(tint_col));
  3885. }
  3886. else
  3887. {
  3888. window->DrawList->AddImage(user_texture_id, bb.Min, bb.Max, uv0, uv1, window->Color(tint_col));
  3889. }
  3890. }
  3891. // frame_padding < 0: uses FramePadding from style (default)
  3892. // frame_padding = 0: no framing
  3893. // frame_padding > 0: set framing size
  3894. // The color used are the button colors.
  3895. bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col)
  3896. {
  3897. ImGuiState& g = *GImGui;
  3898. ImGuiWindow* window = GetCurrentWindow();
  3899. if (window->SkipItems)
  3900. return false;
  3901. const ImGuiStyle& style = g.Style;
  3902. // Default to using texture ID as ID. User can still push string/integer prefixes.
  3903. // We could hash the size/uv to create a unique ID but that would prevent the user from animating buttons.
  3904. ImGui::PushID((void *)user_texture_id);
  3905. const ImGuiID id = window->GetID("#image");
  3906. ImGui::PopID();
  3907. const ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : style.FramePadding;
  3908. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding*2);
  3909. const ImRect image_bb(window->DC.CursorPos + padding, window->DC.CursorPos + padding + size);
  3910. ItemSize(bb);
  3911. if (!ItemAdd(bb, &id))
  3912. return false;
  3913. bool hovered, held;
  3914. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  3915. // Render
  3916. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  3917. if (padding.x > 0.0f || padding.y > 0.0f)
  3918. RenderFrame(bb.Min, bb.Max, col);
  3919. if (bg_col.w > 0.0f)
  3920. window->DrawList->AddRectFilled(image_bb.Min, image_bb.Max, window->Color(bg_col));
  3921. window->DrawList->AddImage(user_texture_id, image_bb.Min, image_bb.Max, uv0, uv1, window->Color(tint_col));
  3922. return pressed;
  3923. }
  3924. // Start logging ImGui output to TTY
  3925. void ImGui::LogToTTY(int max_depth)
  3926. {
  3927. ImGuiState& g = *GImGui;
  3928. ImGuiWindow* window = GetCurrentWindow();
  3929. if (g.LogEnabled)
  3930. return;
  3931. g.LogEnabled = true;
  3932. g.LogFile = stdout;
  3933. g.LogStartDepth = window->DC.TreeDepth;
  3934. if (max_depth >= 0)
  3935. g.LogAutoExpandMaxDepth = max_depth;
  3936. }
  3937. // Start logging ImGui output to given file
  3938. void ImGui::LogToFile(int max_depth, const char* filename)
  3939. {
  3940. ImGuiState& g = *GImGui;
  3941. ImGuiWindow* window = GetCurrentWindow();
  3942. if (g.LogEnabled)
  3943. return;
  3944. if (!filename)
  3945. {
  3946. filename = g.IO.LogFilename;
  3947. if (!filename)
  3948. return;
  3949. }
  3950. g.LogFile = fopen(filename, "ab");
  3951. if (!g.LogFile)
  3952. {
  3953. IM_ASSERT(g.LogFile != NULL); // Consider this an error
  3954. return;
  3955. }
  3956. g.LogEnabled = true;
  3957. g.LogStartDepth = window->DC.TreeDepth;
  3958. if (max_depth >= 0)
  3959. g.LogAutoExpandMaxDepth = max_depth;
  3960. }
  3961. // Start logging ImGui output to clipboard
  3962. void ImGui::LogToClipboard(int max_depth)
  3963. {
  3964. ImGuiWindow* window = GetCurrentWindow();
  3965. ImGuiState& g = *GImGui;
  3966. if (g.LogEnabled)
  3967. return;
  3968. g.LogEnabled = true;
  3969. g.LogFile = NULL;
  3970. g.LogStartDepth = window->DC.TreeDepth;
  3971. if (max_depth >= 0)
  3972. g.LogAutoExpandMaxDepth = max_depth;
  3973. }
  3974. void ImGui::LogFinish()
  3975. {
  3976. ImGuiState& g = *GImGui;
  3977. if (!g.LogEnabled)
  3978. return;
  3979. ImGui::LogText(STR_NEWLINE);
  3980. g.LogEnabled = false;
  3981. if (g.LogFile != NULL)
  3982. {
  3983. if (g.LogFile == stdout)
  3984. fflush(g.LogFile);
  3985. else
  3986. fclose(g.LogFile);
  3987. g.LogFile = NULL;
  3988. }
  3989. if (g.LogClipboard->size() > 1)
  3990. {
  3991. if (g.IO.SetClipboardTextFn)
  3992. g.IO.SetClipboardTextFn(g.LogClipboard->begin());
  3993. g.LogClipboard->clear();
  3994. }
  3995. }
  3996. // Helper to display logging buttons
  3997. void ImGui::LogButtons()
  3998. {
  3999. ImGuiState& g = *GImGui;
  4000. ImGui::PushID("LogButtons");
  4001. const bool log_to_tty = ImGui::Button("Log To TTY");
  4002. ImGui::SameLine();
  4003. const bool log_to_file = ImGui::Button("Log To File");
  4004. ImGui::SameLine();
  4005. const bool log_to_clipboard = ImGui::Button("Log To Clipboard");
  4006. ImGui::SameLine();
  4007. ImGui::PushItemWidth(80.0f);
  4008. ImGui::PushAllowKeyboardFocus(false);
  4009. ImGui::SliderInt("Depth", &g.LogAutoExpandMaxDepth, 0, 9, NULL);
  4010. ImGui::PopAllowKeyboardFocus();
  4011. ImGui::PopItemWidth();
  4012. ImGui::PopID();
  4013. // Start logging at the end of the function so that the buttons don't appear in the log
  4014. if (log_to_tty)
  4015. LogToTTY(g.LogAutoExpandMaxDepth);
  4016. if (log_to_file)
  4017. LogToFile(g.LogAutoExpandMaxDepth, g.IO.LogFilename);
  4018. if (log_to_clipboard)
  4019. LogToClipboard(g.LogAutoExpandMaxDepth);
  4020. }
  4021. bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display_frame, bool default_open)
  4022. {
  4023. ImGuiState& g = *GImGui;
  4024. ImGuiWindow* window = GetCurrentWindow();
  4025. if (window->SkipItems)
  4026. return false;
  4027. const ImGuiStyle& style = g.Style;
  4028. IM_ASSERT(str_id != NULL || label != NULL);
  4029. if (str_id == NULL)
  4030. str_id = label;
  4031. if (label == NULL)
  4032. label = str_id;
  4033. const ImGuiID id = window->GetID(str_id);
  4034. // We only write to the tree storage if the user clicks (or explicitely use SetNextTreeNode*** functions)
  4035. ImGuiStorage* storage = window->DC.StateStorage;
  4036. bool opened;
  4037. if (g.SetNextTreeNodeOpenedCond != 0)
  4038. {
  4039. if (g.SetNextTreeNodeOpenedCond & ImGuiSetCond_Always)
  4040. {
  4041. opened = g.SetNextTreeNodeOpenedVal;
  4042. storage->SetInt(id, opened);
  4043. }
  4044. else
  4045. {
  4046. // We treat ImGuiSetCondition_Once and ImGuiSetCondition_FirstUseEver the same because tree node state are not saved persistently.
  4047. const int stored_value = storage->GetInt(id, -1);
  4048. if (stored_value == -1)
  4049. {
  4050. opened = g.SetNextTreeNodeOpenedVal;
  4051. storage->SetInt(id, opened);
  4052. }
  4053. else
  4054. {
  4055. opened = stored_value != 0;
  4056. }
  4057. }
  4058. g.SetNextTreeNodeOpenedCond = 0;
  4059. }
  4060. else
  4061. {
  4062. opened = storage->GetInt(id, default_open) != 0;
  4063. }
  4064. // Framed header expand a little outside the default padding
  4065. const ImVec2 window_padding = window->WindowPadding();
  4066. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  4067. const ImVec2 pos_min = window->DC.CursorPos;
  4068. const ImVec2 pos_max = window->Pos + GetContentRegionMax();
  4069. ImRect bb = ImRect(pos_min, ImVec2(pos_max.x, pos_min.y + label_size.y));
  4070. if (display_frame)
  4071. {
  4072. bb.Min.x -= window_padding.x*0.5f - 1;
  4073. bb.Max.x += window_padding.x*0.5f - 1;
  4074. bb.Max.y += style.FramePadding.y * 2;
  4075. }
  4076. // FIXME: we don't provide our width so that it doesn't get feed back into AutoFit. Should manage that better so we can still hover without extending ContentsSize
  4077. const ImRect text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + label_size);
  4078. ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y), display_frame ? style.FramePadding.y : 0.0f);
  4079. // When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behavior).
  4080. // NB- If we are above max depth we still allow manually opened nodes to be logged.
  4081. if (g.LogEnabled && !display_frame && window->DC.TreeDepth < g.LogAutoExpandMaxDepth)
  4082. opened = true;
  4083. if (!ItemAdd(bb, &id))
  4084. return opened;
  4085. bool hovered, held;
  4086. bool pressed = ButtonBehavior(display_frame ? bb : text_bb, id, &hovered, &held, false);
  4087. if (pressed)
  4088. {
  4089. opened = !opened;
  4090. storage->SetInt(id, opened);
  4091. }
  4092. // Render
  4093. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
  4094. if (display_frame)
  4095. {
  4096. // Framed type
  4097. RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
  4098. RenderCollapseTriangle(bb.Min + style.FramePadding, opened, 1.0f, true);
  4099. if (g.LogEnabled)
  4100. {
  4101. // NB: '##' is normally used to hide text (as a library-wide feature), so we need to specify the text range to make sure the ## aren't stripped out here.
  4102. const char log_prefix[] = "\n##";
  4103. LogText(bb.Min + style.FramePadding, log_prefix, log_prefix+3);
  4104. }
  4105. RenderText(bb.Min + style.FramePadding + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label);
  4106. if (g.LogEnabled)
  4107. {
  4108. const char log_suffix[] = "##";
  4109. LogText(bb.Min + style.FramePadding, log_suffix, log_suffix+2);
  4110. }
  4111. }
  4112. else
  4113. {
  4114. // Unframed typed for tree nodes
  4115. if ((held && hovered) || hovered)
  4116. RenderFrame(bb.Min, bb.Max, col, false);
  4117. RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f, false);
  4118. if (g.LogEnabled)
  4119. LogText(bb.Min, ">");
  4120. RenderText(bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label);
  4121. }
  4122. return opened;
  4123. }
  4124. void ImGui::Bullet()
  4125. {
  4126. ImGuiState& g = *GImGui;
  4127. ImGuiWindow* window = GetCurrentWindow();
  4128. if (window->SkipItems)
  4129. return;
  4130. const ImGuiStyle& style = g.Style;
  4131. const float line_height = window->FontSize();
  4132. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height, line_height));
  4133. ItemSize(bb);
  4134. if (!ItemAdd(bb, NULL))
  4135. return;
  4136. // Render
  4137. const float bullet_size = line_height*0.15f;
  4138. window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text));
  4139. // Stay on same line
  4140. ImGui::SameLine(0, -1);
  4141. }
  4142. // Text with a little bullet aligned to the typical tree node.
  4143. void ImGui::BulletTextV(const char* fmt, va_list args)
  4144. {
  4145. ImGuiState& g = *GImGui;
  4146. ImGuiWindow* window = GetCurrentWindow();
  4147. if (window->SkipItems)
  4148. return;
  4149. const char* text_begin = g.TempBuffer;
  4150. const char* text_end = text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  4151. const ImGuiStyle& style = g.Style;
  4152. const float line_height = window->FontSize();
  4153. const ImVec2 label_size = CalcTextSize(text_begin, text_end, true);
  4154. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (label_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + label_size); // Empty text doesn't add padding
  4155. ItemSize(bb);
  4156. if (!ItemAdd(bb, NULL))
  4157. return;
  4158. // Render
  4159. const float bullet_size = line_height*0.15f;
  4160. window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text));
  4161. RenderText(bb.Min+ImVec2(window->FontSize() + style.FramePadding.x*2,0), text_begin, text_end);
  4162. }
  4163. void ImGui::BulletText(const char* fmt, ...)
  4164. {
  4165. va_list args;
  4166. va_start(args, fmt);
  4167. BulletTextV(fmt, args);
  4168. va_end(args);
  4169. }
  4170. // If returning 'true' the node is open and the user is responsible for calling TreePop
  4171. bool ImGui::TreeNodeV(const char* str_id, const char* fmt, va_list args)
  4172. {
  4173. ImGuiState& g = *GImGui;
  4174. ImGuiWindow* window = GetCurrentWindow();
  4175. if (window->SkipItems)
  4176. return false;
  4177. ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  4178. if (!str_id || !str_id[0])
  4179. str_id = fmt;
  4180. ImGui::PushID(str_id);
  4181. const bool opened = ImGui::CollapsingHeader(g.TempBuffer, "", false);
  4182. ImGui::PopID();
  4183. if (opened)
  4184. ImGui::TreePush(str_id);
  4185. return opened;
  4186. }
  4187. bool ImGui::TreeNode(const char* str_id, const char* fmt, ...)
  4188. {
  4189. va_list args;
  4190. va_start(args, fmt);
  4191. bool s = TreeNodeV(str_id, fmt, args);
  4192. va_end(args);
  4193. return s;
  4194. }
  4195. // If returning 'true' the node is open and the user is responsible for calling TreePop
  4196. bool ImGui::TreeNodeV(const void* ptr_id, const char* fmt, va_list args)
  4197. {
  4198. ImGuiState& g = *GImGui;
  4199. ImGuiWindow* window = GetCurrentWindow();
  4200. if (window->SkipItems)
  4201. return false;
  4202. ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  4203. if (!ptr_id)
  4204. ptr_id = fmt;
  4205. ImGui::PushID(ptr_id);
  4206. const bool opened = ImGui::CollapsingHeader(g.TempBuffer, "", false);
  4207. ImGui::PopID();
  4208. if (opened)
  4209. ImGui::TreePush(ptr_id);
  4210. return opened;
  4211. }
  4212. bool ImGui::TreeNode(const void* ptr_id, const char* fmt, ...)
  4213. {
  4214. va_list args;
  4215. va_start(args, fmt);
  4216. bool s = TreeNodeV(ptr_id, fmt, args);
  4217. va_end(args);
  4218. return s;
  4219. }
  4220. bool ImGui::TreeNode(const char* str_label_id)
  4221. {
  4222. return TreeNode(str_label_id, "%s", str_label_id);
  4223. }
  4224. void ImGui::SetNextTreeNodeOpened(bool opened, ImGuiSetCond cond)
  4225. {
  4226. ImGuiState& g = *GImGui;
  4227. g.SetNextTreeNodeOpenedVal = opened;
  4228. g.SetNextTreeNodeOpenedCond = cond ? cond : ImGuiSetCond_Always;
  4229. }
  4230. void ImGui::PushID(const char* str_id)
  4231. {
  4232. ImGuiWindow* window = GetCurrentWindow();
  4233. window->IDStack.push_back(window->GetID(str_id));
  4234. }
  4235. void ImGui::PushID(const void* ptr_id)
  4236. {
  4237. ImGuiWindow* window = GetCurrentWindow();
  4238. window->IDStack.push_back(window->GetID(ptr_id));
  4239. }
  4240. void ImGui::PushID(const int int_id)
  4241. {
  4242. const void* ptr_id = (void*)(intptr_t)int_id;
  4243. ImGuiWindow* window = GetCurrentWindow();
  4244. window->IDStack.push_back(window->GetID(ptr_id));
  4245. }
  4246. void ImGui::PopID()
  4247. {
  4248. ImGuiWindow* window = GetCurrentWindow();
  4249. window->IDStack.pop_back();
  4250. }
  4251. ImGuiID ImGui::GetID(const char* str_id)
  4252. {
  4253. ImGuiWindow* window = GetCurrentWindow();
  4254. return window->GetID(str_id);
  4255. }
  4256. ImGuiID ImGui::GetID(const void* ptr_id)
  4257. {
  4258. ImGuiWindow* window = GetCurrentWindow();
  4259. return window->GetID(ptr_id);
  4260. }
  4261. // User can input math operators (e.g. +100) to edit a numerical values.
  4262. // NB: only call right after InputText because we are using its InitialValue storage
  4263. static void ApplyNumericalTextInput(const char* buf, float *v)
  4264. {
  4265. while (ImCharIsSpace(*buf))
  4266. buf++;
  4267. // We don't support '-' op because it would conflict with inputing negative value.
  4268. // Instead you can use +-100 to subtract from an existing value
  4269. char op = buf[0];
  4270. if (op == '+' || op == '*' || op == '/')
  4271. {
  4272. buf++;
  4273. while (ImCharIsSpace(*buf))
  4274. buf++;
  4275. }
  4276. else
  4277. {
  4278. op = 0;
  4279. }
  4280. if (!buf[0])
  4281. return;
  4282. float ref_v = *v;
  4283. if (op)
  4284. if (sscanf(GImGui->InputTextState.InitialText, "%f", &ref_v) < 1)
  4285. return;
  4286. float op_v = 0.0f;
  4287. if (sscanf(buf, "%f", &op_v) < 1)
  4288. return;
  4289. if (op == '+')
  4290. *v = ref_v + op_v;
  4291. else if (op == '*')
  4292. *v = ref_v * op_v;
  4293. else if (op == '/')
  4294. {
  4295. if (op_v == 0.0f)
  4296. return;
  4297. *v = ref_v / op_v;
  4298. }
  4299. else
  4300. *v = op_v;
  4301. }
  4302. // Create text input in place of a slider (when CTRL+Clicking on slider)
  4303. static bool SliderFloatAsInputText(const char* label, float* v, ImGuiID id, int decimal_precision)
  4304. {
  4305. ImGuiState& g = *GImGui;
  4306. ImGuiWindow* window = GetCurrentWindow();
  4307. char text_buf[64];
  4308. ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%.*f", decimal_precision, *v);
  4309. SetActiveId(g.SliderAsInputTextId);
  4310. g.HoveredId = 0;
  4311. // Our replacement widget will override the focus ID (registered previously to allow for a TAB focus to happen)
  4312. window->FocusItemUnregister();
  4313. bool value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll);
  4314. if (g.SliderAsInputTextId == 0)
  4315. {
  4316. // First frame
  4317. IM_ASSERT(g.ActiveId == id); // InputText ID expected to match the Slider ID (else we'd need to store them both, which is also possible)
  4318. g.SliderAsInputTextId = g.ActiveId;
  4319. g.HoveredId = id;
  4320. }
  4321. else if (g.ActiveId != g.SliderAsInputTextId)
  4322. {
  4323. // Release
  4324. g.SliderAsInputTextId = 0;
  4325. }
  4326. if (value_changed)
  4327. {
  4328. ApplyNumericalTextInput(text_buf, v);
  4329. }
  4330. return value_changed;
  4331. }
  4332. // Parse display precision back from the display format string
  4333. static void ParseFormat(const char* fmt, int& decimal_precision)
  4334. {
  4335. while ((fmt = strchr(fmt, '%')) != NULL)
  4336. {
  4337. fmt++;
  4338. if (fmt[0] == '%') { fmt++; continue; } // Ignore "%%"
  4339. while (*fmt >= '0' && *fmt <= '9')
  4340. fmt++;
  4341. if (*fmt == '.')
  4342. {
  4343. decimal_precision = atoi(fmt + 1);
  4344. if (decimal_precision < 0 || decimal_precision > 10)
  4345. decimal_precision = 3;
  4346. }
  4347. break;
  4348. }
  4349. }
  4350. static bool SliderBehavior(const ImRect& frame_bb, const ImRect& slider_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, bool horizontal)
  4351. {
  4352. ImGuiState& g = *GImGui;
  4353. ImGuiWindow* window = GetCurrentWindow();
  4354. const ImGuiStyle& style = g.Style;
  4355. // Draw frame
  4356. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  4357. const bool is_finite = (v_min != -FLT_MAX && v_min != FLT_MAX && v_max != -FLT_MAX && v_max != FLT_MAX);
  4358. const bool is_non_linear = fabsf(power - 1.0f) > 0.0001f;
  4359. const float slider_sz = horizontal ? slider_bb.GetWidth() : slider_bb.GetHeight();
  4360. float grab_sz;
  4361. if (decimal_precision > 0 || !is_finite)
  4362. grab_sz = style.GrabMinSize;
  4363. else
  4364. grab_sz = ImMax(1.0f * (slider_sz / (v_max-v_min+1.0f)), style.GrabMinSize); // Integer sliders, if possible have the grab size represent 1 unit
  4365. const float slider_usable_sz = slider_sz - grab_sz;
  4366. const float slider_usable_pos_min = (horizontal ? slider_bb.Min.x : slider_bb.Min.y) + grab_sz*0.5f;
  4367. const float slider_usable_pos_max = (horizontal ? slider_bb.Max.x : slider_bb.Max.y) - grab_sz*0.5f;
  4368. bool value_changed = false;
  4369. if (is_finite)
  4370. {
  4371. // For logarithmic sliders that cross over sign boundary we want the exponential increase to be symmetric around 0.0f
  4372. float linear_zero_pos = 0.0f; // 0.0->1.0f
  4373. if (v_min * v_max < 0.0f)
  4374. {
  4375. // Different sign
  4376. const float linear_dist_min_to_0 = powf(fabsf(0.0f - v_min), 1.0f/power);
  4377. const float linear_dist_max_to_0 = powf(fabsf(v_max - 0.0f), 1.0f/power);
  4378. linear_zero_pos = linear_dist_min_to_0 / (linear_dist_min_to_0+linear_dist_max_to_0);
  4379. }
  4380. else
  4381. {
  4382. // Same sign
  4383. linear_zero_pos = v_min < 0.0f ? 1.0f : 0.0f;
  4384. }
  4385. // Process clicking on the slider
  4386. if (g.ActiveId == id)
  4387. {
  4388. if (g.IO.MouseDown[0])
  4389. {
  4390. const float mouse_abs_pos = horizontal ? g.IO.MousePos.x : g.IO.MousePos.y;
  4391. float normalized_pos = ImClamp((mouse_abs_pos - slider_usable_pos_min) / slider_usable_sz, 0.0f, 1.0f);
  4392. if (!horizontal)
  4393. normalized_pos = 1.0f - normalized_pos;
  4394. float new_value;
  4395. if (is_non_linear)
  4396. {
  4397. // Account for logarithmic scale on both sides of the zero
  4398. if (normalized_pos < linear_zero_pos)
  4399. {
  4400. // Negative: rescale to the negative range before powering
  4401. float a = 1.0f - (normalized_pos / linear_zero_pos);
  4402. a = powf(a, power);
  4403. new_value = ImLerp(ImMin(v_max,0.f), v_min, a);
  4404. }
  4405. else
  4406. {
  4407. // Positive: rescale to the positive range before powering
  4408. float a;
  4409. if (fabsf(linear_zero_pos - 1.0f) > 1.e-6)
  4410. a = (normalized_pos - linear_zero_pos) / (1.0f - linear_zero_pos);
  4411. else
  4412. a = normalized_pos;
  4413. a = powf(a, power);
  4414. new_value = ImLerp(ImMax(v_min,0.0f), v_max, a);
  4415. }
  4416. }
  4417. else
  4418. {
  4419. // Linear slider
  4420. new_value = ImLerp(v_min, v_max, normalized_pos);
  4421. }
  4422. // Round past decimal precision
  4423. // 0->1, 1->0.1, 2->0.01, etc.
  4424. // So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0
  4425. const float min_step = 1.0f / powf(10.0f, (float)decimal_precision);
  4426. const float remainder = fmodf(new_value, min_step);
  4427. if (remainder <= min_step*0.5f)
  4428. new_value -= remainder;
  4429. else
  4430. new_value += (min_step - remainder);
  4431. if (*v != new_value)
  4432. {
  4433. *v = new_value;
  4434. value_changed = true;
  4435. }
  4436. }
  4437. else
  4438. {
  4439. SetActiveId(0);
  4440. }
  4441. }
  4442. // Calculate slider grab positioning
  4443. float grab_t;
  4444. if (is_non_linear)
  4445. {
  4446. float v_clamped = ImClamp(*v, v_min, v_max);
  4447. if (v_clamped < 0.0f)
  4448. {
  4449. const float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min);
  4450. grab_t = (1.0f - powf(f, 1.0f/power)) * linear_zero_pos;
  4451. }
  4452. else
  4453. {
  4454. const float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min));
  4455. grab_t = linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos);
  4456. }
  4457. }
  4458. else
  4459. {
  4460. // Linear slider
  4461. grab_t = (ImClamp(*v, v_min, v_max) - v_min) / (v_max - v_min);
  4462. }
  4463. // Draw
  4464. if (!horizontal)
  4465. grab_t = 1.0f - grab_t;
  4466. const float grab_pos = ImLerp(slider_usable_pos_min, slider_usable_pos_max, grab_t);
  4467. ImRect grab_bb;
  4468. if (horizontal)
  4469. grab_bb = ImRect(ImVec2(grab_pos - grab_sz*0.5f, frame_bb.Min.y + 2.0f), ImVec2(grab_pos + grab_sz*0.5f, frame_bb.Max.y - 2.0f));
  4470. else
  4471. grab_bb = ImRect(ImVec2(frame_bb.Min.x + 2.0f, grab_pos - grab_sz*0.5f), ImVec2(frame_bb.Max.x - 2.0f, grab_pos + grab_sz*0.5f));
  4472. window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab));
  4473. }
  4474. return value_changed;
  4475. }
  4476. // Use power!=1.0 for logarithmic sliders.
  4477. // Adjust display_format to decorate the value with a prefix or a suffix.
  4478. // "%.3f" 1.234
  4479. // "%5.2f secs" 01.23 secs
  4480. // "Gold: %.0f" Gold: 1
  4481. bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format, float power)
  4482. {
  4483. ImGuiState& g = *GImGui;
  4484. ImGuiWindow* window = GetCurrentWindow();
  4485. if (window->SkipItems)
  4486. return false;
  4487. const ImGuiStyle& style = g.Style;
  4488. const ImGuiID id = window->GetID(label);
  4489. const float w = ImGui::CalcItemWidth();
  4490. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  4491. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
  4492. const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
  4493. const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
  4494. // NB- we don't call ItemSize() yet becausae we may turn into a text edit box below
  4495. if (!ItemAdd(total_bb, &id))
  4496. {
  4497. ItemSize(total_bb, style.FramePadding.y);
  4498. return false;
  4499. }
  4500. const bool hovered = IsHovered(frame_bb, id);
  4501. if (hovered)
  4502. g.HoveredId = id;
  4503. if (!display_format)
  4504. display_format = "%.3f";
  4505. int decimal_precision = 3;
  4506. ParseFormat(display_format, decimal_precision);
  4507. const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id);
  4508. const bool is_finite = (v_min != -FLT_MAX && v_min != FLT_MAX && v_max != -FLT_MAX && v_max != FLT_MAX);
  4509. // Tabbing or CTRL-clicking through slider turns into an input box
  4510. bool start_text_input = false;
  4511. if (tab_focus_requested || (hovered && g.IO.MouseClicked[0]))
  4512. {
  4513. SetActiveId(id);
  4514. FocusWindow(window);
  4515. const bool is_ctrl_down = g.IO.KeyCtrl;
  4516. if (tab_focus_requested || is_ctrl_down || !is_finite)
  4517. {
  4518. start_text_input = true;
  4519. g.SliderAsInputTextId = 0;
  4520. }
  4521. }
  4522. if (start_text_input || (g.ActiveId == id && id == g.SliderAsInputTextId))
  4523. return SliderFloatAsInputText(label, v, id, decimal_precision);
  4524. ItemSize(total_bb, style.FramePadding.y);
  4525. // Actual slider behavior + render grab
  4526. bool value_changed = SliderBehavior(frame_bb, inner_bb, id, v, v_min, v_max, power, decimal_precision, true);
  4527. // Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
  4528. char value_buf[64];
  4529. char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
  4530. const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true);
  4531. RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x + style.FramePadding.x, inner_bb.GetCenter().x - value_text_size.x*0.5f), frame_bb.Min.y + style.FramePadding.y), value_buf, value_buf_end, &value_text_size, frame_bb.Max);
  4532. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label);
  4533. return value_changed;
  4534. }
  4535. bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format, float power)
  4536. {
  4537. ImGuiState& g = *GImGui;
  4538. ImGuiWindow* window = GetCurrentWindow();
  4539. if (window->SkipItems)
  4540. return false;
  4541. const ImGuiStyle& style = g.Style;
  4542. const ImGuiID id = window->GetID(label);
  4543. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  4544. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size);
  4545. const ImRect slider_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
  4546. const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
  4547. ItemSize(bb, style.FramePadding.y);
  4548. if (!ItemAdd(frame_bb, &id))
  4549. return false;
  4550. const bool hovered = IsHovered(frame_bb, id);
  4551. if (hovered)
  4552. g.HoveredId = id;
  4553. if (!display_format)
  4554. display_format = "%.3f";
  4555. int decimal_precision = 3;
  4556. ParseFormat(display_format, decimal_precision);
  4557. if (hovered && g.IO.MouseClicked[0])
  4558. {
  4559. SetActiveId(id);
  4560. FocusWindow(window);
  4561. }
  4562. // Actual slider behavior + render grab
  4563. bool value_changed = SliderBehavior(frame_bb, slider_bb, id, v, v_min, v_max, power, decimal_precision, false);
  4564. // Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
  4565. // For the vertical slider we allow centered text to overlap the frame padding
  4566. char value_buf[64];
  4567. char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
  4568. const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true);
  4569. RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x, slider_bb.GetCenter().x - value_text_size.x*0.5f), frame_bb.Min.y + style.FramePadding.y), value_buf, value_buf_end, &value_text_size, frame_bb.Max);
  4570. if (label_size.x > 0.0f)
  4571. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, slider_bb.Min.y), label);
  4572. return value_changed;
  4573. }
  4574. bool ImGui::SliderAngle(const char* label, float* v, float v_degrees_min, float v_degrees_max)
  4575. {
  4576. float v_deg = *v * 360.0f / (2*PI);
  4577. bool value_changed = ImGui::SliderFloat(label, &v_deg, v_degrees_min, v_degrees_max, "%.0f deg", 1.0f);
  4578. *v = v_deg * (2*PI) / 360.0f;
  4579. return value_changed;
  4580. }
  4581. bool ImGui::SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format)
  4582. {
  4583. if (!display_format)
  4584. display_format = "%.0f";
  4585. float v_f = (float)*v;
  4586. bool value_changed = ImGui::SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f);
  4587. *v = (int)v_f;
  4588. return value_changed;
  4589. }
  4590. bool ImGui::VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format)
  4591. {
  4592. if (!display_format)
  4593. display_format = "%.0f";
  4594. float v_f = (float)*v;
  4595. bool value_changed = ImGui::VSliderFloat(label, size, &v_f, (float)v_min, (float)v_max, display_format, 1.0f);
  4596. *v = (int)v_f;
  4597. return value_changed;
  4598. }
  4599. // Add multiple sliders on 1 line for compact edition of multiple components
  4600. static bool SliderFloatN(const char* label, float v[3], int components, float v_min, float v_max, const char* display_format, float power)
  4601. {
  4602. ImGuiState& g = *GImGui;
  4603. ImGuiWindow* window = GetCurrentWindow();
  4604. if (window->SkipItems)
  4605. return false;
  4606. const ImGuiStyle& style = g.Style;
  4607. const float w_full = ImGui::CalcItemWidth();
  4608. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components));
  4609. const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)));
  4610. bool value_changed = false;
  4611. ImGui::BeginGroup();
  4612. ImGui::PushID(label);
  4613. ImGui::PushItemWidth(w_item_one);
  4614. for (int i = 0; i < components; i++)
  4615. {
  4616. ImGui::PushID(i);
  4617. if (i + 1 == components)
  4618. {
  4619. ImGui::PopItemWidth();
  4620. ImGui::PushItemWidth(w_item_last);
  4621. }
  4622. value_changed |= ImGui::SliderFloat("##v", &v[i], v_min, v_max, display_format, power);
  4623. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4624. ImGui::PopID();
  4625. }
  4626. ImGui::PopItemWidth();
  4627. ImGui::PopID();
  4628. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4629. ImGui::EndGroup();
  4630. return value_changed;
  4631. }
  4632. bool ImGui::SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format, float power)
  4633. {
  4634. return SliderFloatN(label, v, 2, v_min, v_max, display_format, power);
  4635. }
  4636. bool ImGui::SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format, float power)
  4637. {
  4638. return SliderFloatN(label, v, 3, v_min, v_max, display_format, power);
  4639. }
  4640. bool ImGui::SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format, float power)
  4641. {
  4642. return SliderFloatN(label, v, 4, v_min, v_max, display_format, power);
  4643. }
  4644. static bool SliderIntN(const char* label, int v[3], int components, int v_min, int v_max, const char* display_format)
  4645. {
  4646. ImGuiState& g = *GImGui;
  4647. ImGuiWindow* window = GetCurrentWindow();
  4648. if (window->SkipItems)
  4649. return false;
  4650. const ImGuiStyle& style = g.Style;
  4651. const float w_full = ImGui::CalcItemWidth();
  4652. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components));
  4653. const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)));
  4654. bool value_changed = false;
  4655. ImGui::BeginGroup();
  4656. ImGui::PushID(label);
  4657. ImGui::PushItemWidth(w_item_one);
  4658. for (int i = 0; i < components; i++)
  4659. {
  4660. ImGui::PushID(i);
  4661. if (i + 1 == components)
  4662. {
  4663. ImGui::PopItemWidth();
  4664. ImGui::PushItemWidth(w_item_last);
  4665. }
  4666. value_changed |= ImGui::SliderInt("##v", &v[i], v_min, v_max, display_format);
  4667. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4668. ImGui::PopID();
  4669. }
  4670. ImGui::PopItemWidth();
  4671. ImGui::PopID();
  4672. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4673. ImGui::EndGroup();
  4674. return value_changed;
  4675. }
  4676. bool ImGui::SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format)
  4677. {
  4678. return SliderIntN(label, v, 2, v_min, v_max, display_format);
  4679. }
  4680. bool ImGui::SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format)
  4681. {
  4682. return SliderIntN(label, v, 3, v_min, v_max, display_format);
  4683. }
  4684. bool ImGui::SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format)
  4685. {
  4686. return SliderIntN(label, v, 4, v_min, v_max, display_format);
  4687. }
  4688. enum ImGuiPlotType
  4689. {
  4690. ImGuiPlotType_Lines,
  4691. ImGuiPlotType_Histogram
  4692. };
  4693. static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size)
  4694. {
  4695. ImGuiState& g = *GImGui;
  4696. ImGuiWindow* window = GetCurrentWindow();
  4697. if (window->SkipItems)
  4698. return;
  4699. const ImGuiStyle& style = g.Style;
  4700. const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
  4701. if (graph_size.x == 0.0f)
  4702. graph_size.x = ImGui::CalcItemWidth() + (style.FramePadding.x * 2);
  4703. if (graph_size.y == 0.0f)
  4704. graph_size.y = label_size.y + (style.FramePadding.y * 2);
  4705. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y));
  4706. const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
  4707. const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0));
  4708. ItemSize(total_bb, style.FramePadding.y);
  4709. if (!ItemAdd(total_bb, NULL))
  4710. return;
  4711. // Determine scale from values if not specified
  4712. if (scale_min == FLT_MAX || scale_max == FLT_MAX)
  4713. {
  4714. float v_min = FLT_MAX;
  4715. float v_max = -FLT_MAX;
  4716. for (int i = 0; i < values_count; i++)
  4717. {
  4718. const float v = values_getter(data, i);
  4719. v_min = ImMin(v_min, v);
  4720. v_max = ImMax(v_max, v);
  4721. }
  4722. if (scale_min == FLT_MAX)
  4723. scale_min = v_min;
  4724. if (scale_max == FLT_MAX)
  4725. scale_max = v_max;
  4726. }
  4727. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  4728. int res_w = ImMin((int)graph_size.x, values_count);
  4729. if (plot_type == ImGuiPlotType_Lines)
  4730. res_w -= 1;
  4731. // Tooltip on hover
  4732. int v_hovered = -1;
  4733. if (IsMouseHoveringRect(inner_bb))
  4734. {
  4735. const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f);
  4736. const int v_idx = (int)(t * (values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0)));
  4737. IM_ASSERT(v_idx >= 0 && v_idx < values_count);
  4738. const float v0 = values_getter(data, (v_idx + values_offset) % values_count);
  4739. const float v1 = values_getter(data, (v_idx + 1 + values_offset) % values_count);
  4740. if (plot_type == ImGuiPlotType_Lines)
  4741. ImGui::SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx+1, v1);
  4742. else if (plot_type == ImGuiPlotType_Histogram)
  4743. ImGui::SetTooltip("%d: %8.4g", v_idx, v0);
  4744. v_hovered = v_idx;
  4745. }
  4746. const float t_step = 1.0f / (float)res_w;
  4747. float v0 = values_getter(data, (0 + values_offset) % values_count);
  4748. float t0 = 0.0f;
  4749. ImVec2 p0 = ImVec2( t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min)) );
  4750. const ImU32 col_base = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram);
  4751. const ImU32 col_hovered = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered);
  4752. for (int n = 0; n < res_w; n++)
  4753. {
  4754. const float t1 = t0 + t_step;
  4755. const int v_idx = (int)(t0 * values_count);
  4756. IM_ASSERT(v_idx >= 0 && v_idx < values_count);
  4757. const float v1 = values_getter(data, (v_idx + values_offset + 1) % values_count);
  4758. const ImVec2 p1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) );
  4759. // NB- Draw calls are merged together by the DrawList system.
  4760. if (plot_type == ImGuiPlotType_Lines)
  4761. window->DrawList->AddLine(ImLerp(inner_bb.Min, inner_bb.Max, p0), ImLerp(inner_bb.Min, inner_bb.Max, p1), v_hovered == v_idx ? col_hovered : col_base);
  4762. else if (plot_type == ImGuiPlotType_Histogram)
  4763. window->DrawList->AddRectFilled(ImLerp(inner_bb.Min, inner_bb.Max, p0), ImLerp(inner_bb.Min, inner_bb.Max, ImVec2(p1.x, 1.0f))+ImVec2(-1,0), v_hovered == v_idx ? col_hovered : col_base);
  4764. t0 = t1;
  4765. p0 = p1;
  4766. }
  4767. // Text overlay
  4768. if (overlay_text)
  4769. RenderText(ImVec2(inner_bb.GetCenter().x - ImGui::CalcTextSize(overlay_text, NULL, true).x*0.5f, frame_bb.Min.y + style.FramePadding.y), overlay_text);
  4770. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label);
  4771. }
  4772. struct ImGuiPlotArrayGetterData
  4773. {
  4774. const float* Values;
  4775. size_t Stride;
  4776. ImGuiPlotArrayGetterData(const float* values, size_t stride) { Values = values; Stride = stride; }
  4777. };
  4778. static float Plot_ArrayGetter(void* data, int idx)
  4779. {
  4780. ImGuiPlotArrayGetterData* plot_data = (ImGuiPlotArrayGetterData*)data;
  4781. const float v = *(float*)(void*)((unsigned char*)plot_data->Values + (size_t)idx * plot_data->Stride);
  4782. return v;
  4783. }
  4784. void ImGui::PlotLines(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, size_t stride)
  4785. {
  4786. ImGuiPlotArrayGetterData data(values, stride);
  4787. Plot(ImGuiPlotType_Lines, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  4788. }
  4789. void ImGui::PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size)
  4790. {
  4791. Plot(ImGuiPlotType_Lines, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  4792. }
  4793. void ImGui::PlotHistogram(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, size_t stride)
  4794. {
  4795. ImGuiPlotArrayGetterData data(values, stride);
  4796. Plot(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  4797. }
  4798. void ImGui::PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size)
  4799. {
  4800. Plot(ImGuiPlotType_Histogram, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  4801. }
  4802. bool ImGui::Checkbox(const char* label, bool* v)
  4803. {
  4804. ImGuiState& g = *GImGui;
  4805. ImGuiWindow* window = GetCurrentWindow();
  4806. if (window->SkipItems)
  4807. return false;
  4808. const ImGuiStyle& style = g.Style;
  4809. const ImGuiID id = window->GetID(label);
  4810. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  4811. const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2, label_size.y + style.FramePadding.y*2));
  4812. ItemSize(check_bb, style.FramePadding.y);
  4813. ImRect total_bb = check_bb;
  4814. if (label_size.x > 0)
  4815. SameLine(0, (int)style.ItemInnerSpacing.x);
  4816. const ImRect text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + label_size);
  4817. if (label_size.x > 0)
  4818. {
  4819. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
  4820. total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
  4821. }
  4822. if (!ItemAdd(total_bb, &id))
  4823. return false;
  4824. bool hovered, held;
  4825. bool pressed = ButtonBehavior(total_bb, id, &hovered, &held, true);
  4826. if (pressed)
  4827. *v = !(*v);
  4828. RenderFrame(check_bb.Min, check_bb.Max, window->Color((held && hovered) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), true, style.FrameRounding);
  4829. if (*v)
  4830. {
  4831. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  4832. const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f;
  4833. window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), window->Color(ImGuiCol_CheckMark), style.FrameRounding);
  4834. }
  4835. if (g.LogEnabled)
  4836. LogText(text_bb.GetTL(), *v ? "[x]" : "[ ]");
  4837. RenderText(text_bb.GetTL(), label);
  4838. return pressed;
  4839. }
  4840. bool ImGui::CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value)
  4841. {
  4842. bool v = (*flags & flags_value) ? true : false;
  4843. bool pressed = ImGui::Checkbox(label, &v);
  4844. if (v)
  4845. *flags |= flags_value;
  4846. else
  4847. *flags &= ~flags_value;
  4848. return pressed;
  4849. }
  4850. bool ImGui::RadioButton(const char* label, bool active)
  4851. {
  4852. ImGuiState& g = *GImGui;
  4853. ImGuiWindow* window = GetCurrentWindow();
  4854. if (window->SkipItems)
  4855. return false;
  4856. const ImGuiStyle& style = g.Style;
  4857. const ImGuiID id = window->GetID(label);
  4858. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  4859. const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2-1, label_size.y + style.FramePadding.y*2-1));
  4860. ItemSize(check_bb, style.FramePadding.y);
  4861. ImRect total_bb = check_bb;
  4862. if (label_size.x > 0)
  4863. SameLine(0, (int)style.ItemInnerSpacing.x);
  4864. const ImRect text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size);
  4865. if (label_size.x > 0)
  4866. {
  4867. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
  4868. total_bb.Add(text_bb);
  4869. }
  4870. if (!ItemAdd(total_bb, &id))
  4871. return false;
  4872. ImVec2 center = check_bb.GetCenter();
  4873. center.x = (float)(int)center.x + 0.5f;
  4874. center.y = (float)(int)center.y + 0.5f;
  4875. const float radius = check_bb.GetHeight() * 0.5f;
  4876. bool hovered, held;
  4877. bool pressed = ButtonBehavior(total_bb, id, &hovered, &held, true);
  4878. window->DrawList->AddCircleFilled(center, radius, window->Color((held && hovered) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), 16);
  4879. if (active)
  4880. {
  4881. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  4882. const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f;
  4883. window->DrawList->AddCircleFilled(center, radius-pad, window->Color(ImGuiCol_CheckMark), 16);
  4884. }
  4885. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  4886. {
  4887. window->DrawList->AddCircle(center+ImVec2(1,1), radius, window->Color(ImGuiCol_BorderShadow), 16);
  4888. window->DrawList->AddCircle(center, radius, window->Color(ImGuiCol_Border), 16);
  4889. }
  4890. if (g.LogEnabled)
  4891. LogText(text_bb.GetTL(), active ? "(x)" : "( )");
  4892. RenderText(text_bb.GetTL(), label);
  4893. return pressed;
  4894. }
  4895. bool ImGui::RadioButton(const char* label, int* v, int v_button)
  4896. {
  4897. const bool pressed = ImGui::RadioButton(label, *v == v_button);
  4898. if (pressed)
  4899. {
  4900. *v = v_button;
  4901. }
  4902. return pressed;
  4903. }
  4904. // Wrapper for stb_textedit.h to edit text (our wrapper is for: statically sized buffer, single-line, wchar characters. InputText converts between UTF-8 and wchar)
  4905. static int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return (int)ImStrlenW(obj->Text); }
  4906. static ImWchar STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return obj->Text[idx]; }
  4907. static float STB_TEXTEDIT_GETWIDTH(STB_TEXTEDIT_STRING* obj, int line_start_idx, int char_idx) { (void)line_start_idx; return obj->Font->CalcTextSizeW(obj->FontSize, FLT_MAX, &obj->Text[char_idx], &obj->Text[char_idx]+1, NULL).x; }
  4908. static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : key; }
  4909. static ImWchar STB_TEXTEDIT_NEWLINE = '\n';
  4910. static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx)
  4911. {
  4912. const ImWchar* text_remaining = NULL;
  4913. const ImVec2 size = obj->Font->CalcTextSizeW(obj->FontSize, FLT_MAX, obj->Text + line_start_idx, NULL, &text_remaining);
  4914. r->x0 = 0.0f;
  4915. r->x1 = size.x;
  4916. r->baseline_y_delta = size.y;
  4917. r->ymin = 0.0f;
  4918. r->ymax = size.y;
  4919. r->num_chars = (int)(text_remaining - (obj->Text + line_start_idx));
  4920. }
  4921. static bool is_separator(unsigned int c) { return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; }
  4922. #define STB_TEXTEDIT_IS_SPACE(CH) ( ImCharIsSpace((unsigned int)CH) || is_separator((unsigned int)CH) )
  4923. static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n)
  4924. {
  4925. ImWchar* dst = obj->Text + pos;
  4926. // We maintain our buffer length in both UTF-8 and wchar formats
  4927. obj->CurLenA -= ImTextCountUtf8BytesFromStr(dst, dst + n);
  4928. obj->CurLenW -= n;
  4929. // Offset remaining text
  4930. const ImWchar* src = obj->Text + pos + n;
  4931. while (ImWchar c = *src++)
  4932. *dst++ = c;
  4933. *dst = '\0';
  4934. }
  4935. static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len)
  4936. {
  4937. const size_t text_len = obj->CurLenW;
  4938. if ((size_t)new_text_len + text_len + 1 > IM_ARRAYSIZE(obj->Text))
  4939. return false;
  4940. const int new_text_len_utf8 = ImTextCountUtf8BytesFromStr(new_text, new_text + new_text_len);
  4941. if ((size_t)new_text_len_utf8 + obj->CurLenA + 1 > obj->BufSizeA)
  4942. return false;
  4943. if (pos != (int)text_len)
  4944. memmove(obj->Text + (size_t)pos + new_text_len, obj->Text + (size_t)pos, (text_len - (size_t)pos) * sizeof(ImWchar));
  4945. memcpy(obj->Text + (size_t)pos, new_text, (size_t)new_text_len * sizeof(ImWchar));
  4946. obj->CurLenW += new_text_len;
  4947. obj->CurLenA += new_text_len_utf8;
  4948. obj->Text[obj->CurLenW] = '\0';
  4949. return true;
  4950. }
  4951. // We don't use an enum so we can build even with conflicting symbols (if another user of stb_textedit.h leak their STB_TEXTEDIT_K_* symbols)
  4952. #define STB_TEXTEDIT_K_LEFT 0x10000 // keyboard input to move cursor left
  4953. #define STB_TEXTEDIT_K_RIGHT 0x10001 // keyboard input to move cursor right
  4954. #define STB_TEXTEDIT_K_UP 0x10002 // keyboard input to move cursor up
  4955. #define STB_TEXTEDIT_K_DOWN 0x10003 // keyboard input to move cursor down
  4956. #define STB_TEXTEDIT_K_LINESTART 0x10004 // keyboard input to move cursor to start of line
  4957. #define STB_TEXTEDIT_K_LINEEND 0x10005 // keyboard input to move cursor to end of line
  4958. #define STB_TEXTEDIT_K_TEXTSTART 0x10006 // keyboard input to move cursor to start of text
  4959. #define STB_TEXTEDIT_K_TEXTEND 0x10007 // keyboard input to move cursor to end of text
  4960. #define STB_TEXTEDIT_K_DELETE 0x10008 // keyboard input to delete selection or character under cursor
  4961. #define STB_TEXTEDIT_K_BACKSPACE 0x10009 // keyboard input to delete selection or character left of cursor
  4962. #define STB_TEXTEDIT_K_UNDO 0x1000A // keyboard input to perform undo
  4963. #define STB_TEXTEDIT_K_REDO 0x1000B // keyboard input to perform redo
  4964. #define STB_TEXTEDIT_K_WORDLEFT 0x1000C // keyboard input to move cursor left one word
  4965. #define STB_TEXTEDIT_K_WORDRIGHT 0x1000D // keyboard input to move cursor right one word
  4966. #define STB_TEXTEDIT_K_SHIFT 0x20000
  4967. #ifdef IMGUI_STB_NAMESPACE
  4968. namespace IMGUI_STB_NAMESPACE
  4969. {
  4970. #endif
  4971. #define STB_TEXTEDIT_IMPLEMENTATION
  4972. #include "stb_textedit.h"
  4973. #ifdef IMGUI_STB_NAMESPACE
  4974. }
  4975. #endif
  4976. void ImGuiTextEditState::OnKeyPressed(int key)
  4977. {
  4978. stb_textedit_key(this, &StbState, key);
  4979. CursorAnimReset();
  4980. }
  4981. void ImGuiTextEditState::UpdateScrollOffset()
  4982. {
  4983. // Scroll in chunks of quarter width
  4984. const float scroll_x_increment = Width * 0.25f;
  4985. const float cursor_offset_x = Font->CalcTextSizeW(FontSize, FLT_MAX, Text, Text+StbState.cursor, NULL).x;
  4986. // If widget became bigger than text (because of a resize), reset horizontal scrolling
  4987. if (ScrollX > 0.0f)
  4988. {
  4989. const float text_width = cursor_offset_x + Font->CalcTextSizeW(FontSize, FLT_MAX, Text+StbState.cursor, NULL, NULL).x;
  4990. if (text_width < Width)
  4991. {
  4992. ScrollX = 0.0f;
  4993. return;
  4994. }
  4995. }
  4996. if (cursor_offset_x < ScrollX)
  4997. ScrollX = ImMax(0.0f, cursor_offset_x - scroll_x_increment);
  4998. else if (cursor_offset_x - Width >= ScrollX)
  4999. ScrollX = cursor_offset_x - Width + scroll_x_increment;
  5000. }
  5001. ImVec2 ImGuiTextEditState::CalcDisplayOffsetFromCharIdx(int i) const
  5002. {
  5003. const ImWchar* text_start = GetTextPointerClippedW(Font, FontSize, Text, ScrollX, NULL);
  5004. const ImWchar* text_end = (Text+i >= text_start) ? Text+i : text_start; // Clip if requested character is outside of display
  5005. IM_ASSERT(text_end >= text_start);
  5006. const ImVec2 offset = Font->CalcTextSizeW(FontSize, Width+1, text_start, text_end, NULL);
  5007. return offset;
  5008. }
  5009. // [Static]
  5010. const char* ImGuiTextEditState::GetTextPointerClippedA(ImFont* font, float font_size, const char* text, float width, ImVec2* out_text_size)
  5011. {
  5012. if (width <= 0.0f)
  5013. return text;
  5014. const char* text_clipped_end = NULL;
  5015. const ImVec2 text_size = font->CalcTextSizeA(font_size, width, 0.0f, text, NULL, &text_clipped_end);
  5016. if (out_text_size)
  5017. *out_text_size = text_size;
  5018. return text_clipped_end;
  5019. }
  5020. // [Static]
  5021. const ImWchar* ImGuiTextEditState::GetTextPointerClippedW(ImFont* font, float font_size, const ImWchar* text, float width, ImVec2* out_text_size)
  5022. {
  5023. if (width <= 0.0f)
  5024. return text;
  5025. const ImWchar* text_clipped_end = NULL;
  5026. const ImVec2 text_size = font->CalcTextSizeW(font_size, width, text, NULL, &text_clipped_end);
  5027. if (out_text_size)
  5028. *out_text_size = text_size;
  5029. return text_clipped_end;
  5030. }
  5031. // [Static]
  5032. void ImGuiTextEditState::RenderTextScrolledClipped(ImFont* font, float font_size, const char* buf, ImVec2 pos, float width, float scroll_x)
  5033. {
  5034. ImGuiWindow* window = GetCurrentWindow();
  5035. const ImU32 font_color = window->Color(ImGuiCol_Text);
  5036. //window->DrawList->AddLine(pos, pos+ImVec2(width,0), 0xFF00FFFF);
  5037. // Determine start and end of visible string
  5038. // FIXME-OPT: This is pretty slow for what it does.
  5039. const char* text_start = scroll_x <= 0.0f ? buf : GetTextPointerClippedA(font, font_size, buf, scroll_x, NULL);
  5040. const char* text_end = GetTextPointerClippedA(font, font_size, text_start, width + 1, NULL); // +1 to allow character spacing to fit outside the allowed width
  5041. window->DrawList->AddText(font, font_size, pos, font_color, text_start, text_end);
  5042. // Log as text
  5043. if (GImGui->LogEnabled)
  5044. LogText(pos, buf, NULL);
  5045. }
  5046. bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags)
  5047. {
  5048. ImGuiState& g = *GImGui;
  5049. ImGuiWindow* window = GetCurrentWindow();
  5050. if (window->SkipItems)
  5051. return false;
  5052. const ImGuiStyle& style = g.Style;
  5053. const float w = ImGui::CalcItemWidth();
  5054. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5055. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
  5056. ImGui::BeginGroup();
  5057. ImGui::PushID(label);
  5058. const ImVec2 button_sz = ImVec2(window->FontSize(), window->FontSize()) + style.FramePadding * 2;
  5059. if (step > 0.0f)
  5060. ImGui::PushItemWidth(ImMax(1.0f, w - (button_sz.x + style.ItemInnerSpacing.x)*2));
  5061. char buf[64];
  5062. if (decimal_precision < 0)
  5063. ImFormatString(buf, IM_ARRAYSIZE(buf), "%f", *v); // Ideally we'd have a minimum decimal precision of 1 to visually denote that it is a float, while hiding non-significant digits?
  5064. else
  5065. ImFormatString(buf, IM_ARRAYSIZE(buf), "%.*f", decimal_precision, *v);
  5066. bool value_changed = false;
  5067. const ImGuiInputTextFlags flags = extra_flags | (ImGuiInputTextFlags_CharsDecimal|ImGuiInputTextFlags_AutoSelectAll);
  5068. if (ImGui::InputText("", buf, IM_ARRAYSIZE(buf), flags))
  5069. {
  5070. ApplyNumericalTextInput(buf, v);
  5071. value_changed = true;
  5072. }
  5073. // Step buttons
  5074. if (step > 0.0f)
  5075. {
  5076. ImGui::PopItemWidth();
  5077. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5078. if (ImGui::Button("-", button_sz, true))
  5079. {
  5080. *v -= g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
  5081. value_changed = true;
  5082. }
  5083. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5084. if (ImGui::Button("+", button_sz, true))
  5085. {
  5086. *v += g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
  5087. value_changed = true;
  5088. }
  5089. }
  5090. ImGui::PopID();
  5091. if (label_size.x > 0)
  5092. {
  5093. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5094. RenderText(ImVec2(window->DC.CursorPos.x, window->DC.CursorPos.y + style.FramePadding.y), label);
  5095. ItemSize(label_size, style.FramePadding.y);
  5096. }
  5097. ImGui::EndGroup();
  5098. return value_changed;
  5099. }
  5100. bool ImGui::InputInt(const char* label, int *v, int step, int step_fast, ImGuiInputTextFlags extra_flags)
  5101. {
  5102. float f = (float)*v;
  5103. const bool value_changed = ImGui::InputFloat(label, &f, (float)step, (float)step_fast, 0, extra_flags);
  5104. if (value_changed)
  5105. *v = (int)f;
  5106. return value_changed;
  5107. }
  5108. // Public API to manipulate UTF-8 text
  5109. // We expose UTF-8 to the user (unlike the STB_TEXTEDIT_* functions which are manipulating wchar)
  5110. void ImGuiTextEditCallbackData::DeleteChars(int pos, int bytes_count)
  5111. {
  5112. char* dst = Buf + pos;
  5113. const char* src = Buf + pos + bytes_count;
  5114. while (char c = *src++)
  5115. *dst++ = c;
  5116. *dst = '\0';
  5117. BufDirty = true;
  5118. if (CursorPos + bytes_count >= pos)
  5119. CursorPos -= bytes_count;
  5120. else if (CursorPos >= pos)
  5121. CursorPos = pos;
  5122. SelectionStart = SelectionEnd = CursorPos;
  5123. }
  5124. void ImGuiTextEditCallbackData::InsertChars(int pos, const char* new_text, const char* new_text_end)
  5125. {
  5126. const size_t text_len = strlen(Buf);
  5127. if (!new_text_end)
  5128. new_text_end = new_text + strlen(new_text);
  5129. const size_t new_text_len = (size_t)(new_text_end - new_text);
  5130. if (new_text_len + text_len + 1 >= BufSize)
  5131. return;
  5132. size_t upos = (size_t)pos;
  5133. if (text_len != upos)
  5134. memmove(Buf + upos + new_text_len, Buf + upos, text_len - upos);
  5135. memcpy(Buf + upos, new_text, new_text_len * sizeof(char));
  5136. Buf[text_len + new_text_len] = '\0';
  5137. BufDirty = true;
  5138. if (CursorPos >= pos)
  5139. CursorPos += (int)new_text_len;
  5140. SelectionStart = SelectionEnd = CursorPos;
  5141. }
  5142. // Return false to discard a character.
  5143. static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data)
  5144. {
  5145. unsigned int c = *p_char;
  5146. if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF)))
  5147. return false;
  5148. if (c >= 0xE000 && c <= 0xF8FF) // Filter private Unicode range. I don't imagine anybody would want to input them. GLFW on OSX seems to send private characters for special keys like arrow keys.
  5149. return false;
  5150. if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank))
  5151. {
  5152. if (flags & ImGuiInputTextFlags_CharsDecimal)
  5153. if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
  5154. return false;
  5155. if (flags & ImGuiInputTextFlags_CharsHexadecimal)
  5156. if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
  5157. return false;
  5158. if (flags & ImGuiInputTextFlags_CharsUppercase)
  5159. if (c >= 'a' && c <= 'z')
  5160. *p_char = (c += (unsigned int)('A'-'a'));
  5161. if (flags & ImGuiInputTextFlags_CharsNoBlank)
  5162. if (ImCharIsSpace(c))
  5163. return false;
  5164. }
  5165. if (flags & ImGuiInputTextFlags_CallbackCharFilter)
  5166. {
  5167. ImGuiTextEditCallbackData callback_data;
  5168. memset(&callback_data, 0, sizeof(ImGuiTextEditCallbackData));
  5169. callback_data.EventFlag = ImGuiInputTextFlags_CallbackCharFilter;
  5170. callback_data.EventChar = (ImWchar)c;
  5171. callback_data.Flags = flags;
  5172. callback_data.UserData = user_data;
  5173. if (callback(&callback_data) != 0)
  5174. return false;
  5175. *p_char = callback_data.EventChar;
  5176. if (!callback_data.EventChar)
  5177. return false;
  5178. }
  5179. return true;
  5180. }
  5181. // Edit a string of text
  5182. bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data)
  5183. {
  5184. ImGuiState& g = *GImGui;
  5185. ImGuiWindow* window = GetCurrentWindow();
  5186. if (window->SkipItems)
  5187. return false;
  5188. const ImGuiIO& io = g.IO;
  5189. const ImGuiStyle& style = g.Style;
  5190. const ImGuiID id = window->GetID(label);
  5191. const float w = ImGui::CalcItemWidth();
  5192. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5193. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
  5194. const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f));
  5195. ItemSize(total_bb, style.FramePadding.y);
  5196. if (!ItemAdd(total_bb, &id))
  5197. return false;
  5198. // NB: we are only allowed to access 'edit_state' if we are the active widget.
  5199. ImGuiTextEditState& edit_state = g.InputTextState;
  5200. const bool is_ctrl_down = io.KeyCtrl;
  5201. const bool is_shift_down = io.KeyShift;
  5202. const bool focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & ImGuiInputTextFlags_CallbackCompletion) == 0); // Using completion callback disable keyboard tabbing
  5203. const bool focus_requested_by_code = focus_requested && (window->FocusIdxAllCounter == window->FocusIdxAllRequestCurrent);
  5204. const bool focus_requested_by_tab = focus_requested && !focus_requested_by_code;
  5205. const bool hovered = IsHovered(frame_bb, id);
  5206. if (hovered)
  5207. {
  5208. g.HoveredId = id;
  5209. g.MouseCursor = ImGuiMouseCursor_TextInput;
  5210. }
  5211. const bool user_clicked = hovered && io.MouseClicked[0];
  5212. bool select_all = (g.ActiveId != id) && (flags & ImGuiInputTextFlags_AutoSelectAll) != 0;
  5213. if (focus_requested || user_clicked)
  5214. {
  5215. if (g.ActiveId != id)
  5216. {
  5217. // Start edition
  5218. // Take a copy of the initial buffer value (both in original UTF-8 format and converted to wchar)
  5219. // From the moment we focused we are ignoring the content of 'buf'
  5220. ImFormatString(edit_state.InitialText, IM_ARRAYSIZE(edit_state.InitialText), "%s", buf);
  5221. const char* buf_end = NULL;
  5222. edit_state.CurLenW = ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), buf, NULL, &buf_end);
  5223. edit_state.CurLenA = buf_end - buf; // We can't get the result from ImFormatString() above because it is not UTF-8 aware. Here we'll cut off malformed UTF-8.
  5224. edit_state.Width = w + style.FramePadding.x;
  5225. edit_state.InputCursorScreenPos = ImVec2(-1.f,-1.f);
  5226. edit_state.CursorAnimReset();
  5227. if (edit_state.Id != id)
  5228. {
  5229. edit_state.Id = id;
  5230. edit_state.ScrollX = 0.0f;
  5231. stb_textedit_initialize_state(&edit_state.StbState, true);
  5232. if (focus_requested_by_code)
  5233. select_all = true;
  5234. }
  5235. else
  5236. {
  5237. // Recycle existing cursor/selection/undo stack but clamp position
  5238. // Note a single mouse click will override the cursor/position immediately by calling stb_textedit_click handler.
  5239. edit_state.StbState.cursor = ImMin(edit_state.StbState.cursor, (int)edit_state.CurLenW);
  5240. edit_state.StbState.select_start = ImMin(edit_state.StbState.select_start, (int)edit_state.CurLenW);
  5241. edit_state.StbState.select_end = ImMin(edit_state.StbState.select_end, (int)edit_state.CurLenW);
  5242. }
  5243. if (focus_requested_by_tab || (user_clicked && is_ctrl_down))
  5244. select_all = true;
  5245. }
  5246. SetActiveId(id);
  5247. FocusWindow(window);
  5248. }
  5249. else if (io.MouseClicked[0])
  5250. {
  5251. // Release focus when we click outside
  5252. if (g.ActiveId == id)
  5253. {
  5254. SetActiveId(0);
  5255. }
  5256. }
  5257. // Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget.
  5258. // Down the line we should have a cleaner concept of focused vs active in the library.
  5259. if (g.ActiveId == id)
  5260. g.ActiveIdIsFocusedOnly = !io.MouseDown[0];
  5261. bool value_changed = false;
  5262. bool cancel_edit = false;
  5263. bool enter_pressed = false;
  5264. if (g.ActiveId == id)
  5265. //if (edit_state.Id == id) // Works, but double-click to select-all sets cursors to end which in turn tends to scroll toward the right when shrinking widget.
  5266. {
  5267. // Update some data if we are active or last active
  5268. edit_state.Width = w + style.FramePadding.x;
  5269. edit_state.BufSizeA = buf_size;
  5270. edit_state.Font = window->Font();
  5271. edit_state.FontSize = window->FontSize();
  5272. edit_state.UpdateScrollOffset();
  5273. }
  5274. if (g.ActiveId == id)
  5275. {
  5276. // Edit in progress
  5277. const float mx = g.IO.MousePos.x - frame_bb.Min.x - style.FramePadding.x;
  5278. const float my = window->FontSize()*0.5f; // Flatten mouse because we are doing a single-line edit
  5279. if (select_all || (hovered && io.MouseDoubleClicked[0]))
  5280. {
  5281. edit_state.SelectAll();
  5282. edit_state.SelectedAllMouseLock = true;
  5283. }
  5284. else if (io.MouseClicked[0] && !edit_state.SelectedAllMouseLock)
  5285. {
  5286. stb_textedit_click(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my);
  5287. edit_state.CursorAnimReset();
  5288. }
  5289. else if (io.MouseDown[0] && !edit_state.SelectedAllMouseLock)
  5290. {
  5291. stb_textedit_drag(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my);
  5292. edit_state.CursorAnimReset();
  5293. }
  5294. if (edit_state.SelectedAllMouseLock && !io.MouseDown[0])
  5295. edit_state.SelectedAllMouseLock = false;
  5296. if (g.IO.InputCharacters[0])
  5297. {
  5298. // Process text input (before we check for Return because using some IME will effectively send a Return?)
  5299. for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++)
  5300. {
  5301. unsigned int c = (unsigned int)g.IO.InputCharacters[n];
  5302. if (c)
  5303. {
  5304. // Insert character if they pass filtering
  5305. if (!InputTextFilterCharacter(&c, flags, callback, user_data))
  5306. continue;
  5307. edit_state.OnKeyPressed((int)c);
  5308. }
  5309. }
  5310. // Consume characters
  5311. memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
  5312. }
  5313. const int k_mask = (is_shift_down ? STB_TEXTEDIT_K_SHIFT : 0);
  5314. if (IsKeyPressedMap(ImGuiKey_LeftArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDLEFT | k_mask : STB_TEXTEDIT_K_LEFT | k_mask); }
  5315. else if (IsKeyPressedMap(ImGuiKey_RightArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDRIGHT | k_mask : STB_TEXTEDIT_K_RIGHT | k_mask); }
  5316. else if (IsKeyPressedMap(ImGuiKey_Home)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); }
  5317. else if (IsKeyPressedMap(ImGuiKey_End)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); }
  5318. else if (IsKeyPressedMap(ImGuiKey_Delete)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); }
  5319. else if (IsKeyPressedMap(ImGuiKey_Backspace)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask); }
  5320. else if (IsKeyPressedMap(ImGuiKey_Enter)) { SetActiveId(0); enter_pressed = true; }
  5321. else if (IsKeyPressedMap(ImGuiKey_Escape)) { SetActiveId(0); cancel_edit = true; }
  5322. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Z)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_UNDO); }
  5323. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Y)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_REDO); }
  5324. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_A)) { edit_state.SelectAll(); }
  5325. else if (is_ctrl_down && (IsKeyPressedMap(ImGuiKey_X) || IsKeyPressedMap(ImGuiKey_C)))
  5326. {
  5327. // Cut, Copy
  5328. const bool cut = IsKeyPressedMap(ImGuiKey_X);
  5329. if (cut && !edit_state.HasSelection())
  5330. edit_state.SelectAll();
  5331. if (g.IO.SetClipboardTextFn)
  5332. {
  5333. const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0;
  5334. const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : (int)edit_state.CurLenW;
  5335. ImTextStrToUtf8(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), edit_state.Text+ib, edit_state.Text+ie);
  5336. g.IO.SetClipboardTextFn(g.TempBuffer);
  5337. }
  5338. if (cut)
  5339. stb_textedit_cut(&edit_state, &edit_state.StbState);
  5340. }
  5341. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_V))
  5342. {
  5343. // Paste
  5344. if (g.IO.GetClipboardTextFn)
  5345. {
  5346. if (const char* clipboard = g.IO.GetClipboardTextFn())
  5347. {
  5348. // Remove new-line from pasted buffer
  5349. const size_t clipboard_len = strlen(clipboard);
  5350. ImWchar* clipboard_filtered = (ImWchar*)ImGui::MemAlloc((clipboard_len+1) * sizeof(ImWchar));
  5351. int clipboard_filtered_len = 0;
  5352. for (const char* s = clipboard; *s; )
  5353. {
  5354. unsigned int c;
  5355. s += ImTextCharFromUtf8(&c, s, NULL);
  5356. if (c == 0)
  5357. break;
  5358. if (c >= 0x10000)
  5359. continue;
  5360. if (!InputTextFilterCharacter(&c, flags, callback, user_data))
  5361. continue;
  5362. clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c;
  5363. }
  5364. clipboard_filtered[clipboard_filtered_len] = 0;
  5365. if (clipboard_filtered_len > 0) // If everything was filtered, ignore the pasting operation
  5366. stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len);
  5367. ImGui::MemFree(clipboard_filtered);
  5368. }
  5369. }
  5370. }
  5371. edit_state.CursorAnim += g.IO.DeltaTime;
  5372. edit_state.UpdateScrollOffset();
  5373. if (cancel_edit)
  5374. {
  5375. // Restore initial value
  5376. ImFormatString(buf, buf_size, "%s", edit_state.InitialText);
  5377. value_changed = true;
  5378. }
  5379. else
  5380. {
  5381. // Apply new value immediately - copy modified buffer back
  5382. // Note that as soon as we can focus into the input box, the in-widget value gets priority over any underlying modification of the input buffer
  5383. // FIXME: We actually always render 'buf' in RenderTextScrolledClipped
  5384. // FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks
  5385. ImTextStrToUtf8(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), edit_state.Text, NULL);
  5386. // User callback
  5387. if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways)) != 0)
  5388. {
  5389. IM_ASSERT(callback != NULL);
  5390. // The reason we specify the usage semantic (Completion/History) is that Completion needs to disable keyboard TABBING at the moment.
  5391. ImGuiInputTextFlags event_flag = 0;
  5392. ImGuiKey event_key = ImGuiKey_COUNT;
  5393. if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && IsKeyPressedMap(ImGuiKey_Tab))
  5394. {
  5395. event_flag = ImGuiInputTextFlags_CallbackCompletion;
  5396. event_key = ImGuiKey_Tab;
  5397. }
  5398. else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_UpArrow))
  5399. {
  5400. event_flag = ImGuiInputTextFlags_CallbackHistory;
  5401. event_key = ImGuiKey_UpArrow;
  5402. }
  5403. else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_DownArrow))
  5404. {
  5405. event_flag = ImGuiInputTextFlags_CallbackHistory;
  5406. event_key = ImGuiKey_DownArrow;
  5407. }
  5408. if (event_key != ImGuiKey_COUNT || (flags & ImGuiInputTextFlags_CallbackAlways) != 0)
  5409. {
  5410. ImGuiTextEditCallbackData callback_data;
  5411. callback_data.EventFlag = event_flag;
  5412. callback_data.EventKey = event_key;
  5413. callback_data.Buf = g.TempBuffer;
  5414. callback_data.BufSize = edit_state.BufSizeA;
  5415. callback_data.BufDirty = false;
  5416. callback_data.Flags = flags;
  5417. callback_data.UserData = user_data;
  5418. // We have to convert from position from wchar to UTF-8 positions
  5419. const int utf8_cursor_pos = callback_data.CursorPos = ImTextCountUtf8BytesFromStr(edit_state.Text, edit_state.Text + edit_state.StbState.cursor);
  5420. const int utf8_selection_start = callback_data.SelectionStart = ImTextCountUtf8BytesFromStr(edit_state.Text, edit_state.Text + edit_state.StbState.select_start);
  5421. const int utf8_selection_end = callback_data.SelectionEnd = ImTextCountUtf8BytesFromStr(edit_state.Text, edit_state.Text + edit_state.StbState.select_end);
  5422. // Call user code
  5423. callback(&callback_data);
  5424. // Read back what user may have modified
  5425. IM_ASSERT(callback_data.Buf == g.TempBuffer); // Invalid to modify those fields
  5426. IM_ASSERT(callback_data.BufSize == edit_state.BufSizeA);
  5427. IM_ASSERT(callback_data.Flags == flags);
  5428. if (callback_data.CursorPos != utf8_cursor_pos) edit_state.StbState.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos);
  5429. if (callback_data.SelectionStart != utf8_selection_start) edit_state.StbState.select_start = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionStart);
  5430. if (callback_data.SelectionEnd != utf8_selection_end) edit_state.StbState.select_end = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionEnd);
  5431. if (callback_data.BufDirty)
  5432. {
  5433. ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), g.TempBuffer, NULL);
  5434. edit_state.CursorAnimReset();
  5435. }
  5436. }
  5437. }
  5438. if (strcmp(g.TempBuffer, buf) != 0)
  5439. {
  5440. ImFormatString(buf, buf_size, "%s", g.TempBuffer);
  5441. value_changed = true;
  5442. }
  5443. }
  5444. }
  5445. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  5446. const ImVec2 font_off_up = ImVec2(0.0f,window->FontSize()+1.0f); // FIXME: those offsets are part of the style or font API
  5447. const ImVec2 font_off_dn = ImVec2(0.0f,2.0f);
  5448. if (g.ActiveId == id)
  5449. {
  5450. // Draw selection
  5451. const int select_begin_idx = edit_state.StbState.select_start;
  5452. const int select_end_idx = edit_state.StbState.select_end;
  5453. if (select_begin_idx != select_end_idx)
  5454. {
  5455. const ImVec2 select_begin_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMin(select_begin_idx,select_end_idx));
  5456. const ImVec2 select_end_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMax(select_begin_idx,select_end_idx));
  5457. window->DrawList->AddRectFilled(select_begin_pos - font_off_up, select_end_pos + font_off_dn, window->Color(ImGuiCol_TextSelectedBg));
  5458. }
  5459. }
  5460. //const float render_scroll_x = (g.ActiveId == id) ? edit_state.ScrollX : 0.0f;
  5461. const float render_scroll_x = (edit_state.Id == id) ? edit_state.ScrollX : 0.0f;
  5462. ImGuiTextEditState::RenderTextScrolledClipped(window->Font(), window->FontSize(), buf, frame_bb.Min + style.FramePadding, w + style.FramePadding.x, render_scroll_x);
  5463. if (g.ActiveId == id)
  5464. {
  5465. const ImVec2 cursor_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(edit_state.StbState.cursor);
  5466. // Draw blinking cursor
  5467. if (g.InputTextState.CursorIsVisible())
  5468. window->DrawList->AddRect(cursor_pos - font_off_up + ImVec2(0,2), cursor_pos + font_off_dn - ImVec2(0,3), window->Color(ImGuiCol_Text));
  5469. // Notify OS of text input position for advanced IME
  5470. if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.InputCursorScreenPos - cursor_pos) > 0.0001f)
  5471. io.ImeSetInputScreenPosFn((int)cursor_pos.x - 1, (int)(cursor_pos.y - window->FontSize())); // -1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety.
  5472. edit_state.InputCursorScreenPos = cursor_pos;
  5473. }
  5474. if (label_size.x > 0)
  5475. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  5476. if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0)
  5477. return enter_pressed;
  5478. else
  5479. return value_changed;
  5480. }
  5481. static bool InputFloatN(const char* label, float* v, int components, int decimal_precision)
  5482. {
  5483. ImGuiState& g = *GImGui;
  5484. ImGuiWindow* window = GetCurrentWindow();
  5485. if (window->SkipItems)
  5486. return false;
  5487. const ImGuiStyle& style = g.Style;
  5488. const float w_full = ImGui::CalcItemWidth();
  5489. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components));
  5490. const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)));
  5491. bool value_changed = false;
  5492. ImGui::BeginGroup();
  5493. ImGui::PushID(label);
  5494. ImGui::PushItemWidth(w_item_one);
  5495. for (int i = 0; i < components; i++)
  5496. {
  5497. ImGui::PushID(i);
  5498. if (i + 1 == components)
  5499. {
  5500. ImGui::PopItemWidth();
  5501. ImGui::PushItemWidth(w_item_last);
  5502. }
  5503. value_changed |= ImGui::InputFloat("##v", &v[i], 0, 0, decimal_precision);
  5504. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5505. ImGui::PopID();
  5506. }
  5507. ImGui::PopItemWidth();
  5508. ImGui::PopID();
  5509. window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, style.FramePadding.y);
  5510. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  5511. ImGui::EndGroup();
  5512. return value_changed;
  5513. }
  5514. bool ImGui::InputFloat2(const char* label, float v[2], int decimal_precision)
  5515. {
  5516. return InputFloatN(label, v, 2, decimal_precision);
  5517. }
  5518. bool ImGui::InputFloat3(const char* label, float v[3], int decimal_precision)
  5519. {
  5520. return InputFloatN(label, v, 3, decimal_precision);
  5521. }
  5522. bool ImGui::InputFloat4(const char* label, float v[4], int decimal_precision)
  5523. {
  5524. return InputFloatN(label, v, 4, decimal_precision);
  5525. }
  5526. static bool InputIntN(const char* label, int* v, int components)
  5527. {
  5528. ImGuiState& g = *GImGui;
  5529. ImGuiWindow* window = GetCurrentWindow();
  5530. if (window->SkipItems)
  5531. return false;
  5532. const ImGuiStyle& style = g.Style;
  5533. const float w_full = ImGui::CalcItemWidth();
  5534. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components));
  5535. const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)));
  5536. bool value_changed = false;
  5537. ImGui::BeginGroup();
  5538. ImGui::PushID(label);
  5539. ImGui::PushItemWidth(w_item_one);
  5540. for (int i = 0; i < components; i++)
  5541. {
  5542. ImGui::PushID(i);
  5543. if (i + 1 == components)
  5544. {
  5545. ImGui::PopItemWidth();
  5546. ImGui::PushItemWidth(w_item_last);
  5547. }
  5548. value_changed |= ImGui::InputInt("##v", &v[i], 0, 0);
  5549. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5550. ImGui::PopID();
  5551. }
  5552. ImGui::PopItemWidth();
  5553. ImGui::PopID();
  5554. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  5555. ImGui::EndGroup();
  5556. return value_changed;
  5557. }
  5558. bool ImGui::InputInt2(const char* label, int v[2])
  5559. {
  5560. return InputIntN(label, v, 2);
  5561. }
  5562. bool ImGui::InputInt3(const char* label, int v[3])
  5563. {
  5564. return InputIntN(label, v, 3);
  5565. }
  5566. bool ImGui::InputInt4(const char* label, int v[4])
  5567. {
  5568. return InputIntN(label, v, 4);
  5569. }
  5570. static bool Items_ArrayGetter(void* data, int idx, const char** out_text)
  5571. {
  5572. const char** items = (const char**)data;
  5573. if (out_text)
  5574. *out_text = items[idx];
  5575. return true;
  5576. }
  5577. static bool Items_SingleStringGetter(void* data, int idx, const char** out_text)
  5578. {
  5579. // FIXME-OPT: we could pre-compute the indices to fasten this. But only 1 active combo means the waste is limited.
  5580. const char* items_separated_by_zeros = (const char*)data;
  5581. int items_count = 0;
  5582. const char* p = items_separated_by_zeros;
  5583. while (*p)
  5584. {
  5585. if (idx == items_count)
  5586. break;
  5587. p += strlen(p) + 1;
  5588. items_count++;
  5589. }
  5590. if (!*p)
  5591. return false;
  5592. if (out_text)
  5593. *out_text = p;
  5594. return true;
  5595. }
  5596. // Combo box helper allowing to pass an array of strings.
  5597. bool ImGui::Combo(const char* label, int* current_item, const char** items, int items_count, int height_in_items)
  5598. {
  5599. const bool value_changed = Combo(label, current_item, Items_ArrayGetter, (void*)items, items_count, height_in_items);
  5600. return value_changed;
  5601. }
  5602. // Combo box helper allowing to pass all items in a single string.
  5603. bool ImGui::Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int height_in_items)
  5604. {
  5605. int items_count = 0;
  5606. const char* p = items_separated_by_zeros; // FIXME-OPT: Avoid computing this
  5607. while (*p)
  5608. {
  5609. p += strlen(p) + 1;
  5610. items_count++;
  5611. }
  5612. bool value_changed = Combo(label, current_item, Items_SingleStringGetter, (void*)items_separated_by_zeros, items_count, height_in_items);
  5613. return value_changed;
  5614. }
  5615. // Combo box function.
  5616. bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int height_in_items)
  5617. {
  5618. ImGuiState& g = *GImGui;
  5619. ImGuiWindow* window = GetCurrentWindow();
  5620. if (window->SkipItems)
  5621. return false;
  5622. const ImGuiStyle& style = g.Style;
  5623. const ImGuiID id = window->GetID(label);
  5624. const float w = ImGui::CalcItemWidth();
  5625. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5626. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
  5627. const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + label_size.x,0));
  5628. ItemSize(total_bb, style.FramePadding.y);
  5629. if (!ItemAdd(total_bb, &id))
  5630. return false;
  5631. const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f);
  5632. const bool hovered = IsHovered(frame_bb, id);
  5633. bool value_changed = false;
  5634. const ImRect value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f));
  5635. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  5636. RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, window->Color(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button), true, style.FrameRounding); // FIXME-ROUNDING
  5637. RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true);
  5638. if (*current_item >= 0 && *current_item < items_count)
  5639. {
  5640. const char* item_text;
  5641. if (items_getter(data, *current_item, &item_text))
  5642. RenderTextClipped(frame_bb.Min + style.FramePadding, item_text, NULL, NULL, value_bb.Max);
  5643. }
  5644. if (label_size.x > 0)
  5645. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  5646. ImGui::PushID((int)id);
  5647. bool menu_toggled = false;
  5648. if (hovered)
  5649. {
  5650. g.HoveredId = id;
  5651. if (g.IO.MouseClicked[0])
  5652. {
  5653. menu_toggled = true;
  5654. g.ActiveComboID = (g.ActiveComboID == id) ? 0 : id;
  5655. if (g.ActiveComboID)
  5656. FocusWindow(window);
  5657. }
  5658. }
  5659. if (g.ActiveComboID == id)
  5660. {
  5661. // Size default to hold ~7 items
  5662. if (height_in_items < 0)
  5663. height_in_items = 7;
  5664. const ImVec2 backup_pos = ImGui::GetCursorPos();
  5665. const float popup_off_x = 0.0f;//style.ItemInnerSpacing.x;
  5666. const float popup_height = (label_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + style.WindowPadding.y;
  5667. const ImRect popup_rect(ImVec2(frame_bb.Min.x+popup_off_x, frame_bb.Max.y), ImVec2(frame_bb.Max.x+popup_off_x, frame_bb.Max.y + popup_height));
  5668. ImGui::SetCursorPos(popup_rect.Min - window->Pos);
  5669. const ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ((window->Flags & ImGuiWindowFlags_ShowBorders) ? ImGuiWindowFlags_ShowBorders : 0);
  5670. ImGui::BeginChild("#ComboBox", popup_rect.GetSize(), false, flags);
  5671. ImGui::Spacing();
  5672. bool combo_item_active = false;
  5673. combo_item_active |= (g.ActiveId == GetCurrentWindow()->GetID("#SCROLLY"));
  5674. // Display items
  5675. for (int i = 0; i < items_count; i++)
  5676. {
  5677. ImGui::PushID((void*)(intptr_t)i);
  5678. const bool item_selected = (i == *current_item);
  5679. const char* item_text;
  5680. if (!items_getter(data, i, &item_text))
  5681. item_text = "*Unknown item*";
  5682. if (ImGui::Selectable(item_text, item_selected))
  5683. {
  5684. SetActiveId(0);
  5685. g.ActiveComboID = 0;
  5686. value_changed = true;
  5687. *current_item = i;
  5688. }
  5689. if (item_selected && menu_toggled)
  5690. ImGui::SetScrollPosHere();
  5691. combo_item_active |= ImGui::IsItemActive();
  5692. ImGui::PopID();
  5693. }
  5694. ImGui::EndChild();
  5695. ImGui::SetCursorPos(backup_pos);
  5696. if (!combo_item_active && g.ActiveId != 0)
  5697. g.ActiveComboID = 0;
  5698. }
  5699. ImGui::PopID();
  5700. return value_changed;
  5701. }
  5702. // Tip: pass an empty label (e.g. "##dummy") then you can use the space to draw other text or image.
  5703. // But you need to make sure the ID is unique, e.g. enclose calls in PushID/PopID.
  5704. bool ImGui::Selectable(const char* label, bool selected, const ImVec2& size_arg)
  5705. {
  5706. ImGuiState& g = *GImGui;
  5707. ImGuiWindow* window = GetCurrentWindow();
  5708. if (window->SkipItems)
  5709. return false;
  5710. const ImGuiStyle& style = g.Style;
  5711. const ImGuiID id = window->GetID(label);
  5712. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5713. const float w = ImMax(label_size.x, window->Pos.x + ImGui::GetContentRegionMax().x - style.AutoFitPadding.x - window->DC.CursorPos.x);
  5714. const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : w, size_arg.y != 0.0f ? size_arg.y : label_size.y);
  5715. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
  5716. ItemSize(bb);
  5717. // Selectables are meant to be tightly packed together. So for both rendering and collision we extend to compensate for spacing.
  5718. ImRect bb_with_spacing = bb;
  5719. const float spacing_L = (float)(int)(style.ItemSpacing.x * 0.5f);
  5720. const float spacing_U = (float)(int)(style.ItemSpacing.y * 0.5f);
  5721. const float spacing_R = style.ItemSpacing.x - spacing_L;
  5722. const float spacing_D = style.ItemSpacing.y - spacing_U;
  5723. bb_with_spacing.Min.x -= spacing_L;
  5724. bb_with_spacing.Min.y -= spacing_U;
  5725. bb_with_spacing.Max.x += spacing_R;
  5726. bb_with_spacing.Max.y += spacing_D;
  5727. if (!ItemAdd(bb_with_spacing, &id))
  5728. return false;
  5729. bool hovered, held;
  5730. bool pressed = ButtonBehavior(bb_with_spacing, id, &hovered, &held, true, false, false);
  5731. // Render
  5732. if (hovered || selected)
  5733. {
  5734. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
  5735. RenderFrame(bb_with_spacing.Min, bb_with_spacing.Max, col, false, style.FrameRounding);
  5736. }
  5737. //const ImVec2 off = ImVec2(ImMax(0.0f, size.x - text_size.x) * 0.5f, ImMax(0.0f, size.y - text_size.y) * 0.5f);
  5738. RenderTextClipped(bb.Min, label, NULL, &label_size, bb_with_spacing.Max);
  5739. return pressed;
  5740. }
  5741. bool ImGui::Selectable(const char* label, bool* p_selected, const ImVec2& size_arg)
  5742. {
  5743. if (ImGui::Selectable(label, *p_selected, size_arg))
  5744. {
  5745. *p_selected = !*p_selected;
  5746. return true;
  5747. }
  5748. return false;
  5749. }
  5750. // Helper to calculate the size of a listbox and display a label on the right.
  5751. // Tip: To have a list filling the entire window width, PushItemWidth(-1) and pass an empty label "##empty"
  5752. bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg)
  5753. {
  5754. ImGuiWindow* window = GetCurrentWindow();
  5755. const ImGuiStyle& style = ImGui::GetStyle();
  5756. const ImGuiID id = ImGui::GetID(label);
  5757. const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
  5758. // Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar.
  5759. ImVec2 size;
  5760. size.x = (size_arg.x != 0.0f) ? (size_arg.x) : ImGui::CalcItemWidth() + style.FramePadding.x * 2.0f;
  5761. size.y = (size_arg.y != 0.0f) ? (size_arg.y) : ImGui::GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y;
  5762. const ImVec2 frame_size = ImVec2(size.x, ImMax(size.y, label_size.y));
  5763. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
  5764. const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
  5765. window->DC.LastItemRect = bb;
  5766. ImGui::BeginGroup();
  5767. if (label_size.x > 0)
  5768. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  5769. ImGui::BeginChildFrame(id, frame_bb.GetSize());
  5770. return true;
  5771. }
  5772. bool ImGui::ListBoxHeader(const char* label, int items_count, int height_in_items)
  5773. {
  5774. // Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar.
  5775. // However we don't add +0.40f if items_count <= height_in_items. It is slightly dodgy, because it means a dynamic list of items will make the widget resize occasionally when it crosses that size.
  5776. // I am expecting that someone will come and complain about this behavior in a remote future, then we can advise on a better solution.
  5777. if (height_in_items < 0)
  5778. height_in_items = ImMin(items_count, 7);
  5779. float height_in_items_f = height_in_items < items_count ? (height_in_items + 0.40f) : (height_in_items + 0.00f);
  5780. // We include ItemSpacing.y so that a list sized for the exact number of items doesn't make a scrollbar appears. We could also enforce that by passing a flag to BeginChild().
  5781. ImVec2 size;
  5782. size.x = 0.0f;
  5783. size.y = ImGui::GetTextLineHeightWithSpacing() * height_in_items_f + ImGui::GetStyle().ItemSpacing.y;
  5784. return ImGui::ListBoxHeader(label, size);
  5785. }
  5786. void ImGui::ListBoxFooter()
  5787. {
  5788. ImGuiWindow* parent_window = GetParentWindow();
  5789. const ImRect bb = parent_window->DC.LastItemRect;
  5790. const ImGuiStyle& style = ImGui::GetStyle();
  5791. ImGui::EndChildFrame();
  5792. // Redeclare item size so that it includes the label (we have stored the full size in LastItemRect)
  5793. // We call SameLine() to restore DC.CurrentLine* data
  5794. ImGui::SameLine();
  5795. parent_window->DC.CursorPos = bb.Min;
  5796. ItemSize(bb, style.FramePadding.y);
  5797. ImGui::EndGroup();
  5798. }
  5799. bool ImGui::ListBox(const char* label, int* current_item, const char** items, int items_count, int height_items)
  5800. {
  5801. const bool value_changed = ListBox(label, current_item, Items_ArrayGetter, (void*)items, items_count, height_items);
  5802. return value_changed;
  5803. }
  5804. bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int height_in_items)
  5805. {
  5806. ImGuiWindow* window = GetCurrentWindow();
  5807. if (window->SkipItems)
  5808. return false;
  5809. if (!ImGui::ListBoxHeader(label, items_count, height_in_items))
  5810. return false;
  5811. bool value_changed = false;
  5812. for (int i = 0; i < items_count; i++)
  5813. {
  5814. const bool item_selected = (i == *current_item);
  5815. const char* item_text;
  5816. if (!items_getter(data, i, &item_text))
  5817. item_text = "*Unknown item*";
  5818. ImGui::PushID(i);
  5819. if (ImGui::Selectable(item_text, item_selected))
  5820. {
  5821. *current_item = i;
  5822. value_changed = true;
  5823. }
  5824. ImGui::PopID();
  5825. }
  5826. ImGui::ListBoxFooter();
  5827. return value_changed;
  5828. }
  5829. // A little colored square. Return true when clicked.
  5830. bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_border)
  5831. {
  5832. ImGuiState& g = *GImGui;
  5833. ImGuiWindow* window = GetCurrentWindow();
  5834. if (window->SkipItems)
  5835. return false;
  5836. const ImGuiStyle& style = g.Style;
  5837. const ImGuiID id = window->GetID("#colorbutton");
  5838. const float square_size = window->FontSize();
  5839. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(square_size + style.FramePadding.x*2, square_size + (small_height ? 0 : style.FramePadding.y*2)));
  5840. ItemSize(bb, small_height ? 0.0f : style.FramePadding.y);
  5841. if (!ItemAdd(bb, &id))
  5842. return false;
  5843. bool hovered, held;
  5844. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  5845. RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border, style.FrameRounding);
  5846. if (hovered)
  5847. {
  5848. int ix = (int)(col.x * 255.0f + 0.5f);
  5849. int iy = (int)(col.y * 255.0f + 0.5f);
  5850. int iz = (int)(col.z * 255.0f + 0.5f);
  5851. int iw = (int)(col.w * 255.0f + 0.5f);
  5852. ImGui::SetTooltip("Color:\n(%.2f,%.2f,%.2f,%.2f)\n#%02X%02X%02X%02X", col.x, col.y, col.z, col.w, ix, iy, iz, iw);
  5853. }
  5854. return pressed;
  5855. }
  5856. bool ImGui::ColorEdit3(const char* label, float col[3])
  5857. {
  5858. float col4[4];
  5859. col4[0] = col[0];
  5860. col4[1] = col[1];
  5861. col4[2] = col[2];
  5862. col4[3] = 1.0f;
  5863. const bool value_changed = ImGui::ColorEdit4(label, col4, false);
  5864. col[0] = col4[0];
  5865. col[1] = col4[1];
  5866. col[2] = col4[2];
  5867. return value_changed;
  5868. }
  5869. // Edit colors components (each component in 0.0f..1.0f range
  5870. // Use CTRL-Click to input value and TAB to go to next item.
  5871. bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha)
  5872. {
  5873. ImGuiState& g = *GImGui;
  5874. ImGuiWindow* window = GetCurrentWindow();
  5875. if (window->SkipItems)
  5876. return false;
  5877. const ImGuiStyle& style = g.Style;
  5878. const ImGuiID id = window->GetID(label);
  5879. const float w_full = ImGui::CalcItemWidth();
  5880. const float square_sz = (window->FontSize() + style.FramePadding.x * 2.0f);
  5881. ImGuiColorEditMode edit_mode = window->DC.ColorEditMode;
  5882. if (edit_mode == ImGuiColorEditMode_UserSelect || edit_mode == ImGuiColorEditMode_UserSelectShowButton)
  5883. edit_mode = g.ColorEditModeStorage.GetInt(id, 0) % 3;
  5884. float fx = col[0];
  5885. float fy = col[1];
  5886. float fz = col[2];
  5887. float fw = col[3];
  5888. const ImVec4 col_display(fx, fy, fz, 1.0f);
  5889. if (edit_mode == ImGuiColorEditMode_HSV)
  5890. ImGui::ColorConvertRGBtoHSV(fx, fy, fz, fx, fy, fz);
  5891. int ix = (int)(fx * 255.0f + 0.5f);
  5892. int iy = (int)(fy * 255.0f + 0.5f);
  5893. int iz = (int)(fz * 255.0f + 0.5f);
  5894. int iw = (int)(fw * 255.0f + 0.5f);
  5895. int components = alpha ? 4 : 3;
  5896. bool value_changed = false;
  5897. ImGui::BeginGroup();
  5898. ImGui::PushID(label);
  5899. bool hsv = (edit_mode == 1);
  5900. switch (edit_mode)
  5901. {
  5902. case ImGuiColorEditMode_RGB:
  5903. case ImGuiColorEditMode_HSV:
  5904. {
  5905. // 0: RGB 0..255 Sliders
  5906. // 1: HSV 0..255 Sliders
  5907. const float w_items_all = w_full - (square_sz + style.ItemInnerSpacing.x);
  5908. const float w_item_one = ImMax(1.0f, (float)(int)((w_items_all - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components));
  5909. const float w_item_last = ImMax(1.0f, (float)(int)(w_items_all - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)));
  5910. ImGui::PushItemWidth(w_item_one);
  5911. value_changed |= ImGui::SliderInt("##X", &ix, 0, 255, hsv ? "H:%3.0f" : "R:%3.0f");
  5912. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5913. value_changed |= ImGui::SliderInt("##Y", &iy, 0, 255, hsv ? "S:%3.0f" : "G:%3.0f");
  5914. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5915. if (alpha)
  5916. {
  5917. value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f");
  5918. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5919. ImGui::PushItemWidth(w_item_last);
  5920. value_changed |= ImGui::SliderInt("##W", &iw, 0, 255, "A:%3.0f");
  5921. }
  5922. else
  5923. {
  5924. ImGui::PushItemWidth(w_item_last);
  5925. value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f");
  5926. }
  5927. ImGui::PopItemWidth();
  5928. ImGui::PopItemWidth();
  5929. }
  5930. break;
  5931. case ImGuiColorEditMode_HEX:
  5932. {
  5933. // 2: RGB Hexadecimal
  5934. const float w_slider_all = w_full - square_sz;
  5935. char buf[64];
  5936. if (alpha)
  5937. ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X%02X", ix, iy, iz, iw);
  5938. else
  5939. ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X", ix, iy, iz);
  5940. ImGui::PushItemWidth(w_slider_all - style.ItemInnerSpacing.x);
  5941. value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal);
  5942. ImGui::PopItemWidth();
  5943. char* p = buf;
  5944. while (*p == '#' || ImCharIsSpace(*p))
  5945. p++;
  5946. // Treat at unsigned (%X is unsigned)
  5947. ix = iy = iz = iw = 0;
  5948. if (alpha)
  5949. sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz, (unsigned int*)&iw);
  5950. else
  5951. sscanf(p, "%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz);
  5952. }
  5953. break;
  5954. }
  5955. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5956. if (ImGui::ColorButton(col_display))
  5957. {
  5958. // Don't set local copy of 'edit_mode' right away!
  5959. g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3);
  5960. }
  5961. if (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelectShowButton)
  5962. {
  5963. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5964. const char* button_titles[3] = { "RGB", "HSV", "HEX" };
  5965. if (ImGui::Button(button_titles[edit_mode]))
  5966. {
  5967. // Don't set local copy of 'edit_mode' right away!
  5968. g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3);
  5969. }
  5970. ImGui::SameLine();
  5971. }
  5972. else
  5973. {
  5974. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5975. }
  5976. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  5977. // Convert back
  5978. fx = ix / 255.0f;
  5979. fy = iy / 255.0f;
  5980. fz = iz / 255.0f;
  5981. fw = iw / 255.0f;
  5982. if (edit_mode == 1)
  5983. ImGui::ColorConvertHSVtoRGB(fx, fy, fz, fx, fy, fz);
  5984. if (value_changed)
  5985. {
  5986. col[0] = fx;
  5987. col[1] = fy;
  5988. col[2] = fz;
  5989. if (alpha)
  5990. col[3] = fw;
  5991. }
  5992. ImGui::PopID();
  5993. ImGui::EndGroup();
  5994. return value_changed;
  5995. }
  5996. void ImGui::ColorEditMode(ImGuiColorEditMode mode)
  5997. {
  5998. ImGuiWindow* window = GetCurrentWindow();
  5999. window->DC.ColorEditMode = mode;
  6000. }
  6001. // Horizontal separating line.
  6002. void ImGui::Separator()
  6003. {
  6004. ImGuiWindow* window = GetCurrentWindow();
  6005. if (window->SkipItems)
  6006. return;
  6007. if (window->DC.ColumnsCount > 1)
  6008. PopClipRect();
  6009. const ImRect bb(ImVec2(window->Pos.x, window->DC.CursorPos.y), ImVec2(window->Pos.x + window->Size.x, window->DC.CursorPos.y));
  6010. ItemSize(ImVec2(0.0f, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit
  6011. if (!ItemAdd(bb, NULL))
  6012. {
  6013. if (window->DC.ColumnsCount > 1)
  6014. PushColumnClipRect();
  6015. return;
  6016. }
  6017. window->DrawList->AddLine(bb.Min, bb.Max, window->Color(ImGuiCol_Border));
  6018. ImGuiState& g = *GImGui;
  6019. if (g.LogEnabled)
  6020. ImGui::LogText(STR_NEWLINE "--------------------------------");
  6021. if (window->DC.ColumnsCount > 1)
  6022. {
  6023. PushColumnClipRect();
  6024. window->DC.ColumnsCellMinY = window->DC.CursorPos.y;
  6025. }
  6026. }
  6027. // A little vertical spacing.
  6028. void ImGui::Spacing()
  6029. {
  6030. ImGuiWindow* window = GetCurrentWindow();
  6031. if (window->SkipItems)
  6032. return;
  6033. ItemSize(ImVec2(0,0));
  6034. }
  6035. // Advance cursor given item size.
  6036. static void ItemSize(ImVec2 size, float text_offset_y)
  6037. {
  6038. ImGuiState& g = *GImGui;
  6039. ImGuiWindow* window = GetCurrentWindow();
  6040. if (window->SkipItems)
  6041. return;
  6042. // Always align ourselves on pixel boundaries
  6043. const float line_height = ImMax(window->DC.CurrentLineHeight, size.y);
  6044. const float text_base_offset = ImMax(window->DC.CurrentLineTextBaseOffset, text_offset_y);
  6045. window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y);
  6046. window->DC.CursorPos = ImVec2((float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX), (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y));
  6047. window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x);
  6048. window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y);
  6049. //window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, 0xFF0000FF, 4); // Debug
  6050. window->DC.PrevLineHeight = line_height;
  6051. window->DC.PrevLineTextBaseOffset = text_base_offset;
  6052. window->DC.CurrentLineHeight = window->DC.CurrentLineTextBaseOffset = 0.0f;
  6053. }
  6054. static inline void ItemSize(const ImRect& bb, float text_offset_y)
  6055. {
  6056. ItemSize(bb.GetSize(), text_offset_y);
  6057. }
  6058. static bool IsClipped(const ImRect& bb)
  6059. {
  6060. ImGuiState& g = *GImGui;
  6061. ImGuiWindow* window = GetCurrentWindow();
  6062. if (!bb.Overlaps(ImRect(window->ClipRectStack.back())) && !g.LogEnabled)
  6063. return true;
  6064. return false;
  6065. }
  6066. bool ImGui::IsClipped(const ImVec2& item_size)
  6067. {
  6068. ImGuiWindow* window = GetCurrentWindow();
  6069. return IsClipped(ImRect(window->DC.CursorPos, window->DC.CursorPos + item_size));
  6070. }
  6071. static bool ItemAdd(const ImRect& bb, const ImGuiID* id)
  6072. {
  6073. ImGuiWindow* window = GetCurrentWindow();
  6074. window->DC.LastItemID = id ? *id : 0;
  6075. window->DC.LastItemRect = bb;
  6076. if (IsClipped(bb))
  6077. {
  6078. window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = false;
  6079. return false;
  6080. }
  6081. // This is a sensible default, but widgets are free to override it after calling ItemAdd()
  6082. ImGuiState& g = *GImGui;
  6083. if (IsMouseHoveringRect(bb))
  6084. {
  6085. // Matching the behavior of IsHovered() but ignore if ActiveId==window->MoveID (we clicked on the window background)
  6086. // So that clicking on items with no active id such as Text() still returns true with IsItemHovered()
  6087. window->DC.LastItemHoveredRect = true;
  6088. window->DC.LastItemHoveredAndUsable = false;
  6089. if (g.ActiveId == 0 || (id && g.ActiveId == *id) || g.ActiveIdIsFocusedOnly || (g.ActiveId == window->MoveID))
  6090. if (IsWindowContentHoverable(window))
  6091. window->DC.LastItemHoveredAndUsable = true;
  6092. }
  6093. else
  6094. {
  6095. window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = false;
  6096. }
  6097. return true;
  6098. }
  6099. void ImGui::BeginGroup()
  6100. {
  6101. ImGuiWindow* window = GetCurrentWindow();
  6102. window->DC.GroupStack.resize(window->DC.GroupStack.size() + 1);
  6103. ImGuiGroupData& group_data = window->DC.GroupStack.back();
  6104. group_data.BackupCursorPos = window->DC.CursorPos;
  6105. group_data.BackupCursorMaxPos = window->DC.CursorMaxPos;
  6106. group_data.BackupColumnsStartX = window->DC.ColumnsStartX;
  6107. group_data.BackupCurrentLineHeight = window->DC.CurrentLineHeight;
  6108. group_data.BackupCurrentLineTextBaseOffset = window->DC.CurrentLineTextBaseOffset;
  6109. group_data.BackupLogLinePosY = window->DC.LogLinePosY;
  6110. window->DC.ColumnsStartX = window->DC.CursorPos.x - window->Pos.x;
  6111. window->DC.CursorMaxPos = window->DC.CursorPos;
  6112. window->DC.CurrentLineHeight = 0.0f;
  6113. window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f;
  6114. }
  6115. void ImGui::EndGroup()
  6116. {
  6117. ImGuiWindow* window = GetCurrentWindow();
  6118. ImGuiStyle& style = ImGui::GetStyle();
  6119. IM_ASSERT(!window->DC.GroupStack.empty());
  6120. ImGuiGroupData& group_data = window->DC.GroupStack.back();
  6121. ImRect group_bb(group_data.BackupCursorPos, window->DC.CursorMaxPos);
  6122. group_bb.Max.y -= style.ItemSpacing.y; // Cancel out last vertical spacing because we are adding one ourselves.
  6123. group_bb.Max = ImMax(group_bb.Min, group_bb.Max);
  6124. window->DC.CursorPos = group_data.BackupCursorPos;
  6125. window->DC.CursorMaxPos = ImMax(group_data.BackupCursorMaxPos, window->DC.CursorMaxPos);
  6126. window->DC.CurrentLineHeight = group_data.BackupCurrentLineHeight;
  6127. window->DC.CurrentLineTextBaseOffset = group_data.BackupCurrentLineTextBaseOffset; // FIXME: Ideally we'll grab the base offset from the first line of the group.
  6128. window->DC.ColumnsStartX = group_data.BackupColumnsStartX;
  6129. window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f;
  6130. ItemSize(group_bb.GetSize(), group_data.BackupCurrentLineTextBaseOffset);
  6131. ItemAdd(group_bb, NULL);
  6132. window->DC.GroupStack.pop_back();
  6133. //window->DrawList->AddRect(group_bb.Min, group_bb.Max, 0xFFFF00FF); // Debug
  6134. }
  6135. // Gets back to previous line and continue with horizontal layout
  6136. // column_x == 0 : follow on previous item
  6137. // columm_x != 0 : align to specified column
  6138. // spacing_w < 0 : use default spacing if column_x==0, no spacing if column_x!=0
  6139. // spacing_w >= 0 : enforce spacing
  6140. void ImGui::SameLine(int column_x, int spacing_w)
  6141. {
  6142. ImGuiState& g = *GImGui;
  6143. ImGuiWindow* window = GetCurrentWindow();
  6144. if (window->SkipItems)
  6145. return;
  6146. float x, y;
  6147. if (column_x != 0)
  6148. {
  6149. if (spacing_w < 0) spacing_w = 0;
  6150. x = window->Pos.x + (float)column_x + (float)spacing_w;
  6151. y = window->DC.CursorPosPrevLine.y;
  6152. }
  6153. else
  6154. {
  6155. if (spacing_w < 0) spacing_w = (int)g.Style.ItemSpacing.x;
  6156. x = window->DC.CursorPosPrevLine.x + (float)spacing_w;
  6157. y = window->DC.CursorPosPrevLine.y;
  6158. }
  6159. window->DC.CurrentLineHeight = window->DC.PrevLineHeight;
  6160. window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset;
  6161. window->DC.CursorPos = ImVec2(x, y);
  6162. }
  6163. void ImGui::NextColumn()
  6164. {
  6165. ImGuiState& g = *GImGui;
  6166. ImGuiWindow* window = GetCurrentWindow();
  6167. if (window->SkipItems)
  6168. return;
  6169. if (window->DC.ColumnsCount > 1)
  6170. {
  6171. ImGui::PopItemWidth();
  6172. PopClipRect();
  6173. window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
  6174. if (++window->DC.ColumnsCurrent < window->DC.ColumnsCount)
  6175. {
  6176. window->DC.ColumnsOffsetX = ImGui::GetColumnOffset(window->DC.ColumnsCurrent) - window->DC.ColumnsStartX + g.Style.ItemSpacing.x;
  6177. }
  6178. else
  6179. {
  6180. window->DC.ColumnsCurrent = 0;
  6181. window->DC.ColumnsOffsetX = 0.0f;
  6182. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY;
  6183. }
  6184. window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX);
  6185. window->DC.CursorPos.y = window->DC.ColumnsCellMinY;
  6186. window->DC.CurrentLineHeight = 0.0f;
  6187. window->DC.CurrentLineTextBaseOffset = 0.0f;
  6188. PushColumnClipRect();
  6189. ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);
  6190. }
  6191. }
  6192. int ImGui::GetColumnIndex()
  6193. {
  6194. ImGuiWindow* window = GetCurrentWindow();
  6195. return window->DC.ColumnsCurrent;
  6196. }
  6197. int ImGui::GetColumnsCount()
  6198. {
  6199. ImGuiWindow* window = GetCurrentWindow();
  6200. return window->DC.ColumnsCount;
  6201. }
  6202. float ImGui::GetColumnOffset(int column_index)
  6203. {
  6204. ImGuiState& g = *GImGui;
  6205. ImGuiWindow* window = GetCurrentWindow();
  6206. if (column_index < 0)
  6207. column_index = window->DC.ColumnsCurrent;
  6208. // Read from cache
  6209. IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size());
  6210. const float t = window->DC.ColumnsOffsetsT[column_index];
  6211. const float min_x = window->DC.ColumnsStartX;
  6212. const float max_x = window->Size.x - (g.Style.ScrollbarWidth);// - window->WindowPadding().x;
  6213. const float offset = min_x + t * (max_x - min_x);
  6214. return offset;
  6215. }
  6216. void ImGui::SetColumnOffset(int column_index, float offset)
  6217. {
  6218. ImGuiState& g = *GImGui;
  6219. ImGuiWindow* window = GetCurrentWindow();
  6220. if (column_index < 0)
  6221. column_index = window->DC.ColumnsCurrent;
  6222. IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size());
  6223. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  6224. const float min_x = window->DC.ColumnsStartX;
  6225. const float max_x = window->Size.x - (g.Style.ScrollbarWidth);// - window->WindowPadding().x;
  6226. const float t = (offset - min_x) / (max_x - min_x);
  6227. window->DC.StateStorage->SetFloat(column_id, t);
  6228. window->DC.ColumnsOffsetsT[column_index] = t;
  6229. }
  6230. float ImGui::GetColumnWidth(int column_index)
  6231. {
  6232. ImGuiWindow* window = GetCurrentWindow();
  6233. if (column_index < 0)
  6234. column_index = window->DC.ColumnsCurrent;
  6235. const float w = GetColumnOffset(column_index+1) - GetColumnOffset(column_index);
  6236. return w;
  6237. }
  6238. static void PushColumnClipRect(int column_index)
  6239. {
  6240. ImGuiWindow* window = GetCurrentWindow();
  6241. if (column_index < 0)
  6242. column_index = window->DC.ColumnsCurrent;
  6243. const float x1 = window->Pos.x + ImGui::GetColumnOffset(column_index) - 1;
  6244. const float x2 = window->Pos.x + ImGui::GetColumnOffset(column_index+1) - 1;
  6245. PushClipRect(ImVec4(x1,-FLT_MAX,x2,+FLT_MAX));
  6246. }
  6247. void ImGui::Columns(int columns_count, const char* id, bool border)
  6248. {
  6249. ImGuiState& g = *GImGui;
  6250. ImGuiWindow* window = GetCurrentWindow();
  6251. if (window->DC.ColumnsCount != 1)
  6252. {
  6253. if (window->DC.ColumnsCurrent != 0)
  6254. ItemSize(ImVec2(0,0)); // Advance to column 0
  6255. ImGui::PopItemWidth();
  6256. PopClipRect();
  6257. window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
  6258. window->DC.CursorPos.y = window->DC.ColumnsCellMaxY;
  6259. }
  6260. // Draw columns borders and handle resize at the time of "closing" a columns set
  6261. if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders && !window->SkipItems)
  6262. {
  6263. const float y1 = window->DC.ColumnsStartPos.y;
  6264. const float y2 = window->DC.CursorPos.y;
  6265. for (int i = 1; i < window->DC.ColumnsCount; i++)
  6266. {
  6267. float x = window->Pos.x + GetColumnOffset(i);
  6268. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(i);
  6269. const ImRect column_rect(ImVec2(x-4,y1),ImVec2(x+4,y2));
  6270. if (IsClipped(column_rect))
  6271. continue;
  6272. bool hovered, held;
  6273. ButtonBehavior(column_rect, column_id, &hovered, &held, true);
  6274. if (hovered || held)
  6275. g.MouseCursor = ImGuiMouseCursor_ResizeEW;
  6276. // Draw before resize so our items positioning are in sync with the line being drawn
  6277. const ImU32 col = window->Color(held ? ImGuiCol_ColumnActive : hovered ? ImGuiCol_ColumnHovered : ImGuiCol_Column);
  6278. const float xi = (float)(int)x;
  6279. window->DrawList->AddLine(ImVec2(xi, y1), ImVec2(xi, y2), col);
  6280. if (held)
  6281. {
  6282. x -= window->Pos.x;
  6283. x = ImClamp(x + g.IO.MouseDelta.x, ImGui::GetColumnOffset(i-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(i+1)-g.Style.ColumnsMinSpacing);
  6284. SetColumnOffset(i, x);
  6285. x += window->Pos.x;
  6286. }
  6287. }
  6288. }
  6289. // Set state for first column
  6290. window->DC.ColumnsSetID = window->GetID(id ? id : "");
  6291. window->DC.ColumnsCurrent = 0;
  6292. window->DC.ColumnsCount = columns_count;
  6293. window->DC.ColumnsShowBorders = border;
  6294. window->DC.ColumnsStartPos = window->DC.CursorPos;
  6295. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.CursorPos.y;
  6296. window->DC.ColumnsOffsetX = 0.0f;
  6297. window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX);
  6298. if (window->DC.ColumnsCount != 1)
  6299. {
  6300. // Cache column offsets
  6301. window->DC.ColumnsOffsetsT.resize((size_t)columns_count + 1);
  6302. for (int column_index = 0; column_index < columns_count + 1; column_index++)
  6303. {
  6304. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  6305. RegisterAliveId(column_id);
  6306. const float default_t = column_index / (float)window->DC.ColumnsCount;
  6307. const float t = window->DC.StateStorage->GetFloat(column_id, default_t); // Cheaply store our floating point value inside the integer (could store an union into the map?)
  6308. window->DC.ColumnsOffsetsT[column_index] = t;
  6309. }
  6310. PushColumnClipRect();
  6311. ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);
  6312. }
  6313. else
  6314. {
  6315. window->DC.ColumnsOffsetsT.resize(2);
  6316. window->DC.ColumnsOffsetsT[0] = 0.0f;
  6317. window->DC.ColumnsOffsetsT[1] = 1.0f;
  6318. }
  6319. }
  6320. inline void ImGui::Indent()
  6321. {
  6322. ImGuiState& g = *GImGui;
  6323. ImGuiWindow* window = GetCurrentWindow();
  6324. window->DC.ColumnsStartX += g.Style.IndentSpacing;
  6325. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  6326. }
  6327. inline void ImGui::Unindent()
  6328. {
  6329. ImGuiState& g = *GImGui;
  6330. ImGuiWindow* window = GetCurrentWindow();
  6331. window->DC.ColumnsStartX -= g.Style.IndentSpacing;
  6332. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  6333. }
  6334. void ImGui::TreePush(const char* str_id)
  6335. {
  6336. ImGuiWindow* window = GetCurrentWindow();
  6337. ImGui::Indent();
  6338. window->DC.TreeDepth++;
  6339. PushID(str_id ? str_id : "#TreePush");
  6340. }
  6341. void ImGui::TreePush(const void* ptr_id)
  6342. {
  6343. ImGuiWindow* window = GetCurrentWindow();
  6344. ImGui::Indent();
  6345. window->DC.TreeDepth++;
  6346. PushID(ptr_id ? ptr_id : (const void*)"#TreePush");
  6347. }
  6348. void ImGui::TreePop()
  6349. {
  6350. ImGuiWindow* window = GetCurrentWindow();
  6351. ImGui::Unindent();
  6352. window->DC.TreeDepth--;
  6353. PopID();
  6354. }
  6355. void ImGui::Value(const char* prefix, bool b)
  6356. {
  6357. ImGui::Text("%s: %s", prefix, (b ? "true" : "false"));
  6358. }
  6359. void ImGui::Value(const char* prefix, int v)
  6360. {
  6361. ImGui::Text("%s: %d", prefix, v);
  6362. }
  6363. void ImGui::Value(const char* prefix, unsigned int v)
  6364. {
  6365. ImGui::Text("%s: %d", prefix, v);
  6366. }
  6367. void ImGui::Value(const char* prefix, float v, const char* float_format)
  6368. {
  6369. if (float_format)
  6370. {
  6371. char fmt[64];
  6372. ImFormatString(fmt, IM_ARRAYSIZE(fmt), "%%s: %s", float_format);
  6373. ImGui::Text(fmt, prefix, v);
  6374. }
  6375. else
  6376. {
  6377. ImGui::Text("%s: %.3f", prefix, v);
  6378. }
  6379. }
  6380. void ImGui::Color(const char* prefix, const ImVec4& v)
  6381. {
  6382. ImGui::Text("%s: (%.2f,%.2f,%.2f,%.2f)", prefix, v.x, v.y, v.z, v.w);
  6383. ImGui::SameLine();
  6384. ImGui::ColorButton(v, true);
  6385. }
  6386. void ImGui::Color(const char* prefix, unsigned int v)
  6387. {
  6388. ImGui::Text("%s: %08X", prefix, v);
  6389. ImGui::SameLine();
  6390. ImVec4 col;
  6391. col.x = (float)((v >> 0) & 0xFF) / 255.0f;
  6392. col.y = (float)((v >> 8) & 0xFF) / 255.0f;
  6393. col.z = (float)((v >> 16) & 0xFF) / 255.0f;
  6394. col.w = (float)((v >> 24) & 0xFF) / 255.0f;
  6395. ImGui::ColorButton(col, true);
  6396. }
  6397. //-----------------------------------------------------------------------------
  6398. // ImDrawList
  6399. //-----------------------------------------------------------------------------
  6400. static ImVec4 GNullClipRect(-9999.0f,-9999.0f, +9999.0f, +9999.0f);
  6401. void ImDrawList::Clear()
  6402. {
  6403. commands.resize(0);
  6404. vtx_buffer.resize(0);
  6405. vtx_write = NULL;
  6406. clip_rect_stack.resize(0);
  6407. texture_id_stack.resize(0);
  6408. }
  6409. void ImDrawList::ClearFreeMemory()
  6410. {
  6411. commands.clear();
  6412. vtx_buffer.clear();
  6413. vtx_write = NULL;
  6414. clip_rect_stack.clear();
  6415. texture_id_stack.clear();
  6416. }
  6417. void ImDrawList::AddDrawCmd()
  6418. {
  6419. ImDrawCmd draw_cmd;
  6420. draw_cmd.vtx_count = 0;
  6421. draw_cmd.clip_rect = clip_rect_stack.empty() ? GNullClipRect : clip_rect_stack.back();
  6422. draw_cmd.texture_id = texture_id_stack.empty() ? NULL : texture_id_stack.back();
  6423. draw_cmd.user_callback = NULL;
  6424. draw_cmd.user_callback_data = NULL;
  6425. IM_ASSERT(draw_cmd.clip_rect.x <= draw_cmd.clip_rect.z && draw_cmd.clip_rect.y <= draw_cmd.clip_rect.w);
  6426. commands.push_back(draw_cmd);
  6427. }
  6428. void ImDrawList::AddCallback(ImDrawCallback callback, void* callback_data)
  6429. {
  6430. ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back();
  6431. if (!current_cmd || current_cmd->vtx_count != 0 || current_cmd->user_callback != NULL)
  6432. {
  6433. AddDrawCmd();
  6434. current_cmd = &commands.back();
  6435. }
  6436. current_cmd->user_callback = callback;
  6437. current_cmd->user_callback_data = callback_data;
  6438. // Force a new command after us
  6439. // We function this way so that the most common calls (AddLine, AddRect..) always have a command to add to without doing any check.
  6440. AddDrawCmd();
  6441. }
  6442. void ImDrawList::UpdateClipRect()
  6443. {
  6444. ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back();
  6445. if (!current_cmd || (current_cmd->vtx_count != 0) || current_cmd->user_callback != NULL)
  6446. {
  6447. AddDrawCmd();
  6448. }
  6449. else
  6450. {
  6451. current_cmd->clip_rect = clip_rect_stack.empty() ? GNullClipRect : clip_rect_stack.back();
  6452. }
  6453. }
  6454. // Scissoring. The values in clip_rect are x1, y1, x2, y2.
  6455. void ImDrawList::PushClipRect(const ImVec4& clip_rect)
  6456. {
  6457. clip_rect_stack.push_back(clip_rect);
  6458. UpdateClipRect();
  6459. }
  6460. void ImDrawList::PushClipRectFullScreen()
  6461. {
  6462. PushClipRect(GNullClipRect);
  6463. // This would be more correct but we're not supposed to access ImGuiState from here?
  6464. //ImGuiState& g = *GImGui;
  6465. //if (g.IO.DisplayVisibleMin.x != g.IO.DisplayVisibleMax.x && g.IO.DisplayVisibleMin.y != g.IO.DisplayVisibleMax.y)
  6466. // PushClipRect(ImVec4(g.IO.DisplayVisibleMin.x, g.IO.DisplayVisibleMin.y, g.IO.DisplayVisibleMax.x, g.IO.DisplayVisibleMax.y));
  6467. //else
  6468. // PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y));
  6469. }
  6470. void ImDrawList::PopClipRect()
  6471. {
  6472. IM_ASSERT(clip_rect_stack.size() > 0);
  6473. clip_rect_stack.pop_back();
  6474. UpdateClipRect();
  6475. }
  6476. void ImDrawList::UpdateTextureID()
  6477. {
  6478. ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back();
  6479. const ImTextureID texture_id = texture_id_stack.empty() ? NULL : texture_id_stack.back();
  6480. if (!current_cmd || (current_cmd->vtx_count != 0 && current_cmd->texture_id != texture_id) || current_cmd->user_callback != NULL)
  6481. {
  6482. AddDrawCmd();
  6483. }
  6484. else
  6485. {
  6486. current_cmd->texture_id = texture_id;
  6487. }
  6488. }
  6489. void ImDrawList::PushTextureID(const ImTextureID& texture_id)
  6490. {
  6491. texture_id_stack.push_back(texture_id);
  6492. UpdateTextureID();
  6493. }
  6494. void ImDrawList::PopTextureID()
  6495. {
  6496. IM_ASSERT(texture_id_stack.size() > 0);
  6497. texture_id_stack.pop_back();
  6498. UpdateTextureID();
  6499. }
  6500. void ImDrawList::ReserveVertices(unsigned int vtx_count)
  6501. {
  6502. if (vtx_count > 0)
  6503. {
  6504. ImDrawCmd& draw_cmd = commands.back();
  6505. draw_cmd.vtx_count += vtx_count;
  6506. vtx_buffer.resize(vtx_buffer.size() + vtx_count);
  6507. vtx_write = &vtx_buffer[vtx_buffer.size() - vtx_count];
  6508. }
  6509. }
  6510. void ImDrawList::AddVtx(const ImVec2& pos, ImU32 col)
  6511. {
  6512. vtx_write->pos = pos;
  6513. vtx_write->col = col;
  6514. vtx_write->uv = GImGui->FontTexUvWhitePixel;
  6515. vtx_write++;
  6516. }
  6517. void ImDrawList::AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv)
  6518. {
  6519. vtx_write->pos = pos;
  6520. vtx_write->col = col;
  6521. vtx_write->uv = uv;
  6522. vtx_write++;
  6523. }
  6524. // NB: memory should be reserved for 6 vertices by the caller.
  6525. void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness)
  6526. {
  6527. const float inv_length = 1.0f / sqrtf(ImLengthSqr(b - a));
  6528. const ImVec2 hn = (b - a) * (thickness * 0.5f * inv_length);// half normal
  6529. const ImVec2 hp0 = ImVec2(+hn.y, -hn.x); // half perpendiculars + user offset
  6530. const ImVec2 hp1 = ImVec2(-hn.y, +hn.x);
  6531. // Two triangles makes up one line. Using triangles allows us to reduce amount of draw calls.
  6532. AddVtx(a + hp0, col);
  6533. AddVtx(b + hp0, col);
  6534. AddVtx(a + hp1, col);
  6535. AddVtx(b + hp0, col);
  6536. AddVtx(b + hp1, col);
  6537. AddVtx(a + hp1, col);
  6538. }
  6539. void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness)
  6540. {
  6541. if ((col >> 24) == 0)
  6542. return;
  6543. ReserveVertices(6);
  6544. AddVtxLine(a, b, col, thickness);
  6545. }
  6546. void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris, const ImVec2& third_point_offset)
  6547. {
  6548. if ((col >> 24) == 0)
  6549. return;
  6550. static ImVec2 circle_vtx[12];
  6551. static bool circle_vtx_builds = false;
  6552. if (!circle_vtx_builds)
  6553. {
  6554. for (int i = 0; i < IM_ARRAYSIZE(circle_vtx); i++)
  6555. {
  6556. const float a = ((float)i / (float)IM_ARRAYSIZE(circle_vtx)) * 2*PI;
  6557. circle_vtx[i].x = cosf(a + PI);
  6558. circle_vtx[i].y = sinf(a + PI);
  6559. }
  6560. circle_vtx_builds = true;
  6561. }
  6562. if (tris)
  6563. {
  6564. ReserveVertices((unsigned int)(a_max-a_min) * 3);
  6565. for (int a = a_min; a < a_max; a++)
  6566. {
  6567. AddVtx(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, col);
  6568. AddVtx(center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col);
  6569. AddVtx(center + third_point_offset, col);
  6570. }
  6571. }
  6572. else
  6573. {
  6574. ReserveVertices((unsigned int)(a_max-a_min) * 6);
  6575. for (int a = a_min; a < a_max; a++)
  6576. AddVtxLine(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col);
  6577. }
  6578. }
  6579. void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
  6580. {
  6581. if ((col >> 24) == 0)
  6582. return;
  6583. float r = rounding;
  6584. r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
  6585. r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
  6586. if (r == 0.0f || rounding_corners == 0)
  6587. {
  6588. ReserveVertices(4*6);
  6589. AddVtxLine(ImVec2(a.x,a.y), ImVec2(b.x,a.y), col);
  6590. AddVtxLine(ImVec2(b.x,a.y), ImVec2(b.x,b.y), col);
  6591. AddVtxLine(ImVec2(b.x,b.y), ImVec2(a.x,b.y), col);
  6592. AddVtxLine(ImVec2(a.x,b.y), ImVec2(a.x,a.y), col);
  6593. }
  6594. else
  6595. {
  6596. ReserveVertices(4*6);
  6597. AddVtxLine(ImVec2(a.x + ((rounding_corners & 1)?r:0), a.y), ImVec2(b.x - ((rounding_corners & 2)?r:0), a.y), col);
  6598. AddVtxLine(ImVec2(b.x, a.y + ((rounding_corners & 2)?r:0)), ImVec2(b.x, b.y - ((rounding_corners & 4)?r:0)), col);
  6599. AddVtxLine(ImVec2(b.x - ((rounding_corners & 4)?r:0), b.y), ImVec2(a.x + ((rounding_corners & 8)?r:0), b.y), col);
  6600. AddVtxLine(ImVec2(a.x, b.y - ((rounding_corners & 8)?r:0)), ImVec2(a.x, a.y + ((rounding_corners & 1)?r:0)), col);
  6601. if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3);
  6602. if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6);
  6603. if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9);
  6604. if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12);
  6605. }
  6606. }
  6607. void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
  6608. {
  6609. if ((col >> 24) == 0)
  6610. return;
  6611. float r = rounding;
  6612. r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
  6613. r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
  6614. if (r == 0.0f || rounding_corners == 0)
  6615. {
  6616. // Use triangle so we can merge more draw calls together (at the cost of extra vertices)
  6617. ReserveVertices(6);
  6618. AddVtx(ImVec2(a.x,a.y), col);
  6619. AddVtx(ImVec2(b.x,a.y), col);
  6620. AddVtx(ImVec2(b.x,b.y), col);
  6621. AddVtx(ImVec2(a.x,a.y), col);
  6622. AddVtx(ImVec2(b.x,b.y), col);
  6623. AddVtx(ImVec2(a.x,b.y), col);
  6624. }
  6625. else
  6626. {
  6627. ReserveVertices(6+6*2);
  6628. AddVtx(ImVec2(a.x+r,a.y), col);
  6629. AddVtx(ImVec2(b.x-r,a.y), col);
  6630. AddVtx(ImVec2(b.x-r,b.y), col);
  6631. AddVtx(ImVec2(a.x+r,a.y), col);
  6632. AddVtx(ImVec2(b.x-r,b.y), col);
  6633. AddVtx(ImVec2(a.x+r,b.y), col);
  6634. float top_y = (rounding_corners & 1) ? a.y+r : a.y;
  6635. float bot_y = (rounding_corners & 8) ? b.y-r : b.y;
  6636. AddVtx(ImVec2(a.x,top_y), col);
  6637. AddVtx(ImVec2(a.x+r,top_y), col);
  6638. AddVtx(ImVec2(a.x+r,bot_y), col);
  6639. AddVtx(ImVec2(a.x,top_y), col);
  6640. AddVtx(ImVec2(a.x+r,bot_y), col);
  6641. AddVtx(ImVec2(a.x,bot_y), col);
  6642. top_y = (rounding_corners & 2) ? a.y+r : a.y;
  6643. bot_y = (rounding_corners & 4) ? b.y-r : b.y;
  6644. AddVtx(ImVec2(b.x-r,top_y), col);
  6645. AddVtx(ImVec2(b.x,top_y), col);
  6646. AddVtx(ImVec2(b.x,bot_y), col);
  6647. AddVtx(ImVec2(b.x-r,top_y), col);
  6648. AddVtx(ImVec2(b.x,bot_y), col);
  6649. AddVtx(ImVec2(b.x-r,bot_y), col);
  6650. if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3, true);
  6651. if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6, true);
  6652. if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9, true);
  6653. if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12,true);
  6654. }
  6655. }
  6656. void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col)
  6657. {
  6658. if ((col >> 24) == 0)
  6659. return;
  6660. ReserveVertices(3);
  6661. AddVtx(a, col);
  6662. AddVtx(b, col);
  6663. AddVtx(c, col);
  6664. }
  6665. void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments)
  6666. {
  6667. if ((col >> 24) == 0)
  6668. return;
  6669. ReserveVertices((unsigned int)num_segments*6);
  6670. const float a_step = 2*PI/(float)num_segments;
  6671. float a0 = 0.0f;
  6672. for (int i = 0; i < num_segments; i++)
  6673. {
  6674. const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
  6675. AddVtxLine(centre + ImVec2(cosf(a0), sinf(a0))*radius, centre + ImVec2(cosf(a1), sinf(a1))*radius, col);
  6676. a0 = a1;
  6677. }
  6678. }
  6679. void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments)
  6680. {
  6681. if ((col >> 24) == 0)
  6682. return;
  6683. ReserveVertices((unsigned int)num_segments*3);
  6684. const float a_step = 2*PI/(float)num_segments;
  6685. float a0 = 0.0f;
  6686. for (int i = 0; i < num_segments; i++)
  6687. {
  6688. const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
  6689. AddVtx(centre + ImVec2(cosf(a0), sinf(a0))*radius, col);
  6690. AddVtx(centre + ImVec2(cosf(a1), sinf(a1))*radius, col);
  6691. AddVtx(centre, col);
  6692. a0 = a1;
  6693. }
  6694. }
  6695. void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width, const ImVec2* cpu_clip_max)
  6696. {
  6697. if ((col >> 24) == 0)
  6698. return;
  6699. if (text_end == NULL)
  6700. text_end = text_begin + strlen(text_begin);
  6701. IM_ASSERT(font->ContainerAtlas->TexID == texture_id_stack.back()); // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
  6702. // reserve vertices for worse case
  6703. const unsigned int char_count = (unsigned int)(text_end - text_begin);
  6704. const unsigned int vtx_count_max = char_count * 6;
  6705. const size_t vtx_begin = vtx_buffer.size();
  6706. ReserveVertices(vtx_count_max);
  6707. font->RenderText(font_size, pos, col, clip_rect_stack.back(), text_begin, text_end, vtx_write, wrap_width, cpu_clip_max);
  6708. // give back unused vertices
  6709. vtx_buffer.resize((size_t)(vtx_write - &vtx_buffer.front()));
  6710. const size_t vtx_count = vtx_buffer.size() - vtx_begin;
  6711. commands.back().vtx_count -= (unsigned int)(vtx_count_max - vtx_count);
  6712. vtx_write -= (vtx_count_max - vtx_count);
  6713. }
  6714. void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col)
  6715. {
  6716. if ((col >> 24) == 0)
  6717. return;
  6718. // FIXME-OPT: This is wasting draw calls.
  6719. const bool push_texture_id = texture_id_stack.empty() || user_texture_id != texture_id_stack.back();
  6720. if (push_texture_id)
  6721. PushTextureID(user_texture_id);
  6722. ReserveVertices(6);
  6723. AddVtxUV(ImVec2(a.x,a.y), col, uv0);
  6724. AddVtxUV(ImVec2(b.x,a.y), col, ImVec2(uv1.x,uv0.y));
  6725. AddVtxUV(ImVec2(b.x,b.y), col, uv1);
  6726. AddVtxUV(ImVec2(a.x,a.y), col, ImVec2(uv0.x,uv0.y));
  6727. AddVtxUV(ImVec2(b.x,b.y), col, uv1);
  6728. AddVtxUV(ImVec2(a.x,b.y), col, ImVec2(uv0.x,uv1.y));
  6729. if (push_texture_id)
  6730. PopTextureID();
  6731. }
  6732. //-----------------------------------------------------------------------------
  6733. // ImFontAtlias
  6734. //-----------------------------------------------------------------------------
  6735. struct ImFontAtlas::ImFontAtlasData
  6736. {
  6737. // Input
  6738. ImFont* OutFont; // Load into this font
  6739. void* TTFData; // TTF data, we own the memory
  6740. size_t TTFDataSize; // TTF data size, in bytes
  6741. float SizePixels; // Desired output size, in pixels
  6742. const ImWchar* GlyphRanges; // List of Unicode range (2 value per range, values are inclusive, zero-terminated list)
  6743. int FontNo; // Index of font within .TTF file (0)
  6744. // Temporary Build Data
  6745. stbtt_fontinfo FontInfo;
  6746. stbrp_rect* Rects;
  6747. stbtt_pack_range* Ranges;
  6748. int RangesCount;
  6749. };
  6750. ImFontAtlas::ImFontAtlas()
  6751. {
  6752. TexID = NULL;
  6753. TexPixelsAlpha8 = NULL;
  6754. TexPixelsRGBA32 = NULL;
  6755. TexWidth = TexHeight = 0;
  6756. TexUvWhitePixel = ImVec2(0, 0);
  6757. }
  6758. ImFontAtlas::~ImFontAtlas()
  6759. {
  6760. Clear();
  6761. }
  6762. void ImFontAtlas::ClearInputData()
  6763. {
  6764. for (size_t i = 0; i < InputData.size(); i++)
  6765. {
  6766. if (InputData[i]->TTFData)
  6767. ImGui::MemFree(InputData[i]->TTFData);
  6768. ImGui::MemFree(InputData[i]);
  6769. }
  6770. InputData.clear();
  6771. }
  6772. void ImFontAtlas::ClearTexData()
  6773. {
  6774. if (TexPixelsAlpha8)
  6775. ImGui::MemFree(TexPixelsAlpha8);
  6776. if (TexPixelsRGBA32)
  6777. ImGui::MemFree(TexPixelsRGBA32);
  6778. TexPixelsAlpha8 = NULL;
  6779. TexPixelsRGBA32 = NULL;
  6780. }
  6781. void ImFontAtlas::Clear()
  6782. {
  6783. ClearInputData();
  6784. ClearTexData();
  6785. for (size_t i = 0; i < Fonts.size(); i++)
  6786. {
  6787. Fonts[i]->~ImFont();
  6788. ImGui::MemFree(Fonts[i]);
  6789. }
  6790. Fonts.clear();
  6791. }
  6792. void ImGui::GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size)
  6793. {
  6794. printf("GetDefaultFontData() is obsoleted in ImGui 1.30.\n");
  6795. printf("Please use ImGui::GetIO().Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() functions to retrieve uncompressed texture data.\n");
  6796. if (fnt_data) *fnt_data = NULL;
  6797. if (fnt_size) *fnt_size = 0;
  6798. if (png_data) *png_data = NULL;
  6799. if (png_size) *png_size = 0;
  6800. IM_ASSERT(false);
  6801. }
  6802. void ImFontAtlas::GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel)
  6803. {
  6804. // Lazily build
  6805. if (TexPixelsAlpha8 == NULL)
  6806. {
  6807. if (InputData.empty())
  6808. AddFontDefault();
  6809. Build();
  6810. }
  6811. *out_pixels = TexPixelsAlpha8;
  6812. if (out_width) *out_width = TexWidth;
  6813. if (out_height) *out_height = TexHeight;
  6814. if (out_bytes_per_pixel) *out_bytes_per_pixel = 1;
  6815. }
  6816. void ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel)
  6817. {
  6818. // Lazily convert to RGBA32 format
  6819. // Although it is likely to be the most commonly used format, our font rendering is 8 bpp
  6820. if (!TexPixelsRGBA32)
  6821. {
  6822. unsigned char* pixels;
  6823. GetTexDataAsAlpha8(&pixels, NULL, NULL);
  6824. TexPixelsRGBA32 = (unsigned int*)ImGui::MemAlloc((size_t)(TexWidth * TexHeight * 4));
  6825. const unsigned char* src = pixels;
  6826. unsigned int* dst = TexPixelsRGBA32;
  6827. for (int n = TexWidth * TexHeight; n > 0; n--)
  6828. *dst++ = ((unsigned int)(*src++) << 24) | 0x00FFFFFF;
  6829. }
  6830. *out_pixels = (unsigned char*)TexPixelsRGBA32;
  6831. if (out_width) *out_width = TexWidth;
  6832. if (out_height) *out_height = TexHeight;
  6833. if (out_bytes_per_pixel) *out_bytes_per_pixel = 4;
  6834. }
  6835. static void GetDefaultCompressedFontDataTTF(const void** ttf_compressed_data, unsigned int* ttf_compressed_size);
  6836. static unsigned int stb_decompress_length(unsigned char *input);
  6837. static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length);
  6838. // Load embedded ProggyClean.ttf at size 13
  6839. ImFont* ImFontAtlas::AddFontDefault()
  6840. {
  6841. // Get compressed data
  6842. unsigned int ttf_compressed_size;
  6843. const void* ttf_compressed;
  6844. GetDefaultCompressedFontDataTTF(&ttf_compressed, &ttf_compressed_size);
  6845. // Decompress
  6846. const size_t buf_decompressed_size = stb_decompress_length((unsigned char*)ttf_compressed);
  6847. unsigned char* buf_decompressed = (unsigned char *)ImGui::MemAlloc(buf_decompressed_size);
  6848. stb_decompress(buf_decompressed, (unsigned char*)ttf_compressed, ttf_compressed_size);
  6849. // Add
  6850. ImFont* font = AddFontFromMemoryTTF(buf_decompressed, buf_decompressed_size, 13.0f, GetGlyphRangesDefault(), 0);
  6851. font->DisplayOffset.y += 1;
  6852. return font;
  6853. }
  6854. ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImWchar* glyph_ranges, int font_no)
  6855. {
  6856. void* data = NULL;
  6857. size_t data_size = 0;
  6858. if (!ImLoadFileToMemory(filename, "rb", (void**)&data, &data_size))
  6859. {
  6860. IM_ASSERT(0); // Could not load file.
  6861. return NULL;
  6862. }
  6863. // Add
  6864. ImFont* font = AddFontFromMemoryTTF(data, data_size, size_pixels, glyph_ranges, font_no);
  6865. return font;
  6866. }
  6867. // NB: ownership of 'data' is given to ImFontAtlas which will clear it.
  6868. ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* in_ttf_data, size_t in_ttf_data_size, float size_pixels, const ImWchar* glyph_ranges, int font_no)
  6869. {
  6870. // Create new font
  6871. ImFont* font = (ImFont*)ImGui::MemAlloc(sizeof(ImFont));
  6872. new (font) ImFont();
  6873. Fonts.push_back(font);
  6874. // Add to build list
  6875. ImFontAtlasData* data = (ImFontAtlasData*)ImGui::MemAlloc(sizeof(ImFontAtlasData));
  6876. memset(data, 0, sizeof(ImFontAtlasData));
  6877. data->OutFont = font;
  6878. data->TTFData = in_ttf_data;
  6879. data->TTFDataSize = in_ttf_data_size;
  6880. data->SizePixels = size_pixels;
  6881. data->GlyphRanges = glyph_ranges;
  6882. data->FontNo = font_no;
  6883. InputData.push_back(data);
  6884. // Invalidate texture
  6885. ClearTexData();
  6886. return font;
  6887. }
  6888. bool ImFontAtlas::Build()
  6889. {
  6890. IM_ASSERT(InputData.size() > 0);
  6891. TexID = NULL;
  6892. TexWidth = TexHeight = 0;
  6893. TexUvWhitePixel = ImVec2(0, 0);
  6894. ClearTexData();
  6895. // Initialize font information early (so we can error without any cleanup) + count glyphs
  6896. int total_glyph_count = 0;
  6897. int total_glyph_range_count = 0;
  6898. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  6899. {
  6900. ImFontAtlasData& data = *InputData[input_i];
  6901. IM_ASSERT(data.OutFont && !data.OutFont->IsLoaded());
  6902. const int font_offset = stbtt_GetFontOffsetForIndex((unsigned char*)data.TTFData, data.FontNo);
  6903. IM_ASSERT(font_offset >= 0);
  6904. if (!stbtt_InitFont(&data.FontInfo, (unsigned char*)data.TTFData, font_offset))
  6905. return false;
  6906. if (!data.GlyphRanges)
  6907. data.GlyphRanges = GetGlyphRangesDefault();
  6908. for (const ImWchar* in_range = data.GlyphRanges; in_range[0] && in_range[1]; in_range += 2)
  6909. {
  6910. total_glyph_count += (in_range[1] - in_range[0]) + 1;
  6911. total_glyph_range_count++;
  6912. }
  6913. }
  6914. // Start packing
  6915. TexWidth = (total_glyph_count > 1000) ? 1024 : 512; // Width doesn't actually matters.
  6916. TexHeight = 0;
  6917. const int max_tex_height = 1024*32;
  6918. stbtt_pack_context spc;
  6919. int ret = stbtt_PackBegin(&spc, NULL, TexWidth, max_tex_height, 0, 1, NULL);
  6920. IM_ASSERT(ret);
  6921. stbtt_PackSetOversampling(&spc, 1, 1);
  6922. // Pack our extra data rectangles first, so it will be on the upper-left corner of our texture (UV will have small values).
  6923. ImVector<stbrp_rect> extra_rects;
  6924. RenderCustomTexData(0, &extra_rects);
  6925. stbrp_pack_rects((stbrp_context*)spc.pack_info, &extra_rects[0], (int)extra_rects.size());
  6926. for (size_t i = 0; i < extra_rects.size(); i++)
  6927. if (extra_rects[i].was_packed)
  6928. TexHeight = ImMax(TexHeight, extra_rects[i].y + extra_rects[i].h);
  6929. // Allocate packing character data and flag packed characters buffer as non-packed (x0=y0=x1=y1=0)
  6930. int buf_packedchars_n = 0, buf_rects_n = 0, buf_ranges_n = 0;
  6931. stbtt_packedchar* buf_packedchars = (stbtt_packedchar*)ImGui::MemAlloc(total_glyph_count * sizeof(stbtt_packedchar));
  6932. stbrp_rect* buf_rects = (stbrp_rect*)ImGui::MemAlloc(total_glyph_count * sizeof(stbrp_rect));
  6933. stbtt_pack_range* buf_ranges = (stbtt_pack_range*)ImGui::MemAlloc(total_glyph_range_count * sizeof(stbtt_pack_range));
  6934. memset(buf_packedchars, 0, total_glyph_count * sizeof(stbtt_packedchar));
  6935. memset(buf_rects, 0, total_glyph_count * sizeof(stbrp_rect)); // Unnecessary but let's clear this for the sake of sanity.
  6936. memset(buf_ranges, 0, total_glyph_range_count * sizeof(stbtt_pack_range));
  6937. // First font pass: pack all glyphs (no rendering at this point, we are working with glyph sizes only)
  6938. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  6939. {
  6940. ImFontAtlasData& data = *InputData[input_i];
  6941. // Setup ranges
  6942. int glyph_count = 0;
  6943. int glyph_ranges_count = 0;
  6944. for (const ImWchar* in_range = data.GlyphRanges; in_range[0] && in_range[1]; in_range += 2)
  6945. {
  6946. glyph_count += (in_range[1] - in_range[0]) + 1;
  6947. glyph_ranges_count++;
  6948. }
  6949. data.Ranges = buf_ranges + buf_ranges_n;
  6950. data.RangesCount = glyph_ranges_count;
  6951. buf_ranges_n += glyph_ranges_count;
  6952. for (int i = 0; i < glyph_ranges_count; i++)
  6953. {
  6954. const ImWchar* in_range = &data.GlyphRanges[i * 2];
  6955. stbtt_pack_range& range = data.Ranges[i];
  6956. range.font_size = data.SizePixels;
  6957. range.first_unicode_char_in_range = in_range[0];
  6958. range.num_chars_in_range = (in_range[1] - in_range[0]) + 1;
  6959. range.chardata_for_range = buf_packedchars + buf_packedchars_n;
  6960. buf_packedchars_n += range.num_chars_in_range;
  6961. }
  6962. // Pack
  6963. data.Rects = buf_rects + buf_rects_n;
  6964. buf_rects_n += glyph_count;
  6965. const int n = stbtt_PackFontRangesGatherRects(&spc, &data.FontInfo, data.Ranges, data.RangesCount, data.Rects);
  6966. stbrp_pack_rects((stbrp_context*)spc.pack_info, data.Rects, n);
  6967. // Extend texture height
  6968. for (int i = 0; i < n; i++)
  6969. if (data.Rects[i].was_packed)
  6970. TexHeight = ImMax(TexHeight, data.Rects[i].y + data.Rects[i].h);
  6971. }
  6972. IM_ASSERT(buf_rects_n == total_glyph_count);
  6973. IM_ASSERT(buf_packedchars_n == total_glyph_count);
  6974. IM_ASSERT(buf_ranges_n == total_glyph_range_count);
  6975. // Create texture
  6976. TexHeight = ImUpperPowerOfTwo(TexHeight);
  6977. TexPixelsAlpha8 = (unsigned char*)ImGui::MemAlloc(TexWidth * TexHeight);
  6978. memset(TexPixelsAlpha8, 0, TexWidth * TexHeight);
  6979. spc.pixels = TexPixelsAlpha8;
  6980. spc.height = TexHeight;
  6981. // Second pass: render characters
  6982. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  6983. {
  6984. ImFontAtlasData& data = *InputData[input_i];
  6985. ret = stbtt_PackFontRangesRenderIntoRects(&spc, &data.FontInfo, data.Ranges, data.RangesCount, data.Rects);
  6986. data.Rects = NULL;
  6987. }
  6988. // End packing
  6989. stbtt_PackEnd(&spc);
  6990. ImGui::MemFree(buf_rects);
  6991. buf_rects = NULL;
  6992. // Third pass: setup ImFont and glyphs for runtime
  6993. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  6994. {
  6995. ImFontAtlasData& data = *InputData[input_i];
  6996. data.OutFont->ContainerAtlas = this;
  6997. data.OutFont->FontSize = data.SizePixels;
  6998. const float font_scale = stbtt_ScaleForPixelHeight(&data.FontInfo, data.SizePixels);
  6999. int font_ascent, font_descent, font_line_gap;
  7000. stbtt_GetFontVMetrics(&data.FontInfo, &font_ascent, &font_descent, &font_line_gap);
  7001. const float uv_scale_x = 1.0f / TexWidth;
  7002. const float uv_scale_y = 1.0f / TexHeight;
  7003. const int character_spacing_x = 1;
  7004. for (int i = 0; i < data.RangesCount; i++)
  7005. {
  7006. stbtt_pack_range& range = data.Ranges[i];
  7007. for (int char_idx = 0; char_idx < range.num_chars_in_range; char_idx += 1)
  7008. {
  7009. const int codepoint = range.first_unicode_char_in_range + char_idx;
  7010. const stbtt_packedchar& pc = range.chardata_for_range[char_idx];
  7011. if (!pc.x0 && !pc.x1 && !pc.y0 && !pc.y1)
  7012. continue;
  7013. data.OutFont->Glyphs.resize(data.OutFont->Glyphs.size() + 1);
  7014. ImFont::Glyph& glyph = data.OutFont->Glyphs.back();
  7015. glyph.Codepoint = (ImWchar)codepoint;
  7016. glyph.Width = (signed short)pc.x1 - pc.x0 + 1;
  7017. glyph.Height = (signed short)pc.y1 - pc.y0 + 1;
  7018. glyph.XOffset = (signed short)(pc.xoff);
  7019. glyph.YOffset = (signed short)(pc.yoff + (int)(font_ascent * font_scale));
  7020. glyph.XAdvance = (signed short)(pc.xadvance + character_spacing_x); // Bake spacing into XAdvance
  7021. glyph.U0 = ((float)pc.x0 - 0.5f) * uv_scale_x;
  7022. glyph.V0 = ((float)pc.y0 - 0.5f) * uv_scale_y;
  7023. glyph.U1 = ((float)pc.x0 - 0.5f + glyph.Width) * uv_scale_x;
  7024. glyph.V1 = ((float)pc.y0 - 0.5f + glyph.Height) * uv_scale_y;
  7025. }
  7026. }
  7027. data.OutFont->BuildLookupTable();
  7028. }
  7029. // Cleanup temporaries
  7030. ImGui::MemFree(buf_packedchars);
  7031. ImGui::MemFree(buf_ranges);
  7032. buf_packedchars = NULL;
  7033. buf_ranges = NULL;
  7034. ClearInputData();
  7035. // Render into our custom data block
  7036. RenderCustomTexData(1, &extra_rects);
  7037. return true;
  7038. }
  7039. void ImFontAtlas::RenderCustomTexData(int pass, void* p_rects)
  7040. {
  7041. // . = white layer, X = black layer, others are blank
  7042. const int TEX_DATA_W = 90;
  7043. const int TEX_DATA_H = 27;
  7044. const char texture_data[TEX_DATA_W*TEX_DATA_H+1] =
  7045. {
  7046. "..- -XXXXXXX- X - X -XXXXXXX - XXXXXXX"
  7047. "..- -X.....X- X.X - X.X -X.....X - X.....X"
  7048. "--- -XXX.XXX- X...X - X...X -X....X - X....X"
  7049. "X - X.X - X.....X - X.....X -X...X - X...X"
  7050. "XX - X.X -X.......X- X.......X -X..X.X - X.X..X"
  7051. "X.X - X.X -XXXX.XXXX- XXXX.XXXX -X.X X.X - X.X X.X"
  7052. "X..X - X.X - X.X - X.X -XX X.X - X.X XX"
  7053. "X...X - X.X - X.X - XX X.X XX - X.X - X.X "
  7054. "X....X - X.X - X.X - X.X X.X X.X - X.X - X.X "
  7055. "X.....X - X.X - X.X - X..X X.X X..X - X.X - X.X "
  7056. "X......X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X XX-XX X.X "
  7057. "X.......X - X.X - X.X -X.....................X- X.X X.X-X.X X.X "
  7058. "X........X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X..X-X..X.X "
  7059. "X.........X -XXX.XXX- X.X - X..X X.X X..X - X...X-X...X "
  7060. "X..........X-X.....X- X.X - X.X X.X X.X - X....X-X....X "
  7061. "X......XXXXX-XXXXXXX- X.X - XX X.X XX - X.....X-X.....X "
  7062. "X...X..X --------- X.X - X.X - XXXXXXX-XXXXXXX "
  7063. "X..X X..X - -XXXX.XXXX- XXXX.XXXX ------------------------------------"
  7064. "X.X X..X - -X.......X- X.......X - XX XX - "
  7065. "XX X..X - - X.....X - X.....X - X.X X.X - "
  7066. " X..X - X...X - X...X - X..X X..X - "
  7067. " XX - X.X - X.X - X...XXXXXXXXXXXXX...X - "
  7068. "------------ - X - X -X.....................X- "
  7069. " ----------------------------------- X...XXXXXXXXXXXXX...X - "
  7070. " - X..X X..X - "
  7071. " - X.X X.X - "
  7072. " - XX XX - "
  7073. };
  7074. ImVector<stbrp_rect>& rects = *(ImVector<stbrp_rect>*)p_rects;
  7075. if (pass == 0)
  7076. {
  7077. stbrp_rect r;
  7078. r.w = (TEX_DATA_W*2)+1;
  7079. r.h = TEX_DATA_H+1;
  7080. rects.push_back(r);
  7081. }
  7082. else if (pass == 1)
  7083. {
  7084. // Copy pixels
  7085. const stbrp_rect& r = rects[0];
  7086. for (int y = 0, n = 0; y < TEX_DATA_H; y++)
  7087. for (int x = 0; x < TEX_DATA_W; x++, n++)
  7088. {
  7089. const int offset0 = (int)(r.x + x) + (int)(r.y + y) * TexWidth;
  7090. const int offset1 = offset0 + 1 + TEX_DATA_W;
  7091. TexPixelsAlpha8[offset0] = texture_data[n] == '.' ? 0xFF : 0x00;
  7092. TexPixelsAlpha8[offset1] = texture_data[n] == 'X' ? 0xFF : 0x00;
  7093. }
  7094. const ImVec2 tex_uv_scale(1.0f / TexWidth, 1.0f / TexHeight);
  7095. TexUvWhitePixel = ImVec2(r.x + 0.5f, r.y + 0.5f) * tex_uv_scale;
  7096. const ImVec2 cursor_datas[ImGuiMouseCursor_Count_][3] =
  7097. {
  7098. // Pos ........ Size ......... Offset ......
  7099. { ImVec2(0,3), ImVec2(12,19), ImVec2( 0, 0) }, // ImGuiMouseCursor_Arrow
  7100. { ImVec2(13,0), ImVec2(7,16), ImVec2( 4, 8) }, // ImGuiMouseCursor_TextInput
  7101. { ImVec2(31,0), ImVec2(23,23), ImVec2(11,11) }, // ImGuiMouseCursor_Move
  7102. { ImVec2(21,0), ImVec2( 9,23), ImVec2( 5,11) }, // ImGuiMouseCursor_ResizeNS
  7103. { ImVec2(55,18),ImVec2(23, 9), ImVec2(11, 5) }, // ImGuiMouseCursor_ResizeEW
  7104. { ImVec2(73,0), ImVec2(17,17), ImVec2( 9, 9) }, // ImGuiMouseCursor_ResizeNESW
  7105. { ImVec2(55,0), ImVec2(17,17), ImVec2( 9, 9) }, // ImGuiMouseCursor_ResizeNWSE
  7106. };
  7107. for (int type = 0; type < ImGuiMouseCursor_Count_; type++)
  7108. {
  7109. ImGuiMouseCursorData& cursor_data = GImGui->MouseCursorData[type];
  7110. ImVec2 pos = cursor_datas[type][0] + ImVec2((float)r.x, (float)r.y);
  7111. const ImVec2 size = cursor_datas[type][1];
  7112. cursor_data.Type = type;
  7113. cursor_data.Size = size;
  7114. cursor_data.Offset = cursor_datas[type][2];
  7115. cursor_data.TexUvMin[0] = (pos) * tex_uv_scale;
  7116. cursor_data.TexUvMax[0] = (pos + size) * tex_uv_scale;
  7117. pos.x += TEX_DATA_W+1;
  7118. cursor_data.TexUvMin[1] = (pos) * tex_uv_scale;
  7119. cursor_data.TexUvMax[1] = (pos + size) * tex_uv_scale;
  7120. }
  7121. }
  7122. }
  7123. //-----------------------------------------------------------------------------
  7124. // ImFont
  7125. //-----------------------------------------------------------------------------
  7126. ImFont::ImFont()
  7127. {
  7128. Scale = 1.0f;
  7129. FallbackChar = (ImWchar)'?';
  7130. Clear();
  7131. }
  7132. void ImFont::Clear()
  7133. {
  7134. FontSize = 0.0f;
  7135. DisplayOffset = ImVec2(-0.5f, 0.5f);
  7136. ContainerAtlas = NULL;
  7137. Glyphs.clear();
  7138. FallbackGlyph = NULL;
  7139. FallbackXAdvance = 0.0f;
  7140. IndexXAdvance.clear();
  7141. IndexLookup.clear();
  7142. }
  7143. // Retrieve list of range (2 int per range, values are inclusive)
  7144. const ImWchar* ImFontAtlas::GetGlyphRangesDefault()
  7145. {
  7146. static const ImWchar ranges[] =
  7147. {
  7148. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  7149. 0,
  7150. };
  7151. return &ranges[0];
  7152. }
  7153. const ImWchar* ImFontAtlas::GetGlyphRangesChinese()
  7154. {
  7155. static const ImWchar ranges[] =
  7156. {
  7157. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  7158. 0x3000, 0x30FF, // Punctuations, Hiragana, Katakana
  7159. 0x31F0, 0x31FF, // Katakana Phonetic Extensions
  7160. 0xFF00, 0xFFEF, // Half-width characters
  7161. 0x4e00, 0x9FAF, // CJK Ideograms
  7162. 0,
  7163. };
  7164. return &ranges[0];
  7165. }
  7166. const ImWchar* ImFontAtlas::GetGlyphRangesJapanese()
  7167. {
  7168. // Store the 1946 ideograms code points as successive offsets from the initial unicode codepoint 0x4E00. Each offset has an implicit +1.
  7169. // This encoding helps us reduce the source code size.
  7170. static const short offsets_from_0x4E00[] =
  7171. {
  7172. -1,0,1,3,0,0,0,0,1,0,5,1,1,0,7,4,6,10,0,1,9,9,7,1,3,19,1,10,7,1,0,1,0,5,1,0,6,4,2,6,0,0,12,6,8,0,3,5,0,1,0,9,0,0,8,1,1,3,4,5,13,0,0,8,2,17,
  7173. 4,3,1,1,9,6,0,0,0,2,1,3,2,22,1,9,11,1,13,1,3,12,0,5,9,2,0,6,12,5,3,12,4,1,2,16,1,1,4,6,5,3,0,6,13,15,5,12,8,14,0,0,6,15,3,6,0,18,8,1,6,14,1,
  7174. 5,4,12,24,3,13,12,10,24,0,0,0,1,0,1,1,2,9,10,2,2,0,0,3,3,1,0,3,8,0,3,2,4,4,1,6,11,10,14,6,15,3,4,15,1,0,0,5,2,2,0,0,1,6,5,5,6,0,3,6,5,0,0,1,0,
  7175. 11,2,2,8,4,7,0,10,0,1,2,17,19,3,0,2,5,0,6,2,4,4,6,1,1,11,2,0,3,1,2,1,2,10,7,6,3,16,0,8,24,0,0,3,1,1,3,0,1,6,0,0,0,2,0,1,5,15,0,1,0,0,2,11,19,
  7176. 1,4,19,7,6,5,1,0,0,0,0,5,1,0,1,9,0,0,5,0,2,0,1,0,3,0,11,3,0,2,0,0,0,0,0,9,3,6,4,12,0,14,0,0,29,10,8,0,14,37,13,0,31,16,19,0,8,30,1,20,8,3,48,
  7177. 21,1,0,12,0,10,44,34,42,54,11,18,82,0,2,1,2,12,1,0,6,2,17,2,12,7,0,7,17,4,2,6,24,23,8,23,39,2,16,23,1,0,5,1,2,15,14,5,6,2,11,0,8,6,2,2,2,14,
  7178. 20,4,15,3,4,11,10,10,2,5,2,1,30,2,1,0,0,22,5,5,0,3,1,5,4,1,0,0,2,2,21,1,5,1,2,16,2,1,3,4,0,8,4,0,0,5,14,11,2,16,1,13,1,7,0,22,15,3,1,22,7,14,
  7179. 22,19,11,24,18,46,10,20,64,45,3,2,0,4,5,0,1,4,25,1,0,0,2,10,0,0,0,1,0,1,2,0,0,9,1,2,0,0,0,2,5,2,1,1,5,5,8,1,1,1,5,1,4,9,1,3,0,1,0,1,1,2,0,0,
  7180. 2,0,1,8,22,8,1,0,0,0,0,4,2,1,0,9,8,5,0,9,1,30,24,2,6,4,39,0,14,5,16,6,26,179,0,2,1,1,0,0,0,5,2,9,6,0,2,5,16,7,5,1,1,0,2,4,4,7,15,13,14,0,0,
  7181. 3,0,1,0,0,0,2,1,6,4,5,1,4,9,0,3,1,8,0,0,10,5,0,43,0,2,6,8,4,0,2,0,0,9,6,0,9,3,1,6,20,14,6,1,4,0,7,2,3,0,2,0,5,0,3,1,0,3,9,7,0,3,4,0,4,9,1,6,0,
  7182. 9,0,0,2,3,10,9,28,3,6,2,4,1,2,32,4,1,18,2,0,3,1,5,30,10,0,2,2,2,0,7,9,8,11,10,11,7,2,13,7,5,10,0,3,40,2,0,1,6,12,0,4,5,1,5,11,11,21,4,8,3,7,
  7183. 8,8,33,5,23,0,0,19,8,8,2,3,0,6,1,1,1,5,1,27,4,2,5,0,3,5,6,3,1,0,3,1,12,5,3,3,2,0,7,7,2,1,0,4,0,1,1,2,0,10,10,6,2,5,9,7,5,15,15,21,6,11,5,20,
  7184. 4,3,5,5,2,5,0,2,1,0,1,7,28,0,9,0,5,12,5,5,18,30,0,12,3,3,21,16,25,32,9,3,14,11,24,5,66,9,1,2,0,5,9,1,5,1,8,0,8,3,3,0,1,15,1,4,8,1,2,7,0,7,2,
  7185. 8,3,7,5,3,7,10,2,1,0,0,2,25,0,6,4,0,10,0,4,2,4,1,12,5,38,4,0,4,1,10,5,9,4,0,14,4,2,5,18,20,21,1,3,0,5,0,7,0,3,7,1,3,1,1,8,1,0,0,0,3,2,5,2,11,
  7186. 6,0,13,1,3,9,1,12,0,16,6,2,1,0,2,1,12,6,13,11,2,0,28,1,7,8,14,13,8,13,0,2,0,5,4,8,10,2,37,42,19,6,6,7,4,14,11,18,14,80,7,6,0,4,72,12,36,27,
  7187. 7,7,0,14,17,19,164,27,0,5,10,7,3,13,6,14,0,2,2,5,3,0,6,13,0,0,10,29,0,4,0,3,13,0,3,1,6,51,1,5,28,2,0,8,0,20,2,4,0,25,2,10,13,10,0,16,4,0,1,0,
  7188. 2,1,7,0,1,8,11,0,0,1,2,7,2,23,11,6,6,4,16,2,2,2,0,22,9,3,3,5,2,0,15,16,21,2,9,20,15,15,5,3,9,1,0,0,1,7,7,5,4,2,2,2,38,24,14,0,0,15,5,6,24,14,
  7189. 5,5,11,0,21,12,0,3,8,4,11,1,8,0,11,27,7,2,4,9,21,59,0,1,39,3,60,62,3,0,12,11,0,3,30,11,0,13,88,4,15,5,28,13,1,4,48,17,17,4,28,32,46,0,16,0,
  7190. 18,11,1,8,6,38,11,2,6,11,38,2,0,45,3,11,2,7,8,4,30,14,17,2,1,1,65,18,12,16,4,2,45,123,12,56,33,1,4,3,4,7,0,0,0,3,2,0,16,4,2,4,2,0,7,4,5,2,26,
  7191. 2,25,6,11,6,1,16,2,6,17,77,15,3,35,0,1,0,5,1,0,38,16,6,3,12,3,3,3,0,9,3,1,3,5,2,9,0,18,0,25,1,3,32,1,72,46,6,2,7,1,3,14,17,0,28,1,40,13,0,20,
  7192. 15,40,6,38,24,12,43,1,1,9,0,12,6,0,6,2,4,19,3,7,1,48,0,9,5,0,5,6,9,6,10,15,2,11,19,3,9,2,0,1,10,1,27,8,1,3,6,1,14,0,26,0,27,16,3,4,9,6,2,23,
  7193. 9,10,5,25,2,1,6,1,1,48,15,9,15,14,3,4,26,60,29,13,37,21,1,6,4,0,2,11,22,23,16,16,2,2,1,3,0,5,1,6,4,0,0,4,0,0,8,3,0,2,5,0,7,1,7,3,13,2,4,10,
  7194. 3,0,2,31,0,18,3,0,12,10,4,1,0,7,5,7,0,5,4,12,2,22,10,4,2,15,2,8,9,0,23,2,197,51,3,1,1,4,13,4,3,21,4,19,3,10,5,40,0,4,1,1,10,4,1,27,34,7,21,
  7195. 2,17,2,9,6,4,2,3,0,4,2,7,8,2,5,1,15,21,3,4,4,2,2,17,22,1,5,22,4,26,7,0,32,1,11,42,15,4,1,2,5,0,19,3,1,8,6,0,10,1,9,2,13,30,8,2,24,17,19,1,4,
  7196. 4,25,13,0,10,16,11,39,18,8,5,30,82,1,6,8,18,77,11,13,20,75,11,112,78,33,3,0,0,60,17,84,9,1,1,12,30,10,49,5,32,158,178,5,5,6,3,3,1,3,1,4,7,6,
  7197. 19,31,21,0,2,9,5,6,27,4,9,8,1,76,18,12,1,4,0,3,3,6,3,12,2,8,30,16,2,25,1,5,5,4,3,0,6,10,2,3,1,0,5,1,19,3,0,8,1,5,2,6,0,0,0,19,1,2,0,5,1,2,5,
  7198. 1,3,7,0,4,12,7,3,10,22,0,9,5,1,0,2,20,1,1,3,23,30,3,9,9,1,4,191,14,3,15,6,8,50,0,1,0,0,4,0,0,1,0,2,4,2,0,2,3,0,2,0,2,2,8,7,0,1,1,1,3,3,17,11,
  7199. 91,1,9,3,2,13,4,24,15,41,3,13,3,1,20,4,125,29,30,1,0,4,12,2,21,4,5,5,19,11,0,13,11,86,2,18,0,7,1,8,8,2,2,22,1,2,6,5,2,0,1,2,8,0,2,0,5,2,1,0,
  7200. 2,10,2,0,5,9,2,1,2,0,1,0,4,0,0,10,2,5,3,0,6,1,0,1,4,4,33,3,13,17,3,18,6,4,7,1,5,78,0,4,1,13,7,1,8,1,0,35,27,15,3,0,0,0,1,11,5,41,38,15,22,6,
  7201. 14,14,2,1,11,6,20,63,5,8,27,7,11,2,2,40,58,23,50,54,56,293,8,8,1,5,1,14,0,1,12,37,89,8,8,8,2,10,6,0,0,0,4,5,2,1,0,1,1,2,7,0,3,3,0,4,6,0,3,2,
  7202. 19,3,8,0,0,0,4,4,16,0,4,1,5,1,3,0,3,4,6,2,17,10,10,31,6,4,3,6,10,126,7,3,2,2,0,9,0,0,5,20,13,0,15,0,6,0,2,5,8,64,50,3,2,12,2,9,0,0,11,8,20,
  7203. 109,2,18,23,0,0,9,61,3,0,28,41,77,27,19,17,81,5,2,14,5,83,57,252,14,154,263,14,20,8,13,6,57,39,38,
  7204. };
  7205. static int ranges_unpacked = false;
  7206. static ImWchar ranges[8 + IM_ARRAYSIZE(offsets_from_0x4E00)*2 + 1] =
  7207. {
  7208. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  7209. 0x3000, 0x30FF, // Punctuations, Hiragana, Katakana
  7210. 0x31F0, 0x31FF, // Katakana Phonetic Extensions
  7211. 0xFF00, 0xFFEF, // Half-width characters
  7212. };
  7213. if (!ranges_unpacked)
  7214. {
  7215. // Unpack
  7216. int codepoint = 0x4e00;
  7217. ImWchar* dst = &ranges[8];
  7218. for (int n = 0; n < IM_ARRAYSIZE(offsets_from_0x4E00); n++, dst += 2)
  7219. dst[0] = dst[1] = (ImWchar)(codepoint += (offsets_from_0x4E00[n] + 1));
  7220. dst[0] = 0;
  7221. ranges_unpacked = true;
  7222. }
  7223. return &ranges[0];
  7224. }
  7225. void ImFont::BuildLookupTable()
  7226. {
  7227. int max_codepoint = 0;
  7228. for (size_t i = 0; i != Glyphs.size(); i++)
  7229. max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint);
  7230. IndexXAdvance.clear();
  7231. IndexXAdvance.resize((size_t)max_codepoint + 1);
  7232. IndexLookup.clear();
  7233. IndexLookup.resize((size_t)max_codepoint + 1);
  7234. for (size_t i = 0; i < (size_t)max_codepoint + 1; i++)
  7235. {
  7236. IndexXAdvance[i] = -1.0f;
  7237. IndexLookup[i] = -1;
  7238. }
  7239. for (size_t i = 0; i < Glyphs.size(); i++)
  7240. {
  7241. const size_t codepoint = (int)Glyphs[i].Codepoint;
  7242. IndexXAdvance[codepoint] = Glyphs[i].XAdvance;
  7243. IndexLookup[codepoint] = (int)i;
  7244. }
  7245. // Create a glyph to handle TAB
  7246. // FIXME: Needs proper TAB handling but it needs to be contextualized (can arbitrary say that each string starts at "column 0"
  7247. if (FindGlyph((unsigned short)' '))
  7248. {
  7249. if (Glyphs.back().Codepoint != '\t') // So we can call this function multiple times
  7250. Glyphs.resize(Glyphs.size() + 1);
  7251. ImFont::Glyph& tab_glyph = Glyphs.back();
  7252. tab_glyph = *FindGlyph((unsigned short)' ');
  7253. tab_glyph.Codepoint = '\t';
  7254. tab_glyph.XAdvance *= 4;
  7255. IndexXAdvance[(size_t)tab_glyph.Codepoint] = (float)tab_glyph.XAdvance;
  7256. IndexLookup[(size_t)tab_glyph.Codepoint] = (int)(Glyphs.size()-1);
  7257. }
  7258. FallbackGlyph = NULL;
  7259. FallbackGlyph = FindGlyph(FallbackChar);
  7260. FallbackXAdvance = FallbackGlyph ? FallbackGlyph->XAdvance : 0.0f;
  7261. for (size_t i = 0; i < (size_t)max_codepoint + 1; i++)
  7262. if (IndexXAdvance[i] < 0.0f)
  7263. IndexXAdvance[i] = FallbackXAdvance;
  7264. }
  7265. void ImFont::SetFallbackChar(ImWchar c)
  7266. {
  7267. FallbackChar = c;
  7268. BuildLookupTable();
  7269. }
  7270. const ImFont::Glyph* ImFont::FindGlyph(unsigned short c) const
  7271. {
  7272. if (c < (int)IndexLookup.size())
  7273. {
  7274. const int i = IndexLookup[c];
  7275. if (i != -1)
  7276. return &Glyphs[i];
  7277. }
  7278. return FallbackGlyph;
  7279. }
  7280. // Convert UTF-8 to 32-bits character, process single character input.
  7281. // Based on stb_from_utf8() from github.com/nothings/stb/
  7282. // We handle UTF-8 decoding error by skipping forward.
  7283. static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end)
  7284. {
  7285. unsigned int c = (unsigned int)-1;
  7286. const unsigned char* str = (const unsigned char*)in_text;
  7287. if (!(*str & 0x80))
  7288. {
  7289. c = (unsigned int)(*str++);
  7290. *out_char = c;
  7291. return 1;
  7292. }
  7293. if ((*str & 0xe0) == 0xc0)
  7294. {
  7295. *out_char = 0;
  7296. if (in_text_end && in_text_end - (const char*)str < 2) return 0;
  7297. if (*str < 0xc2) return 0;
  7298. c = (unsigned int)((*str++ & 0x1f) << 6);
  7299. if ((*str & 0xc0) != 0x80) return 0;
  7300. c += (*str++ & 0x3f);
  7301. *out_char = c;
  7302. return 2;
  7303. }
  7304. if ((*str & 0xf0) == 0xe0)
  7305. {
  7306. *out_char = 0;
  7307. if (in_text_end && in_text_end - (const char*)str < 3) return 0;
  7308. if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return 0;
  7309. if (*str == 0xed && str[1] > 0x9f) return 0; // str[1] < 0x80 is checked below
  7310. c = (unsigned int)((*str++ & 0x0f) << 12);
  7311. if ((*str & 0xc0) != 0x80) return 0;
  7312. c += (unsigned int)((*str++ & 0x3f) << 6);
  7313. if ((*str & 0xc0) != 0x80) return 0;
  7314. c += (*str++ & 0x3f);
  7315. *out_char = c;
  7316. return 3;
  7317. }
  7318. if ((*str & 0xf8) == 0xf0)
  7319. {
  7320. *out_char = 0;
  7321. if (in_text_end && in_text_end - (const char*)str < 4) return 0;
  7322. if (*str > 0xf4) return 0;
  7323. if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return 0;
  7324. if (*str == 0xf4 && str[1] > 0x8f) return 0; // str[1] < 0x80 is checked below
  7325. c = (unsigned int)((*str++ & 0x07) << 18);
  7326. if ((*str & 0xc0) != 0x80) return 0;
  7327. c += (unsigned int)((*str++ & 0x3f) << 12);
  7328. if ((*str & 0xc0) != 0x80) return 0;
  7329. c += (unsigned int)((*str++ & 0x3f) << 6);
  7330. if ((*str & 0xc0) != 0x80) return 0;
  7331. c += (*str++ & 0x3f);
  7332. // utf-8 encodings of values used in surrogate pairs are invalid
  7333. if ((c & 0xFFFFF800) == 0xD800) return 0;
  7334. *out_char = c;
  7335. return 4;
  7336. }
  7337. *out_char = 0;
  7338. return 0;
  7339. }
  7340. static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end, const char** in_text_remaining)
  7341. {
  7342. ImWchar* buf_out = buf;
  7343. ImWchar* buf_end = buf + buf_size;
  7344. while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text)
  7345. {
  7346. unsigned int c;
  7347. in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
  7348. if (c == 0)
  7349. break;
  7350. if (c < 0x10000) // FIXME: Losing characters that don't fit in 2 bytes
  7351. *buf_out++ = (ImWchar)c;
  7352. }
  7353. *buf_out = 0;
  7354. if (in_text_remaining)
  7355. *in_text_remaining = in_text;
  7356. return buf_out - buf;
  7357. }
  7358. static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end)
  7359. {
  7360. int char_count = 0;
  7361. while ((!in_text_end || in_text < in_text_end) && *in_text)
  7362. {
  7363. unsigned int c;
  7364. in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
  7365. if (c == 0)
  7366. break;
  7367. if (c < 0x10000)
  7368. char_count++;
  7369. }
  7370. return char_count;
  7371. }
  7372. // Based on stb_to_utf8() from github.com/nothings/stb/
  7373. static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int c)
  7374. {
  7375. if (c)
  7376. {
  7377. size_t i = 0;
  7378. size_t n = buf_size;
  7379. if (c < 0x80)
  7380. {
  7381. if (i+1 > n) return 0;
  7382. buf[i++] = (char)c;
  7383. return 1;
  7384. }
  7385. else if (c < 0x800)
  7386. {
  7387. if (i+2 > n) return 0;
  7388. buf[i++] = (char)(0xc0 + (c >> 6));
  7389. buf[i++] = (char)(0x80 + (c & 0x3f));
  7390. return 2;
  7391. }
  7392. else if (c >= 0xdc00 && c < 0xe000)
  7393. {
  7394. return 0;
  7395. }
  7396. else if (c >= 0xd800 && c < 0xdc00)
  7397. {
  7398. if (i+4 > n) return 0;
  7399. buf[i++] = (char)(0xf0 + (c >> 18));
  7400. buf[i++] = (char)(0x80 + ((c >> 12) & 0x3f));
  7401. buf[i++] = (char)(0x80 + ((c >> 6) & 0x3f));
  7402. buf[i++] = (char)(0x80 + ((c ) & 0x3f));
  7403. return 4;
  7404. }
  7405. //else if (c < 0x10000)
  7406. {
  7407. if (i+3 > n) return 0;
  7408. buf[i++] = (char)(0xe0 + (c >> 12));
  7409. buf[i++] = (char)(0x80 + ((c>> 6) & 0x3f));
  7410. buf[i++] = (char)(0x80 + ((c ) & 0x3f));
  7411. return 3;
  7412. }
  7413. }
  7414. return 0;
  7415. }
  7416. static ptrdiff_t ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end)
  7417. {
  7418. char* buf_out = buf;
  7419. const char* buf_end = buf + buf_size;
  7420. while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text)
  7421. {
  7422. buf_out += ImTextCharToUtf8(buf_out, (uintptr_t)(buf_end-buf_out-1), (unsigned int)*in_text);
  7423. in_text++;
  7424. }
  7425. *buf_out = 0;
  7426. return buf_out - buf;
  7427. }
  7428. static int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end)
  7429. {
  7430. int bytes_count = 0;
  7431. while ((!in_text_end || in_text < in_text_end) && *in_text)
  7432. {
  7433. char dummy[5]; // FIXME-OPT
  7434. bytes_count += ImTextCharToUtf8(dummy, 5, (unsigned int)*in_text);
  7435. in_text++;
  7436. }
  7437. return bytes_count;
  7438. }
  7439. const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const
  7440. {
  7441. // Simple word-wrapping for English, not full-featured. Please submit failing cases!
  7442. // FIXME: Much possible improvements (don't cut things like "word !", "word!!!" but cut within "word,,,,", more sensible support for punctuations, support for Unicode punctuations, etc.)
  7443. // For references, possible wrap point marked with ^
  7444. // "aaa bbb, ccc,ddd. eee fff. ggg!"
  7445. // ^ ^ ^ ^ ^__ ^ ^
  7446. // List of hardcoded separators: .,;!?'"
  7447. // Skip extra blanks after a line returns (that includes not counting them in width computation)
  7448. // e.g. "Hello world" --> "Hello" "World"
  7449. // Cut words that cannot possibly fit within one line.
  7450. // e.g.: "The tropical fish" with ~5 characters worth of width --> "The tr" "opical" "fish"
  7451. float line_width = 0.0f;
  7452. float word_width = 0.0f;
  7453. float blank_width = 0.0f;
  7454. const char* word_end = text;
  7455. const char* prev_word_end = NULL;
  7456. bool inside_word = true;
  7457. const char* s = text;
  7458. while (s < text_end)
  7459. {
  7460. unsigned int c = (unsigned int)*s;
  7461. const char* next_s;
  7462. if (c < 0x80)
  7463. next_s = s + 1;
  7464. else
  7465. next_s = s + ImTextCharFromUtf8(&c, s, text_end);
  7466. if (c == 0)
  7467. break;
  7468. if (c == '\n')
  7469. {
  7470. line_width = word_width = blank_width = 0.0f;
  7471. inside_word = true;
  7472. s = next_s;
  7473. continue;
  7474. }
  7475. const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance;
  7476. if (ImCharIsSpace(c))
  7477. {
  7478. if (inside_word)
  7479. {
  7480. line_width += blank_width;
  7481. blank_width = 0.0f;
  7482. }
  7483. blank_width += char_width;
  7484. inside_word = false;
  7485. }
  7486. else
  7487. {
  7488. word_width += char_width;
  7489. if (inside_word)
  7490. {
  7491. word_end = next_s;
  7492. }
  7493. else
  7494. {
  7495. prev_word_end = word_end;
  7496. line_width += word_width + blank_width;
  7497. word_width = blank_width = 0.0f;
  7498. }
  7499. // Allow wrapping after punctuation.
  7500. inside_word = !(c == '.' || c == ',' || c == ';' || c == '!' || c == '?' || c == '\"');
  7501. }
  7502. // We ignore blank width at the end of the line (they can be skipped)
  7503. if (line_width + word_width >= wrap_width)
  7504. {
  7505. // Words that cannot possibly fit within an entire line will be cut anywhere.
  7506. if (word_width < wrap_width)
  7507. s = prev_word_end ? prev_word_end : word_end;
  7508. break;
  7509. }
  7510. s = next_s;
  7511. }
  7512. return s;
  7513. }
  7514. ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining) const
  7515. {
  7516. if (!text_end)
  7517. text_end = text_begin + strlen(text_begin); // FIXME-OPT: Need to avoid this.
  7518. const float scale = size / FontSize;
  7519. const float line_height = FontSize * scale;
  7520. ImVec2 text_size = ImVec2(0,0);
  7521. float line_width = 0.0f;
  7522. const bool word_wrap_enabled = (wrap_width > 0.0f);
  7523. const char* word_wrap_eol = NULL;
  7524. const char* s = text_begin;
  7525. while (s < text_end)
  7526. {
  7527. if (word_wrap_enabled)
  7528. {
  7529. // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
  7530. if (!word_wrap_eol)
  7531. {
  7532. word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - line_width);
  7533. if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
  7534. word_wrap_eol++; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below
  7535. }
  7536. if (s >= word_wrap_eol)
  7537. {
  7538. if (text_size.x < line_width)
  7539. text_size.x = line_width;
  7540. text_size.y += line_height;
  7541. line_width = 0.0f;
  7542. word_wrap_eol = NULL;
  7543. // Wrapping skips upcoming blanks
  7544. while (s < text_end)
  7545. {
  7546. const char c = *s;
  7547. if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; }
  7548. }
  7549. continue;
  7550. }
  7551. }
  7552. // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
  7553. const char* prev_s = s;
  7554. unsigned int c = (unsigned int)*s;
  7555. if (c < 0x80)
  7556. {
  7557. s += 1;
  7558. }
  7559. else
  7560. {
  7561. s += ImTextCharFromUtf8(&c, s, text_end);
  7562. if (c == 0)
  7563. break;
  7564. }
  7565. if (c == '\n')
  7566. {
  7567. text_size.x = ImMax(text_size.x, line_width);
  7568. text_size.y += line_height;
  7569. line_width = 0.0f;
  7570. continue;
  7571. }
  7572. const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance;
  7573. if (line_width + char_width >= max_width)
  7574. {
  7575. s = prev_s;
  7576. break;
  7577. }
  7578. line_width += char_width;
  7579. }
  7580. if (line_width > 0 || text_size.y == 0.0f)
  7581. {
  7582. if (text_size.x < line_width)
  7583. text_size.x = line_width;
  7584. text_size.y += line_height;
  7585. }
  7586. if (remaining)
  7587. *remaining = s;
  7588. return text_size;
  7589. }
  7590. ImVec2 ImFont::CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining) const
  7591. {
  7592. if (!text_end)
  7593. text_end = text_begin + ImStrlenW(text_begin);
  7594. const float scale = size / FontSize;
  7595. const float line_height = FontSize * scale;
  7596. ImVec2 text_size = ImVec2(0,0);
  7597. float line_width = 0.0f;
  7598. const ImWchar* s = text_begin;
  7599. while (s < text_end)
  7600. {
  7601. const unsigned int c = (unsigned int)(*s++);
  7602. if (c == '\n')
  7603. {
  7604. text_size.x = ImMax(text_size.x, line_width);
  7605. text_size.y += line_height;
  7606. line_width = 0.0f;
  7607. continue;
  7608. }
  7609. const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance;
  7610. if (line_width + char_width >= max_width)
  7611. {
  7612. s--;
  7613. break;
  7614. }
  7615. line_width += char_width;
  7616. }
  7617. if (line_width > 0 || text_size.y == 0.0f)
  7618. {
  7619. if (text_size.x < line_width)
  7620. text_size.x = line_width;
  7621. text_size.y += line_height;
  7622. }
  7623. if (remaining)
  7624. *remaining = s;
  7625. return text_size;
  7626. }
  7627. void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect_ref, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices, float wrap_width, const ImVec2* cpu_clip_max) const
  7628. {
  7629. if (!text_end)
  7630. text_end = text_begin + strlen(text_begin);
  7631. const float scale = size / FontSize;
  7632. const float line_height = FontSize * scale;
  7633. // Align to be pixel perfect
  7634. pos.x = (float)(int)pos.x + DisplayOffset.x;
  7635. pos.y = (float)(int)pos.y + DisplayOffset.y;
  7636. const bool word_wrap_enabled = (wrap_width > 0.0f);
  7637. const char* word_wrap_eol = NULL;
  7638. ImVec4 clip_rect = clip_rect_ref;
  7639. if (cpu_clip_max)
  7640. {
  7641. clip_rect.z = ImMin(clip_rect.z, cpu_clip_max->x);
  7642. clip_rect.w = ImMin(clip_rect.w, cpu_clip_max->y);
  7643. }
  7644. float x = pos.x;
  7645. float y = pos.y;
  7646. const char* s = text_begin;
  7647. while (s < text_end)
  7648. {
  7649. if (word_wrap_enabled)
  7650. {
  7651. // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
  7652. if (!word_wrap_eol)
  7653. {
  7654. word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - pos.x));
  7655. if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
  7656. word_wrap_eol++; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below
  7657. }
  7658. if (s >= word_wrap_eol)
  7659. {
  7660. x = pos.x;
  7661. y += line_height;
  7662. word_wrap_eol = NULL;
  7663. // Wrapping skips upcoming blanks
  7664. while (s < text_end)
  7665. {
  7666. const char c = *s;
  7667. if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; }
  7668. }
  7669. continue;
  7670. }
  7671. }
  7672. // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
  7673. unsigned int c = (unsigned int)*s;
  7674. if (c < 0x80)
  7675. {
  7676. s += 1;
  7677. }
  7678. else
  7679. {
  7680. s += ImTextCharFromUtf8(&c, s, text_end);
  7681. if (c == 0)
  7682. break;
  7683. }
  7684. if (c == '\n')
  7685. {
  7686. x = pos.x;
  7687. y += line_height;
  7688. continue;
  7689. }
  7690. float char_width = 0.0f;
  7691. if (const Glyph* glyph = FindGlyph((unsigned short)c))
  7692. {
  7693. char_width = glyph->XAdvance * scale;
  7694. if (c != ' ' && c != '\t')
  7695. {
  7696. // Clipping on Y is more likely
  7697. float y1 = (float)(y + glyph->YOffset * scale);
  7698. float y2 = (float)(y1 + glyph->Height * scale);
  7699. if (y1 <= clip_rect.w && y2 >= clip_rect.y)
  7700. {
  7701. float x1 = (float)(x + glyph->XOffset * scale);
  7702. float x2 = (float)(x1 + glyph->Width * scale);
  7703. if (x1 <= clip_rect.z && x2 >= clip_rect.x)
  7704. {
  7705. // Render a character
  7706. float u1 = glyph->U0;
  7707. float v1 = glyph->V0;
  7708. float u2 = glyph->U1;
  7709. float v2 = glyph->V1;
  7710. // CPU side clipping used to fit text in their frame when the frame is too small. Only does clipping for axis aligned quad and in the "max" direction (bottom-right)
  7711. if (cpu_clip_max)
  7712. {
  7713. if (x2 > cpu_clip_max->x)
  7714. {
  7715. const float clip_tx = (cpu_clip_max->x - x1) / (x2 - x1);
  7716. x2 = cpu_clip_max->x;
  7717. u2 = u1 + clip_tx * (u2 - u1);
  7718. }
  7719. if (y2 > cpu_clip_max->y)
  7720. {
  7721. const float clip_ty = (cpu_clip_max->y - y1) / (y2 - y1);
  7722. y2 = cpu_clip_max->y;
  7723. v2 = v1 + clip_ty * (v2 - v1);
  7724. }
  7725. }
  7726. out_vertices[0].pos = ImVec2(x1, y1);
  7727. out_vertices[0].uv = ImVec2(u1, v1);
  7728. out_vertices[0].col = col;
  7729. out_vertices[1].pos = ImVec2(x2, y1);
  7730. out_vertices[1].uv = ImVec2(u2, v1);
  7731. out_vertices[1].col = col;
  7732. out_vertices[2].pos = ImVec2(x2, y2);
  7733. out_vertices[2].uv = ImVec2(u2, v2);
  7734. out_vertices[2].col = col;
  7735. out_vertices[3] = out_vertices[0];
  7736. out_vertices[4] = out_vertices[2];
  7737. out_vertices[5].pos = ImVec2(x1, y2);
  7738. out_vertices[5].uv = ImVec2(u1, v2);
  7739. out_vertices[5].col = col;
  7740. out_vertices += 6;
  7741. }
  7742. }
  7743. }
  7744. }
  7745. x += char_width;
  7746. }
  7747. }
  7748. //-----------------------------------------------------------------------------
  7749. // PLATFORM DEPENDANT HELPERS
  7750. //-----------------------------------------------------------------------------
  7751. #if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS)
  7752. #ifndef _WINDOWS_
  7753. #define WIN32_LEAN_AND_MEAN
  7754. #include <windows.h>
  7755. #endif
  7756. // Win32 API clipboard implementation
  7757. static const char* GetClipboardTextFn_DefaultImpl()
  7758. {
  7759. static char* buf_local = NULL;
  7760. if (buf_local)
  7761. {
  7762. ImGui::MemFree(buf_local);
  7763. buf_local = NULL;
  7764. }
  7765. if (!OpenClipboard(NULL))
  7766. return NULL;
  7767. HANDLE wbuf_handle = GetClipboardData(CF_UNICODETEXT);
  7768. if (wbuf_handle == NULL)
  7769. return NULL;
  7770. if (ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle))
  7771. {
  7772. int buf_len = ImTextCountUtf8BytesFromStr(wbuf_global, NULL) + 1;
  7773. buf_local = (char*)ImGui::MemAlloc(buf_len * sizeof(char));
  7774. ImTextStrToUtf8(buf_local, buf_len, wbuf_global, NULL);
  7775. }
  7776. GlobalUnlock(wbuf_handle);
  7777. CloseClipboard();
  7778. return buf_local;
  7779. }
  7780. // Win32 API clipboard implementation
  7781. static void SetClipboardTextFn_DefaultImpl(const char* text)
  7782. {
  7783. if (!OpenClipboard(NULL))
  7784. return;
  7785. const int wbuf_length = ImTextCountCharsFromUtf8(text, NULL) + 1;
  7786. HGLOBAL wbuf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)wbuf_length * sizeof(ImWchar));
  7787. if (wbuf_handle == NULL)
  7788. return;
  7789. ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle);
  7790. ImTextStrFromUtf8(wbuf_global, wbuf_length, text, NULL);
  7791. GlobalUnlock(wbuf_handle);
  7792. EmptyClipboard();
  7793. SetClipboardData(CF_UNICODETEXT, wbuf_handle);
  7794. CloseClipboard();
  7795. }
  7796. #else
  7797. // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
  7798. static const char* GetClipboardTextFn_DefaultImpl()
  7799. {
  7800. return GImGui->PrivateClipboard;
  7801. }
  7802. // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
  7803. static void SetClipboardTextFn_DefaultImpl(const char* text)
  7804. {
  7805. ImGuiState& g = *GImGui;
  7806. if (g.PrivateClipboard)
  7807. {
  7808. ImGui::MemFree(g.PrivateClipboard);
  7809. g.PrivateClipboard = NULL;
  7810. }
  7811. const char* text_end = text + strlen(text);
  7812. g.PrivateClipboard = (char*)ImGui::MemAlloc((size_t)(text_end - text) + 1);
  7813. memcpy(g.PrivateClipboard, text, (size_t)(text_end - text));
  7814. g.PrivateClipboard[(size_t)(text_end - text)] = 0;
  7815. }
  7816. #endif
  7817. #if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS)
  7818. #ifndef _WINDOWS_
  7819. #define WIN32_LEAN_AND_MEAN
  7820. #include <windows.h>
  7821. #endif
  7822. #include <Imm.h>
  7823. #pragma comment(lib, "imm32")
  7824. static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y)
  7825. {
  7826. // Notify OS Input Method Editor of text input position
  7827. if (HWND hwnd = (HWND)GImGui->IO.ImeWindowHandle)
  7828. if (HIMC himc = ImmGetContext(hwnd))
  7829. {
  7830. COMPOSITIONFORM cf;
  7831. cf.ptCurrentPos.x = x;
  7832. cf.ptCurrentPos.y = y;
  7833. cf.dwStyle = CFS_FORCE_POSITION;
  7834. ImmSetCompositionWindow(himc, &cf);
  7835. }
  7836. }
  7837. #else
  7838. static void ImeSetInputScreenPosFn_DefaultImpl(int, int)
  7839. {
  7840. }
  7841. #endif
  7842. #ifdef IMGUI_DISABLE_TEST_WINDOWS
  7843. void ImGui::ShowUserGuide() {}
  7844. void ImGui::ShowStyleEditor(ImGuiStyle*) {}
  7845. void ImGui::ShowTestWindow(bool*) {}
  7846. #else
  7847. //-----------------------------------------------------------------------------
  7848. // HELP
  7849. //-----------------------------------------------------------------------------
  7850. void ImGui::ShowUserGuide()
  7851. {
  7852. ImGuiState& g = *GImGui;
  7853. ImGui::BulletText("Double-click on title bar to collapse window.");
  7854. ImGui::BulletText("Click and drag on lower right corner to resize window.");
  7855. ImGui::BulletText("Click and drag on any empty space to move window.");
  7856. ImGui::BulletText("Mouse Wheel to scroll.");
  7857. if (g.IO.FontAllowUserScaling)
  7858. ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents.");
  7859. ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields.");
  7860. ImGui::BulletText("CTRL+Click on a slider to input text.");
  7861. ImGui::BulletText(
  7862. "While editing text:\n"
  7863. "- Hold SHIFT or use mouse to select text\n"
  7864. "- CTRL+Left/Right to word jump\n"
  7865. "- CTRL+A select all\n"
  7866. "- CTRL+X,CTRL+C,CTRL+V clipboard\n"
  7867. "- CTRL+Z,CTRL+Y undo/redo\n"
  7868. "- ESCAPE to revert\n"
  7869. "- You can apply arithmetic operators +,*,/ on numerical values.\n"
  7870. " Use +- to subtract.\n");
  7871. }
  7872. void ImGui::ShowStyleEditor(ImGuiStyle* ref)
  7873. {
  7874. ImGuiState& g = *GImGui;
  7875. ImGuiStyle& style = g.Style;
  7876. const ImGuiStyle def; // Default style
  7877. if (ImGui::Button("Revert Style"))
  7878. g.Style = ref ? *ref : def;
  7879. if (ref)
  7880. {
  7881. ImGui::SameLine();
  7882. if (ImGui::Button("Save Style"))
  7883. *ref = g.Style;
  7884. }
  7885. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.55f);
  7886. if (ImGui::TreeNode("Sizes"))
  7887. {
  7888. ImGui::SliderFloat("Alpha", &style.Alpha, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI. But application code could have a toggle to switch between zero and non-zero.
  7889. ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f");
  7890. ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f");
  7891. ImGui::SliderFloat("ChildWindowRounding", &style.ChildWindowRounding, 0.0f, 16.0f, "%.0f");
  7892. ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f");
  7893. ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 16.0f, "%.0f");
  7894. ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f");
  7895. ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f");
  7896. ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f");
  7897. ImGui::SliderFloat("IndentSpacing", &style.IndentSpacing, 0.0f, 20.0f, "%.0f");
  7898. ImGui::SliderFloat("ScrollBarWidth", &style.ScrollbarWidth, 1.0f, 20.0f, "%.0f");
  7899. ImGui::SliderFloat("GrabMinSize", &style.GrabMinSize, 1.0f, 20.0f, "%.0f");
  7900. ImGui::TreePop();
  7901. }
  7902. if (ImGui::TreeNode("Colors"))
  7903. {
  7904. static int output_dest = 0;
  7905. static bool output_only_modified = false;
  7906. if (ImGui::Button("Output Colors"))
  7907. {
  7908. if (output_dest == 0)
  7909. ImGui::LogToClipboard();
  7910. else
  7911. ImGui::LogToTTY();
  7912. ImGui::LogText("ImGuiStyle& style = ImGui::GetStyle();" STR_NEWLINE);
  7913. for (int i = 0; i < ImGuiCol_COUNT; i++)
  7914. {
  7915. const ImVec4& col = style.Colors[i];
  7916. const char* name = ImGui::GetStyleColName(i);
  7917. if (!output_only_modified || memcmp(&col, (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0)
  7918. ImGui::LogText("style.Colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff);" STR_NEWLINE, name, 22 - strlen(name), "", col.x, col.y, col.z, col.w);
  7919. }
  7920. ImGui::LogFinish();
  7921. }
  7922. ImGui::SameLine(); ImGui::PushItemWidth(150); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY"); ImGui::PopItemWidth();
  7923. ImGui::SameLine(); ImGui::Checkbox("Only Modified Fields", &output_only_modified);
  7924. static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB;
  7925. ImGui::RadioButton("RGB", &edit_mode, ImGuiColorEditMode_RGB);
  7926. ImGui::SameLine();
  7927. ImGui::RadioButton("HSV", &edit_mode, ImGuiColorEditMode_HSV);
  7928. ImGui::SameLine();
  7929. ImGui::RadioButton("HEX", &edit_mode, ImGuiColorEditMode_HEX);
  7930. //ImGui::Text("Tip: Click on colored square to change edit mode.");
  7931. static ImGuiTextFilter filter;
  7932. filter.Draw("Filter colors", 200);
  7933. ImGui::BeginChild("#colors", ImVec2(0, 300), true);
  7934. ImGui::ColorEditMode(edit_mode);
  7935. for (int i = 0; i < ImGuiCol_COUNT; i++)
  7936. {
  7937. const char* name = ImGui::GetStyleColName(i);
  7938. if (!filter.PassFilter(name))
  7939. continue;
  7940. ImGui::PushID(i);
  7941. ImGui::ColorEdit4(name, (float*)&style.Colors[i], true);
  7942. if (memcmp(&style.Colors[i], (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0)
  7943. {
  7944. ImGui::SameLine(); if (ImGui::Button("Revert")) style.Colors[i] = ref ? ref->Colors[i] : def.Colors[i];
  7945. if (ref) { ImGui::SameLine(); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i]; }
  7946. }
  7947. ImGui::PopID();
  7948. }
  7949. ImGui::EndChild();
  7950. ImGui::TreePop();
  7951. }
  7952. ImGui::PopItemWidth();
  7953. }
  7954. //-----------------------------------------------------------------------------
  7955. // SAMPLE CODE
  7956. //-----------------------------------------------------------------------------
  7957. static void ShowExampleAppConsole(bool* opened);
  7958. static void ShowExampleAppLongText(bool* opened);
  7959. static void ShowExampleAppAutoResize(bool* opened);
  7960. static void ShowExampleAppFixedOverlay(bool* opened);
  7961. static void ShowExampleAppManipulatingWindowTitle(bool* opened);
  7962. static void ShowExampleAppCustomRendering(bool* opened);
  7963. // Demonstrate ImGui features (unfortunately this makes this function a little bloated!)
  7964. void ImGui::ShowTestWindow(bool* opened)
  7965. {
  7966. // Examples apps
  7967. static bool show_app_console = false;
  7968. static bool show_app_long_text = false;
  7969. static bool show_app_auto_resize = false;
  7970. static bool show_app_fixed_overlay = false;
  7971. static bool show_app_custom_rendering = false;
  7972. static bool show_app_manipulating_window_title = false;
  7973. if (show_app_console)
  7974. ShowExampleAppConsole(&show_app_console);
  7975. if (show_app_long_text)
  7976. ShowExampleAppLongText(&show_app_long_text);
  7977. if (show_app_auto_resize)
  7978. ShowExampleAppAutoResize(&show_app_auto_resize);
  7979. if (show_app_fixed_overlay)
  7980. ShowExampleAppFixedOverlay(&show_app_fixed_overlay);
  7981. if (show_app_manipulating_window_title)
  7982. ShowExampleAppManipulatingWindowTitle(&show_app_manipulating_window_title);
  7983. if (show_app_custom_rendering)
  7984. ShowExampleAppCustomRendering(&show_app_custom_rendering);
  7985. static bool no_titlebar = false;
  7986. static bool no_border = true;
  7987. static bool no_resize = false;
  7988. static bool no_move = false;
  7989. static bool no_scrollbar = false;
  7990. static bool no_collapse = false;
  7991. static float bg_alpha = 0.65f;
  7992. // Demonstrate the various window flags. Typically you would just use the default.
  7993. ImGuiWindowFlags window_flags = 0;
  7994. if (no_titlebar) window_flags |= ImGuiWindowFlags_NoTitleBar;
  7995. if (!no_border) window_flags |= ImGuiWindowFlags_ShowBorders;
  7996. if (no_resize) window_flags |= ImGuiWindowFlags_NoResize;
  7997. if (no_move) window_flags |= ImGuiWindowFlags_NoMove;
  7998. if (no_scrollbar) window_flags |= ImGuiWindowFlags_NoScrollbar;
  7999. if (no_collapse) window_flags |= ImGuiWindowFlags_NoCollapse;
  8000. if (!ImGui::Begin("ImGui Test", opened, ImVec2(550,680), bg_alpha, window_flags))
  8001. {
  8002. // Early out if the window is collapsed, as an optimization.
  8003. ImGui::End();
  8004. return;
  8005. }
  8006. //ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); // 2/3 of the space for widget and 1/3 for labels
  8007. ImGui::PushItemWidth(-140); // Right align, keep 140 pixels for labels
  8008. ImGui::Text("ImGui says hello.");
  8009. //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
  8010. //ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel);
  8011. //ImGui::Text("KeyMods %s%s%s", ImGui::GetIO().KeyCtrl ? "CTRL" : "", ImGui::GetIO().KeyShift ? "SHIFT" : "", ImGui::GetIO().KeyAlt? "ALT" : "");
  8012. //ImGui::Text("WantCaptureMouse: %d", ImGui::GetIO().WantCaptureMouse);
  8013. //ImGui::Text("WantCaptureKeyboard: %d", ImGui::GetIO().WantCaptureKeyboard);
  8014. ImGui::Spacing();
  8015. if (ImGui::CollapsingHeader("Help"))
  8016. {
  8017. ImGui::TextWrapped("This window is being created by the ShowTestWindow() function. Please refer to the code for programming reference.\n\nUser Guide:");
  8018. ImGui::ShowUserGuide();
  8019. }
  8020. if (ImGui::CollapsingHeader("Window options"))
  8021. {
  8022. ImGui::Checkbox("no titlebar", &no_titlebar); ImGui::SameLine(150);
  8023. ImGui::Checkbox("no border", &no_border); ImGui::SameLine(300);
  8024. ImGui::Checkbox("no resize", &no_resize);
  8025. ImGui::Checkbox("no move", &no_move); ImGui::SameLine(150);
  8026. ImGui::Checkbox("no scrollbar", &no_scrollbar); ImGui::SameLine(300);
  8027. ImGui::Checkbox("no collapse", &no_collapse);
  8028. ImGui::SliderFloat("bg alpha", &bg_alpha, 0.0f, 1.0f);
  8029. if (ImGui::TreeNode("Style"))
  8030. {
  8031. ImGui::ShowStyleEditor();
  8032. ImGui::TreePop();
  8033. }
  8034. if (ImGui::TreeNode("Fonts"))
  8035. {
  8036. ImGui::TextWrapped("Tip: Load fonts with GetIO().Fonts->AddFontFromFileTTF().");
  8037. for (size_t i = 0; i < ImGui::GetIO().Fonts->Fonts.size(); i++)
  8038. {
  8039. ImFont* font = ImGui::GetIO().Fonts->Fonts[i];
  8040. ImGui::BulletText("Font %d: %.2f pixels, %d glyphs", i, font->FontSize, font->Glyphs.size());
  8041. ImGui::TreePush((void*)i);
  8042. ImGui::PushFont(font);
  8043. ImGui::Text("The quick brown fox jumps over the lazy dog");
  8044. ImGui::PopFont();
  8045. if (i > 0 && ImGui::Button("Set as default"))
  8046. {
  8047. ImGui::GetIO().Fonts->Fonts[i] = ImGui::GetIO().Fonts->Fonts[0];
  8048. ImGui::GetIO().Fonts->Fonts[0] = font;
  8049. }
  8050. ImGui::SliderFloat("font scale", &font->Scale, 0.3f, 2.0f, "%.1f"); // scale only this font
  8051. ImGui::TreePop();
  8052. }
  8053. static float window_scale = 1.0f;
  8054. ImGui::SliderFloat("this window scale", &window_scale, 0.3f, 2.0f, "%.1f"); // scale only this window
  8055. ImGui::SliderFloat("global scale", &ImGui::GetIO().FontGlobalScale, 0.3f, 2.0f, "%.1f"); // scale everything
  8056. ImGui::SetWindowFontScale(window_scale);
  8057. ImGui::TreePop();
  8058. }
  8059. if (ImGui::TreeNode("Logging"))
  8060. {
  8061. ImGui::LogButtons();
  8062. ImGui::TreePop();
  8063. }
  8064. }
  8065. if (ImGui::CollapsingHeader("Widgets"))
  8066. {
  8067. static bool a=false;
  8068. if (ImGui::Button("Button")) { printf("Clicked\n"); a ^= 1; }
  8069. if (a)
  8070. {
  8071. ImGui::SameLine();
  8072. ImGui::Text("Thanks for clicking me!");
  8073. }
  8074. if (ImGui::TreeNode("Tree"))
  8075. {
  8076. for (size_t i = 0; i < 5; i++)
  8077. {
  8078. if (ImGui::TreeNode((void*)i, "Child %d", i))
  8079. {
  8080. ImGui::Text("blah blah");
  8081. ImGui::SameLine();
  8082. if (ImGui::SmallButton("print"))
  8083. printf("Child %d pressed", (int)i);
  8084. ImGui::TreePop();
  8085. }
  8086. }
  8087. ImGui::TreePop();
  8088. }
  8089. if (ImGui::TreeNode("Bullets"))
  8090. {
  8091. ImGui::BulletText("Bullet point 1");
  8092. ImGui::BulletText("Bullet point 2\nOn multiple lines");
  8093. ImGui::Bullet(); ImGui::Text("Bullet point 3 (two calls)");
  8094. ImGui::Bullet(); ImGui::SmallButton("Button 1");
  8095. ImGui::Bullet(); ImGui::SmallButton("Button 2");
  8096. ImGui::TreePop();
  8097. }
  8098. if (ImGui::TreeNode("Colored Text"))
  8099. {
  8100. // Using shortcut. You can use PushStyleColor()/PopStyleColor() for more flexibility.
  8101. ImGui::TextColored(ImVec4(1.0f,0.0f,1.0f,1.0f), "Pink");
  8102. ImGui::TextColored(ImVec4(1.0f,1.0f,0.0f,1.0f), "Yellow");
  8103. ImGui::TreePop();
  8104. }
  8105. if (ImGui::TreeNode("Word Wrapping"))
  8106. {
  8107. // Using shortcut. You can use PushTextWrapPos()/PopTextWrapPos() for more flexibility.
  8108. ImGui::TextWrapped("This text should automatically wrap on the edge of the window. The current implementation for text wrapping follows simple rules that works for English and possibly other languages.");
  8109. ImGui::Spacing();
  8110. static float wrap_width = 200.0f;
  8111. ImGui::SliderFloat("Wrap width", &wrap_width, -20, 600, "%.0f");
  8112. ImGui::Text("Test paragraph 1:");
  8113. ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF);
  8114. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  8115. ImGui::Text("lazy dog. This paragraph is made to fit within %.0f pixels. The quick brown fox jumps over the lazy dog.", wrap_width);
  8116. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), 0xFF00FFFF);
  8117. ImGui::PopTextWrapPos();
  8118. ImGui::Text("Test paragraph 2:");
  8119. ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF);
  8120. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  8121. ImGui::Text("aaaaaaaa bbbbbbbb, cccccccc,dddddddd. eeeeeeee ffffffff. gggggggg!hhhhhhhh");
  8122. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), 0xFF00FFFF);
  8123. ImGui::PopTextWrapPos();
  8124. ImGui::TreePop();
  8125. }
  8126. if (ImGui::TreeNode("UTF-8 Text"))
  8127. {
  8128. // UTF-8 test with Japanese characters
  8129. // (needs a suitable font, try Arial Unicode or M+ fonts http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html)
  8130. // Most compiler appears to support UTF-8 in source code (with Visual Studio you need to save your file as 'UTF-8 without signature')
  8131. // However for the sake for maximum portability here we are *not* including raw UTF-8 character in this source file, instead we encode the string with hexadecimal constants.
  8132. // In your own application be reasonable and use UTF-8 in source or retrieve the data from file system!
  8133. // Note that characters values are preserved even if the font cannot be displayed, so you can safely copy & paste garbled characters into another application.
  8134. ImGui::TextWrapped("CJK text will only appears if the font was loaded with the appropriate CJK character ranges. Call io.Font->LoadFromFileTTF() manually to load extra character ranges.");
  8135. ImGui::Text("Hiragana: \xe3\x81\x8b\xe3\x81\x8d\xe3\x81\x8f\xe3\x81\x91\xe3\x81\x93 (kakikukeko)");
  8136. ImGui::Text("Kanjis: \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e (nihongo)");
  8137. static char buf[32] = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e";
  8138. ImGui::InputText("UTF-8 input", buf, IM_ARRAYSIZE(buf));
  8139. ImGui::TreePop();
  8140. }
  8141. if (ImGui::TreeNode("Clipping"))
  8142. {
  8143. static ImVec2 size(80, 20);
  8144. ImGui::TextWrapped("On a per-widget basis we are occasionally clipping text if it won't fit in its frame.");
  8145. ImGui::SliderFloat2("size", (float*)&size, 5.0f, 200.0f);
  8146. ImGui::Button("Line 1 hello\nLine 2 clip me!", size);
  8147. ImGui::TextWrapped("Otherwise we are doing coarser clipping + passing a scissor rectangle to the renderer. The system is designed to try minimizing both execution and rendering cost.");
  8148. ImGui::TreePop();
  8149. }
  8150. if (ImGui::TreeNode("Images"))
  8151. {
  8152. ImGui::TextWrapped("Below we are displaying the font texture (which is the only texture we have access to in this demo). Use the 'ImTextureID' type as storage to pass pointers or identifier to your own texture data. Hover the texture for a zoomed view!");
  8153. ImVec2 tex_screen_pos = ImGui::GetCursorScreenPos();
  8154. float tex_w = (float)ImGui::GetIO().Fonts->TexWidth;
  8155. float tex_h = (float)ImGui::GetIO().Fonts->TexHeight;
  8156. ImTextureID tex_id = ImGui::GetIO().Fonts->TexID;
  8157. ImGui::Image(tex_id, ImVec2(tex_w, tex_h), ImVec2(0,0), ImVec2(1,1), ImColor(255,255,255,255), ImColor(255,255,255,128));
  8158. if (ImGui::IsItemHovered())
  8159. {
  8160. ImGui::BeginTooltip();
  8161. float focus_sz = 32.0f;
  8162. float focus_x = ImClamp(ImGui::GetMousePos().x - tex_screen_pos.x - focus_sz * 0.5f, 0.0f, tex_w - focus_sz);
  8163. float focus_y = ImClamp(ImGui::GetMousePos().y - tex_screen_pos.y - focus_sz * 0.5f, 0.0f, tex_h - focus_sz);
  8164. ImGui::Text("Min: (%.2f, %.2f)", focus_x, focus_y);
  8165. ImGui::Text("Max: (%.2f, %.2f)", focus_x + focus_sz, focus_y + focus_sz);
  8166. ImVec2 uv0 = ImVec2((focus_x) / tex_w, (focus_y) / tex_h);
  8167. ImVec2 uv1 = ImVec2((focus_x + focus_sz) / tex_w, (focus_y + focus_sz) / tex_h);
  8168. ImGui::Image(tex_id, ImVec2(128,128), uv0, uv1, ImColor(255,255,255,255), ImColor(255,255,255,128));
  8169. ImGui::EndTooltip();
  8170. }
  8171. ImGui::TextWrapped("And now some textured buttons..");
  8172. static int pressed_count = 0;
  8173. for (int i = 0; i < 8; i++)
  8174. {
  8175. if (i > 0)
  8176. ImGui::SameLine();
  8177. ImGui::PushID(i);
  8178. int frame_padding = -1 + i; // -1 padding uses default padding
  8179. if (ImGui::ImageButton(tex_id, ImVec2(32,32), ImVec2(0,0), ImVec2(32.0f/tex_w,32/tex_h), frame_padding))
  8180. pressed_count += 1;
  8181. ImGui::PopID();
  8182. }
  8183. ImGui::Text("Pressed %d times.", pressed_count);
  8184. ImGui::TreePop();
  8185. }
  8186. if (ImGui::TreeNode("Selectables"))
  8187. {
  8188. if (ImGui::TreeNode("Basic"))
  8189. {
  8190. static bool selected[3] = { false, true, false };
  8191. ImGui::Selectable("1. I am selectable", &selected[0]);
  8192. ImGui::Selectable("2. I am selectable", &selected[1]);
  8193. ImGui::Text("3. I am not selectable");
  8194. ImGui::Selectable("4. I am selectable", &selected[2]);
  8195. ImGui::TreePop();
  8196. }
  8197. if (ImGui::TreeNode("Rendering more text into the same block"))
  8198. {
  8199. static bool selected[3] = { false, false, false };
  8200. ImGui::Selectable("main.c", &selected[0]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes");
  8201. ImGui::Selectable("Hello.cpp", &selected[1]); ImGui::SameLine(300); ImGui::Text("12,345 bytes");
  8202. ImGui::Selectable("Hello.h", &selected[2]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes");
  8203. ImGui::TreePop();
  8204. }
  8205. if (ImGui::TreeNode("Grid"))
  8206. {
  8207. static bool selected[16] = { true, false, false, false, false, true, false, false, false, false, true, false, false, false, false, true };
  8208. for (int i = 0; i < 16; i++)
  8209. {
  8210. ImGui::PushID(i);
  8211. if (ImGui::Selectable("Me", &selected[i], ImVec2(50,50)))
  8212. {
  8213. int x = i % 4, y = i / 4;
  8214. if (x > 0) selected[i - 1] ^= 1;
  8215. if (x < 3) selected[i + 1] ^= 1;
  8216. if (y > 0) selected[i - 4] ^= 1;
  8217. if (y < 3) selected[i + 4] ^= 1;
  8218. }
  8219. if ((i % 4) < 3) ImGui::SameLine();
  8220. ImGui::PopID();
  8221. }
  8222. ImGui::TreePop();
  8223. }
  8224. ImGui::TreePop();
  8225. }
  8226. if (ImGui::TreeNode("Popup"))
  8227. {
  8228. static bool popup_open = false;
  8229. static int selected_fish = -1;
  8230. const char* fishes[] = { "Bream", "Haddock", "Mackerel", "Pollock", "Tilefish" };
  8231. if (ImGui::Button("Select.."))
  8232. popup_open = true;
  8233. ImGui::SameLine();
  8234. ImGui::Text(selected_fish == -1 ? "<None>" : fishes[selected_fish]);
  8235. if (popup_open)
  8236. {
  8237. ImGui::BeginPopup(&popup_open);
  8238. ImGui::Text("Aquarium");
  8239. ImGui::Separator();
  8240. for (size_t i = 0; i < IM_ARRAYSIZE(fishes); i++)
  8241. {
  8242. if (ImGui::Selectable(fishes[i], false))
  8243. {
  8244. selected_fish = i;
  8245. popup_open = false;
  8246. }
  8247. }
  8248. ImGui::EndPopup();
  8249. }
  8250. ImGui::TreePop();
  8251. }
  8252. if (ImGui::TreeNode("Filtered Text Input"))
  8253. {
  8254. static char buf1[64] = ""; ImGui::InputText("default", buf1, 64);
  8255. static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal);
  8256. static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
  8257. static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase);
  8258. static char buf5[64] = ""; ImGui::InputText("no blank", buf5, 64, ImGuiInputTextFlags_CharsNoBlank);
  8259. struct TextFilters { static int FilterImGuiLetters(ImGuiTextEditCallbackData* data) { if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar)) return 0; return 1; } };
  8260. static char buf6[64] = ""; ImGui::InputText("\"imgui\" letters", buf6, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters);
  8261. ImGui::TreePop();
  8262. }
  8263. static bool check = true;
  8264. ImGui::Checkbox("checkbox", &check);
  8265. static int e = 0;
  8266. ImGui::RadioButton("radio a", &e, 0); ImGui::SameLine();
  8267. ImGui::RadioButton("radio b", &e, 1); ImGui::SameLine();
  8268. ImGui::RadioButton("radio c", &e, 2);
  8269. // Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style.
  8270. for (int i = 0; i < 7; i++)
  8271. {
  8272. if (i > 0) ImGui::SameLine();
  8273. ImGui::PushID(i);
  8274. ImGui::PushStyleColor(ImGuiCol_Button, ImColor::HSV(i/7.0f, 0.6f, 0.6f));
  8275. ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImColor::HSV(i/7.0f, 0.7f, 0.7f));
  8276. ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImColor::HSV(i/7.0f, 0.8f, 0.8f));
  8277. ImGui::Button("Click");
  8278. ImGui::PopStyleColor(3);
  8279. ImGui::PopID();
  8280. }
  8281. ImGui::Text("Hover over me");
  8282. if (ImGui::IsItemHovered())
  8283. ImGui::SetTooltip("I am a tooltip");
  8284. ImGui::SameLine();
  8285. ImGui::Text("- or me");
  8286. if (ImGui::IsItemHovered())
  8287. {
  8288. ImGui::BeginTooltip();
  8289. ImGui::Text("I am a fancy tooltip");
  8290. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  8291. ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr));
  8292. ImGui::EndTooltip();
  8293. }
  8294. // Testing IMGUI_ONCE_UPON_A_FRAME macro
  8295. //for (int i = 0; i < 5; i++)
  8296. //{
  8297. // IMGUI_ONCE_UPON_A_FRAME
  8298. // {
  8299. // ImGui::Text("This will be displayed only once.");
  8300. // }
  8301. //}
  8302. ImGui::Separator();
  8303. ImGui::LabelText("label", "Value");
  8304. static int item = 1;
  8305. ImGui::Combo("combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0");
  8306. const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK" };
  8307. static int item2 = -1;
  8308. ImGui::Combo("combo scroll", &item2, items, IM_ARRAYSIZE(items));
  8309. static char str0[128] = "Hello, world!";
  8310. static int i0=123;
  8311. static float f0=0.001f;
  8312. ImGui::InputText("string", str0, IM_ARRAYSIZE(str0));
  8313. ImGui::InputInt("input int", &i0);
  8314. ImGui::InputFloat("input float", &f0, 0.01f, 1.0f);
  8315. static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
  8316. //ImGui::InputFloat2("input float2", vec4a);
  8317. ImGui::InputFloat3("input float3", vec4a);
  8318. //ImGui::InputFloat4("input float4", vec4a);
  8319. static int i1=0;
  8320. static int i2=42;
  8321. ImGui::SliderInt("int 0..3", &i1, 0, 3);
  8322. ImGui::SliderInt("int -100..100", &i2, -100, 100);
  8323. static float f1=1.123f;
  8324. static float f2=0;
  8325. static float f3=0;
  8326. static float f4=123456789.0f;
  8327. ImGui::SliderFloat("float", &f1, 0.0f, 2.0f);
  8328. ImGui::SliderFloat("log float", &f2, 0.0f, 10.0f, "%.4f", 2.0f);
  8329. ImGui::SliderFloat("signed log float", &f3, -10.0f, 10.0f, "%.4f", 3.0f);
  8330. ImGui::SliderFloat("unbound float", &f4, -FLT_MAX, FLT_MAX, "%.4f");
  8331. static float angle = 0.0f;
  8332. ImGui::SliderAngle("angle", &angle);
  8333. static float col1[3] = { 1.0f,0.0f,0.2f };
  8334. static float col2[4] = { 0.4f,0.7f,0.0f,0.5f };
  8335. ImGui::ColorEdit3("color 1", col1);
  8336. ImGui::ColorEdit4("color 2", col2);
  8337. const char* listbox_items[] = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon" };
  8338. static int listbox_item_current = 1;
  8339. ImGui::ListBox("listbox\n(single select)", &listbox_item_current, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
  8340. //static int listbox_item_current2 = 2;
  8341. //ImGui::PushItemWidth(-1);
  8342. //ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
  8343. //ImGui::PopItemWidth();
  8344. if (ImGui::TreeNode("Multi-component Widgets"))
  8345. {
  8346. ImGui::Unindent();
  8347. static float vec4f[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
  8348. static int vec4i[4] = { 1, 5, 100, 255 };
  8349. ImGui::InputFloat2("input float2", vec4f);
  8350. ImGui::SliderFloat2("slider float2", vec4f, 0.0f, 1.0f);
  8351. ImGui::InputInt2("input int2", vec4i);
  8352. ImGui::SliderInt2("slider int2", vec4i, 0, 255);
  8353. ImGui::InputFloat3("input float3", vec4f);
  8354. ImGui::SliderFloat3("slider float3", vec4f, 0.0f, 1.0f);
  8355. ImGui::InputInt3("input int3", vec4i);
  8356. ImGui::SliderInt3("slider int3", vec4i, 0, 255);
  8357. ImGui::InputFloat4("input float4", vec4f);
  8358. ImGui::SliderFloat4("slider float4", vec4f, 0.0f, 1.0f);
  8359. ImGui::InputInt4("input int4", vec4i);
  8360. ImGui::SliderInt4("slider int4", vec4i, 0, 255);
  8361. ImGui::Indent();
  8362. ImGui::TreePop();
  8363. }
  8364. if (ImGui::TreeNode("Vertical Sliders"))
  8365. {
  8366. ImGui::Unindent();
  8367. const float spacing = 4;
  8368. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(spacing, spacing));
  8369. static int int_value = 0;
  8370. ImGui::VSliderInt("##int", ImVec2(18,160), &int_value, 0, 5);
  8371. ImGui::SameLine();
  8372. static float values[7] = { 0.0f, 0.60f, 0.35f, 0.9f, 0.70f, 0.20f, 0.0f };
  8373. ImGui::PushID("set1");
  8374. for (int i = 0; i < 7; i++)
  8375. {
  8376. if (i > 0) ImGui::SameLine();
  8377. ImGui::PushID(i);
  8378. ImGui::PushStyleColor(ImGuiCol_FrameBg, ImColor::HSV(i/7.0f, 0.5f, 0.5f));
  8379. ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImColor::HSV(i/7.0f, 0.9f, 0.9f));
  8380. ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, ImColor::HSV(i/7.0f, 1.0f, 1.0f));
  8381. ImGui::VSliderFloat("##v", ImVec2(18,160), &values[i], 0.0f, 1.0f, "");
  8382. if (ImGui::IsItemActive() || ImGui::IsItemHovered())
  8383. ImGui::SetTooltip("%.3f", values[i]);
  8384. ImGui::PopStyleColor(3);
  8385. ImGui::PopID();
  8386. }
  8387. ImGui::PopID();
  8388. ImGui::SameLine();
  8389. ImGui::PushID("set2");
  8390. static float values2[4] = { 0.20f, 0.80f, 0.40f, 0.25f };
  8391. const int rows = 3;
  8392. const ImVec2 small_slider_size(18, (160.0f-(rows-1)*spacing)/rows);
  8393. for (int nx = 0; nx < 4; nx++)
  8394. {
  8395. if (nx > 0) ImGui::SameLine();
  8396. ImGui::BeginGroup();
  8397. for (int ny = 0; ny < rows; ny++)
  8398. {
  8399. ImGui::PushID(nx*rows+ny);
  8400. ImGui::VSliderFloat("##v", small_slider_size, &values2[nx], 0.0f, 1.0f, "");
  8401. if (ImGui::IsItemActive() || ImGui::IsItemHovered())
  8402. ImGui::SetTooltip("%.3f", values2[nx]);
  8403. ImGui::PopID();
  8404. }
  8405. ImGui::EndGroup();
  8406. }
  8407. ImGui::PopID();
  8408. ImGui::SameLine();
  8409. ImGui::PushID("set3");
  8410. for (int i = 0; i < 4; i++)
  8411. {
  8412. if (i > 0) ImGui::SameLine();
  8413. ImGui::PushID(i);
  8414. ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, 40);
  8415. ImGui::VSliderFloat("##v", ImVec2(40,160), &values[i], 0.0f, 1.0f, "%.2f");
  8416. ImGui::PopStyleVar();
  8417. ImGui::PopID();
  8418. }
  8419. ImGui::PopID();
  8420. ImGui::Indent();
  8421. ImGui::TreePop();
  8422. }
  8423. if (ImGui::TreeNode("Dragging"))
  8424. {
  8425. // You can use ImGui::GetItemActiveDragDelta() to query for the dragged amount on any widget.
  8426. static ImVec2 value_raw(0.0f, 0.0f);
  8427. static ImVec2 value_with_lock_threshold(0.0f, 0.0f);
  8428. ImGui::Button("Drag Me");
  8429. if (ImGui::IsItemActive())
  8430. {
  8431. value_raw = ImGui::GetMouseDragDelta(0, 0.0f);
  8432. value_with_lock_threshold = ImGui::GetMouseDragDelta(0);
  8433. //ImGui::SetTooltip("Delta: %.1f, %.1f", value.x, value.y);
  8434. // Draw a line between the button and the mouse cursor
  8435. ImDrawList* draw_list = ImGui::GetWindowDrawList();
  8436. draw_list->PushClipRectFullScreen();
  8437. draw_list->AddLine(ImGui::CalcItemRectClosestPoint(ImGui::GetIO().MousePos, true, -2.0f), ImGui::GetIO().MousePos, ImColor(ImGui::GetStyle().Colors[ImGuiCol_Button]), 4.0f);
  8438. draw_list->PopClipRect();
  8439. }
  8440. ImGui::SameLine(); ImGui::Text("Raw (%.1f, %.1f), WithLockThresold (%.1f, %.1f)", value_raw.x, value_raw.y, value_with_lock_threshold.x, value_with_lock_threshold.y);
  8441. ImGui::TreePop();
  8442. }
  8443. }
  8444. if (ImGui::CollapsingHeader("Graphs widgets"))
  8445. {
  8446. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  8447. ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr));
  8448. static bool pause;
  8449. static ImVector<float> values; if (values.empty()) { values.resize(90); memset(&values.front(), 0, values.size()*sizeof(float)); }
  8450. static size_t values_offset = 0;
  8451. if (!pause)
  8452. {
  8453. // create dummy data at fixed 60 hz rate
  8454. static float refresh_time = -1.0f;
  8455. if (ImGui::GetTime() > refresh_time + 1.0f/60.0f)
  8456. {
  8457. refresh_time = ImGui::GetTime();
  8458. static float phase = 0.0f;
  8459. values[values_offset] = cosf(phase);
  8460. values_offset = (values_offset+1)%values.size();
  8461. phase += 0.10f*values_offset;
  8462. }
  8463. }
  8464. ImGui::PlotLines("##Graph", &values.front(), (int)values.size(), (int)values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80));
  8465. ImGui::SameLine(0, (int)ImGui::GetStyle().ItemInnerSpacing.x);
  8466. ImGui::BeginGroup();
  8467. ImGui::Text("Graph");
  8468. ImGui::Checkbox("pause", &pause);
  8469. ImGui::EndGroup();
  8470. ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,80));
  8471. }
  8472. if (ImGui::CollapsingHeader("Layout"))
  8473. {
  8474. if (ImGui::TreeNode("Widgets Alignment"))
  8475. {
  8476. static float f = 0.0f;
  8477. ImGui::Text("Fixed: 100 pixels");
  8478. ImGui::PushItemWidth(100);
  8479. ImGui::InputFloat("float##1", &f);
  8480. ImGui::PopItemWidth();
  8481. ImGui::Text("Proportional: 50%% of window width");
  8482. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
  8483. ImGui::InputFloat("float##2", &f);
  8484. ImGui::PopItemWidth();
  8485. ImGui::Text("Right-aligned: Leave 100 pixels for label");
  8486. ImGui::PushItemWidth(-100);
  8487. ImGui::InputFloat("float##3", &f);
  8488. ImGui::PopItemWidth();
  8489. ImGui::TreePop();
  8490. }
  8491. if (ImGui::TreeNode("Basic Horizontal Layout"))
  8492. {
  8493. ImGui::TextWrapped("(Use ImGui::SameLine() to keep adding items to the right of the preceeding item)");
  8494. // Text
  8495. ImGui::Text("Two items: Hello");
  8496. ImGui::SameLine();
  8497. ImGui::TextColored(ImVec4(1,1,0,1), "World");
  8498. // Adjust spacing
  8499. ImGui::Text("More spacing: Hello");
  8500. ImGui::SameLine(0, 20);
  8501. ImGui::TextColored(ImVec4(1,1,0,1), "World");
  8502. // Button
  8503. ImGui::AlignFirstTextHeightToWidgets();
  8504. ImGui::Text("Normal buttons"); ImGui::SameLine();
  8505. ImGui::Button("Banana"); ImGui::SameLine();
  8506. ImGui::Button("Apple"); ImGui::SameLine();
  8507. ImGui::Button("Corniflower");
  8508. // Button
  8509. ImGui::Text("Small buttons"); ImGui::SameLine();
  8510. ImGui::SmallButton("Like this one"); ImGui::SameLine();
  8511. ImGui::Text("can fit within a text block.");
  8512. // Aligned to arbitrary position. Easy/cheap column.
  8513. ImGui::Text("Aligned");
  8514. ImGui::SameLine(150); ImGui::Text("x=150");
  8515. ImGui::SameLine(300); ImGui::Text("x=300");
  8516. ImGui::Text("Aligned");
  8517. ImGui::SameLine(150); ImGui::SmallButton("x=150");
  8518. ImGui::SameLine(300); ImGui::SmallButton("x=300");
  8519. // Checkbox
  8520. static bool c1=false,c2=false,c3=false,c4=false;
  8521. ImGui::Checkbox("My", &c1); ImGui::SameLine();
  8522. ImGui::Checkbox("Tailor", &c2); ImGui::SameLine();
  8523. ImGui::Checkbox("Is", &c3); ImGui::SameLine();
  8524. ImGui::Checkbox("Rich", &c4);
  8525. // Various
  8526. static float f0=1.0f, f1=2.0f, f2=3.0f;
  8527. ImGui::PushItemWidth(80);
  8528. const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD" };
  8529. static int item = -1;
  8530. ImGui::Combo("Combo", &item, items, IM_ARRAYSIZE(items)); ImGui::SameLine();
  8531. ImGui::SliderFloat("X", &f0, 0.0f,5.0f); ImGui::SameLine();
  8532. ImGui::SliderFloat("Y", &f1, 0.0f,5.0f); ImGui::SameLine();
  8533. ImGui::SliderFloat("Z", &f2, 0.0f,5.0f);
  8534. ImGui::PopItemWidth();
  8535. ImGui::PushItemWidth(80);
  8536. ImGui::Text("Lists:");
  8537. static int selection[4] = { 0, 1, 2, 3 };
  8538. for (int i = 0; i < 4; i++)
  8539. {
  8540. if (i > 0) ImGui::SameLine();
  8541. ImGui::PushID(i);
  8542. ImGui::ListBox("", &selection[i], items, IM_ARRAYSIZE(items));
  8543. ImGui::PopID();
  8544. //if (ImGui::IsItemHovered()) ImGui::SetTooltip("ListBox %d hovered", i);
  8545. }
  8546. ImGui::PopItemWidth();
  8547. ImGui::TreePop();
  8548. }
  8549. if (ImGui::TreeNode("Groups"))
  8550. {
  8551. ImGui::TextWrapped("(Using ImGui::BeginGroup()/EndGroup() to layout items)");
  8552. ImVec2 size;
  8553. ImGui::BeginGroup();
  8554. {
  8555. ImGui::BeginGroup();
  8556. ImGui::Button("AAA");
  8557. ImGui::SameLine();
  8558. ImGui::Button("BBB");
  8559. ImGui::SameLine();
  8560. ImGui::BeginGroup();
  8561. ImGui::Button("CCC");
  8562. ImGui::Button("DDD");
  8563. ImGui::EndGroup();
  8564. if (ImGui::IsItemHovered())
  8565. ImGui::SetTooltip("Group hovered");
  8566. ImGui::SameLine();
  8567. ImGui::Button("EEE");
  8568. ImGui::EndGroup();
  8569. // Capture the group size and create widgets using the same size
  8570. size = ImGui::GetItemRectSize();
  8571. const float values[5] = { 0.5f, 0.20f, 0.80f, 0.60f, 0.25f };
  8572. ImGui::PlotHistogram("##values", values, IM_ARRAYSIZE(values), 0, NULL, 0.0f, 1.0f, size);
  8573. }
  8574. ImGui::Button("ACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y));
  8575. ImGui::SameLine();
  8576. ImGui::Button("REACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y));
  8577. ImGui::EndGroup();
  8578. ImGui::SameLine();
  8579. ImGui::Button("LEVERAGE\nBUZZWORD", size);
  8580. ImGui::SameLine();
  8581. ImGui::ListBoxHeader("List", size);
  8582. ImGui::Selectable("Selected", true);
  8583. ImGui::Selectable("Not Selected", false);
  8584. ImGui::ListBoxFooter();
  8585. ImGui::TreePop();
  8586. }
  8587. if (ImGui::TreeNode("Text Baseline Alignment"))
  8588. {
  8589. ImGui::TextWrapped("(This is testing the vertical alignment that occurs on text to keep it at the same baseline as widgets. Lines only composed of text or \"small\" widgets fit in less vertical spaces than lines with normal widgets)");
  8590. ImGui::Text("One\nTwo\nThree"); ImGui::SameLine();
  8591. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  8592. ImGui::Text("Banana");
  8593. ImGui::Text("Banana"); ImGui::SameLine();
  8594. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  8595. ImGui::Text("One\nTwo\nThree");
  8596. ImGui::Button("HOP"); ImGui::SameLine();
  8597. ImGui::Text("Banana"); ImGui::SameLine();
  8598. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  8599. ImGui::Text("Banana");
  8600. ImGui::Button("HOP"); ImGui::SameLine();
  8601. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  8602. ImGui::Text("Banana");
  8603. ImGui::Button("TEST"); ImGui::SameLine();
  8604. ImGui::Text("TEST"); ImGui::SameLine();
  8605. ImGui::SmallButton("TEST");
  8606. ImGui::AlignFirstTextHeightToWidgets(); // If your line starts with text, call this to align it to upcoming widgets.
  8607. ImGui::Text("Text aligned to Widget"); ImGui::SameLine();
  8608. ImGui::Button("Widget"); ImGui::SameLine();
  8609. ImGui::Text("Widget"); ImGui::SameLine();
  8610. ImGui::SmallButton("Widget");
  8611. ImGui::TreePop();
  8612. }
  8613. }
  8614. if (ImGui::CollapsingHeader("Child regions"))
  8615. {
  8616. ImGui::Text("Without border");
  8617. static int line = 50;
  8618. bool goto_line = ImGui::Button("Goto");
  8619. ImGui::SameLine();
  8620. ImGui::PushItemWidth(100);
  8621. goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue);
  8622. ImGui::PopItemWidth();
  8623. ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowWidth() * 0.5f,300));
  8624. for (int i = 0; i < 100; i++)
  8625. {
  8626. ImGui::Text("%04d: scrollable region", i);
  8627. if (goto_line && line == i)
  8628. ImGui::SetScrollPosHere();
  8629. }
  8630. if (goto_line && line >= 100)
  8631. ImGui::SetScrollPosHere();
  8632. ImGui::EndChild();
  8633. ImGui::SameLine();
  8634. ImGui::PushStyleVar(ImGuiStyleVar_ChildWindowRounding, 5.0f);
  8635. ImGui::BeginChild("Sub2", ImVec2(0,300), true);
  8636. ImGui::Text("With border");
  8637. ImGui::Columns(2);
  8638. for (int i = 0; i < 100; i++)
  8639. {
  8640. if (i == 50)
  8641. ImGui::NextColumn();
  8642. char buf[32];
  8643. ImFormatString(buf, IM_ARRAYSIZE(buf), "%08x", i*5731);
  8644. ImGui::Button(buf);
  8645. }
  8646. ImGui::EndChild();
  8647. ImGui::PopStyleVar();
  8648. }
  8649. if (ImGui::CollapsingHeader("Columns"))
  8650. {
  8651. // Basic columns
  8652. ImGui::Text("Basic:");
  8653. ImGui::Columns(4, "mycolumns");
  8654. ImGui::Separator();
  8655. ImGui::Text("ID"); ImGui::NextColumn();
  8656. ImGui::Text("Name"); ImGui::NextColumn();
  8657. ImGui::Text("Path"); ImGui::NextColumn();
  8658. ImGui::Text("Flags"); ImGui::NextColumn();
  8659. ImGui::Separator();
  8660. const char* names[3] = { "Robert", "Stephanie", "C64" };
  8661. const char* paths[3] = { "/path/robert", "/path/stephanie", "/path/computer" };
  8662. for (int i = 0; i < 3; i++)
  8663. {
  8664. ImGui::Text("%04d", i); ImGui::NextColumn();
  8665. ImGui::Text(names[i]); ImGui::NextColumn();
  8666. ImGui::Text(paths[i]); ImGui::NextColumn();
  8667. ImGui::Text("...."); ImGui::NextColumn();
  8668. }
  8669. ImGui::Columns(1);
  8670. ImGui::Separator();
  8671. ImGui::Spacing();
  8672. // Scrolling columns
  8673. /*
  8674. ImGui::Text("Scrolling:");
  8675. ImGui::BeginChild("##header", ImVec2(0, ImGui::GetTextLineHeightWithSpacing()+ImGui::GetStyle().ItemSpacing.y));
  8676. ImGui::Columns(3);
  8677. ImGui::Text("ID"); ImGui::NextColumn();
  8678. ImGui::Text("Name"); ImGui::NextColumn();
  8679. ImGui::Text("Path"); ImGui::NextColumn();
  8680. ImGui::Columns(1);
  8681. ImGui::Separator();
  8682. ImGui::EndChild();
  8683. ImGui::BeginChild("##scrollingregion", ImVec2(0, 60));
  8684. ImGui::Columns(3);
  8685. for (int i = 0; i < 10; i++)
  8686. {
  8687. ImGui::Text("%04d", i); ImGui::NextColumn();
  8688. ImGui::Text("Foobar"); ImGui::NextColumn();
  8689. ImGui::Text("/path/foobar/%04d/", i); ImGui::NextColumn();
  8690. }
  8691. ImGui::Columns(1);
  8692. ImGui::EndChild();
  8693. ImGui::Separator();
  8694. ImGui::Spacing();
  8695. */
  8696. // Create multiple items in a same cell before switching to next column
  8697. ImGui::Text("Mixed items:");
  8698. ImGui::Columns(3, "mixed");
  8699. ImGui::Separator();
  8700. static int e = 0;
  8701. ImGui::Text("Hello");
  8702. ImGui::Button("Banana");
  8703. ImGui::RadioButton("radio a", &e, 0);
  8704. ImGui::NextColumn();
  8705. ImGui::Text("ImGui");
  8706. ImGui::Button("Apple");
  8707. ImGui::RadioButton("radio b", &e, 1);
  8708. static float foo = 1.0f;
  8709. ImGui::InputFloat("red", &foo, 0.05f, 0, 3);
  8710. ImGui::Text("An extra line here.");
  8711. ImGui::NextColumn();
  8712. ImGui::Text("World!");
  8713. ImGui::Button("Corniflower");
  8714. ImGui::RadioButton("radio c", &e, 2);
  8715. static float bar = 1.0f;
  8716. ImGui::InputFloat("blue", &bar, 0.05f, 0, 3);
  8717. ImGui::NextColumn();
  8718. if (ImGui::CollapsingHeader("Category A")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  8719. if (ImGui::CollapsingHeader("Category B")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  8720. if (ImGui::CollapsingHeader("Category C")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  8721. ImGui::Columns(1);
  8722. ImGui::Separator();
  8723. ImGui::Spacing();
  8724. // Tree items
  8725. ImGui::Text("Tree items:");
  8726. ImGui::Columns(2, "tree items");
  8727. ImGui::Separator();
  8728. if (ImGui::TreeNode("Hello")) { ImGui::BulletText("World"); ImGui::TreePop(); } ImGui::NextColumn();
  8729. if (ImGui::TreeNode("Bonjour")) { ImGui::BulletText("Monde"); ImGui::TreePop(); } ImGui::NextColumn();
  8730. ImGui::Columns(1);
  8731. ImGui::Separator();
  8732. ImGui::Spacing();
  8733. // Word-wrapping
  8734. ImGui::Text("Word-wrapping:");
  8735. ImGui::Columns(2, "word-wrapping");
  8736. ImGui::Separator();
  8737. ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
  8738. ImGui::Text("Hello Left");
  8739. ImGui::NextColumn();
  8740. ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
  8741. ImGui::Text("Hello Right");
  8742. ImGui::Columns(1);
  8743. ImGui::Separator();
  8744. ImGui::Spacing();
  8745. if (ImGui::TreeNode("Inside a tree.."))
  8746. {
  8747. if (ImGui::TreeNode("node 1 (with borders)"))
  8748. {
  8749. ImGui::Columns(4);
  8750. for (int i = 0; i < 8; i++)
  8751. {
  8752. ImGui::Text("%c%c%c", 'a'+i, 'a'+i, 'a'+i);
  8753. ImGui::NextColumn();
  8754. }
  8755. ImGui::Columns(1);
  8756. ImGui::TreePop();
  8757. }
  8758. if (ImGui::TreeNode("node 2 (without borders)"))
  8759. {
  8760. ImGui::Columns(4, NULL, false);
  8761. for (int i = 0; i < 8; i++)
  8762. {
  8763. ImGui::Text("%c%c%c", 'a'+i, 'a'+i, 'a'+i);
  8764. ImGui::NextColumn();
  8765. }
  8766. ImGui::Columns(1);
  8767. ImGui::TreePop();
  8768. }
  8769. ImGui::TreePop();
  8770. }
  8771. }
  8772. if (ImGui::CollapsingHeader("Filtering"))
  8773. {
  8774. static ImGuiTextFilter filter;
  8775. ImGui::Text("Filter usage:\n"
  8776. " \"\" display all lines\n"
  8777. " \"xxx\" display lines containing \"xxx\"\n"
  8778. " \"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n"
  8779. " \"-xxx\" hide lines containing \"xxx\"");
  8780. filter.Draw();
  8781. const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" };
  8782. for (size_t i = 0; i < IM_ARRAYSIZE(lines); i++)
  8783. if (filter.PassFilter(lines[i]))
  8784. ImGui::BulletText("%s", lines[i]);
  8785. }
  8786. if (ImGui::CollapsingHeader("Keyboard, Mouse & Focus"))
  8787. {
  8788. if (ImGui::TreeNode("Tabbing"))
  8789. {
  8790. ImGui::Text("Use TAB/SHIFT+TAB to cycle thru keyboard editable fields.");
  8791. static char buf[32] = "dummy";
  8792. ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
  8793. ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
  8794. ImGui::InputText("3", buf, IM_ARRAYSIZE(buf));
  8795. ImGui::PushAllowKeyboardFocus(false);
  8796. ImGui::InputText("4 (tab skip)", buf, IM_ARRAYSIZE(buf));
  8797. //ImGui::SameLine(); ImGui::Text("(?)"); if (ImGui::IsHovered()) ImGui::SetTooltip("Use ImGui::PushAllowKeyboardFocus(bool)\nto disable tabbing through certain widgets.");
  8798. ImGui::PopAllowKeyboardFocus();
  8799. ImGui::InputText("5", buf, IM_ARRAYSIZE(buf));
  8800. ImGui::TreePop();
  8801. }
  8802. if (ImGui::TreeNode("Focus from code"))
  8803. {
  8804. bool focus_1 = ImGui::Button("Focus on 1"); ImGui::SameLine();
  8805. bool focus_2 = ImGui::Button("Focus on 2"); ImGui::SameLine();
  8806. bool focus_3 = ImGui::Button("Focus on 3");
  8807. int has_focus = 0;
  8808. static char buf[128] = "click on a button to set focus";
  8809. if (focus_1) ImGui::SetKeyboardFocusHere();
  8810. ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
  8811. if (ImGui::IsItemActive()) has_focus = 1;
  8812. if (focus_2) ImGui::SetKeyboardFocusHere();
  8813. ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
  8814. if (ImGui::IsItemActive()) has_focus = 2;
  8815. ImGui::PushAllowKeyboardFocus(false);
  8816. if (focus_3) ImGui::SetKeyboardFocusHere();
  8817. ImGui::InputText("3 (tab skip)", buf, IM_ARRAYSIZE(buf));
  8818. if (ImGui::IsItemActive()) has_focus = 3;
  8819. ImGui::PopAllowKeyboardFocus();
  8820. if (has_focus)
  8821. ImGui::Text("Item with focus: %d", has_focus);
  8822. else
  8823. ImGui::Text("Item with focus: <none>");
  8824. ImGui::TextWrapped("Cursor & selection are preserved when refocusing last used item in code.");
  8825. ImGui::TreePop();
  8826. }
  8827. if (ImGui::TreeNode("Mouse cursors"))
  8828. {
  8829. ImGui::TextWrapped("(Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. You can also set io.MouseDrawCursor to ask ImGui to render the cursor for you in software)");
  8830. ImGui::Checkbox("io.MouseDrawCursor", &ImGui::GetIO().MouseDrawCursor);
  8831. ImGui::Text("Hover to see mouse cursors:");
  8832. for (int i = 0; i < ImGuiMouseCursor_Count_; i++)
  8833. {
  8834. char label[32];
  8835. sprintf(label, "Mouse cursor %d", i);
  8836. ImGui::Bullet(); ImGui::Selectable(label, false);
  8837. if (ImGui::IsItemHovered())
  8838. ImGui::SetMouseCursor(i);
  8839. }
  8840. ImGui::TreePop();
  8841. }
  8842. }
  8843. if (ImGui::CollapsingHeader("App Examples"))
  8844. {
  8845. ImGui::Checkbox("Console", &show_app_console);
  8846. ImGui::Checkbox("Long text display", &show_app_long_text);
  8847. ImGui::Checkbox("Auto-resizing window", &show_app_auto_resize);
  8848. ImGui::Checkbox("Simple overlay", &show_app_fixed_overlay);
  8849. ImGui::Checkbox("Manipulating window title", &show_app_manipulating_window_title);
  8850. ImGui::Checkbox("Custom rendering", &show_app_custom_rendering);
  8851. }
  8852. ImGui::End();
  8853. }
  8854. static void ShowExampleAppAutoResize(bool* opened)
  8855. {
  8856. if (!ImGui::Begin("Example: Auto-Resizing Window", opened, ImGuiWindowFlags_AlwaysAutoResize))
  8857. {
  8858. ImGui::End();
  8859. return;
  8860. }
  8861. static int lines = 10;
  8862. ImGui::TextWrapped("Window will resize every-frame to the size of its content. Note that you don't want to query the window size to output your content because that would create a feedback loop.");
  8863. ImGui::SliderInt("Number of lines", &lines, 1, 20);
  8864. for (int i = 0; i < lines; i++)
  8865. ImGui::Text("%*sThis is line %d", i*4, "", i); // Pad with space to extend size horizontally
  8866. ImGui::End();
  8867. }
  8868. static void ShowExampleAppFixedOverlay(bool* opened)
  8869. {
  8870. ImGui::SetNextWindowPos(ImVec2(10,10));
  8871. if (!ImGui::Begin("Example: Fixed Overlay", opened, ImVec2(0,0), 0.3f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoSavedSettings))
  8872. {
  8873. ImGui::End();
  8874. return;
  8875. }
  8876. ImGui::Text("Simple overlay\non the top-left side of the screen.");
  8877. ImGui::Separator();
  8878. ImGui::Text("Mouse Position: (%.1f,%.1f)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
  8879. ImGui::End();
  8880. }
  8881. static void ShowExampleAppManipulatingWindowTitle(bool* opened)
  8882. {
  8883. (void)opened;
  8884. // By default, Windows are uniquely identified by their title.
  8885. // You can use the "##" and "###" markers to manipulate the display/ID. Read FAQ at the top of this file!
  8886. // Using "##" to display same title but have unique identifier.
  8887. ImGui::SetNextWindowPos(ImVec2(100,100), ImGuiSetCond_FirstUseEver);
  8888. ImGui::Begin("Same title as another window##1");
  8889. ImGui::Text("This is window 1.\nMy title is the same as window 2, but my identifier is unique.");
  8890. ImGui::End();
  8891. ImGui::SetNextWindowPos(ImVec2(100,200), ImGuiSetCond_FirstUseEver);
  8892. ImGui::Begin("Same title as another window##2");
  8893. ImGui::Text("This is window 2.\nMy title is the same as window 1, but my identifier is unique.");
  8894. ImGui::End();
  8895. // Using "###" to display a changing title but keep a static identifier "MyWindow"
  8896. char buf[128];
  8897. ImFormatString(buf, IM_ARRAYSIZE(buf), "Animated title %c %d###MyWindow", "|/-\\"[(int)(ImGui::GetTime()/0.25f)&3], rand());
  8898. ImGui::SetNextWindowPos(ImVec2(100,300), ImGuiSetCond_FirstUseEver);
  8899. ImGui::Begin(buf);
  8900. ImGui::Text("This window has a changing title.");
  8901. ImGui::End();
  8902. }
  8903. static void ShowExampleAppCustomRendering(bool* opened)
  8904. {
  8905. ImGui::SetNextWindowSize(ImVec2(300,350), ImGuiSetCond_FirstUseEver);
  8906. if (!ImGui::Begin("Example: Custom Rendering", opened))
  8907. {
  8908. ImGui::End();
  8909. return;
  8910. }
  8911. // Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of overloaded operators, etc.
  8912. // Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your types and ImVec2/ImVec4.
  8913. // ImGui defines overloaded operators but they are internal to imgui.cpp and not exposed outside (to avoid messing with your types)
  8914. // In this example we aren't using the operators.
  8915. static ImVector<ImVec2> points;
  8916. static bool adding_line = false;
  8917. if (ImGui::Button("Clear")) points.clear();
  8918. if (points.size() >= 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) { points.pop_back(); points.pop_back(); } }
  8919. ImGui::Text("Left-click and drag to add lines");
  8920. ImGui::Text("Right-click to undo");
  8921. ImDrawList* draw_list = ImGui::GetWindowDrawList();
  8922. // Here we are using InvisibleButton() as a convenience to 1) advance the cursor and 2) allows us to use IsItemHovered()
  8923. // However you can draw directly and poll mouse/keyboard by yourself. You can manipulate the cursor using GetCursorPos() and SetCursorPos().
  8924. // If you only use the ImDrawList API, you can notify the owner window of its extends by using SetCursorPos(max).
  8925. ImVec2 canvas_pos = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
  8926. ImVec2 canvas_size = ImVec2(ImMax(50.0f,ImGui::GetWindowContentRegionMax().x-ImGui::GetCursorPos().x), ImMax(50.0f,ImGui::GetWindowContentRegionMax().y-ImGui::GetCursorPos().y)); // Resize canvas what's available
  8927. draw_list->AddRect(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), 0xFFFFFFFF);
  8928. bool adding_preview = false;
  8929. ImGui::InvisibleButton("canvas", canvas_size);
  8930. if (ImGui::IsItemHovered())
  8931. {
  8932. ImVec2 mouse_pos_in_canvas = ImVec2(ImGui::GetIO().MousePos.x - canvas_pos.x, ImGui::GetIO().MousePos.y - canvas_pos.y);
  8933. if (!adding_line && ImGui::GetIO().MouseClicked[0])
  8934. {
  8935. points.push_back(mouse_pos_in_canvas);
  8936. adding_line = true;
  8937. }
  8938. if (adding_line)
  8939. {
  8940. adding_preview = true;
  8941. points.push_back(mouse_pos_in_canvas);
  8942. if (!ImGui::GetIO().MouseDown[0])
  8943. adding_line = adding_preview = false;
  8944. }
  8945. if (ImGui::GetIO().MouseClicked[1] && !points.empty())
  8946. {
  8947. adding_line = false;
  8948. points.pop_back();
  8949. points.pop_back();
  8950. }
  8951. }
  8952. draw_list->PushClipRect(ImVec4(canvas_pos.x, canvas_pos.y, canvas_pos.x+canvas_size.x, canvas_pos.y+canvas_size.y)); // clip lines within the canvas (if we resize it, etc.)
  8953. for (int i = 0; i < (int)points.size() - 1; i += 2)
  8954. draw_list->AddLine(ImVec2(canvas_pos.x + points[i].x, canvas_pos.y + points[i].y), ImVec2(canvas_pos.x + points[i+1].x, canvas_pos.y + points[i+1].y), 0xFF00FFFF);
  8955. draw_list->PopClipRect();
  8956. if (adding_preview)
  8957. points.pop_back();
  8958. ImGui::End();
  8959. }
  8960. struct ExampleAppConsole
  8961. {
  8962. char InputBuf[256];
  8963. ImVector<char*> Items;
  8964. bool ScrollToBottom;
  8965. ImVector<char*> History;
  8966. int HistoryPos; // -1: new line, 0..History.size()-1 browsing history.
  8967. ImVector<const char*> Commands;
  8968. ExampleAppConsole()
  8969. {
  8970. ClearLog();
  8971. HistoryPos = -1;
  8972. Commands.push_back("HELP");
  8973. Commands.push_back("HISTORY");
  8974. Commands.push_back("CLEAR");
  8975. Commands.push_back("CLASSIFY"); // "classify" is here to provide an example of "C"+[tab] completing to "CL" and displaying matches.
  8976. }
  8977. ~ExampleAppConsole()
  8978. {
  8979. ClearLog();
  8980. for (size_t i = 0; i < Items.size(); i++)
  8981. ImGui::MemFree(History[i]);
  8982. }
  8983. void ClearLog()
  8984. {
  8985. for (size_t i = 0; i < Items.size(); i++)
  8986. ImGui::MemFree(Items[i]);
  8987. Items.clear();
  8988. ScrollToBottom = true;
  8989. }
  8990. void AddLog(const char* fmt, ...)
  8991. {
  8992. char buf[1024];
  8993. va_list args;
  8994. va_start(args, fmt);
  8995. ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  8996. va_end(args);
  8997. Items.push_back(ImStrdup(buf));
  8998. ScrollToBottom = true;
  8999. }
  9000. void Run(const char* title, bool* opened)
  9001. {
  9002. ImGui::SetNextWindowSize(ImVec2(520,600), ImGuiSetCond_FirstUseEver);
  9003. if (!ImGui::Begin(title, opened))
  9004. {
  9005. ImGui::End();
  9006. return;
  9007. }
  9008. ImGui::TextWrapped("This example implements a console with basic coloring, completion and history. A more elaborate implementation may want to store entries along with extra data such as timestamp, emitter, etc.");
  9009. ImGui::TextWrapped("Enter 'HELP' for help, press TAB to use text completion.");
  9010. // TODO: display from bottom
  9011. // TODO: clip manually
  9012. if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.size()); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine();
  9013. if (ImGui::SmallButton("Add Dummy Error")) AddLog("[error] something went wrong"); ImGui::SameLine();
  9014. if (ImGui::SmallButton("Clear")) ClearLog();
  9015. //static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); }
  9016. ImGui::Separator();
  9017. ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
  9018. static ImGuiTextFilter filter;
  9019. filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
  9020. //if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover
  9021. ImGui::PopStyleVar();
  9022. ImGui::Separator();
  9023. // Display every line as a separate entry so we can change their color or add custom widgets. If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end());
  9024. // NB- if you have thousands of entries this approach may be too inefficient. You can seek and display only the lines that are visible - CalcListClipping() is a helper to compute this information.
  9025. // If your items are of variable size you may want to implement code similar to what CalcListClipping() does. Or split your data into fixed height items to allow random-seeking into your list.
  9026. ImGui::BeginChild("ScrollingRegion", ImVec2(0,-ImGui::GetTextLineHeightWithSpacing()*2));
  9027. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing
  9028. for (size_t i = 0; i < Items.size(); i++)
  9029. {
  9030. const char* item = Items[i];
  9031. if (!filter.PassFilter(item))
  9032. continue;
  9033. ImVec4 col(1,1,1,1); // A better implement may store a type per-item. For the sample let's just parse the text.
  9034. if (strstr(item, "[error]")) col = ImVec4(1.0f,0.4f,0.4f,1.0f);
  9035. else if (strncmp(item, "# ", 2) == 0) col = ImVec4(1.0f,0.8f,0.6f,1.0f);
  9036. ImGui::PushStyleColor(ImGuiCol_Text, col);
  9037. ImGui::TextUnformatted(item);
  9038. ImGui::PopStyleColor();
  9039. }
  9040. if (ScrollToBottom)
  9041. ImGui::SetScrollPosHere();
  9042. ScrollToBottom = false;
  9043. ImGui::PopStyleVar();
  9044. ImGui::EndChild();
  9045. ImGui::Separator();
  9046. // Command-line
  9047. if (ImGui::InputText("Input", InputBuf, IM_ARRAYSIZE(InputBuf), ImGuiInputTextFlags_EnterReturnsTrue|ImGuiInputTextFlags_CallbackCompletion|ImGuiInputTextFlags_CallbackHistory, &TextEditCallbackStub, (void*)this))
  9048. {
  9049. char* input_end = InputBuf+strlen(InputBuf);
  9050. while (input_end > InputBuf && input_end[-1] == ' ') input_end--; *input_end = 0;
  9051. if (InputBuf[0])
  9052. ExecCommand(InputBuf);
  9053. strcpy(InputBuf, "");
  9054. }
  9055. // Demonstrate keeping auto focus on the input box
  9056. if (ImGui::IsItemHovered() || (ImGui::IsRootWindowOrAnyChildFocused() && !ImGui::IsAnyItemActive() && !ImGui::IsMouseClicked(0)))
  9057. ImGui::SetKeyboardFocusHere(-1); // Auto focus
  9058. ImGui::End();
  9059. }
  9060. void ExecCommand(const char* command_line)
  9061. {
  9062. AddLog("# %s\n", command_line);
  9063. // Insert into history. First find match and delete it so it can be pushed to the back. This isn't trying to be smart or optimal.
  9064. HistoryPos = -1;
  9065. for (int i = (int)History.size()-1; i >= 0; i--)
  9066. if (ImStricmp(History[i], command_line) == 0)
  9067. {
  9068. ImGui::MemFree(History[i]);
  9069. History.erase(History.begin() + i);
  9070. break;
  9071. }
  9072. History.push_back(ImStrdup(command_line));
  9073. // Process command
  9074. if (ImStricmp(command_line, "CLEAR") == 0)
  9075. {
  9076. ClearLog();
  9077. }
  9078. else if (ImStricmp(command_line, "HELP") == 0)
  9079. {
  9080. AddLog("Commands:");
  9081. for (size_t i = 0; i < Commands.size(); i++)
  9082. AddLog("- %s", Commands[i]);
  9083. }
  9084. else if (ImStricmp(command_line, "HISTORY") == 0)
  9085. {
  9086. for (size_t i = History.size() >= 10 ? History.size() - 10 : 0; i < History.size(); i++)
  9087. AddLog("%3d: %s\n", i, History[i]);
  9088. }
  9089. else
  9090. {
  9091. AddLog("Unknown command: '%s'\n", command_line);
  9092. }
  9093. }
  9094. static int TextEditCallbackStub(ImGuiTextEditCallbackData* data)
  9095. {
  9096. ExampleAppConsole* console = (ExampleAppConsole*)data->UserData;
  9097. return console->TextEditCallback(data);
  9098. }
  9099. int TextEditCallback(ImGuiTextEditCallbackData* data)
  9100. {
  9101. //AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
  9102. switch (data->EventFlag)
  9103. {
  9104. case ImGuiInputTextFlags_CallbackCompletion:
  9105. {
  9106. // Example of TEXT COMPLETION
  9107. // Locate beginning of current word
  9108. const char* word_end = data->Buf + data->CursorPos;
  9109. const char* word_start = word_end;
  9110. while (word_start > data->Buf)
  9111. {
  9112. const char c = word_start[-1];
  9113. if (ImCharIsSpace(c) || c == ',' || c == ';')
  9114. break;
  9115. word_start--;
  9116. }
  9117. // Build a list of candidates
  9118. ImVector<const char*> candidates;
  9119. for (size_t i = 0; i < Commands.size(); i++)
  9120. if (ImStrnicmp(Commands[i], word_start, (int)(word_end-word_start)) == 0)
  9121. candidates.push_back(Commands[i]);
  9122. if (candidates.size() == 0)
  9123. {
  9124. // No match
  9125. AddLog("No match for \"%.*s\"!\n", word_end-word_start, word_start);
  9126. }
  9127. else if (candidates.size() == 1)
  9128. {
  9129. // Single match. Delete the beginning of the word and replace it entirely so we've got nice casing
  9130. data->DeleteChars((int)(word_start-data->Buf), (int)(word_end-word_start));
  9131. data->InsertChars(data->CursorPos, candidates[0]);
  9132. data->InsertChars(data->CursorPos, " ");
  9133. }
  9134. else
  9135. {
  9136. // Multiple matches. Complete as much as we can, so inputing "C" will complete to "CL" and display "CLEAR" and "CLASSIFY"
  9137. int match_len = (int)(word_end - word_start);
  9138. for (;;)
  9139. {
  9140. int c = 0;
  9141. bool all_candidates_matches = true;
  9142. for (size_t i = 0; i < candidates.size() && all_candidates_matches; i++)
  9143. if (i == 0)
  9144. c = toupper(candidates[i][match_len]);
  9145. else if (c != toupper(candidates[i][match_len]))
  9146. all_candidates_matches = false;
  9147. if (!all_candidates_matches)
  9148. break;
  9149. match_len++;
  9150. }
  9151. if (match_len > 0)
  9152. {
  9153. data->DeleteChars((int)(word_start - data->Buf), (int)(word_end-word_start));
  9154. data->InsertChars(data->CursorPos, candidates[0], candidates[0] + match_len);
  9155. }
  9156. // List matches
  9157. AddLog("Possible matches:\n");
  9158. for (size_t i = 0; i < candidates.size(); i++)
  9159. AddLog("- %s\n", candidates[i]);
  9160. }
  9161. break;
  9162. }
  9163. case ImGuiInputTextFlags_CallbackHistory:
  9164. {
  9165. // Example of HISTORY
  9166. const int prev_history_pos = HistoryPos;
  9167. if (data->EventKey == ImGuiKey_UpArrow)
  9168. {
  9169. if (HistoryPos == -1)
  9170. HistoryPos = (int)(History.size() - 1);
  9171. else if (HistoryPos > 0)
  9172. HistoryPos--;
  9173. }
  9174. else if (data->EventKey == ImGuiKey_DownArrow)
  9175. {
  9176. if (HistoryPos != -1)
  9177. if (++HistoryPos >= (int)History.size())
  9178. HistoryPos = -1;
  9179. }
  9180. // A better implementation would preserve the data on the current input line along with cursor position.
  9181. if (prev_history_pos != HistoryPos)
  9182. {
  9183. ImFormatString(data->Buf, data->BufSize, "%s", (HistoryPos >= 0) ? History[HistoryPos] : "");
  9184. data->BufDirty = true;
  9185. data->CursorPos = data->SelectionStart = data->SelectionEnd = (int)strlen(data->Buf);
  9186. }
  9187. }
  9188. }
  9189. return 0;
  9190. }
  9191. };
  9192. static void ShowExampleAppConsole(bool* opened)
  9193. {
  9194. static ExampleAppConsole console;
  9195. console.Run("Example: Console", opened);
  9196. }
  9197. static void ShowExampleAppLongText(bool* opened)
  9198. {
  9199. ImGui::SetNextWindowSize(ImVec2(520,600), ImGuiSetCond_FirstUseEver);
  9200. if (!ImGui::Begin("Example: Long text display", opened))
  9201. {
  9202. ImGui::End();
  9203. return;
  9204. }
  9205. static int test_type = 0;
  9206. static ImGuiTextBuffer log;
  9207. static int lines = 0;
  9208. ImGui::Text("Printing unusually long amount of text.");
  9209. ImGui::Combo("Test type", &test_type, "Single call to TextUnformatted()\0Multiple calls to Text(), clipped manually\0Multiple calls to Text(), not clipped");
  9210. ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size());
  9211. if (ImGui::Button("Clear")) { log.clear(); lines = 0; }
  9212. ImGui::SameLine();
  9213. if (ImGui::Button("Add 1000 lines"))
  9214. {
  9215. for (int i = 0; i < 1000; i++)
  9216. log.append("%i The quick brown fox jumps over the lazy dog\n", lines+i);
  9217. lines += 1000;
  9218. }
  9219. ImGui::BeginChild("Log");
  9220. switch (test_type)
  9221. {
  9222. case 0:
  9223. // Single call to TextUnformatted() with a big buffer
  9224. ImGui::TextUnformatted(log.begin(), log.end());
  9225. break;
  9226. case 1:
  9227. // Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the CalcListClipping() helper.
  9228. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0,0));
  9229. int display_start, display_end;
  9230. ImGui::CalcListClipping(lines, ImGui::GetTextLineHeight(), &display_start, &display_end);
  9231. ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (display_start) * ImGui::GetTextLineHeight());
  9232. for (int i = display_start; i < display_end; i++)
  9233. ImGui::Text("%i The quick brown fox jumps over the lazy dog\n", i);
  9234. ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (lines - display_end) * ImGui::GetTextLineHeight());
  9235. ImGui::PopStyleVar();
  9236. break;
  9237. case 2:
  9238. // Multiple calls to Text(), not clipped
  9239. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0,0));
  9240. for (int i = 0; i < lines; i++)
  9241. ImGui::Text("%i The quick brown fox jumps over the lazy dog\n", i);
  9242. ImGui::PopStyleVar();
  9243. break;
  9244. }
  9245. ImGui::EndChild();
  9246. ImGui::End();
  9247. }
  9248. // End of Sample code
  9249. #endif
  9250. //-----------------------------------------------------------------------------
  9251. // FONT DATA
  9252. //-----------------------------------------------------------------------------
  9253. //-----------------------------------------------------------------------------
  9254. // ProggyClean.ttf
  9255. // Copyright (c) 2004, 2005 Tristan Grimmer
  9256. // MIT license (see License.txt in http://www.upperbounds.net/download/ProggyClean.ttf.zip)
  9257. // Download and more information at http://upperbounds.net
  9258. //-----------------------------------------------------------------------------
  9259. // Compressed with stb_compress() then converted to a C array.
  9260. // Decompressor from stb.h (public domain) by Sean Barrett
  9261. // https://github.com/nothings/stb/blob/master/stb.h
  9262. //-----------------------------------------------------------------------------
  9263. static unsigned int stb_decompress_length(unsigned char *input)
  9264. {
  9265. return (input[8] << 24) + (input[9] << 16) + (input[10] << 8) + input[11];
  9266. }
  9267. static unsigned char *stb__barrier, *stb__barrier2, *stb__barrier3, *stb__barrier4;
  9268. static unsigned char *stb__dout;
  9269. static void stb__match(unsigned char *data, unsigned int length)
  9270. {
  9271. // INVERSE of memmove... write each byte before copying the next...
  9272. IM_ASSERT (stb__dout + length <= stb__barrier);
  9273. if (stb__dout + length > stb__barrier) { stb__dout += length; return; }
  9274. if (data < stb__barrier4) { stb__dout = stb__barrier+1; return; }
  9275. while (length--) *stb__dout++ = *data++;
  9276. }
  9277. static void stb__lit(unsigned char *data, unsigned int length)
  9278. {
  9279. IM_ASSERT (stb__dout + length <= stb__barrier);
  9280. if (stb__dout + length > stb__barrier) { stb__dout += length; return; }
  9281. if (data < stb__barrier2) { stb__dout = stb__barrier+1; return; }
  9282. memcpy(stb__dout, data, length);
  9283. stb__dout += length;
  9284. }
  9285. #define stb__in2(x) ((i[x] << 8) + i[(x)+1])
  9286. #define stb__in3(x) ((i[x] << 16) + stb__in2((x)+1))
  9287. #define stb__in4(x) ((i[x] << 24) + stb__in3((x)+1))
  9288. static unsigned char *stb_decompress_token(unsigned char *i)
  9289. {
  9290. if (*i >= 0x20) { // use fewer if's for cases that expand small
  9291. if (*i >= 0x80) stb__match(stb__dout-i[1]-1, i[0] - 0x80 + 1), i += 2;
  9292. else if (*i >= 0x40) stb__match(stb__dout-(stb__in2(0) - 0x4000 + 1), i[2]+1), i += 3;
  9293. else /* *i >= 0x20 */ stb__lit(i+1, i[0] - 0x20 + 1), i += 1 + (i[0] - 0x20 + 1);
  9294. } else { // more ifs for cases that expand large, since overhead is amortized
  9295. if (*i >= 0x18) stb__match(stb__dout-(stb__in3(0) - 0x180000 + 1), i[3]+1), i += 4;
  9296. else if (*i >= 0x10) stb__match(stb__dout-(stb__in3(0) - 0x100000 + 1), stb__in2(3)+1), i += 5;
  9297. else if (*i >= 0x08) stb__lit(i+2, stb__in2(0) - 0x0800 + 1), i += 2 + (stb__in2(0) - 0x0800 + 1);
  9298. else if (*i == 0x07) stb__lit(i+3, stb__in2(1) + 1), i += 3 + (stb__in2(1) + 1);
  9299. else if (*i == 0x06) stb__match(stb__dout-(stb__in3(1)+1), i[4]+1), i += 5;
  9300. else if (*i == 0x04) stb__match(stb__dout-(stb__in3(1)+1), stb__in2(4)+1), i += 6;
  9301. }
  9302. return i;
  9303. }
  9304. static unsigned int stb_adler32(unsigned int adler32, unsigned char *buffer, unsigned int buflen)
  9305. {
  9306. const unsigned long ADLER_MOD = 65521;
  9307. unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16;
  9308. unsigned long blocklen, i;
  9309. blocklen = buflen % 5552;
  9310. while (buflen) {
  9311. for (i=0; i + 7 < blocklen; i += 8) {
  9312. s1 += buffer[0], s2 += s1;
  9313. s1 += buffer[1], s2 += s1;
  9314. s1 += buffer[2], s2 += s1;
  9315. s1 += buffer[3], s2 += s1;
  9316. s1 += buffer[4], s2 += s1;
  9317. s1 += buffer[5], s2 += s1;
  9318. s1 += buffer[6], s2 += s1;
  9319. s1 += buffer[7], s2 += s1;
  9320. buffer += 8;
  9321. }
  9322. for (; i < blocklen; ++i)
  9323. s1 += *buffer++, s2 += s1;
  9324. s1 %= ADLER_MOD, s2 %= ADLER_MOD;
  9325. buflen -= blocklen;
  9326. blocklen = 5552;
  9327. }
  9328. return (unsigned int)(s2 << 16) + (unsigned int)s1;
  9329. }
  9330. static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length)
  9331. {
  9332. unsigned int olen;
  9333. if (stb__in4(0) != 0x57bC0000) return 0;
  9334. if (stb__in4(4) != 0) return 0; // error! stream is > 4GB
  9335. olen = stb_decompress_length(i);
  9336. stb__barrier2 = i;
  9337. stb__barrier3 = i+length;
  9338. stb__barrier = output + olen;
  9339. stb__barrier4 = output;
  9340. i += 16;
  9341. stb__dout = output;
  9342. for (;;) {
  9343. unsigned char *old_i = i;
  9344. i = stb_decompress_token(i);
  9345. if (i == old_i) {
  9346. if (*i == 0x05 && i[1] == 0xfa) {
  9347. IM_ASSERT(stb__dout == output + olen);
  9348. if (stb__dout != output + olen) return 0;
  9349. if (stb_adler32(1, output, olen) != (unsigned int) stb__in4(2))
  9350. return 0;
  9351. return olen;
  9352. } else {
  9353. IM_ASSERT(0); /* NOTREACHED */
  9354. return 0;
  9355. }
  9356. }
  9357. IM_ASSERT(stb__dout <= output + olen);
  9358. if (stb__dout > output + olen)
  9359. return 0;
  9360. }
  9361. }
  9362. static const unsigned int proggy_clean_ttf_compressed_size = 9583;
  9363. static const unsigned int proggy_clean_ttf_compressed_data[9584/4] =
  9364. {
  9365. 0x0000bc57, 0x00000000, 0xf8a00000, 0x00000400, 0x00010037, 0x000c0000, 0x00030080, 0x2f534f40, 0x74eb8832, 0x01000090, 0x2c158248, 0x616d634e,
  9366. 0x23120270, 0x03000075, 0x241382a0, 0x74766352, 0x82178220, 0xfc042102, 0x02380482, 0x66796c67, 0x5689af12, 0x04070000, 0x80920000, 0x64616568,
  9367. 0xd36691d7, 0xcc201b82, 0x36210382, 0x27108268, 0xc3014208, 0x04010000, 0x243b0f82, 0x78746d68, 0x807e008a, 0x98010000, 0x06020000, 0x61636f6c,
  9368. 0xd8b0738c, 0x82050000, 0x0402291e, 0x7078616d, 0xda00ae01, 0x28201f82, 0x202c1082, 0x656d616e, 0x96bb5925, 0x84990000, 0x9e2c1382, 0x74736f70,
  9369. 0xef83aca6, 0x249b0000, 0xd22c3382, 0x70657270, 0x12010269, 0xf4040000, 0x08202f82, 0x012ecb84, 0x553c0000, 0x0f5fd5e9, 0x0300f53c, 0x00830008,
  9370. 0x7767b722, 0x002b3f82, 0xa692bd00, 0xfe0000d7, 0x83800380, 0x21f1826f, 0x00850002, 0x41820120, 0x40fec026, 0x80030000, 0x05821083, 0x07830120,
  9371. 0x0221038a, 0x24118200, 0x90000101, 0x82798200, 0x00022617, 0x00400008, 0x2009820a, 0x82098276, 0x82002006, 0x9001213b, 0x0223c883, 0x828a02bc,
  9372. 0x858f2010, 0xc5012507, 0x00023200, 0x04210083, 0x91058309, 0x6c412b03, 0x40007374, 0xac200000, 0x00830008, 0x01000523, 0x834d8380, 0x80032103,
  9373. 0x012101bf, 0x23b88280, 0x00800000, 0x0b830382, 0x07820120, 0x83800021, 0x88012001, 0x84002009, 0x2005870f, 0x870d8301, 0x2023901b, 0x83199501,
  9374. 0x82002015, 0x84802000, 0x84238267, 0x88002027, 0x8561882d, 0x21058211, 0x13880000, 0x01800022, 0x05850d85, 0x0f828020, 0x03208384, 0x03200582,
  9375. 0x47901b84, 0x1b850020, 0x1f821d82, 0x3f831d88, 0x3f410383, 0x84058405, 0x210982cd, 0x09830000, 0x03207789, 0xf38a1384, 0x01203782, 0x13872384,
  9376. 0x0b88c983, 0x0d898f84, 0x00202982, 0x23900383, 0x87008021, 0x83df8301, 0x86118d03, 0x863f880d, 0x8f35880f, 0x2160820f, 0x04830300, 0x1c220382,
  9377. 0x05820100, 0x4c000022, 0x09831182, 0x04001c24, 0x11823000, 0x0800082e, 0x00000200, 0xff007f00, 0xffffac20, 0x00220982, 0x09848100, 0xdf216682,
  9378. 0x843586d5, 0x06012116, 0x04400684, 0xa58120d7, 0x00b127d8, 0x01b88d01, 0x2d8685ff, 0xc100c621, 0xf4be0801, 0x9e011c01, 0x88021402, 0x1403fc02,
  9379. 0x9c035803, 0x1404de03, 0x50043204, 0xa2046204, 0x66051605, 0x1206bc05, 0xd6067406, 0x7e073807, 0x4e08ec07, 0x96086c08, 0x1009d008, 0x88094a09,
  9380. 0x800a160a, 0x560b040b, 0x2e0cc80b, 0xea0c820c, 0xa40d5e0d, 0x500eea0d, 0x280f960e, 0x1210b00f, 0xe0107410, 0xb6115211, 0x6e120412, 0x4c13c412,
  9381. 0xf613ac13, 0xae145814, 0x4015ea14, 0xa6158015, 0x1216b815, 0xc6167e16, 0x8e173417, 0x5618e017, 0xee18ba18, 0x96193619, 0x481ad419, 0xf01a9c1a,
  9382. 0xc81b5c1b, 0x4c1c041c, 0xea1c961c, 0x921d2a1d, 0x401ed21d, 0xe01e8e1e, 0x761f241f, 0xa61fa61f, 0x01821020, 0x8a202e34, 0xc820b220, 0x74211421,
  9383. 0xee219821, 0x86226222, 0x01820c23, 0x83238021, 0x23983c01, 0x24d823b0, 0x244a2400, 0x24902468, 0x250625ae, 0x25822560, 0x26f825f8, 0x82aa2658,
  9384. 0xd8be0801, 0x9a274027, 0x68280a28, 0x0e29a828, 0xb8292029, 0x362af829, 0x602a602a, 0x2a2b022b, 0xac2b5e2b, 0x202ce62b, 0x9a2c342c, 0x5c2d282d,
  9385. 0xaa2d782d, 0x262ee82d, 0x262fa62e, 0xf42fb62f, 0xc8305e30, 0xb4313e31, 0x9e321e32, 0x82331e33, 0x5c34ee33, 0x3a35ce34, 0xd4358635, 0x72362636,
  9386. 0x7637e636, 0x3a38d837, 0x1239a638, 0xae397439, 0x9a3a2e3a, 0x7c3b063b, 0x3a3ce83b, 0x223d963c, 0xec3d863d, 0xc63e563e, 0x9a3f2a3f, 0x6a401240,
  9387. 0x3641d040, 0x0842a241, 0x7a424042, 0xf042b842, 0xcc436243, 0x8a442a44, 0x5845ee44, 0xe245b645, 0xb4465446, 0x7a471447, 0x5448da47, 0x4049c648,
  9388. 0x15462400, 0x034d0808, 0x0b000700, 0x13000f00, 0x1b001700, 0x23001f00, 0x2b002700, 0x33002f00, 0x3b003700, 0x43003f00, 0x4b004700, 0x53004f00,
  9389. 0x5b005700, 0x63005f00, 0x6b006700, 0x73006f00, 0x7b007700, 0x83007f00, 0x8b008700, 0x00008f00, 0x15333511, 0x20039631, 0x20178205, 0xd3038221,
  9390. 0x20739707, 0x25008580, 0x028080fc, 0x05be8080, 0x04204a85, 0x05ce0685, 0x0107002a, 0x02000080, 0x00000400, 0x250d8b41, 0x33350100, 0x03920715,
  9391. 0x13820320, 0x858d0120, 0x0e8d0320, 0xff260d83, 0x00808000, 0x54820106, 0x04800223, 0x845b8c80, 0x41332059, 0x078b068f, 0x82000121, 0x82fe2039,
  9392. 0x84802003, 0x83042004, 0x23598a0e, 0x00180000, 0x03210082, 0x42ab9080, 0x73942137, 0x2013bb41, 0x8f978205, 0x2027a39b, 0x20b68801, 0x84b286fd,
  9393. 0x91c88407, 0x41032011, 0x11a51130, 0x15000027, 0x80ff8000, 0x11af4103, 0x841b0341, 0x8bd983fd, 0x9be99bc9, 0x8343831b, 0x21f1821f, 0xb58300ff,
  9394. 0x0f84e889, 0xf78a0484, 0x8000ff22, 0x0020eeb3, 0x14200082, 0x2130ef41, 0xeb431300, 0x4133200a, 0xd7410ecb, 0x9a07200b, 0x2027871b, 0x21238221,
  9395. 0xe7828080, 0xe784fd20, 0xe8848020, 0xfe808022, 0x08880d85, 0xba41fd20, 0x82248205, 0x85eab02a, 0x008022e7, 0x2cd74200, 0x44010021, 0xd34406eb,
  9396. 0x44312013, 0xcf8b0eef, 0x0d422f8b, 0x82332007, 0x0001212f, 0x8023cf82, 0x83000180, 0x820583de, 0x830682d4, 0x820020d4, 0x82dc850a, 0x20e282e9,
  9397. 0xb2ff85fe, 0x010327e9, 0x02000380, 0x0f440400, 0x0c634407, 0x68825982, 0x85048021, 0x260a825d, 0x010b0000, 0x4400ff00, 0x2746103f, 0x08d74209,
  9398. 0x4d440720, 0x0eaf4406, 0xc3441d20, 0x23078406, 0xff800002, 0x04845b83, 0x8d05b241, 0x1781436f, 0x6b8c87a5, 0x1521878e, 0x06474505, 0x01210783,
  9399. 0x84688c00, 0x8904828e, 0x441e8cf7, 0x0b270cff, 0x80008000, 0x45030003, 0xfb430fab, 0x080f4107, 0x410bf942, 0xd34307e5, 0x070d4207, 0x80800123,
  9400. 0x205d85fe, 0x849183fe, 0x20128404, 0x82809702, 0x00002217, 0x41839a09, 0x6b4408cf, 0x0733440f, 0x3b460720, 0x82798707, 0x97802052, 0x0000296f,
  9401. 0xff800004, 0x01800100, 0x0021ef89, 0x0a914625, 0x410a4d41, 0x00250ed4, 0x00050000, 0x056d4280, 0x210a7b46, 0x21481300, 0x46ed8512, 0x00210bd1,
  9402. 0x89718202, 0x21738877, 0x2b850001, 0x00220582, 0x87450a00, 0x0ddb4606, 0x41079b42, 0x9d420c09, 0x0b09420b, 0x8d820720, 0x9742fc84, 0x42098909,
  9403. 0x00241e0f, 0x00800014, 0x0b47da82, 0x0833442a, 0x49078d41, 0x2f450f13, 0x42278f17, 0x01200751, 0x22063742, 0x44808001, 0x20450519, 0x88068906,
  9404. 0x83fe2019, 0x4203202a, 0x1a941a58, 0x00820020, 0xe7a40e20, 0x420ce146, 0x854307e9, 0x0fcb4713, 0xff20a182, 0xfe209b82, 0x0c867f8b, 0x0021aea4,
  9405. 0x219fa40f, 0x7d41003b, 0x07194214, 0xbf440520, 0x071d4206, 0x6941a590, 0x80802309, 0x028900ff, 0xa9a4b685, 0xc5808021, 0x449b82ab, 0x152007eb,
  9406. 0x42134d46, 0x61440a15, 0x051e4208, 0x222b0442, 0x47001100, 0xfd412913, 0x17194714, 0x410f5b41, 0x02220773, 0x09428080, 0x21a98208, 0xd4420001,
  9407. 0x481c840d, 0x00232bc9, 0x42120000, 0xe74c261b, 0x149d4405, 0x07209d87, 0x410db944, 0x14421c81, 0x42fd2005, 0x80410bd2, 0x203d8531, 0x06874100,
  9408. 0x48256f4a, 0xcb420c95, 0x13934113, 0x44075d44, 0x044c0855, 0x00ff2105, 0xfe228185, 0x45448000, 0x22c5b508, 0x410c0000, 0x7b412087, 0x1bb74514,
  9409. 0x32429c85, 0x0a574805, 0x21208943, 0x8ba01300, 0x440dfb4e, 0x77431437, 0x245b4113, 0x200fb145, 0x41108ffe, 0x80203562, 0x00200082, 0x46362b42,
  9410. 0x1742178d, 0x4527830f, 0x0f830b2f, 0x4a138146, 0x802409a1, 0xfe8000ff, 0x94419982, 0x09294320, 0x04000022, 0x49050f4f, 0xcb470a63, 0x48032008,
  9411. 0x2b48067b, 0x85022008, 0x82638338, 0x00002209, 0x05af4806, 0x900e9f49, 0x84c5873f, 0x214285bd, 0x064900ff, 0x0c894607, 0x00000023, 0x4903820a,
  9412. 0x714319f3, 0x0749410c, 0x8a07a145, 0x02152507, 0xfe808000, 0x74490386, 0x8080211b, 0x0c276f82, 0x00018000, 0x48028003, 0x2b2315db, 0x43002f00,
  9413. 0x6f82142f, 0x44011521, 0x93510da7, 0x20e68508, 0x06494d80, 0x8e838020, 0x06821286, 0x124bff20, 0x25f3830c, 0x03800080, 0xe74a0380, 0x207b8715,
  9414. 0x876b861d, 0x4a152007, 0x07870775, 0xf6876086, 0x8417674a, 0x0a0021f2, 0x431c9743, 0x8d421485, 0x200b830b, 0x06474d03, 0x71828020, 0x04510120,
  9415. 0x42da8606, 0x1f831882, 0x001a0022, 0xff4d0082, 0x0b0f532c, 0x0d449b94, 0x4e312007, 0x074f12e7, 0x0bf3490b, 0xbb412120, 0x413f820a, 0xef490857,
  9416. 0x80002313, 0xe2830001, 0x6441fc20, 0x8b802006, 0x00012108, 0xfd201582, 0x492c9b48, 0x802014ff, 0x51084347, 0x0f4327f3, 0x17bf4a14, 0x201b7944,
  9417. 0x06964201, 0x134ffe20, 0x20d6830b, 0x25d78280, 0xfd800002, 0x05888000, 0x9318dc41, 0x21d282d4, 0xdb481800, 0x0dff542a, 0x45107743, 0xe14813f5,
  9418. 0x0f034113, 0x83135d45, 0x47b28437, 0xe4510e73, 0x21f58e06, 0x2b8400fd, 0x1041fcac, 0x08db4b0b, 0x421fdb41, 0xdf4b18df, 0x011d210a, 0x420af350,
  9419. 0x6e8308af, 0xac85cb86, 0x1e461082, 0x82b7a407, 0x411420a3, 0xa34130ab, 0x178f4124, 0x41139741, 0x86410d93, 0x82118511, 0x057243d8, 0x8941d9a4,
  9420. 0x3093480c, 0x4a13474f, 0xfb5016a9, 0x07ad4108, 0x4a0f9d42, 0xfe200fad, 0x4708aa41, 0x83482dba, 0x288f4d06, 0xb398c3bb, 0x44267b41, 0xb34439d7,
  9421. 0x0755410f, 0x200ebb45, 0x0f5f4215, 0x20191343, 0x06df5301, 0xf04c0220, 0x2ba64d07, 0x82050841, 0x430020ce, 0xa78f3627, 0x5213ff42, 0x2f970bc1,
  9422. 0x4305ab55, 0xa084111b, 0x450bac45, 0x5f4238b8, 0x010c2106, 0x0220ed82, 0x441bb344, 0x875010af, 0x0737480f, 0x490c5747, 0x0c840c03, 0x4c204b42,
  9423. 0x8ba905d7, 0x8b948793, 0x510c0c51, 0xfb4b24b9, 0x1b174107, 0x5709d74c, 0xd1410ca5, 0x079d480f, 0x201ff541, 0x06804780, 0x7d520120, 0x80002205,
  9424. 0x20a983fe, 0x47bb83fe, 0x1b8409b4, 0x81580220, 0x4e00202c, 0x4f41282f, 0x0eab4f17, 0x57471520, 0x0e0f4808, 0x8221e041, 0x3e1b4a8b, 0x4407175d,
  9425. 0x1b4b071f, 0x4a0f8b07, 0x174a0703, 0x0ba5411b, 0x430fb141, 0x0120057b, 0xfc20dd82, 0x4a056047, 0xf4850c0c, 0x01221982, 0x02828000, 0x1a5d088b,
  9426. 0x20094108, 0x8c0e3941, 0x4900200e, 0x7744434f, 0x200b870b, 0x0e4b5a33, 0x2b41f78b, 0x8b138307, 0x0b9f450b, 0x2406f741, 0xfd808001, 0x09475a00,
  9427. 0x84000121, 0x5980200e, 0x85450e5d, 0x832c8206, 0x4106831e, 0x00213814, 0x28b34810, 0x410c2f4b, 0x5f4a13d7, 0x0b2b4113, 0x6e43a883, 0x11174b05,
  9428. 0x4b066a45, 0xcc470541, 0x5000202b, 0xcb472f4b, 0x44b59f0f, 0xc5430b5b, 0x0d654907, 0x21065544, 0xd6828080, 0xfe201982, 0x8230ec4a, 0x120025c2,
  9429. 0x80ff8000, 0x4128d74d, 0x3320408b, 0x410a9f50, 0xdb822793, 0x822bd454, 0x61134b2e, 0x410b214a, 0xad4117c9, 0x0001211f, 0x4206854f, 0x4b430596,
  9430. 0x06bb5530, 0x2025cf46, 0x0ddd5747, 0x500ea349, 0x0f840fa7, 0x5213c153, 0x634e08d1, 0x0bbe4809, 0x59316e4d, 0x5b50053f, 0x203f6323, 0x5117eb46,
  9431. 0x94450a63, 0x246e410a, 0x63410020, 0x0bdb5f2f, 0x4233ab44, 0x39480757, 0x112d4a07, 0x7241118f, 0x000e2132, 0x9f286f41, 0x0f8762c3, 0x33350723,
  9432. 0x094e6415, 0x2010925f, 0x067252fe, 0xd0438020, 0x63a68225, 0x11203a4f, 0x480e6360, 0x5748131f, 0x079b521f, 0x200e2f43, 0x864b8315, 0x113348e7,
  9433. 0x85084e48, 0x06855008, 0x5880fd21, 0x7c420925, 0x0c414824, 0x37470c86, 0x1b8b422b, 0x5b0a8755, 0x23410c21, 0x0b83420b, 0x5a082047, 0xf482067f,
  9434. 0xa80b4c47, 0x0c0021cf, 0x20207b42, 0x0fb74100, 0x420b8744, 0xeb43076f, 0x0f6f420b, 0x4261fe20, 0x439aa00c, 0x215034e3, 0x0ff9570f, 0x4b1f2d5d,
  9435. 0x2d5d0c6f, 0x09634d0b, 0x1f51b8a0, 0x620f200c, 0xaf681e87, 0x24f94d07, 0x4e0f4945, 0xfe200c05, 0x22139742, 0x57048080, 0x23950c20, 0x97601585,
  9436. 0x4813201f, 0xad620523, 0x200f8f0f, 0x9e638f15, 0x00002181, 0x41342341, 0x0f930f0b, 0x210b4b62, 0x978f0001, 0xfe200f84, 0x8425c863, 0x2704822b,
  9437. 0x80000a00, 0x00038001, 0x610e9768, 0x834514bb, 0x0bc3430f, 0x2107e357, 0x80848080, 0x4400fe21, 0x2e410983, 0x00002a1a, 0x00000700, 0x800380ff,
  9438. 0x0fdf5800, 0x59150021, 0xd142163d, 0x0c02410c, 0x01020025, 0x65800300, 0x00240853, 0x1d333501, 0x15220382, 0x35420001, 0x44002008, 0x376406d7,
  9439. 0x096f6b19, 0x480bc142, 0x8f4908a7, 0x211f8b1f, 0x9e830001, 0x0584fe20, 0x4180fd21, 0x11850910, 0x8d198259, 0x000021d4, 0x5a08275d, 0x275d1983,
  9440. 0x06d9420e, 0x9f08b36a, 0x0f7d47b5, 0x8d8a2f8b, 0x4c0e0b57, 0xe7410e17, 0x42d18c1a, 0xb351087a, 0x1ac36505, 0x4b4a2f20, 0x0b9f450d, 0x430beb53,
  9441. 0xa7881015, 0xa5826a83, 0x80200f82, 0x86185a65, 0x4100208e, 0x176c3367, 0x0fe7650b, 0x4a17ad4b, 0x0f4217ed, 0x112e4206, 0x41113a42, 0xf7423169,
  9442. 0x0cb34737, 0x560f8b46, 0xa75407e5, 0x5f01200f, 0x31590c48, 0x80802106, 0x42268841, 0x0020091e, 0x4207ef64, 0x69461df7, 0x138d4114, 0x820f5145,
  9443. 0x53802090, 0xff200529, 0xb944b183, 0x417e8505, 0x00202561, 0x15210082, 0x42378200, 0x9b431cc3, 0x004f220d, 0x0dd54253, 0x4213f149, 0x7d41133b,
  9444. 0x42c9870b, 0x802010f9, 0x420b2c42, 0x8f441138, 0x267c4408, 0x600cb743, 0x8f4109d3, 0x05ab701d, 0x83440020, 0x3521223f, 0x0b794733, 0xfb62fe20,
  9445. 0x4afd2010, 0xaf410ae7, 0x25ce8525, 0x01080000, 0x7b6b0000, 0x0973710b, 0x82010021, 0x49038375, 0x33420767, 0x052c4212, 0x58464b85, 0x41fe2005,
  9446. 0x50440c27, 0x000c2209, 0x1cb36b80, 0x9b06df44, 0x0f93566f, 0x52830220, 0xfe216e8d, 0x200f8200, 0x0fb86704, 0xb057238d, 0x050b5305, 0x7217eb47,
  9447. 0xbd410b6b, 0x0f214610, 0x871f9956, 0x1e91567e, 0x2029b741, 0x20008200, 0x18b7410a, 0x27002322, 0x41095543, 0x0f8f0fb3, 0x41000121, 0x889d111c,
  9448. 0x14207b82, 0x00200382, 0x73188761, 0x475013a7, 0x6e33200c, 0x234e0ea3, 0x9b138313, 0x08e54d17, 0x9711094e, 0x2ee74311, 0x4908875e, 0xd75d1f1f,
  9449. 0x19ab5238, 0xa2084d48, 0x63a7a9b3, 0x55450b83, 0x0fd74213, 0x440d814c, 0x4f481673, 0x05714323, 0x13000022, 0x412e1f46, 0xdf493459, 0x21c7550f,
  9450. 0x8408215f, 0x201d49cb, 0xb1103043, 0x0f0d65d7, 0x452b8d41, 0x594b0f8d, 0x0b004605, 0xb215eb46, 0x000a24d7, 0x47000080, 0x002118cf, 0x06436413,
  9451. 0x420bd750, 0x2b500743, 0x076a470c, 0x4105c050, 0xd942053f, 0x0d00211a, 0x5f44779c, 0x0ce94805, 0x51558186, 0x14a54c0b, 0x49082b41, 0x0a4b0888,
  9452. 0x8080261f, 0x0d000000, 0x20048201, 0x1deb6a03, 0x420cb372, 0x07201783, 0x4306854d, 0x8b830c59, 0x59093c74, 0x0020250f, 0x67070f4a, 0x2341160b,
  9453. 0x00372105, 0x431c515d, 0x554e17ef, 0x0e5d6b05, 0x41115442, 0xb74a1ac1, 0x2243420a, 0x5b4f878f, 0x7507200f, 0x384b086f, 0x09d45409, 0x0020869a,
  9454. 0x12200082, 0xab460382, 0x10075329, 0x54138346, 0xaf540fbf, 0x1ea75413, 0x9a0c9e54, 0x0f6b44c1, 0x41000021, 0x47412a4f, 0x07374907, 0x5310bf76,
  9455. 0xff2009b4, 0x9a09a64c, 0x8200208d, 0x34c34500, 0x970fe141, 0x1fd74b0f, 0x440a3850, 0x206411f0, 0x27934609, 0x470c5d41, 0x555c2947, 0x1787540f,
  9456. 0x6e0f234e, 0x7d540a1b, 0x1d736b08, 0x0026a088, 0x80000e00, 0x9b5200ff, 0x08ef4318, 0x450bff77, 0x1d4d0b83, 0x081f7006, 0xcb691b86, 0x4b022008,
  9457. 0xc34b0b33, 0x1d0d4a0c, 0x8025a188, 0x0b000000, 0x52a38201, 0xbf7d0873, 0x0c234511, 0x8f0f894a, 0x4101200f, 0x0c880c9d, 0x2b418ea1, 0x06c74128,
  9458. 0x66181341, 0x7b4c0bb9, 0x0c06630b, 0xfe200c87, 0x9ba10882, 0x27091765, 0x01000008, 0x02800380, 0x48113f4e, 0x29430cf5, 0x09a75a0b, 0x31618020,
  9459. 0x6d802009, 0x61840e33, 0x8208bf51, 0x0c637d61, 0x7f092379, 0x4f470f4b, 0x1797510c, 0x46076157, 0xf5500fdf, 0x0f616910, 0x1171fe20, 0x82802006,
  9460. 0x08696908, 0x41127a4c, 0x3f4a15f3, 0x01042607, 0x0200ff00, 0x1cf77700, 0xff204185, 0x00235b8d, 0x43100000, 0x3b22243f, 0x3b4d3f00, 0x0b937709,
  9461. 0xad42f18f, 0x0b1f420f, 0x51084b43, 0x8020104a, 0xb557ff83, 0x052b7f2a, 0x0280ff22, 0x250beb78, 0x00170013, 0xbf6d2500, 0x07db760e, 0x410e2b7f,
  9462. 0x00230e4f, 0x49030000, 0x0582055b, 0x07000326, 0x00000b00, 0x580bcd46, 0x00200cdd, 0x57078749, 0x8749160f, 0x0f994f0a, 0x41134761, 0x01200b31,
  9463. 0xeb796883, 0x0b41500b, 0x0e90b38e, 0x202e7b51, 0x05d95801, 0x41080570, 0x1d530fc9, 0x0b937a0f, 0xaf8eb387, 0xf743b98f, 0x07c74227, 0x80000523,
  9464. 0x0fcb4503, 0x430ca37b, 0x7782077f, 0x8d0a9947, 0x08af4666, 0xeb798020, 0x6459881e, 0xc3740bbf, 0x0feb6f0b, 0x20072748, 0x052b6102, 0x435e0584,
  9465. 0x7d088308, 0x03200afd, 0x92109e41, 0x28aa8210, 0x80001500, 0x80030000, 0x0fdb5805, 0x209f4018, 0xa7418d87, 0x0aa3440f, 0x20314961, 0x073a52ff,
  9466. 0x6108505d, 0x43181051, 0x00223457, 0xe7820500, 0x50028021, 0x81410d33, 0x063d7108, 0xdb41af84, 0x4d888205, 0x00201198, 0x463d835f, 0x152106d7,
  9467. 0x0a355a33, 0x6917614e, 0x75411f4d, 0x184b8b07, 0x1809c344, 0x21091640, 0x0b828000, 0x42808021, 0x26790519, 0x86058605, 0x2428422d, 0x22123b42,
  9468. 0x42000080, 0xf587513b, 0x7813677b, 0xaf4d139f, 0x00ff210c, 0x5e0a1d57, 0x3b421546, 0x01032736, 0x02000380, 0x41180480, 0x2f420f07, 0x0c624807,
  9469. 0x00000025, 0x18000103, 0x83153741, 0x430120c3, 0x042106b2, 0x088d4d00, 0x2f830620, 0x1810434a, 0x18140345, 0x8507fb41, 0x5ee582ea, 0x0023116c,
  9470. 0x8d000600, 0x053b56af, 0xa6554fa2, 0x0d704608, 0x40180d20, 0x47181a43, 0xd37b07ff, 0x0b79500c, 0x420fd745, 0x47450bd9, 0x8471830a, 0x095a777e,
  9471. 0x84137542, 0x82002013, 0x2f401800, 0x0007213b, 0x4405e349, 0x0d550ff3, 0x16254c0c, 0x820ffe4a, 0x0400218a, 0x89066f41, 0x106b414f, 0xc84d0120,
  9472. 0x80802206, 0x0c9a4b03, 0x00100025, 0x68000200, 0x9d8c2473, 0x44134344, 0xf36a0f33, 0x4678860f, 0x1b440a25, 0x41988c0a, 0x80201879, 0x43079b5e,
  9473. 0x4a18080b, 0x0341190b, 0x1259530c, 0x43251552, 0x908205c8, 0x0cac4018, 0x86000421, 0x0e504aa2, 0x0020b891, 0xfb450082, 0x51132014, 0x8f5205f3,
  9474. 0x35052108, 0x8505cb59, 0x0f6d4f70, 0x82150021, 0x29af5047, 0x4f004b24, 0x75795300, 0x1b595709, 0x460b6742, 0xbf4b0f0d, 0x5743870b, 0xcb6d1461,
  9475. 0x08f64505, 0x4e05ab6c, 0x334126c3, 0x0bcb6b0d, 0x1811034d, 0x4111ef4b, 0x814f1ce5, 0x20af8227, 0x07fd7b80, 0x41188e84, 0xef410f33, 0x80802429,
  9476. 0x410d0000, 0xa34205ab, 0x76b7881c, 0xff500b89, 0x0741430f, 0x20086f4a, 0x209d8200, 0x234c18fd, 0x05d4670a, 0x4509af51, 0x9642078d, 0x189e831d,
  9477. 0x7c1cc74b, 0xcd4c07b9, 0x0e7c440f, 0x8b7b0320, 0x21108210, 0xc76c8080, 0x03002106, 0x6b23bf41, 0xc549060b, 0x7946180b, 0x0ff7530f, 0x17ad4618,
  9478. 0x200ecd45, 0x208c83fd, 0x5e0488fe, 0x032009c6, 0x420d044e, 0x0d8f0d7f, 0x00820020, 0x18001021, 0x6d273b45, 0xfd4c0c93, 0xcf451813, 0x0fe5450f,
  9479. 0x5a47c382, 0x820a8b0a, 0x282b4998, 0x410a8b5b, 0x4b232583, 0x54004f00, 0x978f0ce3, 0x500f1944, 0xa95f1709, 0x0280220b, 0x05ba7080, 0xa1530682,
  9480. 0x06324c13, 0x91412582, 0x05536e2c, 0x63431020, 0x0f434706, 0x8c11374c, 0x176143d7, 0x4d0f454c, 0xd3680bed, 0x0bee4d17, 0x212b9a41, 0x0f530a00,
  9481. 0x140d531c, 0x43139143, 0x95610e8d, 0x0f094415, 0x4205fb56, 0x1b4205cf, 0x17015225, 0x5e0c477f, 0xaf6e0aeb, 0x0ff36218, 0x04849a84, 0x0a454218,
  9482. 0x9c430420, 0x23c6822b, 0x04000102, 0x45091b4b, 0xf05f0955, 0x82802007, 0x421c2023, 0x5218282b, 0x7b53173f, 0x0fe7480c, 0x74173b7f, 0x47751317,
  9483. 0x634d1807, 0x0f6f430f, 0x24086547, 0xfc808002, 0x0b3c7f80, 0x10840120, 0x188d1282, 0x20096b43, 0x0fc24403, 0x00260faf, 0x0180000b, 0x3f500280,
  9484. 0x18002019, 0x450b4941, 0xf3530fb9, 0x18002010, 0x8208a551, 0x06234d56, 0xcb58a39b, 0xc3421805, 0x1313461e, 0x0f855018, 0xd34b0120, 0x6cfe2008,
  9485. 0x574f0885, 0x09204114, 0x07000029, 0x00008000, 0x44028002, 0x01420f57, 0x10c95c10, 0x11184c18, 0x80221185, 0x7f421e00, 0x00732240, 0x09cd4977,
  9486. 0x6d0b2b42, 0x4f180f8f, 0x8f5a0bcb, 0x9b0f830f, 0x0fb9411f, 0x230b5756, 0x00fd8080, 0x82060745, 0x000121d5, 0x8e0fb277, 0x4a8d4211, 0x24061c53,
  9487. 0x04000007, 0x12275280, 0x430c954c, 0x80201545, 0x200f764f, 0x20008200, 0x20ce8308, 0x09534f02, 0x660edf64, 0x73731771, 0xe7411807, 0x20a2820c,
  9488. 0x13b64404, 0x8f5d6682, 0x1d6b4508, 0x0cff4d18, 0x3348c58f, 0x0fc34c07, 0x31558b84, 0x8398820f, 0x17514712, 0x240b0e46, 0x80000a00, 0x093b4502,
  9489. 0x420f9759, 0xa54c0bf1, 0x0f2b470c, 0x410d314b, 0x2584170c, 0x73b30020, 0xb55fe782, 0x204d8410, 0x08e043fe, 0x4f147e41, 0x022008ab, 0x4b055159,
  9490. 0x2950068f, 0x00022208, 0x48511880, 0x82002009, 0x00112300, 0x634dff00, 0x24415f27, 0x180f6d43, 0x4d0b5d45, 0x4d5f05ef, 0x01802317, 0x56188000,
  9491. 0xa7840807, 0xc6450220, 0x21ca8229, 0x4b781a00, 0x3359182c, 0x0cf3470f, 0x180bef46, 0x420b0354, 0xff470b07, 0x4515200a, 0x9758239b, 0x4a80200c,
  9492. 0xd2410a26, 0x05fb4a08, 0x4b05e241, 0x03200dc9, 0x92290941, 0x00002829, 0x00010900, 0x5b020001, 0x23201363, 0x460d776a, 0xef530fdb, 0x209a890c,
  9493. 0x13fc4302, 0x00008024, 0xc4820104, 0x08820220, 0x20086b5b, 0x18518700, 0x8408d349, 0x0da449a1, 0x00080024, 0x7b690280, 0x4c438b1a, 0x01220f63,
  9494. 0x4c878000, 0x5c149c53, 0xfb430868, 0x2f56181e, 0x0ccf7b1b, 0x0f075618, 0x2008e347, 0x14144104, 0x00207f83, 0x00207b82, 0x201adf47, 0x16c35a13,
  9495. 0x540fdf47, 0x802006c8, 0x5418f185, 0x29430995, 0x00002419, 0x58001600, 0x5720316f, 0x4d051542, 0x4b7b1b03, 0x138f4707, 0xb747b787, 0x4aab8213,
  9496. 0x058305fc, 0x20115759, 0x82128401, 0x0a0b44e8, 0x46800121, 0xe64210d0, 0x82129312, 0x4bffdffe, 0x3b41171b, 0x9b27870f, 0x808022ff, 0x085c68fe,
  9497. 0x41800021, 0x01410b20, 0x001a213a, 0x47480082, 0x11374e12, 0x56130b4c, 0xdf4b0c65, 0x0b0f590b, 0x0f574c18, 0x830feb4b, 0x075f480f, 0x480b4755,
  9498. 0x40490b73, 0x80012206, 0x09d74280, 0x80fe8022, 0x80210e86, 0x056643ff, 0x10820020, 0x420b2646, 0x0b58391a, 0xd74c1808, 0x078b4e22, 0x2007f55f,
  9499. 0x4b491807, 0x83802017, 0x65aa82a7, 0x3152099e, 0x068b7616, 0x9b431220, 0x09bb742c, 0x500e376c, 0x8342179b, 0x0a4d5d0f, 0x8020a883, 0x180cd349,
  9500. 0x2016bb4b, 0x14476004, 0x84136c43, 0x08cf7813, 0x4f4c0520, 0x156f420f, 0x20085f42, 0x6fd3be03, 0xd4d30803, 0xa7411420, 0x004b222c, 0x0d3b614f,
  9501. 0x3f702120, 0x1393410a, 0x8f132745, 0x47421827, 0x41e08209, 0xb05e2bb9, 0x18b7410c, 0x18082647, 0x4107a748, 0xeb8826bf, 0x0ca76018, 0x733ecb41,
  9502. 0xd0410d83, 0x43ebaf2a, 0x0420067f, 0x721dab4c, 0x472005bb, 0x4105d341, 0x334844cb, 0x20dba408, 0x47d6ac00, 0x034e3aef, 0x0f8f421b, 0x930f134d,
  9503. 0x3521231f, 0xb7421533, 0x42f5ad0a, 0x1e961eaa, 0x17000022, 0x4c367b50, 0x7d491001, 0x0bf5520f, 0x4c18fda7, 0xb8460c55, 0x83fe2005, 0x00fe25b9,
  9504. 0x80000180, 0x9e751085, 0x261b5c12, 0x82110341, 0x001123fb, 0x4518fe80, 0xf38c2753, 0x6d134979, 0x295107a7, 0xaf5f180f, 0x0fe3660c, 0x180b6079,
  9505. 0x2007bd5f, 0x9aab9103, 0x2f4d1811, 0x05002109, 0x44254746, 0x1d200787, 0x450bab75, 0x4f180f57, 0x4f181361, 0x3b831795, 0xeb4b0120, 0x0b734805,
  9506. 0x84078f48, 0x2e1b47bc, 0x00203383, 0xaf065f45, 0x831520d7, 0x130f51a7, 0x1797bf97, 0x2b47d783, 0x18fe2005, 0x4a18a44f, 0xa64d086d, 0x1ab0410d,
  9507. 0x6205a258, 0xdbab069f, 0x4f06f778, 0xa963081d, 0x133b670a, 0x8323d141, 0x13195b23, 0x530f5e70, 0xe5ad0824, 0x58001421, 0x1f472b4b, 0x47bf410c,
  9508. 0x82000121, 0x83fe20cb, 0x07424404, 0x68068243, 0xd7ad0d3d, 0x00010d26, 0x80020000, 0x4a1c6f43, 0x23681081, 0x10a14f13, 0x8a070e57, 0x430a848f,
  9509. 0x7372243e, 0x4397a205, 0xb56c1021, 0x43978f0f, 0x64180505, 0x99aa0ff2, 0x0e000022, 0x20223341, 0x094b4f37, 0x074a3320, 0x2639410a, 0xfe208e84,
  9510. 0x8b0e0048, 0x508020a3, 0x9e4308fe, 0x073f4115, 0xe3480420, 0x0c9b5f1b, 0x7c137743, 0x9a95185b, 0x6122b148, 0x979b08df, 0x0fe36c18, 0x48109358,
  9511. 0x23441375, 0x0ffd5c0b, 0x180fc746, 0x2011d157, 0x07e95702, 0x58180120, 0x18770ac3, 0x51032008, 0x7d4118e3, 0x80802315, 0x3b4c1900, 0xbb5a1830,
  9512. 0x0ceb6109, 0x5b0b3d42, 0x4f181369, 0x4f180b8d, 0x4f180f75, 0x355a1b81, 0x200d820d, 0x18e483fd, 0x4528854f, 0x89420846, 0x1321411f, 0x44086b60,
  9513. 0x07421d77, 0x107d4405, 0x4113fd41, 0x5a181bf1, 0x4f180db3, 0x8021128f, 0x20f68280, 0x44a882fe, 0x334d249a, 0x052f6109, 0x1520c3a7, 0xef4eb783,
  9514. 0x4ec39b1b, 0xc4c90ee7, 0x20060b4d, 0x256f4905, 0x4d0cf761, 0xcf9b1f13, 0xa213d74e, 0x0e1145d4, 0x50135b42, 0xcb4e398f, 0x20d79f27, 0x08865d80,
  9515. 0x186d5018, 0xa90f7142, 0x067342d7, 0x3f450420, 0x65002021, 0xe3560771, 0x24d38f23, 0x15333531, 0x0eb94d01, 0x451c9f41, 0x384322fb, 0x00092108,
  9516. 0x19af6b18, 0x6e0c6f5a, 0xbd770bfb, 0x22bb7718, 0x20090f57, 0x25e74204, 0x4207275a, 0xdb5408ef, 0x1769450f, 0x1b1b5518, 0x210b1f57, 0x5e4c8001,
  9517. 0x55012006, 0x802107f1, 0x0a306a80, 0x45808021, 0x0d850b88, 0x31744f18, 0x1808ec54, 0x2009575b, 0x45ffa505, 0x1b420c73, 0x180f9f0f, 0x4a0cf748,
  9518. 0x501805b2, 0x00210f40, 0x4d118f80, 0xd6823359, 0x072b5118, 0x314ad7aa, 0x8fc79f08, 0x45d78b1f, 0xfe20058f, 0x23325118, 0x7b54d9b5, 0x9fc38f46,
  9519. 0x10bb410f, 0x41077b42, 0xc1410faf, 0x27cf441d, 0x46051b4f, 0x04200683, 0x2121d344, 0x8f530043, 0x8fcf9f0e, 0x21df8c1f, 0x50188000, 0x5d180e52,
  9520. 0xfd201710, 0x4405c341, 0xd68528e3, 0x20071f6b, 0x1b734305, 0x6b080957, 0x7d422b1f, 0x67002006, 0x7f8317b1, 0x2024cb48, 0x08676e00, 0x8749a39b,
  9521. 0x18132006, 0x410a6370, 0x8f490b47, 0x7e1f8f13, 0x551805c3, 0x4c180915, 0xfe200e2f, 0x244d5d18, 0x270bcf44, 0xff000019, 0x04800380, 0x5f253342,
  9522. 0xff520df7, 0x13274c18, 0x5542dd93, 0x0776181b, 0xf94a1808, 0x084a4c0c, 0x4308ea5b, 0xde831150, 0x7900fd21, 0x00492c1e, 0x060f4510, 0x17410020,
  9523. 0x0ce74526, 0x6206b341, 0x1f561083, 0x9d6c181b, 0x08a0500e, 0x112e4118, 0x60000421, 0xbf901202, 0x4408e241, 0xc7ab0513, 0xb40f0950, 0x055943c7,
  9524. 0x4f18ff20, 0xc9ae1cad, 0x32b34f18, 0x7a180120, 0x3d520a05, 0x53d1b40a, 0x80200813, 0x1b815018, 0x832bf86f, 0x67731847, 0x297f4308, 0x6418d54e,
  9525. 0x734213f7, 0x056b4b27, 0xdba5fe20, 0x1828aa4e, 0x2031a370, 0x06cb6101, 0x2040ad41, 0x07365300, 0x2558d985, 0x83fe200c, 0x0380211c, 0x542c4743,
  9526. 0x052006b7, 0x6021df45, 0x897b0707, 0x18d3c010, 0x20090e70, 0x1d5843ff, 0x540a0e44, 0x002126c5, 0x322f7416, 0x636a5720, 0x0f317409, 0x610fe159,
  9527. 0x294617e7, 0x08555213, 0x2006a75d, 0x6cec84fd, 0xfb5907be, 0x3a317405, 0x83808021, 0x180f20ea, 0x4626434a, 0x531818e3, 0xdb59172d, 0x0cbb460c,
  9528. 0x2013d859, 0x18b94502, 0x8f46188d, 0x77521842, 0x0a184e38, 0x9585fd20, 0x6a180684, 0xc64507e9, 0x51cbb230, 0xd3440cf3, 0x17ff6a0f, 0x450f5b42,
  9529. 0x276407c1, 0x4853180a, 0x21ccb010, 0xcf580013, 0x0c15442d, 0x410a1144, 0x1144359d, 0x5cfe2006, 0xa1410a43, 0x2bb64519, 0x2f5b7618, 0xb512b745,
  9530. 0x0cfd6fd1, 0x42089f59, 0xb8450c70, 0x0000232d, 0x50180900, 0xb9491ae3, 0x0fc37610, 0x01210f83, 0x0f3b4100, 0xa01b2742, 0x0ccd426f, 0x6e8f6f94,
  9531. 0x9c808021, 0xc7511870, 0x17c74b08, 0x9b147542, 0x44fe2079, 0xd5480c7e, 0x95ef861d, 0x101b597b, 0xf5417594, 0x9f471808, 0x86868d0e, 0x3733491c,
  9532. 0x690f4d6d, 0x43440b83, 0x1ba94c0b, 0x660cd16b, 0x802008ae, 0x74126448, 0xcb4f38a3, 0x2cb74b0b, 0x47137755, 0xe3971777, 0x1b5d0120, 0x057a4108,
  9533. 0x6e08664d, 0x17421478, 0x11af4208, 0x850c3f42, 0x08234f0c, 0x4321eb4a, 0xf3451095, 0x0f394e0f, 0x4310eb45, 0xc09707b1, 0x54431782, 0xaec08d1d,
  9534. 0x0f434dbb, 0x9f0c0b45, 0x0a3b4dbb, 0x4618bdc7, 0x536032eb, 0x17354213, 0x4d134169, 0xc7a30c2f, 0x4e254342, 0x174332cf, 0x43cdae17, 0x6b4706e4,
  9535. 0x0e16430d, 0x530b5542, 0x2f7c26bb, 0x13075f31, 0x43175342, 0x60181317, 0x6550114e, 0x28624710, 0x58070021, 0x59181683, 0x2d540cf5, 0x05d5660c,
  9536. 0x20090c7b, 0x0e157e02, 0x8000ff2b, 0x14000080, 0x80ff8000, 0x27137e03, 0x336a4b20, 0x0f817107, 0x13876e18, 0x730f2f7e, 0x2f450b75, 0x6d02200b,
  9537. 0x6d66094c, 0x4b802009, 0x15820a02, 0x2f45fe20, 0x5e032006, 0x00202fd9, 0x450af741, 0xeb412e0f, 0x0ff3411f, 0x420a8b65, 0xf7410eae, 0x1c664810,
  9538. 0x540e1145, 0xbfa509f3, 0x42302f58, 0x80200c35, 0xcb066c47, 0x4b1120c1, 0x41492abb, 0x34854110, 0xa7097b72, 0x251545c7, 0x4b2c7f56, 0xc5b40bab,
  9539. 0x940cd54e, 0x2e6151c8, 0x09f35f18, 0x4b420420, 0x09677121, 0x8f24f357, 0x1b5418e1, 0x08915a1f, 0x3143d894, 0x22541805, 0x1b9b4b0e, 0x8c0d3443,
  9540. 0x1400240d, 0x18ff8000, 0x582e6387, 0xf99b2b3b, 0x8807a550, 0x17a14790, 0x2184fd20, 0x5758fe20, 0x2354882c, 0x15000080, 0x5e056751, 0x334c2c2f,
  9541. 0x97c58f0c, 0x1fd7410f, 0x0d4d4018, 0x4114dc41, 0x04470ed6, 0x0dd54128, 0x00820020, 0x02011523, 0x22008700, 0x86480024, 0x0001240a, 0x8682001a,
  9542. 0x0002240b, 0x866c000e, 0x8a03200b, 0x8a042017, 0x0005220b, 0x22218614, 0x84060000, 0x86012017, 0x8212200f, 0x250b8519, 0x000d0001, 0x0b850031,
  9543. 0x07000224, 0x0b862600, 0x11000324, 0x0b862d00, 0x238a0420, 0x0a000524, 0x17863e00, 0x17840620, 0x01000324, 0x57820904, 0x0b85a783, 0x0b85a785,
  9544. 0x0b85a785, 0x22000325, 0x85007a00, 0x85a7850b, 0x85a7850b, 0x22a7850b, 0x82300032, 0x00342201, 0x0805862f, 0x35003131, 0x54207962, 0x74736972,
  9545. 0x47206e61, 0x6d6d6972, 0x65527265, 0x616c7567, 0x58545472, 0x6f725020, 0x43796767, 0x6e61656c, 0x30325454, 0x822f3430, 0x35313502, 0x79006200,
  9546. 0x54002000, 0x69007200, 0x74007300, 0x6e006100, 0x47200f82, 0x6d240f84, 0x65006d00, 0x52200982, 0x67240582, 0x6c007500, 0x72201d82, 0x54222b82,
  9547. 0x23825800, 0x19825020, 0x67006f22, 0x79220182, 0x1b824300, 0x3b846520, 0x1f825420, 0x41000021, 0x1422099b, 0x0b410000, 0x87088206, 0x01012102,
  9548. 0x78080982, 0x01020101, 0x01040103, 0x01060105, 0x01080107, 0x010a0109, 0x010c010b, 0x010e010d, 0x0110010f, 0x01120111, 0x01140113, 0x01160115,
  9549. 0x01180117, 0x011a0119, 0x011c011b, 0x011e011d, 0x0020011f, 0x00040003, 0x00060005, 0x00080007, 0x000a0009, 0x000c000b, 0x000e000d, 0x0010000f,
  9550. 0x00120011, 0x00140013, 0x00160015, 0x00180017, 0x001a0019, 0x001c001b, 0x001e001d, 0x08bb821f, 0x22002142, 0x24002300, 0x26002500, 0x28002700,
  9551. 0x2a002900, 0x2c002b00, 0x2e002d00, 0x30002f00, 0x32003100, 0x34003300, 0x36003500, 0x38003700, 0x3a003900, 0x3c003b00, 0x3e003d00, 0x40003f00,
  9552. 0x42004100, 0x4b09f382, 0x00450044, 0x00470046, 0x00490048, 0x004b004a, 0x004d004c, 0x004f004e, 0x00510050, 0x00530052, 0x00550054, 0x00570056,
  9553. 0x00590058, 0x005b005a, 0x005d005c, 0x005f005e, 0x01610060, 0x01220121, 0x01240123, 0x01260125, 0x01280127, 0x012a0129, 0x012c012b, 0x012e012d,
  9554. 0x0130012f, 0x01320131, 0x01340133, 0x01360135, 0x01380137, 0x013a0139, 0x013c013b, 0x013e013d, 0x0140013f, 0x00ac0041, 0x008400a3, 0x00bd0085,
  9555. 0x00e80096, 0x008e0086, 0x009d008b, 0x00a400a9, 0x008a00ef, 0x008300da, 0x00f20093, 0x008d00f3, 0x00880097, 0x00de00c3, 0x009e00f1, 0x00f500aa,
  9556. 0x00f600f4, 0x00ad00a2, 0x00c700c9, 0x006200ae, 0x00900063, 0x00cb0064, 0x00c80065, 0x00cf00ca, 0x00cd00cc, 0x00e900ce, 0x00d30066, 0x00d100d0,
  9557. 0x006700af, 0x009100f0, 0x00d400d6, 0x006800d5, 0x00ed00eb, 0x006a0089, 0x006b0069, 0x006c006d, 0x00a0006e, 0x0071006f, 0x00720070, 0x00750073,
  9558. 0x00760074, 0x00ea0077, 0x007a0078, 0x007b0079, 0x007c007d, 0x00a100b8, 0x007e007f, 0x00810080, 0x00ee00ec, 0x6e750eba, 0x646f6369, 0x78302365,
  9559. 0x31303030, 0x32200e8d, 0x33200e8d, 0x34200e8d, 0x35200e8d, 0x36200e8d, 0x37200e8d, 0x38200e8d, 0x39200e8d, 0x61200e8d, 0x62200e8d, 0x63200e8d,
  9560. 0x64200e8d, 0x65200e8d, 0x66200e8d, 0x31210e8c, 0x8d0e8d30, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef,
  9561. 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x66312def, 0x6c656406, 0x04657465, 0x6f727545, 0x3820ec8c, 0x3820ec8d,
  9562. 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d,
  9563. 0x3820ec8d, 0x200ddc41, 0x0ddc4139, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920,
  9564. 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0x00663923, 0x48fa0500, 0x00f762f9,
  9565. };
  9566. static void GetDefaultCompressedFontDataTTF(const void** ttf_compressed_data, unsigned int* ttf_compressed_size)
  9567. {
  9568. *ttf_compressed_data = proggy_clean_ttf_compressed_data;
  9569. *ttf_compressed_size = proggy_clean_ttf_compressed_size;
  9570. }
  9571. //-----------------------------------------------------------------------------
  9572. //---- Include imgui_user.inl at the end of imgui.cpp
  9573. //---- So you can include code that extends ImGui using its private data/functions.
  9574. #ifdef IMGUI_INCLUDE_IMGUI_USER_INL
  9575. #include "imgui_user.inl"
  9576. #endif
  9577. //-----------------------------------------------------------------------------