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 474KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499
  1. // ImGui library v1.39 WIP
  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 ImGui 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. - How do I update to a newer version of ImGui?
  15. - Why is my text output blurry?
  16. - How can I load a different font than the default?
  17. - How can I load multiple fonts?
  18. - How can I display and input Chinese, Japanese, Korean characters?
  19. - ISSUES & TODO-LIST
  20. - CODE
  21. - SAMPLE CODE
  22. - FONT DATA
  23. MISSION STATEMENT
  24. =================
  25. - easy to use to create code-driven and data-driven tools
  26. - easy to use to create ad hoc short-lived tools and long-lived, more elaborate tools
  27. - easy to hack and improve
  28. - minimize screen real-estate usage
  29. - minimize setup and maintenance
  30. - minimize state storage on user side
  31. - portable, minimize dependencies, run on target (consoles, phones, etc.)
  32. - 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)
  33. - read about immediate-mode gui principles @ http://mollyrocket.com/861, http://mollyrocket.com/forums/index.html
  34. Designed for developers and content-creators, not the typical end-user! Some of the weaknesses includes:
  35. - doesn't look fancy, doesn't animate
  36. - limited layout features, intricate layouts are typically crafted in code
  37. - 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.
  38. END-USER GUIDE
  39. ==============
  40. - double-click title bar to collapse window
  41. - click upper right corner to close a window, available when 'bool* p_opened' is passed to ImGui::Begin()
  42. - click and drag on lower right corner to resize window
  43. - click and drag on any empty space to move window
  44. - double-click/double-tap on lower right corner grip to auto-fit to content
  45. - TAB/SHIFT+TAB to cycle through keyboard editable fields
  46. - use mouse wheel to scroll
  47. - use CTRL+mouse wheel to zoom window contents (if IO.FontAllowScaling is true)
  48. - CTRL+Click on a slider to input value as text
  49. - text editor:
  50. - Hold SHIFT or use mouse to select text.
  51. - CTRL+Left/Right to word jump
  52. - CTRL+Shift+Left/Right to select words
  53. - CTRL+A our Double-Click to select all
  54. - CTRL+X,CTRL+C,CTRL+V to use OS clipboard
  55. - CTRL+Z,CTRL+Y to undo/redo
  56. - ESCAPE to revert text to its original value
  57. - You can apply arithmetic operators +,*,/ on numerical values. Use +- to subtract (because - would set a negative value!)
  58. PROGRAMMER GUIDE
  59. ================
  60. - read the FAQ below this section!
  61. - 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.
  62. - call and read ImGui::ShowTestWindow() for sample code demonstrating most features.
  63. - see examples/ folder for standalone sample applications. e.g. examples/opengl_example/
  64. - 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).
  65. - getting started:
  66. - initialisation: call ImGui::GetIO() to retrieve the ImGuiIO structure and fill the 'Settings' data.
  67. - every frame:
  68. 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().
  69. 2/ use any ImGui function you want between NewFrame() and Render()
  70. 3/ ImGui::Render() to render all the accumulated command-lists. it will call your RenderDrawListFn handler that you set in the IO structure.
  71. - all rendering information are stored into command-lists until ImGui::Render() is called.
  72. - ImGui never touches or know about your GPU state. the only function that knows about GPU is the RenderDrawListFn handler that you must provide.
  73. - effectively it means you can create widgets at any time in your code, regardless of "update" vs "render" considerations.
  74. - refer to the examples applications in the examples/ folder for instruction on how to setup your code.
  75. - a typical application skeleton may be:
  76. // Application init
  77. ImGuiIO& io = ImGui::GetIO();
  78. io.DisplaySize.x = 1920.0f;
  79. io.DisplaySize.y = 1280.0f;
  80. io.DeltaTime = 1.0f/60.0f;
  81. io.IniFilename = "imgui.ini";
  82. // TODO: Fill others settings of the io structure
  83. // Load texture
  84. unsigned char* pixels;
  85. int width, height, bytes_per_pixels;
  86. io.Fonts->GetTexDataAsRGBA32(pixels, &width, &height, &bytes_per_pixels);
  87. // TODO: copy texture to graphics memory.
  88. // TODO: store your texture pointer/identifier in 'io.Fonts->TexID'
  89. // Application main loop
  90. while (true)
  91. {
  92. // 1) get low-level input
  93. // e.g. on Win32, GetKeyboardState(), or poll your events, etc.
  94. // 2) TODO: fill all fields of IO structure and call NewFrame
  95. ImGuiIO& io = ImGui::GetIO();
  96. io.MousePos = mouse_pos;
  97. io.MouseDown[0] = mouse_button_0;
  98. io.KeysDown[i] = ...
  99. ImGui::NewFrame();
  100. // 3) most of your application code here - you can use any of ImGui::* functions at any point in the frame
  101. ImGui::Begin("My window");
  102. ImGui::Text("Hello, world.");
  103. ImGui::End();
  104. GameUpdate();
  105. GameRender();
  106. // 4) render & swap video buffers
  107. ImGui::Render();
  108. // swap video buffer, etc.
  109. }
  110. - after calling ImGui::NewFrame() you can read back 'io.WantCaptureMouse' and 'io.WantCaptureKeyboard' to tell if ImGui
  111. wants to use your inputs. if it does you can discard/hide the inputs from the rest of your application.
  112. API BREAKING CHANGES
  113. ====================
  114. Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix.
  115. 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.
  116. - 2015/04/13 (1.38) - renamed IsClipped() to IsRectClipped(). Kept inline redirection function (will obsolete).
  117. - 2015/04/09 (1.38) - renamed ImDrawList::AddArc() to ImDrawList::AddArcFast() for compatibility with future API
  118. - 2015/04/03 (1.38) - removed ImGuiCol_CheckHovered, ImGuiCol_CheckActive, replaced with the more general ImGuiCol_FrameBgHovered, ImGuiCol_FrameBgActive.
  119. - 2014/04/03 (1.38) - removed support for passing -FLT_MAX..+FLT_MAX as the range for a SliderFloat(). Use DragFloat() or Inputfloat() instead.
  120. - 2015/03/17 (1.36) - renamed GetItemRectMin()/GetItemRectMax()/IsMouseHoveringBox() to GetItemRectMin()/GetItemRectMax()/IsMouseHoveringRect(). Kept inline redirection function (will obsolete).
  121. - 2015/03/15 (1.36) - renamed style.TreeNodeSpacing to style.IndentSpacing, ImGuiStyleVar_TreeNodeSpacing to ImGuiStyleVar_IndentSpacing
  122. - 2015/03/13 (1.36) - renamed GetWindowIsFocused() to IsWindowFocused(). Kept inline redirection function (will obsolete).
  123. - 2015/03/08 (1.35) - renamed style.ScrollBarWidth to style.ScrollbarWidth
  124. - 2015/02/27 (1.34) - renamed OpenNextNode(bool) to SetNextTreeNodeOpened(bool, ImGuiSetCond). Kept inline redirection function (will obsolete).
  125. - 2015/02/27 (1.34) - renamed ImGuiSetCondition_*** to ImGuiSetCond_***, and _FirstUseThisSession becomes _Once.
  126. - 2015/02/11 (1.32) - changed text input callback ImGuiTextEditCallback return type from void-->int. reserved for future use, return 0 for now.
  127. - 2015/02/10 (1.32) - renamed GetItemWidth() to CalcItemWidth() to clarify its evolving behavior
  128. - 2015/02/08 (1.31) - renamed GetTextLineSpacing() to GetTextLineHeightWithSpacing()
  129. - 2015/02/01 (1.31) - removed IO.MemReallocFn (unused)
  130. - 2015/01/19 (1.30) - renamed ImGuiStorage::GetIntPtr()/GetFloatPtr() to GetIntRef()/GetIntRef() because Ptr was conflicting with actual pointer storage functions.
  131. - 2015/01/11 (1.30) - big font/image API change! now loads TTF file. allow for multiple fonts. no need for a PNG loader.
  132. (1.30) - removed GetDefaultFontData(). uses io.Fonts->GetTextureData*() API to retrieve uncompressed pixels.
  133. this sequence:
  134. const void* png_data;
  135. unsigned int png_size;
  136. ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
  137. // <Copy to GPU>
  138. became:
  139. unsigned char* pixels;
  140. int width, height;
  141. io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
  142. // <Copy to GPU>
  143. io.Fonts->TexID = (your_texture_identifier);
  144. you now have much more flexibility to load multiple TTF fonts and manage the texture buffer for internal needs.
  145. it is now recommended your sample the font texture with bilinear interpolation.
  146. (1.30) - added texture identifier in ImDrawCmd passed to your render function (we can now render images). make sure to set io.Fonts->TexID.
  147. (1.30) - removed IO.PixelCenterOffset (unnecessary, can be handled in user projection matrix)
  148. (1.30) - removed ImGui::IsItemFocused() in favor of ImGui::IsItemActive() which handles all widgets
  149. - 2014/12/10 (1.18) - removed SetNewWindowDefaultPos() in favor of new generic API SetNextWindowPos(pos, ImGuiSetCondition_FirstUseEver)
  150. - 2014/11/28 (1.17) - moved IO.Font*** options to inside the IO.Font-> structure (FontYOffset, FontTexUvForWhite, FontBaseScale, FontFallbackGlyph)
  151. - 2014/11/26 (1.17) - reworked syntax of IMGUI_ONCE_UPON_A_FRAME helper macro to increase compiler compatibility
  152. - 2014/11/07 (1.15) - renamed IsHovered() to IsItemHovered()
  153. - 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)
  154. - 2014/09/25 (1.13) - removed 'text_end' parameter from IO.SetClipboardTextFn (the string is now always zero-terminated for simplicity)
  155. - 2014/09/24 (1.12) - renamed SetFontScale() to SetWindowFontScale()
  156. - 2014/09/24 (1.12) - moved IM_MALLOC/IM_REALLOC/IM_FREE preprocessor defines to IO.MemAllocFn/IO.MemReallocFn/IO.MemFreeFn
  157. - 2014/08/30 (1.09) - removed IO.FontHeight (now computed automatically)
  158. - 2014/08/30 (1.09) - moved IMGUI_FONT_TEX_UV_FOR_WHITE preprocessor define to IO.FontTexUvForWhite
  159. - 2014/08/28 (1.09) - changed the behavior of IO.PixelCenterOffset following various rendering fixes
  160. FREQUENTLY ASKED QUESTIONS (FAQ), TIPS
  161. ======================================
  162. Q: Can I have multiple widgets with the same label?
  163. A: Yes. A primer on the use of labels/IDs in ImGui..
  164. - Interactive widgets require state to be carried over multiple frames (most typically ImGui often needs to remember what is the "active" widget).
  165. to do so they need an unique ID. unique ID are typically derived from a string label, an integer index or a pointer.
  166. Button("OK"); // Label = "OK", ID = hash of "OK"
  167. Button("Cancel"); // Label = "Cancel", ID = hash of "Cancel"
  168. - Elements that are not clickable, such as Text() items don't need an ID.
  169. - 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
  170. or in two different locations of a tree.
  171. - if you have a same ID twice in the same location, you'll have a conflict:
  172. Button("OK");
  173. Button("OK"); // ID collision! Both buttons will be treated as the same.
  174. Fear not! this is easy to solve and there are many ways to solve it!
  175. - when passing a label you can optionally specify extra unique ID information within string itself. This helps solving the simpler collision cases.
  176. use "##" to pass a complement to the ID that won't be visible to the end-user:
  177. Button("Play##0"); // Label = "Play", ID = hash of "Play##0"
  178. Button("Play##1"); // Label = "Play", ID = hash of "Play##1" (different from above)
  179. - occasionally (rarely) you might want change a label while preserving a constant ID. This allows you to animate labels.
  180. use "###" to pass a label that isn't part of ID:
  181. Button("Hello###ID"; // Label = "Hello", ID = hash of "ID"
  182. Button("World###ID"; // Label = "World", ID = hash of "ID" (same as above)
  183. - use PushID() / PopID() to create scopes and avoid ID conflicts within the same Window.
  184. this is the most convenient way of distinguish ID if you are iterating and creating many UI elements.
  185. 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!
  186. for (int i = 0; i < 100; i++)
  187. {
  188. PushID(i);
  189. Button("Click"); // Label = "Click", ID = hash of integer + "label" (unique)
  190. PopID();
  191. }
  192. for (int i = 0; i < 100; i++)
  193. {
  194. MyObject* obj = Objects[i];
  195. PushID(obj);
  196. Button("Click"); // Label = "Click", ID = hash of pointer + "label" (unique)
  197. PopID();
  198. }
  199. for (int i = 0; i < 100; i++)
  200. {
  201. MyObject* obj = Objects[i];
  202. PushID(obj->Name);
  203. Button("Click"); // Label = "Click", ID = hash of string + "label" (unique)
  204. PopID();
  205. }
  206. - more example showing that you can stack multiple prefixes into the ID stack:
  207. Button("Click"); // Label = "Click", ID = hash of "Click"
  208. PushID("node");
  209. Button("Click"); // Label = "Click", ID = hash of "node" + "Click"
  210. PushID(my_ptr);
  211. Button("Click"); // Label = "Click", ID = hash of "node" + ptr + "Click"
  212. PopID();
  213. PopID();
  214. - tree nodes implicitly creates a scope for you by calling PushID().
  215. Button("Click"); // Label = "Click", ID = hash of "Click"
  216. if (TreeNode("node"))
  217. {
  218. Button("Click"); // Label = "Click", ID = hash of "node" + "Click"
  219. TreePop();
  220. }
  221. - when working with trees, ID are used to preserve the opened/closed state of each tree node.
  222. depending on your use cases you may want to use strings, indices or pointers as ID.
  223. 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.
  224. 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!
  225. Q: How do I update to a newer version of ImGui?
  226. A: Overwrite the following files:
  227. imgui.cpp
  228. imgui.h
  229. stb_rect_pack.h
  230. stb_textedit.h
  231. stb_truetype.h
  232. Check the "API BREAKING CHANGES" sections for a list of occasional API breaking changes.
  233. Q: Why is my text output blurry?
  234. A: In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
  235. Q: How can I load a different font than the default? (default is an embedded version of ProggyClean.ttf, rendered at size 13)
  236. A: Use the font atlas to load the TTF file you want:
  237. io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
  238. io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
  239. Q: How can I load multiple fonts?
  240. A: Use the font atlas to pack them into a single texture:
  241. ImFont* font0 = io.Fonts->AddFontDefault();
  242. ImFont* font1 = io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
  243. ImFont* font2 = io.Fonts->AddFontFromFileTTF("myfontfile2.ttf", size_in_pixels);
  244. io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
  245. // the first loaded font gets used by default
  246. // use ImGui::PushFont()/ImGui::PopFont() to change the font at runtime
  247. Q: How can I render and input Chinese, Japanese, Korean characters?
  248. A: When loading a font, pass custom Unicode ranges to specify the glyphs to load. ImGui will support UTF-8 encoding across the board.
  249. Character input depends on you passing the right character code to io.AddInputCharacter(). The example applications do that.
  250. io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, io.Fonts->GetGlyphRangesJapanese()); // Load Japanese characters
  251. io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
  252. io.ImeWindowHandle = MY_HWND; // To input using Microsoft IME, give ImGui the hwnd of your application
  253. - 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.
  254. - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug"
  255. - tip: you can call Begin() multiple times with the same name during the same frame, it will keep appending to the same window.
  256. - tip: you can call Render() multiple times (e.g for VR renders).
  257. - tip: call and read the ShowTestWindow() code for more example of how to use ImGui!
  258. ISSUES & TODO-LIST
  259. ==================
  260. - misc: merge or clarify ImVec4 vs ImRect?
  261. - window: add horizontal scroll
  262. - window: fix resize grip rendering scaling along with Rounding style setting
  263. - window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit?
  264. - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list.
  265. - window: allow resizing of child windows (possibly given min/max for each axis?)
  266. - window: background options for child windows, border option (disable rounding)
  267. - window: resizing from any sides? + mouse cursor directives for app.
  268. - widgets: display mode: widget-label, label-widget (aligned on column or using fixed size), label-newline-tab-widget etc.
  269. - widgets: clean up widgets internal toward exposing everything.
  270. - main: considering adding EndFrame()/Init(). some constructs are awkward in the implementation because of the lack of them.
  271. - 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
  272. - main: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode?
  273. !- input number: large int not reliably supported because of int<>float conversions.
  274. - input number: optional range min/max for Input*() functions
  275. - input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled)
  276. - input number: use mouse wheel to step up/down
  277. - input number: non-decimal input.
  278. - text: proper alignment options
  279. - layout: horizontal layout helper (github issue #97)
  280. - layout: more generic alignment state (left/right/centered) for single items?
  281. - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding.
  282. - columns: separator function or parameter that works within the column (currently Separator() bypass all columns) (github issue #125)
  283. - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills) (github issue #125)
  284. - columns: columns header to act as button (~sort op) and allow resize/reorder (github issue #125)
  285. - columns: user specify columns size (github issue #125)
  286. - popup: border options. richer api like BeginChild() perhaps? (github issue #197)
  287. - combo: turn child handling code into pop up helper
  288. - combo: contents should extends to fit label if combo widget is small
  289. - listbox: multiple selection
  290. - listbox: user may want to initial scroll to focus on the one selected value?
  291. ! menubar, menus (github issue #126)
  292. - tabs
  293. - gauge: various forms of gauge/loading bars widgets
  294. - color: better color editor.
  295. - plot: make it easier for user to draw extra stuff into the graph (e.g: draw basis, highlight certain points, 2d plots, multiple plots)
  296. - plot: "smooth" automatic scale over time, user give an input 0.0(full user scale) 1.0(full derived from value)
  297. - 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)
  298. - file selection widget -> build the tool in our codebase to improve model-dialog idioms
  299. - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt()
  300. - slider: initial absolute click is imprecise. change to relative movement slider (same as scrollbar).
  301. - slider: add dragging-based widgets to edit values with mouse (on 2 axises), saving screen real-estate.
  302. - text edit: clean up the mess caused by converting UTF-8 <> wchar. the code is rather inefficient right now.
  303. - text edit: centered text for slider as input text so it matches typical positioning.
  304. - text edit: flag to disable live update of the user buffer.
  305. - text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text?
  306. - text edit: add multi-line text edit
  307. - tree: add treenode/treepush int variants? because (void*) cast from int warns on some platforms/settings
  308. - settings: write more decent code to allow saving/loading new fields
  309. - settings: api for per-tool simple persistent data (bool,int,float,columns sizes,etc.) in .ini file
  310. ! style: store rounded corners in texture to use 1 quad per corner (filled and wireframe). so rounding have minor cost.
  311. - style: checkbox: padding for "active" color should be a multiplier of the
  312. - style: colorbox not always square?
  313. - text: simple markup language for color change?
  314. - log: LogButtons() options for specifying depth and/or hiding depth slider
  315. - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope)
  316. - log: be able to log anything (e.g. right-click on a window/tree-node, shows context menu? log into tty/file/clipboard)
  317. - 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.
  318. - filters: set a current filter that tree node can automatically query to hide themselves
  319. - filters: handle wildcards (with implicit leading/trailing *), regexps
  320. - 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)
  321. ! keyboard: tooltip & combo boxes are messing up / not honoring keyboard tabbing
  322. - keyboard: full keyboard navigation and focus.
  323. - input: rework IO to be able to pass actual events to fix temporal aliasing issues.
  324. - input: support track pad style scrolling & slider edit.
  325. - tooltip: move to fit within screen (e.g. when mouse cursor is right of the screen).
  326. - portability: big-endian test/support (github issue #81)
  327. - misc: mark printf compiler attributes on relevant functions
  328. - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL)
  329. - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon?
  330. - style editor: have a more global HSV setter (e.g. alter hue on all elements). consider replacing active/hovered by offset in HSV space?
  331. - style editor: color child window height expressed in multiple of line height.
  332. - optimization/render: use indexed rendering to reduce vertex data cost (e.g. for remote/networked imgui)
  333. - 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)?
  334. - optimization: turn some the various stack vectors into statically-sized arrays
  335. - optimization: better clipping for multi-component widgets
  336. */
  337. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  338. #define _CRT_SECURE_NO_WARNINGS
  339. #endif
  340. #include "imgui.h"
  341. #include <ctype.h> // toupper, isprint
  342. #include <math.h> // sqrtf, fabsf, fmodf, powf, cosf, sinf, floorf, ceilf
  343. #include <stdint.h> // intptr_t
  344. #include <stdio.h> // vsnprintf, sscanf
  345. #include <new> // new (ptr)
  346. #ifdef _MSC_VER
  347. #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
  348. #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
  349. #endif
  350. // Clang warnings with -Weverything
  351. #ifdef __clang__
  352. #pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
  353. #pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants ok.
  354. #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.
  355. #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.
  356. #pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it.
  357. #pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness //
  358. #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.
  359. #endif
  360. #ifdef __GNUC__
  361. #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
  362. #endif
  363. //-------------------------------------------------------------------------
  364. // STB libraries implementation
  365. //-------------------------------------------------------------------------
  366. struct ImGuiTextEditState;
  367. //#define IMGUI_STB_NAMESPACE ImStb
  368. //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
  369. //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
  370. #ifdef IMGUI_STB_NAMESPACE
  371. namespace IMGUI_STB_NAMESPACE
  372. {
  373. #endif
  374. #ifdef __clang__
  375. #pragma clang diagnostic push
  376. #pragma clang diagnostic ignored "-Wunused-function"
  377. #pragma clang diagnostic ignored "-Wmissing-prototypes"
  378. #endif
  379. #define STBRP_ASSERT(x) IM_ASSERT(x)
  380. #ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
  381. #define STBRP_STATIC
  382. #define STB_RECT_PACK_IMPLEMENTATION
  383. #endif
  384. #include "stb_rect_pack.h"
  385. #define STBTT_malloc(x,u) ((void)(u), ImGui::MemAlloc(x))
  386. #define STBTT_free(x,u) ((void)(u), ImGui::MemFree(x))
  387. #define STBTT_assert(x) IM_ASSERT(x)
  388. #ifndef IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
  389. #define STBTT_STATIC
  390. #define STB_TRUETYPE_IMPLEMENTATION
  391. #endif
  392. #include "stb_truetype.h"
  393. #undef STB_TEXTEDIT_STRING
  394. #undef STB_TEXTEDIT_CHARTYPE
  395. #define STB_TEXTEDIT_STRING ImGuiTextEditState
  396. #define STB_TEXTEDIT_CHARTYPE ImWchar
  397. #include "stb_textedit.h"
  398. #ifdef __clang__
  399. #pragma clang diagnostic pop
  400. #endif
  401. #ifdef IMGUI_STB_NAMESPACE
  402. } // namespace ImStb
  403. using namespace IMGUI_STB_NAMESPACE;
  404. #endif
  405. //-------------------------------------------------------------------------
  406. // Forward Declarations
  407. //-------------------------------------------------------------------------
  408. struct ImRect;
  409. struct ImGuiColMod;
  410. struct ImGuiStyleMod;
  411. struct ImGuiDrawContext;
  412. struct ImGuiTextEditState;
  413. struct ImGuiIniData;
  414. struct ImGuiState;
  415. struct ImGuiWindow;
  416. 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);
  417. static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL);
  418. static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true);
  419. static void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width);
  420. static void RenderTextClipped(ImVec2 pos, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& clip_max);
  421. static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
  422. static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false);
  423. static void SetFont(ImFont* font);
  424. static bool ItemAdd(const ImRect& bb, const ImGuiID* id);
  425. static void ItemSize(ImVec2 size, float text_offset_y = 0.0f);
  426. static void ItemSize(const ImRect& bb, float text_offset_y = 0.0f);
  427. static void PushColumnClipRect(int column_index = -1);
  428. static bool IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged);
  429. static bool IsMouseHoveringRect(const ImRect& bb);
  430. static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true);
  431. static void Scrollbar(ImGuiWindow* window);
  432. static bool CloseWindowButton(bool* p_opened = NULL);
  433. static void FocusWindow(ImGuiWindow* window);
  434. static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs);
  435. // Helpers: String
  436. static int ImStricmp(const char* str1, const char* str2);
  437. static int ImStrnicmp(const char* str1, const char* str2, int count);
  438. static char* ImStrdup(const char *str);
  439. static size_t ImStrlenW(const ImWchar* str);
  440. static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end);
  441. static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...);
  442. static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args);
  443. // Helpers: Misc
  444. static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed);
  445. 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);
  446. 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; }
  447. static inline bool ImCharIsSpace(int c) { return c == ' ' || c == '\t' || c == 0x3000; }
  448. // Helpers: UTF-8 <> wchar
  449. static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int in_char); // return output UTF-8 bytes count
  450. 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
  451. static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count
  452. 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
  453. static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count)
  454. static int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points
  455. //-----------------------------------------------------------------------------
  456. // Platform dependent default implementations
  457. //-----------------------------------------------------------------------------
  458. static const char* GetClipboardTextFn_DefaultImpl();
  459. static void SetClipboardTextFn_DefaultImpl(const char* text);
  460. static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y);
  461. //-----------------------------------------------------------------------------
  462. // User facing structures
  463. //-----------------------------------------------------------------------------
  464. ImGuiStyle::ImGuiStyle()
  465. {
  466. Alpha = 1.0f; // Global alpha applies to everything in ImGui
  467. WindowPadding = ImVec2(8,8); // Padding within a window
  468. WindowMinSize = ImVec2(32,32); // Minimum window size
  469. WindowRounding = 9.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
  470. ChildWindowRounding = 0.0f; // Radius of child window corners rounding. Set to 0.0f to have rectangular windows
  471. FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets)
  472. FrameRounding = 0.0f; // Radius of frame corners rounding. Set to 0.0f to have rectangular frames (used by most widgets).
  473. ItemSpacing = ImVec2(8,4); // Horizontal and vertical spacing between widgets/lines
  474. ItemInnerSpacing = ImVec2(4,4); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
  475. 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!
  476. AutoFitPadding = ImVec2(8,8); // Extra space after auto-fit (double-clicking on resize grip)
  477. WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin()
  478. IndentSpacing = 22.0f; // Horizontal spacing when e.g. entering a tree node
  479. ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns
  480. ScrollbarWidth = 16.0f; // Width of the vertical scrollbar
  481. GrabMinSize = 10.0f; // Minimum width/height of a slider or scrollbar grab
  482. 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
  483. Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
  484. Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
  485. Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  486. Colors[ImGuiCol_Border] = ImVec4(0.70f, 0.70f, 0.70f, 1.00f);
  487. Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.60f);
  488. Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f); // Background of checkbox, radio button, plot, slider, text input
  489. Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.90f, 0.80f, 0.80f, 0.40f);
  490. Colors[ImGuiCol_FrameBgActive] = ImVec4(0.90f, 0.65f, 0.65f, 0.45f);
  491. Colors[ImGuiCol_TitleBg] = ImVec4(0.50f, 0.50f, 1.00f, 0.45f);
  492. Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.40f, 0.40f, 0.80f, 0.20f);
  493. Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.40f, 0.40f, 0.80f, 0.15f);
  494. Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.80f, 0.30f);
  495. Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f);
  496. Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 0.40f);
  497. Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f);
  498. Colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f);
  499. Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
  500. Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  501. Colors[ImGuiCol_Button] = ImVec4(0.67f, 0.40f, 0.40f, 0.60f);
  502. Colors[ImGuiCol_ButtonHovered] = ImVec4(0.67f, 0.40f, 0.40f, 1.00f);
  503. Colors[ImGuiCol_ButtonActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  504. Colors[ImGuiCol_Header] = ImVec4(0.40f, 0.40f, 0.90f, 0.45f);
  505. Colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.90f, 0.80f);
  506. Colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.87f, 0.80f);
  507. Colors[ImGuiCol_Column] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
  508. Colors[ImGuiCol_ColumnHovered] = ImVec4(0.70f, 0.60f, 0.60f, 1.00f);
  509. Colors[ImGuiCol_ColumnActive] = ImVec4(0.90f, 0.70f, 0.70f, 1.00f);
  510. Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
  511. Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.00f, 1.00f, 1.00f, 0.60f);
  512. Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.90f);
  513. Colors[ImGuiCol_CloseButton] = ImVec4(0.50f, 0.50f, 0.90f, 0.50f);
  514. Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.70f, 0.70f, 0.90f, 0.60f);
  515. Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.70f, 0.70f, 0.70f, 1.00f);
  516. Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  517. Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  518. Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  519. Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
  520. Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
  521. Colors[ImGuiCol_TooltipBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
  522. }
  523. // 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)
  524. // Also we wouldn't be able to new() one at this point, before users may define IO.MemAllocFn.
  525. static ImFontAtlas GDefaultFontAtlas;
  526. ImGuiIO::ImGuiIO()
  527. {
  528. // Most fields are initialized with zero
  529. memset(this, 0, sizeof(*this));
  530. DisplaySize = ImVec2(-1.0f, -1.0f);
  531. DeltaTime = 1.0f/60.0f;
  532. IniSavingRate = 5.0f;
  533. IniFilename = "imgui.ini";
  534. LogFilename = "imgui_log.txt";
  535. Fonts = &GDefaultFontAtlas;
  536. FontGlobalScale = 1.0f;
  537. MousePos = ImVec2(-1,-1);
  538. MousePosPrev = ImVec2(-1,-1);
  539. MouseDoubleClickTime = 0.30f;
  540. MouseDoubleClickMaxDist = 6.0f;
  541. MouseDragThreshold = 6.0f;
  542. UserData = NULL;
  543. // User functions
  544. RenderDrawListsFn = NULL;
  545. MemAllocFn = malloc;
  546. MemFreeFn = free;
  547. GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations
  548. SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
  549. ImeSetInputScreenPosFn = ImeSetInputScreenPosFn_DefaultImpl;
  550. }
  551. // Pass in translated ASCII characters for text input.
  552. // - with glfw you can get those from the callback set in glfwSetCharCallback()
  553. // - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message
  554. void ImGuiIO::AddInputCharacter(ImWchar c)
  555. {
  556. const size_t n = ImStrlenW(InputCharacters);
  557. if (n + 1 < sizeof(InputCharacters) / sizeof(InputCharacters[0]))
  558. {
  559. InputCharacters[n] = c;
  560. InputCharacters[n+1] = 0;
  561. }
  562. }
  563. //-----------------------------------------------------------------------------
  564. // Helpers
  565. //-----------------------------------------------------------------------------
  566. #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
  567. #undef PI
  568. const float PI = 3.14159265358979323846f;
  569. #ifdef INT_MAX
  570. #define IM_INT_MIN INT_MIN
  571. #define IM_INT_MAX INT_MAX
  572. #else
  573. #define IM_INT_MIN (-2147483647-1)
  574. #define IM_INT_MAX (2147483647)
  575. #endif
  576. // Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n.
  577. #ifdef _MSC_VER
  578. #define STR_NEWLINE "\r\n"
  579. #else
  580. #define STR_NEWLINE "\n"
  581. #endif
  582. // Math bits
  583. // 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.
  584. static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); }
  585. //static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); }
  586. static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); }
  587. static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); }
  588. static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); }
  589. static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); }
  590. static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; }
  591. static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; }
  592. static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; }
  593. //static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; }
  594. static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; }
  595. static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; }
  596. static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; }
  597. static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; }
  598. static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); }
  599. static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); }
  600. static inline int ImClamp(int v, int mn, int mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
  601. static inline float ImClamp(float v, float mn, float mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
  602. 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)); }
  603. static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; }
  604. static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; }
  605. 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); }
  606. static inline float ImLengthSqr(const ImVec2& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y; }
  607. static int ImStricmp(const char* str1, const char* str2)
  608. {
  609. int d;
  610. while ((d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; }
  611. return d;
  612. }
  613. static int ImStrnicmp(const char* str1, const char* str2, int count)
  614. {
  615. int d = 0;
  616. while (count > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; count--; }
  617. return d;
  618. }
  619. static char* ImStrdup(const char *str)
  620. {
  621. char *buff = (char*)ImGui::MemAlloc(strlen(str) + 1);
  622. IM_ASSERT(buff);
  623. strcpy(buff, str);
  624. return buff;
  625. }
  626. static size_t ImStrlenW(const ImWchar* str)
  627. {
  628. size_t n = 0;
  629. while (*str++) n++;
  630. return n;
  631. }
  632. static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end)
  633. {
  634. if (!needle_end)
  635. needle_end = needle + strlen(needle);
  636. const char un0 = (char)toupper(*needle);
  637. while (*haystack)
  638. {
  639. if (toupper(*haystack) == un0)
  640. {
  641. const char* b = needle + 1;
  642. for (const char* a = haystack + 1; b < needle_end; a++, b++)
  643. if (toupper(*a) != toupper(*b))
  644. break;
  645. if (b == needle_end)
  646. return haystack;
  647. }
  648. haystack++;
  649. }
  650. return NULL;
  651. }
  652. // Pass data_size==0 for zero-terminated string
  653. // Try to replace with FNV1a hash?
  654. static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed = 0)
  655. {
  656. static ImU32 crc32_lut[256] = { 0 };
  657. if (!crc32_lut[1])
  658. {
  659. const ImU32 polynomial = 0xEDB88320;
  660. for (ImU32 i = 0; i < 256; i++)
  661. {
  662. ImU32 crc = i;
  663. for (ImU32 j = 0; j < 8; j++)
  664. crc = (crc >> 1) ^ (ImU32(-int(crc & 1)) & polynomial);
  665. crc32_lut[i] = crc;
  666. }
  667. }
  668. seed = ~seed;
  669. ImU32 crc = seed;
  670. const unsigned char* current = (const unsigned char*)data;
  671. if (data_size > 0)
  672. {
  673. // Known size
  674. while (data_size--)
  675. crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++];
  676. }
  677. else
  678. {
  679. // Zero-terminated string
  680. while (unsigned char c = *current++)
  681. {
  682. // We support a syntax of "label###id" where only "###id" is included in the hash, and only "label" gets displayed.
  683. // Because this syntax is rarely used we are optimizing for the common case.
  684. // - If we reach ### in the string we discard the hash so far and reset to the seed.
  685. // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller.
  686. if (c == '#' && current[0] == '#' && current[1] == '#')
  687. crc = seed;
  688. crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
  689. }
  690. }
  691. return ~crc;
  692. }
  693. static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...)
  694. {
  695. va_list args;
  696. va_start(args, fmt);
  697. int w = vsnprintf(buf, buf_size, fmt, args);
  698. va_end(args);
  699. buf[buf_size-1] = 0;
  700. return (w == -1) ? buf_size : (size_t)w;
  701. }
  702. static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args)
  703. {
  704. int w = vsnprintf(buf, buf_size, fmt, args);
  705. buf[buf_size-1] = 0;
  706. return (w == -1) ? buf_size : (size_t)w;
  707. }
  708. ImU32 ImGui::ColorConvertFloat4ToU32(const ImVec4& in)
  709. {
  710. ImU32 out = ((ImU32)(ImSaturate(in.x)*255.f));
  711. out |= ((ImU32)(ImSaturate(in.y)*255.f) << 8);
  712. out |= ((ImU32)(ImSaturate(in.z)*255.f) << 16);
  713. out |= ((ImU32)(ImSaturate(in.w)*255.f) << 24);
  714. return out;
  715. }
  716. // Convert rgb floats ([0-1],[0-1],[0-1]) to hsv floats ([0-1],[0-1],[0-1]), from Foley & van Dam p592
  717. // Optimized http://lolengine.net/blog/2013/01/13/fast-rgb-to-hsv
  718. void ImGui::ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v)
  719. {
  720. float K = 0.f;
  721. if (g < b)
  722. {
  723. const float tmp = g; g = b; b = tmp;
  724. K = -1.f;
  725. }
  726. if (r < g)
  727. {
  728. const float tmp = r; r = g; g = tmp;
  729. K = -2.f / 6.f - K;
  730. }
  731. const float chroma = r - (g < b ? g : b);
  732. out_h = fabsf(K + (g - b) / (6.f * chroma + 1e-20f));
  733. out_s = chroma / (r + 1e-20f);
  734. out_v = r;
  735. }
  736. // Convert hsv floats ([0-1],[0-1],[0-1]) to rgb floats ([0-1],[0-1],[0-1]), from Foley & van Dam p593
  737. // also http://en.wikipedia.org/wiki/HSL_and_HSV
  738. void ImGui::ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b)
  739. {
  740. if (s == 0.0f)
  741. {
  742. // gray
  743. out_r = out_g = out_b = v;
  744. return;
  745. }
  746. h = fmodf(h, 1.0f) / (60.0f/360.0f);
  747. int i = (int)h;
  748. float f = h - (float)i;
  749. float p = v * (1.0f - s);
  750. float q = v * (1.0f - s * f);
  751. float t = v * (1.0f - s * (1.0f - f));
  752. switch (i)
  753. {
  754. case 0: out_r = v; out_g = t; out_b = p; break;
  755. case 1: out_r = q; out_g = v; out_b = p; break;
  756. case 2: out_r = p; out_g = v; out_b = t; break;
  757. case 3: out_r = p; out_g = q; out_b = v; break;
  758. case 4: out_r = t; out_g = p; out_b = v; break;
  759. case 5: default: out_r = v; out_g = p; out_b = q; break;
  760. }
  761. }
  762. // Load file content into memory
  763. // Memory allocated with ImGui::MemAlloc(), must be freed by user using ImGui::MemFree()
  764. static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes)
  765. {
  766. IM_ASSERT(filename && file_open_mode && out_file_data && out_file_size);
  767. *out_file_data = NULL;
  768. *out_file_size = 0;
  769. FILE* f;
  770. if ((f = fopen(filename, file_open_mode)) == NULL)
  771. return false;
  772. long file_size_signed;
  773. if (fseek(f, 0, SEEK_END) || (file_size_signed = ftell(f)) == -1 || fseek(f, 0, SEEK_SET))
  774. {
  775. fclose(f);
  776. return false;
  777. }
  778. size_t file_size = (size_t)file_size_signed;
  779. void* file_data = ImGui::MemAlloc(file_size + padding_bytes);
  780. if (file_data == NULL)
  781. {
  782. fclose(f);
  783. return false;
  784. }
  785. if (fread(file_data, 1, file_size, f) != file_size)
  786. {
  787. fclose(f);
  788. ImGui::MemFree(file_data);
  789. return false;
  790. }
  791. if (padding_bytes > 0)
  792. memset((void *)(((char*)file_data) + file_size), 0, padding_bytes);
  793. fclose(f);
  794. *out_file_data = file_data;
  795. *out_file_size = file_size;
  796. return true;
  797. }
  798. //-----------------------------------------------------------------------------
  799. struct ImGuiColMod // Color modifier, backup of modified data so we can restore it
  800. {
  801. ImGuiCol Col;
  802. ImVec4 PreviousValue;
  803. };
  804. struct ImGuiStyleMod // Style modifier, backup of modified data so we can restore it
  805. {
  806. ImGuiStyleVar Var;
  807. ImVec2 PreviousValue;
  808. };
  809. struct ImRect // 2D axis aligned bounding-box
  810. {
  811. ImVec2 Min;
  812. ImVec2 Max;
  813. ImRect() { Min = ImVec2(FLT_MAX,FLT_MAX); Max = ImVec2(-FLT_MAX,-FLT_MAX); }
  814. ImRect(const ImVec2& min, const ImVec2& max) { Min = min; Max = max; }
  815. ImRect(const ImVec4& v) { Min.x = v.x; Min.y = v.y; Max.x = v.z; Max.y = v.w; }
  816. ImRect(float x1, float y1, float x2, float y2) { Min.x = x1; Min.y = y1; Max.x = x2; Max.y = y2; }
  817. ImVec2 GetCenter() const { return Min + (Max-Min)*0.5f; }
  818. ImVec2 GetSize() const { return Max-Min; }
  819. float GetWidth() const { return (Max-Min).x; }
  820. float GetHeight() const { return (Max-Min).y; }
  821. ImVec2 GetTL() const { return Min; }
  822. ImVec2 GetTR() const { return ImVec2(Max.x,Min.y); }
  823. ImVec2 GetBL() const { return ImVec2(Min.x,Max.y); }
  824. ImVec2 GetBR() const { return Max; }
  825. bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x < Max.x && p.y < Max.y; }
  826. 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; }
  827. 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; }
  828. 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); }
  829. 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); }
  830. void Expand(const float amount) { Min.x -= amount; Min.y -= amount; Max.x += amount; Max.y += amount; }
  831. void Expand(const ImVec2& amount) { Min -= amount; Max += amount; }
  832. 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); }
  833. ImVec2 GetClosestPoint(ImVec2 p, bool on_edge) const
  834. {
  835. if (!on_edge && Contains(p))
  836. return p;
  837. if (p.x > Max.x) p.x = Max.x;
  838. else if (p.x < Min.x) p.x = Min.x;
  839. if (p.y > Max.y) p.y = Max.y;
  840. else if (p.y < Min.y) p.y = Min.y;
  841. return p;
  842. }
  843. };
  844. typedef ImRect ImGuiAabb; // FIXME-OBSOLETE
  845. struct ImGuiGroupData
  846. {
  847. ImVec2 BackupCursorPos;
  848. ImVec2 BackupCursorMaxPos;
  849. float BackupColumnsStartX;
  850. float BackupCurrentLineHeight;
  851. float BackupCurrentLineTextBaseOffset;
  852. float BackupLogLinePosY;
  853. };
  854. // Temporary per-window data, reset at the beginning of the frame
  855. struct ImGuiDrawContext
  856. {
  857. ImVec2 CursorPos;
  858. ImVec2 CursorPosPrevLine;
  859. ImVec2 CursorStartPos;
  860. ImVec2 CursorMaxPos; // Implicitly calculate the size of our contents, always extending. Saved into window->SizeContents at the end of the frame
  861. float CurrentLineHeight;
  862. float CurrentLineTextBaseOffset;
  863. float PrevLineHeight;
  864. float PrevLineTextBaseOffset;
  865. float LogLinePosY;
  866. int TreeDepth;
  867. ImGuiID LastItemID;
  868. ImRect LastItemRect;
  869. bool LastItemHoveredAndUsable;
  870. bool LastItemHoveredRect;
  871. ImVector<ImGuiWindow*> ChildWindows;
  872. ImVector<bool> AllowKeyboardFocus;
  873. ImVector<float> ItemWidth; // 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window
  874. ImVector<float> TextWrapPos;
  875. ImVector<ImGuiGroupData> GroupStack;
  876. ImGuiColorEditMode ColorEditMode;
  877. ImGuiStorage* StateStorage;
  878. float ColumnsStartX; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.)
  879. 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.
  880. int ColumnsCurrent;
  881. int ColumnsCount;
  882. ImVec2 ColumnsStartPos;
  883. float ColumnsCellMinY;
  884. float ColumnsCellMaxY;
  885. bool ColumnsShowBorders;
  886. ImGuiID ColumnsSetID;
  887. ImVector<float> ColumnsOffsetsT; // Columns offset normalized 0.0 (far left) -> 1.0 (far right)
  888. ImGuiDrawContext()
  889. {
  890. CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f);
  891. CurrentLineHeight = PrevLineHeight = 0.0f;
  892. CurrentLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f;
  893. LogLinePosY = -1.0f;
  894. TreeDepth = 0;
  895. LastItemID = 0;
  896. LastItemRect = ImRect(0.0f,0.0f,0.0f,0.0f);
  897. LastItemHoveredAndUsable = LastItemHoveredRect = false;
  898. ColorEditMode = ImGuiColorEditMode_RGB;
  899. StateStorage = NULL;
  900. ColumnsStartX = 0.0f;
  901. ColumnsOffsetX = 0.0f;
  902. ColumnsCurrent = 0;
  903. ColumnsCount = 1;
  904. ColumnsStartPos = ImVec2(0.0f, 0.0f);
  905. ColumnsCellMinY = ColumnsCellMaxY = 0.0f;
  906. ColumnsShowBorders = true;
  907. ColumnsSetID = 0;
  908. }
  909. };
  910. // Internal state of the currently focused/edited text input box
  911. struct ImGuiTextEditState
  912. {
  913. ImGuiID Id; // widget id owning the text state
  914. 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.
  915. char InitialText[1024*3+1]; // backup of end-user buffer at the time of focus (in UTF-8, unaltered)
  916. size_t CurLenA, CurLenW; // we need to maintain our buffer length in both UTF-8 and wchar format.
  917. size_t BufSizeA; // end-user buffer size, <= 1024 (or increase above)
  918. float Width; // widget width
  919. float ScrollX;
  920. STB_TexteditState StbState;
  921. float CursorAnim;
  922. ImVec2 InputCursorScreenPos; // Cursor position in screen space to be used by IME callback.
  923. bool SelectedAllMouseLock;
  924. ImFont* Font;
  925. float FontSize;
  926. ImGuiTextEditState() { memset(this, 0, sizeof(*this)); }
  927. void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking
  928. bool CursorIsVisible() const { return CursorAnim <= 0.0f || fmodf(CursorAnim, 1.20f) <= 0.80f; } // Blinking
  929. bool HasSelection() const { return StbState.select_start != StbState.select_end; }
  930. void SelectAll() { StbState.select_start = 0; StbState.select_end = (int)ImStrlenW(Text); StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; }
  931. void OnKeyPressed(int key);
  932. void UpdateScrollOffset();
  933. ImVec2 CalcDisplayOffsetFromCharIdx(int i) const;
  934. // Static functions because they are used to render non-focused instances of a text input box
  935. static const char* GetTextPointerClippedA(ImFont* font, float font_size, const char* text, float width, ImVec2* out_text_size = NULL);
  936. static const ImWchar* GetTextPointerClippedW(ImFont* font, float font_size, const ImWchar* text, float width, ImVec2* out_text_size = NULL);
  937. static void RenderTextScrolledClipped(ImFont* font, float font_size, const char* text, ImVec2 pos_base, float width, float scroll_x);
  938. };
  939. // Data saved in imgui.ini file
  940. struct ImGuiIniData
  941. {
  942. char* Name;
  943. ImGuiID ID;
  944. ImVec2 Pos;
  945. ImVec2 Size;
  946. bool Collapsed;
  947. ImGuiIniData() { memset(this, 0, sizeof(*this)); }
  948. ~ImGuiIniData() { if (Name) { ImGui::MemFree(Name); Name = NULL; } }
  949. };
  950. struct ImGuiMouseCursorData
  951. {
  952. ImGuiMouseCursor Type;
  953. ImVec2 Offset;
  954. ImVec2 Size;
  955. ImVec2 TexUvMin[2];
  956. ImVec2 TexUvMax[2];
  957. };
  958. // Main state for ImGui
  959. struct ImGuiState
  960. {
  961. bool Initialized;
  962. ImGuiIO IO;
  963. ImGuiStyle Style;
  964. ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
  965. float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize()
  966. float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters.
  967. ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvForWhite
  968. float Time;
  969. int FrameCount;
  970. int FrameCountRendered;
  971. ImVector<ImGuiWindow*> Windows;
  972. ImVector<ImGuiWindow*> WindowsSortBuffer;
  973. ImGuiWindow* CurrentWindow; // Being drawn into
  974. ImVector<ImGuiWindow*> CurrentWindowStack;
  975. ImGuiWindow* FocusedWindow; // Will catch keyboard inputs
  976. ImGuiWindow* HoveredWindow; // Will catch mouse inputs
  977. ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only)
  978. ImGuiID HoveredId; // Hovered widget
  979. ImGuiID ActiveId; // Active widget
  980. ImGuiID ActiveIdPreviousFrame;
  981. bool ActiveIdIsAlive;
  982. bool ActiveIdIsJustActivated; // Set when
  983. bool ActiveIdIsFocusedOnly; // Set only by active widget. Denote focus but no active interaction.
  984. ImGuiWindow* MovedWindow; // Track the child window we clicked on to move a window. Only valid if ActiveID is the "#MOVE" identifier of a window.
  985. float SettingsDirtyTimer;
  986. ImVector<ImGuiIniData*> Settings;
  987. int DisableHideTextAfterDoubleHash;
  988. ImVector<ImGuiColMod> ColorModifiers;
  989. ImVector<ImGuiStyleMod> StyleModifiers;
  990. ImVector<ImFont*> FontStack;
  991. ImVec2 SetNextWindowPosVal;
  992. ImGuiSetCond SetNextWindowPosCond;
  993. ImVec2 SetNextWindowSizeVal;
  994. ImGuiSetCond SetNextWindowSizeCond;
  995. bool SetNextWindowCollapsedVal;
  996. ImGuiSetCond SetNextWindowCollapsedCond;
  997. bool SetNextWindowFocus;
  998. bool SetNextTreeNodeOpenedVal;
  999. ImGuiSetCond SetNextTreeNodeOpenedCond;
  1000. // Render
  1001. ImVector<ImDrawList*> RenderDrawLists[3];
  1002. // Mouse cursor
  1003. ImGuiMouseCursor MouseCursor;
  1004. ImDrawList MouseCursorDrawList; // Optional software render of mouse cursors, if io.MouseDrawCursor is set
  1005. ImGuiMouseCursorData MouseCursorData[ImGuiMouseCursor_Count_];
  1006. // Widget state
  1007. ImGuiTextEditState InputTextState;
  1008. ImGuiID ScalarAsInputTextId; // Temporary text input when CTRL+clicking on a slider, etc.
  1009. ImGuiStorage ColorEditModeStorage; // for user selection
  1010. ImGuiID ActiveComboID;
  1011. ImVec2 ActiveClickDeltaToCenter;
  1012. float DragCurrentValue; // current dragged value, always float, not rounded by end-user precision settings
  1013. ImVec2 DragLastMouseDelta;
  1014. float DragSpeedDefaultRatio; // if speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio
  1015. float DragSpeedScaleSlow;
  1016. float DragSpeedScaleFast;
  1017. float ScrollbarClickDeltaToGrabCenter; // distance between mouse and center of grab box, normalized in parent space
  1018. char Tooltip[1024];
  1019. char* PrivateClipboard; // if no custom clipboard handler is defined
  1020. // Logging
  1021. bool LogEnabled;
  1022. FILE* LogFile;
  1023. ImGuiTextBuffer* LogClipboard; // pointer so our GImGui static constructor doesn't call heap allocators.
  1024. int LogStartDepth;
  1025. int LogAutoExpandMaxDepth;
  1026. // Misc
  1027. float FramerateSecPerFrame[120]; // calculate estimate of framerate for user
  1028. int FramerateSecPerFrameIdx;
  1029. float FramerateSecPerFrameAccum;
  1030. char TempBuffer[1024*3+1]; // temporary text buffer
  1031. ImGuiState()
  1032. {
  1033. Initialized = false;
  1034. Font = NULL;
  1035. FontBaseSize = FontSize = 0.0f;
  1036. FontTexUvWhitePixel = ImVec2(0.0f, 0.0f);
  1037. Time = 0.0f;
  1038. FrameCount = 0;
  1039. FrameCountRendered = -1;
  1040. CurrentWindow = NULL;
  1041. FocusedWindow = NULL;
  1042. HoveredWindow = NULL;
  1043. HoveredRootWindow = NULL;
  1044. HoveredId = 0;
  1045. ActiveId = 0;
  1046. ActiveIdPreviousFrame = 0;
  1047. ActiveIdIsAlive = false;
  1048. ActiveIdIsJustActivated = false;
  1049. ActiveIdIsFocusedOnly = false;
  1050. MovedWindow = NULL;
  1051. SettingsDirtyTimer = 0.0f;
  1052. DisableHideTextAfterDoubleHash = 0;
  1053. SetNextWindowPosVal = ImVec2(0.0f, 0.0f);
  1054. SetNextWindowPosCond = 0;
  1055. SetNextWindowSizeVal = ImVec2(0.0f, 0.0f);
  1056. SetNextWindowSizeCond = 0;
  1057. SetNextWindowCollapsedVal = false;
  1058. SetNextWindowCollapsedCond = 0;
  1059. SetNextWindowFocus = false;
  1060. SetNextTreeNodeOpenedVal = false;
  1061. SetNextTreeNodeOpenedCond = 0;
  1062. ScalarAsInputTextId = 0;
  1063. ActiveComboID = 0;
  1064. ActiveClickDeltaToCenter = ImVec2(0.0f, 0.0f);
  1065. DragCurrentValue = 0.0f;
  1066. DragLastMouseDelta = ImVec2(0.0f, 0.0f);
  1067. DragSpeedDefaultRatio = 0.01f;
  1068. DragSpeedScaleSlow = 0.01f;
  1069. DragSpeedScaleFast = 10.0f;
  1070. ScrollbarClickDeltaToGrabCenter = 0.0f;
  1071. memset(Tooltip, 0, sizeof(Tooltip));
  1072. PrivateClipboard = NULL;
  1073. MouseCursor = ImGuiMouseCursor_Arrow;
  1074. LogEnabled = false;
  1075. LogFile = NULL;
  1076. LogClipboard = NULL;
  1077. LogStartDepth = 0;
  1078. LogAutoExpandMaxDepth = 2;
  1079. memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame));
  1080. FramerateSecPerFrameIdx = 0;
  1081. FramerateSecPerFrameAccum = 0.0f;
  1082. }
  1083. };
  1084. static ImGuiState GImDefaultState; // Internal state storage
  1085. static ImGuiState* GImGui = &GImDefaultState; // We access everything through this pointer. NB: this pointer is always assumed to be != NULL
  1086. struct ImGuiWindow
  1087. {
  1088. char* Name;
  1089. ImGuiID ID;
  1090. ImGuiWindowFlags Flags;
  1091. ImVec2 PosFloat;
  1092. ImVec2 Pos; // Position rounded-up to nearest pixel
  1093. ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
  1094. ImVec2 SizeFull; // Size when non collapsed
  1095. ImVec2 SizeContents; // Size of contents (== extents reach of the drawing cursor) from previous frame
  1096. ImGuiID MoveID; // == window->GetID("#MOVE")
  1097. float ScrollY;
  1098. float NextScrollY;
  1099. bool ScrollbarY;
  1100. bool Visible; // Set to true on Begin()
  1101. bool WasVisible;
  1102. bool Accessed; // Set to true when any widget access the current window
  1103. bool Collapsed; // Set when collapsing window to become only title-bar
  1104. bool SkipItems; // == Visible && !Collapsed
  1105. int AutoFitFrames;
  1106. bool AutoFitOnlyGrows;
  1107. int SetWindowPosAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowPos() call will succeed with this particular flag.
  1108. int SetWindowSizeAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowSize() call will succeed with this particular flag.
  1109. int SetWindowCollapsedAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowCollapsed() call will succeed with this particular flag.
  1110. ImGuiDrawContext DC; // Temporary per-window data, reset at the beginning of the frame
  1111. ImVector<ImGuiID> IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack
  1112. ImVector<ImVec4> ClipRectStack; // Scissoring / clipping rectangle. x1, y1, x2, y2.
  1113. ImRect ClippedRect; // = ClipRectStack.front() after setup in Begin()
  1114. int LastFrameDrawn;
  1115. float ItemWidthDefault;
  1116. ImGuiStorage StateStorage;
  1117. float FontWindowScale; // Scale multiplier per-window
  1118. ImDrawList* DrawList;
  1119. ImGuiWindow* RootWindow;
  1120. // Focus
  1121. int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister()
  1122. int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through)
  1123. int FocusIdxAllRequestCurrent; // Item being requested for focus
  1124. int FocusIdxTabRequestCurrent; // Tab-able item being requested for focus
  1125. 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)
  1126. int FocusIdxTabRequestNext; // "
  1127. public:
  1128. ImGuiWindow(const char* name);
  1129. ~ImGuiWindow();
  1130. ImGuiID GetID(const char* str, const char* str_end = NULL);
  1131. ImGuiID GetID(const void* ptr);
  1132. bool FocusItemRegister(bool is_active, bool tab_stop = true); // Return true if focus is requested
  1133. void FocusItemUnregister();
  1134. ImRect Rect() const { return ImRect(Pos, Pos+Size); }
  1135. float CalcFontSize() const { return GImGui->FontBaseSize * FontWindowScale; }
  1136. float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f; }
  1137. ImRect TitleBarRect() const { return ImRect(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); }
  1138. ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders) && !(Flags & ImGuiWindowFlags_ComboBox)) ? ImVec2(0,0) : GImGui->Style.WindowPadding; }
  1139. 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); }
  1140. ImU32 Color(const ImVec4& col) const { ImVec4 c = col; c.w *= GImGui->Style.Alpha; return ImGui::ColorConvertFloat4ToU32(c); }
  1141. };
  1142. static inline ImGuiWindow* GetCurrentWindow()
  1143. {
  1144. // 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)
  1145. ImGuiState& g = *GImGui;
  1146. g.CurrentWindow->Accessed = true;
  1147. return g.CurrentWindow;
  1148. }
  1149. static inline void SetCurrentWindow(ImGuiWindow* window)
  1150. {
  1151. ImGuiState& g = *GImGui;
  1152. g.CurrentWindow = window;
  1153. if (window)
  1154. g.FontSize = window->CalcFontSize();
  1155. }
  1156. static inline ImGuiWindow* GetParentWindow()
  1157. {
  1158. ImGuiState& g = *GImGui;
  1159. IM_ASSERT(g.CurrentWindowStack.size() >= 2);
  1160. return g.CurrentWindowStack[g.CurrentWindowStack.size() - 2];
  1161. }
  1162. static void SetActiveId(ImGuiID id)
  1163. {
  1164. ImGuiState& g = *GImGui;
  1165. g.ActiveId = id;
  1166. g.ActiveIdIsFocusedOnly = false;
  1167. g.ActiveIdIsJustActivated = true;
  1168. }
  1169. static void RegisterAliveId(ImGuiID id)
  1170. {
  1171. ImGuiState& g = *GImGui;
  1172. if (g.ActiveId == id)
  1173. g.ActiveIdIsAlive = true;
  1174. }
  1175. //-----------------------------------------------------------------------------
  1176. // Helper: Key->value storage
  1177. void ImGuiStorage::Clear()
  1178. {
  1179. Data.clear();
  1180. }
  1181. // std::lower_bound but without the bullshit
  1182. static ImVector<ImGuiStorage::Pair>::iterator LowerBound(ImVector<ImGuiStorage::Pair>& data, ImU32 key)
  1183. {
  1184. ImVector<ImGuiStorage::Pair>::iterator first = data.begin();
  1185. ImVector<ImGuiStorage::Pair>::iterator last = data.end();
  1186. int count = (int)(last - first);
  1187. while (count > 0)
  1188. {
  1189. int count2 = count / 2;
  1190. ImVector<ImGuiStorage::Pair>::iterator mid = first + count2;
  1191. if (mid->key < key)
  1192. {
  1193. first = ++mid;
  1194. count -= count2 + 1;
  1195. }
  1196. else
  1197. {
  1198. count = count2;
  1199. }
  1200. }
  1201. return first;
  1202. }
  1203. int ImGuiStorage::GetInt(ImU32 key, int default_val) const
  1204. {
  1205. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  1206. if (it == Data.end() || it->key != key)
  1207. return default_val;
  1208. return it->val_i;
  1209. }
  1210. float ImGuiStorage::GetFloat(ImU32 key, float default_val) const
  1211. {
  1212. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  1213. if (it == Data.end() || it->key != key)
  1214. return default_val;
  1215. return it->val_f;
  1216. }
  1217. void* ImGuiStorage::GetVoidPtr(ImGuiID key) const
  1218. {
  1219. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  1220. if (it == Data.end() || it->key != key)
  1221. return NULL;
  1222. return it->val_p;
  1223. }
  1224. // 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.
  1225. int* ImGuiStorage::GetIntRef(ImGuiID key, int default_val)
  1226. {
  1227. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1228. if (it == Data.end() || it->key != key)
  1229. it = Data.insert(it, Pair(key, default_val));
  1230. return &it->val_i;
  1231. }
  1232. float* ImGuiStorage::GetFloatRef(ImGuiID key, float default_val)
  1233. {
  1234. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1235. if (it == Data.end() || it->key != key)
  1236. it = Data.insert(it, Pair(key, default_val));
  1237. return &it->val_f;
  1238. }
  1239. void** ImGuiStorage::GetVoidPtrRef(ImGuiID key, void* default_val)
  1240. {
  1241. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1242. if (it == Data.end() || it->key != key)
  1243. it = Data.insert(it, Pair(key, default_val));
  1244. return &it->val_p;
  1245. }
  1246. // FIXME-OPT: Wasting CPU because all SetInt() are preceeded by GetInt() calls so we should have the result from lower_bound already in place.
  1247. // However we only use SetInt() on explicit user action (so that's maximum once a frame) so the optimisation isn't much needed.
  1248. void ImGuiStorage::SetInt(ImU32 key, int val)
  1249. {
  1250. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1251. if (it == Data.end() || it->key != key)
  1252. {
  1253. Data.insert(it, Pair(key, val));
  1254. return;
  1255. }
  1256. it->val_i = val;
  1257. }
  1258. void ImGuiStorage::SetFloat(ImU32 key, float val)
  1259. {
  1260. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1261. if (it == Data.end() || it->key != key)
  1262. {
  1263. Data.insert(it, Pair(key, val));
  1264. return;
  1265. }
  1266. it->val_f = val;
  1267. }
  1268. void ImGuiStorage::SetVoidPtr(ImU32 key, void* val)
  1269. {
  1270. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1271. if (it == Data.end() || it->key != key)
  1272. {
  1273. Data.insert(it, Pair(key, val));
  1274. return;
  1275. }
  1276. it->val_p = val;
  1277. }
  1278. void ImGuiStorage::SetAllInt(int v)
  1279. {
  1280. for (size_t i = 0; i < Data.size(); i++)
  1281. Data[i].val_i = v;
  1282. }
  1283. //-----------------------------------------------------------------------------
  1284. // Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
  1285. ImGuiTextFilter::ImGuiTextFilter(const char* default_filter)
  1286. {
  1287. if (default_filter)
  1288. {
  1289. ImFormatString(InputBuf, IM_ARRAYSIZE(InputBuf), "%s", default_filter);
  1290. Build();
  1291. }
  1292. else
  1293. {
  1294. InputBuf[0] = 0;
  1295. CountGrep = 0;
  1296. }
  1297. }
  1298. void ImGuiTextFilter::Draw(const char* label, float width)
  1299. {
  1300. if (width > 0.0f)
  1301. ImGui::PushItemWidth(width);
  1302. ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf));
  1303. if (width > 0.0f)
  1304. ImGui::PopItemWidth();
  1305. Build();
  1306. }
  1307. void ImGuiTextFilter::TextRange::split(char separator, ImVector<TextRange>& out)
  1308. {
  1309. out.resize(0);
  1310. const char* wb = b;
  1311. const char* we = wb;
  1312. while (we < e)
  1313. {
  1314. if (*we == separator)
  1315. {
  1316. out.push_back(TextRange(wb, we));
  1317. wb = we + 1;
  1318. }
  1319. we++;
  1320. }
  1321. if (wb != we)
  1322. out.push_back(TextRange(wb, we));
  1323. }
  1324. void ImGuiTextFilter::Build()
  1325. {
  1326. Filters.resize(0);
  1327. TextRange input_range(InputBuf, InputBuf+strlen(InputBuf));
  1328. input_range.split(',', Filters);
  1329. CountGrep = 0;
  1330. for (size_t i = 0; i != Filters.size(); i++)
  1331. {
  1332. Filters[i].trim_blanks();
  1333. if (Filters[i].empty())
  1334. continue;
  1335. if (Filters[i].front() != '-')
  1336. CountGrep += 1;
  1337. }
  1338. }
  1339. bool ImGuiTextFilter::PassFilter(const char* val) const
  1340. {
  1341. if (Filters.empty())
  1342. return true;
  1343. if (val == NULL)
  1344. val = "";
  1345. for (size_t i = 0; i != Filters.size(); i++)
  1346. {
  1347. const TextRange& f = Filters[i];
  1348. if (f.empty())
  1349. continue;
  1350. if (f.front() == '-')
  1351. {
  1352. // Subtract
  1353. if (ImStristr(val, f.begin()+1, f.end()) != NULL)
  1354. return false;
  1355. }
  1356. else
  1357. {
  1358. // Grep
  1359. if (ImStristr(val, f.begin(), f.end()) != NULL)
  1360. return true;
  1361. }
  1362. }
  1363. // Implicit * grep
  1364. if (CountGrep == 0)
  1365. return true;
  1366. return false;
  1367. }
  1368. //-----------------------------------------------------------------------------
  1369. // On some platform vsnprintf() takes va_list by reference and modifies it.
  1370. // va_copy is the 'correct' way to copy a va_list but Visual Studio prior to 2013 doesn't have it.
  1371. #ifndef va_copy
  1372. #define va_copy(dest, src) (dest = src)
  1373. #endif
  1374. // Helper: Text buffer for logging/accumulating text
  1375. void ImGuiTextBuffer::appendv(const char* fmt, va_list args)
  1376. {
  1377. va_list args_copy;
  1378. va_copy(args_copy, args);
  1379. int len = vsnprintf(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass.
  1380. if (len <= 0)
  1381. return;
  1382. const size_t write_off = Buf.size();
  1383. const size_t needed_sz = write_off + (size_t)len;
  1384. if (write_off + (size_t)len >= Buf.capacity())
  1385. {
  1386. const size_t double_capacity = Buf.capacity() * 2;
  1387. Buf.reserve(needed_sz > double_capacity ? needed_sz : double_capacity);
  1388. }
  1389. Buf.resize(needed_sz);
  1390. ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args_copy);
  1391. }
  1392. void ImGuiTextBuffer::append(const char* fmt, ...)
  1393. {
  1394. va_list args;
  1395. va_start(args, fmt);
  1396. appendv(fmt, args);
  1397. va_end(args);
  1398. }
  1399. //-----------------------------------------------------------------------------
  1400. ImGuiWindow::ImGuiWindow(const char* name)
  1401. {
  1402. Name = ImStrdup(name);
  1403. ID = ImHash(name, 0);
  1404. IDStack.push_back(ID);
  1405. MoveID = GetID("#MOVE");
  1406. Flags = 0;
  1407. PosFloat = Pos = ImVec2(0.0f, 0.0f);
  1408. Size = SizeFull = ImVec2(0.0f, 0.0f);
  1409. SizeContents = ImVec2(0.0f, 0.0f);
  1410. ScrollY = 0.0f;
  1411. NextScrollY = 0.0f;
  1412. ScrollbarY = false;
  1413. Visible = WasVisible = false;
  1414. Accessed = false;
  1415. Collapsed = false;
  1416. SkipItems = false;
  1417. AutoFitFrames = -1;
  1418. AutoFitOnlyGrows = false;
  1419. SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCond_Always | ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver;
  1420. LastFrameDrawn = -1;
  1421. ItemWidthDefault = 0.0f;
  1422. FontWindowScale = 1.0f;
  1423. DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
  1424. new(DrawList) ImDrawList();
  1425. RootWindow = NULL;
  1426. FocusIdxAllCounter = FocusIdxTabCounter = -1;
  1427. FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX;
  1428. FocusIdxAllRequestNext = FocusIdxTabRequestNext = IM_INT_MAX;
  1429. }
  1430. ImGuiWindow::~ImGuiWindow()
  1431. {
  1432. DrawList->~ImDrawList();
  1433. ImGui::MemFree(DrawList);
  1434. DrawList = NULL;
  1435. ImGui::MemFree(Name);
  1436. Name = NULL;
  1437. }
  1438. ImGuiID ImGuiWindow::GetID(const char* str, const char* str_end)
  1439. {
  1440. ImGuiID seed = IDStack.back();
  1441. const ImGuiID id = ImHash(str, str_end ? str_end - str : 0, seed);
  1442. RegisterAliveId(id);
  1443. return id;
  1444. }
  1445. ImGuiID ImGuiWindow::GetID(const void* ptr)
  1446. {
  1447. ImGuiID seed = IDStack.back();
  1448. const ImGuiID id = ImHash(&ptr, sizeof(void*), seed);
  1449. RegisterAliveId(id);
  1450. return id;
  1451. }
  1452. bool ImGuiWindow::FocusItemRegister(bool is_active, bool tab_stop)
  1453. {
  1454. ImGuiState& g = *GImGui;
  1455. ImGuiWindow* window = GetCurrentWindow();
  1456. const bool allow_keyboard_focus = window->DC.AllowKeyboardFocus.back();
  1457. FocusIdxAllCounter++;
  1458. if (allow_keyboard_focus)
  1459. FocusIdxTabCounter++;
  1460. // Process keyboard input at this point: TAB, Shift-TAB switch focus
  1461. // We can always TAB out of a widget that doesn't allow tabbing in.
  1462. if (tab_stop && FocusIdxAllRequestNext == IM_INT_MAX && FocusIdxTabRequestNext == IM_INT_MAX && is_active && IsKeyPressedMap(ImGuiKey_Tab))
  1463. {
  1464. // Modulo on index will be applied at the end of frame once we've got the total counter of items.
  1465. FocusIdxTabRequestNext = FocusIdxTabCounter + (g.IO.KeyShift ? (allow_keyboard_focus ? -1 : 0) : +1);
  1466. }
  1467. if (FocusIdxAllCounter == FocusIdxAllRequestCurrent)
  1468. return true;
  1469. if (allow_keyboard_focus)
  1470. if (FocusIdxTabCounter == FocusIdxTabRequestCurrent)
  1471. return true;
  1472. return false;
  1473. }
  1474. void ImGuiWindow::FocusItemUnregister()
  1475. {
  1476. FocusIdxAllCounter--;
  1477. FocusIdxTabCounter--;
  1478. }
  1479. static inline void AddDrawListToRenderList(ImVector<ImDrawList*>& out_render_list, ImDrawList* draw_list)
  1480. {
  1481. if (!draw_list->commands.empty() && !draw_list->vtx_buffer.empty())
  1482. {
  1483. if (draw_list->commands.back().vtx_count == 0)
  1484. draw_list->commands.pop_back();
  1485. out_render_list.push_back(draw_list);
  1486. GImGui->IO.MetricsRenderVertices += (int)draw_list->vtx_buffer.size();
  1487. }
  1488. }
  1489. static void AddWindowToRenderList(ImVector<ImDrawList*>& out_render_list, ImGuiWindow* window)
  1490. {
  1491. AddDrawListToRenderList(out_render_list, window->DrawList);
  1492. for (size_t i = 0; i < window->DC.ChildWindows.size(); i++)
  1493. {
  1494. ImGuiWindow* child = window->DC.ChildWindows[i];
  1495. if (child->Visible) // clipped children may have been marked not Visible
  1496. AddWindowToRenderList(out_render_list, child);
  1497. }
  1498. }
  1499. //-----------------------------------------------------------------------------
  1500. void* ImGui::MemAlloc(size_t sz)
  1501. {
  1502. return GImGui->IO.MemAllocFn(sz);
  1503. }
  1504. void ImGui::MemFree(void* ptr)
  1505. {
  1506. return GImGui->IO.MemFreeFn(ptr);
  1507. }
  1508. static ImGuiIniData* FindWindowSettings(const char* name)
  1509. {
  1510. ImGuiState& g = *GImGui;
  1511. ImGuiID id = ImHash(name, 0);
  1512. for (size_t i = 0; i != g.Settings.size(); i++)
  1513. {
  1514. ImGuiIniData* ini = g.Settings[i];
  1515. if (ini->ID == id)
  1516. return ini;
  1517. }
  1518. return NULL;
  1519. }
  1520. static ImGuiIniData* AddWindowSettings(const char* name)
  1521. {
  1522. ImGuiIniData* ini = (ImGuiIniData*)ImGui::MemAlloc(sizeof(ImGuiIniData));
  1523. new(ini) ImGuiIniData();
  1524. ini->Name = ImStrdup(name);
  1525. ini->ID = ImHash(name, 0);
  1526. ini->Collapsed = false;
  1527. ini->Pos = ImVec2(FLT_MAX,FLT_MAX);
  1528. ini->Size = ImVec2(0,0);
  1529. GImGui->Settings.push_back(ini);
  1530. return ini;
  1531. }
  1532. // Zero-tolerance, poor-man .ini parsing
  1533. // FIXME: Write something less rubbish
  1534. static void LoadSettings()
  1535. {
  1536. ImGuiState& g = *GImGui;
  1537. const char* filename = g.IO.IniFilename;
  1538. if (!filename)
  1539. return;
  1540. char* file_data;
  1541. size_t file_size;
  1542. if (!ImLoadFileToMemory(filename, "rb", (void**)&file_data, &file_size, 1))
  1543. return;
  1544. ImGuiIniData* settings = NULL;
  1545. const char* buf_end = file_data + file_size;
  1546. for (const char* line_start = file_data; line_start < buf_end; )
  1547. {
  1548. const char* line_end = line_start;
  1549. while (line_end < buf_end && *line_end != '\n' && *line_end != '\r')
  1550. line_end++;
  1551. if (line_start[0] == '[' && line_end > line_start && line_end[-1] == ']')
  1552. {
  1553. char name[64];
  1554. ImFormatString(name, IM_ARRAYSIZE(name), "%.*s", line_end-line_start-2, line_start+1);
  1555. settings = FindWindowSettings(name);
  1556. if (!settings)
  1557. settings = AddWindowSettings(name);
  1558. }
  1559. else if (settings)
  1560. {
  1561. float x, y;
  1562. int i;
  1563. if (sscanf(line_start, "Pos=%f,%f", &x, &y) == 2)
  1564. settings->Pos = ImVec2(x, y);
  1565. else if (sscanf(line_start, "Size=%f,%f", &x, &y) == 2)
  1566. settings->Size = ImMax(ImVec2(x, y), g.Style.WindowMinSize);
  1567. else if (sscanf(line_start, "Collapsed=%d", &i) == 1)
  1568. settings->Collapsed = (i != 0);
  1569. }
  1570. line_start = line_end+1;
  1571. }
  1572. ImGui::MemFree(file_data);
  1573. }
  1574. static void SaveSettings()
  1575. {
  1576. ImGuiState& g = *GImGui;
  1577. const char* filename = g.IO.IniFilename;
  1578. if (!filename)
  1579. return;
  1580. // Gather data from windows that were active during this session
  1581. for (size_t i = 0; i != g.Windows.size(); i++)
  1582. {
  1583. ImGuiWindow* window = g.Windows[i];
  1584. if (window->Flags & ImGuiWindowFlags_NoSavedSettings)
  1585. continue;
  1586. ImGuiIniData* settings = FindWindowSettings(window->Name);
  1587. settings->Pos = window->Pos;
  1588. settings->Size = window->SizeFull;
  1589. settings->Collapsed = window->Collapsed;
  1590. }
  1591. // Write .ini file
  1592. // If a window wasn't opened in this session we preserve its settings
  1593. FILE* f = fopen(filename, "wt");
  1594. if (!f)
  1595. return;
  1596. for (size_t i = 0; i != g.Settings.size(); i++)
  1597. {
  1598. const ImGuiIniData* settings = g.Settings[i];
  1599. if (settings->Pos.x == FLT_MAX)
  1600. continue;
  1601. const char* name = settings->Name;
  1602. if (const char* p = strstr(name, "###")) // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID()
  1603. name = p;
  1604. fprintf(f, "[%s]\n", name);
  1605. fprintf(f, "Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y);
  1606. fprintf(f, "Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y);
  1607. fprintf(f, "Collapsed=%d\n", settings->Collapsed);
  1608. fprintf(f, "\n");
  1609. }
  1610. fclose(f);
  1611. }
  1612. static void MarkSettingsDirty()
  1613. {
  1614. ImGuiState& g = *GImGui;
  1615. if (g.SettingsDirtyTimer <= 0.0f)
  1616. g.SettingsDirtyTimer = g.IO.IniSavingRate;
  1617. }
  1618. const char* ImGui::GetVersion()
  1619. {
  1620. return IMGUI_VERSION;
  1621. }
  1622. // Internal state access - if you want to share ImGui state between modules (e.g. DLL) or allocate it yourself
  1623. // 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
  1624. void* ImGui::GetInternalState()
  1625. {
  1626. return GImGui;
  1627. }
  1628. size_t ImGui::GetInternalStateSize()
  1629. {
  1630. return sizeof(ImGuiState);
  1631. }
  1632. void ImGui::SetInternalState(void* state, bool construct)
  1633. {
  1634. if (construct)
  1635. new (state) ImGuiState();
  1636. GImGui = (ImGuiState*)state;
  1637. }
  1638. ImGuiIO& ImGui::GetIO()
  1639. {
  1640. return GImGui->IO;
  1641. }
  1642. ImGuiStyle& ImGui::GetStyle()
  1643. {
  1644. return GImGui->Style;
  1645. }
  1646. void ImGui::NewFrame()
  1647. {
  1648. ImGuiState& g = *GImGui;
  1649. // Check user data
  1650. IM_ASSERT(g.IO.DeltaTime > 0.0f);
  1651. IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f);
  1652. IM_ASSERT(g.IO.RenderDrawListsFn != NULL); // Must be implemented
  1653. IM_ASSERT(g.IO.Fonts->Fonts.size() > 0); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
  1654. IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded()); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
  1655. if (!g.Initialized)
  1656. {
  1657. // Initialize on first frame
  1658. g.LogClipboard = (ImGuiTextBuffer*)ImGui::MemAlloc(sizeof(ImGuiTextBuffer));
  1659. new(g.LogClipboard) ImGuiTextBuffer();
  1660. IM_ASSERT(g.Settings.empty());
  1661. LoadSettings();
  1662. g.Initialized = true;
  1663. }
  1664. SetFont(g.IO.Fonts->Fonts[0]);
  1665. g.Time += g.IO.DeltaTime;
  1666. g.FrameCount += 1;
  1667. g.Tooltip[0] = '\0';
  1668. // Update inputs state
  1669. if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
  1670. g.IO.MousePos = ImVec2(-9999.0f, -9999.0f);
  1671. 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
  1672. g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
  1673. else
  1674. g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
  1675. g.IO.MousePosPrev = g.IO.MousePos;
  1676. for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
  1677. {
  1678. 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;
  1679. g.IO.MouseClicked[i] = (g.IO.MouseDownTime[i] == 0.0f);
  1680. g.IO.MouseDoubleClicked[i] = false;
  1681. if (g.IO.MouseClicked[i])
  1682. {
  1683. if (g.Time - g.IO.MouseClickedTime[i] < g.IO.MouseDoubleClickTime)
  1684. {
  1685. if (ImLengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist)
  1686. g.IO.MouseDoubleClicked[i] = true;
  1687. g.IO.MouseClickedTime[i] = -FLT_MAX; // so the third click isn't turned into a double-click
  1688. }
  1689. else
  1690. {
  1691. g.IO.MouseClickedTime[i] = g.Time;
  1692. }
  1693. g.IO.MouseClickedPos[i] = g.IO.MousePos;
  1694. g.IO.MouseDragMaxDistanceSqr[i] = 0.0f;
  1695. }
  1696. else if (g.IO.MouseDown[i])
  1697. {
  1698. g.IO.MouseDragMaxDistanceSqr[i] = ImMax(g.IO.MouseDragMaxDistanceSqr[i], ImLengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]));
  1699. }
  1700. }
  1701. for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
  1702. 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;
  1703. // Calculate frame-rate for the user, as a purely luxurious feature
  1704. g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx];
  1705. g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx] = g.IO.DeltaTime;
  1706. g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % IM_ARRAYSIZE(g.FramerateSecPerFrame);
  1707. g.IO.Framerate = 1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame));
  1708. // Clear reference to active widget if the widget isn't alive anymore
  1709. g.HoveredId = 0;
  1710. if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0)
  1711. SetActiveId(0);
  1712. g.ActiveIdPreviousFrame = g.ActiveId;
  1713. g.ActiveIdIsAlive = false;
  1714. g.ActiveIdIsJustActivated = false;
  1715. if (!g.ActiveId)
  1716. g.MovedWindow = NULL;
  1717. // Delay saving settings so we don't spam disk too much
  1718. if (g.SettingsDirtyTimer > 0.0f)
  1719. {
  1720. g.SettingsDirtyTimer -= g.IO.DeltaTime;
  1721. if (g.SettingsDirtyTimer <= 0.0f)
  1722. SaveSettings();
  1723. }
  1724. // Find the window we are hovering. Child windows can extend beyond the limit of their parent so we need to derive HoveredRootWindow from HoveredWindow
  1725. g.HoveredWindow = FindHoveredWindow(g.IO.MousePos, false);
  1726. if (g.HoveredWindow && (g.HoveredWindow->Flags & ImGuiWindowFlags_ChildWindow))
  1727. g.HoveredRootWindow = g.HoveredWindow->RootWindow;
  1728. else
  1729. g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true);
  1730. // Are we using inputs? Tell user so they can capture/discard the inputs away from the rest of their application.
  1731. // When clicking outside of a window we assume the click is owned by the application and won't request capture.
  1732. int mouse_earliest_button_down = -1;
  1733. for (int i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
  1734. {
  1735. if (g.IO.MouseClicked[i])
  1736. g.IO.MouseDownOwned[i] = (g.HoveredWindow != NULL);
  1737. if (g.IO.MouseDown[i])
  1738. if (mouse_earliest_button_down == -1 || g.IO.MouseClickedTime[mouse_earliest_button_down] > g.IO.MouseClickedTime[i])
  1739. mouse_earliest_button_down = i;
  1740. }
  1741. bool mouse_owned_by_application = mouse_earliest_button_down != -1 && !g.IO.MouseDownOwned[mouse_earliest_button_down];
  1742. g.IO.WantCaptureMouse = (!mouse_owned_by_application && g.HoveredWindow != NULL) || (g.ActiveId != 0);
  1743. g.IO.WantCaptureKeyboard = (g.ActiveId != 0);
  1744. g.MouseCursor = ImGuiMouseCursor_Arrow;
  1745. // If mouse was first clicked outside of ImGui bounds we also cancel out hovering.
  1746. if (mouse_owned_by_application)
  1747. g.HoveredWindow = g.HoveredRootWindow = NULL;
  1748. // Scale & Scrolling
  1749. if (g.HoveredWindow && g.IO.MouseWheel != 0.0f)
  1750. {
  1751. ImGuiWindow* window = g.HoveredWindow;
  1752. if (g.IO.KeyCtrl)
  1753. {
  1754. if (g.IO.FontAllowUserScaling)
  1755. {
  1756. // Zoom / Scale window
  1757. float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
  1758. float scale = new_font_scale / window->FontWindowScale;
  1759. window->FontWindowScale = new_font_scale;
  1760. const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
  1761. window->Pos += offset;
  1762. window->PosFloat += offset;
  1763. window->Size *= scale;
  1764. window->SizeFull *= scale;
  1765. }
  1766. }
  1767. else
  1768. {
  1769. // Scroll
  1770. if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse))
  1771. {
  1772. const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5;
  1773. window->NextScrollY -= g.IO.MouseWheel * window->CalcFontSize() * scroll_lines;
  1774. }
  1775. }
  1776. }
  1777. // Pressing TAB activate widget focus
  1778. // 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.
  1779. if (g.ActiveId == 0 && g.FocusedWindow != NULL && g.FocusedWindow->Visible && IsKeyPressedMap(ImGuiKey_Tab, false))
  1780. {
  1781. g.FocusedWindow->FocusIdxTabRequestNext = 0;
  1782. }
  1783. // Mark all windows as not visible
  1784. for (size_t i = 0; i != g.Windows.size(); i++)
  1785. {
  1786. ImGuiWindow* window = g.Windows[i];
  1787. window->WasVisible = window->Visible;
  1788. window->Visible = false;
  1789. window->Accessed = false;
  1790. }
  1791. // No window should be open at the beginning of the frame.
  1792. // But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear.
  1793. g.CurrentWindowStack.resize(0);
  1794. // Create implicit window - we will only render it if the user has added something to it.
  1795. ImGui::SetNextWindowSize(ImVec2(400,400), ImGuiSetCond_FirstUseEver);
  1796. ImGui::Begin("Debug");
  1797. }
  1798. // NB: behavior of ImGui after Shutdown() is not tested/guaranteed at the moment. This function is merely here to free heap allocations.
  1799. void ImGui::Shutdown()
  1800. {
  1801. ImGuiState& g = *GImGui;
  1802. if (!g.Initialized)
  1803. return;
  1804. SaveSettings();
  1805. for (size_t i = 0; i < g.Windows.size(); i++)
  1806. {
  1807. g.Windows[i]->~ImGuiWindow();
  1808. ImGui::MemFree(g.Windows[i]);
  1809. }
  1810. g.Windows.clear();
  1811. g.WindowsSortBuffer.clear();
  1812. g.CurrentWindowStack.clear();
  1813. g.FocusedWindow = NULL;
  1814. g.HoveredWindow = NULL;
  1815. g.HoveredRootWindow = NULL;
  1816. for (size_t i = 0; i < g.Settings.size(); i++)
  1817. {
  1818. g.Settings[i]->~ImGuiIniData();
  1819. ImGui::MemFree(g.Settings[i]);
  1820. }
  1821. g.Settings.clear();
  1822. g.ColorModifiers.clear();
  1823. g.StyleModifiers.clear();
  1824. g.FontStack.clear();
  1825. for (size_t i = 0; i < IM_ARRAYSIZE(g.RenderDrawLists); i++)
  1826. g.RenderDrawLists[i].clear();
  1827. g.MouseCursorDrawList.ClearFreeMemory();
  1828. g.ColorEditModeStorage.Clear();
  1829. if (g.PrivateClipboard)
  1830. {
  1831. ImGui::MemFree(g.PrivateClipboard);
  1832. g.PrivateClipboard = NULL;
  1833. }
  1834. if (g.LogFile && g.LogFile != stdout)
  1835. {
  1836. fclose(g.LogFile);
  1837. g.LogFile = NULL;
  1838. }
  1839. if (g.LogClipboard)
  1840. {
  1841. g.LogClipboard->~ImGuiTextBuffer();
  1842. ImGui::MemFree(g.LogClipboard);
  1843. }
  1844. g.IO.Fonts->Clear();
  1845. g.Initialized = false;
  1846. }
  1847. // FIXME: Add a more explicit sort order in the window structure.
  1848. static int ChildWindowComparer(const void* lhs, const void* rhs)
  1849. {
  1850. const ImGuiWindow* a = *(const ImGuiWindow**)lhs;
  1851. const ImGuiWindow* b = *(const ImGuiWindow**)rhs;
  1852. if (int d = (a->Flags & ImGuiWindowFlags_Popup) - (b->Flags & ImGuiWindowFlags_Popup))
  1853. return d;
  1854. if (int d = (a->Flags & ImGuiWindowFlags_Tooltip) - (b->Flags & ImGuiWindowFlags_Tooltip))
  1855. return d;
  1856. if (int d = (a->Flags & ImGuiWindowFlags_ComboBox) - (b->Flags & ImGuiWindowFlags_ComboBox))
  1857. return d;
  1858. return 0;
  1859. }
  1860. static void AddWindowToSortedBuffer(ImVector<ImGuiWindow*>& out_sorted_windows, ImGuiWindow* window)
  1861. {
  1862. out_sorted_windows.push_back(window);
  1863. if (window->Visible)
  1864. {
  1865. const size_t count = window->DC.ChildWindows.size();
  1866. if (count > 1)
  1867. qsort(window->DC.ChildWindows.begin(), count, sizeof(ImGuiWindow*), ChildWindowComparer);
  1868. for (size_t i = 0; i < count; i++)
  1869. {
  1870. ImGuiWindow* child = window->DC.ChildWindows[i];
  1871. if (child->Visible)
  1872. AddWindowToSortedBuffer(out_sorted_windows, child);
  1873. }
  1874. }
  1875. }
  1876. static void PushClipRect(const ImVec4& clip_rect, bool clipped = true)
  1877. {
  1878. ImGuiWindow* window = GetCurrentWindow();
  1879. ImVec4 cr = clip_rect;
  1880. if (clipped && !window->ClipRectStack.empty())
  1881. {
  1882. // Clip with existing clip rect
  1883. const ImVec4 cur_cr = window->ClipRectStack.back();
  1884. 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));
  1885. }
  1886. cr.z = ImMax(cr.x, cr.z);
  1887. cr.w = ImMax(cr.y, cr.w);
  1888. IM_ASSERT(cr.x <= cr.z && cr.y <= cr.w);
  1889. window->ClipRectStack.push_back(cr);
  1890. window->DrawList->PushClipRect(cr);
  1891. }
  1892. static void PopClipRect()
  1893. {
  1894. ImGuiWindow* window = GetCurrentWindow();
  1895. window->ClipRectStack.pop_back();
  1896. window->DrawList->PopClipRect();
  1897. }
  1898. void ImGui::Render()
  1899. {
  1900. ImGuiState& g = *GImGui;
  1901. IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
  1902. const bool first_render_of_the_frame = (g.FrameCountRendered != g.FrameCount);
  1903. g.FrameCountRendered = g.FrameCount;
  1904. if (first_render_of_the_frame)
  1905. {
  1906. // Hide implicit window if it hasn't been used
  1907. IM_ASSERT(g.CurrentWindowStack.size() == 1); // Mismatched Begin/End
  1908. if (g.CurrentWindow && !g.CurrentWindow->Accessed)
  1909. g.CurrentWindow->Visible = false;
  1910. ImGui::End();
  1911. if (g.ActiveId == 0 && g.HoveredId == 0 && g.IO.MouseClicked[0])
  1912. {
  1913. if (g.HoveredRootWindow != NULL)
  1914. {
  1915. // Select window for move/focus when we're done with all our widgets (we use the root window ID here)
  1916. IM_ASSERT(g.MovedWindow == NULL);
  1917. g.MovedWindow = g.HoveredWindow;
  1918. SetActiveId(g.HoveredRootWindow->MoveID);
  1919. }
  1920. else if (g.FocusedWindow != NULL)
  1921. {
  1922. // Clicking on void disable focus
  1923. FocusWindow(NULL);
  1924. }
  1925. }
  1926. // Sort the window list so that all child windows are after their parent
  1927. // We cannot do that on FocusWindow() because childs may not exist yet
  1928. g.WindowsSortBuffer.resize(0);
  1929. g.WindowsSortBuffer.reserve(g.Windows.size());
  1930. for (size_t i = 0; i != g.Windows.size(); i++)
  1931. {
  1932. ImGuiWindow* window = g.Windows[i];
  1933. if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is visible its parent will add it
  1934. if (window->Visible)
  1935. continue;
  1936. AddWindowToSortedBuffer(g.WindowsSortBuffer, window);
  1937. }
  1938. IM_ASSERT(g.Windows.size() == g.WindowsSortBuffer.size()); // we done something wrong
  1939. g.Windows.swap(g.WindowsSortBuffer);
  1940. // Clear data for next frame
  1941. g.IO.MouseWheel = 0.0f;
  1942. memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
  1943. }
  1944. // Skip render altogether if alpha is 0.0
  1945. // Note that vertex buffers have been created, so it is best practice that you don't call Begin/End in the first place.
  1946. if (g.Style.Alpha > 0.0f)
  1947. {
  1948. // Render tooltip
  1949. if (g.Tooltip[0])
  1950. {
  1951. // Use a dummy window to render the tooltip
  1952. ImGui::BeginTooltip();
  1953. ImGui::TextUnformatted(g.Tooltip);
  1954. ImGui::EndTooltip();
  1955. }
  1956. // Gather windows to render
  1957. g.IO.MetricsRenderVertices = 0;
  1958. for (size_t i = 0; i < IM_ARRAYSIZE(g.RenderDrawLists); i++)
  1959. g.RenderDrawLists[i].resize(0);
  1960. for (size_t i = 0; i != g.Windows.size(); i++)
  1961. {
  1962. ImGuiWindow* window = g.Windows[i];
  1963. if (window->Visible && (window->Flags & (ImGuiWindowFlags_ChildWindow)) == 0)
  1964. {
  1965. // FIXME: Generalize this with a proper layering system so we can stack.
  1966. if (window->Flags & ImGuiWindowFlags_Popup)
  1967. AddWindowToRenderList(g.RenderDrawLists[1], window);
  1968. else if (window->Flags & ImGuiWindowFlags_Tooltip)
  1969. AddWindowToRenderList(g.RenderDrawLists[2], window);
  1970. else
  1971. AddWindowToRenderList(g.RenderDrawLists[0], window);
  1972. }
  1973. }
  1974. // Flatten layers
  1975. size_t n = g.RenderDrawLists[0].size();
  1976. size_t flattened_size = n;
  1977. for (size_t i = 1; i < IM_ARRAYSIZE(g.RenderDrawLists); i++)
  1978. flattened_size += g.RenderDrawLists[i].size();
  1979. g.RenderDrawLists[0].resize(flattened_size);
  1980. for (size_t i = 1; i < IM_ARRAYSIZE(g.RenderDrawLists); i++)
  1981. {
  1982. ImVector<ImDrawList*>& layer = g.RenderDrawLists[i];
  1983. if (!layer.empty())
  1984. {
  1985. memcpy(&g.RenderDrawLists[0][n], &layer[0], layer.size() * sizeof(ImDrawList*));
  1986. n += layer.size();
  1987. }
  1988. }
  1989. if (g.IO.MouseDrawCursor)
  1990. {
  1991. const ImGuiMouseCursorData& cursor_data = g.MouseCursorData[g.MouseCursor];
  1992. const ImVec2 pos = g.IO.MousePos - cursor_data.Offset;
  1993. const ImVec2 size = cursor_data.Size;
  1994. const ImTextureID tex_id = g.IO.Fonts->TexID;
  1995. g.MouseCursorDrawList.Clear();
  1996. g.MouseCursorDrawList.PushTextureID(tex_id);
  1997. g.MouseCursorDrawList.AddImage(tex_id, pos+ImVec2(1,0), pos+ImVec2(1,0) + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], 0x30000000); // Shadow
  1998. g.MouseCursorDrawList.AddImage(tex_id, pos+ImVec2(2,0), pos+ImVec2(2,0) + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], 0x30000000); // Shadow
  1999. g.MouseCursorDrawList.AddImage(tex_id, pos, pos + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], 0xFF000000); // Black border
  2000. g.MouseCursorDrawList.AddImage(tex_id, pos, pos + size, cursor_data.TexUvMin[0], cursor_data.TexUvMax[0], 0xFFFFFFFF); // White fill
  2001. g.MouseCursorDrawList.PopTextureID();
  2002. AddDrawListToRenderList(g.RenderDrawLists[0], &g.MouseCursorDrawList);
  2003. }
  2004. // Render
  2005. if (!g.RenderDrawLists[0].empty())
  2006. g.IO.RenderDrawListsFn(&g.RenderDrawLists[0][0], (int)g.RenderDrawLists[0].size());
  2007. }
  2008. }
  2009. // Find the optional ## from which we stop displaying text.
  2010. static const char* FindTextDisplayEnd(const char* text, const char* text_end = NULL)
  2011. {
  2012. const char* text_display_end = text;
  2013. if (!text_end)
  2014. text_end = (const char*)-1;
  2015. ImGuiState& g = *GImGui;
  2016. if (g.DisableHideTextAfterDoubleHash > 0)
  2017. {
  2018. while (text_display_end < text_end && *text_display_end != '\0')
  2019. text_display_end++;
  2020. }
  2021. else
  2022. {
  2023. while (text_display_end < text_end && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#'))
  2024. text_display_end++;
  2025. }
  2026. return text_display_end;
  2027. }
  2028. // Pass text data straight to log (without being displayed)
  2029. void ImGui::LogText(const char* fmt, ...)
  2030. {
  2031. ImGuiState& g = *GImGui;
  2032. if (!g.LogEnabled)
  2033. return;
  2034. va_list args;
  2035. va_start(args, fmt);
  2036. if (g.LogFile)
  2037. {
  2038. vfprintf(g.LogFile, fmt, args);
  2039. }
  2040. else
  2041. {
  2042. g.LogClipboard->appendv(fmt, args);
  2043. }
  2044. va_end(args);
  2045. }
  2046. // Internal version that takes a position to decide on newline placement and pad items according to their depth.
  2047. // We split text into individual lines to add current tree level padding
  2048. static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end)
  2049. {
  2050. ImGuiState& g = *GImGui;
  2051. ImGuiWindow* window = GetCurrentWindow();
  2052. if (!text_end)
  2053. text_end = FindTextDisplayEnd(text, text_end);
  2054. const bool log_new_line = ref_pos.y > window->DC.LogLinePosY+1;
  2055. window->DC.LogLinePosY = ref_pos.y;
  2056. const char* text_remaining = text;
  2057. if (g.LogStartDepth > window->DC.TreeDepth) // Re-adjust padding if we have popped out of our starting depth
  2058. g.LogStartDepth = window->DC.TreeDepth;
  2059. const int tree_depth = (window->DC.TreeDepth - g.LogStartDepth);
  2060. for (;;)
  2061. {
  2062. // Split the string. Each new line (after a '\n') is followed by spacing corresponding to the current depth of our log entry.
  2063. const char* line_end = text_remaining;
  2064. while (line_end < text_end)
  2065. if (*line_end == '\n')
  2066. break;
  2067. else
  2068. line_end++;
  2069. if (line_end >= text_end)
  2070. line_end = NULL;
  2071. const bool is_first_line = (text == text_remaining);
  2072. bool is_last_line = false;
  2073. if (line_end == NULL)
  2074. {
  2075. is_last_line = true;
  2076. line_end = text_end;
  2077. }
  2078. if (line_end != NULL && !(is_last_line && (line_end - text_remaining)==0))
  2079. {
  2080. const int char_count = (int)(line_end - text_remaining);
  2081. if (log_new_line || !is_first_line)
  2082. ImGui::LogText(STR_NEWLINE "%*s%.*s", tree_depth*4, "", char_count, text_remaining);
  2083. else
  2084. ImGui::LogText(" %.*s", char_count, text_remaining);
  2085. }
  2086. if (is_last_line)
  2087. break;
  2088. text_remaining = line_end + 1;
  2089. }
  2090. }
  2091. static float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
  2092. {
  2093. if (wrap_pos_x < 0.0f)
  2094. return 0.0f;
  2095. ImGuiWindow* window = GetCurrentWindow();
  2096. if (wrap_pos_x == 0.0f)
  2097. wrap_pos_x = ImGui::GetContentRegionMax().x;
  2098. if (wrap_pos_x > 0.0f)
  2099. wrap_pos_x += window->Pos.x; // wrap_pos_x is provided is window local space
  2100. const float wrap_width = wrap_pos_x > 0.0f ? ImMax(wrap_pos_x - pos.x, 0.00001f) : 0.0f;
  2101. return wrap_width;
  2102. }
  2103. // Internal ImGui functions to render text
  2104. // RenderText***() functions calls ImDrawList::AddText() calls ImBitmapFont::RenderText()
  2105. static void RenderText(ImVec2 pos, const char* text, const char* text_end, bool hide_text_after_hash)
  2106. {
  2107. ImGuiState& g = *GImGui;
  2108. ImGuiWindow* window = GetCurrentWindow();
  2109. // Hide anything after a '##' string
  2110. const char* text_display_end;
  2111. if (hide_text_after_hash)
  2112. {
  2113. text_display_end = FindTextDisplayEnd(text, text_end);
  2114. }
  2115. else
  2116. {
  2117. if (!text_end)
  2118. text_end = text + strlen(text); // FIXME-OPT
  2119. text_display_end = text_end;
  2120. }
  2121. const int text_len = (int)(text_display_end - text);
  2122. if (text_len > 0)
  2123. {
  2124. // Render
  2125. window->DrawList->AddText(g.Font, g.FontSize, pos, window->Color(ImGuiCol_Text), text, text_display_end);
  2126. // Log as text
  2127. if (g.LogEnabled)
  2128. LogText(pos, text, text_display_end);
  2129. }
  2130. }
  2131. static void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width)
  2132. {
  2133. ImGuiState& g = *GImGui;
  2134. ImGuiWindow* window = GetCurrentWindow();
  2135. if (!text_end)
  2136. text_end = text + strlen(text); // FIXME-OPT
  2137. const int text_len = (int)(text_end - text);
  2138. if (text_len > 0)
  2139. {
  2140. // Render
  2141. window->DrawList->AddText(g.Font, g.FontSize, pos, window->Color(ImGuiCol_Text), text, text_end, wrap_width);
  2142. // Log as text
  2143. if (g.LogEnabled)
  2144. LogText(pos, text, text_end);
  2145. }
  2146. }
  2147. static void RenderTextClipped(ImVec2 pos, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& clip_max)
  2148. {
  2149. ImGuiState& g = *GImGui;
  2150. ImGuiWindow* window = GetCurrentWindow();
  2151. // Hide anything after a '##' string
  2152. const char* text_display_end = FindTextDisplayEnd(text, text_end);
  2153. const int text_len = (int)(text_display_end - text);
  2154. if (text_len > 0)
  2155. {
  2156. const ImVec2 text_size = text_size_if_known ? *text_size_if_known : ImGui::CalcTextSize(text, text_display_end, false, 0.0f);
  2157. // Perform CPU side clipping for single clipped element to avoid using scissor state
  2158. const bool need_clipping = (pos.x + text_size.x >= clip_max.x) || (pos.y + text_size.y >= clip_max.y);
  2159. // Render
  2160. window->DrawList->AddText(g.Font, g.FontSize, pos, window->Color(ImGuiCol_Text), text, text_display_end, 0.0f, need_clipping ? &clip_max : NULL);
  2161. // Log as text
  2162. if (g.LogEnabled)
  2163. LogText(pos, text, text_display_end);
  2164. }
  2165. }
  2166. // Render a rectangle shaped with optional rounding and borders
  2167. static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding)
  2168. {
  2169. ImGuiWindow* window = GetCurrentWindow();
  2170. window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding);
  2171. if (border && (window->Flags & ImGuiWindowFlags_ShowBorders))
  2172. {
  2173. // FIXME: This is the best I've found that works on multiple renderer/back ends. Bit dodgy.
  2174. window->DrawList->AddRect(p_min+ImVec2(1.5f,1.5f), p_max+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding);
  2175. window->DrawList->AddRect(p_min+ImVec2(0.5f,0.5f), p_max+ImVec2(0,0), window->Color(ImGuiCol_Border), rounding);
  2176. }
  2177. }
  2178. // Render a triangle to denote expanded/collapsed state
  2179. static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale, bool shadow)
  2180. {
  2181. ImGuiState& g = *GImGui;
  2182. ImGuiWindow* window = GetCurrentWindow();
  2183. const float h = g.FontSize * 1.00f;
  2184. const float r = h * 0.40f * scale;
  2185. ImVec2 center = p_min + ImVec2(h*0.50f, h*0.50f*scale);
  2186. ImVec2 a, b, c;
  2187. if (opened)
  2188. {
  2189. center.y -= r*0.25f;
  2190. a = center + ImVec2(0,1)*r;
  2191. b = center + ImVec2(-0.866f,-0.5f)*r;
  2192. c = center + ImVec2(0.866f,-0.5f)*r;
  2193. }
  2194. else
  2195. {
  2196. a = center + ImVec2(1,0)*r;
  2197. b = center + ImVec2(-0.500f,0.866f)*r;
  2198. c = center + ImVec2(-0.500f,-0.866f)*r;
  2199. }
  2200. if (shadow && (window->Flags & ImGuiWindowFlags_ShowBorders) != 0)
  2201. window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow));
  2202. window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Text));
  2203. }
  2204. // Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
  2205. // CalcTextSize("") should return ImVec2(0.0f, GImGui->FontSize)
  2206. ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width)
  2207. {
  2208. ImGuiState& g = *GImGui;
  2209. const char* text_display_end;
  2210. if (hide_text_after_double_hash)
  2211. text_display_end = FindTextDisplayEnd(text, text_end); // Hide anything after a '##' string
  2212. else
  2213. text_display_end = text_end;
  2214. ImFont* font = g.Font;
  2215. const float font_size = g.FontSize;
  2216. ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL);
  2217. // Cancel out character spacing for the last character of a line (it is baked into glyph->XAdvance field)
  2218. const float font_scale = font_size / font->FontSize;
  2219. const float character_spacing_x = 1.0f * font_scale;
  2220. if (text_size.x > 0.0f)
  2221. text_size.x -= character_spacing_x;
  2222. return text_size;
  2223. }
  2224. // Helper to calculate coarse clipping of large list of evenly sized items.
  2225. // 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.
  2226. // {
  2227. // float item_height = ImGui::GetTextLineHeightWithSpacing();
  2228. // int display_start, display_end;
  2229. // ImGui::CalcListClipping(count, item_height, &display_start, &display_end); // calculate how many to clip/display
  2230. // ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (display_start) * item_height); // advance cursor
  2231. // for (int i = display_start; i < display_end; i++) // display only visible items
  2232. // // TODO: display visible item
  2233. // ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (count - display_end) * item_height); // advance cursor
  2234. // }
  2235. void ImGui::CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end)
  2236. {
  2237. ImGuiState& g = *GImGui;
  2238. ImGuiWindow* window = GetCurrentWindow();
  2239. if (g.LogEnabled)
  2240. {
  2241. // If logging is active, do not perform any clipping
  2242. *out_items_display_start = 0;
  2243. *out_items_display_end = items_count;
  2244. return;
  2245. }
  2246. const ImVec2 pos = window->DC.CursorPos;
  2247. const ImVec4 clip_rect = window->ClipRectStack.back();
  2248. const float clip_y1 = clip_rect.y;
  2249. const float clip_y2 = clip_rect.w;
  2250. int start = (int)((clip_y1 - pos.y) / items_height);
  2251. int end = (int)((clip_y2 - pos.y) / items_height);
  2252. start = ImClamp(start, 0, items_count);
  2253. end = ImClamp(end + 1, start, items_count);
  2254. *out_items_display_start = start;
  2255. *out_items_display_end = end;
  2256. }
  2257. // Find window given position, search front-to-back
  2258. static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs)
  2259. {
  2260. ImGuiState& g = *GImGui;
  2261. for (int i = (int)g.Windows.size()-1; i >= 0; i--)
  2262. {
  2263. ImGuiWindow* window = g.Windows[(size_t)i];
  2264. if (!window->Visible)
  2265. continue;
  2266. if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
  2267. continue;
  2268. // Using the clipped AABB so a child window will typically be clipped by its parent.
  2269. ImRect bb(window->ClippedRect.Min - g.Style.TouchExtraPadding, window->ClippedRect.Max + g.Style.TouchExtraPadding);
  2270. if (bb.Contains(pos))
  2271. return window;
  2272. }
  2273. return NULL;
  2274. }
  2275. // Test if mouse cursor is hovering given rectangle
  2276. // NB- Rectangle is clipped by our current clip setting
  2277. // NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
  2278. static bool IsMouseHoveringRect(const ImRect& rect)
  2279. {
  2280. ImGuiState& g = *GImGui;
  2281. ImGuiWindow* window = GetCurrentWindow();
  2282. // Clip
  2283. ImRect rect_clipped = rect;
  2284. if (!window->ClipRectStack.empty())
  2285. {
  2286. const ImVec4 clip_rect = window->ClipRectStack.back();
  2287. rect_clipped.Clip(ImRect(ImVec2(clip_rect.x, clip_rect.y), ImVec2(clip_rect.z, clip_rect.w)));
  2288. }
  2289. // Expand for touch input
  2290. const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding);
  2291. return rect_for_touch.Contains(g.IO.MousePos);
  2292. }
  2293. bool ImGui::IsMouseHoveringRect(const ImVec2& rect_min, const ImVec2& rect_max)
  2294. {
  2295. return IsMouseHoveringRect(ImRect(rect_min, rect_max));
  2296. }
  2297. bool ImGui::IsMouseHoveringWindow()
  2298. {
  2299. ImGuiState& g = *GImGui;
  2300. ImGuiWindow* window = GetCurrentWindow();
  2301. return g.HoveredWindow == window;
  2302. }
  2303. bool ImGui::IsMouseHoveringAnyWindow()
  2304. {
  2305. ImGuiState& g = *GImGui;
  2306. return g.HoveredWindow != NULL;
  2307. }
  2308. bool ImGui::IsPosHoveringAnyWindow(const ImVec2& pos)
  2309. {
  2310. return FindHoveredWindow(pos, false) != NULL;
  2311. }
  2312. static bool IsKeyPressedMap(ImGuiKey key, bool repeat)
  2313. {
  2314. ImGuiState& g = *GImGui;
  2315. const int key_index = g.IO.KeyMap[key];
  2316. return ImGui::IsKeyPressed(key_index, repeat);
  2317. }
  2318. bool ImGui::IsKeyPressed(int key_index, bool repeat)
  2319. {
  2320. ImGuiState& g = *GImGui;
  2321. IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
  2322. const float t = g.IO.KeysDownTime[key_index];
  2323. if (t == 0.0f)
  2324. return true;
  2325. // FIXME: Repeat rate should be provided elsewhere?
  2326. const float KEY_REPEAT_DELAY = 0.250f;
  2327. const float KEY_REPEAT_RATE = 0.020f;
  2328. if (repeat && t > KEY_REPEAT_DELAY)
  2329. 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))
  2330. return true;
  2331. return false;
  2332. }
  2333. bool ImGui::IsMouseClicked(int button, bool repeat)
  2334. {
  2335. ImGuiState& g = *GImGui;
  2336. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2337. const float t = g.IO.MouseDownTime[button];
  2338. if (t == 0.0f)
  2339. return true;
  2340. // FIXME: Repeat rate should be provided elsewhere?
  2341. const float MOUSE_REPEAT_DELAY = 0.250f;
  2342. const float MOUSE_REPEAT_RATE = 0.020f;
  2343. if (repeat && t > MOUSE_REPEAT_DELAY)
  2344. 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))
  2345. return true;
  2346. return false;
  2347. }
  2348. bool ImGui::IsMouseDoubleClicked(int button)
  2349. {
  2350. ImGuiState& g = *GImGui;
  2351. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2352. return g.IO.MouseDoubleClicked[button];
  2353. }
  2354. bool ImGui::IsMouseDragging(int button, float lock_threshold)
  2355. {
  2356. ImGuiState& g = *GImGui;
  2357. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2358. if (lock_threshold < 0.0f)
  2359. lock_threshold = g.IO.MouseDragThreshold;
  2360. return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold;
  2361. }
  2362. ImVec2 ImGui::GetMousePos()
  2363. {
  2364. return GImGui->IO.MousePos;
  2365. }
  2366. ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold)
  2367. {
  2368. ImGuiState& g = *GImGui;
  2369. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2370. if (lock_threshold < 0.0f)
  2371. lock_threshold = g.IO.MouseDragThreshold;
  2372. if (g.IO.MouseDown[button])
  2373. if (g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold)
  2374. return g.IO.MousePos - g.IO.MouseClickedPos[button]; // Assume we can only get active with left-mouse button (at the moment).
  2375. return ImVec2(0.0f, 0.0f);
  2376. }
  2377. void ImGui::ResetMouseDragDelta(int button)
  2378. {
  2379. ImGuiState& g = *GImGui;
  2380. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2381. // NB: We don't need to reset g.IO.MouseDragMaxDistanceSqr
  2382. g.IO.MouseClickedPos[button] = g.IO.MousePos;
  2383. }
  2384. ImGuiMouseCursor ImGui::GetMouseCursor()
  2385. {
  2386. return GImGui->MouseCursor;
  2387. }
  2388. void ImGui::SetMouseCursor(ImGuiMouseCursor cursor_type)
  2389. {
  2390. GImGui->MouseCursor = cursor_type;
  2391. }
  2392. bool ImGui::IsItemHovered()
  2393. {
  2394. ImGuiWindow* window = GetCurrentWindow();
  2395. return window->DC.LastItemHoveredAndUsable;
  2396. }
  2397. bool ImGui::IsItemHoveredRect()
  2398. {
  2399. ImGuiWindow* window = GetCurrentWindow();
  2400. return window->DC.LastItemHoveredRect;
  2401. }
  2402. bool ImGui::IsItemActive()
  2403. {
  2404. ImGuiState& g = *GImGui;
  2405. if (g.ActiveId)
  2406. {
  2407. ImGuiWindow* window = GetCurrentWindow();
  2408. return g.ActiveId == window->DC.LastItemID;
  2409. }
  2410. return false;
  2411. }
  2412. bool ImGui::IsAnyItemActive()
  2413. {
  2414. ImGuiState& g = *GImGui;
  2415. return g.ActiveId != 0;
  2416. }
  2417. bool ImGui::IsItemVisible()
  2418. {
  2419. ImGuiWindow* window = GetCurrentWindow();
  2420. ImRect r(window->ClipRectStack.back());
  2421. return r.Overlaps(window->DC.LastItemRect);
  2422. }
  2423. ImVec2 ImGui::GetItemRectMin()
  2424. {
  2425. ImGuiWindow* window = GetCurrentWindow();
  2426. return window->DC.LastItemRect.Min;
  2427. }
  2428. ImVec2 ImGui::GetItemRectMax()
  2429. {
  2430. ImGuiWindow* window = GetCurrentWindow();
  2431. return window->DC.LastItemRect.Max;
  2432. }
  2433. ImVec2 ImGui::GetItemRectSize()
  2434. {
  2435. ImGuiWindow* window = GetCurrentWindow();
  2436. return window->DC.LastItemRect.GetSize();
  2437. }
  2438. ImVec2 ImGui::CalcItemRectClosestPoint(const ImVec2& pos, bool on_edge, float outward)
  2439. {
  2440. ImGuiWindow* window = GetCurrentWindow();
  2441. ImRect rect = window->DC.LastItemRect;
  2442. rect.Expand(outward);
  2443. return rect.GetClosestPoint(pos, on_edge);
  2444. }
  2445. // Tooltip is stored and turned into a BeginTooltip()/EndTooltip() sequence at the end of the frame. Each call override previous value.
  2446. void ImGui::SetTooltipV(const char* fmt, va_list args)
  2447. {
  2448. ImGuiState& g = *GImGui;
  2449. ImFormatStringV(g.Tooltip, IM_ARRAYSIZE(g.Tooltip), fmt, args);
  2450. }
  2451. void ImGui::SetTooltip(const char* fmt, ...)
  2452. {
  2453. va_list args;
  2454. va_start(args, fmt);
  2455. SetTooltipV(fmt, args);
  2456. va_end(args);
  2457. }
  2458. float ImGui::GetTime()
  2459. {
  2460. return GImGui->Time;
  2461. }
  2462. int ImGui::GetFrameCount()
  2463. {
  2464. return GImGui->FrameCount;
  2465. }
  2466. void ImGui::BeginTooltip()
  2467. {
  2468. ImGuiState& g = *GImGui;
  2469. ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize;
  2470. ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), g.Style.Colors[ImGuiCol_TooltipBg].w, flags);
  2471. }
  2472. void ImGui::EndTooltip()
  2473. {
  2474. IM_ASSERT(GetCurrentWindow()->Flags & ImGuiWindowFlags_Tooltip);
  2475. ImGui::End();
  2476. }
  2477. void ImGui::BeginPopup(bool* p_opened)
  2478. {
  2479. IM_ASSERT(p_opened != NULL); // Must provide a bool at the moment
  2480. ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
  2481. ImGuiWindowFlags flags = ImGuiWindowFlags_Popup|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize;
  2482. ImGui::Begin("##Popup", p_opened, flags);
  2483. }
  2484. void ImGui::EndPopup()
  2485. {
  2486. IM_ASSERT(GetCurrentWindow()->Flags & ImGuiWindowFlags_Popup);
  2487. ImGui::End();
  2488. ImGui::PopStyleVar();
  2489. }
  2490. bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags)
  2491. {
  2492. ImGuiState& g = *GImGui;
  2493. ImGuiWindow* window = GetCurrentWindow();
  2494. ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow;
  2495. const ImVec2 content_max = window->Pos + ImGui::GetContentRegionMax();
  2496. const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos();
  2497. ImVec2 size = size_arg;
  2498. if (size.x <= 0.0f)
  2499. {
  2500. if (size.x == 0.0f)
  2501. flags |= ImGuiWindowFlags_ChildWindowAutoFitX;
  2502. size.x = ImMax(content_max.x - cursor_pos.x, g.Style.WindowMinSize.x) - fabsf(size.x);
  2503. }
  2504. if (size.y <= 0.0f)
  2505. {
  2506. if (size.y == 0.0f)
  2507. flags |= ImGuiWindowFlags_ChildWindowAutoFitY;
  2508. size.y = ImMax(content_max.y - cursor_pos.y, g.Style.WindowMinSize.y) - fabsf(size.y);
  2509. }
  2510. if (border)
  2511. flags |= ImGuiWindowFlags_ShowBorders;
  2512. flags |= extra_flags;
  2513. char title[256];
  2514. ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s", window->Name, str_id);
  2515. const float alpha = 1.0f;
  2516. bool ret = ImGui::Begin(title, NULL, size, alpha, flags);
  2517. if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
  2518. g.CurrentWindow->Flags &= ~ImGuiWindowFlags_ShowBorders;
  2519. return ret;
  2520. }
  2521. bool ImGui::BeginChild(ImGuiID id, const ImVec2& size, bool border, ImGuiWindowFlags extra_flags)
  2522. {
  2523. char str_id[32];
  2524. ImFormatString(str_id, IM_ARRAYSIZE(str_id), "child_%x", id);
  2525. bool ret = ImGui::BeginChild(str_id, size, border, extra_flags);
  2526. return ret;
  2527. }
  2528. void ImGui::EndChild()
  2529. {
  2530. ImGuiWindow* window = GetCurrentWindow();
  2531. IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow);
  2532. if (window->Flags & ImGuiWindowFlags_ComboBox)
  2533. {
  2534. ImGui::End();
  2535. }
  2536. else
  2537. {
  2538. // 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.
  2539. ImGuiState& g = *GImGui;
  2540. ImVec2 sz = ImGui::GetWindowSize();
  2541. if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitX)
  2542. sz.x = ImMax(g.Style.WindowMinSize.x, sz.x - g.Style.AutoFitPadding.x);
  2543. if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitY)
  2544. sz.y = ImMax(g.Style.WindowMinSize.y, sz.y - g.Style.AutoFitPadding.y);
  2545. ImGui::End();
  2546. window = GetCurrentWindow();
  2547. ImRect bb(window->DC.CursorPos, window->DC.CursorPos + sz);
  2548. ItemSize(sz);
  2549. ItemAdd(bb, NULL);
  2550. }
  2551. }
  2552. // Helper to create a child window / scrolling region that looks like a normal widget frame.
  2553. void ImGui::BeginChildFrame(ImGuiID id, const ImVec2& size)
  2554. {
  2555. ImGuiState& g = *GImGui;
  2556. const ImGuiStyle& style = g.Style;
  2557. ImGui::PushStyleColor(ImGuiCol_ChildWindowBg, style.Colors[ImGuiCol_FrameBg]);
  2558. ImGui::PushStyleVar(ImGuiStyleVar_ChildWindowRounding, style.FrameRounding);
  2559. ImGui::BeginChild(id, size);
  2560. }
  2561. void ImGui::EndChildFrame()
  2562. {
  2563. ImGui::EndChild();
  2564. ImGui::PopStyleVar();
  2565. ImGui::PopStyleColor();
  2566. }
  2567. static ImGuiWindow* FindWindowByName(const char* name)
  2568. {
  2569. // FIXME-OPT: Store sorted hashes -> pointers.
  2570. ImGuiState& g = *GImGui;
  2571. ImGuiID id = ImHash(name, 0);
  2572. for (size_t i = 0; i < g.Windows.size(); i++)
  2573. if (g.Windows[i]->ID == id)
  2574. return g.Windows[i];
  2575. return NULL;
  2576. }
  2577. static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags)
  2578. {
  2579. ImGuiState& g = *GImGui;
  2580. // Create window the first time
  2581. ImGuiWindow* window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow));
  2582. new(window) ImGuiWindow(name);
  2583. window->Flags = flags;
  2584. if (flags & ImGuiWindowFlags_NoSavedSettings)
  2585. {
  2586. // User can disable loading and saving of settings. Tooltip and child windows also don't store settings.
  2587. window->Size = window->SizeFull = size;
  2588. }
  2589. else
  2590. {
  2591. // Retrieve settings from .ini file
  2592. // Use SetWindowPos() or SetNextWindowPos() with the appropriate condition flag to change the initial position of a window.
  2593. window->PosFloat = ImVec2(60, 60);
  2594. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  2595. ImGuiIniData* settings = FindWindowSettings(name);
  2596. if (!settings)
  2597. {
  2598. settings = AddWindowSettings(name);
  2599. }
  2600. else
  2601. {
  2602. window->SetWindowPosAllowFlags &= ~ImGuiSetCond_FirstUseEver;
  2603. window->SetWindowSizeAllowFlags &= ~ImGuiSetCond_FirstUseEver;
  2604. window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCond_FirstUseEver;
  2605. }
  2606. if (settings->Pos.x != FLT_MAX)
  2607. {
  2608. window->PosFloat = settings->Pos;
  2609. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  2610. window->Collapsed = settings->Collapsed;
  2611. }
  2612. if (ImLengthSqr(settings->Size) > 0.00001f && !(flags & ImGuiWindowFlags_NoResize))
  2613. size = settings->Size;
  2614. window->Size = window->SizeFull = size;
  2615. }
  2616. if ((flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
  2617. {
  2618. window->AutoFitFrames = 2;
  2619. window->AutoFitOnlyGrows = false;
  2620. }
  2621. else if (ImLengthSqr(window->Size) < 0.00001f)
  2622. {
  2623. window->AutoFitFrames = 2;
  2624. window->AutoFitOnlyGrows = true;
  2625. }
  2626. g.Windows.push_back(window);
  2627. return window;
  2628. }
  2629. // Push a new ImGui window to add widgets to.
  2630. // - '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.
  2631. // - 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.
  2632. // - Begin/End can be called multiple times during the frame with the same window name to append content.
  2633. // - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file).
  2634. // 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.
  2635. // - 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.
  2636. // - 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.
  2637. // - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCond_FirstUseEver) prior to calling Begin().
  2638. bool ImGui::Begin(const char* name, bool* p_opened, ImGuiWindowFlags flags)
  2639. {
  2640. return ImGui::Begin(name, p_opened, ImVec2(0.f, 0.f), -1.0f, flags);
  2641. }
  2642. bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_use, float bg_alpha, ImGuiWindowFlags flags)
  2643. {
  2644. ImGuiState& g = *GImGui;
  2645. const ImGuiStyle& style = g.Style;
  2646. IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
  2647. IM_ASSERT(name != NULL); // Must pass a name
  2648. // Find or create
  2649. bool window_is_new = false;
  2650. ImGuiWindow* window = FindWindowByName(name);
  2651. if (!window)
  2652. {
  2653. window = CreateNewWindow(name, size_on_first_use, flags);
  2654. window_is_new = true;
  2655. }
  2656. window->Flags = (ImGuiWindowFlags)flags;
  2657. // Add to stack
  2658. g.CurrentWindowStack.push_back(window);
  2659. SetCurrentWindow(window);
  2660. // Process SetNextWindow***() calls
  2661. bool window_pos_set_by_api = false;
  2662. if (g.SetNextWindowPosCond)
  2663. {
  2664. const ImVec2 backup_cursor_pos = window->DC.CursorPos; // FIXME: not sure of the exact reason of this anymore :( need to look into that.
  2665. ImGui::SetWindowPos(g.SetNextWindowPosVal, g.SetNextWindowPosCond);
  2666. window->DC.CursorPos = backup_cursor_pos;
  2667. window_pos_set_by_api = true;
  2668. g.SetNextWindowPosCond = 0;
  2669. }
  2670. if (g.SetNextWindowSizeCond)
  2671. {
  2672. ImGui::SetWindowSize(g.SetNextWindowSizeVal, g.SetNextWindowSizeCond);
  2673. g.SetNextWindowSizeCond = 0;
  2674. }
  2675. if (g.SetNextWindowCollapsedCond)
  2676. {
  2677. ImGui::SetWindowCollapsed(g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond);
  2678. g.SetNextWindowCollapsedCond = 0;
  2679. }
  2680. if (g.SetNextWindowFocus)
  2681. {
  2682. ImGui::SetWindowFocus();
  2683. g.SetNextWindowFocus = false;
  2684. }
  2685. // Find parent
  2686. ImGuiWindow* parent_window = (flags & ImGuiWindowFlags_ChildWindow) != 0 ? g.CurrentWindowStack[g.CurrentWindowStack.size()-2] : NULL;
  2687. // Update known root window (if we are a child window, otherwise window == window->RootWindow)
  2688. size_t root_idx = g.CurrentWindowStack.size() - 1;
  2689. while (root_idx > 0)
  2690. {
  2691. if ((g.CurrentWindowStack[root_idx]->Flags & ImGuiWindowFlags_ChildWindow) == 0)
  2692. break;
  2693. root_idx--;
  2694. }
  2695. window->RootWindow = g.CurrentWindowStack[root_idx];
  2696. // Default alpha
  2697. if (bg_alpha < 0.0f)
  2698. bg_alpha = style.WindowFillAlphaDefault;
  2699. // When reusing window again multiple times a frame, just append content (don't need to setup again)
  2700. const int current_frame = ImGui::GetFrameCount();
  2701. const bool first_begin_of_the_frame = (window->LastFrameDrawn != current_frame);
  2702. if (first_begin_of_the_frame)
  2703. {
  2704. window->DrawList->Clear();
  2705. window->Visible = true;
  2706. // New windows appears in front
  2707. if (!(flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Tooltip))
  2708. {
  2709. if (window->LastFrameDrawn < current_frame - 1)
  2710. {
  2711. FocusWindow(window);
  2712. // Popup position themselves when they first appear
  2713. if (flags & ImGuiWindowFlags_Popup)
  2714. {
  2715. if (!window_pos_set_by_api)
  2716. window->PosFloat = g.IO.MousePos;
  2717. }
  2718. }
  2719. }
  2720. window->LastFrameDrawn = current_frame;
  2721. window->ClipRectStack.resize(0);
  2722. // Reset contents size for auto-fitting
  2723. window->SizeContents = window_is_new ? ImVec2(0.0f, 0.0f) : window->DC.CursorMaxPos - window->Pos;
  2724. window->SizeContents.y += window->ScrollY;
  2725. if (flags & ImGuiWindowFlags_ChildWindow)
  2726. {
  2727. parent_window->DC.ChildWindows.push_back(window);
  2728. window->Pos = window->PosFloat = parent_window->DC.CursorPos;
  2729. window->SizeFull = size_on_first_use;
  2730. }
  2731. }
  2732. // Setup texture
  2733. window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID);
  2734. // Setup outer clipping rectangle
  2735. if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox))
  2736. PushClipRect(parent_window->ClipRectStack.back());
  2737. else if (g.IO.DisplayVisibleMin.x != g.IO.DisplayVisibleMax.x && g.IO.DisplayVisibleMin.y != g.IO.DisplayVisibleMax.y)
  2738. PushClipRect(ImVec4(g.IO.DisplayVisibleMin.x, g.IO.DisplayVisibleMin.y, g.IO.DisplayVisibleMax.x, g.IO.DisplayVisibleMax.y));
  2739. else
  2740. PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y));
  2741. // Setup and draw window
  2742. if (first_begin_of_the_frame)
  2743. {
  2744. // Reset ID stack
  2745. window->IDStack.resize(1);
  2746. // Move window (at the beginning of the frame to avoid input lag or sheering). Only valid for root windows.
  2747. RegisterAliveId(window->MoveID);
  2748. if (g.ActiveId == window->MoveID)
  2749. {
  2750. if (g.IO.MouseDown[0])
  2751. {
  2752. if (!(window->Flags & ImGuiWindowFlags_NoMove))
  2753. {
  2754. window->PosFloat += g.IO.MouseDelta;
  2755. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2756. MarkSettingsDirty();
  2757. }
  2758. IM_ASSERT(g.MovedWindow != NULL);
  2759. FocusWindow(g.MovedWindow);
  2760. }
  2761. else
  2762. {
  2763. SetActiveId(0);
  2764. g.MovedWindow = NULL; // Not strictly necessary but doing it for sanity.
  2765. }
  2766. }
  2767. // Tooltips always follows mouse
  2768. if (!window_pos_set_by_api && (window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2769. {
  2770. window->PosFloat = g.IO.MousePos + ImVec2(32,16) - style.FramePadding*2;
  2771. }
  2772. // Clamp into view
  2773. if (!(window->Flags & ImGuiWindowFlags_ChildWindow) && !(window->Flags & ImGuiWindowFlags_Tooltip))
  2774. {
  2775. 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.
  2776. {
  2777. ImVec2 clip_min = style.DisplaySafeAreaPadding;
  2778. ImVec2 clip_max = g.IO.DisplaySize - style.DisplaySafeAreaPadding;
  2779. window->PosFloat = ImMax(window->PosFloat + window->Size, clip_min) - window->Size;
  2780. window->PosFloat = ImMin(window->PosFloat, clip_max);
  2781. }
  2782. window->SizeFull = ImMax(window->SizeFull, style.WindowMinSize);
  2783. }
  2784. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  2785. // Default item width. Make it proportional to window size if window manually resizes
  2786. if (window->Size.x > 0.0f && !(window->Flags & ImGuiWindowFlags_Tooltip) && !(window->Flags & ImGuiWindowFlags_AlwaysAutoResize))
  2787. window->ItemWidthDefault = (float)(int)(window->Size.x * 0.65f);
  2788. else
  2789. window->ItemWidthDefault = 200.0f;
  2790. // Prepare for focus requests
  2791. if (window->FocusIdxAllRequestNext == IM_INT_MAX || window->FocusIdxAllCounter == -1)
  2792. window->FocusIdxAllRequestCurrent = IM_INT_MAX;
  2793. else
  2794. window->FocusIdxAllRequestCurrent = (window->FocusIdxAllRequestNext + (window->FocusIdxAllCounter+1)) % (window->FocusIdxAllCounter+1);
  2795. if (window->FocusIdxTabRequestNext == IM_INT_MAX || window->FocusIdxTabCounter == -1)
  2796. window->FocusIdxTabRequestCurrent = IM_INT_MAX;
  2797. else
  2798. window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext + (window->FocusIdxTabCounter+1)) % (window->FocusIdxTabCounter+1);
  2799. window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1;
  2800. window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = IM_INT_MAX;
  2801. ImRect title_bar_rect = window->TitleBarRect();
  2802. // Apply and ImClamp scrolling
  2803. window->ScrollY = window->NextScrollY;
  2804. window->ScrollY = ImMax(window->ScrollY, 0.0f);
  2805. if (!window->Collapsed && !window->SkipItems)
  2806. window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, window->SizeContents.y - window->SizeFull.y));
  2807. window->NextScrollY = window->ScrollY;
  2808. // At this point we don't have a clipping rectangle setup yet, so we can test and draw in title bar
  2809. // Collapse window by double-clicking on title bar
  2810. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2811. {
  2812. if (!(window->Flags & ImGuiWindowFlags_NoCollapse) && g.HoveredWindow == window && IsMouseHoveringRect(title_bar_rect) && g.IO.MouseDoubleClicked[0])
  2813. {
  2814. window->Collapsed = !window->Collapsed;
  2815. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2816. MarkSettingsDirty();
  2817. FocusWindow(window);
  2818. }
  2819. }
  2820. else
  2821. {
  2822. window->Collapsed = false;
  2823. }
  2824. // Calculate auto-fit size
  2825. ImVec2 size_auto_fit;
  2826. if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2827. {
  2828. // Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose.
  2829. size_auto_fit = window->SizeContents + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y);
  2830. }
  2831. else
  2832. {
  2833. size_auto_fit = ImClamp(window->SizeContents + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding));
  2834. if (size_auto_fit.y < window->SizeContents.y + style.AutoFitPadding.y)
  2835. size_auto_fit.x += style.ScrollbarWidth;
  2836. }
  2837. const float window_rounding = (window->Flags & ImGuiWindowFlags_ChildWindow) ? style.ChildWindowRounding : style.WindowRounding;
  2838. if (window->Collapsed)
  2839. {
  2840. // We still process initial auto-fit on collapsed windows to get a window width
  2841. // But otherwise we don't honor ImGuiWindowFlags_AlwaysAutoResize when collapsed.
  2842. if (window->AutoFitFrames > 0)
  2843. {
  2844. window->SizeFull = window->AutoFitOnlyGrows ? ImMax(window->SizeFull, size_auto_fit) : size_auto_fit;
  2845. title_bar_rect = window->TitleBarRect();
  2846. }
  2847. // Draw title bar only
  2848. window->Size = title_bar_rect.GetSize();
  2849. window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), window_rounding);
  2850. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  2851. {
  2852. window->DrawList->AddRect(title_bar_rect.GetTL()+ImVec2(1,1), title_bar_rect.GetBR()+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), window_rounding);
  2853. window->DrawList->AddRect(title_bar_rect.GetTL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_Border), window_rounding);
  2854. }
  2855. }
  2856. else
  2857. {
  2858. ImU32 resize_col = 0;
  2859. if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2860. {
  2861. window->Size = window->SizeFull = size_auto_fit;
  2862. }
  2863. else
  2864. {
  2865. if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
  2866. {
  2867. // Don't continuously mark settings as dirty, the size of the window doesn't need to be stored.
  2868. window->SizeFull = size_auto_fit;
  2869. }
  2870. else if (window->AutoFitFrames > 0)
  2871. {
  2872. // Auto-fit only grows during the first few frames
  2873. window->SizeFull = window->AutoFitOnlyGrows ? ImMax(window->SizeFull, size_auto_fit) : size_auto_fit;
  2874. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2875. MarkSettingsDirty();
  2876. }
  2877. else if (!(window->Flags & ImGuiWindowFlags_NoResize))
  2878. {
  2879. // Manual resize grip
  2880. const ImRect resize_rect(window->Rect().GetBR()-ImVec2(14,14), window->Rect().GetBR());
  2881. const ImGuiID resize_id = window->GetID("#RESIZE");
  2882. bool hovered, held;
  2883. ButtonBehavior(resize_rect, resize_id, &hovered, &held, true);
  2884. resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
  2885. if (hovered || held)
  2886. g.MouseCursor = ImGuiMouseCursor_ResizeNWSE;
  2887. if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0])
  2888. {
  2889. // Manual auto-fit when double-clicking
  2890. window->SizeFull = size_auto_fit;
  2891. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2892. MarkSettingsDirty();
  2893. SetActiveId(0);
  2894. }
  2895. else if (held)
  2896. {
  2897. // Resize
  2898. window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize);
  2899. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2900. MarkSettingsDirty();
  2901. }
  2902. }
  2903. // Update rectangle immediately so that rendering right below us isn't one frame late
  2904. window->Size = window->SizeFull;
  2905. title_bar_rect = window->TitleBarRect();
  2906. }
  2907. // Scrollbar
  2908. window->ScrollbarY = (window->SizeContents.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar);
  2909. // Window background
  2910. if (bg_alpha > 0.0f)
  2911. {
  2912. if ((window->Flags & ImGuiWindowFlags_ComboBox) != 0)
  2913. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, bg_alpha), window_rounding);
  2914. else if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2915. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_TooltipBg, bg_alpha), window_rounding);
  2916. else if ((window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
  2917. 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));
  2918. else
  2919. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, bg_alpha), window_rounding);
  2920. }
  2921. // Title bar
  2922. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2923. window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_TitleBg), window_rounding, 1|2);
  2924. // Borders
  2925. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  2926. {
  2927. window->DrawList->AddRect(window->Pos+ImVec2(1,1), window->Pos+window->Size+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), window_rounding);
  2928. window->DrawList->AddRect(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_Border), window_rounding);
  2929. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2930. window->DrawList->AddLine(title_bar_rect.GetBL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_Border));
  2931. }
  2932. // Scrollbar
  2933. if (window->ScrollbarY)
  2934. Scrollbar(window);
  2935. // Render resize grip
  2936. // (after the input handling so we don't have a frame of latency)
  2937. if (!(window->Flags & ImGuiWindowFlags_NoResize))
  2938. {
  2939. const float r = window_rounding;
  2940. const ImVec2 br = window->Rect().GetBR();
  2941. if (r == 0.0f)
  2942. {
  2943. window->DrawList->AddTriangleFilled(br, br-ImVec2(0,14), br-ImVec2(14,0), resize_col);
  2944. }
  2945. else
  2946. {
  2947. // FIXME: We should draw 4 triangles and decide on a size that's not dependent on the rounding size (previously used 18)
  2948. window->DrawList->AddArcFast(br - ImVec2(r,r), r, resize_col, 6, 9, true);
  2949. window->DrawList->AddTriangleFilled(br+ImVec2(0,-2*r),br+ImVec2(0,-r),br+ImVec2(-r,-r), resize_col);
  2950. window->DrawList->AddTriangleFilled(br+ImVec2(-r,-r), br+ImVec2(-r,0),br+ImVec2(-2*r,0), resize_col);
  2951. }
  2952. }
  2953. }
  2954. // Setup drawing context
  2955. window->DC.ColumnsStartX = window->WindowPadding().x;
  2956. window->DC.ColumnsOffsetX = 0.0f;
  2957. window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.ColumnsStartX + window->DC.ColumnsOffsetX, window->TitleBarHeight() + window->WindowPadding().y) - ImVec2(0.0f, window->ScrollY);
  2958. window->DC.CursorPos = window->DC.CursorStartPos;
  2959. window->DC.CursorPosPrevLine = window->DC.CursorPos;
  2960. window->DC.CursorMaxPos = window->DC.CursorStartPos;
  2961. window->DC.CurrentLineHeight = window->DC.PrevLineHeight = 0.0f;
  2962. window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f;
  2963. window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f;
  2964. window->DC.ChildWindows.resize(0);
  2965. window->DC.ItemWidth.resize(0);
  2966. window->DC.ItemWidth.push_back(window->ItemWidthDefault);
  2967. window->DC.AllowKeyboardFocus.resize(0);
  2968. window->DC.AllowKeyboardFocus.push_back(true);
  2969. window->DC.TextWrapPos.resize(0);
  2970. window->DC.TextWrapPos.push_back(-1.0f); // disabled
  2971. window->DC.ColorEditMode = ImGuiColorEditMode_UserSelect;
  2972. window->DC.ColumnsCurrent = 0;
  2973. window->DC.ColumnsCount = 1;
  2974. window->DC.ColumnsStartPos = window->DC.CursorPos;
  2975. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.ColumnsStartPos.y;
  2976. window->DC.TreeDepth = 0;
  2977. window->DC.StateStorage = &window->StateStorage;
  2978. window->DC.GroupStack.resize(0);
  2979. if (window->AutoFitFrames > 0)
  2980. window->AutoFitFrames--;
  2981. // Title bar
  2982. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2983. {
  2984. if (p_opened != NULL)
  2985. CloseWindowButton(p_opened);
  2986. ImVec2 text_min = window->Pos + style.FramePadding;
  2987. if (!(window->Flags & ImGuiWindowFlags_NoCollapse))
  2988. {
  2989. RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true);
  2990. text_min.x += g.FontSize + style.ItemInnerSpacing.x;
  2991. }
  2992. const ImVec2 text_size = CalcTextSize(name, NULL, true);
  2993. 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);
  2994. RenderTextClipped(text_min, name, NULL, &text_size, text_max);
  2995. }
  2996. if (window->Flags & ImGuiWindowFlags_Popup)
  2997. {
  2998. if (p_opened)
  2999. {
  3000. if (g.IO.MouseClicked[0] && (!g.HoveredWindow || g.HoveredWindow->RootWindow != window))
  3001. *p_opened = false;
  3002. else if (!g.FocusedWindow)
  3003. *p_opened = false;
  3004. else if (g.FocusedWindow->RootWindow != window)// && !(g.FocusedWindow->RootWindow->Flags & ImGuiWindowFlags_Tooltip))
  3005. *p_opened = false;
  3006. }
  3007. }
  3008. // Save clipped aabb so we can access it in constant-time in FindHoveredWindow()
  3009. window->ClippedRect = window->Rect();
  3010. window->ClippedRect.Clip(window->ClipRectStack.front());
  3011. // Pressing CTRL+C while holding on a window copy its content to the clipboard
  3012. // 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.
  3013. // Maybe we can support CTRL+C on every element?
  3014. /*
  3015. if (g.ActiveId == move_id)
  3016. if (g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_C))
  3017. ImGui::LogToClipboard();
  3018. */
  3019. }
  3020. // Inner clipping rectangle
  3021. // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame
  3022. // Note that if our window is collapsed we will end up with a null clipping rectangle which is the correct behavior.
  3023. const ImRect title_bar_rect = window->TitleBarRect();
  3024. 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);
  3025. if (window->ScrollbarY)
  3026. clip_rect.z -= style.ScrollbarWidth;
  3027. PushClipRect(clip_rect);
  3028. // Clear 'accessed' flag last thing
  3029. if (first_begin_of_the_frame)
  3030. window->Accessed = false;
  3031. // Child window can be out of sight and have "negative" clip windows.
  3032. // Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar).
  3033. if (flags & ImGuiWindowFlags_ChildWindow)
  3034. {
  3035. IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0);
  3036. window->Collapsed = parent_window && parent_window->Collapsed;
  3037. const ImVec4 clip_rect_t = window->ClipRectStack.back();
  3038. window->Collapsed |= (clip_rect_t.x >= clip_rect_t.z || clip_rect_t.y >= clip_rect_t.w);
  3039. // We also hide the window from rendering because we've already added its border to the command list.
  3040. // (we could perform the check earlier in the function but it is simpler at this point)
  3041. if (window->Collapsed)
  3042. window->Visible = false;
  3043. }
  3044. if (style.Alpha <= 0.0f)
  3045. window->Visible = false;
  3046. // Return false if we don't intend to display anything to allow user to perform an early out optimization
  3047. window->SkipItems = (window->Collapsed || !window->Visible) && window->AutoFitFrames <= 0;
  3048. return !window->SkipItems;
  3049. }
  3050. void ImGui::End()
  3051. {
  3052. ImGuiState& g = *GImGui;
  3053. ImGuiWindow* window = g.CurrentWindow;
  3054. ImGui::Columns(1, "#CloseColumns");
  3055. PopClipRect(); // inner window clip rectangle
  3056. PopClipRect(); // outer window clip rectangle
  3057. window->DrawList->PopTextureID();
  3058. // Stop logging
  3059. if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of logging
  3060. ImGui::LogFinish();
  3061. // Pop
  3062. // NB: we don't clear 'window->RootWindow'. The pointer is allowed to live until the next call to Begin().
  3063. g.CurrentWindowStack.pop_back();
  3064. SetCurrentWindow(g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back());
  3065. }
  3066. // Vertical scrollbar
  3067. // The entire piece of code below is rather confusing because:
  3068. // - We handle absolute seeking (when first clicking outside the grab) and relative manipulation (afterward or when clicking inside the grab)
  3069. // - We store values as ratio and in a form that allows the window content to change while we are holding on a scrollbar
  3070. static void Scrollbar(ImGuiWindow* window)
  3071. {
  3072. ImGuiState& g = *GImGui;
  3073. const ImGuiStyle& style = g.Style;
  3074. const ImGuiID id = window->GetID("#SCROLLY");
  3075. // Render background
  3076. ImRect bb(window->Rect().Max.x - style.ScrollbarWidth, window->Pos.y + window->TitleBarHeight()+1, window->Rect().Max.x, window->Rect().Max.y-1);
  3077. window->DrawList->AddRectFilled(bb.Min, bb.Max, window->Color(ImGuiCol_ScrollbarBg));
  3078. bb.Expand(-3.0f);
  3079. const float scrollbar_height = bb.GetHeight();
  3080. // The grabable box size generally represent the amount visible (vs the total scrollable amount)
  3081. // But we maintain a minimum size in pixel to allow for the user to still aim inside.
  3082. const float grab_h_pixels = ImMin(ImMax(scrollbar_height * ImSaturate(window->Size.y / ImMax(window->SizeContents.y, window->Size.y)), style.GrabMinSize), scrollbar_height);
  3083. const float grab_h_norm = grab_h_pixels / scrollbar_height;
  3084. // Handle input right away. None of the code of Begin() is relying on scrolling position before calling Scrollbar().
  3085. bool held = false;
  3086. bool hovered = false;
  3087. const bool previously_held = (g.ActiveId == id);
  3088. ButtonBehavior(bb, id, &hovered, &held, true);
  3089. const float scroll_max = ImMax(1.0f, window->SizeContents.y - window->Size.y);
  3090. float scroll_ratio = ImSaturate(window->ScrollY / scroll_max);
  3091. float grab_y_norm = scroll_ratio * (scrollbar_height - grab_h_pixels) / scrollbar_height;
  3092. if (held)
  3093. {
  3094. const float clicked_y_norm = ImSaturate((g.IO.MousePos.y - bb.Min.y) / scrollbar_height); // Click position in scrollbar space (0.0f->1.0f)
  3095. g.HoveredId = id;
  3096. bool seek_absolute = false;
  3097. if (!previously_held)
  3098. {
  3099. // On initial click calculate the distance between mouse and the center of the grab
  3100. if (clicked_y_norm >= grab_y_norm && clicked_y_norm <= grab_y_norm + grab_h_norm)
  3101. {
  3102. g.ScrollbarClickDeltaToGrabCenter = clicked_y_norm - grab_y_norm - grab_h_norm*0.5f;
  3103. }
  3104. else
  3105. {
  3106. seek_absolute = true;
  3107. g.ScrollbarClickDeltaToGrabCenter = 0;
  3108. }
  3109. }
  3110. // Apply scroll
  3111. const float scroll_y_norm = ImSaturate((clicked_y_norm - g.ScrollbarClickDeltaToGrabCenter - grab_h_norm*0.5f) / (1.0f - grab_h_norm));
  3112. window->ScrollY = (float)(int)(0.5f + scroll_y_norm * (window->SizeContents.y - window->Size.y));
  3113. window->NextScrollY = window->ScrollY;
  3114. // Update values for rendering
  3115. scroll_ratio = ImSaturate(window->ScrollY / scroll_max);
  3116. grab_y_norm = scroll_ratio * (scrollbar_height - grab_h_pixels) / scrollbar_height;
  3117. // Update distance to grab now that we have seeked and saturated
  3118. if (seek_absolute)
  3119. g.ScrollbarClickDeltaToGrabCenter = clicked_y_norm - grab_y_norm - grab_h_norm*0.5f;
  3120. }
  3121. // Render
  3122. const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab);
  3123. 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);
  3124. }
  3125. // Moving window to front of display (which happens to be back of our sorted list)
  3126. static void FocusWindow(ImGuiWindow* window)
  3127. {
  3128. ImGuiState& g = *GImGui;
  3129. // Always mark the window we passed as focused. This is used for keyboard interactions such as tabbing.
  3130. g.FocusedWindow = window;
  3131. // Passing NULL allow to disable keyboard focus
  3132. if (!window)
  3133. return;
  3134. // And move its root window to the top of the pile
  3135. if (window->RootWindow)
  3136. window = window->RootWindow;
  3137. if (g.Windows.back() == window)
  3138. return;
  3139. for (size_t i = 0; i < g.Windows.size(); i++)
  3140. if (g.Windows[i] == window)
  3141. {
  3142. g.Windows.erase(g.Windows.begin() + i);
  3143. break;
  3144. }
  3145. g.Windows.push_back(window);
  3146. }
  3147. void ImGui::PushItemWidth(float item_width)
  3148. {
  3149. ImGuiWindow* window = GetCurrentWindow();
  3150. window->DC.ItemWidth.push_back(item_width == 0.0f ? window->ItemWidthDefault : item_width);
  3151. }
  3152. void ImGui::PopItemWidth()
  3153. {
  3154. ImGuiWindow* window = GetCurrentWindow();
  3155. window->DC.ItemWidth.pop_back();
  3156. }
  3157. float ImGui::CalcItemWidth()
  3158. {
  3159. ImGuiWindow* window = GetCurrentWindow();
  3160. float w = window->DC.ItemWidth.back();
  3161. if (w < 0.0f)
  3162. {
  3163. // 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.
  3164. ImGuiState& g = *GImGui;
  3165. w = -w;
  3166. float width_to_right_edge = window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x;
  3167. w = ImMax(1.0f, width_to_right_edge - w - g.Style.FramePadding.x * 2.0f);
  3168. }
  3169. w = (float)(int)w;
  3170. return w;
  3171. }
  3172. static void SetFont(ImFont* font)
  3173. {
  3174. ImGuiState& g = *GImGui;
  3175. IM_ASSERT(font && font->IsLoaded());
  3176. IM_ASSERT(font->Scale > 0.0f);
  3177. g.Font = font;
  3178. g.FontBaseSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale;
  3179. g.FontSize = g.CurrentWindow ? g.CurrentWindow->CalcFontSize() : 0.0f;
  3180. g.FontTexUvWhitePixel = g.Font->ContainerAtlas->TexUvWhitePixel;
  3181. }
  3182. void ImGui::PushFont(ImFont* font)
  3183. {
  3184. ImGuiState& g = *GImGui;
  3185. if (!font)
  3186. font = g.IO.Fonts->Fonts[0];
  3187. SetFont(font);
  3188. g.FontStack.push_back(font);
  3189. g.CurrentWindow->DrawList->PushTextureID(font->ContainerAtlas->TexID);
  3190. }
  3191. void ImGui::PopFont()
  3192. {
  3193. ImGuiState& g = *GImGui;
  3194. g.CurrentWindow->DrawList->PopTextureID();
  3195. g.FontStack.pop_back();
  3196. SetFont(g.FontStack.empty() ? g.IO.Fonts->Fonts[0] : g.FontStack.back());
  3197. }
  3198. void ImGui::PushAllowKeyboardFocus(bool allow_keyboard_focus)
  3199. {
  3200. ImGuiWindow* window = GetCurrentWindow();
  3201. window->DC.AllowKeyboardFocus.push_back(allow_keyboard_focus);
  3202. }
  3203. void ImGui::PopAllowKeyboardFocus()
  3204. {
  3205. ImGuiWindow* window = GetCurrentWindow();
  3206. window->DC.AllowKeyboardFocus.pop_back();
  3207. }
  3208. void ImGui::PushTextWrapPos(float wrap_x)
  3209. {
  3210. ImGuiWindow* window = GetCurrentWindow();
  3211. window->DC.TextWrapPos.push_back(wrap_x);
  3212. }
  3213. void ImGui::PopTextWrapPos()
  3214. {
  3215. ImGuiWindow* window = GetCurrentWindow();
  3216. window->DC.TextWrapPos.pop_back();
  3217. }
  3218. void ImGui::PushStyleColor(ImGuiCol idx, const ImVec4& col)
  3219. {
  3220. ImGuiState& g = *GImGui;
  3221. ImGuiColMod backup;
  3222. backup.Col = idx;
  3223. backup.PreviousValue = g.Style.Colors[idx];
  3224. g.ColorModifiers.push_back(backup);
  3225. g.Style.Colors[idx] = col;
  3226. }
  3227. void ImGui::PopStyleColor(int count)
  3228. {
  3229. ImGuiState& g = *GImGui;
  3230. while (count > 0)
  3231. {
  3232. ImGuiColMod& backup = g.ColorModifiers.back();
  3233. g.Style.Colors[backup.Col] = backup.PreviousValue;
  3234. g.ColorModifiers.pop_back();
  3235. count--;
  3236. }
  3237. }
  3238. static float* GetStyleVarFloatAddr(ImGuiStyleVar idx)
  3239. {
  3240. ImGuiState& g = *GImGui;
  3241. switch (idx)
  3242. {
  3243. case ImGuiStyleVar_Alpha: return &g.Style.Alpha;
  3244. case ImGuiStyleVar_WindowRounding: return &g.Style.WindowRounding;
  3245. case ImGuiStyleVar_ChildWindowRounding: return &g.Style.ChildWindowRounding;
  3246. case ImGuiStyleVar_FrameRounding: return &g.Style.FrameRounding;
  3247. case ImGuiStyleVar_IndentSpacing: return &g.Style.IndentSpacing;
  3248. case ImGuiStyleVar_GrabMinSize: return &g.Style.GrabMinSize;
  3249. }
  3250. return NULL;
  3251. }
  3252. static ImVec2* GetStyleVarVec2Addr(ImGuiStyleVar idx)
  3253. {
  3254. ImGuiState& g = *GImGui;
  3255. switch (idx)
  3256. {
  3257. case ImGuiStyleVar_WindowPadding: return &g.Style.WindowPadding;
  3258. case ImGuiStyleVar_FramePadding: return &g.Style.FramePadding;
  3259. case ImGuiStyleVar_ItemSpacing: return &g.Style.ItemSpacing;
  3260. case ImGuiStyleVar_ItemInnerSpacing: return &g.Style.ItemInnerSpacing;
  3261. }
  3262. return NULL;
  3263. }
  3264. void ImGui::PushStyleVar(ImGuiStyleVar idx, float val)
  3265. {
  3266. ImGuiState& g = *GImGui;
  3267. float* pvar = GetStyleVarFloatAddr(idx);
  3268. IM_ASSERT(pvar != NULL); // Called function with wrong-type? Variable is not a float.
  3269. ImGuiStyleMod backup;
  3270. backup.Var = idx;
  3271. backup.PreviousValue = ImVec2(*pvar, 0.0f);
  3272. g.StyleModifiers.push_back(backup);
  3273. *pvar = val;
  3274. }
  3275. void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
  3276. {
  3277. ImGuiState& g = *GImGui;
  3278. ImVec2* pvar = GetStyleVarVec2Addr(idx);
  3279. IM_ASSERT(pvar != NULL); // Called function with wrong-type? Variable is not a ImVec2.
  3280. ImGuiStyleMod backup;
  3281. backup.Var = idx;
  3282. backup.PreviousValue = *pvar;
  3283. g.StyleModifiers.push_back(backup);
  3284. *pvar = val;
  3285. }
  3286. void ImGui::PopStyleVar(int count)
  3287. {
  3288. ImGuiState& g = *GImGui;
  3289. while (count > 0)
  3290. {
  3291. ImGuiStyleMod& backup = g.StyleModifiers.back();
  3292. if (float* pvar_f = GetStyleVarFloatAddr(backup.Var))
  3293. *pvar_f = backup.PreviousValue.x;
  3294. else if (ImVec2* pvar_v = GetStyleVarVec2Addr(backup.Var))
  3295. *pvar_v = backup.PreviousValue;
  3296. g.StyleModifiers.pop_back();
  3297. count--;
  3298. }
  3299. }
  3300. const char* ImGui::GetStyleColName(ImGuiCol idx)
  3301. {
  3302. // Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1";
  3303. switch (idx)
  3304. {
  3305. case ImGuiCol_Text: return "Text";
  3306. case ImGuiCol_WindowBg: return "WindowBg";
  3307. case ImGuiCol_ChildWindowBg: return "ChildWindowBg";
  3308. case ImGuiCol_Border: return "Border";
  3309. case ImGuiCol_BorderShadow: return "BorderShadow";
  3310. case ImGuiCol_FrameBg: return "FrameBg";
  3311. case ImGuiCol_FrameBgHovered: return "FrameBgHovered";
  3312. case ImGuiCol_FrameBgActive: return "FrameBgActive";
  3313. case ImGuiCol_TitleBg: return "TitleBg";
  3314. case ImGuiCol_TitleBgCollapsed: return "TitleBgCollapsed";
  3315. case ImGuiCol_ScrollbarBg: return "ScrollbarBg";
  3316. case ImGuiCol_ScrollbarGrab: return "ScrollbarGrab";
  3317. case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered";
  3318. case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive";
  3319. case ImGuiCol_ComboBg: return "ComboBg";
  3320. case ImGuiCol_CheckMark: return "CheckMark";
  3321. case ImGuiCol_SliderGrab: return "SliderGrab";
  3322. case ImGuiCol_SliderGrabActive: return "SliderGrabActive";
  3323. case ImGuiCol_Button: return "Button";
  3324. case ImGuiCol_ButtonHovered: return "ButtonHovered";
  3325. case ImGuiCol_ButtonActive: return "ButtonActive";
  3326. case ImGuiCol_Header: return "Header";
  3327. case ImGuiCol_HeaderHovered: return "HeaderHovered";
  3328. case ImGuiCol_HeaderActive: return "HeaderActive";
  3329. case ImGuiCol_Column: return "Column";
  3330. case ImGuiCol_ColumnHovered: return "ColumnHovered";
  3331. case ImGuiCol_ColumnActive: return "ColumnActive";
  3332. case ImGuiCol_ResizeGrip: return "ResizeGrip";
  3333. case ImGuiCol_ResizeGripHovered: return "ResizeGripHovered";
  3334. case ImGuiCol_ResizeGripActive: return "ResizeGripActive";
  3335. case ImGuiCol_CloseButton: return "CloseButton";
  3336. case ImGuiCol_CloseButtonHovered: return "CloseButtonHovered";
  3337. case ImGuiCol_CloseButtonActive: return "CloseButtonActive";
  3338. case ImGuiCol_PlotLines: return "PlotLines";
  3339. case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered";
  3340. case ImGuiCol_PlotHistogram: return "PlotHistogram";
  3341. case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered";
  3342. case ImGuiCol_TextSelectedBg: return "TextSelectedBg";
  3343. case ImGuiCol_TooltipBg: return "TooltipBg";
  3344. }
  3345. IM_ASSERT(0);
  3346. return "Unknown";
  3347. }
  3348. bool ImGui::IsWindowFocused()
  3349. {
  3350. ImGuiState& g = *GImGui;
  3351. ImGuiWindow* window = GetCurrentWindow();
  3352. return g.FocusedWindow == window;
  3353. }
  3354. bool ImGui::IsRootWindowFocused()
  3355. {
  3356. ImGuiState& g = *GImGui;
  3357. ImGuiWindow* root_window = GetCurrentWindow()->RootWindow;
  3358. return g.FocusedWindow == root_window;
  3359. }
  3360. bool ImGui::IsRootWindowOrAnyChildFocused()
  3361. {
  3362. ImGuiState& g = *GImGui;
  3363. ImGuiWindow* root_window = GetCurrentWindow()->RootWindow;
  3364. return g.FocusedWindow && g.FocusedWindow->RootWindow == root_window;
  3365. }
  3366. float ImGui::GetWindowWidth()
  3367. {
  3368. ImGuiWindow* window = GetCurrentWindow();
  3369. return window->Size.x;
  3370. }
  3371. ImVec2 ImGui::GetWindowPos()
  3372. {
  3373. ImGuiWindow* window = GetCurrentWindow();
  3374. return window->Pos;
  3375. }
  3376. static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiSetCond cond)
  3377. {
  3378. // Test condition (NB: bit 0 is always true) and clear flags for next time
  3379. if (cond && (window->SetWindowPosAllowFlags & cond) == 0)
  3380. return;
  3381. window->SetWindowPosAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver);
  3382. // Set
  3383. const ImVec2 old_pos = window->Pos;
  3384. window->PosFloat = pos;
  3385. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  3386. 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
  3387. window->DC.CursorMaxPos += (window->Pos - old_pos); // And more importantly we need to adjust this so size calculation doesn't get affected.
  3388. }
  3389. void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCond cond)
  3390. {
  3391. ImGuiWindow* window = GetCurrentWindow();
  3392. SetWindowPos(window, pos, cond);
  3393. }
  3394. void ImGui::SetWindowPos(const char* name, const ImVec2& pos, ImGuiSetCond cond)
  3395. {
  3396. ImGuiWindow* window = FindWindowByName(name);
  3397. if (window)
  3398. SetWindowPos(window, pos, cond);
  3399. }
  3400. ImVec2 ImGui::GetWindowSize()
  3401. {
  3402. ImGuiWindow* window = GetCurrentWindow();
  3403. return window->Size;
  3404. }
  3405. static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiSetCond cond)
  3406. {
  3407. // Test condition (NB: bit 0 is always true) and clear flags for next time
  3408. if (cond && (window->SetWindowSizeAllowFlags & cond) == 0)
  3409. return;
  3410. window->SetWindowSizeAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver);
  3411. // Set
  3412. if (ImLengthSqr(size) > 0.00001f)
  3413. {
  3414. window->SizeFull = size;
  3415. window->AutoFitFrames = 0;
  3416. }
  3417. else
  3418. {
  3419. // Autofit
  3420. window->AutoFitFrames = 2;
  3421. window->AutoFitOnlyGrows = false;
  3422. }
  3423. }
  3424. void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCond cond)
  3425. {
  3426. ImGuiWindow* window = GetCurrentWindow();
  3427. SetWindowSize(window, size, cond);
  3428. }
  3429. void ImGui::SetWindowSize(const char* name, const ImVec2& size, ImGuiSetCond cond)
  3430. {
  3431. ImGuiWindow* window = FindWindowByName(name);
  3432. if (window)
  3433. SetWindowSize(window, size, cond);
  3434. }
  3435. static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiSetCond cond)
  3436. {
  3437. // Test condition (NB: bit 0 is always true) and clear flags for next time
  3438. if (cond && (window->SetWindowCollapsedAllowFlags & cond) == 0)
  3439. return;
  3440. window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver);
  3441. // Set
  3442. window->Collapsed = collapsed;
  3443. }
  3444. void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCond cond)
  3445. {
  3446. ImGuiWindow* window = GetCurrentWindow();
  3447. SetWindowCollapsed(window, collapsed, cond);
  3448. }
  3449. bool ImGui::GetWindowCollapsed()
  3450. {
  3451. ImGuiWindow* window = GetCurrentWindow();
  3452. return window->Collapsed;
  3453. }
  3454. void ImGui::SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCond cond)
  3455. {
  3456. ImGuiWindow* window = FindWindowByName(name);
  3457. if (window)
  3458. SetWindowCollapsed(window, collapsed, cond);
  3459. }
  3460. void ImGui::SetWindowFocus()
  3461. {
  3462. ImGuiWindow* window = GetCurrentWindow();
  3463. FocusWindow(window);
  3464. }
  3465. void ImGui::SetWindowFocus(const char* name)
  3466. {
  3467. if (name)
  3468. {
  3469. ImGuiWindow* window = FindWindowByName(name);
  3470. if (window)
  3471. FocusWindow(window);
  3472. }
  3473. else
  3474. {
  3475. FocusWindow(NULL);
  3476. }
  3477. }
  3478. void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond)
  3479. {
  3480. ImGuiState& g = *GImGui;
  3481. g.SetNextWindowPosVal = pos;
  3482. g.SetNextWindowPosCond = cond ? cond : ImGuiSetCond_Always;
  3483. }
  3484. void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond)
  3485. {
  3486. ImGuiState& g = *GImGui;
  3487. g.SetNextWindowSizeVal = size;
  3488. g.SetNextWindowSizeCond = cond ? cond : ImGuiSetCond_Always;
  3489. }
  3490. void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond)
  3491. {
  3492. ImGuiState& g = *GImGui;
  3493. g.SetNextWindowCollapsedVal = collapsed;
  3494. g.SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCond_Always;
  3495. }
  3496. void ImGui::SetNextWindowFocus()
  3497. {
  3498. ImGuiState& g = *GImGui;
  3499. g.SetNextWindowFocus = true;
  3500. }
  3501. ImVec2 ImGui::GetContentRegionMax()
  3502. {
  3503. ImGuiWindow* window = GetCurrentWindow();
  3504. ImVec2 window_padding = window->WindowPadding();
  3505. ImVec2 mx = window->Size - window_padding;
  3506. if (window->DC.ColumnsCount != 1)
  3507. {
  3508. mx.x = ImGui::GetColumnOffset(window->DC.ColumnsCurrent + 1);
  3509. mx.x -= window_padding.x;
  3510. }
  3511. else
  3512. {
  3513. if (window->ScrollbarY)
  3514. mx.x -= GImGui->Style.ScrollbarWidth;
  3515. }
  3516. return mx;
  3517. }
  3518. ImVec2 ImGui::GetWindowContentRegionMin()
  3519. {
  3520. ImGuiWindow* window = GetCurrentWindow();
  3521. return ImVec2(0, window->TitleBarHeight()) + window->WindowPadding();
  3522. }
  3523. ImVec2 ImGui::GetWindowContentRegionMax()
  3524. {
  3525. ImGuiWindow* window = GetCurrentWindow();
  3526. ImVec2 m = window->Size - window->WindowPadding();
  3527. if (window->ScrollbarY)
  3528. m.x -= GImGui->Style.ScrollbarWidth;
  3529. return m;
  3530. }
  3531. float ImGui::GetTextLineHeight()
  3532. {
  3533. ImGuiState& g = *GImGui;
  3534. return g.FontSize;
  3535. }
  3536. float ImGui::GetTextLineHeightWithSpacing()
  3537. {
  3538. ImGuiState& g = *GImGui;
  3539. return g.FontSize + g.Style.ItemSpacing.y;
  3540. }
  3541. ImDrawList* ImGui::GetWindowDrawList()
  3542. {
  3543. ImGuiWindow* window = GetCurrentWindow();
  3544. return window->DrawList;
  3545. }
  3546. ImFont* ImGui::GetWindowFont()
  3547. {
  3548. ImGuiState& g = *GImGui;
  3549. return g.Font;
  3550. }
  3551. float ImGui::GetWindowFontSize()
  3552. {
  3553. ImGuiState& g = *GImGui;
  3554. return g.FontSize;
  3555. }
  3556. void ImGui::SetWindowFontScale(float scale)
  3557. {
  3558. ImGuiState& g = *GImGui;
  3559. ImGuiWindow* window = GetCurrentWindow();
  3560. window->FontWindowScale = scale;
  3561. g.FontSize = window->CalcFontSize();
  3562. }
  3563. // NB: internally we store CursorPos in absolute screen coordinates because it is more convenient.
  3564. // Conversion happens as we pass the value to user, but it makes our naming convention dodgy. May want to rename 'DC.CursorPos'.
  3565. ImVec2 ImGui::GetCursorPos()
  3566. {
  3567. ImGuiWindow* window = GetCurrentWindow();
  3568. return window->DC.CursorPos - window->Pos;
  3569. }
  3570. float ImGui::GetCursorPosX()
  3571. {
  3572. return ImGui::GetCursorPos().x;
  3573. }
  3574. float ImGui::GetCursorPosY()
  3575. {
  3576. return ImGui::GetCursorPos().y;
  3577. }
  3578. void ImGui::SetCursorPos(const ImVec2& pos)
  3579. {
  3580. ImGuiWindow* window = GetCurrentWindow();
  3581. window->DC.CursorPos = window->Pos + pos;
  3582. window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos);
  3583. }
  3584. void ImGui::SetCursorPosX(float x)
  3585. {
  3586. ImGuiWindow* window = GetCurrentWindow();
  3587. window->DC.CursorPos.x = window->Pos.x + x;
  3588. window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPos.x);
  3589. }
  3590. void ImGui::SetCursorPosY(float y)
  3591. {
  3592. ImGuiWindow* window = GetCurrentWindow();
  3593. window->DC.CursorPos.y = window->Pos.y + y;
  3594. window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y);
  3595. }
  3596. ImVec2 ImGui::GetCursorScreenPos()
  3597. {
  3598. ImGuiWindow* window = GetCurrentWindow();
  3599. return window->DC.CursorPos;
  3600. }
  3601. void ImGui::SetCursorScreenPos(const ImVec2& screen_pos)
  3602. {
  3603. ImGuiWindow* window = GetCurrentWindow();
  3604. window->DC.CursorPos = screen_pos;
  3605. }
  3606. float ImGui::GetScrollPosY()
  3607. {
  3608. ImGuiWindow* window = GetCurrentWindow();
  3609. return window->ScrollY;
  3610. }
  3611. float ImGui::GetScrollMaxY()
  3612. {
  3613. ImGuiWindow* window = GetCurrentWindow();
  3614. return window->SizeContents.y - window->SizeFull.y;
  3615. }
  3616. void ImGui::SetScrollPosHere()
  3617. {
  3618. ImGuiWindow* window = GetCurrentWindow();
  3619. window->NextScrollY = (window->DC.CursorPos.y + window->ScrollY) - (window->Pos.y + window->SizeFull.y * 0.5f) - (window->TitleBarHeight() + window->WindowPadding().y);
  3620. }
  3621. void ImGui::SetKeyboardFocusHere(int offset)
  3622. {
  3623. ImGuiWindow* window = GetCurrentWindow();
  3624. window->FocusIdxAllRequestNext = window->FocusIdxAllCounter + 1 + offset;
  3625. window->FocusIdxTabRequestNext = IM_INT_MAX;
  3626. }
  3627. void ImGui::SetStateStorage(ImGuiStorage* tree)
  3628. {
  3629. ImGuiWindow* window = GetCurrentWindow();
  3630. window->DC.StateStorage = tree ? tree : &window->StateStorage;
  3631. }
  3632. ImGuiStorage* ImGui::GetStateStorage()
  3633. {
  3634. ImGuiWindow* window = GetCurrentWindow();
  3635. return window->DC.StateStorage;
  3636. }
  3637. void ImGui::TextV(const char* fmt, va_list args)
  3638. {
  3639. ImGuiState& g = *GImGui;
  3640. ImGuiWindow* window = GetCurrentWindow();
  3641. if (window->SkipItems)
  3642. return;
  3643. const char* text_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  3644. TextUnformatted(g.TempBuffer, text_end);
  3645. }
  3646. void ImGui::Text(const char* fmt, ...)
  3647. {
  3648. va_list args;
  3649. va_start(args, fmt);
  3650. TextV(fmt, args);
  3651. va_end(args);
  3652. }
  3653. void ImGui::TextColoredV(const ImVec4& col, const char* fmt, va_list args)
  3654. {
  3655. ImGui::PushStyleColor(ImGuiCol_Text, col);
  3656. TextV(fmt, args);
  3657. ImGui::PopStyleColor();
  3658. }
  3659. void ImGui::TextColored(const ImVec4& col, const char* fmt, ...)
  3660. {
  3661. va_list args;
  3662. va_start(args, fmt);
  3663. TextColoredV(col, fmt, args);
  3664. va_end(args);
  3665. }
  3666. void ImGui::TextWrappedV(const char* fmt, va_list args)
  3667. {
  3668. ImGui::PushTextWrapPos(0.0f);
  3669. TextV(fmt, args);
  3670. ImGui::PopTextWrapPos();
  3671. }
  3672. void ImGui::TextWrapped(const char* fmt, ...)
  3673. {
  3674. va_list args;
  3675. va_start(args, fmt);
  3676. TextWrappedV(fmt, args);
  3677. va_end(args);
  3678. }
  3679. void ImGui::TextUnformatted(const char* text, const char* text_end)
  3680. {
  3681. ImGuiState& g = *GImGui;
  3682. ImGuiWindow* window = GetCurrentWindow();
  3683. if (window->SkipItems)
  3684. return;
  3685. IM_ASSERT(text != NULL);
  3686. const char* text_begin = text;
  3687. if (text_end == NULL)
  3688. text_end = text + strlen(text); // FIXME-OPT
  3689. const float wrap_pos_x = window->DC.TextWrapPos.back();
  3690. const bool wrap_enabled = wrap_pos_x >= 0.0f;
  3691. if (text_end - text > 2000 && !wrap_enabled)
  3692. {
  3693. // Long text!
  3694. // Perform manual coarse clipping to optimize for long multi-line text
  3695. // From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled.
  3696. // 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.
  3697. const char* line = text;
  3698. const float line_height = ImGui::GetTextLineHeight();
  3699. const ImVec2 text_pos = window->DC.CursorPos + ImVec2(0.0f, window->DC.CurrentLineTextBaseOffset);
  3700. const ImVec4 clip_rect = window->ClipRectStack.back();
  3701. ImVec2 text_size(0,0);
  3702. if (text_pos.y <= clip_rect.w)
  3703. {
  3704. ImVec2 pos = text_pos;
  3705. // Lines to skip (can't skip when logging text)
  3706. if (!g.LogEnabled)
  3707. {
  3708. int lines_skippable = (int)((clip_rect.y - text_pos.y) / line_height) - 1;
  3709. if (lines_skippable > 0)
  3710. {
  3711. int lines_skipped = 0;
  3712. while (line < text_end && lines_skipped <= lines_skippable)
  3713. {
  3714. const char* line_end = strchr(line, '\n');
  3715. line = line_end + 1;
  3716. lines_skipped++;
  3717. }
  3718. pos.y += lines_skipped * line_height;
  3719. }
  3720. }
  3721. // Lines to render
  3722. if (line < text_end)
  3723. {
  3724. ImRect line_rect(pos, pos + ImVec2(ImGui::GetWindowWidth(), line_height));
  3725. while (line < text_end)
  3726. {
  3727. const char* line_end = strchr(line, '\n');
  3728. if (IsClippedEx(line_rect, NULL, false))
  3729. break;
  3730. const ImVec2 line_size = CalcTextSize(line, line_end, false);
  3731. text_size.x = ImMax(text_size.x, line_size.x);
  3732. RenderText(pos, line, line_end, false);
  3733. if (!line_end)
  3734. line_end = text_end;
  3735. line = line_end + 1;
  3736. line_rect.Min.y += line_height;
  3737. line_rect.Max.y += line_height;
  3738. pos.y += line_height;
  3739. }
  3740. // Count remaining lines
  3741. int lines_skipped = 0;
  3742. while (line < text_end)
  3743. {
  3744. const char* line_end = strchr(line, '\n');
  3745. if (!line_end)
  3746. line_end = text_end;
  3747. line = line_end + 1;
  3748. lines_skipped++;
  3749. }
  3750. pos.y += lines_skipped * line_height;
  3751. }
  3752. text_size.y += (pos - text_pos).y;
  3753. }
  3754. ImRect bb(text_pos, text_pos + text_size);
  3755. ItemSize(bb);
  3756. ItemAdd(bb, NULL);
  3757. }
  3758. else
  3759. {
  3760. const float wrap_width = wrap_enabled ? CalcWrapWidthForPos(window->DC.CursorPos, wrap_pos_x) : 0.0f;
  3761. const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width);
  3762. // Account of baseline offset
  3763. ImVec2 text_pos = window->DC.CursorPos;
  3764. text_pos.y += window->DC.CurrentLineTextBaseOffset;
  3765. ImRect bb(text_pos, text_pos + text_size);
  3766. ItemSize(bb.GetSize());
  3767. if (!ItemAdd(bb, NULL))
  3768. return;
  3769. // Render (we don't hide text after ## in this end-user function)
  3770. RenderTextWrapped(bb.Min, text_begin, text_end, wrap_width);
  3771. }
  3772. }
  3773. void ImGui::AlignFirstTextHeightToWidgets()
  3774. {
  3775. ImGuiState& g = *GImGui;
  3776. ImGuiWindow* window = GetCurrentWindow();
  3777. if (window->SkipItems)
  3778. return;
  3779. // Declare a dummy item size to that upcoming items that are smaller will center-align on the newly expanded line height.
  3780. ItemSize(ImVec2(0, g.FontSize + g.Style.FramePadding.y*2), g.Style.FramePadding.y);
  3781. ImGui::SameLine(0, 0);
  3782. }
  3783. // Add a label+text combo aligned to other label+value widgets
  3784. void ImGui::LabelTextV(const char* label, const char* fmt, va_list args)
  3785. {
  3786. ImGuiState& g = *GImGui;
  3787. ImGuiWindow* window = GetCurrentWindow();
  3788. if (window->SkipItems)
  3789. return;
  3790. const ImGuiStyle& style = g.Style;
  3791. const float w = ImGui::CalcItemWidth();
  3792. const char* value_text_begin = &g.TempBuffer[0];
  3793. const char* value_text_end = value_text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  3794. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  3795. const ImRect value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, label_size.y + style.FramePadding.y*2));
  3796. 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);
  3797. ItemSize(total_bb, style.FramePadding.y);
  3798. if (!ItemAdd(total_bb, NULL))
  3799. return;
  3800. // Render
  3801. RenderTextClipped(ImVec2(value_bb.Min.x, value_bb.Min.y + style.FramePadding.y), value_text_begin, value_text_end, NULL, value_bb.Max);
  3802. RenderText(ImVec2(value_bb.Max.x + style.ItemInnerSpacing.x, value_bb.Min.y + style.FramePadding.y), label);
  3803. }
  3804. void ImGui::LabelText(const char* label, const char* fmt, ...)
  3805. {
  3806. va_list args;
  3807. va_start(args, fmt);
  3808. LabelTextV(label, fmt, args);
  3809. va_end(args);
  3810. }
  3811. static inline bool IsWindowContentHoverable(ImGuiWindow* window)
  3812. {
  3813. ImGuiState& g = *GImGui;
  3814. // An active popup disable hovering on other windows (apart from its own children)
  3815. if (ImGuiWindow* focused_window = g.FocusedWindow)
  3816. if (ImGuiWindow* focused_root_window = focused_window->RootWindow)
  3817. if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) != 0 && focused_root_window->WasVisible && focused_root_window != window->RootWindow)
  3818. return false;
  3819. return true;
  3820. }
  3821. static bool IsHovered(const ImRect& bb, ImGuiID id)
  3822. {
  3823. ImGuiState& g = *GImGui;
  3824. if (g.HoveredId == 0)
  3825. {
  3826. ImGuiWindow* window = GetCurrentWindow();
  3827. if (g.HoveredRootWindow == window->RootWindow)
  3828. if ((g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdIsFocusedOnly) && IsMouseHoveringRect(bb))
  3829. if (IsWindowContentHoverable(g.HoveredRootWindow))
  3830. return true;
  3831. }
  3832. return false;
  3833. }
  3834. static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat, bool pressed_on_click)
  3835. {
  3836. ImGuiState& g = *GImGui;
  3837. ImGuiWindow* window = GetCurrentWindow();
  3838. const bool hovered = IsHovered(bb, id);
  3839. bool pressed = false;
  3840. if (hovered)
  3841. {
  3842. g.HoveredId = id;
  3843. if (allow_key_modifiers || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt))
  3844. {
  3845. if (g.IO.MouseClicked[0])
  3846. {
  3847. if (pressed_on_click)
  3848. {
  3849. pressed = true;
  3850. SetActiveId(0);
  3851. }
  3852. else
  3853. {
  3854. SetActiveId(id);
  3855. }
  3856. FocusWindow(window);
  3857. }
  3858. else if (repeat && g.ActiveId && ImGui::IsMouseClicked(0, true))
  3859. {
  3860. pressed = true;
  3861. }
  3862. }
  3863. }
  3864. bool held = false;
  3865. if (g.ActiveId == id)
  3866. {
  3867. if (g.IO.MouseDown[0])
  3868. {
  3869. held = true;
  3870. }
  3871. else
  3872. {
  3873. if (hovered)
  3874. pressed = true;
  3875. SetActiveId(0);
  3876. }
  3877. }
  3878. if (out_hovered) *out_hovered = hovered;
  3879. if (out_held) *out_held = held;
  3880. return pressed;
  3881. }
  3882. bool ImGui::Button(const char* label, const ImVec2& size_arg, bool repeat_when_held)
  3883. {
  3884. ImGuiState& g = *GImGui;
  3885. ImGuiWindow* window = GetCurrentWindow();
  3886. if (window->SkipItems)
  3887. return false;
  3888. const ImGuiStyle& style = g.Style;
  3889. const ImGuiID id = window->GetID(label);
  3890. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  3891. 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));
  3892. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
  3893. ItemSize(bb, style.FramePadding.y);
  3894. if (!ItemAdd(bb, &id))
  3895. return false;
  3896. bool hovered, held;
  3897. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true, repeat_when_held);
  3898. // Render
  3899. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  3900. RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
  3901. 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)
  3902. 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)
  3903. return pressed;
  3904. }
  3905. // Small buttons fits within text without additional spacing.
  3906. bool ImGui::SmallButton(const char* label)
  3907. {
  3908. ImGuiState& g = *GImGui;
  3909. ImGuiWindow* window = GetCurrentWindow();
  3910. if (window->SkipItems)
  3911. return false;
  3912. const ImGuiStyle& style = g.Style;
  3913. const ImGuiID id = window->GetID(label);
  3914. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  3915. ImVec2 text_pos = window->DC.CursorPos;
  3916. text_pos.y += window->DC.CurrentLineTextBaseOffset;
  3917. ImRect bb(text_pos, text_pos + label_size + ImVec2(style.FramePadding.x*2,0));
  3918. ItemSize(bb);
  3919. if (!ItemAdd(bb, &id))
  3920. return false;
  3921. bool hovered, held;
  3922. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  3923. // Render
  3924. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  3925. RenderFrame(bb.Min, bb.Max, col);
  3926. RenderText(bb.Min + ImVec2(style.FramePadding.x,0), label);
  3927. return pressed;
  3928. }
  3929. // Tip: use ImGui::PushID()/PopID() to push indices or pointers in the ID stack.
  3930. // 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)
  3931. bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size)
  3932. {
  3933. ImGuiWindow* window = GetCurrentWindow();
  3934. if (window->SkipItems)
  3935. return false;
  3936. const ImGuiID id = window->GetID(str_id);
  3937. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
  3938. ItemSize(bb);
  3939. if (!ItemAdd(bb, &id))
  3940. return false;
  3941. bool hovered, held;
  3942. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  3943. return pressed;
  3944. }
  3945. // Upper-right button to close a window.
  3946. static bool CloseWindowButton(bool* p_opened)
  3947. {
  3948. ImGuiWindow* window = GetCurrentWindow();
  3949. const ImGuiID id = window->GetID("#CLOSE");
  3950. const float size = window->TitleBarHeight() - 4.0f;
  3951. const ImRect bb(window->Rect().GetTR() + ImVec2(-3.0f-size,2.0f), window->Rect().GetTR() + ImVec2(-3.0f,2.0f+size));
  3952. bool hovered, held;
  3953. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  3954. // Render
  3955. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton);
  3956. const ImVec2 center = bb.GetCenter();
  3957. window->DrawList->AddCircleFilled(center, ImMax(2.0f,size*0.5f), col, 16);
  3958. const float cross_extent = (size * 0.5f * 0.7071f) - 1.0f;
  3959. if (hovered)
  3960. {
  3961. window->DrawList->AddLine(center + ImVec2(+cross_extent,+cross_extent), center + ImVec2(-cross_extent,-cross_extent), window->Color(ImGuiCol_Text));
  3962. window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), window->Color(ImGuiCol_Text));
  3963. }
  3964. if (p_opened != NULL && pressed)
  3965. *p_opened = !*p_opened;
  3966. return pressed;
  3967. }
  3968. void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col)
  3969. {
  3970. ImGuiWindow* window = GetCurrentWindow();
  3971. if (window->SkipItems)
  3972. return;
  3973. ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
  3974. if (border_col.w > 0.0f)
  3975. bb.Max += ImVec2(2,2);
  3976. ItemSize(bb);
  3977. if (!ItemAdd(bb, NULL))
  3978. return;
  3979. if (border_col.w > 0.0f)
  3980. {
  3981. window->DrawList->AddRect(bb.Min, bb.Max, window->Color(border_col), 0.0f);
  3982. window->DrawList->AddImage(user_texture_id, bb.Min+ImVec2(1,1), bb.Max-ImVec2(1,1), uv0, uv1, window->Color(tint_col));
  3983. }
  3984. else
  3985. {
  3986. window->DrawList->AddImage(user_texture_id, bb.Min, bb.Max, uv0, uv1, window->Color(tint_col));
  3987. }
  3988. }
  3989. // frame_padding < 0: uses FramePadding from style (default)
  3990. // frame_padding = 0: no framing
  3991. // frame_padding > 0: set framing size
  3992. // The color used are the button colors.
  3993. 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)
  3994. {
  3995. ImGuiState& g = *GImGui;
  3996. ImGuiWindow* window = GetCurrentWindow();
  3997. if (window->SkipItems)
  3998. return false;
  3999. const ImGuiStyle& style = g.Style;
  4000. // Default to using texture ID as ID. User can still push string/integer prefixes.
  4001. // We could hash the size/uv to create a unique ID but that would prevent the user from animating buttons.
  4002. ImGui::PushID((void *)user_texture_id);
  4003. const ImGuiID id = window->GetID("#image");
  4004. ImGui::PopID();
  4005. const ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : style.FramePadding;
  4006. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding*2);
  4007. const ImRect image_bb(window->DC.CursorPos + padding, window->DC.CursorPos + padding + size);
  4008. ItemSize(bb);
  4009. if (!ItemAdd(bb, &id))
  4010. return false;
  4011. bool hovered, held;
  4012. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  4013. // Render
  4014. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  4015. if (padding.x > 0.0f || padding.y > 0.0f)
  4016. RenderFrame(bb.Min, bb.Max, col);
  4017. if (bg_col.w > 0.0f)
  4018. window->DrawList->AddRectFilled(image_bb.Min, image_bb.Max, window->Color(bg_col));
  4019. window->DrawList->AddImage(user_texture_id, image_bb.Min, image_bb.Max, uv0, uv1, window->Color(tint_col));
  4020. return pressed;
  4021. }
  4022. // Start logging ImGui output to TTY
  4023. void ImGui::LogToTTY(int max_depth)
  4024. {
  4025. ImGuiState& g = *GImGui;
  4026. ImGuiWindow* window = GetCurrentWindow();
  4027. if (g.LogEnabled)
  4028. return;
  4029. g.LogEnabled = true;
  4030. g.LogFile = stdout;
  4031. g.LogStartDepth = window->DC.TreeDepth;
  4032. if (max_depth >= 0)
  4033. g.LogAutoExpandMaxDepth = max_depth;
  4034. }
  4035. // Start logging ImGui output to given file
  4036. void ImGui::LogToFile(int max_depth, const char* filename)
  4037. {
  4038. ImGuiState& g = *GImGui;
  4039. ImGuiWindow* window = GetCurrentWindow();
  4040. if (g.LogEnabled)
  4041. return;
  4042. if (!filename)
  4043. {
  4044. filename = g.IO.LogFilename;
  4045. if (!filename)
  4046. return;
  4047. }
  4048. g.LogFile = fopen(filename, "ab");
  4049. if (!g.LogFile)
  4050. {
  4051. IM_ASSERT(g.LogFile != NULL); // Consider this an error
  4052. return;
  4053. }
  4054. g.LogEnabled = true;
  4055. g.LogStartDepth = window->DC.TreeDepth;
  4056. if (max_depth >= 0)
  4057. g.LogAutoExpandMaxDepth = max_depth;
  4058. }
  4059. // Start logging ImGui output to clipboard
  4060. void ImGui::LogToClipboard(int max_depth)
  4061. {
  4062. ImGuiWindow* window = GetCurrentWindow();
  4063. ImGuiState& g = *GImGui;
  4064. if (g.LogEnabled)
  4065. return;
  4066. g.LogEnabled = true;
  4067. g.LogFile = NULL;
  4068. g.LogStartDepth = window->DC.TreeDepth;
  4069. if (max_depth >= 0)
  4070. g.LogAutoExpandMaxDepth = max_depth;
  4071. }
  4072. void ImGui::LogFinish()
  4073. {
  4074. ImGuiState& g = *GImGui;
  4075. if (!g.LogEnabled)
  4076. return;
  4077. ImGui::LogText(STR_NEWLINE);
  4078. g.LogEnabled = false;
  4079. if (g.LogFile != NULL)
  4080. {
  4081. if (g.LogFile == stdout)
  4082. fflush(g.LogFile);
  4083. else
  4084. fclose(g.LogFile);
  4085. g.LogFile = NULL;
  4086. }
  4087. if (g.LogClipboard->size() > 1)
  4088. {
  4089. if (g.IO.SetClipboardTextFn)
  4090. g.IO.SetClipboardTextFn(g.LogClipboard->begin());
  4091. g.LogClipboard->clear();
  4092. }
  4093. }
  4094. // Helper to display logging buttons
  4095. void ImGui::LogButtons()
  4096. {
  4097. ImGuiState& g = *GImGui;
  4098. ImGui::PushID("LogButtons");
  4099. const bool log_to_tty = ImGui::Button("Log To TTY");
  4100. ImGui::SameLine();
  4101. const bool log_to_file = ImGui::Button("Log To File");
  4102. ImGui::SameLine();
  4103. const bool log_to_clipboard = ImGui::Button("Log To Clipboard");
  4104. ImGui::SameLine();
  4105. ImGui::PushItemWidth(80.0f);
  4106. ImGui::PushAllowKeyboardFocus(false);
  4107. ImGui::SliderInt("Depth", &g.LogAutoExpandMaxDepth, 0, 9, NULL);
  4108. ImGui::PopAllowKeyboardFocus();
  4109. ImGui::PopItemWidth();
  4110. ImGui::PopID();
  4111. // Start logging at the end of the function so that the buttons don't appear in the log
  4112. if (log_to_tty)
  4113. LogToTTY(g.LogAutoExpandMaxDepth);
  4114. if (log_to_file)
  4115. LogToFile(g.LogAutoExpandMaxDepth, g.IO.LogFilename);
  4116. if (log_to_clipboard)
  4117. LogToClipboard(g.LogAutoExpandMaxDepth);
  4118. }
  4119. bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display_frame, bool default_open)
  4120. {
  4121. ImGuiState& g = *GImGui;
  4122. ImGuiWindow* window = GetCurrentWindow();
  4123. if (window->SkipItems)
  4124. return false;
  4125. const ImGuiStyle& style = g.Style;
  4126. IM_ASSERT(str_id != NULL || label != NULL);
  4127. if (str_id == NULL)
  4128. str_id = label;
  4129. if (label == NULL)
  4130. label = str_id;
  4131. const ImGuiID id = window->GetID(str_id);
  4132. // We only write to the tree storage if the user clicks (or explicitely use SetNextTreeNode*** functions)
  4133. ImGuiStorage* storage = window->DC.StateStorage;
  4134. bool opened;
  4135. if (g.SetNextTreeNodeOpenedCond != 0)
  4136. {
  4137. if (g.SetNextTreeNodeOpenedCond & ImGuiSetCond_Always)
  4138. {
  4139. opened = g.SetNextTreeNodeOpenedVal;
  4140. storage->SetInt(id, opened);
  4141. }
  4142. else
  4143. {
  4144. // We treat ImGuiSetCondition_Once and ImGuiSetCondition_FirstUseEver the same because tree node state are not saved persistently.
  4145. const int stored_value = storage->GetInt(id, -1);
  4146. if (stored_value == -1)
  4147. {
  4148. opened = g.SetNextTreeNodeOpenedVal;
  4149. storage->SetInt(id, opened);
  4150. }
  4151. else
  4152. {
  4153. opened = stored_value != 0;
  4154. }
  4155. }
  4156. g.SetNextTreeNodeOpenedCond = 0;
  4157. }
  4158. else
  4159. {
  4160. opened = storage->GetInt(id, default_open) != 0;
  4161. }
  4162. // Framed header expand a little outside the default padding
  4163. const ImVec2 window_padding = window->WindowPadding();
  4164. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  4165. const ImVec2 pos_min = window->DC.CursorPos;
  4166. const ImVec2 pos_max = window->Pos + GetContentRegionMax();
  4167. ImRect bb = ImRect(pos_min, ImVec2(pos_max.x, pos_min.y + label_size.y));
  4168. if (display_frame)
  4169. {
  4170. bb.Min.x -= window_padding.x*0.5f - 1;
  4171. bb.Max.x += window_padding.x*0.5f - 1;
  4172. bb.Max.y += style.FramePadding.y * 2;
  4173. }
  4174. // 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
  4175. const ImRect text_bb(bb.Min, bb.Min + ImVec2(g.FontSize + style.FramePadding.x*2*2,0) + label_size);
  4176. ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y), display_frame ? style.FramePadding.y : 0.0f);
  4177. // When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behavior).
  4178. // NB- If we are above max depth we still allow manually opened nodes to be logged.
  4179. if (g.LogEnabled && !display_frame && window->DC.TreeDepth < g.LogAutoExpandMaxDepth)
  4180. opened = true;
  4181. if (!ItemAdd(bb, &id))
  4182. return opened;
  4183. bool hovered, held;
  4184. bool pressed = ButtonBehavior(display_frame ? bb : text_bb, id, &hovered, &held, false);
  4185. if (pressed)
  4186. {
  4187. opened = !opened;
  4188. storage->SetInt(id, opened);
  4189. }
  4190. // Render
  4191. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
  4192. if (display_frame)
  4193. {
  4194. // Framed type
  4195. RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
  4196. RenderCollapseTriangle(bb.Min + style.FramePadding, opened, 1.0f, true);
  4197. if (g.LogEnabled)
  4198. {
  4199. // 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.
  4200. const char log_prefix[] = "\n##";
  4201. LogText(bb.Min + style.FramePadding, log_prefix, log_prefix+3);
  4202. }
  4203. RenderText(bb.Min + style.FramePadding + ImVec2(g.FontSize + style.FramePadding.x*2,0), label);
  4204. if (g.LogEnabled)
  4205. {
  4206. const char log_suffix[] = "##";
  4207. LogText(bb.Min + style.FramePadding, log_suffix, log_suffix+2);
  4208. }
  4209. }
  4210. else
  4211. {
  4212. // Unframed typed for tree nodes
  4213. if ((held && hovered) || hovered)
  4214. RenderFrame(bb.Min, bb.Max, col, false);
  4215. RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, g.FontSize*0.15f), opened, 0.70f, false);
  4216. if (g.LogEnabled)
  4217. LogText(bb.Min, ">");
  4218. RenderText(bb.Min + ImVec2(g.FontSize + style.FramePadding.x*2,0), label);
  4219. }
  4220. return opened;
  4221. }
  4222. void ImGui::Bullet()
  4223. {
  4224. ImGuiState& g = *GImGui;
  4225. ImGuiWindow* window = GetCurrentWindow();
  4226. if (window->SkipItems)
  4227. return;
  4228. const ImGuiStyle& style = g.Style;
  4229. const float line_height = g.FontSize;
  4230. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height, line_height));
  4231. ItemSize(bb);
  4232. if (!ItemAdd(bb, NULL))
  4233. return;
  4234. // Render
  4235. const float bullet_size = line_height*0.15f;
  4236. window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text));
  4237. // Stay on same line
  4238. ImGui::SameLine(0, -1);
  4239. }
  4240. // Text with a little bullet aligned to the typical tree node.
  4241. void ImGui::BulletTextV(const char* fmt, va_list args)
  4242. {
  4243. ImGuiState& g = *GImGui;
  4244. ImGuiWindow* window = GetCurrentWindow();
  4245. if (window->SkipItems)
  4246. return;
  4247. const char* text_begin = g.TempBuffer;
  4248. const char* text_end = text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  4249. const ImGuiStyle& style = g.Style;
  4250. const float line_height = g.FontSize;
  4251. const ImVec2 label_size = CalcTextSize(text_begin, text_end, true);
  4252. 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
  4253. ItemSize(bb);
  4254. if (!ItemAdd(bb, NULL))
  4255. return;
  4256. // Render
  4257. const float bullet_size = line_height*0.15f;
  4258. window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text));
  4259. RenderText(bb.Min+ImVec2(g.FontSize + style.FramePadding.x*2,0), text_begin, text_end);
  4260. }
  4261. void ImGui::BulletText(const char* fmt, ...)
  4262. {
  4263. va_list args;
  4264. va_start(args, fmt);
  4265. BulletTextV(fmt, args);
  4266. va_end(args);
  4267. }
  4268. // If returning 'true' the node is open and the user is responsible for calling TreePop
  4269. bool ImGui::TreeNodeV(const char* str_id, const char* fmt, va_list args)
  4270. {
  4271. ImGuiState& g = *GImGui;
  4272. ImGuiWindow* window = GetCurrentWindow();
  4273. if (window->SkipItems)
  4274. return false;
  4275. ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  4276. if (!str_id || !str_id[0])
  4277. str_id = fmt;
  4278. ImGui::PushID(str_id);
  4279. const bool opened = ImGui::CollapsingHeader(g.TempBuffer, "", false);
  4280. ImGui::PopID();
  4281. if (opened)
  4282. ImGui::TreePush(str_id);
  4283. return opened;
  4284. }
  4285. bool ImGui::TreeNode(const char* str_id, const char* fmt, ...)
  4286. {
  4287. va_list args;
  4288. va_start(args, fmt);
  4289. bool s = TreeNodeV(str_id, fmt, args);
  4290. va_end(args);
  4291. return s;
  4292. }
  4293. // If returning 'true' the node is open and the user is responsible for calling TreePop
  4294. bool ImGui::TreeNodeV(const void* ptr_id, const char* fmt, va_list args)
  4295. {
  4296. ImGuiState& g = *GImGui;
  4297. ImGuiWindow* window = GetCurrentWindow();
  4298. if (window->SkipItems)
  4299. return false;
  4300. ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  4301. if (!ptr_id)
  4302. ptr_id = fmt;
  4303. ImGui::PushID(ptr_id);
  4304. const bool opened = ImGui::CollapsingHeader(g.TempBuffer, "", false);
  4305. ImGui::PopID();
  4306. if (opened)
  4307. ImGui::TreePush(ptr_id);
  4308. return opened;
  4309. }
  4310. bool ImGui::TreeNode(const void* ptr_id, const char* fmt, ...)
  4311. {
  4312. va_list args;
  4313. va_start(args, fmt);
  4314. bool s = TreeNodeV(ptr_id, fmt, args);
  4315. va_end(args);
  4316. return s;
  4317. }
  4318. bool ImGui::TreeNode(const char* str_label_id)
  4319. {
  4320. return TreeNode(str_label_id, "%s", str_label_id);
  4321. }
  4322. void ImGui::SetNextTreeNodeOpened(bool opened, ImGuiSetCond cond)
  4323. {
  4324. ImGuiState& g = *GImGui;
  4325. g.SetNextTreeNodeOpenedVal = opened;
  4326. g.SetNextTreeNodeOpenedCond = cond ? cond : ImGuiSetCond_Always;
  4327. }
  4328. void ImGui::PushID(const char* str_id)
  4329. {
  4330. ImGuiWindow* window = GetCurrentWindow();
  4331. window->IDStack.push_back(window->GetID(str_id));
  4332. }
  4333. void ImGui::PushID(const char* str_id_begin, const char* str_id_end)
  4334. {
  4335. ImGuiWindow* window = GetCurrentWindow();
  4336. window->IDStack.push_back(window->GetID(str_id_begin, str_id_end));
  4337. }
  4338. void ImGui::PushID(const void* ptr_id)
  4339. {
  4340. ImGuiWindow* window = GetCurrentWindow();
  4341. window->IDStack.push_back(window->GetID(ptr_id));
  4342. }
  4343. void ImGui::PushID(const int int_id)
  4344. {
  4345. const void* ptr_id = (void*)(intptr_t)int_id;
  4346. ImGuiWindow* window = GetCurrentWindow();
  4347. window->IDStack.push_back(window->GetID(ptr_id));
  4348. }
  4349. void ImGui::PopID()
  4350. {
  4351. ImGuiWindow* window = GetCurrentWindow();
  4352. window->IDStack.pop_back();
  4353. }
  4354. ImGuiID ImGui::GetID(const char* str_id)
  4355. {
  4356. ImGuiWindow* window = GetCurrentWindow();
  4357. return window->GetID(str_id);
  4358. }
  4359. ImGuiID ImGui::GetID(const char* str_id_begin, const char* str_id_end)
  4360. {
  4361. ImGuiWindow* window = GetCurrentWindow();
  4362. return window->GetID(str_id_begin, str_id_end);
  4363. }
  4364. ImGuiID ImGui::GetID(const void* ptr_id)
  4365. {
  4366. ImGuiWindow* window = GetCurrentWindow();
  4367. return window->GetID(ptr_id);
  4368. }
  4369. // User can input math operators (e.g. +100) to edit a numerical values.
  4370. // NB: only call right after InputText because we are using its InitialValue storage
  4371. static void ApplyNumericalTextInput(const char* buf, float *v)
  4372. {
  4373. while (ImCharIsSpace(*buf))
  4374. buf++;
  4375. // We don't support '-' op because it would conflict with inputing negative value.
  4376. // Instead you can use +-100 to subtract from an existing value
  4377. char op = buf[0];
  4378. if (op == '+' || op == '*' || op == '/')
  4379. {
  4380. buf++;
  4381. while (ImCharIsSpace(*buf))
  4382. buf++;
  4383. }
  4384. else
  4385. {
  4386. op = 0;
  4387. }
  4388. if (!buf[0])
  4389. return;
  4390. float ref_v = *v;
  4391. if (op)
  4392. if (sscanf(GImGui->InputTextState.InitialText, "%f", &ref_v) < 1)
  4393. return;
  4394. float op_v = 0.0f;
  4395. if (sscanf(buf, "%f", &op_v) < 1)
  4396. return;
  4397. if (op == '+')
  4398. *v = ref_v + op_v;
  4399. else if (op == '*')
  4400. *v = ref_v * op_v;
  4401. else if (op == '/')
  4402. {
  4403. if (op_v == 0.0f)
  4404. return;
  4405. *v = ref_v / op_v;
  4406. }
  4407. else
  4408. *v = op_v;
  4409. }
  4410. // Create text input in place of a slider (when CTRL+Clicking on slider)
  4411. static bool SliderFloatAsInputText(const char* label, float* v, ImGuiID id, int decimal_precision)
  4412. {
  4413. ImGuiState& g = *GImGui;
  4414. ImGuiWindow* window = GetCurrentWindow();
  4415. char text_buf[64];
  4416. ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%.*f", decimal_precision, *v);
  4417. SetActiveId(g.ScalarAsInputTextId);
  4418. g.HoveredId = 0;
  4419. // Our replacement widget will override the focus ID (registered previously to allow for a TAB focus to happen)
  4420. window->FocusItemUnregister();
  4421. bool value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll);
  4422. if (g.ScalarAsInputTextId == 0)
  4423. {
  4424. // First frame
  4425. 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)
  4426. g.ScalarAsInputTextId = g.ActiveId;
  4427. g.HoveredId = id;
  4428. }
  4429. else if (g.ActiveId != g.ScalarAsInputTextId)
  4430. {
  4431. // Release
  4432. g.ScalarAsInputTextId = 0;
  4433. }
  4434. if (value_changed)
  4435. {
  4436. ApplyNumericalTextInput(text_buf, v);
  4437. }
  4438. return value_changed;
  4439. }
  4440. // Parse display precision back from the display format string
  4441. static inline void ParseFormat(const char* fmt, int& decimal_precision)
  4442. {
  4443. while ((fmt = strchr(fmt, '%')) != NULL)
  4444. {
  4445. fmt++;
  4446. if (fmt[0] == '%') { fmt++; continue; } // Ignore "%%"
  4447. while (*fmt >= '0' && *fmt <= '9')
  4448. fmt++;
  4449. if (*fmt == '.')
  4450. {
  4451. decimal_precision = atoi(fmt + 1);
  4452. if (decimal_precision < 0 || decimal_precision > 10)
  4453. decimal_precision = 3;
  4454. }
  4455. break;
  4456. }
  4457. }
  4458. static inline float RoundScalar(float value, int decimal_precision)
  4459. {
  4460. // Round past decimal precision
  4461. // 0: 1, 1: 0.1, 2: 0.01, etc.
  4462. // So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0
  4463. // FIXME: Investigate better rounding methods
  4464. const float min_step = 1.0f / powf(10.0f, (float)decimal_precision);
  4465. const float remainder = fmodf(value, min_step);
  4466. if (remainder <= min_step*0.5f)
  4467. value -= remainder;
  4468. else
  4469. value += (min_step - remainder);
  4470. return value;
  4471. }
  4472. static bool SliderScalarBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, bool horizontal)
  4473. {
  4474. ImGuiState& g = *GImGui;
  4475. ImGuiWindow* window = GetCurrentWindow();
  4476. const ImGuiStyle& style = g.Style;
  4477. // Draw frame
  4478. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  4479. const bool is_non_linear = fabsf(power - 1.0f) > 0.0001f;
  4480. const float padding = horizontal ? style.FramePadding.x : style.FramePadding.y;
  4481. const float slider_sz = horizontal ? (frame_bb.GetWidth() - padding * 2.0f) : (frame_bb.GetHeight() - padding * 2.0f);
  4482. float grab_sz;
  4483. if (decimal_precision > 0)
  4484. grab_sz = ImMin(style.GrabMinSize, slider_sz);
  4485. else
  4486. grab_sz = ImMin(ImMax(1.0f * (slider_sz / (v_max-v_min+1.0f)), style.GrabMinSize), slider_sz); // Integer sliders, if possible have the grab size represent 1 unit
  4487. const float slider_usable_sz = slider_sz - grab_sz;
  4488. const float slider_usable_pos_min = (horizontal ? frame_bb.Min.x : frame_bb.Min.y) + padding + grab_sz*0.5f;
  4489. const float slider_usable_pos_max = (horizontal ? frame_bb.Max.x : frame_bb.Max.y) - padding - grab_sz*0.5f;
  4490. bool value_changed = false;
  4491. // For logarithmic sliders that cross over sign boundary we want the exponential increase to be symmetric around 0.0f
  4492. float linear_zero_pos = 0.0f; // 0.0->1.0f
  4493. if (v_min * v_max < 0.0f)
  4494. {
  4495. // Different sign
  4496. const float linear_dist_min_to_0 = powf(fabsf(0.0f - v_min), 1.0f/power);
  4497. const float linear_dist_max_to_0 = powf(fabsf(v_max - 0.0f), 1.0f/power);
  4498. linear_zero_pos = linear_dist_min_to_0 / (linear_dist_min_to_0+linear_dist_max_to_0);
  4499. }
  4500. else
  4501. {
  4502. // Same sign
  4503. linear_zero_pos = v_min < 0.0f ? 1.0f : 0.0f;
  4504. }
  4505. // Process clicking on the slider
  4506. if (g.ActiveId == id)
  4507. {
  4508. if (g.IO.MouseDown[0])
  4509. {
  4510. const float mouse_abs_pos = horizontal ? g.IO.MousePos.x : g.IO.MousePos.y;
  4511. float normalized_pos = ImClamp((mouse_abs_pos - slider_usable_pos_min) / slider_usable_sz, 0.0f, 1.0f);
  4512. if (!horizontal)
  4513. normalized_pos = 1.0f - normalized_pos;
  4514. float new_value;
  4515. if (is_non_linear)
  4516. {
  4517. // Account for logarithmic scale on both sides of the zero
  4518. if (normalized_pos < linear_zero_pos)
  4519. {
  4520. // Negative: rescale to the negative range before powering
  4521. float a = 1.0f - (normalized_pos / linear_zero_pos);
  4522. a = powf(a, power);
  4523. new_value = ImLerp(ImMin(v_max,0.0f), v_min, a);
  4524. }
  4525. else
  4526. {
  4527. // Positive: rescale to the positive range before powering
  4528. float a;
  4529. if (fabsf(linear_zero_pos - 1.0f) > 1.e-6)
  4530. a = (normalized_pos - linear_zero_pos) / (1.0f - linear_zero_pos);
  4531. else
  4532. a = normalized_pos;
  4533. a = powf(a, power);
  4534. new_value = ImLerp(ImMax(v_min,0.0f), v_max, a);
  4535. }
  4536. }
  4537. else
  4538. {
  4539. // Linear slider
  4540. new_value = ImLerp(v_min, v_max, normalized_pos);
  4541. }
  4542. // Round past decimal precision
  4543. new_value = RoundScalar(new_value, decimal_precision);
  4544. if (*v != new_value)
  4545. {
  4546. *v = new_value;
  4547. value_changed = true;
  4548. }
  4549. }
  4550. else
  4551. {
  4552. SetActiveId(0);
  4553. }
  4554. }
  4555. // Calculate slider grab positioning
  4556. float grab_t;
  4557. if (is_non_linear)
  4558. {
  4559. float v_clamped = ImClamp(*v, v_min, v_max);
  4560. if (v_clamped < 0.0f)
  4561. {
  4562. const float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min);
  4563. grab_t = (1.0f - powf(f, 1.0f/power)) * linear_zero_pos;
  4564. }
  4565. else
  4566. {
  4567. const float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min));
  4568. grab_t = linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos);
  4569. }
  4570. }
  4571. else
  4572. {
  4573. // Linear slider
  4574. grab_t = (ImClamp(*v, v_min, v_max) - v_min) / (v_max - v_min);
  4575. }
  4576. // Draw
  4577. if (!horizontal)
  4578. grab_t = 1.0f - grab_t;
  4579. const float grab_pos = ImLerp(slider_usable_pos_min, slider_usable_pos_max, grab_t);
  4580. ImRect grab_bb;
  4581. if (horizontal)
  4582. 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));
  4583. else
  4584. 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));
  4585. window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab));
  4586. return value_changed;
  4587. }
  4588. // Use power!=1.0 for logarithmic sliders.
  4589. // Adjust display_format to decorate the value with a prefix or a suffix.
  4590. // "%.3f" 1.234
  4591. // "%5.2f secs" 01.23 secs
  4592. // "Gold: %.0f" Gold: 1
  4593. bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format, float power)
  4594. {
  4595. ImGuiState& g = *GImGui;
  4596. ImGuiWindow* window = GetCurrentWindow();
  4597. if (window->SkipItems)
  4598. return false;
  4599. const ImGuiStyle& style = g.Style;
  4600. const ImGuiID id = window->GetID(label);
  4601. const float w = ImGui::CalcItemWidth();
  4602. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  4603. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
  4604. 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));
  4605. // NB- we don't call ItemSize() yet because we may turn into a text edit box below
  4606. if (!ItemAdd(total_bb, &id))
  4607. {
  4608. ItemSize(total_bb, style.FramePadding.y);
  4609. return false;
  4610. }
  4611. const bool hovered = IsHovered(frame_bb, id);
  4612. if (hovered)
  4613. g.HoveredId = id;
  4614. if (!display_format)
  4615. display_format = "%.3f";
  4616. int decimal_precision = 3;
  4617. ParseFormat(display_format, decimal_precision);
  4618. // Tabbing or CTRL-clicking on Slider turns it into an input box
  4619. bool start_text_input = false;
  4620. const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id);
  4621. if (tab_focus_requested || (hovered && g.IO.MouseClicked[0]))
  4622. {
  4623. SetActiveId(id);
  4624. FocusWindow(window);
  4625. const bool is_ctrl_down = g.IO.KeyCtrl;
  4626. if (tab_focus_requested || is_ctrl_down)
  4627. {
  4628. start_text_input = true;
  4629. g.ScalarAsInputTextId = 0;
  4630. }
  4631. }
  4632. if (start_text_input || (g.ActiveId == id && g.ScalarAsInputTextId == id))
  4633. return SliderFloatAsInputText(label, v, id, decimal_precision);
  4634. ItemSize(total_bb, style.FramePadding.y);
  4635. // Actual slider behavior + render grab
  4636. const bool value_changed = SliderScalarBehavior(frame_bb, id, v, v_min, v_max, power, decimal_precision, true);
  4637. // Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
  4638. char value_buf[64];
  4639. const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
  4640. const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true);
  4641. RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x + style.FramePadding.x, frame_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);
  4642. if (label_size.x > 0.0f)
  4643. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  4644. return value_changed;
  4645. }
  4646. bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format, float power)
  4647. {
  4648. ImGuiState& g = *GImGui;
  4649. ImGuiWindow* window = GetCurrentWindow();
  4650. if (window->SkipItems)
  4651. return false;
  4652. const ImGuiStyle& style = g.Style;
  4653. const ImGuiID id = window->GetID(label);
  4654. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  4655. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size);
  4656. 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));
  4657. ItemSize(bb, style.FramePadding.y);
  4658. if (!ItemAdd(frame_bb, &id))
  4659. return false;
  4660. const bool hovered = IsHovered(frame_bb, id);
  4661. if (hovered)
  4662. g.HoveredId = id;
  4663. if (!display_format)
  4664. display_format = "%.3f";
  4665. int decimal_precision = 3;
  4666. ParseFormat(display_format, decimal_precision);
  4667. if (hovered && g.IO.MouseClicked[0])
  4668. {
  4669. SetActiveId(id);
  4670. FocusWindow(window);
  4671. }
  4672. // Actual slider behavior + render grab
  4673. bool value_changed = SliderScalarBehavior(frame_bb, id, v, v_min, v_max, power, decimal_precision, false);
  4674. // Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
  4675. // For the vertical slider we allow centered text to overlap the frame padding
  4676. char value_buf[64];
  4677. char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
  4678. const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true);
  4679. RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x, frame_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);
  4680. if (label_size.x > 0.0f)
  4681. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  4682. return value_changed;
  4683. }
  4684. bool ImGui::SliderAngle(const char* label, float* v_rad, float v_degrees_min, float v_degrees_max)
  4685. {
  4686. float v_deg = (*v_rad) * 360.0f / (2*PI);
  4687. bool value_changed = ImGui::SliderFloat(label, &v_deg, v_degrees_min, v_degrees_max, "%.0f deg", 1.0f);
  4688. *v_rad = v_deg * (2*PI) / 360.0f;
  4689. return value_changed;
  4690. }
  4691. bool ImGui::SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format)
  4692. {
  4693. if (!display_format)
  4694. display_format = "%.0f";
  4695. float v_f = (float)*v;
  4696. bool value_changed = ImGui::SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f);
  4697. *v = (int)v_f;
  4698. return value_changed;
  4699. }
  4700. bool ImGui::VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format)
  4701. {
  4702. if (!display_format)
  4703. display_format = "%.0f";
  4704. float v_f = (float)*v;
  4705. bool value_changed = ImGui::VSliderFloat(label, size, &v_f, (float)v_min, (float)v_max, display_format, 1.0f);
  4706. *v = (int)v_f;
  4707. return value_changed;
  4708. }
  4709. // Add multiple sliders on 1 line for compact edition of multiple components
  4710. static bool SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* display_format, float power)
  4711. {
  4712. ImGuiState& g = *GImGui;
  4713. ImGuiWindow* window = GetCurrentWindow();
  4714. if (window->SkipItems)
  4715. return false;
  4716. const ImGuiStyle& style = g.Style;
  4717. const float w_full = ImGui::CalcItemWidth();
  4718. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components));
  4719. 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)));
  4720. bool value_changed = false;
  4721. ImGui::BeginGroup();
  4722. ImGui::PushID(label);
  4723. ImGui::PushItemWidth(w_item_one);
  4724. for (int i = 0; i < components; i++)
  4725. {
  4726. ImGui::PushID(i);
  4727. if (i + 1 == components)
  4728. {
  4729. ImGui::PopItemWidth();
  4730. ImGui::PushItemWidth(w_item_last);
  4731. }
  4732. value_changed |= ImGui::SliderFloat("##v", &v[i], v_min, v_max, display_format, power);
  4733. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4734. ImGui::PopID();
  4735. }
  4736. ImGui::PopItemWidth();
  4737. ImGui::PopID();
  4738. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4739. ImGui::EndGroup();
  4740. return value_changed;
  4741. }
  4742. bool ImGui::SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format, float power)
  4743. {
  4744. return SliderFloatN(label, v, 2, v_min, v_max, display_format, power);
  4745. }
  4746. bool ImGui::SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format, float power)
  4747. {
  4748. return SliderFloatN(label, v, 3, v_min, v_max, display_format, power);
  4749. }
  4750. bool ImGui::SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format, float power)
  4751. {
  4752. return SliderFloatN(label, v, 4, v_min, v_max, display_format, power);
  4753. }
  4754. static bool SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* display_format)
  4755. {
  4756. ImGuiState& g = *GImGui;
  4757. ImGuiWindow* window = GetCurrentWindow();
  4758. if (window->SkipItems)
  4759. return false;
  4760. const ImGuiStyle& style = g.Style;
  4761. const float w_full = ImGui::CalcItemWidth();
  4762. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components));
  4763. 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)));
  4764. bool value_changed = false;
  4765. ImGui::BeginGroup();
  4766. ImGui::PushID(label);
  4767. ImGui::PushItemWidth(w_item_one);
  4768. for (int i = 0; i < components; i++)
  4769. {
  4770. ImGui::PushID(i);
  4771. if (i + 1 == components)
  4772. {
  4773. ImGui::PopItemWidth();
  4774. ImGui::PushItemWidth(w_item_last);
  4775. }
  4776. value_changed |= ImGui::SliderInt("##v", &v[i], v_min, v_max, display_format);
  4777. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4778. ImGui::PopID();
  4779. }
  4780. ImGui::PopItemWidth();
  4781. ImGui::PopID();
  4782. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4783. ImGui::EndGroup();
  4784. return value_changed;
  4785. }
  4786. bool ImGui::SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format)
  4787. {
  4788. return SliderIntN(label, v, 2, v_min, v_max, display_format);
  4789. }
  4790. bool ImGui::SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format)
  4791. {
  4792. return SliderIntN(label, v, 3, v_min, v_max, display_format);
  4793. }
  4794. bool ImGui::SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format)
  4795. {
  4796. return SliderIntN(label, v, 4, v_min, v_max, display_format);
  4797. }
  4798. // FIXME-WIP: Work in progress. May change API / behavior.
  4799. static bool DragScalarBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_speed, float v_min, float v_max, int decimal_precision, float power)
  4800. {
  4801. ImGuiState& g = *GImGui;
  4802. ImGuiWindow* window = GetCurrentWindow();
  4803. const ImGuiStyle& style = g.Style;
  4804. // Draw frame
  4805. const ImU32 frame_col = window->Color(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
  4806. RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, style.FrameRounding);
  4807. bool value_changed = false;
  4808. // Process clicking on the drag
  4809. if (g.ActiveId == id)
  4810. {
  4811. if (g.IO.MouseDown[0])
  4812. {
  4813. if (g.ActiveIdIsJustActivated)
  4814. {
  4815. // Lock current value on click
  4816. g.DragCurrentValue = *v;
  4817. g.DragLastMouseDelta = ImVec2(0.f, 0.f);
  4818. }
  4819. const ImVec2 mouse_drag_delta = ImGui::GetMouseDragDelta(0, 1.0f);
  4820. if (fabsf(mouse_drag_delta.x - g.DragLastMouseDelta.x) > 0.0f)
  4821. {
  4822. float speed = v_speed;
  4823. if (speed == 0.0f && (v_max - v_min) != 0.0f && (v_max - v_min) < FLT_MAX)
  4824. speed = (v_max - v_min) * g.DragSpeedDefaultRatio;
  4825. if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f)
  4826. speed = speed * g.DragSpeedScaleFast;
  4827. if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f)
  4828. speed = speed * g.DragSpeedScaleSlow;
  4829. float v_cur = g.DragCurrentValue;
  4830. float delta = (mouse_drag_delta.x - g.DragLastMouseDelta.x) * speed;
  4831. if (fabsf(power - 1.0f) > 0.001f)
  4832. {
  4833. // Logarithmic curve on both side of 0.0
  4834. float v0_abs = v_cur >= 0.0f ? v_cur : -v_cur;
  4835. float v0_sign = v_cur >= 0.0f ? 1.0f : -1.0f;
  4836. float v1 = powf(v0_abs, 1.0f / power) + (delta * v0_sign);
  4837. float v1_abs = v1 >= 0.0f ? v1 : -v1;
  4838. float v1_sign = v1 >= 0.0f ? 1.0f : -1.0f; // Crossed sign line
  4839. v_cur = powf(v1_abs, power) * v0_sign * v1_sign; // Reapply sign
  4840. }
  4841. else
  4842. {
  4843. v_cur += delta;
  4844. }
  4845. g.DragLastMouseDelta.x = mouse_drag_delta.x;
  4846. // Clamp
  4847. if (v_min < v_max)
  4848. v_cur = ImClamp(v_cur, v_min, v_max);
  4849. g.DragCurrentValue = v_cur;
  4850. // Round to user desired precision, then apply
  4851. v_cur = RoundScalar(v_cur, decimal_precision);
  4852. if (*v != v_cur)
  4853. {
  4854. *v = v_cur;
  4855. value_changed = true;
  4856. }
  4857. }
  4858. }
  4859. else
  4860. {
  4861. SetActiveId(0);
  4862. }
  4863. }
  4864. return value_changed;
  4865. }
  4866. bool ImGui::DragFloat(const char* label, float *v, float v_speed, float v_min, float v_max, const char* display_format, float power)
  4867. {
  4868. ImGuiState& g = *GImGui;
  4869. ImGuiWindow* window = GetCurrentWindow();
  4870. if (window->SkipItems)
  4871. return false;
  4872. const ImGuiStyle& style = g.Style;
  4873. const ImGuiID id = window->GetID(label);
  4874. const float w = ImGui::CalcItemWidth();
  4875. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  4876. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
  4877. const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
  4878. 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));
  4879. // NB- we don't call ItemSize() yet because we may turn into a text edit box below
  4880. if (!ItemAdd(total_bb, &id))
  4881. {
  4882. ItemSize(total_bb, style.FramePadding.y);
  4883. return false;
  4884. }
  4885. const bool hovered = IsHovered(frame_bb, id);
  4886. if (hovered)
  4887. g.HoveredId = id;
  4888. if (!display_format)
  4889. display_format = "%.3f";
  4890. int decimal_precision = 3;
  4891. ParseFormat(display_format, decimal_precision);
  4892. // Tabbing or CTRL-clicking on Drag turns it into an input box
  4893. bool start_text_input = false;
  4894. const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id);
  4895. if (tab_focus_requested || (hovered && (g.IO.MouseClicked[0] | g.IO.MouseDoubleClicked[0])))
  4896. {
  4897. SetActiveId(id);
  4898. FocusWindow(window);
  4899. if (tab_focus_requested || g.IO.KeyCtrl || g.IO.MouseDoubleClicked[0])
  4900. {
  4901. start_text_input = true;
  4902. g.ScalarAsInputTextId = 0;
  4903. }
  4904. }
  4905. if (start_text_input || (g.ActiveId == id && g.ScalarAsInputTextId == id))
  4906. return SliderFloatAsInputText(label, v, id, decimal_precision);
  4907. ItemSize(total_bb, style.FramePadding.y);
  4908. // Actual drag behavior
  4909. const bool value_changed = DragScalarBehavior(frame_bb, id, v, v_speed, v_min, v_max, decimal_precision, power);
  4910. // Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
  4911. char value_buf[64];
  4912. const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
  4913. const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true);
  4914. 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);
  4915. if (label_size.x > 0.0f)
  4916. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label);
  4917. return value_changed;
  4918. }
  4919. static bool DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* display_format, float power)
  4920. {
  4921. ImGuiState& g = *GImGui;
  4922. ImGuiWindow* window = GetCurrentWindow();
  4923. if (window->SkipItems)
  4924. return false;
  4925. const ImGuiStyle& style = g.Style;
  4926. const float w_full = ImGui::CalcItemWidth();
  4927. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components));
  4928. 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)));
  4929. bool value_changed = false;
  4930. ImGui::BeginGroup();
  4931. ImGui::PushID(label);
  4932. ImGui::PushItemWidth(w_item_one);
  4933. for (int i = 0; i < components; i++)
  4934. {
  4935. ImGui::PushID(i);
  4936. if (i + 1 == components)
  4937. {
  4938. ImGui::PopItemWidth();
  4939. ImGui::PushItemWidth(w_item_last);
  4940. }
  4941. value_changed |= ImGui::DragFloat("##v", &v[i], v_speed, v_min, v_max, display_format, power);
  4942. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4943. ImGui::PopID();
  4944. }
  4945. ImGui::PopItemWidth();
  4946. ImGui::PopID();
  4947. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4948. ImGui::EndGroup();
  4949. return value_changed;
  4950. }
  4951. bool ImGui::DragFloat2(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power)
  4952. {
  4953. return DragFloatN(label, v, 2, v_speed, v_min, v_max, display_format, power);
  4954. }
  4955. bool ImGui::DragFloat3(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power)
  4956. {
  4957. return DragFloatN(label, v, 3, v_speed, v_min, v_max, display_format, power);
  4958. }
  4959. bool ImGui::DragFloat4(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power)
  4960. {
  4961. return DragFloatN(label, v, 4, v_speed, v_min, v_max, display_format, power);
  4962. }
  4963. // NB: v_speed is float to allow adjusting the drag speed with more precision
  4964. bool ImGui::DragInt(const char* label, int* v, float v_speed, int v_min, int v_max, const char* display_format)
  4965. {
  4966. if (!display_format)
  4967. display_format = "%.0f";
  4968. float v_f = (float)*v;
  4969. bool value_changed = ImGui::DragFloat(label, &v_f, v_speed, (float)v_min, (float)v_max, display_format);
  4970. *v = (int)v_f;
  4971. return value_changed;
  4972. }
  4973. static bool DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* display_format)
  4974. {
  4975. ImGuiState& g = *GImGui;
  4976. ImGuiWindow* window = GetCurrentWindow();
  4977. if (window->SkipItems)
  4978. return false;
  4979. const ImGuiStyle& style = g.Style;
  4980. const float w_full = ImGui::CalcItemWidth();
  4981. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components));
  4982. 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)));
  4983. bool value_changed = false;
  4984. ImGui::BeginGroup();
  4985. ImGui::PushID(label);
  4986. ImGui::PushItemWidth(w_item_one);
  4987. for (int i = 0; i < components; i++)
  4988. {
  4989. ImGui::PushID(i);
  4990. if (i + 1 == components)
  4991. {
  4992. ImGui::PopItemWidth();
  4993. ImGui::PushItemWidth(w_item_last);
  4994. }
  4995. value_changed |= ImGui::DragInt("##v", &v[i], v_speed, v_min, v_max, display_format);
  4996. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4997. ImGui::PopID();
  4998. }
  4999. ImGui::PopItemWidth();
  5000. ImGui::PopID();
  5001. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  5002. ImGui::EndGroup();
  5003. return value_changed;
  5004. }
  5005. bool ImGui::DragInt2(const char* label, int v[2], float v_speed, int v_min, int v_max, const char* display_format)
  5006. {
  5007. return DragIntN(label, v, 2, v_speed, v_min, v_max, display_format);
  5008. }
  5009. bool ImGui::DragInt3(const char* label, int v[3], float v_speed, int v_min, int v_max, const char* display_format)
  5010. {
  5011. return DragIntN(label, v, 3, v_speed, v_min, v_max, display_format);
  5012. }
  5013. bool ImGui::DragInt4(const char* label, int v[4], float v_speed, int v_min, int v_max, const char* display_format)
  5014. {
  5015. return DragIntN(label, v, 4, v_speed, v_min, v_max, display_format);
  5016. }
  5017. enum ImGuiPlotType
  5018. {
  5019. ImGuiPlotType_Lines,
  5020. ImGuiPlotType_Histogram
  5021. };
  5022. 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)
  5023. {
  5024. ImGuiState& g = *GImGui;
  5025. ImGuiWindow* window = GetCurrentWindow();
  5026. if (window->SkipItems)
  5027. return;
  5028. const ImGuiStyle& style = g.Style;
  5029. const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
  5030. if (graph_size.x == 0.0f)
  5031. graph_size.x = ImGui::CalcItemWidth() + (style.FramePadding.x * 2);
  5032. if (graph_size.y == 0.0f)
  5033. graph_size.y = label_size.y + (style.FramePadding.y * 2);
  5034. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y));
  5035. const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
  5036. 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));
  5037. ItemSize(total_bb, style.FramePadding.y);
  5038. if (!ItemAdd(total_bb, NULL))
  5039. return;
  5040. // Determine scale from values if not specified
  5041. if (scale_min == FLT_MAX || scale_max == FLT_MAX)
  5042. {
  5043. float v_min = FLT_MAX;
  5044. float v_max = -FLT_MAX;
  5045. for (int i = 0; i < values_count; i++)
  5046. {
  5047. const float v = values_getter(data, i);
  5048. v_min = ImMin(v_min, v);
  5049. v_max = ImMax(v_max, v);
  5050. }
  5051. if (scale_min == FLT_MAX)
  5052. scale_min = v_min;
  5053. if (scale_max == FLT_MAX)
  5054. scale_max = v_max;
  5055. }
  5056. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  5057. int res_w = ImMin((int)graph_size.x, values_count);
  5058. if (plot_type == ImGuiPlotType_Lines)
  5059. res_w -= 1;
  5060. // Tooltip on hover
  5061. int v_hovered = -1;
  5062. if (IsMouseHoveringRect(inner_bb))
  5063. {
  5064. const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f);
  5065. const int v_idx = (int)(t * (values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0)));
  5066. IM_ASSERT(v_idx >= 0 && v_idx < values_count);
  5067. const float v0 = values_getter(data, (v_idx + values_offset) % values_count);
  5068. const float v1 = values_getter(data, (v_idx + 1 + values_offset) % values_count);
  5069. if (plot_type == ImGuiPlotType_Lines)
  5070. ImGui::SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx+1, v1);
  5071. else if (plot_type == ImGuiPlotType_Histogram)
  5072. ImGui::SetTooltip("%d: %8.4g", v_idx, v0);
  5073. v_hovered = v_idx;
  5074. }
  5075. const float t_step = 1.0f / (float)res_w;
  5076. float v0 = values_getter(data, (0 + values_offset) % values_count);
  5077. float t0 = 0.0f;
  5078. ImVec2 p0 = ImVec2( t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min)) );
  5079. const ImU32 col_base = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram);
  5080. const ImU32 col_hovered = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered);
  5081. for (int n = 0; n < res_w; n++)
  5082. {
  5083. const float t1 = t0 + t_step;
  5084. const int v_idx = (int)(t0 * values_count);
  5085. IM_ASSERT(v_idx >= 0 && v_idx < values_count);
  5086. const float v1 = values_getter(data, (v_idx + values_offset + 1) % values_count);
  5087. const ImVec2 p1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) );
  5088. // NB- Draw calls are merged together by the DrawList system.
  5089. if (plot_type == ImGuiPlotType_Lines)
  5090. 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);
  5091. else if (plot_type == ImGuiPlotType_Histogram)
  5092. 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);
  5093. t0 = t1;
  5094. p0 = p1;
  5095. }
  5096. // Text overlay
  5097. if (overlay_text)
  5098. RenderText(ImVec2(inner_bb.GetCenter().x - ImGui::CalcTextSize(overlay_text, NULL, true).x*0.5f, frame_bb.Min.y + style.FramePadding.y), overlay_text);
  5099. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label);
  5100. }
  5101. struct ImGuiPlotArrayGetterData
  5102. {
  5103. const float* Values;
  5104. size_t Stride;
  5105. ImGuiPlotArrayGetterData(const float* values, size_t stride) { Values = values; Stride = stride; }
  5106. };
  5107. static float Plot_ArrayGetter(void* data, int idx)
  5108. {
  5109. ImGuiPlotArrayGetterData* plot_data = (ImGuiPlotArrayGetterData*)data;
  5110. const float v = *(float*)(void*)((unsigned char*)plot_data->Values + (size_t)idx * plot_data->Stride);
  5111. return v;
  5112. }
  5113. 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)
  5114. {
  5115. ImGuiPlotArrayGetterData data(values, stride);
  5116. Plot(ImGuiPlotType_Lines, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  5117. }
  5118. 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)
  5119. {
  5120. Plot(ImGuiPlotType_Lines, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  5121. }
  5122. 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)
  5123. {
  5124. ImGuiPlotArrayGetterData data(values, stride);
  5125. Plot(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  5126. }
  5127. 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)
  5128. {
  5129. Plot(ImGuiPlotType_Histogram, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  5130. }
  5131. bool ImGui::Checkbox(const char* label, bool* v)
  5132. {
  5133. ImGuiState& g = *GImGui;
  5134. ImGuiWindow* window = GetCurrentWindow();
  5135. if (window->SkipItems)
  5136. return false;
  5137. const ImGuiStyle& style = g.Style;
  5138. const ImGuiID id = window->GetID(label);
  5139. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5140. 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));
  5141. ItemSize(check_bb, style.FramePadding.y);
  5142. ImRect total_bb = check_bb;
  5143. if (label_size.x > 0)
  5144. SameLine(0, (int)style.ItemInnerSpacing.x);
  5145. const ImRect text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + label_size);
  5146. if (label_size.x > 0)
  5147. {
  5148. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
  5149. total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
  5150. }
  5151. if (!ItemAdd(total_bb, &id))
  5152. return false;
  5153. bool hovered, held;
  5154. bool pressed = ButtonBehavior(total_bb, id, &hovered, &held, true);
  5155. if (pressed)
  5156. *v = !(*v);
  5157. RenderFrame(check_bb.Min, check_bb.Max, window->Color((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), true, style.FrameRounding);
  5158. if (*v)
  5159. {
  5160. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  5161. const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f;
  5162. window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), window->Color(ImGuiCol_CheckMark), style.FrameRounding);
  5163. }
  5164. if (g.LogEnabled)
  5165. LogText(text_bb.GetTL(), *v ? "[x]" : "[ ]");
  5166. RenderText(text_bb.GetTL(), label);
  5167. return pressed;
  5168. }
  5169. bool ImGui::CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value)
  5170. {
  5171. bool v = (*flags & flags_value) ? true : false;
  5172. bool pressed = ImGui::Checkbox(label, &v);
  5173. if (v)
  5174. *flags |= flags_value;
  5175. else
  5176. *flags &= ~flags_value;
  5177. return pressed;
  5178. }
  5179. bool ImGui::RadioButton(const char* label, bool active)
  5180. {
  5181. ImGuiState& g = *GImGui;
  5182. ImGuiWindow* window = GetCurrentWindow();
  5183. if (window->SkipItems)
  5184. return false;
  5185. const ImGuiStyle& style = g.Style;
  5186. const ImGuiID id = window->GetID(label);
  5187. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5188. 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));
  5189. ItemSize(check_bb, style.FramePadding.y);
  5190. ImRect total_bb = check_bb;
  5191. if (label_size.x > 0)
  5192. SameLine(0, (int)style.ItemInnerSpacing.x);
  5193. const ImRect text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size);
  5194. if (label_size.x > 0)
  5195. {
  5196. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
  5197. total_bb.Add(text_bb);
  5198. }
  5199. if (!ItemAdd(total_bb, &id))
  5200. return false;
  5201. ImVec2 center = check_bb.GetCenter();
  5202. center.x = (float)(int)center.x + 0.5f;
  5203. center.y = (float)(int)center.y + 0.5f;
  5204. const float radius = check_bb.GetHeight() * 0.5f;
  5205. bool hovered, held;
  5206. bool pressed = ButtonBehavior(total_bb, id, &hovered, &held, true);
  5207. window->DrawList->AddCircleFilled(center, radius, window->Color((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), 16);
  5208. if (active)
  5209. {
  5210. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  5211. const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f;
  5212. window->DrawList->AddCircleFilled(center, radius-pad, window->Color(ImGuiCol_CheckMark), 16);
  5213. }
  5214. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  5215. {
  5216. window->DrawList->AddCircle(center+ImVec2(1,1), radius, window->Color(ImGuiCol_BorderShadow), 16);
  5217. window->DrawList->AddCircle(center, radius, window->Color(ImGuiCol_Border), 16);
  5218. }
  5219. if (g.LogEnabled)
  5220. LogText(text_bb.GetTL(), active ? "(x)" : "( )");
  5221. RenderText(text_bb.GetTL(), label);
  5222. return pressed;
  5223. }
  5224. bool ImGui::RadioButton(const char* label, int* v, int v_button)
  5225. {
  5226. const bool pressed = ImGui::RadioButton(label, *v == v_button);
  5227. if (pressed)
  5228. {
  5229. *v = v_button;
  5230. }
  5231. return pressed;
  5232. }
  5233. // 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)
  5234. static int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return (int)ImStrlenW(obj->Text); }
  5235. static ImWchar STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return obj->Text[idx]; }
  5236. 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; }
  5237. static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : key; }
  5238. static ImWchar STB_TEXTEDIT_NEWLINE = '\n';
  5239. static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx)
  5240. {
  5241. const ImWchar* text_remaining = NULL;
  5242. const ImVec2 size = obj->Font->CalcTextSizeW(obj->FontSize, FLT_MAX, obj->Text + line_start_idx, NULL, &text_remaining);
  5243. r->x0 = 0.0f;
  5244. r->x1 = size.x;
  5245. r->baseline_y_delta = size.y;
  5246. r->ymin = 0.0f;
  5247. r->ymax = size.y;
  5248. r->num_chars = (int)(text_remaining - (obj->Text + line_start_idx));
  5249. }
  5250. static bool is_separator(unsigned int c) { return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; }
  5251. #define STB_TEXTEDIT_IS_SPACE(CH) ( ImCharIsSpace((unsigned int)CH) || is_separator((unsigned int)CH) )
  5252. static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n)
  5253. {
  5254. ImWchar* dst = obj->Text + pos;
  5255. // We maintain our buffer length in both UTF-8 and wchar formats
  5256. obj->CurLenA -= ImTextCountUtf8BytesFromStr(dst, dst + n);
  5257. obj->CurLenW -= n;
  5258. // Offset remaining text
  5259. const ImWchar* src = obj->Text + pos + n;
  5260. while (ImWchar c = *src++)
  5261. *dst++ = c;
  5262. *dst = '\0';
  5263. }
  5264. static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len)
  5265. {
  5266. const size_t text_len = obj->CurLenW;
  5267. if ((size_t)new_text_len + text_len + 1 > IM_ARRAYSIZE(obj->Text))
  5268. return false;
  5269. const int new_text_len_utf8 = ImTextCountUtf8BytesFromStr(new_text, new_text + new_text_len);
  5270. if ((size_t)new_text_len_utf8 + obj->CurLenA + 1 > obj->BufSizeA)
  5271. return false;
  5272. if (pos != (int)text_len)
  5273. memmove(obj->Text + (size_t)pos + new_text_len, obj->Text + (size_t)pos, (text_len - (size_t)pos) * sizeof(ImWchar));
  5274. memcpy(obj->Text + (size_t)pos, new_text, (size_t)new_text_len * sizeof(ImWchar));
  5275. obj->CurLenW += new_text_len;
  5276. obj->CurLenA += new_text_len_utf8;
  5277. obj->Text[obj->CurLenW] = '\0';
  5278. return true;
  5279. }
  5280. // 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)
  5281. #define STB_TEXTEDIT_K_LEFT 0x10000 // keyboard input to move cursor left
  5282. #define STB_TEXTEDIT_K_RIGHT 0x10001 // keyboard input to move cursor right
  5283. #define STB_TEXTEDIT_K_UP 0x10002 // keyboard input to move cursor up
  5284. #define STB_TEXTEDIT_K_DOWN 0x10003 // keyboard input to move cursor down
  5285. #define STB_TEXTEDIT_K_LINESTART 0x10004 // keyboard input to move cursor to start of line
  5286. #define STB_TEXTEDIT_K_LINEEND 0x10005 // keyboard input to move cursor to end of line
  5287. #define STB_TEXTEDIT_K_TEXTSTART 0x10006 // keyboard input to move cursor to start of text
  5288. #define STB_TEXTEDIT_K_TEXTEND 0x10007 // keyboard input to move cursor to end of text
  5289. #define STB_TEXTEDIT_K_DELETE 0x10008 // keyboard input to delete selection or character under cursor
  5290. #define STB_TEXTEDIT_K_BACKSPACE 0x10009 // keyboard input to delete selection or character left of cursor
  5291. #define STB_TEXTEDIT_K_UNDO 0x1000A // keyboard input to perform undo
  5292. #define STB_TEXTEDIT_K_REDO 0x1000B // keyboard input to perform redo
  5293. #define STB_TEXTEDIT_K_WORDLEFT 0x1000C // keyboard input to move cursor left one word
  5294. #define STB_TEXTEDIT_K_WORDRIGHT 0x1000D // keyboard input to move cursor right one word
  5295. #define STB_TEXTEDIT_K_SHIFT 0x20000
  5296. #ifdef IMGUI_STB_NAMESPACE
  5297. namespace IMGUI_STB_NAMESPACE
  5298. {
  5299. #endif
  5300. #define STB_TEXTEDIT_IMPLEMENTATION
  5301. #include "stb_textedit.h"
  5302. #ifdef IMGUI_STB_NAMESPACE
  5303. }
  5304. #endif
  5305. void ImGuiTextEditState::OnKeyPressed(int key)
  5306. {
  5307. stb_textedit_key(this, &StbState, key);
  5308. CursorAnimReset();
  5309. }
  5310. void ImGuiTextEditState::UpdateScrollOffset()
  5311. {
  5312. // Scroll in chunks of quarter width
  5313. const float scroll_x_increment = Width * 0.25f;
  5314. const float cursor_offset_x = Font->CalcTextSizeW(FontSize, FLT_MAX, Text, Text+StbState.cursor, NULL).x;
  5315. // If widget became bigger than text (because of a resize), reset horizontal scrolling
  5316. if (ScrollX > 0.0f)
  5317. {
  5318. const float text_width = cursor_offset_x + Font->CalcTextSizeW(FontSize, FLT_MAX, Text+StbState.cursor, NULL, NULL).x;
  5319. if (text_width < Width)
  5320. {
  5321. ScrollX = 0.0f;
  5322. return;
  5323. }
  5324. }
  5325. if (cursor_offset_x < ScrollX)
  5326. ScrollX = ImMax(0.0f, cursor_offset_x - scroll_x_increment);
  5327. else if (cursor_offset_x - Width >= ScrollX)
  5328. ScrollX = cursor_offset_x - Width + scroll_x_increment;
  5329. }
  5330. ImVec2 ImGuiTextEditState::CalcDisplayOffsetFromCharIdx(int i) const
  5331. {
  5332. const ImWchar* text_start = GetTextPointerClippedW(Font, FontSize, Text, ScrollX, NULL);
  5333. const ImWchar* text_end = (Text+i >= text_start) ? Text+i : text_start; // Clip if requested character is outside of display
  5334. IM_ASSERT(text_end >= text_start);
  5335. const ImVec2 offset = Font->CalcTextSizeW(FontSize, Width+1, text_start, text_end, NULL);
  5336. return offset;
  5337. }
  5338. // [Static]
  5339. const char* ImGuiTextEditState::GetTextPointerClippedA(ImFont* font, float font_size, const char* text, float width, ImVec2* out_text_size)
  5340. {
  5341. if (width <= 0.0f)
  5342. return text;
  5343. const char* text_clipped_end = NULL;
  5344. const ImVec2 text_size = font->CalcTextSizeA(font_size, width, 0.0f, text, NULL, &text_clipped_end);
  5345. if (out_text_size)
  5346. *out_text_size = text_size;
  5347. return text_clipped_end;
  5348. }
  5349. // [Static]
  5350. const ImWchar* ImGuiTextEditState::GetTextPointerClippedW(ImFont* font, float font_size, const ImWchar* text, float width, ImVec2* out_text_size)
  5351. {
  5352. if (width <= 0.0f)
  5353. return text;
  5354. const ImWchar* text_clipped_end = NULL;
  5355. const ImVec2 text_size = font->CalcTextSizeW(font_size, width, text, NULL, &text_clipped_end);
  5356. if (out_text_size)
  5357. *out_text_size = text_size;
  5358. return text_clipped_end;
  5359. }
  5360. // [Static]
  5361. void ImGuiTextEditState::RenderTextScrolledClipped(ImFont* font, float font_size, const char* buf, ImVec2 pos, float width, float scroll_x)
  5362. {
  5363. ImGuiWindow* window = GetCurrentWindow();
  5364. const ImU32 font_color = window->Color(ImGuiCol_Text);
  5365. //window->DrawList->AddLine(pos, pos+ImVec2(width,0), 0xFF00FFFF);
  5366. // Determine start and end of visible string
  5367. // FIXME-OPT: This is pretty slow for what it does.
  5368. const char* text_start = scroll_x <= 0.0f ? buf : GetTextPointerClippedA(font, font_size, buf, scroll_x, NULL);
  5369. const char* text_end = GetTextPointerClippedA(font, font_size, text_start, width + 1, NULL); // +1 to allow character spacing to fit outside the allowed width
  5370. window->DrawList->AddText(font, font_size, pos, font_color, text_start, text_end);
  5371. // Log as text
  5372. if (GImGui->LogEnabled)
  5373. LogText(pos, buf, NULL);
  5374. }
  5375. bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags)
  5376. {
  5377. ImGuiState& g = *GImGui;
  5378. ImGuiWindow* window = GetCurrentWindow();
  5379. if (window->SkipItems)
  5380. return false;
  5381. const ImGuiStyle& style = g.Style;
  5382. const float w = ImGui::CalcItemWidth();
  5383. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5384. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
  5385. ImGui::BeginGroup();
  5386. ImGui::PushID(label);
  5387. const ImVec2 button_sz = ImVec2(g.FontSize, g.FontSize) + style.FramePadding * 2;
  5388. if (step > 0.0f)
  5389. ImGui::PushItemWidth(ImMax(1.0f, w - (button_sz.x + style.ItemInnerSpacing.x)*2));
  5390. char buf[64];
  5391. if (decimal_precision < 0)
  5392. 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?
  5393. else
  5394. ImFormatString(buf, IM_ARRAYSIZE(buf), "%.*f", decimal_precision, *v);
  5395. bool value_changed = false;
  5396. const ImGuiInputTextFlags flags = extra_flags | (ImGuiInputTextFlags_CharsDecimal|ImGuiInputTextFlags_AutoSelectAll);
  5397. if (ImGui::InputText("", buf, IM_ARRAYSIZE(buf), flags))
  5398. {
  5399. ApplyNumericalTextInput(buf, v);
  5400. value_changed = true;
  5401. }
  5402. // Step buttons
  5403. if (step > 0.0f)
  5404. {
  5405. ImGui::PopItemWidth();
  5406. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5407. if (ImGui::Button("-", button_sz, true))
  5408. {
  5409. *v -= g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
  5410. value_changed = true;
  5411. }
  5412. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5413. if (ImGui::Button("+", button_sz, true))
  5414. {
  5415. *v += g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
  5416. value_changed = true;
  5417. }
  5418. }
  5419. ImGui::PopID();
  5420. if (label_size.x > 0)
  5421. {
  5422. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5423. RenderText(ImVec2(window->DC.CursorPos.x, window->DC.CursorPos.y + style.FramePadding.y), label);
  5424. ItemSize(label_size, style.FramePadding.y);
  5425. }
  5426. ImGui::EndGroup();
  5427. return value_changed;
  5428. }
  5429. bool ImGui::InputInt(const char* label, int *v, int step, int step_fast, ImGuiInputTextFlags extra_flags)
  5430. {
  5431. float f = (float)*v;
  5432. const bool value_changed = ImGui::InputFloat(label, &f, (float)step, (float)step_fast, 0, extra_flags);
  5433. if (value_changed)
  5434. *v = (int)f;
  5435. return value_changed;
  5436. }
  5437. // Public API to manipulate UTF-8 text
  5438. // We expose UTF-8 to the user (unlike the STB_TEXTEDIT_* functions which are manipulating wchar)
  5439. void ImGuiTextEditCallbackData::DeleteChars(int pos, int bytes_count)
  5440. {
  5441. char* dst = Buf + pos;
  5442. const char* src = Buf + pos + bytes_count;
  5443. while (char c = *src++)
  5444. *dst++ = c;
  5445. *dst = '\0';
  5446. BufDirty = true;
  5447. if (CursorPos + bytes_count >= pos)
  5448. CursorPos -= bytes_count;
  5449. else if (CursorPos >= pos)
  5450. CursorPos = pos;
  5451. SelectionStart = SelectionEnd = CursorPos;
  5452. }
  5453. void ImGuiTextEditCallbackData::InsertChars(int pos, const char* new_text, const char* new_text_end)
  5454. {
  5455. const size_t text_len = strlen(Buf);
  5456. if (!new_text_end)
  5457. new_text_end = new_text + strlen(new_text);
  5458. const size_t new_text_len = (size_t)(new_text_end - new_text);
  5459. if (new_text_len + text_len + 1 >= BufSize)
  5460. return;
  5461. size_t upos = (size_t)pos;
  5462. if (text_len != upos)
  5463. memmove(Buf + upos + new_text_len, Buf + upos, text_len - upos);
  5464. memcpy(Buf + upos, new_text, new_text_len * sizeof(char));
  5465. Buf[text_len + new_text_len] = '\0';
  5466. BufDirty = true;
  5467. if (CursorPos >= pos)
  5468. CursorPos += (int)new_text_len;
  5469. SelectionStart = SelectionEnd = CursorPos;
  5470. }
  5471. // Return false to discard a character.
  5472. static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data)
  5473. {
  5474. unsigned int c = *p_char;
  5475. if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF)))
  5476. return false;
  5477. 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.
  5478. return false;
  5479. if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank))
  5480. {
  5481. if (flags & ImGuiInputTextFlags_CharsDecimal)
  5482. if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
  5483. return false;
  5484. if (flags & ImGuiInputTextFlags_CharsHexadecimal)
  5485. if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
  5486. return false;
  5487. if (flags & ImGuiInputTextFlags_CharsUppercase)
  5488. if (c >= 'a' && c <= 'z')
  5489. *p_char = (c += (unsigned int)('A'-'a'));
  5490. if (flags & ImGuiInputTextFlags_CharsNoBlank)
  5491. if (ImCharIsSpace(c))
  5492. return false;
  5493. }
  5494. if (flags & ImGuiInputTextFlags_CallbackCharFilter)
  5495. {
  5496. ImGuiTextEditCallbackData callback_data;
  5497. memset(&callback_data, 0, sizeof(ImGuiTextEditCallbackData));
  5498. callback_data.EventFlag = ImGuiInputTextFlags_CallbackCharFilter;
  5499. callback_data.EventChar = (ImWchar)c;
  5500. callback_data.Flags = flags;
  5501. callback_data.UserData = user_data;
  5502. if (callback(&callback_data) != 0)
  5503. return false;
  5504. *p_char = callback_data.EventChar;
  5505. if (!callback_data.EventChar)
  5506. return false;
  5507. }
  5508. return true;
  5509. }
  5510. // Edit a string of text
  5511. bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data)
  5512. {
  5513. ImGuiState& g = *GImGui;
  5514. ImGuiWindow* window = GetCurrentWindow();
  5515. if (window->SkipItems)
  5516. return false;
  5517. const ImGuiIO& io = g.IO;
  5518. const ImGuiStyle& style = g.Style;
  5519. const ImGuiID id = window->GetID(label);
  5520. const float w = ImGui::CalcItemWidth();
  5521. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5522. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
  5523. 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));
  5524. ItemSize(total_bb, style.FramePadding.y);
  5525. if (!ItemAdd(total_bb, &id))
  5526. return false;
  5527. // NB: we are only allowed to access 'edit_state' if we are the active widget.
  5528. ImGuiTextEditState& edit_state = g.InputTextState;
  5529. const bool is_ctrl_down = io.KeyCtrl;
  5530. const bool is_shift_down = io.KeyShift;
  5531. const bool focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & ImGuiInputTextFlags_CallbackCompletion) == 0); // Using completion callback disable keyboard tabbing
  5532. const bool focus_requested_by_code = focus_requested && (window->FocusIdxAllCounter == window->FocusIdxAllRequestCurrent);
  5533. const bool focus_requested_by_tab = focus_requested && !focus_requested_by_code;
  5534. const bool hovered = IsHovered(frame_bb, id);
  5535. if (hovered)
  5536. {
  5537. g.HoveredId = id;
  5538. g.MouseCursor = ImGuiMouseCursor_TextInput;
  5539. }
  5540. const bool user_clicked = hovered && io.MouseClicked[0];
  5541. bool select_all = (g.ActiveId != id) && (flags & ImGuiInputTextFlags_AutoSelectAll) != 0;
  5542. if (focus_requested || user_clicked)
  5543. {
  5544. if (g.ActiveId != id)
  5545. {
  5546. // Start edition
  5547. // Take a copy of the initial buffer value (both in original UTF-8 format and converted to wchar)
  5548. // From the moment we focused we are ignoring the content of 'buf'
  5549. ImFormatString(edit_state.InitialText, IM_ARRAYSIZE(edit_state.InitialText), "%s", buf);
  5550. const char* buf_end = NULL;
  5551. edit_state.CurLenW = ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), buf, NULL, &buf_end);
  5552. 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.
  5553. edit_state.Width = w + style.FramePadding.x;
  5554. edit_state.InputCursorScreenPos = ImVec2(-1.f,-1.f);
  5555. edit_state.CursorAnimReset();
  5556. if (edit_state.Id != id)
  5557. {
  5558. edit_state.Id = id;
  5559. edit_state.ScrollX = 0.0f;
  5560. stb_textedit_initialize_state(&edit_state.StbState, true);
  5561. if (focus_requested_by_code)
  5562. select_all = true;
  5563. }
  5564. else
  5565. {
  5566. // Recycle existing cursor/selection/undo stack but clamp position
  5567. // Note a single mouse click will override the cursor/position immediately by calling stb_textedit_click handler.
  5568. edit_state.StbState.cursor = ImMin(edit_state.StbState.cursor, (int)edit_state.CurLenW);
  5569. edit_state.StbState.select_start = ImMin(edit_state.StbState.select_start, (int)edit_state.CurLenW);
  5570. edit_state.StbState.select_end = ImMin(edit_state.StbState.select_end, (int)edit_state.CurLenW);
  5571. }
  5572. if (focus_requested_by_tab || (user_clicked && is_ctrl_down))
  5573. select_all = true;
  5574. }
  5575. SetActiveId(id);
  5576. FocusWindow(window);
  5577. }
  5578. else if (io.MouseClicked[0])
  5579. {
  5580. // Release focus when we click outside
  5581. if (g.ActiveId == id)
  5582. {
  5583. SetActiveId(0);
  5584. }
  5585. }
  5586. // Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget.
  5587. // Down the line we should have a cleaner concept of focused vs active in the library.
  5588. if (g.ActiveId == id)
  5589. g.ActiveIdIsFocusedOnly = !io.MouseDown[0];
  5590. bool value_changed = false;
  5591. bool cancel_edit = false;
  5592. bool enter_pressed = false;
  5593. if (g.ActiveId == id)
  5594. //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.
  5595. {
  5596. // Update some data if we are active or last active
  5597. edit_state.Width = w + style.FramePadding.x;
  5598. edit_state.BufSizeA = buf_size;
  5599. edit_state.Font = g.Font;
  5600. edit_state.FontSize = g.FontSize;
  5601. edit_state.UpdateScrollOffset();
  5602. }
  5603. if (g.ActiveId == id)
  5604. {
  5605. // Edit in progress
  5606. const float mx = g.IO.MousePos.x - frame_bb.Min.x - style.FramePadding.x;
  5607. const float my = g.FontSize*0.5f; // Flatten mouse because we are doing a single-line edit
  5608. if (select_all || (hovered && io.MouseDoubleClicked[0]))
  5609. {
  5610. edit_state.SelectAll();
  5611. edit_state.SelectedAllMouseLock = true;
  5612. }
  5613. else if (io.MouseClicked[0] && !edit_state.SelectedAllMouseLock)
  5614. {
  5615. stb_textedit_click(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my);
  5616. edit_state.CursorAnimReset();
  5617. }
  5618. else if (io.MouseDown[0] && !edit_state.SelectedAllMouseLock)
  5619. {
  5620. stb_textedit_drag(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my);
  5621. edit_state.CursorAnimReset();
  5622. }
  5623. if (edit_state.SelectedAllMouseLock && !io.MouseDown[0])
  5624. edit_state.SelectedAllMouseLock = false;
  5625. if (g.IO.InputCharacters[0])
  5626. {
  5627. // Process text input (before we check for Return because using some IME will effectively send a Return?)
  5628. for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++)
  5629. {
  5630. unsigned int c = (unsigned int)g.IO.InputCharacters[n];
  5631. if (c)
  5632. {
  5633. // Insert character if they pass filtering
  5634. if (!InputTextFilterCharacter(&c, flags, callback, user_data))
  5635. continue;
  5636. edit_state.OnKeyPressed((int)c);
  5637. }
  5638. }
  5639. // Consume characters
  5640. memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
  5641. }
  5642. const int k_mask = (is_shift_down ? STB_TEXTEDIT_K_SHIFT : 0);
  5643. if (IsKeyPressedMap(ImGuiKey_LeftArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDLEFT | k_mask : STB_TEXTEDIT_K_LEFT | k_mask); }
  5644. else if (IsKeyPressedMap(ImGuiKey_RightArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDRIGHT | k_mask : STB_TEXTEDIT_K_RIGHT | k_mask); }
  5645. else if (IsKeyPressedMap(ImGuiKey_Home)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); }
  5646. else if (IsKeyPressedMap(ImGuiKey_End)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); }
  5647. else if (IsKeyPressedMap(ImGuiKey_Delete)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); }
  5648. else if (IsKeyPressedMap(ImGuiKey_Backspace)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask); }
  5649. else if (IsKeyPressedMap(ImGuiKey_Enter)) { SetActiveId(0); enter_pressed = true; }
  5650. else if (IsKeyPressedMap(ImGuiKey_Escape)) { SetActiveId(0); cancel_edit = true; }
  5651. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Z)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_UNDO); }
  5652. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Y)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_REDO); }
  5653. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_A)) { edit_state.SelectAll(); }
  5654. else if (is_ctrl_down && (IsKeyPressedMap(ImGuiKey_X) || IsKeyPressedMap(ImGuiKey_C)))
  5655. {
  5656. // Cut, Copy
  5657. const bool cut = IsKeyPressedMap(ImGuiKey_X);
  5658. if (cut && !edit_state.HasSelection())
  5659. edit_state.SelectAll();
  5660. if (g.IO.SetClipboardTextFn)
  5661. {
  5662. const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0;
  5663. const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : (int)edit_state.CurLenW;
  5664. ImTextStrToUtf8(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), edit_state.Text+ib, edit_state.Text+ie);
  5665. g.IO.SetClipboardTextFn(g.TempBuffer);
  5666. }
  5667. if (cut)
  5668. stb_textedit_cut(&edit_state, &edit_state.StbState);
  5669. }
  5670. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_V))
  5671. {
  5672. // Paste
  5673. if (g.IO.GetClipboardTextFn)
  5674. {
  5675. if (const char* clipboard = g.IO.GetClipboardTextFn())
  5676. {
  5677. // Remove new-line from pasted buffer
  5678. const size_t clipboard_len = strlen(clipboard);
  5679. ImWchar* clipboard_filtered = (ImWchar*)ImGui::MemAlloc((clipboard_len+1) * sizeof(ImWchar));
  5680. int clipboard_filtered_len = 0;
  5681. for (const char* s = clipboard; *s; )
  5682. {
  5683. unsigned int c;
  5684. s += ImTextCharFromUtf8(&c, s, NULL);
  5685. if (c == 0)
  5686. break;
  5687. if (c >= 0x10000)
  5688. continue;
  5689. if (!InputTextFilterCharacter(&c, flags, callback, user_data))
  5690. continue;
  5691. clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c;
  5692. }
  5693. clipboard_filtered[clipboard_filtered_len] = 0;
  5694. if (clipboard_filtered_len > 0) // If everything was filtered, ignore the pasting operation
  5695. stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len);
  5696. ImGui::MemFree(clipboard_filtered);
  5697. }
  5698. }
  5699. }
  5700. edit_state.CursorAnim += g.IO.DeltaTime;
  5701. edit_state.UpdateScrollOffset();
  5702. if (cancel_edit)
  5703. {
  5704. // Restore initial value
  5705. ImFormatString(buf, buf_size, "%s", edit_state.InitialText);
  5706. value_changed = true;
  5707. }
  5708. else
  5709. {
  5710. // Apply new value immediately - copy modified buffer back
  5711. // 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
  5712. // FIXME: We actually always render 'buf' in RenderTextScrolledClipped
  5713. // FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks
  5714. ImTextStrToUtf8(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), edit_state.Text, NULL);
  5715. // User callback
  5716. if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways)) != 0)
  5717. {
  5718. IM_ASSERT(callback != NULL);
  5719. // The reason we specify the usage semantic (Completion/History) is that Completion needs to disable keyboard TABBING at the moment.
  5720. ImGuiInputTextFlags event_flag = 0;
  5721. ImGuiKey event_key = ImGuiKey_COUNT;
  5722. if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && IsKeyPressedMap(ImGuiKey_Tab))
  5723. {
  5724. event_flag = ImGuiInputTextFlags_CallbackCompletion;
  5725. event_key = ImGuiKey_Tab;
  5726. }
  5727. else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_UpArrow))
  5728. {
  5729. event_flag = ImGuiInputTextFlags_CallbackHistory;
  5730. event_key = ImGuiKey_UpArrow;
  5731. }
  5732. else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_DownArrow))
  5733. {
  5734. event_flag = ImGuiInputTextFlags_CallbackHistory;
  5735. event_key = ImGuiKey_DownArrow;
  5736. }
  5737. if (event_key != ImGuiKey_COUNT || (flags & ImGuiInputTextFlags_CallbackAlways) != 0)
  5738. {
  5739. ImGuiTextEditCallbackData callback_data;
  5740. callback_data.EventFlag = event_flag;
  5741. callback_data.EventKey = event_key;
  5742. callback_data.Buf = g.TempBuffer;
  5743. callback_data.BufSize = edit_state.BufSizeA;
  5744. callback_data.BufDirty = false;
  5745. callback_data.Flags = flags;
  5746. callback_data.UserData = user_data;
  5747. // We have to convert from position from wchar to UTF-8 positions
  5748. const int utf8_cursor_pos = callback_data.CursorPos = ImTextCountUtf8BytesFromStr(edit_state.Text, edit_state.Text + edit_state.StbState.cursor);
  5749. const int utf8_selection_start = callback_data.SelectionStart = ImTextCountUtf8BytesFromStr(edit_state.Text, edit_state.Text + edit_state.StbState.select_start);
  5750. const int utf8_selection_end = callback_data.SelectionEnd = ImTextCountUtf8BytesFromStr(edit_state.Text, edit_state.Text + edit_state.StbState.select_end);
  5751. // Call user code
  5752. callback(&callback_data);
  5753. // Read back what user may have modified
  5754. IM_ASSERT(callback_data.Buf == g.TempBuffer); // Invalid to modify those fields
  5755. IM_ASSERT(callback_data.BufSize == edit_state.BufSizeA);
  5756. IM_ASSERT(callback_data.Flags == flags);
  5757. if (callback_data.CursorPos != utf8_cursor_pos) edit_state.StbState.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos);
  5758. if (callback_data.SelectionStart != utf8_selection_start) edit_state.StbState.select_start = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionStart);
  5759. if (callback_data.SelectionEnd != utf8_selection_end) edit_state.StbState.select_end = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionEnd);
  5760. if (callback_data.BufDirty)
  5761. {
  5762. ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), g.TempBuffer, NULL);
  5763. edit_state.CursorAnimReset();
  5764. }
  5765. }
  5766. }
  5767. if (strcmp(g.TempBuffer, buf) != 0)
  5768. {
  5769. ImFormatString(buf, buf_size, "%s", g.TempBuffer);
  5770. value_changed = true;
  5771. }
  5772. }
  5773. }
  5774. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  5775. const ImVec2 font_off_up = ImVec2(0.0f, g.FontSize+1.0f); // FIXME: those offsets are part of the style or font API
  5776. const ImVec2 font_off_dn = ImVec2(0.0f, 2.0f);
  5777. if (g.ActiveId == id)
  5778. {
  5779. // Draw selection
  5780. const int select_begin_idx = edit_state.StbState.select_start;
  5781. const int select_end_idx = edit_state.StbState.select_end;
  5782. if (select_begin_idx != select_end_idx)
  5783. {
  5784. const ImVec2 select_begin_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMin(select_begin_idx,select_end_idx));
  5785. const ImVec2 select_end_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMax(select_begin_idx,select_end_idx));
  5786. window->DrawList->AddRectFilled(select_begin_pos - font_off_up, select_end_pos + font_off_dn, window->Color(ImGuiCol_TextSelectedBg));
  5787. }
  5788. }
  5789. //const float render_scroll_x = (g.ActiveId == id) ? edit_state.ScrollX : 0.0f;
  5790. const float render_scroll_x = (edit_state.Id == id) ? edit_state.ScrollX : 0.0f;
  5791. ImGuiTextEditState::RenderTextScrolledClipped(g.Font, g.FontSize, buf, frame_bb.Min + style.FramePadding, w + style.FramePadding.x, render_scroll_x);
  5792. if (g.ActiveId == id)
  5793. {
  5794. const ImVec2 cursor_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(edit_state.StbState.cursor);
  5795. // Draw blinking cursor
  5796. if (g.InputTextState.CursorIsVisible())
  5797. window->DrawList->AddRect(cursor_pos - font_off_up + ImVec2(0,2), cursor_pos + font_off_dn - ImVec2(0,3), window->Color(ImGuiCol_Text));
  5798. // Notify OS of text input position for advanced IME
  5799. if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.InputCursorScreenPos - cursor_pos) > 0.0001f)
  5800. io.ImeSetInputScreenPosFn((int)cursor_pos.x - 1, (int)(cursor_pos.y - g.FontSize)); // -1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety.
  5801. edit_state.InputCursorScreenPos = cursor_pos;
  5802. }
  5803. if (label_size.x > 0)
  5804. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  5805. if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0)
  5806. return enter_pressed;
  5807. else
  5808. return value_changed;
  5809. }
  5810. static bool InputFloatN(const char* label, float* v, int components, int decimal_precision)
  5811. {
  5812. ImGuiState& g = *GImGui;
  5813. ImGuiWindow* window = GetCurrentWindow();
  5814. if (window->SkipItems)
  5815. return false;
  5816. const ImGuiStyle& style = g.Style;
  5817. const float w_full = ImGui::CalcItemWidth();
  5818. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components));
  5819. 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)));
  5820. bool value_changed = false;
  5821. ImGui::BeginGroup();
  5822. ImGui::PushID(label);
  5823. ImGui::PushItemWidth(w_item_one);
  5824. for (int i = 0; i < components; i++)
  5825. {
  5826. ImGui::PushID(i);
  5827. if (i + 1 == components)
  5828. {
  5829. ImGui::PopItemWidth();
  5830. ImGui::PushItemWidth(w_item_last);
  5831. }
  5832. value_changed |= ImGui::InputFloat("##v", &v[i], 0, 0, decimal_precision);
  5833. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5834. ImGui::PopID();
  5835. }
  5836. ImGui::PopItemWidth();
  5837. ImGui::PopID();
  5838. window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, style.FramePadding.y);
  5839. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  5840. ImGui::EndGroup();
  5841. return value_changed;
  5842. }
  5843. bool ImGui::InputFloat2(const char* label, float v[2], int decimal_precision)
  5844. {
  5845. return InputFloatN(label, v, 2, decimal_precision);
  5846. }
  5847. bool ImGui::InputFloat3(const char* label, float v[3], int decimal_precision)
  5848. {
  5849. return InputFloatN(label, v, 3, decimal_precision);
  5850. }
  5851. bool ImGui::InputFloat4(const char* label, float v[4], int decimal_precision)
  5852. {
  5853. return InputFloatN(label, v, 4, decimal_precision);
  5854. }
  5855. static bool InputIntN(const char* label, int* v, int components)
  5856. {
  5857. ImGuiState& g = *GImGui;
  5858. ImGuiWindow* window = GetCurrentWindow();
  5859. if (window->SkipItems)
  5860. return false;
  5861. const ImGuiStyle& style = g.Style;
  5862. const float w_full = ImGui::CalcItemWidth();
  5863. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components));
  5864. 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)));
  5865. bool value_changed = false;
  5866. ImGui::BeginGroup();
  5867. ImGui::PushID(label);
  5868. ImGui::PushItemWidth(w_item_one);
  5869. for (int i = 0; i < components; i++)
  5870. {
  5871. ImGui::PushID(i);
  5872. if (i + 1 == components)
  5873. {
  5874. ImGui::PopItemWidth();
  5875. ImGui::PushItemWidth(w_item_last);
  5876. }
  5877. value_changed |= ImGui::InputInt("##v", &v[i], 0, 0);
  5878. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  5879. ImGui::PopID();
  5880. }
  5881. ImGui::PopItemWidth();
  5882. ImGui::PopID();
  5883. window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, style.FramePadding.y);
  5884. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  5885. ImGui::EndGroup();
  5886. return value_changed;
  5887. }
  5888. bool ImGui::InputInt2(const char* label, int v[2])
  5889. {
  5890. return InputIntN(label, v, 2);
  5891. }
  5892. bool ImGui::InputInt3(const char* label, int v[3])
  5893. {
  5894. return InputIntN(label, v, 3);
  5895. }
  5896. bool ImGui::InputInt4(const char* label, int v[4])
  5897. {
  5898. return InputIntN(label, v, 4);
  5899. }
  5900. static bool Items_ArrayGetter(void* data, int idx, const char** out_text)
  5901. {
  5902. const char** items = (const char**)data;
  5903. if (out_text)
  5904. *out_text = items[idx];
  5905. return true;
  5906. }
  5907. static bool Items_SingleStringGetter(void* data, int idx, const char** out_text)
  5908. {
  5909. // FIXME-OPT: we could pre-compute the indices to fasten this. But only 1 active combo means the waste is limited.
  5910. const char* items_separated_by_zeros = (const char*)data;
  5911. int items_count = 0;
  5912. const char* p = items_separated_by_zeros;
  5913. while (*p)
  5914. {
  5915. if (idx == items_count)
  5916. break;
  5917. p += strlen(p) + 1;
  5918. items_count++;
  5919. }
  5920. if (!*p)
  5921. return false;
  5922. if (out_text)
  5923. *out_text = p;
  5924. return true;
  5925. }
  5926. // Combo box helper allowing to pass an array of strings.
  5927. bool ImGui::Combo(const char* label, int* current_item, const char** items, int items_count, int height_in_items)
  5928. {
  5929. const bool value_changed = Combo(label, current_item, Items_ArrayGetter, (void*)items, items_count, height_in_items);
  5930. return value_changed;
  5931. }
  5932. // Combo box helper allowing to pass all items in a single string.
  5933. bool ImGui::Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int height_in_items)
  5934. {
  5935. int items_count = 0;
  5936. const char* p = items_separated_by_zeros; // FIXME-OPT: Avoid computing this
  5937. while (*p)
  5938. {
  5939. p += strlen(p) + 1;
  5940. items_count++;
  5941. }
  5942. bool value_changed = Combo(label, current_item, Items_SingleStringGetter, (void*)items_separated_by_zeros, items_count, height_in_items);
  5943. return value_changed;
  5944. }
  5945. // Combo box function.
  5946. 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)
  5947. {
  5948. ImGuiState& g = *GImGui;
  5949. ImGuiWindow* window = GetCurrentWindow();
  5950. if (window->SkipItems)
  5951. return false;
  5952. const ImGuiStyle& style = g.Style;
  5953. const ImGuiID id = window->GetID(label);
  5954. const float w = ImGui::CalcItemWidth();
  5955. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5956. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
  5957. const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + label_size.x,0));
  5958. ItemSize(total_bb, style.FramePadding.y);
  5959. if (!ItemAdd(total_bb, &id))
  5960. return false;
  5961. const float arrow_size = (g.FontSize + style.FramePadding.x * 2.0f);
  5962. const bool hovered = IsHovered(frame_bb, id);
  5963. bool value_changed = false;
  5964. const ImRect value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f));
  5965. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  5966. 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
  5967. RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true);
  5968. if (*current_item >= 0 && *current_item < items_count)
  5969. {
  5970. const char* item_text;
  5971. if (items_getter(data, *current_item, &item_text))
  5972. RenderTextClipped(frame_bb.Min + style.FramePadding, item_text, NULL, NULL, value_bb.Max);
  5973. }
  5974. if (label_size.x > 0)
  5975. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  5976. ImGui::PushID((int)id);
  5977. bool menu_toggled = false;
  5978. if (hovered)
  5979. {
  5980. g.HoveredId = id;
  5981. if (g.IO.MouseClicked[0])
  5982. {
  5983. menu_toggled = true;
  5984. g.ActiveComboID = (g.ActiveComboID == id) ? 0 : id;
  5985. if (g.ActiveComboID)
  5986. FocusWindow(window);
  5987. }
  5988. }
  5989. if (g.ActiveComboID == id)
  5990. {
  5991. // Size default to hold ~7 items
  5992. if (height_in_items < 0)
  5993. height_in_items = 7;
  5994. const ImVec2 backup_pos = ImGui::GetCursorPos();
  5995. const float popup_off_x = 0.0f;//style.ItemInnerSpacing.x;
  5996. const float popup_height = (label_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + (style.FramePadding.y * 3);
  5997. 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));
  5998. ImGui::SetCursorPos(popup_rect.Min - window->Pos);
  5999. const ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ((window->Flags & ImGuiWindowFlags_ShowBorders) ? ImGuiWindowFlags_ShowBorders : 0);
  6000. ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.FramePadding);
  6001. ImGui::BeginChild("#ComboBox", popup_rect.GetSize(), false, flags);
  6002. ImGui::Spacing();
  6003. bool combo_item_active = false;
  6004. combo_item_active |= (g.ActiveId == GetCurrentWindow()->GetID("#SCROLLY"));
  6005. // Display items
  6006. for (int i = 0; i < items_count; i++)
  6007. {
  6008. ImGui::PushID((void*)(intptr_t)i);
  6009. const bool item_selected = (i == *current_item);
  6010. const char* item_text;
  6011. if (!items_getter(data, i, &item_text))
  6012. item_text = "*Unknown item*";
  6013. if (ImGui::Selectable(item_text, item_selected))
  6014. {
  6015. SetActiveId(0);
  6016. g.ActiveComboID = 0;
  6017. value_changed = true;
  6018. *current_item = i;
  6019. }
  6020. if (item_selected && menu_toggled)
  6021. ImGui::SetScrollPosHere();
  6022. combo_item_active |= ImGui::IsItemActive();
  6023. ImGui::PopID();
  6024. }
  6025. ImGui::EndChild();
  6026. ImGui::PopStyleVar();
  6027. ImGui::SetCursorPos(backup_pos);
  6028. if (!combo_item_active && g.ActiveId != 0)
  6029. g.ActiveComboID = 0;
  6030. }
  6031. ImGui::PopID();
  6032. return value_changed;
  6033. }
  6034. // Tip: pass an empty label (e.g. "##dummy") then you can use the space to draw other text or image.
  6035. // But you need to make sure the ID is unique, e.g. enclose calls in PushID/PopID.
  6036. bool ImGui::Selectable(const char* label, bool selected, const ImVec2& size_arg)
  6037. {
  6038. ImGuiState& g = *GImGui;
  6039. ImGuiWindow* window = GetCurrentWindow();
  6040. if (window->SkipItems)
  6041. return false;
  6042. const ImGuiStyle& style = g.Style;
  6043. const ImGuiID id = window->GetID(label);
  6044. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  6045. const float w = ImMax(label_size.x, window->Pos.x + ImGui::GetContentRegionMax().x - style.AutoFitPadding.x - window->DC.CursorPos.x);
  6046. const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : w, size_arg.y != 0.0f ? size_arg.y : label_size.y);
  6047. ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
  6048. ItemSize(bb);
  6049. if (size_arg.x == 0.0f)
  6050. bb.Max.x += style.AutoFitPadding.x;
  6051. // Selectables are meant to be tightly packed together. So for both rendering and collision we extend to compensate for spacing.
  6052. ImRect bb_with_spacing = bb;
  6053. const float spacing_L = (float)(int)(style.ItemSpacing.x * 0.5f);
  6054. const float spacing_U = (float)(int)(style.ItemSpacing.y * 0.5f);
  6055. const float spacing_R = style.ItemSpacing.x - spacing_L;
  6056. const float spacing_D = style.ItemSpacing.y - spacing_U;
  6057. bb_with_spacing.Min.x -= spacing_L;
  6058. bb_with_spacing.Min.y -= spacing_U;
  6059. bb_with_spacing.Max.x += spacing_R;
  6060. bb_with_spacing.Max.y += spacing_D;
  6061. if (!ItemAdd(bb_with_spacing, &id))
  6062. return false;
  6063. bool hovered, held;
  6064. bool pressed = ButtonBehavior(bb_with_spacing, id, &hovered, &held, true, false, false);
  6065. // Render
  6066. if (hovered || selected)
  6067. {
  6068. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
  6069. RenderFrame(bb_with_spacing.Min, bb_with_spacing.Max, col, false, style.FrameRounding);
  6070. }
  6071. //const ImVec2 off = ImVec2(ImMax(0.0f, size.x - text_size.x) * 0.5f, ImMax(0.0f, size.y - text_size.y) * 0.5f);
  6072. RenderTextClipped(bb.Min, label, NULL, &label_size, bb_with_spacing.Max);
  6073. return pressed;
  6074. }
  6075. bool ImGui::Selectable(const char* label, bool* p_selected, const ImVec2& size_arg)
  6076. {
  6077. if (ImGui::Selectable(label, *p_selected, size_arg))
  6078. {
  6079. *p_selected = !*p_selected;
  6080. return true;
  6081. }
  6082. return false;
  6083. }
  6084. // Helper to calculate the size of a listbox and display a label on the right.
  6085. // Tip: To have a list filling the entire window width, PushItemWidth(-1) and pass an empty label "##empty"
  6086. bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg)
  6087. {
  6088. ImGuiWindow* window = GetCurrentWindow();
  6089. const ImGuiStyle& style = ImGui::GetStyle();
  6090. const ImGuiID id = ImGui::GetID(label);
  6091. const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
  6092. // Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar.
  6093. ImVec2 size;
  6094. size.x = (size_arg.x != 0.0f) ? (size_arg.x) : ImGui::CalcItemWidth() + style.FramePadding.x * 2.0f;
  6095. size.y = (size_arg.y != 0.0f) ? (size_arg.y) : ImGui::GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y;
  6096. const ImVec2 frame_size = ImVec2(size.x, ImMax(size.y, label_size.y));
  6097. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
  6098. 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));
  6099. window->DC.LastItemRect = bb;
  6100. ImGui::BeginGroup();
  6101. if (label_size.x > 0)
  6102. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  6103. ImGui::BeginChildFrame(id, frame_bb.GetSize());
  6104. return true;
  6105. }
  6106. bool ImGui::ListBoxHeader(const char* label, int items_count, int height_in_items)
  6107. {
  6108. // Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar.
  6109. // 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.
  6110. // I am expecting that someone will come and complain about this behavior in a remote future, then we can advise on a better solution.
  6111. if (height_in_items < 0)
  6112. height_in_items = ImMin(items_count, 7);
  6113. float height_in_items_f = height_in_items < items_count ? (height_in_items + 0.40f) : (height_in_items + 0.00f);
  6114. // 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().
  6115. ImVec2 size;
  6116. size.x = 0.0f;
  6117. size.y = ImGui::GetTextLineHeightWithSpacing() * height_in_items_f + ImGui::GetStyle().ItemSpacing.y;
  6118. return ImGui::ListBoxHeader(label, size);
  6119. }
  6120. void ImGui::ListBoxFooter()
  6121. {
  6122. ImGuiWindow* parent_window = GetParentWindow();
  6123. const ImRect bb = parent_window->DC.LastItemRect;
  6124. const ImGuiStyle& style = ImGui::GetStyle();
  6125. ImGui::EndChildFrame();
  6126. // Redeclare item size so that it includes the label (we have stored the full size in LastItemRect)
  6127. // We call SameLine() to restore DC.CurrentLine* data
  6128. ImGui::SameLine();
  6129. parent_window->DC.CursorPos = bb.Min;
  6130. ItemSize(bb, style.FramePadding.y);
  6131. ImGui::EndGroup();
  6132. }
  6133. bool ImGui::ListBox(const char* label, int* current_item, const char** items, int items_count, int height_items)
  6134. {
  6135. const bool value_changed = ListBox(label, current_item, Items_ArrayGetter, (void*)items, items_count, height_items);
  6136. return value_changed;
  6137. }
  6138. 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)
  6139. {
  6140. ImGuiWindow* window = GetCurrentWindow();
  6141. if (window->SkipItems)
  6142. return false;
  6143. if (!ImGui::ListBoxHeader(label, items_count, height_in_items))
  6144. return false;
  6145. bool value_changed = false;
  6146. for (int i = 0; i < items_count; i++)
  6147. {
  6148. const bool item_selected = (i == *current_item);
  6149. const char* item_text;
  6150. if (!items_getter(data, i, &item_text))
  6151. item_text = "*Unknown item*";
  6152. ImGui::PushID(i);
  6153. if (ImGui::Selectable(item_text, item_selected))
  6154. {
  6155. *current_item = i;
  6156. value_changed = true;
  6157. }
  6158. ImGui::PopID();
  6159. }
  6160. ImGui::ListBoxFooter();
  6161. return value_changed;
  6162. }
  6163. // A little colored square. Return true when clicked.
  6164. bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_border)
  6165. {
  6166. ImGuiState& g = *GImGui;
  6167. ImGuiWindow* window = GetCurrentWindow();
  6168. if (window->SkipItems)
  6169. return false;
  6170. const ImGuiStyle& style = g.Style;
  6171. const ImGuiID id = window->GetID("#colorbutton");
  6172. const float square_size = g.FontSize;
  6173. 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)));
  6174. ItemSize(bb, small_height ? 0.0f : style.FramePadding.y);
  6175. if (!ItemAdd(bb, &id))
  6176. return false;
  6177. bool hovered, held;
  6178. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  6179. RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border, style.FrameRounding);
  6180. if (hovered)
  6181. {
  6182. int ix = (int)(col.x * 255.0f + 0.5f);
  6183. int iy = (int)(col.y * 255.0f + 0.5f);
  6184. int iz = (int)(col.z * 255.0f + 0.5f);
  6185. int iw = (int)(col.w * 255.0f + 0.5f);
  6186. 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);
  6187. }
  6188. return pressed;
  6189. }
  6190. bool ImGui::ColorEdit3(const char* label, float col[3])
  6191. {
  6192. float col4[4];
  6193. col4[0] = col[0];
  6194. col4[1] = col[1];
  6195. col4[2] = col[2];
  6196. col4[3] = 1.0f;
  6197. const bool value_changed = ImGui::ColorEdit4(label, col4, false);
  6198. col[0] = col4[0];
  6199. col[1] = col4[1];
  6200. col[2] = col4[2];
  6201. return value_changed;
  6202. }
  6203. // Edit colors components (each component in 0.0f..1.0f range
  6204. // Use CTRL-Click to input value and TAB to go to next item.
  6205. bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha)
  6206. {
  6207. ImGuiState& g = *GImGui;
  6208. ImGuiWindow* window = GetCurrentWindow();
  6209. if (window->SkipItems)
  6210. return false;
  6211. const ImGuiStyle& style = g.Style;
  6212. const ImGuiID id = window->GetID(label);
  6213. const float w_full = ImGui::CalcItemWidth();
  6214. const float square_sz = (g.FontSize + style.FramePadding.x * 2.0f);
  6215. ImGuiColorEditMode edit_mode = window->DC.ColorEditMode;
  6216. if (edit_mode == ImGuiColorEditMode_UserSelect || edit_mode == ImGuiColorEditMode_UserSelectShowButton)
  6217. edit_mode = g.ColorEditModeStorage.GetInt(id, 0) % 3;
  6218. float f[4] = { col[0], col[1], col[2], col[3] };
  6219. if (edit_mode == ImGuiColorEditMode_HSV)
  6220. ImGui::ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]);
  6221. int i[4] = { (int)(f[0] * 255.0f + 0.5f), (int)(f[1] * 255.0f + 0.5f), (int)(f[2] * 255.0f + 0.5f), (int)(f[3] * 255.0f + 0.5f) };
  6222. int components = alpha ? 4 : 3;
  6223. bool value_changed = false;
  6224. ImGui::BeginGroup();
  6225. ImGui::PushID(label);
  6226. const bool hsv = (edit_mode == 1);
  6227. switch (edit_mode)
  6228. {
  6229. case ImGuiColorEditMode_RGB:
  6230. case ImGuiColorEditMode_HSV:
  6231. {
  6232. // RGB/HSV 0..255 Sliders
  6233. const float w_items_all = w_full - (square_sz + style.ItemInnerSpacing.x);
  6234. 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));
  6235. 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)));
  6236. const bool hide_prefix = (w_item_one <= CalcTextSize("M:999").x);
  6237. const char* ids[4] = { "##X", "##Y", "##Z", "##W" };
  6238. const char* fmt_table[3][4] =
  6239. {
  6240. { "%3.0f", "%3.0f", "%3.0f", "%3.0f" },
  6241. { "R:%3.0f", "G:%3.0f", "B:%3.0f", "A:%3.0f" },
  6242. { "H:%3.0f", "S:%3.0f", "V:%3.0f", "A:%3.0f" }
  6243. };
  6244. const char** fmt = hide_prefix ? fmt_table[0] : hsv ? fmt_table[2] : fmt_table[1];
  6245. ImGui::PushItemWidth(w_item_one);
  6246. for (int n = 0; n < components; n++)
  6247. {
  6248. if (n > 0)
  6249. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  6250. if (n + 1 == components)
  6251. ImGui::PushItemWidth(w_item_last);
  6252. value_changed |= ImGui::DragInt(ids[n], &i[n], 1.0f, 0, 255, fmt[n]);
  6253. }
  6254. ImGui::PopItemWidth();
  6255. ImGui::PopItemWidth();
  6256. }
  6257. break;
  6258. case ImGuiColorEditMode_HEX:
  6259. {
  6260. // RGB Hexadecimal Input
  6261. const float w_slider_all = w_full - square_sz;
  6262. char buf[64];
  6263. if (alpha)
  6264. ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X%02X", i[0], i[1], i[2], i[3]);
  6265. else
  6266. ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X", i[0], i[1], i[2]);
  6267. ImGui::PushItemWidth(w_slider_all - style.ItemInnerSpacing.x);
  6268. value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
  6269. ImGui::PopItemWidth();
  6270. char* p = buf;
  6271. while (*p == '#' || ImCharIsSpace(*p))
  6272. p++;
  6273. // Treat at unsigned (%X is unsigned)
  6274. i[0] = i[1] = i[2] = i[3] = 0;
  6275. if (alpha)
  6276. sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2], (unsigned int*)&i[3]);
  6277. else
  6278. sscanf(p, "%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2]);
  6279. }
  6280. break;
  6281. }
  6282. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  6283. const ImVec4 col_display(col[0], col[1], col[2], 1.0f);
  6284. if (ImGui::ColorButton(col_display))
  6285. g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); // Don't set local copy of 'edit_mode' right away!
  6286. if (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelectShowButton)
  6287. {
  6288. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  6289. const char* button_titles[3] = { "RGB", "HSV", "HEX" };
  6290. if (ImGui::Button(button_titles[edit_mode]))
  6291. g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); // Don't set local copy of 'edit_mode' right away!
  6292. ImGui::SameLine();
  6293. }
  6294. else
  6295. {
  6296. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  6297. }
  6298. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  6299. // Convert back
  6300. for (int n = 0; n < 4; n++)
  6301. f[n] = i[n] / 255.0f;
  6302. if (edit_mode == 1)
  6303. ImGui::ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]);
  6304. if (value_changed)
  6305. {
  6306. col[0] = f[0];
  6307. col[1] = f[1];
  6308. col[2] = f[2];
  6309. if (alpha)
  6310. col[3] = f[3];
  6311. }
  6312. ImGui::PopID();
  6313. ImGui::EndGroup();
  6314. return value_changed;
  6315. }
  6316. void ImGui::ColorEditMode(ImGuiColorEditMode mode)
  6317. {
  6318. ImGuiWindow* window = GetCurrentWindow();
  6319. window->DC.ColorEditMode = mode;
  6320. }
  6321. // Horizontal separating line.
  6322. void ImGui::Separator()
  6323. {
  6324. ImGuiWindow* window = GetCurrentWindow();
  6325. if (window->SkipItems)
  6326. return;
  6327. if (window->DC.ColumnsCount > 1)
  6328. PopClipRect();
  6329. const ImRect bb(ImVec2(window->Pos.x, window->DC.CursorPos.y), ImVec2(window->Pos.x + window->Size.x, window->DC.CursorPos.y));
  6330. ItemSize(ImVec2(0.0f, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit
  6331. if (!ItemAdd(bb, NULL))
  6332. {
  6333. if (window->DC.ColumnsCount > 1)
  6334. PushColumnClipRect();
  6335. return;
  6336. }
  6337. window->DrawList->AddLine(bb.Min, bb.Max, window->Color(ImGuiCol_Border));
  6338. ImGuiState& g = *GImGui;
  6339. if (g.LogEnabled)
  6340. ImGui::LogText(STR_NEWLINE "--------------------------------");
  6341. if (window->DC.ColumnsCount > 1)
  6342. {
  6343. PushColumnClipRect();
  6344. window->DC.ColumnsCellMinY = window->DC.CursorPos.y;
  6345. }
  6346. }
  6347. // A little vertical spacing.
  6348. void ImGui::Spacing()
  6349. {
  6350. ImGuiWindow* window = GetCurrentWindow();
  6351. if (window->SkipItems)
  6352. return;
  6353. ItemSize(ImVec2(0,0));
  6354. }
  6355. // Advance cursor given item size.
  6356. static void ItemSize(ImVec2 size, float text_offset_y)
  6357. {
  6358. ImGuiState& g = *GImGui;
  6359. ImGuiWindow* window = GetCurrentWindow();
  6360. if (window->SkipItems)
  6361. return;
  6362. // Always align ourselves on pixel boundaries
  6363. const float line_height = ImMax(window->DC.CurrentLineHeight, size.y);
  6364. const float text_base_offset = ImMax(window->DC.CurrentLineTextBaseOffset, text_offset_y);
  6365. window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y);
  6366. 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));
  6367. window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x);
  6368. window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y);
  6369. //window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, 0xFF0000FF, 4); // Debug
  6370. window->DC.PrevLineHeight = line_height;
  6371. window->DC.PrevLineTextBaseOffset = text_base_offset;
  6372. window->DC.CurrentLineHeight = window->DC.CurrentLineTextBaseOffset = 0.0f;
  6373. }
  6374. static inline void ItemSize(const ImRect& bb, float text_offset_y)
  6375. {
  6376. ItemSize(bb.GetSize(), text_offset_y);
  6377. }
  6378. static bool IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged)
  6379. {
  6380. ImGuiState& g = *GImGui;
  6381. ImGuiWindow* window = GetCurrentWindow();
  6382. if (!bb.Overlaps(ImRect(window->ClipRectStack.back())))
  6383. {
  6384. if (!id || *id != GImGui->ActiveId)
  6385. if (clip_even_when_logged || !g.LogEnabled)
  6386. return true;
  6387. }
  6388. return false;
  6389. }
  6390. bool ImGui::IsRectClipped(const ImVec2& size)
  6391. {
  6392. ImGuiWindow* window = GetCurrentWindow();
  6393. return IsClippedEx(ImRect(window->DC.CursorPos, window->DC.CursorPos + size), NULL, true);
  6394. }
  6395. static bool ItemAdd(const ImRect& bb, const ImGuiID* id)
  6396. {
  6397. ImGuiWindow* window = GetCurrentWindow();
  6398. window->DC.LastItemID = id ? *id : 0;
  6399. window->DC.LastItemRect = bb;
  6400. if (IsClippedEx(bb, id, false))
  6401. {
  6402. window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = false;
  6403. return false;
  6404. }
  6405. // This is a sensible default, but widgets are free to override it after calling ItemAdd()
  6406. ImGuiState& g = *GImGui;
  6407. if (IsMouseHoveringRect(bb))
  6408. {
  6409. // Matching the behavior of IsHovered() but ignore if ActiveId==window->MoveID (we clicked on the window background)
  6410. // So that clicking on items with no active id such as Text() still returns true with IsItemHovered()
  6411. window->DC.LastItemHoveredRect = true;
  6412. window->DC.LastItemHoveredAndUsable = false;
  6413. if (g.HoveredRootWindow == window->RootWindow)
  6414. if (g.ActiveId == 0 || (id && g.ActiveId == *id) || g.ActiveIdIsFocusedOnly || (g.ActiveId == window->MoveID))
  6415. if (IsWindowContentHoverable(window))
  6416. window->DC.LastItemHoveredAndUsable = true;
  6417. }
  6418. else
  6419. {
  6420. window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = false;
  6421. }
  6422. return true;
  6423. }
  6424. void ImGui::BeginGroup()
  6425. {
  6426. ImGuiWindow* window = GetCurrentWindow();
  6427. window->DC.GroupStack.resize(window->DC.GroupStack.size() + 1);
  6428. ImGuiGroupData& group_data = window->DC.GroupStack.back();
  6429. group_data.BackupCursorPos = window->DC.CursorPos;
  6430. group_data.BackupCursorMaxPos = window->DC.CursorMaxPos;
  6431. group_data.BackupColumnsStartX = window->DC.ColumnsStartX;
  6432. group_data.BackupCurrentLineHeight = window->DC.CurrentLineHeight;
  6433. group_data.BackupCurrentLineTextBaseOffset = window->DC.CurrentLineTextBaseOffset;
  6434. group_data.BackupLogLinePosY = window->DC.LogLinePosY;
  6435. window->DC.ColumnsStartX = window->DC.CursorPos.x - window->Pos.x;
  6436. window->DC.CursorMaxPos = window->DC.CursorPos;
  6437. window->DC.CurrentLineHeight = 0.0f;
  6438. window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f;
  6439. }
  6440. void ImGui::EndGroup()
  6441. {
  6442. ImGuiWindow* window = GetCurrentWindow();
  6443. ImGuiStyle& style = ImGui::GetStyle();
  6444. IM_ASSERT(!window->DC.GroupStack.empty());
  6445. ImGuiGroupData& group_data = window->DC.GroupStack.back();
  6446. ImRect group_bb(group_data.BackupCursorPos, window->DC.CursorMaxPos);
  6447. group_bb.Max.y -= style.ItemSpacing.y; // Cancel out last vertical spacing because we are adding one ourselves.
  6448. group_bb.Max = ImMax(group_bb.Min, group_bb.Max);
  6449. window->DC.CursorPos = group_data.BackupCursorPos;
  6450. window->DC.CursorMaxPos = ImMax(group_data.BackupCursorMaxPos, window->DC.CursorMaxPos);
  6451. window->DC.CurrentLineHeight = group_data.BackupCurrentLineHeight;
  6452. window->DC.CurrentLineTextBaseOffset = group_data.BackupCurrentLineTextBaseOffset; // FIXME: Ideally we'll grab the base offset from the first line of the group.
  6453. window->DC.ColumnsStartX = group_data.BackupColumnsStartX;
  6454. window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f;
  6455. ItemSize(group_bb.GetSize(), group_data.BackupCurrentLineTextBaseOffset);
  6456. ItemAdd(group_bb, NULL);
  6457. window->DC.GroupStack.pop_back();
  6458. //window->DrawList->AddRect(group_bb.Min, group_bb.Max, 0xFFFF00FF); // Debug
  6459. }
  6460. // Gets back to previous line and continue with horizontal layout
  6461. // column_x == 0 : follow on previous item
  6462. // columm_x != 0 : align to specified column
  6463. // spacing_w < 0 : use default spacing if column_x==0, no spacing if column_x!=0
  6464. // spacing_w >= 0 : enforce spacing
  6465. void ImGui::SameLine(int column_x, int spacing_w)
  6466. {
  6467. ImGuiState& g = *GImGui;
  6468. ImGuiWindow* window = GetCurrentWindow();
  6469. if (window->SkipItems)
  6470. return;
  6471. float x, y;
  6472. if (column_x != 0)
  6473. {
  6474. if (spacing_w < 0) spacing_w = 0;
  6475. x = window->Pos.x + (float)column_x + (float)spacing_w;
  6476. y = window->DC.CursorPosPrevLine.y;
  6477. }
  6478. else
  6479. {
  6480. if (spacing_w < 0) spacing_w = (int)g.Style.ItemSpacing.x;
  6481. x = window->DC.CursorPosPrevLine.x + (float)spacing_w;
  6482. y = window->DC.CursorPosPrevLine.y;
  6483. }
  6484. window->DC.CurrentLineHeight = window->DC.PrevLineHeight;
  6485. window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset;
  6486. window->DC.CursorPos = ImVec2(x, y);
  6487. }
  6488. void ImGui::NextColumn()
  6489. {
  6490. ImGuiState& g = *GImGui;
  6491. ImGuiWindow* window = GetCurrentWindow();
  6492. if (window->SkipItems)
  6493. return;
  6494. if (window->DC.ColumnsCount > 1)
  6495. {
  6496. ImGui::PopItemWidth();
  6497. PopClipRect();
  6498. window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
  6499. if (++window->DC.ColumnsCurrent < window->DC.ColumnsCount)
  6500. {
  6501. window->DC.ColumnsOffsetX = ImGui::GetColumnOffset(window->DC.ColumnsCurrent) - window->DC.ColumnsStartX + g.Style.ItemSpacing.x;
  6502. }
  6503. else
  6504. {
  6505. window->DC.ColumnsCurrent = 0;
  6506. window->DC.ColumnsOffsetX = 0.0f;
  6507. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY;
  6508. }
  6509. window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX);
  6510. window->DC.CursorPos.y = window->DC.ColumnsCellMinY;
  6511. window->DC.CurrentLineHeight = 0.0f;
  6512. window->DC.CurrentLineTextBaseOffset = 0.0f;
  6513. PushColumnClipRect();
  6514. ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f); // FIXME
  6515. }
  6516. }
  6517. int ImGui::GetColumnIndex()
  6518. {
  6519. ImGuiWindow* window = GetCurrentWindow();
  6520. return window->DC.ColumnsCurrent;
  6521. }
  6522. int ImGui::GetColumnsCount()
  6523. {
  6524. ImGuiWindow* window = GetCurrentWindow();
  6525. return window->DC.ColumnsCount;
  6526. }
  6527. static float GetDraggedColumnOffset(int column_index)
  6528. {
  6529. // Active (dragged) column always follow mouse. The reason we need this is that dragging a column to the right edge of an auto-resizing
  6530. // window creates a feedback loop because we store normalized positions/ So while dragging we enforce absolute positioning
  6531. ImGuiState& g = *GImGui;
  6532. ImGuiWindow* window = GetCurrentWindow();
  6533. IM_ASSERT(g.ActiveId == window->DC.ColumnsSetID + ImGuiID(column_index));
  6534. float x = g.IO.MousePos.x + g.ActiveClickDeltaToCenter.x;
  6535. x -= window->Pos.x;
  6536. x = ImClamp(x, ImGui::GetColumnOffset(column_index-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(column_index+1)-g.Style.ColumnsMinSpacing);
  6537. return x;
  6538. }
  6539. float ImGui::GetColumnOffset(int column_index)
  6540. {
  6541. ImGuiState& g = *GImGui;
  6542. ImGuiWindow* window = GetCurrentWindow();
  6543. if (column_index < 0)
  6544. column_index = window->DC.ColumnsCurrent;
  6545. if (g.ActiveId)
  6546. {
  6547. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  6548. if (g.ActiveId == column_id)
  6549. return GetDraggedColumnOffset(column_index);
  6550. }
  6551. // Read from cache
  6552. IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size());
  6553. const float t = window->DC.ColumnsOffsetsT[column_index];
  6554. const float min_x = window->DC.ColumnsStartX;
  6555. const float max_x = window->Size.x - (g.Style.ScrollbarWidth);// - window->WindowPadding().x;
  6556. const float offset = min_x + t * (max_x - min_x);
  6557. return offset;
  6558. }
  6559. void ImGui::SetColumnOffset(int column_index, float offset)
  6560. {
  6561. ImGuiState& g = *GImGui;
  6562. ImGuiWindow* window = GetCurrentWindow();
  6563. if (column_index < 0)
  6564. column_index = window->DC.ColumnsCurrent;
  6565. IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size());
  6566. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  6567. const float min_x = window->DC.ColumnsStartX;
  6568. const float max_x = window->Size.x - (g.Style.ScrollbarWidth);// - window->WindowPadding().x;
  6569. const float t = (offset - min_x) / (max_x - min_x);
  6570. window->DC.StateStorage->SetFloat(column_id, t);
  6571. window->DC.ColumnsOffsetsT[column_index] = t;
  6572. }
  6573. float ImGui::GetColumnWidth(int column_index)
  6574. {
  6575. ImGuiWindow* window = GetCurrentWindow();
  6576. if (column_index < 0)
  6577. column_index = window->DC.ColumnsCurrent;
  6578. const float w = GetColumnOffset(column_index+1) - GetColumnOffset(column_index);
  6579. return w;
  6580. }
  6581. static void PushColumnClipRect(int column_index)
  6582. {
  6583. ImGuiWindow* window = GetCurrentWindow();
  6584. if (column_index < 0)
  6585. column_index = window->DC.ColumnsCurrent;
  6586. const float x1 = window->Pos.x + ImGui::GetColumnOffset(column_index) - 1;
  6587. const float x2 = window->Pos.x + ImGui::GetColumnOffset(column_index+1) - 1;
  6588. PushClipRect(ImVec4(x1,-FLT_MAX,x2,+FLT_MAX));
  6589. }
  6590. void ImGui::Columns(int columns_count, const char* id, bool border)
  6591. {
  6592. ImGuiState& g = *GImGui;
  6593. ImGuiWindow* window = GetCurrentWindow();
  6594. if (window->DC.ColumnsCount != 1)
  6595. {
  6596. if (window->DC.ColumnsCurrent != 0)
  6597. ItemSize(ImVec2(0,0)); // Advance to column 0
  6598. ImGui::PopItemWidth();
  6599. PopClipRect();
  6600. window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
  6601. window->DC.CursorPos.y = window->DC.ColumnsCellMaxY;
  6602. }
  6603. // Draw columns borders and handle resize at the time of "closing" a columns set
  6604. if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders && !window->SkipItems)
  6605. {
  6606. const float y1 = window->DC.ColumnsStartPos.y;
  6607. const float y2 = window->DC.CursorPos.y;
  6608. for (int i = 1; i < window->DC.ColumnsCount; i++)
  6609. {
  6610. float x = window->Pos.x + GetColumnOffset(i);
  6611. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(i);
  6612. const ImRect column_rect(ImVec2(x-4,y1),ImVec2(x+4,y2));
  6613. if (IsClippedEx(column_rect, &column_id, false))
  6614. continue;
  6615. bool hovered, held;
  6616. ButtonBehavior(column_rect, column_id, &hovered, &held, true);
  6617. if (hovered || held)
  6618. g.MouseCursor = ImGuiMouseCursor_ResizeEW;
  6619. // Draw before resize so our items positioning are in sync with the line being drawn
  6620. const ImU32 col = window->Color(held ? ImGuiCol_ColumnActive : hovered ? ImGuiCol_ColumnHovered : ImGuiCol_Column);
  6621. const float xi = (float)(int)x;
  6622. window->DrawList->AddLine(ImVec2(xi, y1), ImVec2(xi, y2), col);
  6623. if (held)
  6624. {
  6625. if (g.ActiveIdIsJustActivated)
  6626. g.ActiveClickDeltaToCenter.x = x - g.IO.MousePos.x;
  6627. x = GetDraggedColumnOffset(i);
  6628. SetColumnOffset(i, x);
  6629. }
  6630. }
  6631. }
  6632. // Set state for first column
  6633. window->DC.ColumnsSetID = window->GetID(id ? id : "");
  6634. window->DC.ColumnsCurrent = 0;
  6635. window->DC.ColumnsCount = columns_count;
  6636. window->DC.ColumnsShowBorders = border;
  6637. window->DC.ColumnsStartPos = window->DC.CursorPos;
  6638. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.CursorPos.y;
  6639. window->DC.ColumnsOffsetX = 0.0f;
  6640. window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX);
  6641. if (window->DC.ColumnsCount != 1)
  6642. {
  6643. // Cache column offsets
  6644. window->DC.ColumnsOffsetsT.resize((size_t)columns_count + 1);
  6645. for (int column_index = 0; column_index < columns_count + 1; column_index++)
  6646. {
  6647. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  6648. RegisterAliveId(column_id);
  6649. const float default_t = column_index / (float)window->DC.ColumnsCount;
  6650. 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?)
  6651. window->DC.ColumnsOffsetsT[column_index] = t;
  6652. }
  6653. PushColumnClipRect();
  6654. ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);
  6655. }
  6656. else
  6657. {
  6658. window->DC.ColumnsOffsetsT.resize(2);
  6659. window->DC.ColumnsOffsetsT[0] = 0.0f;
  6660. window->DC.ColumnsOffsetsT[1] = 1.0f;
  6661. }
  6662. }
  6663. inline void ImGui::Indent()
  6664. {
  6665. ImGuiState& g = *GImGui;
  6666. ImGuiWindow* window = GetCurrentWindow();
  6667. window->DC.ColumnsStartX += g.Style.IndentSpacing;
  6668. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  6669. }
  6670. inline void ImGui::Unindent()
  6671. {
  6672. ImGuiState& g = *GImGui;
  6673. ImGuiWindow* window = GetCurrentWindow();
  6674. window->DC.ColumnsStartX -= g.Style.IndentSpacing;
  6675. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  6676. }
  6677. void ImGui::TreePush(const char* str_id)
  6678. {
  6679. ImGuiWindow* window = GetCurrentWindow();
  6680. ImGui::Indent();
  6681. window->DC.TreeDepth++;
  6682. PushID(str_id ? str_id : "#TreePush");
  6683. }
  6684. void ImGui::TreePush(const void* ptr_id)
  6685. {
  6686. ImGuiWindow* window = GetCurrentWindow();
  6687. ImGui::Indent();
  6688. window->DC.TreeDepth++;
  6689. PushID(ptr_id ? ptr_id : (const void*)"#TreePush");
  6690. }
  6691. void ImGui::TreePop()
  6692. {
  6693. ImGuiWindow* window = GetCurrentWindow();
  6694. ImGui::Unindent();
  6695. window->DC.TreeDepth--;
  6696. PopID();
  6697. }
  6698. void ImGui::Value(const char* prefix, bool b)
  6699. {
  6700. ImGui::Text("%s: %s", prefix, (b ? "true" : "false"));
  6701. }
  6702. void ImGui::Value(const char* prefix, int v)
  6703. {
  6704. ImGui::Text("%s: %d", prefix, v);
  6705. }
  6706. void ImGui::Value(const char* prefix, unsigned int v)
  6707. {
  6708. ImGui::Text("%s: %d", prefix, v);
  6709. }
  6710. void ImGui::Value(const char* prefix, float v, const char* float_format)
  6711. {
  6712. if (float_format)
  6713. {
  6714. char fmt[64];
  6715. ImFormatString(fmt, IM_ARRAYSIZE(fmt), "%%s: %s", float_format);
  6716. ImGui::Text(fmt, prefix, v);
  6717. }
  6718. else
  6719. {
  6720. ImGui::Text("%s: %.3f", prefix, v);
  6721. }
  6722. }
  6723. void ImGui::Color(const char* prefix, const ImVec4& v)
  6724. {
  6725. ImGui::Text("%s: (%.2f,%.2f,%.2f,%.2f)", prefix, v.x, v.y, v.z, v.w);
  6726. ImGui::SameLine();
  6727. ImGui::ColorButton(v, true);
  6728. }
  6729. void ImGui::Color(const char* prefix, unsigned int v)
  6730. {
  6731. ImGui::Text("%s: %08X", prefix, v);
  6732. ImGui::SameLine();
  6733. ImVec4 col;
  6734. col.x = (float)((v >> 0) & 0xFF) / 255.0f;
  6735. col.y = (float)((v >> 8) & 0xFF) / 255.0f;
  6736. col.z = (float)((v >> 16) & 0xFF) / 255.0f;
  6737. col.w = (float)((v >> 24) & 0xFF) / 255.0f;
  6738. ImGui::ColorButton(col, true);
  6739. }
  6740. //-----------------------------------------------------------------------------
  6741. // ImDrawList
  6742. //-----------------------------------------------------------------------------
  6743. static ImVec4 GNullClipRect(-9999.0f,-9999.0f, +9999.0f, +9999.0f);
  6744. void ImDrawList::Clear()
  6745. {
  6746. commands.resize(0);
  6747. vtx_buffer.resize(0);
  6748. vtx_write = NULL;
  6749. clip_rect_stack.resize(0);
  6750. texture_id_stack.resize(0);
  6751. }
  6752. void ImDrawList::ClearFreeMemory()
  6753. {
  6754. commands.clear();
  6755. vtx_buffer.clear();
  6756. vtx_write = NULL;
  6757. clip_rect_stack.clear();
  6758. texture_id_stack.clear();
  6759. }
  6760. void ImDrawList::AddDrawCmd()
  6761. {
  6762. ImDrawCmd draw_cmd;
  6763. draw_cmd.vtx_count = 0;
  6764. draw_cmd.clip_rect = clip_rect_stack.empty() ? GNullClipRect : clip_rect_stack.back();
  6765. draw_cmd.texture_id = texture_id_stack.empty() ? NULL : texture_id_stack.back();
  6766. draw_cmd.user_callback = NULL;
  6767. draw_cmd.user_callback_data = NULL;
  6768. IM_ASSERT(draw_cmd.clip_rect.x <= draw_cmd.clip_rect.z && draw_cmd.clip_rect.y <= draw_cmd.clip_rect.w);
  6769. commands.push_back(draw_cmd);
  6770. }
  6771. void ImDrawList::AddCallback(ImDrawCallback callback, void* callback_data)
  6772. {
  6773. ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back();
  6774. if (!current_cmd || current_cmd->vtx_count != 0 || current_cmd->user_callback != NULL)
  6775. {
  6776. AddDrawCmd();
  6777. current_cmd = &commands.back();
  6778. }
  6779. current_cmd->user_callback = callback;
  6780. current_cmd->user_callback_data = callback_data;
  6781. // Force a new command after us
  6782. // We function this way so that the most common calls (AddLine, AddRect..) always have a command to add to without doing any check.
  6783. AddDrawCmd();
  6784. }
  6785. void ImDrawList::UpdateClipRect()
  6786. {
  6787. ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back();
  6788. if (!current_cmd || (current_cmd->vtx_count != 0) || current_cmd->user_callback != NULL)
  6789. {
  6790. AddDrawCmd();
  6791. }
  6792. else
  6793. {
  6794. current_cmd->clip_rect = clip_rect_stack.empty() ? GNullClipRect : clip_rect_stack.back();
  6795. }
  6796. }
  6797. // Scissoring. The values in clip_rect are x1, y1, x2, y2.
  6798. void ImDrawList::PushClipRect(const ImVec4& clip_rect)
  6799. {
  6800. clip_rect_stack.push_back(clip_rect);
  6801. UpdateClipRect();
  6802. }
  6803. void ImDrawList::PushClipRectFullScreen()
  6804. {
  6805. PushClipRect(GNullClipRect);
  6806. // This would be more correct but we're not supposed to access ImGuiState from here?
  6807. //ImGuiState& g = *GImGui;
  6808. //if (g.IO.DisplayVisibleMin.x != g.IO.DisplayVisibleMax.x && g.IO.DisplayVisibleMin.y != g.IO.DisplayVisibleMax.y)
  6809. // PushClipRect(ImVec4(g.IO.DisplayVisibleMin.x, g.IO.DisplayVisibleMin.y, g.IO.DisplayVisibleMax.x, g.IO.DisplayVisibleMax.y));
  6810. //else
  6811. // PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y));
  6812. }
  6813. void ImDrawList::PopClipRect()
  6814. {
  6815. IM_ASSERT(clip_rect_stack.size() > 0);
  6816. clip_rect_stack.pop_back();
  6817. UpdateClipRect();
  6818. }
  6819. void ImDrawList::UpdateTextureID()
  6820. {
  6821. ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back();
  6822. const ImTextureID texture_id = texture_id_stack.empty() ? NULL : texture_id_stack.back();
  6823. if (!current_cmd || (current_cmd->vtx_count != 0 && current_cmd->texture_id != texture_id) || current_cmd->user_callback != NULL)
  6824. {
  6825. AddDrawCmd();
  6826. }
  6827. else
  6828. {
  6829. current_cmd->texture_id = texture_id;
  6830. }
  6831. }
  6832. void ImDrawList::PushTextureID(const ImTextureID& texture_id)
  6833. {
  6834. texture_id_stack.push_back(texture_id);
  6835. UpdateTextureID();
  6836. }
  6837. void ImDrawList::PopTextureID()
  6838. {
  6839. IM_ASSERT(texture_id_stack.size() > 0);
  6840. texture_id_stack.pop_back();
  6841. UpdateTextureID();
  6842. }
  6843. void ImDrawList::PrimReserve(unsigned int vtx_count)
  6844. {
  6845. ImDrawCmd& draw_cmd = commands.back();
  6846. draw_cmd.vtx_count += vtx_count;
  6847. size_t vtx_buffer_size = vtx_buffer.size();
  6848. vtx_buffer.resize(vtx_buffer_size + vtx_count);
  6849. vtx_write = &vtx_buffer[vtx_buffer_size];
  6850. }
  6851. void ImDrawList::PrimTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col)
  6852. {
  6853. const ImVec2 uv = GImGui->FontTexUvWhitePixel;
  6854. vtx_write[0].pos = a; vtx_write[0].uv = uv; vtx_write[0].col = col;
  6855. vtx_write[1].pos = b; vtx_write[1].uv = uv; vtx_write[1].col = col;
  6856. vtx_write[2].pos = c; vtx_write[2].uv = uv; vtx_write[2].col = col;
  6857. vtx_write += 3;
  6858. }
  6859. void ImDrawList::PrimRect(const ImVec2& a, const ImVec2& c, ImU32 col)
  6860. {
  6861. const ImVec2 uv = GImGui->FontTexUvWhitePixel;
  6862. const ImVec2 b(c.x, a.y);
  6863. const ImVec2 d(a.x, c.y);
  6864. vtx_write[0].pos = a; vtx_write[0].uv = uv; vtx_write[0].col = col;
  6865. vtx_write[1].pos = b; vtx_write[1].uv = uv; vtx_write[1].col = col;
  6866. vtx_write[2].pos = c; vtx_write[2].uv = uv; vtx_write[2].col = col;
  6867. vtx_write[3].pos = a; vtx_write[3].uv = uv; vtx_write[3].col = col;
  6868. vtx_write[4].pos = c; vtx_write[4].uv = uv; vtx_write[4].col = col;
  6869. vtx_write[5].pos = d; vtx_write[5].uv = uv; vtx_write[5].col = col;
  6870. vtx_write += 6;
  6871. }
  6872. void ImDrawList::PrimRectUV(const ImVec2& a, const ImVec2& c, const ImVec2& uv_a, const ImVec2& uv_c, ImU32 col)
  6873. {
  6874. const ImVec2 b(c.x, a.y);
  6875. const ImVec2 d(a.x, c.y);
  6876. const ImVec2 uv_b(uv_c.x, uv_a.y);
  6877. const ImVec2 uv_d(uv_a.x, uv_c.y);
  6878. vtx_write[0].pos = a; vtx_write[0].uv = uv_a; vtx_write[0].col = col;
  6879. vtx_write[1].pos = b; vtx_write[1].uv = uv_b; vtx_write[1].col = col;
  6880. vtx_write[2].pos = c; vtx_write[2].uv = uv_c; vtx_write[2].col = col;
  6881. vtx_write[3].pos = a; vtx_write[3].uv = uv_a; vtx_write[3].col = col;
  6882. vtx_write[4].pos = c; vtx_write[4].uv = uv_c; vtx_write[4].col = col;
  6883. vtx_write[5].pos = d; vtx_write[5].uv = uv_d; vtx_write[5].col = col;
  6884. vtx_write += 6;
  6885. }
  6886. void ImDrawList::PrimQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col)
  6887. {
  6888. const ImVec2 uv = GImGui->FontTexUvWhitePixel;
  6889. vtx_write[0].pos = a; vtx_write[0].uv = uv; vtx_write[0].col = col;
  6890. vtx_write[1].pos = b; vtx_write[1].uv = uv; vtx_write[1].col = col;
  6891. vtx_write[2].pos = c; vtx_write[2].uv = uv; vtx_write[2].col = col;
  6892. vtx_write[3].pos = a; vtx_write[3].uv = uv; vtx_write[3].col = col;
  6893. vtx_write[4].pos = c; vtx_write[4].uv = uv; vtx_write[4].col = col;
  6894. vtx_write[5].pos = d; vtx_write[5].uv = uv; vtx_write[5].col = col;
  6895. vtx_write += 6;
  6896. }
  6897. // FIXME-OPT: In many instances the caller could provide a normal.
  6898. void ImDrawList::PrimLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness)
  6899. {
  6900. const float inv_length = 1.0f / sqrtf(ImLengthSqr(b - a));
  6901. const float dx = (b.x - a.x) * (thickness * 0.5f * inv_length); // line direction, halved
  6902. const float dy = (b.y - a.y) * (thickness * 0.5f * inv_length); // line direction, halved
  6903. const ImVec2 pa(a.x + dy, a.y - dx);
  6904. const ImVec2 pb(b.x + dy, b.y - dx);
  6905. const ImVec2 pc(b.x - dy, b.y + dx);
  6906. const ImVec2 pd(a.x - dy, a.y + dx);
  6907. PrimQuad(pa, pb, pc, pd, col);
  6908. }
  6909. void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness)
  6910. {
  6911. if ((col >> 24) == 0)
  6912. return;
  6913. PrimReserve(6);
  6914. PrimLine(a, b, col, thickness);
  6915. }
  6916. void ImDrawList::AddArcFast(const ImVec2& center, float radius, ImU32 col, int a_min, int a_max, bool filled, const ImVec2& third_point_offset)
  6917. {
  6918. if ((col >> 24) == 0)
  6919. return;
  6920. const int SAMPLES = 12;
  6921. static ImVec2 circle_vtx[SAMPLES];
  6922. static bool circle_vtx_builds = false;
  6923. if (!circle_vtx_builds)
  6924. {
  6925. for (int i = 0; i < SAMPLES; i++)
  6926. {
  6927. const float a = ((float)i / (float)SAMPLES) * 2*PI;
  6928. circle_vtx[i].x = cosf(a + PI);
  6929. circle_vtx[i].y = sinf(a + PI);
  6930. }
  6931. circle_vtx_builds = true;
  6932. }
  6933. const ImVec2 uv = GImGui->FontTexUvWhitePixel;
  6934. if (filled)
  6935. {
  6936. PrimReserve((unsigned int)(a_max-a_min) * 3);
  6937. for (int a0 = a_min; a0 < a_max; a0++)
  6938. {
  6939. int a1 = (a0 + 1 == SAMPLES) ? 0 : a0 + 1;
  6940. PrimVtx(center + circle_vtx[a0] * radius, uv, col);
  6941. PrimVtx(center + circle_vtx[a1] * radius, uv, col);
  6942. PrimVtx(center + third_point_offset, uv, col);
  6943. }
  6944. }
  6945. else
  6946. {
  6947. PrimReserve((unsigned int)(a_max-a_min) * 6);
  6948. for (int a0 = a_min; a0 < a_max; a0++)
  6949. {
  6950. int a1 = (a0 + 1 == SAMPLES) ? 0 : a0 + 1;
  6951. PrimLine(center + circle_vtx[a0] * radius, center + circle_vtx[a1] * radius, col);
  6952. }
  6953. }
  6954. }
  6955. void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
  6956. {
  6957. if ((col >> 24) == 0)
  6958. return;
  6959. float r = rounding;
  6960. r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
  6961. r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
  6962. if (r == 0.0f || rounding_corners == 0)
  6963. {
  6964. PrimReserve(4*6);
  6965. PrimLine(ImVec2(a.x,a.y), ImVec2(b.x,a.y), col);
  6966. PrimLine(ImVec2(b.x,a.y), ImVec2(b.x,b.y), col);
  6967. PrimLine(ImVec2(b.x,b.y), ImVec2(a.x,b.y), col);
  6968. PrimLine(ImVec2(a.x,b.y), ImVec2(a.x,a.y), col);
  6969. }
  6970. else
  6971. {
  6972. PrimReserve(4*6);
  6973. PrimLine(ImVec2(a.x + ((rounding_corners & 1)?r:0), a.y), ImVec2(b.x - ((rounding_corners & 2)?r:0), a.y), col);
  6974. PrimLine(ImVec2(b.x, a.y + ((rounding_corners & 2)?r:0)), ImVec2(b.x, b.y - ((rounding_corners & 4)?r:0)), col);
  6975. PrimLine(ImVec2(b.x - ((rounding_corners & 4)?r:0), b.y), ImVec2(a.x + ((rounding_corners & 8)?r:0), b.y), col);
  6976. PrimLine(ImVec2(a.x, b.y - ((rounding_corners & 8)?r:0)), ImVec2(a.x, a.y + ((rounding_corners & 1)?r:0)), col);
  6977. if (rounding_corners & 1) AddArcFast(ImVec2(a.x+r,a.y+r), r, col, 0, 3);
  6978. if (rounding_corners & 2) AddArcFast(ImVec2(b.x-r,a.y+r), r, col, 3, 6);
  6979. if (rounding_corners & 4) AddArcFast(ImVec2(b.x-r,b.y-r), r, col, 6, 9);
  6980. if (rounding_corners & 8) AddArcFast(ImVec2(a.x+r,b.y-r), r, col, 9, 12);
  6981. }
  6982. }
  6983. void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
  6984. {
  6985. if ((col >> 24) == 0)
  6986. return;
  6987. float r = rounding;
  6988. r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
  6989. r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
  6990. if (r == 0.0f || rounding_corners == 0)
  6991. {
  6992. // Use triangle so we can merge more draw calls together (at the cost of extra vertices)
  6993. PrimReserve(6);
  6994. PrimRect(a, b, col);
  6995. }
  6996. else
  6997. {
  6998. PrimReserve(6+6*2);
  6999. PrimRect(ImVec2(a.x+r,a.y), ImVec2(b.x-r,b.y), col);
  7000. float top_y = (rounding_corners & 1) ? a.y+r : a.y;
  7001. float bot_y = (rounding_corners & 8) ? b.y-r : b.y;
  7002. PrimRect(ImVec2(a.x,top_y), ImVec2(a.x+r,bot_y), col);
  7003. top_y = (rounding_corners & 2) ? a.y+r : a.y;
  7004. bot_y = (rounding_corners & 4) ? b.y-r : b.y;
  7005. PrimRect(ImVec2(b.x-r,top_y), ImVec2(b.x,bot_y), col);
  7006. if (rounding_corners & 1) AddArcFast(ImVec2(a.x+r,a.y+r), r, col, 0, 3, true);
  7007. if (rounding_corners & 2) AddArcFast(ImVec2(b.x-r,a.y+r), r, col, 3, 6, true);
  7008. if (rounding_corners & 4) AddArcFast(ImVec2(b.x-r,b.y-r), r, col, 6, 9, true);
  7009. if (rounding_corners & 8) AddArcFast(ImVec2(a.x+r,b.y-r), r, col, 9, 12, true);
  7010. }
  7011. }
  7012. void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col)
  7013. {
  7014. if ((col >> 24) == 0)
  7015. return;
  7016. PrimReserve(3);
  7017. PrimTriangle(a, b, c, col);
  7018. }
  7019. void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments)
  7020. {
  7021. if ((col >> 24) == 0)
  7022. return;
  7023. PrimReserve((unsigned int)num_segments*6);
  7024. const float a_step = 2*PI/(float)num_segments;
  7025. float a0 = 0.0f;
  7026. for (int i = 0; i < num_segments; i++)
  7027. {
  7028. const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
  7029. PrimLine(centre + ImVec2(cosf(a0), sinf(a0))*radius, centre + ImVec2(cosf(a1), sinf(a1))*radius, col);
  7030. a0 = a1;
  7031. }
  7032. }
  7033. void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments)
  7034. {
  7035. if ((col >> 24) == 0)
  7036. return;
  7037. const ImVec2 uv = GImGui->FontTexUvWhitePixel;
  7038. PrimReserve((unsigned int)num_segments*3);
  7039. const float a_step = 2*PI/(float)num_segments;
  7040. float a0 = 0.0f;
  7041. for (int i = 0; i < num_segments; i++)
  7042. {
  7043. const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
  7044. PrimVtx(centre + ImVec2(cosf(a0), sinf(a0))*radius, uv, col);
  7045. PrimVtx(centre + ImVec2(cosf(a1), sinf(a1))*radius, uv, col);
  7046. PrimVtx(centre, uv, col);
  7047. a0 = a1;
  7048. }
  7049. }
  7050. 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)
  7051. {
  7052. if ((col >> 24) == 0)
  7053. return;
  7054. if (text_end == NULL)
  7055. text_end = text_begin + strlen(text_begin);
  7056. if (text_begin == text_end)
  7057. return;
  7058. IM_ASSERT(font->ContainerAtlas->TexID == texture_id_stack.back()); // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
  7059. // reserve vertices for worse case
  7060. const unsigned int char_count = (unsigned int)(text_end - text_begin);
  7061. const unsigned int vtx_count_max = char_count * 6;
  7062. const size_t vtx_begin = vtx_buffer.size();
  7063. PrimReserve(vtx_count_max);
  7064. font->RenderText(font_size, pos, col, clip_rect_stack.back(), text_begin, text_end, this, wrap_width, cpu_clip_max);
  7065. // give back unused vertices
  7066. vtx_buffer.resize((size_t)(vtx_write - &vtx_buffer.front()));
  7067. const size_t vtx_count = vtx_buffer.size() - vtx_begin;
  7068. commands.back().vtx_count -= (unsigned int)(vtx_count_max - vtx_count);
  7069. vtx_write -= (vtx_count_max - vtx_count);
  7070. }
  7071. void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col)
  7072. {
  7073. if ((col >> 24) == 0)
  7074. return;
  7075. // FIXME-OPT: This is wasting draw calls.
  7076. const bool push_texture_id = texture_id_stack.empty() || user_texture_id != texture_id_stack.back();
  7077. if (push_texture_id)
  7078. PushTextureID(user_texture_id);
  7079. PrimReserve(6);
  7080. PrimRectUV(a, b, uv0, uv1, col);
  7081. if (push_texture_id)
  7082. PopTextureID();
  7083. }
  7084. //-----------------------------------------------------------------------------
  7085. // ImFontAtlias
  7086. //-----------------------------------------------------------------------------
  7087. struct ImFontAtlas::ImFontAtlasData
  7088. {
  7089. // Input
  7090. ImFont* OutFont; // Load into this font
  7091. void* TTFData; // TTF data, we own the memory
  7092. size_t TTFDataSize; // TTF data size, in bytes
  7093. float SizePixels; // Desired output size, in pixels
  7094. const ImWchar* GlyphRanges; // List of Unicode range (2 value per range, values are inclusive, zero-terminated list)
  7095. int FontNo; // Index of font within .TTF file (0)
  7096. // Temporary Build Data
  7097. stbtt_fontinfo FontInfo;
  7098. stbrp_rect* Rects;
  7099. stbtt_pack_range* Ranges;
  7100. int RangesCount;
  7101. };
  7102. ImFontAtlas::ImFontAtlas()
  7103. {
  7104. TexID = NULL;
  7105. TexPixelsAlpha8 = NULL;
  7106. TexPixelsRGBA32 = NULL;
  7107. TexWidth = TexHeight = 0;
  7108. TexUvWhitePixel = ImVec2(0, 0);
  7109. }
  7110. ImFontAtlas::~ImFontAtlas()
  7111. {
  7112. Clear();
  7113. }
  7114. void ImFontAtlas::ClearInputData()
  7115. {
  7116. for (size_t i = 0; i < InputData.size(); i++)
  7117. {
  7118. if (InputData[i]->TTFData)
  7119. ImGui::MemFree(InputData[i]->TTFData);
  7120. ImGui::MemFree(InputData[i]);
  7121. }
  7122. InputData.clear();
  7123. }
  7124. void ImFontAtlas::ClearTexData()
  7125. {
  7126. if (TexPixelsAlpha8)
  7127. ImGui::MemFree(TexPixelsAlpha8);
  7128. if (TexPixelsRGBA32)
  7129. ImGui::MemFree(TexPixelsRGBA32);
  7130. TexPixelsAlpha8 = NULL;
  7131. TexPixelsRGBA32 = NULL;
  7132. }
  7133. void ImFontAtlas::Clear()
  7134. {
  7135. ClearInputData();
  7136. ClearTexData();
  7137. for (size_t i = 0; i < Fonts.size(); i++)
  7138. {
  7139. Fonts[i]->~ImFont();
  7140. ImGui::MemFree(Fonts[i]);
  7141. }
  7142. Fonts.clear();
  7143. }
  7144. void ImGui::GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size)
  7145. {
  7146. printf("GetDefaultFontData() is obsoleted in ImGui 1.30.\n");
  7147. printf("Please use ImGui::GetIO().Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() functions to retrieve uncompressed texture data.\n");
  7148. if (fnt_data) *fnt_data = NULL;
  7149. if (fnt_size) *fnt_size = 0;
  7150. if (png_data) *png_data = NULL;
  7151. if (png_size) *png_size = 0;
  7152. IM_ASSERT(false);
  7153. }
  7154. void ImFontAtlas::GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel)
  7155. {
  7156. // Lazily build
  7157. if (TexPixelsAlpha8 == NULL)
  7158. {
  7159. if (InputData.empty())
  7160. AddFontDefault();
  7161. Build();
  7162. }
  7163. *out_pixels = TexPixelsAlpha8;
  7164. if (out_width) *out_width = TexWidth;
  7165. if (out_height) *out_height = TexHeight;
  7166. if (out_bytes_per_pixel) *out_bytes_per_pixel = 1;
  7167. }
  7168. void ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel)
  7169. {
  7170. // Lazily convert to RGBA32 format
  7171. // Although it is likely to be the most commonly used format, our font rendering is 8 bpp
  7172. if (!TexPixelsRGBA32)
  7173. {
  7174. unsigned char* pixels;
  7175. GetTexDataAsAlpha8(&pixels, NULL, NULL);
  7176. TexPixelsRGBA32 = (unsigned int*)ImGui::MemAlloc((size_t)(TexWidth * TexHeight * 4));
  7177. const unsigned char* src = pixels;
  7178. unsigned int* dst = TexPixelsRGBA32;
  7179. for (int n = TexWidth * TexHeight; n > 0; n--)
  7180. *dst++ = ((unsigned int)(*src++) << 24) | 0x00FFFFFF;
  7181. }
  7182. *out_pixels = (unsigned char*)TexPixelsRGBA32;
  7183. if (out_width) *out_width = TexWidth;
  7184. if (out_height) *out_height = TexHeight;
  7185. if (out_bytes_per_pixel) *out_bytes_per_pixel = 4;
  7186. }
  7187. static void GetDefaultCompressedFontDataTTF(const void** ttf_compressed_data, unsigned int* ttf_compressed_size);
  7188. static unsigned int stb_decompress_length(unsigned char *input);
  7189. static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length);
  7190. // Load embedded ProggyClean.ttf at size 13
  7191. ImFont* ImFontAtlas::AddFontDefault()
  7192. {
  7193. unsigned int ttf_compressed_size;
  7194. const void* ttf_compressed;
  7195. GetDefaultCompressedFontDataTTF(&ttf_compressed, &ttf_compressed_size);
  7196. ImFont* font = AddFontFromMemoryCompressedTTF(ttf_compressed, ttf_compressed_size, 13.0f, GetGlyphRangesDefault(), 0);
  7197. font->DisplayOffset.y += 1;
  7198. return font;
  7199. }
  7200. ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImWchar* glyph_ranges, int font_no)
  7201. {
  7202. void* data = NULL;
  7203. size_t data_size = 0;
  7204. if (!ImLoadFileToMemory(filename, "rb", (void**)&data, &data_size))
  7205. {
  7206. IM_ASSERT(0); // Could not load file.
  7207. return NULL;
  7208. }
  7209. ImFont* font = AddFontFromMemoryTTF(data, (unsigned int)data_size, size_pixels, glyph_ranges, font_no);
  7210. return font;
  7211. }
  7212. // NB: ownership of 'data' is given to ImFontAtlas which will clear it.
  7213. ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* in_ttf_data, unsigned int in_ttf_data_size, float size_pixels, const ImWchar* glyph_ranges, int font_no)
  7214. {
  7215. // Create new font
  7216. ImFont* font = (ImFont*)ImGui::MemAlloc(sizeof(ImFont));
  7217. new (font) ImFont();
  7218. Fonts.push_back(font);
  7219. // Add to build list
  7220. ImFontAtlasData* data = (ImFontAtlasData*)ImGui::MemAlloc(sizeof(ImFontAtlasData));
  7221. memset(data, 0, sizeof(ImFontAtlasData));
  7222. data->OutFont = font;
  7223. data->TTFData = in_ttf_data;
  7224. data->TTFDataSize = in_ttf_data_size;
  7225. data->SizePixels = size_pixels;
  7226. data->GlyphRanges = glyph_ranges;
  7227. data->FontNo = font_no;
  7228. InputData.push_back(data);
  7229. // Invalidate texture
  7230. ClearTexData();
  7231. return font;
  7232. }
  7233. ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* in_compressed_ttf_data, unsigned int in_compressed_ttf_data_size, float size_pixels, const ImWchar* glyph_ranges, int font_no)
  7234. {
  7235. // Decompress
  7236. const size_t buf_decompressed_size = stb_decompress_length((unsigned char*)in_compressed_ttf_data);
  7237. unsigned char* buf_decompressed = (unsigned char *)ImGui::MemAlloc(buf_decompressed_size);
  7238. stb_decompress(buf_decompressed, (unsigned char*)in_compressed_ttf_data, in_compressed_ttf_data_size);
  7239. // Add
  7240. ImFont* font = AddFontFromMemoryTTF(buf_decompressed, (unsigned int)buf_decompressed_size, size_pixels, glyph_ranges, font_no);
  7241. return font;
  7242. }
  7243. bool ImFontAtlas::Build()
  7244. {
  7245. IM_ASSERT(InputData.size() > 0);
  7246. TexID = NULL;
  7247. TexWidth = TexHeight = 0;
  7248. TexUvWhitePixel = ImVec2(0, 0);
  7249. ClearTexData();
  7250. // Initialize font information early (so we can error without any cleanup) + count glyphs
  7251. int total_glyph_count = 0;
  7252. int total_glyph_range_count = 0;
  7253. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  7254. {
  7255. ImFontAtlasData& data = *InputData[input_i];
  7256. IM_ASSERT(data.OutFont && !data.OutFont->IsLoaded());
  7257. const int font_offset = stbtt_GetFontOffsetForIndex((unsigned char*)data.TTFData, data.FontNo);
  7258. IM_ASSERT(font_offset >= 0);
  7259. if (!stbtt_InitFont(&data.FontInfo, (unsigned char*)data.TTFData, font_offset))
  7260. return false;
  7261. if (!data.GlyphRanges)
  7262. data.GlyphRanges = GetGlyphRangesDefault();
  7263. for (const ImWchar* in_range = data.GlyphRanges; in_range[0] && in_range[1]; in_range += 2)
  7264. {
  7265. total_glyph_count += (in_range[1] - in_range[0]) + 1;
  7266. total_glyph_range_count++;
  7267. }
  7268. }
  7269. // Start packing
  7270. TexWidth = (total_glyph_count > 1000) ? 1024 : 512; // Width doesn't actually matters.
  7271. TexHeight = 0;
  7272. const int max_tex_height = 1024*32;
  7273. stbtt_pack_context spc;
  7274. int ret = stbtt_PackBegin(&spc, NULL, TexWidth, max_tex_height, 0, 1, NULL);
  7275. IM_ASSERT(ret);
  7276. stbtt_PackSetOversampling(&spc, 1, 1);
  7277. // Pack our extra data rectangles first, so it will be on the upper-left corner of our texture (UV will have small values).
  7278. ImVector<stbrp_rect> extra_rects;
  7279. RenderCustomTexData(0, &extra_rects);
  7280. stbrp_pack_rects((stbrp_context*)spc.pack_info, &extra_rects[0], (int)extra_rects.size());
  7281. for (size_t i = 0; i < extra_rects.size(); i++)
  7282. if (extra_rects[i].was_packed)
  7283. TexHeight = ImMax(TexHeight, extra_rects[i].y + extra_rects[i].h);
  7284. // Allocate packing character data and flag packed characters buffer as non-packed (x0=y0=x1=y1=0)
  7285. int buf_packedchars_n = 0, buf_rects_n = 0, buf_ranges_n = 0;
  7286. stbtt_packedchar* buf_packedchars = (stbtt_packedchar*)ImGui::MemAlloc(total_glyph_count * sizeof(stbtt_packedchar));
  7287. stbrp_rect* buf_rects = (stbrp_rect*)ImGui::MemAlloc(total_glyph_count * sizeof(stbrp_rect));
  7288. stbtt_pack_range* buf_ranges = (stbtt_pack_range*)ImGui::MemAlloc(total_glyph_range_count * sizeof(stbtt_pack_range));
  7289. memset(buf_packedchars, 0, total_glyph_count * sizeof(stbtt_packedchar));
  7290. memset(buf_rects, 0, total_glyph_count * sizeof(stbrp_rect)); // Unnecessary but let's clear this for the sake of sanity.
  7291. memset(buf_ranges, 0, total_glyph_range_count * sizeof(stbtt_pack_range));
  7292. // First font pass: pack all glyphs (no rendering at this point, we are working with glyph sizes only)
  7293. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  7294. {
  7295. ImFontAtlasData& data = *InputData[input_i];
  7296. // Setup ranges
  7297. int glyph_count = 0;
  7298. int glyph_ranges_count = 0;
  7299. for (const ImWchar* in_range = data.GlyphRanges; in_range[0] && in_range[1]; in_range += 2)
  7300. {
  7301. glyph_count += (in_range[1] - in_range[0]) + 1;
  7302. glyph_ranges_count++;
  7303. }
  7304. data.Ranges = buf_ranges + buf_ranges_n;
  7305. data.RangesCount = glyph_ranges_count;
  7306. buf_ranges_n += glyph_ranges_count;
  7307. for (int i = 0; i < glyph_ranges_count; i++)
  7308. {
  7309. const ImWchar* in_range = &data.GlyphRanges[i * 2];
  7310. stbtt_pack_range& range = data.Ranges[i];
  7311. range.font_size = data.SizePixels;
  7312. range.first_unicode_char_in_range = in_range[0];
  7313. range.num_chars_in_range = (in_range[1] - in_range[0]) + 1;
  7314. range.chardata_for_range = buf_packedchars + buf_packedchars_n;
  7315. buf_packedchars_n += range.num_chars_in_range;
  7316. }
  7317. // Pack
  7318. data.Rects = buf_rects + buf_rects_n;
  7319. buf_rects_n += glyph_count;
  7320. const int n = stbtt_PackFontRangesGatherRects(&spc, &data.FontInfo, data.Ranges, data.RangesCount, data.Rects);
  7321. stbrp_pack_rects((stbrp_context*)spc.pack_info, data.Rects, n);
  7322. // Extend texture height
  7323. for (int i = 0; i < n; i++)
  7324. if (data.Rects[i].was_packed)
  7325. TexHeight = ImMax(TexHeight, data.Rects[i].y + data.Rects[i].h);
  7326. }
  7327. IM_ASSERT(buf_rects_n == total_glyph_count);
  7328. IM_ASSERT(buf_packedchars_n == total_glyph_count);
  7329. IM_ASSERT(buf_ranges_n == total_glyph_range_count);
  7330. // Create texture
  7331. TexHeight = ImUpperPowerOfTwo(TexHeight);
  7332. TexPixelsAlpha8 = (unsigned char*)ImGui::MemAlloc(TexWidth * TexHeight);
  7333. memset(TexPixelsAlpha8, 0, TexWidth * TexHeight);
  7334. spc.pixels = TexPixelsAlpha8;
  7335. spc.height = TexHeight;
  7336. // Second pass: render characters
  7337. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  7338. {
  7339. ImFontAtlasData& data = *InputData[input_i];
  7340. ret = stbtt_PackFontRangesRenderIntoRects(&spc, &data.FontInfo, data.Ranges, data.RangesCount, data.Rects);
  7341. data.Rects = NULL;
  7342. }
  7343. // End packing
  7344. stbtt_PackEnd(&spc);
  7345. ImGui::MemFree(buf_rects);
  7346. buf_rects = NULL;
  7347. // Third pass: setup ImFont and glyphs for runtime
  7348. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  7349. {
  7350. ImFontAtlasData& data = *InputData[input_i];
  7351. data.OutFont->ContainerAtlas = this;
  7352. data.OutFont->FontSize = data.SizePixels;
  7353. const float font_scale = stbtt_ScaleForPixelHeight(&data.FontInfo, data.SizePixels);
  7354. int font_ascent, font_descent, font_line_gap;
  7355. stbtt_GetFontVMetrics(&data.FontInfo, &font_ascent, &font_descent, &font_line_gap);
  7356. const float uv_scale_x = 1.0f / TexWidth;
  7357. const float uv_scale_y = 1.0f / TexHeight;
  7358. const int character_spacing_x = 1;
  7359. for (int i = 0; i < data.RangesCount; i++)
  7360. {
  7361. stbtt_pack_range& range = data.Ranges[i];
  7362. for (int char_idx = 0; char_idx < range.num_chars_in_range; char_idx += 1)
  7363. {
  7364. const int codepoint = range.first_unicode_char_in_range + char_idx;
  7365. const stbtt_packedchar& pc = range.chardata_for_range[char_idx];
  7366. if (!pc.x0 && !pc.x1 && !pc.y0 && !pc.y1)
  7367. continue;
  7368. data.OutFont->Glyphs.resize(data.OutFont->Glyphs.size() + 1);
  7369. ImFont::Glyph& glyph = data.OutFont->Glyphs.back();
  7370. glyph.Codepoint = (ImWchar)codepoint;
  7371. glyph.Width = (signed short)pc.x1 - pc.x0 + 1;
  7372. glyph.Height = (signed short)pc.y1 - pc.y0 + 1;
  7373. glyph.XOffset = (signed short)(pc.xoff);
  7374. glyph.YOffset = (signed short)(pc.yoff + (int)(font_ascent * font_scale));
  7375. glyph.XAdvance = (signed short)(pc.xadvance + character_spacing_x); // Bake spacing into XAdvance
  7376. glyph.U0 = ((float)pc.x0 - 0.5f) * uv_scale_x;
  7377. glyph.V0 = ((float)pc.y0 - 0.5f) * uv_scale_y;
  7378. glyph.U1 = ((float)pc.x0 - 0.5f + glyph.Width) * uv_scale_x;
  7379. glyph.V1 = ((float)pc.y0 - 0.5f + glyph.Height) * uv_scale_y;
  7380. }
  7381. }
  7382. data.OutFont->BuildLookupTable();
  7383. }
  7384. // Cleanup temporaries
  7385. ImGui::MemFree(buf_packedchars);
  7386. ImGui::MemFree(buf_ranges);
  7387. buf_packedchars = NULL;
  7388. buf_ranges = NULL;
  7389. ClearInputData();
  7390. // Render into our custom data block
  7391. RenderCustomTexData(1, &extra_rects);
  7392. return true;
  7393. }
  7394. void ImFontAtlas::RenderCustomTexData(int pass, void* p_rects)
  7395. {
  7396. // . = white layer, X = black layer, others are blank
  7397. const int TEX_DATA_W = 90;
  7398. const int TEX_DATA_H = 27;
  7399. const char texture_data[TEX_DATA_W*TEX_DATA_H+1] =
  7400. {
  7401. "..- -XXXXXXX- X - X -XXXXXXX - XXXXXXX"
  7402. "..- -X.....X- X.X - X.X -X.....X - X.....X"
  7403. "--- -XXX.XXX- X...X - X...X -X....X - X....X"
  7404. "X - X.X - X.....X - X.....X -X...X - X...X"
  7405. "XX - X.X -X.......X- X.......X -X..X.X - X.X..X"
  7406. "X.X - X.X -XXXX.XXXX- XXXX.XXXX -X.X X.X - X.X X.X"
  7407. "X..X - X.X - X.X - X.X -XX X.X - X.X XX"
  7408. "X...X - X.X - X.X - XX X.X XX - X.X - X.X "
  7409. "X....X - X.X - X.X - X.X X.X X.X - X.X - X.X "
  7410. "X.....X - X.X - X.X - X..X X.X X..X - X.X - X.X "
  7411. "X......X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X XX-XX X.X "
  7412. "X.......X - X.X - X.X -X.....................X- X.X X.X-X.X X.X "
  7413. "X........X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X..X-X..X.X "
  7414. "X.........X -XXX.XXX- X.X - X..X X.X X..X - X...X-X...X "
  7415. "X..........X-X.....X- X.X - X.X X.X X.X - X....X-X....X "
  7416. "X......XXXXX-XXXXXXX- X.X - XX X.X XX - X.....X-X.....X "
  7417. "X...X..X --------- X.X - X.X - XXXXXXX-XXXXXXX "
  7418. "X..X X..X - -XXXX.XXXX- XXXX.XXXX ------------------------------------"
  7419. "X.X X..X - -X.......X- X.......X - XX XX - "
  7420. "XX X..X - - X.....X - X.....X - X.X X.X - "
  7421. " X..X - X...X - X...X - X..X X..X - "
  7422. " XX - X.X - X.X - X...XXXXXXXXXXXXX...X - "
  7423. "------------ - X - X -X.....................X- "
  7424. " ----------------------------------- X...XXXXXXXXXXXXX...X - "
  7425. " - X..X X..X - "
  7426. " - X.X X.X - "
  7427. " - XX XX - "
  7428. };
  7429. ImVector<stbrp_rect>& rects = *(ImVector<stbrp_rect>*)p_rects;
  7430. if (pass == 0)
  7431. {
  7432. stbrp_rect r;
  7433. memset(&r, 0, sizeof(r));
  7434. r.w = (TEX_DATA_W*2)+1;
  7435. r.h = TEX_DATA_H+1;
  7436. rects.push_back(r);
  7437. }
  7438. else if (pass == 1)
  7439. {
  7440. // Copy pixels
  7441. const stbrp_rect& r = rects[0];
  7442. for (int y = 0, n = 0; y < TEX_DATA_H; y++)
  7443. for (int x = 0; x < TEX_DATA_W; x++, n++)
  7444. {
  7445. const int offset0 = (int)(r.x + x) + (int)(r.y + y) * TexWidth;
  7446. const int offset1 = offset0 + 1 + TEX_DATA_W;
  7447. TexPixelsAlpha8[offset0] = texture_data[n] == '.' ? 0xFF : 0x00;
  7448. TexPixelsAlpha8[offset1] = texture_data[n] == 'X' ? 0xFF : 0x00;
  7449. }
  7450. const ImVec2 tex_uv_scale(1.0f / TexWidth, 1.0f / TexHeight);
  7451. TexUvWhitePixel = ImVec2(r.x + 0.5f, r.y + 0.5f) * tex_uv_scale;
  7452. const ImVec2 cursor_datas[ImGuiMouseCursor_Count_][3] =
  7453. {
  7454. // Pos ........ Size ......... Offset ......
  7455. { ImVec2(0,3), ImVec2(12,19), ImVec2( 0, 0) }, // ImGuiMouseCursor_Arrow
  7456. { ImVec2(13,0), ImVec2(7,16), ImVec2( 4, 8) }, // ImGuiMouseCursor_TextInput
  7457. { ImVec2(31,0), ImVec2(23,23), ImVec2(11,11) }, // ImGuiMouseCursor_Move
  7458. { ImVec2(21,0), ImVec2( 9,23), ImVec2( 5,11) }, // ImGuiMouseCursor_ResizeNS
  7459. { ImVec2(55,18),ImVec2(23, 9), ImVec2(11, 5) }, // ImGuiMouseCursor_ResizeEW
  7460. { ImVec2(73,0), ImVec2(17,17), ImVec2( 9, 9) }, // ImGuiMouseCursor_ResizeNESW
  7461. { ImVec2(55,0), ImVec2(17,17), ImVec2( 9, 9) }, // ImGuiMouseCursor_ResizeNWSE
  7462. };
  7463. for (int type = 0; type < ImGuiMouseCursor_Count_; type++)
  7464. {
  7465. ImGuiMouseCursorData& cursor_data = GImGui->MouseCursorData[type];
  7466. ImVec2 pos = cursor_datas[type][0] + ImVec2((float)r.x, (float)r.y);
  7467. const ImVec2 size = cursor_datas[type][1];
  7468. cursor_data.Type = type;
  7469. cursor_data.Size = size;
  7470. cursor_data.Offset = cursor_datas[type][2];
  7471. cursor_data.TexUvMin[0] = (pos) * tex_uv_scale;
  7472. cursor_data.TexUvMax[0] = (pos + size) * tex_uv_scale;
  7473. pos.x += TEX_DATA_W+1;
  7474. cursor_data.TexUvMin[1] = (pos) * tex_uv_scale;
  7475. cursor_data.TexUvMax[1] = (pos + size) * tex_uv_scale;
  7476. }
  7477. }
  7478. }
  7479. //-----------------------------------------------------------------------------
  7480. // ImFont
  7481. //-----------------------------------------------------------------------------
  7482. ImFont::ImFont()
  7483. {
  7484. Scale = 1.0f;
  7485. FallbackChar = (ImWchar)'?';
  7486. Clear();
  7487. }
  7488. ImFont::~ImFont()
  7489. {
  7490. // Invalidate active font so that the user gets a clear crash instead of a dangling pointer.
  7491. // If you want to delete fonts you need to do it between Render() and NewFrame().
  7492. ImGuiState& g = *GImGui;
  7493. if (g.Font == this)
  7494. g.Font = NULL;
  7495. Clear();
  7496. }
  7497. void ImFont::Clear()
  7498. {
  7499. FontSize = 0.0f;
  7500. DisplayOffset = ImVec2(-0.5f, 0.5f);
  7501. ContainerAtlas = NULL;
  7502. Glyphs.clear();
  7503. FallbackGlyph = NULL;
  7504. FallbackXAdvance = 0.0f;
  7505. IndexXAdvance.clear();
  7506. IndexLookup.clear();
  7507. }
  7508. // Retrieve list of range (2 int per range, values are inclusive)
  7509. const ImWchar* ImFontAtlas::GetGlyphRangesDefault()
  7510. {
  7511. static const ImWchar ranges[] =
  7512. {
  7513. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  7514. 0,
  7515. };
  7516. return &ranges[0];
  7517. }
  7518. const ImWchar* ImFontAtlas::GetGlyphRangesChinese()
  7519. {
  7520. static const ImWchar ranges[] =
  7521. {
  7522. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  7523. 0x3000, 0x30FF, // Punctuations, Hiragana, Katakana
  7524. 0x31F0, 0x31FF, // Katakana Phonetic Extensions
  7525. 0xFF00, 0xFFEF, // Half-width characters
  7526. 0x4e00, 0x9FAF, // CJK Ideograms
  7527. 0,
  7528. };
  7529. return &ranges[0];
  7530. }
  7531. const ImWchar* ImFontAtlas::GetGlyphRangesJapanese()
  7532. {
  7533. // Store the 1946 ideograms code points as successive offsets from the initial unicode codepoint 0x4E00. Each offset has an implicit +1.
  7534. // This encoding helps us reduce the source code size.
  7535. static const short offsets_from_0x4E00[] =
  7536. {
  7537. -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,
  7538. 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,
  7539. 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,
  7540. 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,
  7541. 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,
  7542. 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,
  7543. 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,
  7544. 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,
  7545. 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,
  7546. 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,
  7547. 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,
  7548. 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,
  7549. 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,
  7550. 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,
  7551. 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,
  7552. 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,
  7553. 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,
  7554. 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,
  7555. 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,
  7556. 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,
  7557. 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,
  7558. 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,
  7559. 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,
  7560. 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,
  7561. 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,
  7562. 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,
  7563. 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,
  7564. 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,
  7565. 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,
  7566. 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,
  7567. 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,
  7568. 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,
  7569. };
  7570. static int ranges_unpacked = false;
  7571. static ImWchar ranges[8 + IM_ARRAYSIZE(offsets_from_0x4E00)*2 + 1] =
  7572. {
  7573. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  7574. 0x3000, 0x30FF, // Punctuations, Hiragana, Katakana
  7575. 0x31F0, 0x31FF, // Katakana Phonetic Extensions
  7576. 0xFF00, 0xFFEF, // Half-width characters
  7577. };
  7578. if (!ranges_unpacked)
  7579. {
  7580. // Unpack
  7581. int codepoint = 0x4e00;
  7582. ImWchar* dst = &ranges[8];
  7583. for (int n = 0; n < IM_ARRAYSIZE(offsets_from_0x4E00); n++, dst += 2)
  7584. dst[0] = dst[1] = (ImWchar)(codepoint += (offsets_from_0x4E00[n] + 1));
  7585. dst[0] = 0;
  7586. ranges_unpacked = true;
  7587. }
  7588. return &ranges[0];
  7589. }
  7590. void ImFont::BuildLookupTable()
  7591. {
  7592. int max_codepoint = 0;
  7593. for (size_t i = 0; i != Glyphs.size(); i++)
  7594. max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint);
  7595. IndexXAdvance.clear();
  7596. IndexXAdvance.resize((size_t)max_codepoint + 1);
  7597. IndexLookup.clear();
  7598. IndexLookup.resize((size_t)max_codepoint + 1);
  7599. for (size_t i = 0; i < (size_t)max_codepoint + 1; i++)
  7600. {
  7601. IndexXAdvance[i] = -1.0f;
  7602. IndexLookup[i] = -1;
  7603. }
  7604. for (size_t i = 0; i < Glyphs.size(); i++)
  7605. {
  7606. const size_t codepoint = (int)Glyphs[i].Codepoint;
  7607. IndexXAdvance[codepoint] = Glyphs[i].XAdvance;
  7608. IndexLookup[codepoint] = (int)i;
  7609. }
  7610. // Create a glyph to handle TAB
  7611. // FIXME: Needs proper TAB handling but it needs to be contextualized (can arbitrary say that each string starts at "column 0"
  7612. if (FindGlyph((unsigned short)' '))
  7613. {
  7614. if (Glyphs.back().Codepoint != '\t') // So we can call this function multiple times
  7615. Glyphs.resize(Glyphs.size() + 1);
  7616. ImFont::Glyph& tab_glyph = Glyphs.back();
  7617. tab_glyph = *FindGlyph((unsigned short)' ');
  7618. tab_glyph.Codepoint = '\t';
  7619. tab_glyph.XAdvance *= 4;
  7620. IndexXAdvance[(size_t)tab_glyph.Codepoint] = (float)tab_glyph.XAdvance;
  7621. IndexLookup[(size_t)tab_glyph.Codepoint] = (int)(Glyphs.size()-1);
  7622. }
  7623. FallbackGlyph = NULL;
  7624. FallbackGlyph = FindGlyph(FallbackChar);
  7625. FallbackXAdvance = FallbackGlyph ? FallbackGlyph->XAdvance : 0.0f;
  7626. for (size_t i = 0; i < (size_t)max_codepoint + 1; i++)
  7627. if (IndexXAdvance[i] < 0.0f)
  7628. IndexXAdvance[i] = FallbackXAdvance;
  7629. }
  7630. void ImFont::SetFallbackChar(ImWchar c)
  7631. {
  7632. FallbackChar = c;
  7633. BuildLookupTable();
  7634. }
  7635. const ImFont::Glyph* ImFont::FindGlyph(unsigned short c) const
  7636. {
  7637. if (c < (int)IndexLookup.size())
  7638. {
  7639. const int i = IndexLookup[c];
  7640. if (i != -1)
  7641. return &Glyphs[i];
  7642. }
  7643. return FallbackGlyph;
  7644. }
  7645. // Convert UTF-8 to 32-bits character, process single character input.
  7646. // Based on stb_from_utf8() from github.com/nothings/stb/
  7647. // We handle UTF-8 decoding error by skipping forward.
  7648. static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end)
  7649. {
  7650. unsigned int c = (unsigned int)-1;
  7651. const unsigned char* str = (const unsigned char*)in_text;
  7652. if (!(*str & 0x80))
  7653. {
  7654. c = (unsigned int)(*str++);
  7655. *out_char = c;
  7656. return 1;
  7657. }
  7658. if ((*str & 0xe0) == 0xc0)
  7659. {
  7660. *out_char = 0;
  7661. if (in_text_end && in_text_end - (const char*)str < 2) return 0;
  7662. if (*str < 0xc2) return 0;
  7663. c = (unsigned int)((*str++ & 0x1f) << 6);
  7664. if ((*str & 0xc0) != 0x80) return 0;
  7665. c += (*str++ & 0x3f);
  7666. *out_char = c;
  7667. return 2;
  7668. }
  7669. if ((*str & 0xf0) == 0xe0)
  7670. {
  7671. *out_char = 0;
  7672. if (in_text_end && in_text_end - (const char*)str < 3) return 0;
  7673. if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return 0;
  7674. if (*str == 0xed && str[1] > 0x9f) return 0; // str[1] < 0x80 is checked below
  7675. c = (unsigned int)((*str++ & 0x0f) << 12);
  7676. if ((*str & 0xc0) != 0x80) return 0;
  7677. c += (unsigned int)((*str++ & 0x3f) << 6);
  7678. if ((*str & 0xc0) != 0x80) return 0;
  7679. c += (*str++ & 0x3f);
  7680. *out_char = c;
  7681. return 3;
  7682. }
  7683. if ((*str & 0xf8) == 0xf0)
  7684. {
  7685. *out_char = 0;
  7686. if (in_text_end && in_text_end - (const char*)str < 4) return 0;
  7687. if (*str > 0xf4) return 0;
  7688. if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return 0;
  7689. if (*str == 0xf4 && str[1] > 0x8f) return 0; // str[1] < 0x80 is checked below
  7690. c = (unsigned int)((*str++ & 0x07) << 18);
  7691. if ((*str & 0xc0) != 0x80) return 0;
  7692. c += (unsigned int)((*str++ & 0x3f) << 12);
  7693. if ((*str & 0xc0) != 0x80) return 0;
  7694. c += (unsigned int)((*str++ & 0x3f) << 6);
  7695. if ((*str & 0xc0) != 0x80) return 0;
  7696. c += (*str++ & 0x3f);
  7697. // utf-8 encodings of values used in surrogate pairs are invalid
  7698. if ((c & 0xFFFFF800) == 0xD800) return 0;
  7699. *out_char = c;
  7700. return 4;
  7701. }
  7702. *out_char = 0;
  7703. return 0;
  7704. }
  7705. static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end, const char** in_text_remaining)
  7706. {
  7707. ImWchar* buf_out = buf;
  7708. ImWchar* buf_end = buf + buf_size;
  7709. while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text)
  7710. {
  7711. unsigned int c;
  7712. in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
  7713. if (c == 0)
  7714. break;
  7715. if (c < 0x10000) // FIXME: Losing characters that don't fit in 2 bytes
  7716. *buf_out++ = (ImWchar)c;
  7717. }
  7718. *buf_out = 0;
  7719. if (in_text_remaining)
  7720. *in_text_remaining = in_text;
  7721. return buf_out - buf;
  7722. }
  7723. static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end)
  7724. {
  7725. int char_count = 0;
  7726. while ((!in_text_end || in_text < in_text_end) && *in_text)
  7727. {
  7728. unsigned int c;
  7729. in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
  7730. if (c == 0)
  7731. break;
  7732. if (c < 0x10000)
  7733. char_count++;
  7734. }
  7735. return char_count;
  7736. }
  7737. // Based on stb_to_utf8() from github.com/nothings/stb/
  7738. static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int c)
  7739. {
  7740. if (c)
  7741. {
  7742. size_t i = 0;
  7743. size_t n = buf_size;
  7744. if (c < 0x80)
  7745. {
  7746. if (i+1 > n) return 0;
  7747. buf[i++] = (char)c;
  7748. return 1;
  7749. }
  7750. else if (c < 0x800)
  7751. {
  7752. if (i+2 > n) return 0;
  7753. buf[i++] = (char)(0xc0 + (c >> 6));
  7754. buf[i++] = (char)(0x80 + (c & 0x3f));
  7755. return 2;
  7756. }
  7757. else if (c >= 0xdc00 && c < 0xe000)
  7758. {
  7759. return 0;
  7760. }
  7761. else if (c >= 0xd800 && c < 0xdc00)
  7762. {
  7763. if (i+4 > n) return 0;
  7764. buf[i++] = (char)(0xf0 + (c >> 18));
  7765. buf[i++] = (char)(0x80 + ((c >> 12) & 0x3f));
  7766. buf[i++] = (char)(0x80 + ((c >> 6) & 0x3f));
  7767. buf[i++] = (char)(0x80 + ((c ) & 0x3f));
  7768. return 4;
  7769. }
  7770. //else if (c < 0x10000)
  7771. {
  7772. if (i+3 > n) return 0;
  7773. buf[i++] = (char)(0xe0 + (c >> 12));
  7774. buf[i++] = (char)(0x80 + ((c>> 6) & 0x3f));
  7775. buf[i++] = (char)(0x80 + ((c ) & 0x3f));
  7776. return 3;
  7777. }
  7778. }
  7779. return 0;
  7780. }
  7781. static ptrdiff_t ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end)
  7782. {
  7783. char* buf_out = buf;
  7784. const char* buf_end = buf + buf_size;
  7785. while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text)
  7786. {
  7787. buf_out += ImTextCharToUtf8(buf_out, (uintptr_t)(buf_end-buf_out-1), (unsigned int)*in_text);
  7788. in_text++;
  7789. }
  7790. *buf_out = 0;
  7791. return buf_out - buf;
  7792. }
  7793. static int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end)
  7794. {
  7795. int bytes_count = 0;
  7796. while ((!in_text_end || in_text < in_text_end) && *in_text)
  7797. {
  7798. char dummy[5]; // FIXME-OPT
  7799. bytes_count += ImTextCharToUtf8(dummy, 5, (unsigned int)*in_text);
  7800. in_text++;
  7801. }
  7802. return bytes_count;
  7803. }
  7804. const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const
  7805. {
  7806. // Simple word-wrapping for English, not full-featured. Please submit failing cases!
  7807. // 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.)
  7808. // For references, possible wrap point marked with ^
  7809. // "aaa bbb, ccc,ddd. eee fff. ggg!"
  7810. // ^ ^ ^ ^ ^__ ^ ^
  7811. // List of hardcoded separators: .,;!?'"
  7812. // Skip extra blanks after a line returns (that includes not counting them in width computation)
  7813. // e.g. "Hello world" --> "Hello" "World"
  7814. // Cut words that cannot possibly fit within one line.
  7815. // e.g.: "The tropical fish" with ~5 characters worth of width --> "The tr" "opical" "fish"
  7816. float line_width = 0.0f;
  7817. float word_width = 0.0f;
  7818. float blank_width = 0.0f;
  7819. const char* word_end = text;
  7820. const char* prev_word_end = NULL;
  7821. bool inside_word = true;
  7822. const char* s = text;
  7823. while (s < text_end)
  7824. {
  7825. unsigned int c = (unsigned int)*s;
  7826. const char* next_s;
  7827. if (c < 0x80)
  7828. next_s = s + 1;
  7829. else
  7830. next_s = s + ImTextCharFromUtf8(&c, s, text_end);
  7831. if (c == 0)
  7832. break;
  7833. if (c == '\n')
  7834. {
  7835. line_width = word_width = blank_width = 0.0f;
  7836. inside_word = true;
  7837. s = next_s;
  7838. continue;
  7839. }
  7840. const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance;
  7841. if (ImCharIsSpace(c))
  7842. {
  7843. if (inside_word)
  7844. {
  7845. line_width += blank_width;
  7846. blank_width = 0.0f;
  7847. }
  7848. blank_width += char_width;
  7849. inside_word = false;
  7850. }
  7851. else
  7852. {
  7853. word_width += char_width;
  7854. if (inside_word)
  7855. {
  7856. word_end = next_s;
  7857. }
  7858. else
  7859. {
  7860. prev_word_end = word_end;
  7861. line_width += word_width + blank_width;
  7862. word_width = blank_width = 0.0f;
  7863. }
  7864. // Allow wrapping after punctuation.
  7865. inside_word = !(c == '.' || c == ',' || c == ';' || c == '!' || c == '?' || c == '\"');
  7866. }
  7867. // We ignore blank width at the end of the line (they can be skipped)
  7868. if (line_width + word_width >= wrap_width)
  7869. {
  7870. // Words that cannot possibly fit within an entire line will be cut anywhere.
  7871. if (word_width < wrap_width)
  7872. s = prev_word_end ? prev_word_end : word_end;
  7873. break;
  7874. }
  7875. s = next_s;
  7876. }
  7877. return s;
  7878. }
  7879. ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining) const
  7880. {
  7881. if (!text_end)
  7882. text_end = text_begin + strlen(text_begin); // FIXME-OPT: Need to avoid this.
  7883. const float scale = size / FontSize;
  7884. const float line_height = FontSize * scale;
  7885. ImVec2 text_size = ImVec2(0,0);
  7886. float line_width = 0.0f;
  7887. const bool word_wrap_enabled = (wrap_width > 0.0f);
  7888. const char* word_wrap_eol = NULL;
  7889. const char* s = text_begin;
  7890. while (s < text_end)
  7891. {
  7892. if (word_wrap_enabled)
  7893. {
  7894. // 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.
  7895. if (!word_wrap_eol)
  7896. {
  7897. word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - line_width);
  7898. if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
  7899. 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
  7900. }
  7901. if (s >= word_wrap_eol)
  7902. {
  7903. if (text_size.x < line_width)
  7904. text_size.x = line_width;
  7905. text_size.y += line_height;
  7906. line_width = 0.0f;
  7907. word_wrap_eol = NULL;
  7908. // Wrapping skips upcoming blanks
  7909. while (s < text_end)
  7910. {
  7911. const char c = *s;
  7912. if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; }
  7913. }
  7914. continue;
  7915. }
  7916. }
  7917. // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
  7918. const char* prev_s = s;
  7919. unsigned int c = (unsigned int)*s;
  7920. if (c < 0x80)
  7921. {
  7922. s += 1;
  7923. }
  7924. else
  7925. {
  7926. s += ImTextCharFromUtf8(&c, s, text_end);
  7927. if (c == 0)
  7928. break;
  7929. }
  7930. if (c == '\n')
  7931. {
  7932. text_size.x = ImMax(text_size.x, line_width);
  7933. text_size.y += line_height;
  7934. line_width = 0.0f;
  7935. continue;
  7936. }
  7937. const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance;
  7938. if (line_width + char_width >= max_width)
  7939. {
  7940. s = prev_s;
  7941. break;
  7942. }
  7943. line_width += char_width;
  7944. }
  7945. if (line_width > 0 || text_size.y == 0.0f)
  7946. {
  7947. if (text_size.x < line_width)
  7948. text_size.x = line_width;
  7949. text_size.y += line_height;
  7950. }
  7951. if (remaining)
  7952. *remaining = s;
  7953. return text_size;
  7954. }
  7955. ImVec2 ImFont::CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining) const
  7956. {
  7957. if (!text_end)
  7958. text_end = text_begin + ImStrlenW(text_begin);
  7959. const float scale = size / FontSize;
  7960. const float line_height = FontSize * scale;
  7961. ImVec2 text_size = ImVec2(0,0);
  7962. float line_width = 0.0f;
  7963. const ImWchar* s = text_begin;
  7964. while (s < text_end)
  7965. {
  7966. const unsigned int c = (unsigned int)(*s++);
  7967. if (c == '\n')
  7968. {
  7969. text_size.x = ImMax(text_size.x, line_width);
  7970. text_size.y += line_height;
  7971. line_width = 0.0f;
  7972. continue;
  7973. }
  7974. const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance;
  7975. if (line_width + char_width >= max_width)
  7976. {
  7977. s--;
  7978. break;
  7979. }
  7980. line_width += char_width;
  7981. }
  7982. if (line_width > 0 || text_size.y == 0.0f)
  7983. {
  7984. if (text_size.x < line_width)
  7985. text_size.x = line_width;
  7986. text_size.y += line_height;
  7987. }
  7988. if (remaining)
  7989. *remaining = s;
  7990. return text_size;
  7991. }
  7992. void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect_ref, const char* text_begin, const char* text_end, ImDrawList* draw_list, float wrap_width, const ImVec2* cpu_clip_max) const
  7993. {
  7994. if (!text_end)
  7995. text_end = text_begin + strlen(text_begin);
  7996. const float scale = size / FontSize;
  7997. const float line_height = FontSize * scale;
  7998. // Align to be pixel perfect
  7999. pos.x = (float)(int)pos.x + DisplayOffset.x;
  8000. pos.y = (float)(int)pos.y + DisplayOffset.y;
  8001. const bool word_wrap_enabled = (wrap_width > 0.0f);
  8002. const char* word_wrap_eol = NULL;
  8003. ImVec4 clip_rect = clip_rect_ref;
  8004. if (cpu_clip_max)
  8005. {
  8006. clip_rect.z = ImMin(clip_rect.z, cpu_clip_max->x);
  8007. clip_rect.w = ImMin(clip_rect.w, cpu_clip_max->y);
  8008. }
  8009. float x = pos.x;
  8010. float y = pos.y;
  8011. ImDrawVert* out_vertices = draw_list->vtx_write;
  8012. const char* s = text_begin;
  8013. while (s < text_end)
  8014. {
  8015. if (word_wrap_enabled)
  8016. {
  8017. // 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.
  8018. if (!word_wrap_eol)
  8019. {
  8020. word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - pos.x));
  8021. if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
  8022. 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
  8023. }
  8024. if (s >= word_wrap_eol)
  8025. {
  8026. x = pos.x;
  8027. y += line_height;
  8028. word_wrap_eol = NULL;
  8029. // Wrapping skips upcoming blanks
  8030. while (s < text_end)
  8031. {
  8032. const char c = *s;
  8033. if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; }
  8034. }
  8035. continue;
  8036. }
  8037. }
  8038. // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
  8039. unsigned int c = (unsigned int)*s;
  8040. if (c < 0x80)
  8041. {
  8042. s += 1;
  8043. }
  8044. else
  8045. {
  8046. s += ImTextCharFromUtf8(&c, s, text_end);
  8047. if (c == 0)
  8048. break;
  8049. }
  8050. if (c == '\n')
  8051. {
  8052. x = pos.x;
  8053. y += line_height;
  8054. continue;
  8055. }
  8056. float char_width = 0.0f;
  8057. if (const Glyph* glyph = FindGlyph((unsigned short)c))
  8058. {
  8059. char_width = glyph->XAdvance * scale;
  8060. if (c != ' ' && c != '\t')
  8061. {
  8062. // Clipping on Y is more likely
  8063. float y1 = (float)(y + glyph->YOffset * scale);
  8064. float y2 = (float)(y1 + glyph->Height * scale);
  8065. if (y1 <= clip_rect.w && y2 >= clip_rect.y)
  8066. {
  8067. float x1 = (float)(x + glyph->XOffset * scale);
  8068. float x2 = (float)(x1 + glyph->Width * scale);
  8069. if (x1 <= clip_rect.z && x2 >= clip_rect.x)
  8070. {
  8071. // Render a character
  8072. float u1 = glyph->U0;
  8073. float v1 = glyph->V0;
  8074. float u2 = glyph->U1;
  8075. float v2 = glyph->V1;
  8076. // 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)
  8077. if (cpu_clip_max)
  8078. {
  8079. if (x2 > cpu_clip_max->x)
  8080. {
  8081. const float clip_tx = (cpu_clip_max->x - x1) / (x2 - x1);
  8082. x2 = cpu_clip_max->x;
  8083. u2 = u1 + clip_tx * (u2 - u1);
  8084. }
  8085. if (y2 > cpu_clip_max->y)
  8086. {
  8087. const float clip_ty = (cpu_clip_max->y - y1) / (y2 - y1);
  8088. y2 = cpu_clip_max->y;
  8089. v2 = v1 + clip_ty * (v2 - v1);
  8090. }
  8091. }
  8092. // NB: we are not calling PrimRectUV() here because non-inlined causes too much overhead in a debug build.
  8093. out_vertices[0].pos = ImVec2(x1, y1);
  8094. out_vertices[0].uv = ImVec2(u1, v1);
  8095. out_vertices[0].col = col;
  8096. out_vertices[1].pos = ImVec2(x2, y1);
  8097. out_vertices[1].uv = ImVec2(u2, v1);
  8098. out_vertices[1].col = col;
  8099. out_vertices[2].pos = ImVec2(x2, y2);
  8100. out_vertices[2].uv = ImVec2(u2, v2);
  8101. out_vertices[2].col = col;
  8102. out_vertices[3] = out_vertices[0];
  8103. out_vertices[4] = out_vertices[2];
  8104. out_vertices[5].pos = ImVec2(x1, y2);
  8105. out_vertices[5].uv = ImVec2(u1, v2);
  8106. out_vertices[5].col = col;
  8107. out_vertices += 6;
  8108. }
  8109. }
  8110. }
  8111. }
  8112. x += char_width;
  8113. }
  8114. draw_list->vtx_write = out_vertices;
  8115. }
  8116. //-----------------------------------------------------------------------------
  8117. // PLATFORM DEPENDANT HELPERS
  8118. //-----------------------------------------------------------------------------
  8119. #if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS)
  8120. #ifndef _WINDOWS_
  8121. #define WIN32_LEAN_AND_MEAN
  8122. #include <windows.h>
  8123. #endif
  8124. // Win32 API clipboard implementation
  8125. static const char* GetClipboardTextFn_DefaultImpl()
  8126. {
  8127. static char* buf_local = NULL;
  8128. if (buf_local)
  8129. {
  8130. ImGui::MemFree(buf_local);
  8131. buf_local = NULL;
  8132. }
  8133. if (!OpenClipboard(NULL))
  8134. return NULL;
  8135. HANDLE wbuf_handle = GetClipboardData(CF_UNICODETEXT);
  8136. if (wbuf_handle == NULL)
  8137. return NULL;
  8138. if (ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle))
  8139. {
  8140. int buf_len = ImTextCountUtf8BytesFromStr(wbuf_global, NULL) + 1;
  8141. buf_local = (char*)ImGui::MemAlloc(buf_len * sizeof(char));
  8142. ImTextStrToUtf8(buf_local, buf_len, wbuf_global, NULL);
  8143. }
  8144. GlobalUnlock(wbuf_handle);
  8145. CloseClipboard();
  8146. return buf_local;
  8147. }
  8148. // Win32 API clipboard implementation
  8149. static void SetClipboardTextFn_DefaultImpl(const char* text)
  8150. {
  8151. if (!OpenClipboard(NULL))
  8152. return;
  8153. const int wbuf_length = ImTextCountCharsFromUtf8(text, NULL) + 1;
  8154. HGLOBAL wbuf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)wbuf_length * sizeof(ImWchar));
  8155. if (wbuf_handle == NULL)
  8156. return;
  8157. ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle);
  8158. ImTextStrFromUtf8(wbuf_global, wbuf_length, text, NULL);
  8159. GlobalUnlock(wbuf_handle);
  8160. EmptyClipboard();
  8161. SetClipboardData(CF_UNICODETEXT, wbuf_handle);
  8162. CloseClipboard();
  8163. }
  8164. #else
  8165. // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
  8166. static const char* GetClipboardTextFn_DefaultImpl()
  8167. {
  8168. return GImGui->PrivateClipboard;
  8169. }
  8170. // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
  8171. static void SetClipboardTextFn_DefaultImpl(const char* text)
  8172. {
  8173. ImGuiState& g = *GImGui;
  8174. if (g.PrivateClipboard)
  8175. {
  8176. ImGui::MemFree(g.PrivateClipboard);
  8177. g.PrivateClipboard = NULL;
  8178. }
  8179. const char* text_end = text + strlen(text);
  8180. g.PrivateClipboard = (char*)ImGui::MemAlloc((size_t)(text_end - text) + 1);
  8181. memcpy(g.PrivateClipboard, text, (size_t)(text_end - text));
  8182. g.PrivateClipboard[(size_t)(text_end - text)] = 0;
  8183. }
  8184. #endif
  8185. #if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS)
  8186. #ifndef _WINDOWS_
  8187. #define WIN32_LEAN_AND_MEAN
  8188. #include <windows.h>
  8189. #endif
  8190. #include <Imm.h>
  8191. #pragma comment(lib, "imm32")
  8192. static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y)
  8193. {
  8194. // Notify OS Input Method Editor of text input position
  8195. if (HWND hwnd = (HWND)GImGui->IO.ImeWindowHandle)
  8196. if (HIMC himc = ImmGetContext(hwnd))
  8197. {
  8198. COMPOSITIONFORM cf;
  8199. cf.ptCurrentPos.x = x;
  8200. cf.ptCurrentPos.y = y;
  8201. cf.dwStyle = CFS_FORCE_POSITION;
  8202. ImmSetCompositionWindow(himc, &cf);
  8203. }
  8204. }
  8205. #else
  8206. static void ImeSetInputScreenPosFn_DefaultImpl(int, int)
  8207. {
  8208. }
  8209. #endif
  8210. #ifdef IMGUI_DISABLE_TEST_WINDOWS
  8211. void ImGui::ShowUserGuide() {}
  8212. void ImGui::ShowStyleEditor(ImGuiStyle*) {}
  8213. void ImGui::ShowTestWindow(bool*) {}
  8214. void ImGui::ShowMetricsWindow(bool*) {}
  8215. #else
  8216. //-----------------------------------------------------------------------------
  8217. // HELP
  8218. //-----------------------------------------------------------------------------
  8219. void ImGui::ShowUserGuide()
  8220. {
  8221. ImGuiState& g = *GImGui;
  8222. ImGui::BulletText("Double-click on title bar to collapse window.");
  8223. ImGui::BulletText("Click and drag on lower right corner to resize window.");
  8224. ImGui::BulletText("Click and drag on any empty space to move window.");
  8225. ImGui::BulletText("Mouse Wheel to scroll.");
  8226. if (g.IO.FontAllowUserScaling)
  8227. ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents.");
  8228. ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields.");
  8229. ImGui::BulletText("CTRL+Click on a slider to input text.");
  8230. ImGui::BulletText(
  8231. "While editing text:\n"
  8232. "- Hold SHIFT or use mouse to select text\n"
  8233. "- CTRL+Left/Right to word jump\n"
  8234. "- CTRL+A select all\n"
  8235. "- CTRL+X,CTRL+C,CTRL+V clipboard\n"
  8236. "- CTRL+Z,CTRL+Y undo/redo\n"
  8237. "- ESCAPE to revert\n"
  8238. "- You can apply arithmetic operators +,*,/ on numerical values.\n"
  8239. " Use +- to subtract.\n");
  8240. }
  8241. void ImGui::ShowStyleEditor(ImGuiStyle* ref)
  8242. {
  8243. ImGuiState& g = *GImGui;
  8244. ImGuiStyle& style = g.Style;
  8245. const ImGuiStyle def; // Default style
  8246. if (ImGui::Button("Revert Style"))
  8247. g.Style = ref ? *ref : def;
  8248. if (ref)
  8249. {
  8250. ImGui::SameLine();
  8251. if (ImGui::Button("Save Style"))
  8252. *ref = g.Style;
  8253. }
  8254. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.55f);
  8255. if (ImGui::TreeNode("Sizes"))
  8256. {
  8257. 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.
  8258. ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f");
  8259. ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f");
  8260. ImGui::SliderFloat("ChildWindowRounding", &style.ChildWindowRounding, 0.0f, 16.0f, "%.0f");
  8261. ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f");
  8262. ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 16.0f, "%.0f");
  8263. ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f");
  8264. ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f");
  8265. ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f");
  8266. ImGui::SliderFloat("IndentSpacing", &style.IndentSpacing, 0.0f, 20.0f, "%.0f");
  8267. ImGui::SliderFloat("ScrollBarWidth", &style.ScrollbarWidth, 1.0f, 20.0f, "%.0f");
  8268. ImGui::SliderFloat("GrabMinSize", &style.GrabMinSize, 1.0f, 20.0f, "%.0f");
  8269. ImGui::TreePop();
  8270. }
  8271. if (ImGui::TreeNode("Colors"))
  8272. {
  8273. static int output_dest = 0;
  8274. static bool output_only_modified = false;
  8275. if (ImGui::Button("Output Colors"))
  8276. {
  8277. if (output_dest == 0)
  8278. ImGui::LogToClipboard();
  8279. else
  8280. ImGui::LogToTTY();
  8281. ImGui::LogText("ImGuiStyle& style = ImGui::GetStyle();" STR_NEWLINE);
  8282. for (int i = 0; i < ImGuiCol_COUNT; i++)
  8283. {
  8284. const ImVec4& col = style.Colors[i];
  8285. const char* name = ImGui::GetStyleColName(i);
  8286. if (!output_only_modified || memcmp(&col, (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0)
  8287. 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);
  8288. }
  8289. ImGui::LogFinish();
  8290. }
  8291. ImGui::SameLine(); ImGui::PushItemWidth(150); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY"); ImGui::PopItemWidth();
  8292. ImGui::SameLine(); ImGui::Checkbox("Only Modified Fields", &output_only_modified);
  8293. static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB;
  8294. ImGui::RadioButton("RGB", &edit_mode, ImGuiColorEditMode_RGB);
  8295. ImGui::SameLine();
  8296. ImGui::RadioButton("HSV", &edit_mode, ImGuiColorEditMode_HSV);
  8297. ImGui::SameLine();
  8298. ImGui::RadioButton("HEX", &edit_mode, ImGuiColorEditMode_HEX);
  8299. //ImGui::Text("Tip: Click on colored square to change edit mode.");
  8300. static ImGuiTextFilter filter;
  8301. filter.Draw("Filter colors", 200);
  8302. ImGui::BeginChild("#colors", ImVec2(0, 300), true);
  8303. ImGui::ColorEditMode(edit_mode);
  8304. for (int i = 0; i < ImGuiCol_COUNT; i++)
  8305. {
  8306. const char* name = ImGui::GetStyleColName(i);
  8307. if (!filter.PassFilter(name))
  8308. continue;
  8309. ImGui::PushID(i);
  8310. ImGui::ColorEdit4(name, (float*)&style.Colors[i], true);
  8311. if (memcmp(&style.Colors[i], (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0)
  8312. {
  8313. ImGui::SameLine(); if (ImGui::Button("Revert")) style.Colors[i] = ref ? ref->Colors[i] : def.Colors[i];
  8314. if (ref) { ImGui::SameLine(); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i]; }
  8315. }
  8316. ImGui::PopID();
  8317. }
  8318. ImGui::EndChild();
  8319. ImGui::TreePop();
  8320. }
  8321. ImGui::PopItemWidth();
  8322. }
  8323. //-----------------------------------------------------------------------------
  8324. // SAMPLE CODE
  8325. //-----------------------------------------------------------------------------
  8326. static void ShowExampleAppConsole(bool* opened);
  8327. static void ShowExampleAppLongText(bool* opened);
  8328. static void ShowExampleAppAutoResize(bool* opened);
  8329. static void ShowExampleAppFixedOverlay(bool* opened);
  8330. static void ShowExampleAppManipulatingWindowTitle(bool* opened);
  8331. static void ShowExampleAppCustomRendering(bool* opened);
  8332. // Demonstrate ImGui features (unfortunately this makes this function a little bloated!)
  8333. void ImGui::ShowTestWindow(bool* opened)
  8334. {
  8335. // Examples apps
  8336. static bool show_app_metrics = false;
  8337. static bool show_app_console = false;
  8338. static bool show_app_long_text = false;
  8339. static bool show_app_auto_resize = false;
  8340. static bool show_app_fixed_overlay = false;
  8341. static bool show_app_custom_rendering = false;
  8342. static bool show_app_manipulating_window_title = false;
  8343. if (show_app_metrics)
  8344. ImGui::ShowMetricsWindow(&show_app_metrics);
  8345. if (show_app_console)
  8346. ShowExampleAppConsole(&show_app_console);
  8347. if (show_app_long_text)
  8348. ShowExampleAppLongText(&show_app_long_text);
  8349. if (show_app_auto_resize)
  8350. ShowExampleAppAutoResize(&show_app_auto_resize);
  8351. if (show_app_fixed_overlay)
  8352. ShowExampleAppFixedOverlay(&show_app_fixed_overlay);
  8353. if (show_app_manipulating_window_title)
  8354. ShowExampleAppManipulatingWindowTitle(&show_app_manipulating_window_title);
  8355. if (show_app_custom_rendering)
  8356. ShowExampleAppCustomRendering(&show_app_custom_rendering);
  8357. static bool no_titlebar = false;
  8358. static bool no_border = true;
  8359. static bool no_resize = false;
  8360. static bool no_move = false;
  8361. static bool no_scrollbar = false;
  8362. static bool no_collapse = false;
  8363. static float bg_alpha = 0.65f;
  8364. // Demonstrate the various window flags. Typically you would just use the default.
  8365. ImGuiWindowFlags window_flags = 0;
  8366. if (no_titlebar) window_flags |= ImGuiWindowFlags_NoTitleBar;
  8367. if (!no_border) window_flags |= ImGuiWindowFlags_ShowBorders;
  8368. if (no_resize) window_flags |= ImGuiWindowFlags_NoResize;
  8369. if (no_move) window_flags |= ImGuiWindowFlags_NoMove;
  8370. if (no_scrollbar) window_flags |= ImGuiWindowFlags_NoScrollbar;
  8371. if (no_collapse) window_flags |= ImGuiWindowFlags_NoCollapse;
  8372. if (!ImGui::Begin("ImGui Test", opened, ImVec2(550,680), bg_alpha, window_flags))
  8373. {
  8374. // Early out if the window is collapsed, as an optimization.
  8375. ImGui::End();
  8376. return;
  8377. }
  8378. //ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); // 2/3 of the space for widget and 1/3 for labels
  8379. ImGui::PushItemWidth(-140); // Right align, keep 140 pixels for labels
  8380. ImGui::Text("ImGui says hello.");
  8381. //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
  8382. //ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel);
  8383. //ImGui::Text("KeyMods %s%s%s", ImGui::GetIO().KeyCtrl ? "CTRL" : "", ImGui::GetIO().KeyShift ? "SHIFT" : "", ImGui::GetIO().KeyAlt? "ALT" : "");
  8384. //ImGui::Text("WantCaptureMouse: %d", ImGui::GetIO().WantCaptureMouse);
  8385. //ImGui::Text("WantCaptureKeyboard: %d", ImGui::GetIO().WantCaptureKeyboard);
  8386. ImGui::Spacing();
  8387. if (ImGui::CollapsingHeader("Help"))
  8388. {
  8389. ImGui::TextWrapped("This window is being created by the ShowTestWindow() function. Please refer to the code for programming reference.\n\nUser Guide:");
  8390. ImGui::ShowUserGuide();
  8391. }
  8392. if (ImGui::CollapsingHeader("Window options"))
  8393. {
  8394. ImGui::Checkbox("no titlebar", &no_titlebar); ImGui::SameLine(150);
  8395. ImGui::Checkbox("no border", &no_border); ImGui::SameLine(300);
  8396. ImGui::Checkbox("no resize", &no_resize);
  8397. ImGui::Checkbox("no move", &no_move); ImGui::SameLine(150);
  8398. ImGui::Checkbox("no scrollbar", &no_scrollbar); ImGui::SameLine(300);
  8399. ImGui::Checkbox("no collapse", &no_collapse);
  8400. ImGui::SliderFloat("bg alpha", &bg_alpha, 0.0f, 1.0f);
  8401. if (ImGui::TreeNode("Style"))
  8402. {
  8403. ImGui::ShowStyleEditor();
  8404. ImGui::TreePop();
  8405. }
  8406. if (ImGui::TreeNode("Fonts"))
  8407. {
  8408. ImGui::TextWrapped("Tip: Load fonts with GetIO().Fonts->AddFontFromFileTTF().");
  8409. for (size_t i = 0; i < ImGui::GetIO().Fonts->Fonts.size(); i++)
  8410. {
  8411. ImFont* font = ImGui::GetIO().Fonts->Fonts[i];
  8412. ImGui::BulletText("Font %d: %.2f pixels, %d glyphs", i, font->FontSize, font->Glyphs.size());
  8413. ImGui::TreePush((void*)i);
  8414. ImGui::PushFont(font);
  8415. ImGui::Text("The quick brown fox jumps over the lazy dog");
  8416. ImGui::PopFont();
  8417. if (i > 0 && ImGui::Button("Set as default"))
  8418. {
  8419. ImGui::GetIO().Fonts->Fonts[i] = ImGui::GetIO().Fonts->Fonts[0];
  8420. ImGui::GetIO().Fonts->Fonts[0] = font;
  8421. }
  8422. ImGui::SliderFloat("font scale", &font->Scale, 0.3f, 2.0f, "%.1f"); // scale only this font
  8423. ImGui::TreePop();
  8424. }
  8425. static float window_scale = 1.0f;
  8426. ImGui::SliderFloat("this window scale", &window_scale, 0.3f, 2.0f, "%.1f"); // scale only this window
  8427. ImGui::SliderFloat("global scale", &ImGui::GetIO().FontGlobalScale, 0.3f, 2.0f, "%.1f"); // scale everything
  8428. ImGui::SetWindowFontScale(window_scale);
  8429. ImGui::TreePop();
  8430. }
  8431. if (ImGui::TreeNode("Logging"))
  8432. {
  8433. ImGui::LogButtons();
  8434. ImGui::TreePop();
  8435. }
  8436. }
  8437. if (ImGui::CollapsingHeader("Widgets"))
  8438. {
  8439. static bool a=false;
  8440. if (ImGui::Button("Button")) { printf("Clicked\n"); a ^= 1; }
  8441. if (a)
  8442. {
  8443. ImGui::SameLine();
  8444. ImGui::Text("Thanks for clicking me!");
  8445. }
  8446. if (ImGui::TreeNode("Tree"))
  8447. {
  8448. for (size_t i = 0; i < 5; i++)
  8449. {
  8450. if (ImGui::TreeNode((void*)i, "Child %d", i))
  8451. {
  8452. ImGui::Text("blah blah");
  8453. ImGui::SameLine();
  8454. if (ImGui::SmallButton("print"))
  8455. printf("Child %d pressed", (int)i);
  8456. ImGui::TreePop();
  8457. }
  8458. }
  8459. ImGui::TreePop();
  8460. }
  8461. if (ImGui::TreeNode("Bullets"))
  8462. {
  8463. ImGui::BulletText("Bullet point 1");
  8464. ImGui::BulletText("Bullet point 2\nOn multiple lines");
  8465. ImGui::Bullet(); ImGui::Text("Bullet point 3 (two calls)");
  8466. ImGui::Bullet(); ImGui::SmallButton("Button 1");
  8467. ImGui::Bullet(); ImGui::SmallButton("Button 2");
  8468. ImGui::TreePop();
  8469. }
  8470. if (ImGui::TreeNode("Colored Text"))
  8471. {
  8472. // Using shortcut. You can use PushStyleColor()/PopStyleColor() for more flexibility.
  8473. ImGui::TextColored(ImVec4(1.0f,0.0f,1.0f,1.0f), "Pink");
  8474. ImGui::TextColored(ImVec4(1.0f,1.0f,0.0f,1.0f), "Yellow");
  8475. ImGui::TreePop();
  8476. }
  8477. if (ImGui::TreeNode("Word Wrapping"))
  8478. {
  8479. // Using shortcut. You can use PushTextWrapPos()/PopTextWrapPos() for more flexibility.
  8480. 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.");
  8481. ImGui::Spacing();
  8482. static float wrap_width = 200.0f;
  8483. ImGui::SliderFloat("Wrap width", &wrap_width, -20, 600, "%.0f");
  8484. ImGui::Text("Test paragraph 1:");
  8485. ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF);
  8486. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  8487. ImGui::Text("lazy dog. This paragraph is made to fit within %.0f pixels. The quick brown fox jumps over the lazy dog.", wrap_width);
  8488. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), 0xFF00FFFF);
  8489. ImGui::PopTextWrapPos();
  8490. ImGui::Text("Test paragraph 2:");
  8491. ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF);
  8492. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  8493. ImGui::Text("aaaaaaaa bbbbbbbb, cccccccc,dddddddd. eeeeeeee ffffffff. gggggggg!hhhhhhhh");
  8494. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), 0xFF00FFFF);
  8495. ImGui::PopTextWrapPos();
  8496. ImGui::TreePop();
  8497. }
  8498. if (ImGui::TreeNode("UTF-8 Text"))
  8499. {
  8500. // UTF-8 test with Japanese characters
  8501. // (needs a suitable font, try Arial Unicode or M+ fonts http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html)
  8502. // Most compiler appears to support UTF-8 in source code (with Visual Studio you need to save your file as 'UTF-8 without signature')
  8503. // 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.
  8504. // In your own application be reasonable and use UTF-8 in source or retrieve the data from file system!
  8505. // Note that characters values are preserved even if the font cannot be displayed, so you can safely copy & paste garbled characters into another application.
  8506. 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.");
  8507. ImGui::Text("Hiragana: \xe3\x81\x8b\xe3\x81\x8d\xe3\x81\x8f\xe3\x81\x91\xe3\x81\x93 (kakikukeko)");
  8508. ImGui::Text("Kanjis: \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e (nihongo)");
  8509. static char buf[32] = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e";
  8510. ImGui::InputText("UTF-8 input", buf, IM_ARRAYSIZE(buf));
  8511. ImGui::TreePop();
  8512. }
  8513. if (ImGui::TreeNode("Clipping"))
  8514. {
  8515. static ImVec2 size(80, 20);
  8516. ImGui::TextWrapped("On a per-widget basis we are occasionally clipping text if it won't fit in its frame.");
  8517. ImGui::SliderFloat2("size", (float*)&size, 5.0f, 200.0f);
  8518. ImGui::Button("Line 1 hello\nLine 2 clip me!", size);
  8519. 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.");
  8520. ImGui::TreePop();
  8521. }
  8522. if (ImGui::TreeNode("Images"))
  8523. {
  8524. 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!");
  8525. ImVec2 tex_screen_pos = ImGui::GetCursorScreenPos();
  8526. float tex_w = (float)ImGui::GetIO().Fonts->TexWidth;
  8527. float tex_h = (float)ImGui::GetIO().Fonts->TexHeight;
  8528. ImTextureID tex_id = ImGui::GetIO().Fonts->TexID;
  8529. 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));
  8530. if (ImGui::IsItemHovered())
  8531. {
  8532. ImGui::BeginTooltip();
  8533. float focus_sz = 32.0f;
  8534. float focus_x = ImClamp(ImGui::GetMousePos().x - tex_screen_pos.x - focus_sz * 0.5f, 0.0f, tex_w - focus_sz);
  8535. float focus_y = ImClamp(ImGui::GetMousePos().y - tex_screen_pos.y - focus_sz * 0.5f, 0.0f, tex_h - focus_sz);
  8536. ImGui::Text("Min: (%.2f, %.2f)", focus_x, focus_y);
  8537. ImGui::Text("Max: (%.2f, %.2f)", focus_x + focus_sz, focus_y + focus_sz);
  8538. ImVec2 uv0 = ImVec2((focus_x) / tex_w, (focus_y) / tex_h);
  8539. ImVec2 uv1 = ImVec2((focus_x + focus_sz) / tex_w, (focus_y + focus_sz) / tex_h);
  8540. ImGui::Image(tex_id, ImVec2(128,128), uv0, uv1, ImColor(255,255,255,255), ImColor(255,255,255,128));
  8541. ImGui::EndTooltip();
  8542. }
  8543. ImGui::TextWrapped("And now some textured buttons..");
  8544. static int pressed_count = 0;
  8545. for (int i = 0; i < 8; i++)
  8546. {
  8547. if (i > 0)
  8548. ImGui::SameLine();
  8549. ImGui::PushID(i);
  8550. int frame_padding = -1 + i; // -1 padding uses default padding
  8551. if (ImGui::ImageButton(tex_id, ImVec2(32,32), ImVec2(0,0), ImVec2(32.0f/tex_w,32/tex_h), frame_padding))
  8552. pressed_count += 1;
  8553. ImGui::PopID();
  8554. }
  8555. ImGui::Text("Pressed %d times.", pressed_count);
  8556. ImGui::TreePop();
  8557. }
  8558. if (ImGui::TreeNode("Selectables"))
  8559. {
  8560. if (ImGui::TreeNode("Basic"))
  8561. {
  8562. static bool selected[3] = { false, true, false };
  8563. ImGui::Selectable("1. I am selectable", &selected[0]);
  8564. ImGui::Selectable("2. I am selectable", &selected[1]);
  8565. ImGui::Text("3. I am not selectable");
  8566. ImGui::Selectable("4. I am selectable", &selected[2]);
  8567. ImGui::TreePop();
  8568. }
  8569. if (ImGui::TreeNode("Rendering more text into the same block"))
  8570. {
  8571. static bool selected[3] = { false, false, false };
  8572. ImGui::Selectable("main.c", &selected[0]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes");
  8573. ImGui::Selectable("Hello.cpp", &selected[1]); ImGui::SameLine(300); ImGui::Text("12,345 bytes");
  8574. ImGui::Selectable("Hello.h", &selected[2]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes");
  8575. ImGui::TreePop();
  8576. }
  8577. if (ImGui::TreeNode("Grid"))
  8578. {
  8579. static bool selected[16] = { true, false, false, false, false, true, false, false, false, false, true, false, false, false, false, true };
  8580. for (int i = 0; i < 16; i++)
  8581. {
  8582. ImGui::PushID(i);
  8583. if (ImGui::Selectable("Me", &selected[i], ImVec2(50,50)))
  8584. {
  8585. int x = i % 4, y = i / 4;
  8586. if (x > 0) selected[i - 1] ^= 1;
  8587. if (x < 3) selected[i + 1] ^= 1;
  8588. if (y > 0) selected[i - 4] ^= 1;
  8589. if (y < 3) selected[i + 4] ^= 1;
  8590. }
  8591. if ((i % 4) < 3) ImGui::SameLine();
  8592. ImGui::PopID();
  8593. }
  8594. ImGui::TreePop();
  8595. }
  8596. ImGui::TreePop();
  8597. }
  8598. if (ImGui::TreeNode("Popup"))
  8599. {
  8600. static bool popup_open = false;
  8601. static int selected_fish = -1;
  8602. const char* fishes[] = { "Bream", "Haddock", "Mackerel", "Pollock", "Tilefish" };
  8603. if (ImGui::Button("Select.."))
  8604. popup_open = true;
  8605. ImGui::SameLine();
  8606. ImGui::Text(selected_fish == -1 ? "<None>" : fishes[selected_fish]);
  8607. if (popup_open)
  8608. {
  8609. ImGui::BeginPopup(&popup_open);
  8610. ImGui::Text("Aquarium");
  8611. ImGui::Separator();
  8612. for (int i = 0; i < IM_ARRAYSIZE(fishes); i++)
  8613. {
  8614. if (ImGui::Selectable(fishes[i], false))
  8615. {
  8616. selected_fish = i;
  8617. popup_open = false;
  8618. }
  8619. }
  8620. ImGui::EndPopup();
  8621. }
  8622. ImGui::TreePop();
  8623. }
  8624. if (ImGui::TreeNode("Filtered Text Input"))
  8625. {
  8626. static char buf1[64] = ""; ImGui::InputText("default", buf1, 64);
  8627. static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal);
  8628. static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
  8629. static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase);
  8630. static char buf5[64] = ""; ImGui::InputText("no blank", buf5, 64, ImGuiInputTextFlags_CharsNoBlank);
  8631. struct TextFilters { static int FilterImGuiLetters(ImGuiTextEditCallbackData* data) { if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar)) return 0; return 1; } };
  8632. static char buf6[64] = ""; ImGui::InputText("\"imgui\" letters", buf6, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters);
  8633. ImGui::TreePop();
  8634. }
  8635. static bool check = true;
  8636. ImGui::Checkbox("checkbox", &check);
  8637. static int e = 0;
  8638. ImGui::RadioButton("radio a", &e, 0); ImGui::SameLine();
  8639. ImGui::RadioButton("radio b", &e, 1); ImGui::SameLine();
  8640. ImGui::RadioButton("radio c", &e, 2);
  8641. // Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style.
  8642. for (int i = 0; i < 7; i++)
  8643. {
  8644. if (i > 0) ImGui::SameLine();
  8645. ImGui::PushID(i);
  8646. ImGui::PushStyleColor(ImGuiCol_Button, ImColor::HSV(i/7.0f, 0.6f, 0.6f));
  8647. ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImColor::HSV(i/7.0f, 0.7f, 0.7f));
  8648. ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImColor::HSV(i/7.0f, 0.8f, 0.8f));
  8649. ImGui::Button("Click");
  8650. ImGui::PopStyleColor(3);
  8651. ImGui::PopID();
  8652. }
  8653. ImGui::Text("Hover over me");
  8654. if (ImGui::IsItemHovered())
  8655. ImGui::SetTooltip("I am a tooltip");
  8656. ImGui::SameLine();
  8657. ImGui::Text("- or me");
  8658. if (ImGui::IsItemHovered())
  8659. {
  8660. ImGui::BeginTooltip();
  8661. ImGui::Text("I am a fancy tooltip");
  8662. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  8663. ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr));
  8664. ImGui::EndTooltip();
  8665. }
  8666. // Testing IMGUI_ONCE_UPON_A_FRAME macro
  8667. //for (int i = 0; i < 5; i++)
  8668. //{
  8669. // IMGUI_ONCE_UPON_A_FRAME
  8670. // {
  8671. // ImGui::Text("This will be displayed only once.");
  8672. // }
  8673. //}
  8674. ImGui::Separator();
  8675. ImGui::LabelText("label", "Value");
  8676. static int item = 1;
  8677. ImGui::Combo("combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0");
  8678. const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK" };
  8679. static int item2 = -1;
  8680. ImGui::Combo("combo scroll", &item2, items, IM_ARRAYSIZE(items));
  8681. {
  8682. static char str0[128] = "Hello, world!";
  8683. static int i0=123;
  8684. static float f0=0.001f;
  8685. ImGui::InputText("input text", str0, IM_ARRAYSIZE(str0));
  8686. ImGui::InputInt("input int", &i0);
  8687. ImGui::InputFloat("input float", &f0, 0.01f, 1.0f);
  8688. static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
  8689. ImGui::InputFloat3("input float3", vec4a);
  8690. }
  8691. {
  8692. static int i1=50;
  8693. static int i2=42;
  8694. ImGui::DragInt("drag int", &i1, 1);
  8695. ImGui::SameLine();
  8696. ImGui::TextColored(ImColor(170,170,170,255), "(?)");
  8697. if (ImGui::IsItemHovered())
  8698. ImGui::SetTooltip("Click and drag to edit value.\nHold SHIFT/ALT for faster/slower edit.\nDouble-click or CTRL+click to input text");
  8699. ImGui::DragInt("drag int 0..100", &i2, 1, 0, 100, "%.0f%%");
  8700. static float f1=1.00f;
  8701. static float f2=0.0067f;
  8702. ImGui::DragFloat("drag float", &f1, 1.0f);
  8703. ImGui::DragFloat("drag small float", &f2, 0.0001f, 0.0f, 0.0f, "%.06f ns");
  8704. }
  8705. {
  8706. static int i1=0;
  8707. //static int i2=42;
  8708. ImGui::SliderInt("slider int 0..3", &i1, 0, 3);
  8709. //ImGui::SliderInt("slider int -100..100", &i2, -100, 100);
  8710. static float f1=0.123f;
  8711. static float f2=0.0f;
  8712. ImGui::SliderFloat("slider float", &f1, 0.0f, 1.0f, "ratio = %.3f");
  8713. ImGui::SliderFloat("slider log float", &f2, -10.0f, 10.0f, "%.4f", 3.0f);
  8714. static float angle = 0.0f;
  8715. ImGui::SliderAngle("slider angle", &angle);
  8716. }
  8717. static float col1[3] = { 1.0f,0.0f,0.2f };
  8718. static float col2[4] = { 0.4f,0.7f,0.0f,0.5f };
  8719. ImGui::ColorEdit3("color 1", col1);
  8720. ImGui::ColorEdit4("color 2", col2);
  8721. const char* listbox_items[] = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon" };
  8722. static int listbox_item_current = 1;
  8723. ImGui::ListBox("listbox\n(single select)", &listbox_item_current, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
  8724. //static int listbox_item_current2 = 2;
  8725. //ImGui::PushItemWidth(-1);
  8726. //ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
  8727. //ImGui::PopItemWidth();
  8728. if (ImGui::TreeNode("Multi-component Widgets"))
  8729. {
  8730. ImGui::Unindent();
  8731. static float vec4f[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
  8732. static int vec4i[4] = { 1, 5, 100, 255 };
  8733. ImGui::InputFloat2("input float2", vec4f);
  8734. ImGui::DragFloat2("drag float2", vec4f, 0.01f, 0.0f, 1.0f);
  8735. ImGui::SliderFloat2("slider float2", vec4f, 0.0f, 1.0f);
  8736. ImGui::DragInt2("drag int2", vec4i, 1, 0, 255);
  8737. ImGui::InputInt2("input int2", vec4i);
  8738. ImGui::SliderInt2("slider int2", vec4i, 0, 255);
  8739. ImGui::InputFloat3("input float3", vec4f);
  8740. ImGui::DragFloat3("drag float3", vec4f, 0.01f, 0.0f, 1.0f);
  8741. ImGui::SliderFloat3("slider float3", vec4f, 0.0f, 1.0f);
  8742. ImGui::DragInt3("drag int3", vec4i, 1, 0, 255);
  8743. ImGui::InputInt3("input int3", vec4i);
  8744. ImGui::SliderInt3("slider int3", vec4i, 0, 255);
  8745. ImGui::InputFloat4("input float4", vec4f);
  8746. ImGui::DragFloat4("drag float4", vec4f, 0.01f, 0.0f, 1.0f);
  8747. ImGui::SliderFloat4("slider float4", vec4f, 0.0f, 1.0f);
  8748. ImGui::InputInt4("input int4", vec4i);
  8749. ImGui::DragInt4("drag int4", vec4i, 1, 0, 255);
  8750. ImGui::SliderInt4("slider int4", vec4i, 0, 255);
  8751. ImGui::Indent();
  8752. ImGui::TreePop();
  8753. }
  8754. if (ImGui::TreeNode("Vertical Sliders"))
  8755. {
  8756. ImGui::Unindent();
  8757. const float spacing = 4;
  8758. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(spacing, spacing));
  8759. static int int_value = 0;
  8760. ImGui::VSliderInt("##int", ImVec2(18,160), &int_value, 0, 5);
  8761. ImGui::SameLine();
  8762. static float values[7] = { 0.0f, 0.60f, 0.35f, 0.9f, 0.70f, 0.20f, 0.0f };
  8763. ImGui::PushID("set1");
  8764. for (int i = 0; i < 7; i++)
  8765. {
  8766. if (i > 0) ImGui::SameLine();
  8767. ImGui::PushID(i);
  8768. ImGui::PushStyleColor(ImGuiCol_FrameBg, ImColor::HSV(i/7.0f, 0.5f, 0.5f));
  8769. ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImColor::HSV(i/7.0f, 0.6f, 0.5f));
  8770. ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImColor::HSV(i/7.0f, 0.7f, 0.5f));
  8771. ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImColor::HSV(i/7.0f, 0.9f, 0.9f));
  8772. ImGui::VSliderFloat("##v", ImVec2(18,160), &values[i], 0.0f, 1.0f, "");
  8773. if (ImGui::IsItemActive() || ImGui::IsItemHovered())
  8774. ImGui::SetTooltip("%.3f", values[i]);
  8775. ImGui::PopStyleColor(4);
  8776. ImGui::PopID();
  8777. }
  8778. ImGui::PopID();
  8779. ImGui::SameLine();
  8780. ImGui::PushID("set2");
  8781. static float values2[4] = { 0.20f, 0.80f, 0.40f, 0.25f };
  8782. const int rows = 3;
  8783. const ImVec2 small_slider_size(18, (160.0f-(rows-1)*spacing)/rows);
  8784. for (int nx = 0; nx < 4; nx++)
  8785. {
  8786. if (nx > 0) ImGui::SameLine();
  8787. ImGui::BeginGroup();
  8788. for (int ny = 0; ny < rows; ny++)
  8789. {
  8790. ImGui::PushID(nx*rows+ny);
  8791. ImGui::VSliderFloat("##v", small_slider_size, &values2[nx], 0.0f, 1.0f, "");
  8792. if (ImGui::IsItemActive() || ImGui::IsItemHovered())
  8793. ImGui::SetTooltip("%.3f", values2[nx]);
  8794. ImGui::PopID();
  8795. }
  8796. ImGui::EndGroup();
  8797. }
  8798. ImGui::PopID();
  8799. ImGui::SameLine();
  8800. ImGui::PushID("set3");
  8801. for (int i = 0; i < 4; i++)
  8802. {
  8803. if (i > 0) ImGui::SameLine();
  8804. ImGui::PushID(i);
  8805. ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, 40);
  8806. ImGui::VSliderFloat("##v", ImVec2(40,160), &values[i], 0.0f, 1.0f, "%.2f");
  8807. ImGui::PopStyleVar();
  8808. ImGui::PopID();
  8809. }
  8810. ImGui::PopID();
  8811. ImGui::Indent();
  8812. ImGui::TreePop();
  8813. }
  8814. if (ImGui::TreeNode("Dragging"))
  8815. {
  8816. // You can use ImGui::GetItemActiveDragDelta() to query for the dragged amount on any widget.
  8817. static ImVec2 value_raw(0.0f, 0.0f);
  8818. static ImVec2 value_with_lock_threshold(0.0f, 0.0f);
  8819. ImGui::Button("Drag Me");
  8820. if (ImGui::IsItemActive())
  8821. {
  8822. value_raw = ImGui::GetMouseDragDelta(0, 0.0f);
  8823. value_with_lock_threshold = ImGui::GetMouseDragDelta(0);
  8824. //ImGui::SetTooltip("Delta: %.1f, %.1f", value.x, value.y);
  8825. // Draw a line between the button and the mouse cursor
  8826. ImDrawList* draw_list = ImGui::GetWindowDrawList();
  8827. draw_list->PushClipRectFullScreen();
  8828. draw_list->AddLine(ImGui::CalcItemRectClosestPoint(ImGui::GetIO().MousePos, true, -2.0f), ImGui::GetIO().MousePos, ImColor(ImGui::GetStyle().Colors[ImGuiCol_Button]), 4.0f);
  8829. draw_list->PopClipRect();
  8830. }
  8831. 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);
  8832. ImGui::TreePop();
  8833. }
  8834. }
  8835. if (ImGui::CollapsingHeader("Graphs widgets"))
  8836. {
  8837. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  8838. ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr));
  8839. static bool pause;
  8840. static ImVector<float> values; if (values.empty()) { values.resize(90); memset(&values.front(), 0, values.size()*sizeof(float)); }
  8841. static size_t values_offset = 0;
  8842. if (!pause)
  8843. {
  8844. // create dummy data at fixed 60 hz rate
  8845. static float refresh_time = -1.0f;
  8846. if (ImGui::GetTime() > refresh_time + 1.0f/60.0f)
  8847. {
  8848. refresh_time = ImGui::GetTime();
  8849. static float phase = 0.0f;
  8850. values[values_offset] = cosf(phase);
  8851. values_offset = (values_offset+1)%values.size();
  8852. phase += 0.10f*values_offset;
  8853. }
  8854. }
  8855. ImGui::PlotLines("##Graph", &values.front(), (int)values.size(), (int)values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80));
  8856. ImGui::SameLine(0, (int)ImGui::GetStyle().ItemInnerSpacing.x);
  8857. ImGui::BeginGroup();
  8858. ImGui::Text("Graph");
  8859. ImGui::Checkbox("pause", &pause);
  8860. ImGui::EndGroup();
  8861. ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,80));
  8862. }
  8863. if (ImGui::CollapsingHeader("Layout"))
  8864. {
  8865. if (ImGui::TreeNode("Widgets Alignment"))
  8866. {
  8867. static float f = 0.0f;
  8868. ImGui::Text("Fixed: 100 pixels");
  8869. ImGui::PushItemWidth(100);
  8870. ImGui::InputFloat("float##1", &f);
  8871. ImGui::PopItemWidth();
  8872. ImGui::Text("Proportional: 50%% of window width");
  8873. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
  8874. ImGui::InputFloat("float##2", &f);
  8875. ImGui::PopItemWidth();
  8876. ImGui::Text("Right-aligned: Leave 100 pixels for label");
  8877. ImGui::PushItemWidth(-100);
  8878. ImGui::InputFloat("float##3", &f);
  8879. ImGui::PopItemWidth();
  8880. ImGui::TreePop();
  8881. }
  8882. if (ImGui::TreeNode("Basic Horizontal Layout"))
  8883. {
  8884. ImGui::TextWrapped("(Use ImGui::SameLine() to keep adding items to the right of the preceeding item)");
  8885. // Text
  8886. ImGui::Text("Two items: Hello");
  8887. ImGui::SameLine();
  8888. ImGui::TextColored(ImVec4(1,1,0,1), "World");
  8889. // Adjust spacing
  8890. ImGui::Text("More spacing: Hello");
  8891. ImGui::SameLine(0, 20);
  8892. ImGui::TextColored(ImVec4(1,1,0,1), "World");
  8893. // Button
  8894. ImGui::AlignFirstTextHeightToWidgets();
  8895. ImGui::Text("Normal buttons"); ImGui::SameLine();
  8896. ImGui::Button("Banana"); ImGui::SameLine();
  8897. ImGui::Button("Apple"); ImGui::SameLine();
  8898. ImGui::Button("Corniflower");
  8899. // Button
  8900. ImGui::Text("Small buttons"); ImGui::SameLine();
  8901. ImGui::SmallButton("Like this one"); ImGui::SameLine();
  8902. ImGui::Text("can fit within a text block.");
  8903. // Aligned to arbitrary position. Easy/cheap column.
  8904. ImGui::Text("Aligned");
  8905. ImGui::SameLine(150); ImGui::Text("x=150");
  8906. ImGui::SameLine(300); ImGui::Text("x=300");
  8907. ImGui::Text("Aligned");
  8908. ImGui::SameLine(150); ImGui::SmallButton("x=150");
  8909. ImGui::SameLine(300); ImGui::SmallButton("x=300");
  8910. // Checkbox
  8911. static bool c1=false,c2=false,c3=false,c4=false;
  8912. ImGui::Checkbox("My", &c1); ImGui::SameLine();
  8913. ImGui::Checkbox("Tailor", &c2); ImGui::SameLine();
  8914. ImGui::Checkbox("Is", &c3); ImGui::SameLine();
  8915. ImGui::Checkbox("Rich", &c4);
  8916. // Various
  8917. static float f0=1.0f, f1=2.0f, f2=3.0f;
  8918. ImGui::PushItemWidth(80);
  8919. const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD" };
  8920. static int item = -1;
  8921. ImGui::Combo("Combo", &item, items, IM_ARRAYSIZE(items)); ImGui::SameLine();
  8922. ImGui::SliderFloat("X", &f0, 0.0f,5.0f); ImGui::SameLine();
  8923. ImGui::SliderFloat("Y", &f1, 0.0f,5.0f); ImGui::SameLine();
  8924. ImGui::SliderFloat("Z", &f2, 0.0f,5.0f);
  8925. ImGui::PopItemWidth();
  8926. ImGui::PushItemWidth(80);
  8927. ImGui::Text("Lists:");
  8928. static int selection[4] = { 0, 1, 2, 3 };
  8929. for (int i = 0; i < 4; i++)
  8930. {
  8931. if (i > 0) ImGui::SameLine();
  8932. ImGui::PushID(i);
  8933. ImGui::ListBox("", &selection[i], items, IM_ARRAYSIZE(items));
  8934. ImGui::PopID();
  8935. //if (ImGui::IsItemHovered()) ImGui::SetTooltip("ListBox %d hovered", i);
  8936. }
  8937. ImGui::PopItemWidth();
  8938. ImGui::TreePop();
  8939. }
  8940. if (ImGui::TreeNode("Groups"))
  8941. {
  8942. ImGui::TextWrapped("(Using ImGui::BeginGroup()/EndGroup() to layout items)");
  8943. ImVec2 size;
  8944. ImGui::BeginGroup();
  8945. {
  8946. ImGui::BeginGroup();
  8947. ImGui::Button("AAA");
  8948. ImGui::SameLine();
  8949. ImGui::Button("BBB");
  8950. ImGui::SameLine();
  8951. ImGui::BeginGroup();
  8952. ImGui::Button("CCC");
  8953. ImGui::Button("DDD");
  8954. ImGui::EndGroup();
  8955. if (ImGui::IsItemHovered())
  8956. ImGui::SetTooltip("Group hovered");
  8957. ImGui::SameLine();
  8958. ImGui::Button("EEE");
  8959. ImGui::EndGroup();
  8960. // Capture the group size and create widgets using the same size
  8961. size = ImGui::GetItemRectSize();
  8962. const float values[5] = { 0.5f, 0.20f, 0.80f, 0.60f, 0.25f };
  8963. ImGui::PlotHistogram("##values", values, IM_ARRAYSIZE(values), 0, NULL, 0.0f, 1.0f, size);
  8964. }
  8965. ImGui::Button("ACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y));
  8966. ImGui::SameLine();
  8967. ImGui::Button("REACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y));
  8968. ImGui::EndGroup();
  8969. ImGui::SameLine();
  8970. ImGui::Button("LEVERAGE\nBUZZWORD", size);
  8971. ImGui::SameLine();
  8972. ImGui::ListBoxHeader("List", size);
  8973. ImGui::Selectable("Selected", true);
  8974. ImGui::Selectable("Not Selected", false);
  8975. ImGui::ListBoxFooter();
  8976. ImGui::TreePop();
  8977. }
  8978. if (ImGui::TreeNode("Text Baseline Alignment"))
  8979. {
  8980. 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)");
  8981. ImGui::Text("One\nTwo\nThree"); ImGui::SameLine();
  8982. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  8983. ImGui::Text("Banana");
  8984. ImGui::Text("Banana"); ImGui::SameLine();
  8985. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  8986. ImGui::Text("One\nTwo\nThree");
  8987. ImGui::Button("HOP"); ImGui::SameLine();
  8988. ImGui::Text("Banana"); ImGui::SameLine();
  8989. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  8990. ImGui::Text("Banana");
  8991. ImGui::Button("HOP"); ImGui::SameLine();
  8992. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  8993. ImGui::Text("Banana");
  8994. ImGui::Button("TEST"); ImGui::SameLine();
  8995. ImGui::Text("TEST"); ImGui::SameLine();
  8996. ImGui::SmallButton("TEST");
  8997. ImGui::AlignFirstTextHeightToWidgets(); // If your line starts with text, call this to align it to upcoming widgets.
  8998. ImGui::Text("Text aligned to Widget"); ImGui::SameLine();
  8999. ImGui::Button("Widget"); ImGui::SameLine();
  9000. ImGui::Text("Widget"); ImGui::SameLine();
  9001. ImGui::SmallButton("Widget");
  9002. ImGui::TreePop();
  9003. }
  9004. }
  9005. if (ImGui::CollapsingHeader("Child regions"))
  9006. {
  9007. ImGui::Text("Without border");
  9008. static int line = 50;
  9009. bool goto_line = ImGui::Button("Goto");
  9010. ImGui::SameLine();
  9011. ImGui::PushItemWidth(100);
  9012. goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue);
  9013. ImGui::PopItemWidth();
  9014. ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowWidth() * 0.5f,300));
  9015. for (int i = 0; i < 100; i++)
  9016. {
  9017. ImGui::Text("%04d: scrollable region", i);
  9018. if (goto_line && line == i)
  9019. ImGui::SetScrollPosHere();
  9020. }
  9021. if (goto_line && line >= 100)
  9022. ImGui::SetScrollPosHere();
  9023. ImGui::EndChild();
  9024. ImGui::SameLine();
  9025. ImGui::PushStyleVar(ImGuiStyleVar_ChildWindowRounding, 5.0f);
  9026. ImGui::BeginChild("Sub2", ImVec2(0,300), true);
  9027. ImGui::Text("With border");
  9028. ImGui::Columns(2);
  9029. for (int i = 0; i < 100; i++)
  9030. {
  9031. if (i == 50)
  9032. ImGui::NextColumn();
  9033. char buf[32];
  9034. ImFormatString(buf, IM_ARRAYSIZE(buf), "%08x", i*5731);
  9035. ImGui::Button(buf);
  9036. }
  9037. ImGui::EndChild();
  9038. ImGui::PopStyleVar();
  9039. }
  9040. if (ImGui::CollapsingHeader("Columns"))
  9041. {
  9042. // Basic columns
  9043. ImGui::Text("Basic:");
  9044. ImGui::Columns(4, "mycolumns");
  9045. ImGui::Separator();
  9046. ImGui::Text("ID"); ImGui::NextColumn();
  9047. ImGui::Text("Name"); ImGui::NextColumn();
  9048. ImGui::Text("Path"); ImGui::NextColumn();
  9049. ImGui::Text("Flags"); ImGui::NextColumn();
  9050. ImGui::Separator();
  9051. const char* names[3] = { "Robert", "Stephanie", "C64" };
  9052. const char* paths[3] = { "/path/robert", "/path/stephanie", "/path/computer" };
  9053. for (int i = 0; i < 3; i++)
  9054. {
  9055. ImGui::Text("%04d", i); ImGui::NextColumn();
  9056. ImGui::Text(names[i]); ImGui::NextColumn();
  9057. ImGui::Text(paths[i]); ImGui::NextColumn();
  9058. ImGui::Text("...."); ImGui::NextColumn();
  9059. }
  9060. ImGui::Columns(1);
  9061. ImGui::Separator();
  9062. ImGui::Spacing();
  9063. // Scrolling columns
  9064. /*
  9065. ImGui::Text("Scrolling:");
  9066. ImGui::BeginChild("##header", ImVec2(0, ImGui::GetTextLineHeightWithSpacing()+ImGui::GetStyle().ItemSpacing.y));
  9067. ImGui::Columns(3);
  9068. ImGui::Text("ID"); ImGui::NextColumn();
  9069. ImGui::Text("Name"); ImGui::NextColumn();
  9070. ImGui::Text("Path"); ImGui::NextColumn();
  9071. ImGui::Columns(1);
  9072. ImGui::Separator();
  9073. ImGui::EndChild();
  9074. ImGui::BeginChild("##scrollingregion", ImVec2(0, 60));
  9075. ImGui::Columns(3);
  9076. for (int i = 0; i < 10; i++)
  9077. {
  9078. ImGui::Text("%04d", i); ImGui::NextColumn();
  9079. ImGui::Text("Foobar"); ImGui::NextColumn();
  9080. ImGui::Text("/path/foobar/%04d/", i); ImGui::NextColumn();
  9081. }
  9082. ImGui::Columns(1);
  9083. ImGui::EndChild();
  9084. ImGui::Separator();
  9085. ImGui::Spacing();
  9086. */
  9087. // Create multiple items in a same cell before switching to next column
  9088. ImGui::Text("Mixed items:");
  9089. ImGui::Columns(3, "mixed");
  9090. ImGui::Separator();
  9091. static int e = 0;
  9092. ImGui::Text("Hello");
  9093. ImGui::Button("Banana");
  9094. ImGui::RadioButton("radio a", &e, 0);
  9095. ImGui::NextColumn();
  9096. ImGui::Text("ImGui");
  9097. ImGui::Button("Apple");
  9098. ImGui::RadioButton("radio b", &e, 1);
  9099. static float foo = 1.0f;
  9100. ImGui::InputFloat("red", &foo, 0.05f, 0, 3);
  9101. ImGui::Text("An extra line here.");
  9102. ImGui::NextColumn();
  9103. ImGui::Text("World!");
  9104. ImGui::Button("Corniflower");
  9105. ImGui::RadioButton("radio c", &e, 2);
  9106. static float bar = 1.0f;
  9107. ImGui::InputFloat("blue", &bar, 0.05f, 0, 3);
  9108. ImGui::NextColumn();
  9109. if (ImGui::CollapsingHeader("Category A")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  9110. if (ImGui::CollapsingHeader("Category B")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  9111. if (ImGui::CollapsingHeader("Category C")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  9112. ImGui::Columns(1);
  9113. ImGui::Separator();
  9114. ImGui::Spacing();
  9115. // Tree items
  9116. ImGui::Text("Tree items:");
  9117. ImGui::Columns(2, "tree items");
  9118. ImGui::Separator();
  9119. if (ImGui::TreeNode("Hello")) { ImGui::BulletText("World"); ImGui::TreePop(); } ImGui::NextColumn();
  9120. if (ImGui::TreeNode("Bonjour")) { ImGui::BulletText("Monde"); ImGui::TreePop(); } ImGui::NextColumn();
  9121. ImGui::Columns(1);
  9122. ImGui::Separator();
  9123. ImGui::Spacing();
  9124. // Word-wrapping
  9125. ImGui::Text("Word-wrapping:");
  9126. ImGui::Columns(2, "word-wrapping");
  9127. ImGui::Separator();
  9128. ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
  9129. ImGui::Text("Hello Left");
  9130. ImGui::NextColumn();
  9131. ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
  9132. ImGui::Text("Hello Right");
  9133. ImGui::Columns(1);
  9134. ImGui::Separator();
  9135. ImGui::Spacing();
  9136. if (ImGui::TreeNode("Inside a tree.."))
  9137. {
  9138. if (ImGui::TreeNode("node 1 (with borders)"))
  9139. {
  9140. ImGui::Columns(4);
  9141. for (int i = 0; i < 8; i++)
  9142. {
  9143. ImGui::Text("%c%c%c", 'a'+i, 'a'+i, 'a'+i);
  9144. ImGui::NextColumn();
  9145. }
  9146. ImGui::Columns(1);
  9147. ImGui::TreePop();
  9148. }
  9149. if (ImGui::TreeNode("node 2 (without borders)"))
  9150. {
  9151. ImGui::Columns(4, NULL, false);
  9152. for (int i = 0; i < 8; i++)
  9153. {
  9154. ImGui::Text("%c%c%c", 'a'+i, 'a'+i, 'a'+i);
  9155. ImGui::NextColumn();
  9156. }
  9157. ImGui::Columns(1);
  9158. ImGui::TreePop();
  9159. }
  9160. ImGui::TreePop();
  9161. }
  9162. }
  9163. if (ImGui::CollapsingHeader("Filtering"))
  9164. {
  9165. static ImGuiTextFilter filter;
  9166. ImGui::Text("Filter usage:\n"
  9167. " \"\" display all lines\n"
  9168. " \"xxx\" display lines containing \"xxx\"\n"
  9169. " \"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n"
  9170. " \"-xxx\" hide lines containing \"xxx\"");
  9171. filter.Draw();
  9172. const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" };
  9173. for (size_t i = 0; i < IM_ARRAYSIZE(lines); i++)
  9174. if (filter.PassFilter(lines[i]))
  9175. ImGui::BulletText("%s", lines[i]);
  9176. }
  9177. if (ImGui::CollapsingHeader("Keyboard, Mouse & Focus"))
  9178. {
  9179. if (ImGui::TreeNode("Tabbing"))
  9180. {
  9181. ImGui::Text("Use TAB/SHIFT+TAB to cycle thru keyboard editable fields.");
  9182. static char buf[32] = "dummy";
  9183. ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
  9184. ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
  9185. ImGui::InputText("3", buf, IM_ARRAYSIZE(buf));
  9186. ImGui::PushAllowKeyboardFocus(false);
  9187. ImGui::InputText("4 (tab skip)", buf, IM_ARRAYSIZE(buf));
  9188. //ImGui::SameLine(); ImGui::Text("(?)"); if (ImGui::IsHovered()) ImGui::SetTooltip("Use ImGui::PushAllowKeyboardFocus(bool)\nto disable tabbing through certain widgets.");
  9189. ImGui::PopAllowKeyboardFocus();
  9190. ImGui::InputText("5", buf, IM_ARRAYSIZE(buf));
  9191. ImGui::TreePop();
  9192. }
  9193. if (ImGui::TreeNode("Focus from code"))
  9194. {
  9195. bool focus_1 = ImGui::Button("Focus on 1"); ImGui::SameLine();
  9196. bool focus_2 = ImGui::Button("Focus on 2"); ImGui::SameLine();
  9197. bool focus_3 = ImGui::Button("Focus on 3");
  9198. int has_focus = 0;
  9199. static char buf[128] = "click on a button to set focus";
  9200. if (focus_1) ImGui::SetKeyboardFocusHere();
  9201. ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
  9202. if (ImGui::IsItemActive()) has_focus = 1;
  9203. if (focus_2) ImGui::SetKeyboardFocusHere();
  9204. ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
  9205. if (ImGui::IsItemActive()) has_focus = 2;
  9206. ImGui::PushAllowKeyboardFocus(false);
  9207. if (focus_3) ImGui::SetKeyboardFocusHere();
  9208. ImGui::InputText("3 (tab skip)", buf, IM_ARRAYSIZE(buf));
  9209. if (ImGui::IsItemActive()) has_focus = 3;
  9210. ImGui::PopAllowKeyboardFocus();
  9211. if (has_focus)
  9212. ImGui::Text("Item with focus: %d", has_focus);
  9213. else
  9214. ImGui::Text("Item with focus: <none>");
  9215. ImGui::TextWrapped("Cursor & selection are preserved when refocusing last used item in code.");
  9216. ImGui::TreePop();
  9217. }
  9218. if (ImGui::TreeNode("Mouse cursors"))
  9219. {
  9220. 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)");
  9221. ImGui::Checkbox("io.MouseDrawCursor", &ImGui::GetIO().MouseDrawCursor);
  9222. ImGui::Text("Hover to see mouse cursors:");
  9223. for (int i = 0; i < ImGuiMouseCursor_Count_; i++)
  9224. {
  9225. char label[32];
  9226. sprintf(label, "Mouse cursor %d", i);
  9227. ImGui::Bullet(); ImGui::Selectable(label, false);
  9228. if (ImGui::IsItemHovered())
  9229. ImGui::SetMouseCursor(i);
  9230. }
  9231. ImGui::TreePop();
  9232. }
  9233. }
  9234. if (ImGui::CollapsingHeader("App Examples"))
  9235. {
  9236. ImGui::Checkbox("Metrics", &show_app_metrics);
  9237. ImGui::Checkbox("Console", &show_app_console);
  9238. ImGui::Checkbox("Long text display", &show_app_long_text);
  9239. ImGui::Checkbox("Auto-resizing window", &show_app_auto_resize);
  9240. ImGui::Checkbox("Simple overlay", &show_app_fixed_overlay);
  9241. ImGui::Checkbox("Manipulating window title", &show_app_manipulating_window_title);
  9242. ImGui::Checkbox("Custom rendering", &show_app_custom_rendering);
  9243. }
  9244. ImGui::End();
  9245. }
  9246. void ImGui::ShowMetricsWindow(bool* opened)
  9247. {
  9248. if (ImGui::Begin("ImGui Metrics", opened))
  9249. {
  9250. ImGui::Text("ImGui %s", ImGui::GetVersion());
  9251. ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  9252. ImGui::Text("%d vertices", ImGui::GetIO().MetricsRenderVertices);
  9253. ImGui::Separator();
  9254. struct Funcs
  9255. {
  9256. static void NodeDrawList(ImDrawList* draw_list, const char* label)
  9257. {
  9258. bool node_opened = ImGui::TreeNode(draw_list, "%s: %d vtx, %d cmds", label, draw_list->vtx_buffer.size(), draw_list->commands.size());
  9259. if (draw_list == ImGui::GetWindowDrawList())
  9260. {
  9261. ImGui::SameLine();
  9262. ImGui::TextColored(ImColor(255,100,100), "CURRENTLY APPENDING"); // Can't display stats for active draw list! (we don't have the data double-buffered)
  9263. }
  9264. if (!node_opened)
  9265. return;
  9266. for (const ImDrawCmd* pcmd = draw_list->commands.begin(); pcmd < draw_list->commands.end(); pcmd++)
  9267. if (pcmd->user_callback)
  9268. ImGui::BulletText("Callback %p, user_data %p", pcmd->user_callback, pcmd->user_callback_data);
  9269. else
  9270. ImGui::BulletText("Draw %d vtx, tex = %p", pcmd->vtx_count, pcmd->texture_id);
  9271. ImGui::TreePop();
  9272. }
  9273. static void NodeWindows(ImVector<ImGuiWindow*>& windows, const char* label)
  9274. {
  9275. if (!ImGui::TreeNode(label, "%s (%d)", label, (int)windows.size()))
  9276. return;
  9277. for (int i = 0; i < (int)windows.size(); i++)
  9278. Funcs::NodeWindow(windows[i], "Window");
  9279. ImGui::TreePop();
  9280. }
  9281. static void NodeWindow(ImGuiWindow* window, const char* label)
  9282. {
  9283. if (!ImGui::TreeNode(window, "%s '%s', %d @ 0x%p", label, window->Name, window->Visible, window))
  9284. return;
  9285. NodeDrawList(window->DrawList, "DrawList");
  9286. if (window->RootWindow != window) NodeWindow(window->RootWindow, "RootWindow");
  9287. if (window->DC.ChildWindows.size() > 0) NodeWindows(window->DC.ChildWindows, "ChildWindows");
  9288. ImGui::TreePop();
  9289. }
  9290. };
  9291. ImGuiState& g = *GImGui; // Access private state
  9292. g.DisableHideTextAfterDoubleHash++; // Not exposed (yet). Disable processing that hides text after '##' markers.
  9293. Funcs::NodeWindows(g.Windows, "Windows");
  9294. if (ImGui::TreeNode("DrawList", "Active DrawLists (%d)", (int)g.RenderDrawLists[0].size()))
  9295. {
  9296. for (int i = 0; i < (int)g.RenderDrawLists[0].size(); i++)
  9297. Funcs::NodeDrawList(g.RenderDrawLists[0][i], "DrawList");
  9298. ImGui::TreePop();
  9299. }
  9300. g.DisableHideTextAfterDoubleHash--;
  9301. }
  9302. ImGui::End();
  9303. }
  9304. static void ShowExampleAppAutoResize(bool* opened)
  9305. {
  9306. if (!ImGui::Begin("Example: Auto-Resizing Window", opened, ImGuiWindowFlags_AlwaysAutoResize))
  9307. {
  9308. ImGui::End();
  9309. return;
  9310. }
  9311. static int lines = 10;
  9312. 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.");
  9313. ImGui::SliderInt("Number of lines", &lines, 1, 20);
  9314. for (int i = 0; i < lines; i++)
  9315. ImGui::Text("%*sThis is line %d", i*4, "", i); // Pad with space to extend size horizontally
  9316. ImGui::End();
  9317. }
  9318. static void ShowExampleAppFixedOverlay(bool* opened)
  9319. {
  9320. ImGui::SetNextWindowPos(ImVec2(10,10));
  9321. if (!ImGui::Begin("Example: Fixed Overlay", opened, ImVec2(0,0), 0.3f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoSavedSettings))
  9322. {
  9323. ImGui::End();
  9324. return;
  9325. }
  9326. ImGui::Text("Simple overlay\non the top-left side of the screen.");
  9327. ImGui::Separator();
  9328. ImGui::Text("Mouse Position: (%.1f,%.1f)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
  9329. ImGui::End();
  9330. }
  9331. static void ShowExampleAppManipulatingWindowTitle(bool* opened)
  9332. {
  9333. (void)opened;
  9334. // By default, Windows are uniquely identified by their title.
  9335. // You can use the "##" and "###" markers to manipulate the display/ID. Read FAQ at the top of this file!
  9336. // Using "##" to display same title but have unique identifier.
  9337. ImGui::SetNextWindowPos(ImVec2(100,100), ImGuiSetCond_FirstUseEver);
  9338. ImGui::Begin("Same title as another window##1");
  9339. ImGui::Text("This is window 1.\nMy title is the same as window 2, but my identifier is unique.");
  9340. ImGui::End();
  9341. ImGui::SetNextWindowPos(ImVec2(100,200), ImGuiSetCond_FirstUseEver);
  9342. ImGui::Begin("Same title as another window##2");
  9343. ImGui::Text("This is window 2.\nMy title is the same as window 1, but my identifier is unique.");
  9344. ImGui::End();
  9345. // Using "###" to display a changing title but keep a static identifier "AnimatedTitle"
  9346. char buf[128];
  9347. ImFormatString(buf, IM_ARRAYSIZE(buf), "Animated title %c %d###AnimatedTitle", "|/-\\"[(int)(ImGui::GetTime()/0.25f)&3], rand());
  9348. ImGui::SetNextWindowPos(ImVec2(100,300), ImGuiSetCond_FirstUseEver);
  9349. ImGui::Begin(buf);
  9350. ImGui::Text("This window has a changing title.");
  9351. ImGui::End();
  9352. }
  9353. static void ShowExampleAppCustomRendering(bool* opened)
  9354. {
  9355. ImGui::SetNextWindowSize(ImVec2(300,350), ImGuiSetCond_FirstUseEver);
  9356. if (!ImGui::Begin("Example: Custom Rendering", opened))
  9357. {
  9358. ImGui::End();
  9359. return;
  9360. }
  9361. // Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of overloaded operators, etc.
  9362. // Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your types and ImVec2/ImVec4.
  9363. // ImGui defines overloaded operators but they are internal to imgui.cpp and not exposed outside (to avoid messing with your types)
  9364. // In this example we aren't using the operators.
  9365. static ImVector<ImVec2> points;
  9366. static bool adding_line = false;
  9367. if (ImGui::Button("Clear")) points.clear();
  9368. if (points.size() >= 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) { points.pop_back(); points.pop_back(); } }
  9369. ImGui::Text("Left-click and drag to add lines");
  9370. ImGui::Text("Right-click to undo");
  9371. ImDrawList* draw_list = ImGui::GetWindowDrawList();
  9372. // Here we are using InvisibleButton() as a convenience to 1) advance the cursor and 2) allows us to use IsItemHovered()
  9373. // However you can draw directly and poll mouse/keyboard by yourself. You can manipulate the cursor using GetCursorPos() and SetCursorPos().
  9374. // If you only use the ImDrawList API, you can notify the owner window of its extends by using SetCursorPos(max).
  9375. ImVec2 canvas_pos = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
  9376. 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
  9377. draw_list->AddRect(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), 0xFFFFFFFF);
  9378. bool adding_preview = false;
  9379. ImGui::InvisibleButton("canvas", canvas_size);
  9380. if (ImGui::IsItemHovered())
  9381. {
  9382. ImVec2 mouse_pos_in_canvas = ImVec2(ImGui::GetIO().MousePos.x - canvas_pos.x, ImGui::GetIO().MousePos.y - canvas_pos.y);
  9383. if (!adding_line && ImGui::GetIO().MouseClicked[0])
  9384. {
  9385. points.push_back(mouse_pos_in_canvas);
  9386. adding_line = true;
  9387. }
  9388. if (adding_line)
  9389. {
  9390. adding_preview = true;
  9391. points.push_back(mouse_pos_in_canvas);
  9392. if (!ImGui::GetIO().MouseDown[0])
  9393. adding_line = adding_preview = false;
  9394. }
  9395. if (ImGui::GetIO().MouseClicked[1] && !points.empty())
  9396. {
  9397. adding_line = false;
  9398. points.pop_back();
  9399. points.pop_back();
  9400. }
  9401. }
  9402. 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.)
  9403. for (int i = 0; i < (int)points.size() - 1; i += 2)
  9404. 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);
  9405. draw_list->PopClipRect();
  9406. if (adding_preview)
  9407. points.pop_back();
  9408. ImGui::End();
  9409. }
  9410. struct ExampleAppConsole
  9411. {
  9412. char InputBuf[256];
  9413. ImVector<char*> Items;
  9414. bool ScrollToBottom;
  9415. ImVector<char*> History;
  9416. int HistoryPos; // -1: new line, 0..History.size()-1 browsing history.
  9417. ImVector<const char*> Commands;
  9418. ExampleAppConsole()
  9419. {
  9420. ClearLog();
  9421. HistoryPos = -1;
  9422. Commands.push_back("HELP");
  9423. Commands.push_back("HISTORY");
  9424. Commands.push_back("CLEAR");
  9425. Commands.push_back("CLASSIFY"); // "classify" is here to provide an example of "C"+[tab] completing to "CL" and displaying matches.
  9426. }
  9427. ~ExampleAppConsole()
  9428. {
  9429. ClearLog();
  9430. for (size_t i = 0; i < Items.size(); i++)
  9431. ImGui::MemFree(History[i]);
  9432. }
  9433. void ClearLog()
  9434. {
  9435. for (size_t i = 0; i < Items.size(); i++)
  9436. ImGui::MemFree(Items[i]);
  9437. Items.clear();
  9438. ScrollToBottom = true;
  9439. }
  9440. void AddLog(const char* fmt, ...)
  9441. {
  9442. char buf[1024];
  9443. va_list args;
  9444. va_start(args, fmt);
  9445. ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  9446. va_end(args);
  9447. Items.push_back(ImStrdup(buf));
  9448. ScrollToBottom = true;
  9449. }
  9450. void Run(const char* title, bool* opened)
  9451. {
  9452. ImGui::SetNextWindowSize(ImVec2(520,600), ImGuiSetCond_FirstUseEver);
  9453. if (!ImGui::Begin(title, opened))
  9454. {
  9455. ImGui::End();
  9456. return;
  9457. }
  9458. 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.");
  9459. ImGui::TextWrapped("Enter 'HELP' for help, press TAB to use text completion.");
  9460. // TODO: display from bottom
  9461. // TODO: clip manually
  9462. if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.size()); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine();
  9463. if (ImGui::SmallButton("Add Dummy Error")) AddLog("[error] something went wrong"); ImGui::SameLine();
  9464. if (ImGui::SmallButton("Clear")) ClearLog();
  9465. //static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); }
  9466. ImGui::Separator();
  9467. ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
  9468. static ImGuiTextFilter filter;
  9469. filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
  9470. //if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover
  9471. ImGui::PopStyleVar();
  9472. ImGui::Separator();
  9473. // 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());
  9474. // 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.
  9475. // 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.
  9476. ImGui::BeginChild("ScrollingRegion", ImVec2(0,-ImGui::GetTextLineHeightWithSpacing()*2));
  9477. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing
  9478. for (size_t i = 0; i < Items.size(); i++)
  9479. {
  9480. const char* item = Items[i];
  9481. if (!filter.PassFilter(item))
  9482. continue;
  9483. ImVec4 col(1,1,1,1); // A better implement may store a type per-item. For the sample let's just parse the text.
  9484. if (strstr(item, "[error]")) col = ImVec4(1.0f,0.4f,0.4f,1.0f);
  9485. else if (strncmp(item, "# ", 2) == 0) col = ImVec4(1.0f,0.8f,0.6f,1.0f);
  9486. ImGui::PushStyleColor(ImGuiCol_Text, col);
  9487. ImGui::TextUnformatted(item);
  9488. ImGui::PopStyleColor();
  9489. }
  9490. if (ScrollToBottom)
  9491. ImGui::SetScrollPosHere();
  9492. ScrollToBottom = false;
  9493. ImGui::PopStyleVar();
  9494. ImGui::EndChild();
  9495. ImGui::Separator();
  9496. // Command-line
  9497. if (ImGui::InputText("Input", InputBuf, IM_ARRAYSIZE(InputBuf), ImGuiInputTextFlags_EnterReturnsTrue|ImGuiInputTextFlags_CallbackCompletion|ImGuiInputTextFlags_CallbackHistory, &TextEditCallbackStub, (void*)this))
  9498. {
  9499. char* input_end = InputBuf+strlen(InputBuf);
  9500. while (input_end > InputBuf && input_end[-1] == ' ') input_end--; *input_end = 0;
  9501. if (InputBuf[0])
  9502. ExecCommand(InputBuf);
  9503. strcpy(InputBuf, "");
  9504. }
  9505. // Demonstrate keeping auto focus on the input box
  9506. if (ImGui::IsItemHovered() || (ImGui::IsRootWindowOrAnyChildFocused() && !ImGui::IsAnyItemActive() && !ImGui::IsMouseClicked(0)))
  9507. ImGui::SetKeyboardFocusHere(-1); // Auto focus
  9508. ImGui::End();
  9509. }
  9510. void ExecCommand(const char* command_line)
  9511. {
  9512. AddLog("# %s\n", command_line);
  9513. // 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.
  9514. HistoryPos = -1;
  9515. for (int i = (int)History.size()-1; i >= 0; i--)
  9516. if (ImStricmp(History[i], command_line) == 0)
  9517. {
  9518. ImGui::MemFree(History[i]);
  9519. History.erase(History.begin() + i);
  9520. break;
  9521. }
  9522. History.push_back(ImStrdup(command_line));
  9523. // Process command
  9524. if (ImStricmp(command_line, "CLEAR") == 0)
  9525. {
  9526. ClearLog();
  9527. }
  9528. else if (ImStricmp(command_line, "HELP") == 0)
  9529. {
  9530. AddLog("Commands:");
  9531. for (size_t i = 0; i < Commands.size(); i++)
  9532. AddLog("- %s", Commands[i]);
  9533. }
  9534. else if (ImStricmp(command_line, "HISTORY") == 0)
  9535. {
  9536. for (size_t i = History.size() >= 10 ? History.size() - 10 : 0; i < History.size(); i++)
  9537. AddLog("%3d: %s\n", i, History[i]);
  9538. }
  9539. else
  9540. {
  9541. AddLog("Unknown command: '%s'\n", command_line);
  9542. }
  9543. }
  9544. static int TextEditCallbackStub(ImGuiTextEditCallbackData* data)
  9545. {
  9546. ExampleAppConsole* console = (ExampleAppConsole*)data->UserData;
  9547. return console->TextEditCallback(data);
  9548. }
  9549. int TextEditCallback(ImGuiTextEditCallbackData* data)
  9550. {
  9551. //AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
  9552. switch (data->EventFlag)
  9553. {
  9554. case ImGuiInputTextFlags_CallbackCompletion:
  9555. {
  9556. // Example of TEXT COMPLETION
  9557. // Locate beginning of current word
  9558. const char* word_end = data->Buf + data->CursorPos;
  9559. const char* word_start = word_end;
  9560. while (word_start > data->Buf)
  9561. {
  9562. const char c = word_start[-1];
  9563. if (ImCharIsSpace(c) || c == ',' || c == ';')
  9564. break;
  9565. word_start--;
  9566. }
  9567. // Build a list of candidates
  9568. ImVector<const char*> candidates;
  9569. for (size_t i = 0; i < Commands.size(); i++)
  9570. if (ImStrnicmp(Commands[i], word_start, (int)(word_end-word_start)) == 0)
  9571. candidates.push_back(Commands[i]);
  9572. if (candidates.size() == 0)
  9573. {
  9574. // No match
  9575. AddLog("No match for \"%.*s\"!\n", word_end-word_start, word_start);
  9576. }
  9577. else if (candidates.size() == 1)
  9578. {
  9579. // Single match. Delete the beginning of the word and replace it entirely so we've got nice casing
  9580. data->DeleteChars((int)(word_start-data->Buf), (int)(word_end-word_start));
  9581. data->InsertChars(data->CursorPos, candidates[0]);
  9582. data->InsertChars(data->CursorPos, " ");
  9583. }
  9584. else
  9585. {
  9586. // Multiple matches. Complete as much as we can, so inputing "C" will complete to "CL" and display "CLEAR" and "CLASSIFY"
  9587. int match_len = (int)(word_end - word_start);
  9588. for (;;)
  9589. {
  9590. int c = 0;
  9591. bool all_candidates_matches = true;
  9592. for (size_t i = 0; i < candidates.size() && all_candidates_matches; i++)
  9593. if (i == 0)
  9594. c = toupper(candidates[i][match_len]);
  9595. else if (c != toupper(candidates[i][match_len]))
  9596. all_candidates_matches = false;
  9597. if (!all_candidates_matches)
  9598. break;
  9599. match_len++;
  9600. }
  9601. if (match_len > 0)
  9602. {
  9603. data->DeleteChars((int)(word_start - data->Buf), (int)(word_end-word_start));
  9604. data->InsertChars(data->CursorPos, candidates[0], candidates[0] + match_len);
  9605. }
  9606. // List matches
  9607. AddLog("Possible matches:\n");
  9608. for (size_t i = 0; i < candidates.size(); i++)
  9609. AddLog("- %s\n", candidates[i]);
  9610. }
  9611. break;
  9612. }
  9613. case ImGuiInputTextFlags_CallbackHistory:
  9614. {
  9615. // Example of HISTORY
  9616. const int prev_history_pos = HistoryPos;
  9617. if (data->EventKey == ImGuiKey_UpArrow)
  9618. {
  9619. if (HistoryPos == -1)
  9620. HistoryPos = (int)(History.size() - 1);
  9621. else if (HistoryPos > 0)
  9622. HistoryPos--;
  9623. }
  9624. else if (data->EventKey == ImGuiKey_DownArrow)
  9625. {
  9626. if (HistoryPos != -1)
  9627. if (++HistoryPos >= (int)History.size())
  9628. HistoryPos = -1;
  9629. }
  9630. // A better implementation would preserve the data on the current input line along with cursor position.
  9631. if (prev_history_pos != HistoryPos)
  9632. {
  9633. ImFormatString(data->Buf, data->BufSize, "%s", (HistoryPos >= 0) ? History[HistoryPos] : "");
  9634. data->BufDirty = true;
  9635. data->CursorPos = data->SelectionStart = data->SelectionEnd = (int)strlen(data->Buf);
  9636. }
  9637. }
  9638. }
  9639. return 0;
  9640. }
  9641. };
  9642. static void ShowExampleAppConsole(bool* opened)
  9643. {
  9644. static ExampleAppConsole console;
  9645. console.Run("Example: Console", opened);
  9646. }
  9647. static void ShowExampleAppLongText(bool* opened)
  9648. {
  9649. ImGui::SetNextWindowSize(ImVec2(520,600), ImGuiSetCond_FirstUseEver);
  9650. if (!ImGui::Begin("Example: Long text display", opened))
  9651. {
  9652. ImGui::End();
  9653. return;
  9654. }
  9655. static int test_type = 0;
  9656. static ImGuiTextBuffer log;
  9657. static int lines = 0;
  9658. ImGui::Text("Printing unusually long amount of text.");
  9659. ImGui::Combo("Test type", &test_type, "Single call to TextUnformatted()\0Multiple calls to Text(), clipped manually\0Multiple calls to Text(), not clipped");
  9660. ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size());
  9661. if (ImGui::Button("Clear")) { log.clear(); lines = 0; }
  9662. ImGui::SameLine();
  9663. if (ImGui::Button("Add 1000 lines"))
  9664. {
  9665. for (int i = 0; i < 1000; i++)
  9666. log.append("%i The quick brown fox jumps over the lazy dog\n", lines+i);
  9667. lines += 1000;
  9668. }
  9669. ImGui::BeginChild("Log");
  9670. switch (test_type)
  9671. {
  9672. case 0:
  9673. // Single call to TextUnformatted() with a big buffer
  9674. ImGui::TextUnformatted(log.begin(), log.end());
  9675. break;
  9676. case 1:
  9677. // Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the CalcListClipping() helper.
  9678. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0,0));
  9679. int display_start, display_end;
  9680. ImGui::CalcListClipping(lines, ImGui::GetTextLineHeight(), &display_start, &display_end);
  9681. ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (display_start) * ImGui::GetTextLineHeight());
  9682. for (int i = display_start; i < display_end; i++)
  9683. ImGui::Text("%i The quick brown fox jumps over the lazy dog\n", i);
  9684. ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (lines - display_end) * ImGui::GetTextLineHeight());
  9685. ImGui::PopStyleVar();
  9686. break;
  9687. case 2:
  9688. // Multiple calls to Text(), not clipped
  9689. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0,0));
  9690. for (int i = 0; i < lines; i++)
  9691. ImGui::Text("%i The quick brown fox jumps over the lazy dog\n", i);
  9692. ImGui::PopStyleVar();
  9693. break;
  9694. }
  9695. ImGui::EndChild();
  9696. ImGui::End();
  9697. }
  9698. // End of Sample code
  9699. #endif
  9700. //-----------------------------------------------------------------------------
  9701. // FONT DATA
  9702. //-----------------------------------------------------------------------------
  9703. // Compressed with stb_compress() then converted to a C array.
  9704. // Use the program in extra_fonts/binary_to_compressed_c.cpp to create the array from a TTF file.
  9705. // Decompressor from stb.h (public domain) by Sean Barrett https://github.com/nothings/stb/blob/master/stb.h
  9706. //-----------------------------------------------------------------------------
  9707. static unsigned int stb_decompress_length(unsigned char *input)
  9708. {
  9709. return (input[8] << 24) + (input[9] << 16) + (input[10] << 8) + input[11];
  9710. }
  9711. static unsigned char *stb__barrier, *stb__barrier2, *stb__barrier3, *stb__barrier4;
  9712. static unsigned char *stb__dout;
  9713. static void stb__match(unsigned char *data, unsigned int length)
  9714. {
  9715. // INVERSE of memmove... write each byte before copying the next...
  9716. IM_ASSERT (stb__dout + length <= stb__barrier);
  9717. if (stb__dout + length > stb__barrier) { stb__dout += length; return; }
  9718. if (data < stb__barrier4) { stb__dout = stb__barrier+1; return; }
  9719. while (length--) *stb__dout++ = *data++;
  9720. }
  9721. static void stb__lit(unsigned char *data, unsigned int length)
  9722. {
  9723. IM_ASSERT (stb__dout + length <= stb__barrier);
  9724. if (stb__dout + length > stb__barrier) { stb__dout += length; return; }
  9725. if (data < stb__barrier2) { stb__dout = stb__barrier+1; return; }
  9726. memcpy(stb__dout, data, length);
  9727. stb__dout += length;
  9728. }
  9729. #define stb__in2(x) ((i[x] << 8) + i[(x)+1])
  9730. #define stb__in3(x) ((i[x] << 16) + stb__in2((x)+1))
  9731. #define stb__in4(x) ((i[x] << 24) + stb__in3((x)+1))
  9732. static unsigned char *stb_decompress_token(unsigned char *i)
  9733. {
  9734. if (*i >= 0x20) { // use fewer if's for cases that expand small
  9735. if (*i >= 0x80) stb__match(stb__dout-i[1]-1, i[0] - 0x80 + 1), i += 2;
  9736. else if (*i >= 0x40) stb__match(stb__dout-(stb__in2(0) - 0x4000 + 1), i[2]+1), i += 3;
  9737. else /* *i >= 0x20 */ stb__lit(i+1, i[0] - 0x20 + 1), i += 1 + (i[0] - 0x20 + 1);
  9738. } else { // more ifs for cases that expand large, since overhead is amortized
  9739. if (*i >= 0x18) stb__match(stb__dout-(stb__in3(0) - 0x180000 + 1), i[3]+1), i += 4;
  9740. else if (*i >= 0x10) stb__match(stb__dout-(stb__in3(0) - 0x100000 + 1), stb__in2(3)+1), i += 5;
  9741. else if (*i >= 0x08) stb__lit(i+2, stb__in2(0) - 0x0800 + 1), i += 2 + (stb__in2(0) - 0x0800 + 1);
  9742. else if (*i == 0x07) stb__lit(i+3, stb__in2(1) + 1), i += 3 + (stb__in2(1) + 1);
  9743. else if (*i == 0x06) stb__match(stb__dout-(stb__in3(1)+1), i[4]+1), i += 5;
  9744. else if (*i == 0x04) stb__match(stb__dout-(stb__in3(1)+1), stb__in2(4)+1), i += 6;
  9745. }
  9746. return i;
  9747. }
  9748. static unsigned int stb_adler32(unsigned int adler32, unsigned char *buffer, unsigned int buflen)
  9749. {
  9750. const unsigned long ADLER_MOD = 65521;
  9751. unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16;
  9752. unsigned long blocklen, i;
  9753. blocklen = buflen % 5552;
  9754. while (buflen) {
  9755. for (i=0; i + 7 < blocklen; i += 8) {
  9756. s1 += buffer[0], s2 += s1;
  9757. s1 += buffer[1], s2 += s1;
  9758. s1 += buffer[2], s2 += s1;
  9759. s1 += buffer[3], s2 += s1;
  9760. s1 += buffer[4], s2 += s1;
  9761. s1 += buffer[5], s2 += s1;
  9762. s1 += buffer[6], s2 += s1;
  9763. s1 += buffer[7], s2 += s1;
  9764. buffer += 8;
  9765. }
  9766. for (; i < blocklen; ++i)
  9767. s1 += *buffer++, s2 += s1;
  9768. s1 %= ADLER_MOD, s2 %= ADLER_MOD;
  9769. buflen -= blocklen;
  9770. blocklen = 5552;
  9771. }
  9772. return (unsigned int)(s2 << 16) + (unsigned int)s1;
  9773. }
  9774. static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length)
  9775. {
  9776. unsigned int olen;
  9777. if (stb__in4(0) != 0x57bC0000) return 0;
  9778. if (stb__in4(4) != 0) return 0; // error! stream is > 4GB
  9779. olen = stb_decompress_length(i);
  9780. stb__barrier2 = i;
  9781. stb__barrier3 = i+length;
  9782. stb__barrier = output + olen;
  9783. stb__barrier4 = output;
  9784. i += 16;
  9785. stb__dout = output;
  9786. for (;;) {
  9787. unsigned char *old_i = i;
  9788. i = stb_decompress_token(i);
  9789. if (i == old_i) {
  9790. if (*i == 0x05 && i[1] == 0xfa) {
  9791. IM_ASSERT(stb__dout == output + olen);
  9792. if (stb__dout != output + olen) return 0;
  9793. if (stb_adler32(1, output, olen) != (unsigned int) stb__in4(2))
  9794. return 0;
  9795. return olen;
  9796. } else {
  9797. IM_ASSERT(0); /* NOTREACHED */
  9798. return 0;
  9799. }
  9800. }
  9801. IM_ASSERT(stb__dout <= output + olen);
  9802. if (stb__dout > output + olen)
  9803. return 0;
  9804. }
  9805. }
  9806. //-----------------------------------------------------------------------------
  9807. // ProggyClean.ttf
  9808. // Copyright (c) 2004, 2005 Tristan Grimmer
  9809. // MIT license (see License.txt in http://www.upperbounds.net/download/ProggyClean.ttf.zip)
  9810. // Download and more information at http://upperbounds.net
  9811. //-----------------------------------------------------------------------------
  9812. static const unsigned int proggy_clean_ttf_compressed_size = 9583;
  9813. static const unsigned int proggy_clean_ttf_compressed_data[9584/4] =
  9814. {
  9815. 0x0000bc57, 0x00000000, 0xf8a00000, 0x00000400, 0x00010037, 0x000c0000, 0x00030080, 0x2f534f40, 0x74eb8832, 0x01000090, 0x2c158248, 0x616d634e,
  9816. 0x23120270, 0x03000075, 0x241382a0, 0x74766352, 0x82178220, 0xfc042102, 0x02380482, 0x66796c67, 0x5689af12, 0x04070000, 0x80920000, 0x64616568,
  9817. 0xd36691d7, 0xcc201b82, 0x36210382, 0x27108268, 0xc3014208, 0x04010000, 0x243b0f82, 0x78746d68, 0x807e008a, 0x98010000, 0x06020000, 0x61636f6c,
  9818. 0xd8b0738c, 0x82050000, 0x0402291e, 0x7078616d, 0xda00ae01, 0x28201f82, 0x202c1082, 0x656d616e, 0x96bb5925, 0x84990000, 0x9e2c1382, 0x74736f70,
  9819. 0xef83aca6, 0x249b0000, 0xd22c3382, 0x70657270, 0x12010269, 0xf4040000, 0x08202f82, 0x012ecb84, 0x553c0000, 0x0f5fd5e9, 0x0300f53c, 0x00830008,
  9820. 0x7767b722, 0x002b3f82, 0xa692bd00, 0xfe0000d7, 0x83800380, 0x21f1826f, 0x00850002, 0x41820120, 0x40fec026, 0x80030000, 0x05821083, 0x07830120,
  9821. 0x0221038a, 0x24118200, 0x90000101, 0x82798200, 0x00022617, 0x00400008, 0x2009820a, 0x82098276, 0x82002006, 0x9001213b, 0x0223c883, 0x828a02bc,
  9822. 0x858f2010, 0xc5012507, 0x00023200, 0x04210083, 0x91058309, 0x6c412b03, 0x40007374, 0xac200000, 0x00830008, 0x01000523, 0x834d8380, 0x80032103,
  9823. 0x012101bf, 0x23b88280, 0x00800000, 0x0b830382, 0x07820120, 0x83800021, 0x88012001, 0x84002009, 0x2005870f, 0x870d8301, 0x2023901b, 0x83199501,
  9824. 0x82002015, 0x84802000, 0x84238267, 0x88002027, 0x8561882d, 0x21058211, 0x13880000, 0x01800022, 0x05850d85, 0x0f828020, 0x03208384, 0x03200582,
  9825. 0x47901b84, 0x1b850020, 0x1f821d82, 0x3f831d88, 0x3f410383, 0x84058405, 0x210982cd, 0x09830000, 0x03207789, 0xf38a1384, 0x01203782, 0x13872384,
  9826. 0x0b88c983, 0x0d898f84, 0x00202982, 0x23900383, 0x87008021, 0x83df8301, 0x86118d03, 0x863f880d, 0x8f35880f, 0x2160820f, 0x04830300, 0x1c220382,
  9827. 0x05820100, 0x4c000022, 0x09831182, 0x04001c24, 0x11823000, 0x0800082e, 0x00000200, 0xff007f00, 0xffffac20, 0x00220982, 0x09848100, 0xdf216682,
  9828. 0x843586d5, 0x06012116, 0x04400684, 0xa58120d7, 0x00b127d8, 0x01b88d01, 0x2d8685ff, 0xc100c621, 0xf4be0801, 0x9e011c01, 0x88021402, 0x1403fc02,
  9829. 0x9c035803, 0x1404de03, 0x50043204, 0xa2046204, 0x66051605, 0x1206bc05, 0xd6067406, 0x7e073807, 0x4e08ec07, 0x96086c08, 0x1009d008, 0x88094a09,
  9830. 0x800a160a, 0x560b040b, 0x2e0cc80b, 0xea0c820c, 0xa40d5e0d, 0x500eea0d, 0x280f960e, 0x1210b00f, 0xe0107410, 0xb6115211, 0x6e120412, 0x4c13c412,
  9831. 0xf613ac13, 0xae145814, 0x4015ea14, 0xa6158015, 0x1216b815, 0xc6167e16, 0x8e173417, 0x5618e017, 0xee18ba18, 0x96193619, 0x481ad419, 0xf01a9c1a,
  9832. 0xc81b5c1b, 0x4c1c041c, 0xea1c961c, 0x921d2a1d, 0x401ed21d, 0xe01e8e1e, 0x761f241f, 0xa61fa61f, 0x01821020, 0x8a202e34, 0xc820b220, 0x74211421,
  9833. 0xee219821, 0x86226222, 0x01820c23, 0x83238021, 0x23983c01, 0x24d823b0, 0x244a2400, 0x24902468, 0x250625ae, 0x25822560, 0x26f825f8, 0x82aa2658,
  9834. 0xd8be0801, 0x9a274027, 0x68280a28, 0x0e29a828, 0xb8292029, 0x362af829, 0x602a602a, 0x2a2b022b, 0xac2b5e2b, 0x202ce62b, 0x9a2c342c, 0x5c2d282d,
  9835. 0xaa2d782d, 0x262ee82d, 0x262fa62e, 0xf42fb62f, 0xc8305e30, 0xb4313e31, 0x9e321e32, 0x82331e33, 0x5c34ee33, 0x3a35ce34, 0xd4358635, 0x72362636,
  9836. 0x7637e636, 0x3a38d837, 0x1239a638, 0xae397439, 0x9a3a2e3a, 0x7c3b063b, 0x3a3ce83b, 0x223d963c, 0xec3d863d, 0xc63e563e, 0x9a3f2a3f, 0x6a401240,
  9837. 0x3641d040, 0x0842a241, 0x7a424042, 0xf042b842, 0xcc436243, 0x8a442a44, 0x5845ee44, 0xe245b645, 0xb4465446, 0x7a471447, 0x5448da47, 0x4049c648,
  9838. 0x15462400, 0x034d0808, 0x0b000700, 0x13000f00, 0x1b001700, 0x23001f00, 0x2b002700, 0x33002f00, 0x3b003700, 0x43003f00, 0x4b004700, 0x53004f00,
  9839. 0x5b005700, 0x63005f00, 0x6b006700, 0x73006f00, 0x7b007700, 0x83007f00, 0x8b008700, 0x00008f00, 0x15333511, 0x20039631, 0x20178205, 0xd3038221,
  9840. 0x20739707, 0x25008580, 0x028080fc, 0x05be8080, 0x04204a85, 0x05ce0685, 0x0107002a, 0x02000080, 0x00000400, 0x250d8b41, 0x33350100, 0x03920715,
  9841. 0x13820320, 0x858d0120, 0x0e8d0320, 0xff260d83, 0x00808000, 0x54820106, 0x04800223, 0x845b8c80, 0x41332059, 0x078b068f, 0x82000121, 0x82fe2039,
  9842. 0x84802003, 0x83042004, 0x23598a0e, 0x00180000, 0x03210082, 0x42ab9080, 0x73942137, 0x2013bb41, 0x8f978205, 0x2027a39b, 0x20b68801, 0x84b286fd,
  9843. 0x91c88407, 0x41032011, 0x11a51130, 0x15000027, 0x80ff8000, 0x11af4103, 0x841b0341, 0x8bd983fd, 0x9be99bc9, 0x8343831b, 0x21f1821f, 0xb58300ff,
  9844. 0x0f84e889, 0xf78a0484, 0x8000ff22, 0x0020eeb3, 0x14200082, 0x2130ef41, 0xeb431300, 0x4133200a, 0xd7410ecb, 0x9a07200b, 0x2027871b, 0x21238221,
  9845. 0xe7828080, 0xe784fd20, 0xe8848020, 0xfe808022, 0x08880d85, 0xba41fd20, 0x82248205, 0x85eab02a, 0x008022e7, 0x2cd74200, 0x44010021, 0xd34406eb,
  9846. 0x44312013, 0xcf8b0eef, 0x0d422f8b, 0x82332007, 0x0001212f, 0x8023cf82, 0x83000180, 0x820583de, 0x830682d4, 0x820020d4, 0x82dc850a, 0x20e282e9,
  9847. 0xb2ff85fe, 0x010327e9, 0x02000380, 0x0f440400, 0x0c634407, 0x68825982, 0x85048021, 0x260a825d, 0x010b0000, 0x4400ff00, 0x2746103f, 0x08d74209,
  9848. 0x4d440720, 0x0eaf4406, 0xc3441d20, 0x23078406, 0xff800002, 0x04845b83, 0x8d05b241, 0x1781436f, 0x6b8c87a5, 0x1521878e, 0x06474505, 0x01210783,
  9849. 0x84688c00, 0x8904828e, 0x441e8cf7, 0x0b270cff, 0x80008000, 0x45030003, 0xfb430fab, 0x080f4107, 0x410bf942, 0xd34307e5, 0x070d4207, 0x80800123,
  9850. 0x205d85fe, 0x849183fe, 0x20128404, 0x82809702, 0x00002217, 0x41839a09, 0x6b4408cf, 0x0733440f, 0x3b460720, 0x82798707, 0x97802052, 0x0000296f,
  9851. 0xff800004, 0x01800100, 0x0021ef89, 0x0a914625, 0x410a4d41, 0x00250ed4, 0x00050000, 0x056d4280, 0x210a7b46, 0x21481300, 0x46ed8512, 0x00210bd1,
  9852. 0x89718202, 0x21738877, 0x2b850001, 0x00220582, 0x87450a00, 0x0ddb4606, 0x41079b42, 0x9d420c09, 0x0b09420b, 0x8d820720, 0x9742fc84, 0x42098909,
  9853. 0x00241e0f, 0x00800014, 0x0b47da82, 0x0833442a, 0x49078d41, 0x2f450f13, 0x42278f17, 0x01200751, 0x22063742, 0x44808001, 0x20450519, 0x88068906,
  9854. 0x83fe2019, 0x4203202a, 0x1a941a58, 0x00820020, 0xe7a40e20, 0x420ce146, 0x854307e9, 0x0fcb4713, 0xff20a182, 0xfe209b82, 0x0c867f8b, 0x0021aea4,
  9855. 0x219fa40f, 0x7d41003b, 0x07194214, 0xbf440520, 0x071d4206, 0x6941a590, 0x80802309, 0x028900ff, 0xa9a4b685, 0xc5808021, 0x449b82ab, 0x152007eb,
  9856. 0x42134d46, 0x61440a15, 0x051e4208, 0x222b0442, 0x47001100, 0xfd412913, 0x17194714, 0x410f5b41, 0x02220773, 0x09428080, 0x21a98208, 0xd4420001,
  9857. 0x481c840d, 0x00232bc9, 0x42120000, 0xe74c261b, 0x149d4405, 0x07209d87, 0x410db944, 0x14421c81, 0x42fd2005, 0x80410bd2, 0x203d8531, 0x06874100,
  9858. 0x48256f4a, 0xcb420c95, 0x13934113, 0x44075d44, 0x044c0855, 0x00ff2105, 0xfe228185, 0x45448000, 0x22c5b508, 0x410c0000, 0x7b412087, 0x1bb74514,
  9859. 0x32429c85, 0x0a574805, 0x21208943, 0x8ba01300, 0x440dfb4e, 0x77431437, 0x245b4113, 0x200fb145, 0x41108ffe, 0x80203562, 0x00200082, 0x46362b42,
  9860. 0x1742178d, 0x4527830f, 0x0f830b2f, 0x4a138146, 0x802409a1, 0xfe8000ff, 0x94419982, 0x09294320, 0x04000022, 0x49050f4f, 0xcb470a63, 0x48032008,
  9861. 0x2b48067b, 0x85022008, 0x82638338, 0x00002209, 0x05af4806, 0x900e9f49, 0x84c5873f, 0x214285bd, 0x064900ff, 0x0c894607, 0x00000023, 0x4903820a,
  9862. 0x714319f3, 0x0749410c, 0x8a07a145, 0x02152507, 0xfe808000, 0x74490386, 0x8080211b, 0x0c276f82, 0x00018000, 0x48028003, 0x2b2315db, 0x43002f00,
  9863. 0x6f82142f, 0x44011521, 0x93510da7, 0x20e68508, 0x06494d80, 0x8e838020, 0x06821286, 0x124bff20, 0x25f3830c, 0x03800080, 0xe74a0380, 0x207b8715,
  9864. 0x876b861d, 0x4a152007, 0x07870775, 0xf6876086, 0x8417674a, 0x0a0021f2, 0x431c9743, 0x8d421485, 0x200b830b, 0x06474d03, 0x71828020, 0x04510120,
  9865. 0x42da8606, 0x1f831882, 0x001a0022, 0xff4d0082, 0x0b0f532c, 0x0d449b94, 0x4e312007, 0x074f12e7, 0x0bf3490b, 0xbb412120, 0x413f820a, 0xef490857,
  9866. 0x80002313, 0xe2830001, 0x6441fc20, 0x8b802006, 0x00012108, 0xfd201582, 0x492c9b48, 0x802014ff, 0x51084347, 0x0f4327f3, 0x17bf4a14, 0x201b7944,
  9867. 0x06964201, 0x134ffe20, 0x20d6830b, 0x25d78280, 0xfd800002, 0x05888000, 0x9318dc41, 0x21d282d4, 0xdb481800, 0x0dff542a, 0x45107743, 0xe14813f5,
  9868. 0x0f034113, 0x83135d45, 0x47b28437, 0xe4510e73, 0x21f58e06, 0x2b8400fd, 0x1041fcac, 0x08db4b0b, 0x421fdb41, 0xdf4b18df, 0x011d210a, 0x420af350,
  9869. 0x6e8308af, 0xac85cb86, 0x1e461082, 0x82b7a407, 0x411420a3, 0xa34130ab, 0x178f4124, 0x41139741, 0x86410d93, 0x82118511, 0x057243d8, 0x8941d9a4,
  9870. 0x3093480c, 0x4a13474f, 0xfb5016a9, 0x07ad4108, 0x4a0f9d42, 0xfe200fad, 0x4708aa41, 0x83482dba, 0x288f4d06, 0xb398c3bb, 0x44267b41, 0xb34439d7,
  9871. 0x0755410f, 0x200ebb45, 0x0f5f4215, 0x20191343, 0x06df5301, 0xf04c0220, 0x2ba64d07, 0x82050841, 0x430020ce, 0xa78f3627, 0x5213ff42, 0x2f970bc1,
  9872. 0x4305ab55, 0xa084111b, 0x450bac45, 0x5f4238b8, 0x010c2106, 0x0220ed82, 0x441bb344, 0x875010af, 0x0737480f, 0x490c5747, 0x0c840c03, 0x4c204b42,
  9873. 0x8ba905d7, 0x8b948793, 0x510c0c51, 0xfb4b24b9, 0x1b174107, 0x5709d74c, 0xd1410ca5, 0x079d480f, 0x201ff541, 0x06804780, 0x7d520120, 0x80002205,
  9874. 0x20a983fe, 0x47bb83fe, 0x1b8409b4, 0x81580220, 0x4e00202c, 0x4f41282f, 0x0eab4f17, 0x57471520, 0x0e0f4808, 0x8221e041, 0x3e1b4a8b, 0x4407175d,
  9875. 0x1b4b071f, 0x4a0f8b07, 0x174a0703, 0x0ba5411b, 0x430fb141, 0x0120057b, 0xfc20dd82, 0x4a056047, 0xf4850c0c, 0x01221982, 0x02828000, 0x1a5d088b,
  9876. 0x20094108, 0x8c0e3941, 0x4900200e, 0x7744434f, 0x200b870b, 0x0e4b5a33, 0x2b41f78b, 0x8b138307, 0x0b9f450b, 0x2406f741, 0xfd808001, 0x09475a00,
  9877. 0x84000121, 0x5980200e, 0x85450e5d, 0x832c8206, 0x4106831e, 0x00213814, 0x28b34810, 0x410c2f4b, 0x5f4a13d7, 0x0b2b4113, 0x6e43a883, 0x11174b05,
  9878. 0x4b066a45, 0xcc470541, 0x5000202b, 0xcb472f4b, 0x44b59f0f, 0xc5430b5b, 0x0d654907, 0x21065544, 0xd6828080, 0xfe201982, 0x8230ec4a, 0x120025c2,
  9879. 0x80ff8000, 0x4128d74d, 0x3320408b, 0x410a9f50, 0xdb822793, 0x822bd454, 0x61134b2e, 0x410b214a, 0xad4117c9, 0x0001211f, 0x4206854f, 0x4b430596,
  9880. 0x06bb5530, 0x2025cf46, 0x0ddd5747, 0x500ea349, 0x0f840fa7, 0x5213c153, 0x634e08d1, 0x0bbe4809, 0x59316e4d, 0x5b50053f, 0x203f6323, 0x5117eb46,
  9881. 0x94450a63, 0x246e410a, 0x63410020, 0x0bdb5f2f, 0x4233ab44, 0x39480757, 0x112d4a07, 0x7241118f, 0x000e2132, 0x9f286f41, 0x0f8762c3, 0x33350723,
  9882. 0x094e6415, 0x2010925f, 0x067252fe, 0xd0438020, 0x63a68225, 0x11203a4f, 0x480e6360, 0x5748131f, 0x079b521f, 0x200e2f43, 0x864b8315, 0x113348e7,
  9883. 0x85084e48, 0x06855008, 0x5880fd21, 0x7c420925, 0x0c414824, 0x37470c86, 0x1b8b422b, 0x5b0a8755, 0x23410c21, 0x0b83420b, 0x5a082047, 0xf482067f,
  9884. 0xa80b4c47, 0x0c0021cf, 0x20207b42, 0x0fb74100, 0x420b8744, 0xeb43076f, 0x0f6f420b, 0x4261fe20, 0x439aa00c, 0x215034e3, 0x0ff9570f, 0x4b1f2d5d,
  9885. 0x2d5d0c6f, 0x09634d0b, 0x1f51b8a0, 0x620f200c, 0xaf681e87, 0x24f94d07, 0x4e0f4945, 0xfe200c05, 0x22139742, 0x57048080, 0x23950c20, 0x97601585,
  9886. 0x4813201f, 0xad620523, 0x200f8f0f, 0x9e638f15, 0x00002181, 0x41342341, 0x0f930f0b, 0x210b4b62, 0x978f0001, 0xfe200f84, 0x8425c863, 0x2704822b,
  9887. 0x80000a00, 0x00038001, 0x610e9768, 0x834514bb, 0x0bc3430f, 0x2107e357, 0x80848080, 0x4400fe21, 0x2e410983, 0x00002a1a, 0x00000700, 0x800380ff,
  9888. 0x0fdf5800, 0x59150021, 0xd142163d, 0x0c02410c, 0x01020025, 0x65800300, 0x00240853, 0x1d333501, 0x15220382, 0x35420001, 0x44002008, 0x376406d7,
  9889. 0x096f6b19, 0x480bc142, 0x8f4908a7, 0x211f8b1f, 0x9e830001, 0x0584fe20, 0x4180fd21, 0x11850910, 0x8d198259, 0x000021d4, 0x5a08275d, 0x275d1983,
  9890. 0x06d9420e, 0x9f08b36a, 0x0f7d47b5, 0x8d8a2f8b, 0x4c0e0b57, 0xe7410e17, 0x42d18c1a, 0xb351087a, 0x1ac36505, 0x4b4a2f20, 0x0b9f450d, 0x430beb53,
  9891. 0xa7881015, 0xa5826a83, 0x80200f82, 0x86185a65, 0x4100208e, 0x176c3367, 0x0fe7650b, 0x4a17ad4b, 0x0f4217ed, 0x112e4206, 0x41113a42, 0xf7423169,
  9892. 0x0cb34737, 0x560f8b46, 0xa75407e5, 0x5f01200f, 0x31590c48, 0x80802106, 0x42268841, 0x0020091e, 0x4207ef64, 0x69461df7, 0x138d4114, 0x820f5145,
  9893. 0x53802090, 0xff200529, 0xb944b183, 0x417e8505, 0x00202561, 0x15210082, 0x42378200, 0x9b431cc3, 0x004f220d, 0x0dd54253, 0x4213f149, 0x7d41133b,
  9894. 0x42c9870b, 0x802010f9, 0x420b2c42, 0x8f441138, 0x267c4408, 0x600cb743, 0x8f4109d3, 0x05ab701d, 0x83440020, 0x3521223f, 0x0b794733, 0xfb62fe20,
  9895. 0x4afd2010, 0xaf410ae7, 0x25ce8525, 0x01080000, 0x7b6b0000, 0x0973710b, 0x82010021, 0x49038375, 0x33420767, 0x052c4212, 0x58464b85, 0x41fe2005,
  9896. 0x50440c27, 0x000c2209, 0x1cb36b80, 0x9b06df44, 0x0f93566f, 0x52830220, 0xfe216e8d, 0x200f8200, 0x0fb86704, 0xb057238d, 0x050b5305, 0x7217eb47,
  9897. 0xbd410b6b, 0x0f214610, 0x871f9956, 0x1e91567e, 0x2029b741, 0x20008200, 0x18b7410a, 0x27002322, 0x41095543, 0x0f8f0fb3, 0x41000121, 0x889d111c,
  9898. 0x14207b82, 0x00200382, 0x73188761, 0x475013a7, 0x6e33200c, 0x234e0ea3, 0x9b138313, 0x08e54d17, 0x9711094e, 0x2ee74311, 0x4908875e, 0xd75d1f1f,
  9899. 0x19ab5238, 0xa2084d48, 0x63a7a9b3, 0x55450b83, 0x0fd74213, 0x440d814c, 0x4f481673, 0x05714323, 0x13000022, 0x412e1f46, 0xdf493459, 0x21c7550f,
  9900. 0x8408215f, 0x201d49cb, 0xb1103043, 0x0f0d65d7, 0x452b8d41, 0x594b0f8d, 0x0b004605, 0xb215eb46, 0x000a24d7, 0x47000080, 0x002118cf, 0x06436413,
  9901. 0x420bd750, 0x2b500743, 0x076a470c, 0x4105c050, 0xd942053f, 0x0d00211a, 0x5f44779c, 0x0ce94805, 0x51558186, 0x14a54c0b, 0x49082b41, 0x0a4b0888,
  9902. 0x8080261f, 0x0d000000, 0x20048201, 0x1deb6a03, 0x420cb372, 0x07201783, 0x4306854d, 0x8b830c59, 0x59093c74, 0x0020250f, 0x67070f4a, 0x2341160b,
  9903. 0x00372105, 0x431c515d, 0x554e17ef, 0x0e5d6b05, 0x41115442, 0xb74a1ac1, 0x2243420a, 0x5b4f878f, 0x7507200f, 0x384b086f, 0x09d45409, 0x0020869a,
  9904. 0x12200082, 0xab460382, 0x10075329, 0x54138346, 0xaf540fbf, 0x1ea75413, 0x9a0c9e54, 0x0f6b44c1, 0x41000021, 0x47412a4f, 0x07374907, 0x5310bf76,
  9905. 0xff2009b4, 0x9a09a64c, 0x8200208d, 0x34c34500, 0x970fe141, 0x1fd74b0f, 0x440a3850, 0x206411f0, 0x27934609, 0x470c5d41, 0x555c2947, 0x1787540f,
  9906. 0x6e0f234e, 0x7d540a1b, 0x1d736b08, 0x0026a088, 0x80000e00, 0x9b5200ff, 0x08ef4318, 0x450bff77, 0x1d4d0b83, 0x081f7006, 0xcb691b86, 0x4b022008,
  9907. 0xc34b0b33, 0x1d0d4a0c, 0x8025a188, 0x0b000000, 0x52a38201, 0xbf7d0873, 0x0c234511, 0x8f0f894a, 0x4101200f, 0x0c880c9d, 0x2b418ea1, 0x06c74128,
  9908. 0x66181341, 0x7b4c0bb9, 0x0c06630b, 0xfe200c87, 0x9ba10882, 0x27091765, 0x01000008, 0x02800380, 0x48113f4e, 0x29430cf5, 0x09a75a0b, 0x31618020,
  9909. 0x6d802009, 0x61840e33, 0x8208bf51, 0x0c637d61, 0x7f092379, 0x4f470f4b, 0x1797510c, 0x46076157, 0xf5500fdf, 0x0f616910, 0x1171fe20, 0x82802006,
  9910. 0x08696908, 0x41127a4c, 0x3f4a15f3, 0x01042607, 0x0200ff00, 0x1cf77700, 0xff204185, 0x00235b8d, 0x43100000, 0x3b22243f, 0x3b4d3f00, 0x0b937709,
  9911. 0xad42f18f, 0x0b1f420f, 0x51084b43, 0x8020104a, 0xb557ff83, 0x052b7f2a, 0x0280ff22, 0x250beb78, 0x00170013, 0xbf6d2500, 0x07db760e, 0x410e2b7f,
  9912. 0x00230e4f, 0x49030000, 0x0582055b, 0x07000326, 0x00000b00, 0x580bcd46, 0x00200cdd, 0x57078749, 0x8749160f, 0x0f994f0a, 0x41134761, 0x01200b31,
  9913. 0xeb796883, 0x0b41500b, 0x0e90b38e, 0x202e7b51, 0x05d95801, 0x41080570, 0x1d530fc9, 0x0b937a0f, 0xaf8eb387, 0xf743b98f, 0x07c74227, 0x80000523,
  9914. 0x0fcb4503, 0x430ca37b, 0x7782077f, 0x8d0a9947, 0x08af4666, 0xeb798020, 0x6459881e, 0xc3740bbf, 0x0feb6f0b, 0x20072748, 0x052b6102, 0x435e0584,
  9915. 0x7d088308, 0x03200afd, 0x92109e41, 0x28aa8210, 0x80001500, 0x80030000, 0x0fdb5805, 0x209f4018, 0xa7418d87, 0x0aa3440f, 0x20314961, 0x073a52ff,
  9916. 0x6108505d, 0x43181051, 0x00223457, 0xe7820500, 0x50028021, 0x81410d33, 0x063d7108, 0xdb41af84, 0x4d888205, 0x00201198, 0x463d835f, 0x152106d7,
  9917. 0x0a355a33, 0x6917614e, 0x75411f4d, 0x184b8b07, 0x1809c344, 0x21091640, 0x0b828000, 0x42808021, 0x26790519, 0x86058605, 0x2428422d, 0x22123b42,
  9918. 0x42000080, 0xf587513b, 0x7813677b, 0xaf4d139f, 0x00ff210c, 0x5e0a1d57, 0x3b421546, 0x01032736, 0x02000380, 0x41180480, 0x2f420f07, 0x0c624807,
  9919. 0x00000025, 0x18000103, 0x83153741, 0x430120c3, 0x042106b2, 0x088d4d00, 0x2f830620, 0x1810434a, 0x18140345, 0x8507fb41, 0x5ee582ea, 0x0023116c,
  9920. 0x8d000600, 0x053b56af, 0xa6554fa2, 0x0d704608, 0x40180d20, 0x47181a43, 0xd37b07ff, 0x0b79500c, 0x420fd745, 0x47450bd9, 0x8471830a, 0x095a777e,
  9921. 0x84137542, 0x82002013, 0x2f401800, 0x0007213b, 0x4405e349, 0x0d550ff3, 0x16254c0c, 0x820ffe4a, 0x0400218a, 0x89066f41, 0x106b414f, 0xc84d0120,
  9922. 0x80802206, 0x0c9a4b03, 0x00100025, 0x68000200, 0x9d8c2473, 0x44134344, 0xf36a0f33, 0x4678860f, 0x1b440a25, 0x41988c0a, 0x80201879, 0x43079b5e,
  9923. 0x4a18080b, 0x0341190b, 0x1259530c, 0x43251552, 0x908205c8, 0x0cac4018, 0x86000421, 0x0e504aa2, 0x0020b891, 0xfb450082, 0x51132014, 0x8f5205f3,
  9924. 0x35052108, 0x8505cb59, 0x0f6d4f70, 0x82150021, 0x29af5047, 0x4f004b24, 0x75795300, 0x1b595709, 0x460b6742, 0xbf4b0f0d, 0x5743870b, 0xcb6d1461,
  9925. 0x08f64505, 0x4e05ab6c, 0x334126c3, 0x0bcb6b0d, 0x1811034d, 0x4111ef4b, 0x814f1ce5, 0x20af8227, 0x07fd7b80, 0x41188e84, 0xef410f33, 0x80802429,
  9926. 0x410d0000, 0xa34205ab, 0x76b7881c, 0xff500b89, 0x0741430f, 0x20086f4a, 0x209d8200, 0x234c18fd, 0x05d4670a, 0x4509af51, 0x9642078d, 0x189e831d,
  9927. 0x7c1cc74b, 0xcd4c07b9, 0x0e7c440f, 0x8b7b0320, 0x21108210, 0xc76c8080, 0x03002106, 0x6b23bf41, 0xc549060b, 0x7946180b, 0x0ff7530f, 0x17ad4618,
  9928. 0x200ecd45, 0x208c83fd, 0x5e0488fe, 0x032009c6, 0x420d044e, 0x0d8f0d7f, 0x00820020, 0x18001021, 0x6d273b45, 0xfd4c0c93, 0xcf451813, 0x0fe5450f,
  9929. 0x5a47c382, 0x820a8b0a, 0x282b4998, 0x410a8b5b, 0x4b232583, 0x54004f00, 0x978f0ce3, 0x500f1944, 0xa95f1709, 0x0280220b, 0x05ba7080, 0xa1530682,
  9930. 0x06324c13, 0x91412582, 0x05536e2c, 0x63431020, 0x0f434706, 0x8c11374c, 0x176143d7, 0x4d0f454c, 0xd3680bed, 0x0bee4d17, 0x212b9a41, 0x0f530a00,
  9931. 0x140d531c, 0x43139143, 0x95610e8d, 0x0f094415, 0x4205fb56, 0x1b4205cf, 0x17015225, 0x5e0c477f, 0xaf6e0aeb, 0x0ff36218, 0x04849a84, 0x0a454218,
  9932. 0x9c430420, 0x23c6822b, 0x04000102, 0x45091b4b, 0xf05f0955, 0x82802007, 0x421c2023, 0x5218282b, 0x7b53173f, 0x0fe7480c, 0x74173b7f, 0x47751317,
  9933. 0x634d1807, 0x0f6f430f, 0x24086547, 0xfc808002, 0x0b3c7f80, 0x10840120, 0x188d1282, 0x20096b43, 0x0fc24403, 0x00260faf, 0x0180000b, 0x3f500280,
  9934. 0x18002019, 0x450b4941, 0xf3530fb9, 0x18002010, 0x8208a551, 0x06234d56, 0xcb58a39b, 0xc3421805, 0x1313461e, 0x0f855018, 0xd34b0120, 0x6cfe2008,
  9935. 0x574f0885, 0x09204114, 0x07000029, 0x00008000, 0x44028002, 0x01420f57, 0x10c95c10, 0x11184c18, 0x80221185, 0x7f421e00, 0x00732240, 0x09cd4977,
  9936. 0x6d0b2b42, 0x4f180f8f, 0x8f5a0bcb, 0x9b0f830f, 0x0fb9411f, 0x230b5756, 0x00fd8080, 0x82060745, 0x000121d5, 0x8e0fb277, 0x4a8d4211, 0x24061c53,
  9937. 0x04000007, 0x12275280, 0x430c954c, 0x80201545, 0x200f764f, 0x20008200, 0x20ce8308, 0x09534f02, 0x660edf64, 0x73731771, 0xe7411807, 0x20a2820c,
  9938. 0x13b64404, 0x8f5d6682, 0x1d6b4508, 0x0cff4d18, 0x3348c58f, 0x0fc34c07, 0x31558b84, 0x8398820f, 0x17514712, 0x240b0e46, 0x80000a00, 0x093b4502,
  9939. 0x420f9759, 0xa54c0bf1, 0x0f2b470c, 0x410d314b, 0x2584170c, 0x73b30020, 0xb55fe782, 0x204d8410, 0x08e043fe, 0x4f147e41, 0x022008ab, 0x4b055159,
  9940. 0x2950068f, 0x00022208, 0x48511880, 0x82002009, 0x00112300, 0x634dff00, 0x24415f27, 0x180f6d43, 0x4d0b5d45, 0x4d5f05ef, 0x01802317, 0x56188000,
  9941. 0xa7840807, 0xc6450220, 0x21ca8229, 0x4b781a00, 0x3359182c, 0x0cf3470f, 0x180bef46, 0x420b0354, 0xff470b07, 0x4515200a, 0x9758239b, 0x4a80200c,
  9942. 0xd2410a26, 0x05fb4a08, 0x4b05e241, 0x03200dc9, 0x92290941, 0x00002829, 0x00010900, 0x5b020001, 0x23201363, 0x460d776a, 0xef530fdb, 0x209a890c,
  9943. 0x13fc4302, 0x00008024, 0xc4820104, 0x08820220, 0x20086b5b, 0x18518700, 0x8408d349, 0x0da449a1, 0x00080024, 0x7b690280, 0x4c438b1a, 0x01220f63,
  9944. 0x4c878000, 0x5c149c53, 0xfb430868, 0x2f56181e, 0x0ccf7b1b, 0x0f075618, 0x2008e347, 0x14144104, 0x00207f83, 0x00207b82, 0x201adf47, 0x16c35a13,
  9945. 0x540fdf47, 0x802006c8, 0x5418f185, 0x29430995, 0x00002419, 0x58001600, 0x5720316f, 0x4d051542, 0x4b7b1b03, 0x138f4707, 0xb747b787, 0x4aab8213,
  9946. 0x058305fc, 0x20115759, 0x82128401, 0x0a0b44e8, 0x46800121, 0xe64210d0, 0x82129312, 0x4bffdffe, 0x3b41171b, 0x9b27870f, 0x808022ff, 0x085c68fe,
  9947. 0x41800021, 0x01410b20, 0x001a213a, 0x47480082, 0x11374e12, 0x56130b4c, 0xdf4b0c65, 0x0b0f590b, 0x0f574c18, 0x830feb4b, 0x075f480f, 0x480b4755,
  9948. 0x40490b73, 0x80012206, 0x09d74280, 0x80fe8022, 0x80210e86, 0x056643ff, 0x10820020, 0x420b2646, 0x0b58391a, 0xd74c1808, 0x078b4e22, 0x2007f55f,
  9949. 0x4b491807, 0x83802017, 0x65aa82a7, 0x3152099e, 0x068b7616, 0x9b431220, 0x09bb742c, 0x500e376c, 0x8342179b, 0x0a4d5d0f, 0x8020a883, 0x180cd349,
  9950. 0x2016bb4b, 0x14476004, 0x84136c43, 0x08cf7813, 0x4f4c0520, 0x156f420f, 0x20085f42, 0x6fd3be03, 0xd4d30803, 0xa7411420, 0x004b222c, 0x0d3b614f,
  9951. 0x3f702120, 0x1393410a, 0x8f132745, 0x47421827, 0x41e08209, 0xb05e2bb9, 0x18b7410c, 0x18082647, 0x4107a748, 0xeb8826bf, 0x0ca76018, 0x733ecb41,
  9952. 0xd0410d83, 0x43ebaf2a, 0x0420067f, 0x721dab4c, 0x472005bb, 0x4105d341, 0x334844cb, 0x20dba408, 0x47d6ac00, 0x034e3aef, 0x0f8f421b, 0x930f134d,
  9953. 0x3521231f, 0xb7421533, 0x42f5ad0a, 0x1e961eaa, 0x17000022, 0x4c367b50, 0x7d491001, 0x0bf5520f, 0x4c18fda7, 0xb8460c55, 0x83fe2005, 0x00fe25b9,
  9954. 0x80000180, 0x9e751085, 0x261b5c12, 0x82110341, 0x001123fb, 0x4518fe80, 0xf38c2753, 0x6d134979, 0x295107a7, 0xaf5f180f, 0x0fe3660c, 0x180b6079,
  9955. 0x2007bd5f, 0x9aab9103, 0x2f4d1811, 0x05002109, 0x44254746, 0x1d200787, 0x450bab75, 0x4f180f57, 0x4f181361, 0x3b831795, 0xeb4b0120, 0x0b734805,
  9956. 0x84078f48, 0x2e1b47bc, 0x00203383, 0xaf065f45, 0x831520d7, 0x130f51a7, 0x1797bf97, 0x2b47d783, 0x18fe2005, 0x4a18a44f, 0xa64d086d, 0x1ab0410d,
  9957. 0x6205a258, 0xdbab069f, 0x4f06f778, 0xa963081d, 0x133b670a, 0x8323d141, 0x13195b23, 0x530f5e70, 0xe5ad0824, 0x58001421, 0x1f472b4b, 0x47bf410c,
  9958. 0x82000121, 0x83fe20cb, 0x07424404, 0x68068243, 0xd7ad0d3d, 0x00010d26, 0x80020000, 0x4a1c6f43, 0x23681081, 0x10a14f13, 0x8a070e57, 0x430a848f,
  9959. 0x7372243e, 0x4397a205, 0xb56c1021, 0x43978f0f, 0x64180505, 0x99aa0ff2, 0x0e000022, 0x20223341, 0x094b4f37, 0x074a3320, 0x2639410a, 0xfe208e84,
  9960. 0x8b0e0048, 0x508020a3, 0x9e4308fe, 0x073f4115, 0xe3480420, 0x0c9b5f1b, 0x7c137743, 0x9a95185b, 0x6122b148, 0x979b08df, 0x0fe36c18, 0x48109358,
  9961. 0x23441375, 0x0ffd5c0b, 0x180fc746, 0x2011d157, 0x07e95702, 0x58180120, 0x18770ac3, 0x51032008, 0x7d4118e3, 0x80802315, 0x3b4c1900, 0xbb5a1830,
  9962. 0x0ceb6109, 0x5b0b3d42, 0x4f181369, 0x4f180b8d, 0x4f180f75, 0x355a1b81, 0x200d820d, 0x18e483fd, 0x4528854f, 0x89420846, 0x1321411f, 0x44086b60,
  9963. 0x07421d77, 0x107d4405, 0x4113fd41, 0x5a181bf1, 0x4f180db3, 0x8021128f, 0x20f68280, 0x44a882fe, 0x334d249a, 0x052f6109, 0x1520c3a7, 0xef4eb783,
  9964. 0x4ec39b1b, 0xc4c90ee7, 0x20060b4d, 0x256f4905, 0x4d0cf761, 0xcf9b1f13, 0xa213d74e, 0x0e1145d4, 0x50135b42, 0xcb4e398f, 0x20d79f27, 0x08865d80,
  9965. 0x186d5018, 0xa90f7142, 0x067342d7, 0x3f450420, 0x65002021, 0xe3560771, 0x24d38f23, 0x15333531, 0x0eb94d01, 0x451c9f41, 0x384322fb, 0x00092108,
  9966. 0x19af6b18, 0x6e0c6f5a, 0xbd770bfb, 0x22bb7718, 0x20090f57, 0x25e74204, 0x4207275a, 0xdb5408ef, 0x1769450f, 0x1b1b5518, 0x210b1f57, 0x5e4c8001,
  9967. 0x55012006, 0x802107f1, 0x0a306a80, 0x45808021, 0x0d850b88, 0x31744f18, 0x1808ec54, 0x2009575b, 0x45ffa505, 0x1b420c73, 0x180f9f0f, 0x4a0cf748,
  9968. 0x501805b2, 0x00210f40, 0x4d118f80, 0xd6823359, 0x072b5118, 0x314ad7aa, 0x8fc79f08, 0x45d78b1f, 0xfe20058f, 0x23325118, 0x7b54d9b5, 0x9fc38f46,
  9969. 0x10bb410f, 0x41077b42, 0xc1410faf, 0x27cf441d, 0x46051b4f, 0x04200683, 0x2121d344, 0x8f530043, 0x8fcf9f0e, 0x21df8c1f, 0x50188000, 0x5d180e52,
  9970. 0xfd201710, 0x4405c341, 0xd68528e3, 0x20071f6b, 0x1b734305, 0x6b080957, 0x7d422b1f, 0x67002006, 0x7f8317b1, 0x2024cb48, 0x08676e00, 0x8749a39b,
  9971. 0x18132006, 0x410a6370, 0x8f490b47, 0x7e1f8f13, 0x551805c3, 0x4c180915, 0xfe200e2f, 0x244d5d18, 0x270bcf44, 0xff000019, 0x04800380, 0x5f253342,
  9972. 0xff520df7, 0x13274c18, 0x5542dd93, 0x0776181b, 0xf94a1808, 0x084a4c0c, 0x4308ea5b, 0xde831150, 0x7900fd21, 0x00492c1e, 0x060f4510, 0x17410020,
  9973. 0x0ce74526, 0x6206b341, 0x1f561083, 0x9d6c181b, 0x08a0500e, 0x112e4118, 0x60000421, 0xbf901202, 0x4408e241, 0xc7ab0513, 0xb40f0950, 0x055943c7,
  9974. 0x4f18ff20, 0xc9ae1cad, 0x32b34f18, 0x7a180120, 0x3d520a05, 0x53d1b40a, 0x80200813, 0x1b815018, 0x832bf86f, 0x67731847, 0x297f4308, 0x6418d54e,
  9975. 0x734213f7, 0x056b4b27, 0xdba5fe20, 0x1828aa4e, 0x2031a370, 0x06cb6101, 0x2040ad41, 0x07365300, 0x2558d985, 0x83fe200c, 0x0380211c, 0x542c4743,
  9976. 0x052006b7, 0x6021df45, 0x897b0707, 0x18d3c010, 0x20090e70, 0x1d5843ff, 0x540a0e44, 0x002126c5, 0x322f7416, 0x636a5720, 0x0f317409, 0x610fe159,
  9977. 0x294617e7, 0x08555213, 0x2006a75d, 0x6cec84fd, 0xfb5907be, 0x3a317405, 0x83808021, 0x180f20ea, 0x4626434a, 0x531818e3, 0xdb59172d, 0x0cbb460c,
  9978. 0x2013d859, 0x18b94502, 0x8f46188d, 0x77521842, 0x0a184e38, 0x9585fd20, 0x6a180684, 0xc64507e9, 0x51cbb230, 0xd3440cf3, 0x17ff6a0f, 0x450f5b42,
  9979. 0x276407c1, 0x4853180a, 0x21ccb010, 0xcf580013, 0x0c15442d, 0x410a1144, 0x1144359d, 0x5cfe2006, 0xa1410a43, 0x2bb64519, 0x2f5b7618, 0xb512b745,
  9980. 0x0cfd6fd1, 0x42089f59, 0xb8450c70, 0x0000232d, 0x50180900, 0xb9491ae3, 0x0fc37610, 0x01210f83, 0x0f3b4100, 0xa01b2742, 0x0ccd426f, 0x6e8f6f94,
  9981. 0x9c808021, 0xc7511870, 0x17c74b08, 0x9b147542, 0x44fe2079, 0xd5480c7e, 0x95ef861d, 0x101b597b, 0xf5417594, 0x9f471808, 0x86868d0e, 0x3733491c,
  9982. 0x690f4d6d, 0x43440b83, 0x1ba94c0b, 0x660cd16b, 0x802008ae, 0x74126448, 0xcb4f38a3, 0x2cb74b0b, 0x47137755, 0xe3971777, 0x1b5d0120, 0x057a4108,
  9983. 0x6e08664d, 0x17421478, 0x11af4208, 0x850c3f42, 0x08234f0c, 0x4321eb4a, 0xf3451095, 0x0f394e0f, 0x4310eb45, 0xc09707b1, 0x54431782, 0xaec08d1d,
  9984. 0x0f434dbb, 0x9f0c0b45, 0x0a3b4dbb, 0x4618bdc7, 0x536032eb, 0x17354213, 0x4d134169, 0xc7a30c2f, 0x4e254342, 0x174332cf, 0x43cdae17, 0x6b4706e4,
  9985. 0x0e16430d, 0x530b5542, 0x2f7c26bb, 0x13075f31, 0x43175342, 0x60181317, 0x6550114e, 0x28624710, 0x58070021, 0x59181683, 0x2d540cf5, 0x05d5660c,
  9986. 0x20090c7b, 0x0e157e02, 0x8000ff2b, 0x14000080, 0x80ff8000, 0x27137e03, 0x336a4b20, 0x0f817107, 0x13876e18, 0x730f2f7e, 0x2f450b75, 0x6d02200b,
  9987. 0x6d66094c, 0x4b802009, 0x15820a02, 0x2f45fe20, 0x5e032006, 0x00202fd9, 0x450af741, 0xeb412e0f, 0x0ff3411f, 0x420a8b65, 0xf7410eae, 0x1c664810,
  9988. 0x540e1145, 0xbfa509f3, 0x42302f58, 0x80200c35, 0xcb066c47, 0x4b1120c1, 0x41492abb, 0x34854110, 0xa7097b72, 0x251545c7, 0x4b2c7f56, 0xc5b40bab,
  9989. 0x940cd54e, 0x2e6151c8, 0x09f35f18, 0x4b420420, 0x09677121, 0x8f24f357, 0x1b5418e1, 0x08915a1f, 0x3143d894, 0x22541805, 0x1b9b4b0e, 0x8c0d3443,
  9990. 0x1400240d, 0x18ff8000, 0x582e6387, 0xf99b2b3b, 0x8807a550, 0x17a14790, 0x2184fd20, 0x5758fe20, 0x2354882c, 0x15000080, 0x5e056751, 0x334c2c2f,
  9991. 0x97c58f0c, 0x1fd7410f, 0x0d4d4018, 0x4114dc41, 0x04470ed6, 0x0dd54128, 0x00820020, 0x02011523, 0x22008700, 0x86480024, 0x0001240a, 0x8682001a,
  9992. 0x0002240b, 0x866c000e, 0x8a03200b, 0x8a042017, 0x0005220b, 0x22218614, 0x84060000, 0x86012017, 0x8212200f, 0x250b8519, 0x000d0001, 0x0b850031,
  9993. 0x07000224, 0x0b862600, 0x11000324, 0x0b862d00, 0x238a0420, 0x0a000524, 0x17863e00, 0x17840620, 0x01000324, 0x57820904, 0x0b85a783, 0x0b85a785,
  9994. 0x0b85a785, 0x22000325, 0x85007a00, 0x85a7850b, 0x85a7850b, 0x22a7850b, 0x82300032, 0x00342201, 0x0805862f, 0x35003131, 0x54207962, 0x74736972,
  9995. 0x47206e61, 0x6d6d6972, 0x65527265, 0x616c7567, 0x58545472, 0x6f725020, 0x43796767, 0x6e61656c, 0x30325454, 0x822f3430, 0x35313502, 0x79006200,
  9996. 0x54002000, 0x69007200, 0x74007300, 0x6e006100, 0x47200f82, 0x6d240f84, 0x65006d00, 0x52200982, 0x67240582, 0x6c007500, 0x72201d82, 0x54222b82,
  9997. 0x23825800, 0x19825020, 0x67006f22, 0x79220182, 0x1b824300, 0x3b846520, 0x1f825420, 0x41000021, 0x1422099b, 0x0b410000, 0x87088206, 0x01012102,
  9998. 0x78080982, 0x01020101, 0x01040103, 0x01060105, 0x01080107, 0x010a0109, 0x010c010b, 0x010e010d, 0x0110010f, 0x01120111, 0x01140113, 0x01160115,
  9999. 0x01180117, 0x011a0119, 0x011c011b, 0x011e011d, 0x0020011f, 0x00040003, 0x00060005, 0x00080007, 0x000a0009, 0x000c000b, 0x000e000d, 0x0010000f,
  10000. 0x00120011, 0x00140013, 0x00160015, 0x00180017, 0x001a0019, 0x001c001b, 0x001e001d, 0x08bb821f, 0x22002142, 0x24002300, 0x26002500, 0x28002700,
  10001. 0x2a002900, 0x2c002b00, 0x2e002d00, 0x30002f00, 0x32003100, 0x34003300, 0x36003500, 0x38003700, 0x3a003900, 0x3c003b00, 0x3e003d00, 0x40003f00,
  10002. 0x42004100, 0x4b09f382, 0x00450044, 0x00470046, 0x00490048, 0x004b004a, 0x004d004c, 0x004f004e, 0x00510050, 0x00530052, 0x00550054, 0x00570056,
  10003. 0x00590058, 0x005b005a, 0x005d005c, 0x005f005e, 0x01610060, 0x01220121, 0x01240123, 0x01260125, 0x01280127, 0x012a0129, 0x012c012b, 0x012e012d,
  10004. 0x0130012f, 0x01320131, 0x01340133, 0x01360135, 0x01380137, 0x013a0139, 0x013c013b, 0x013e013d, 0x0140013f, 0x00ac0041, 0x008400a3, 0x00bd0085,
  10005. 0x00e80096, 0x008e0086, 0x009d008b, 0x00a400a9, 0x008a00ef, 0x008300da, 0x00f20093, 0x008d00f3, 0x00880097, 0x00de00c3, 0x009e00f1, 0x00f500aa,
  10006. 0x00f600f4, 0x00ad00a2, 0x00c700c9, 0x006200ae, 0x00900063, 0x00cb0064, 0x00c80065, 0x00cf00ca, 0x00cd00cc, 0x00e900ce, 0x00d30066, 0x00d100d0,
  10007. 0x006700af, 0x009100f0, 0x00d400d6, 0x006800d5, 0x00ed00eb, 0x006a0089, 0x006b0069, 0x006c006d, 0x00a0006e, 0x0071006f, 0x00720070, 0x00750073,
  10008. 0x00760074, 0x00ea0077, 0x007a0078, 0x007b0079, 0x007c007d, 0x00a100b8, 0x007e007f, 0x00810080, 0x00ee00ec, 0x6e750eba, 0x646f6369, 0x78302365,
  10009. 0x31303030, 0x32200e8d, 0x33200e8d, 0x34200e8d, 0x35200e8d, 0x36200e8d, 0x37200e8d, 0x38200e8d, 0x39200e8d, 0x61200e8d, 0x62200e8d, 0x63200e8d,
  10010. 0x64200e8d, 0x65200e8d, 0x66200e8d, 0x31210e8c, 0x8d0e8d30, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef,
  10011. 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x66312def, 0x6c656406, 0x04657465, 0x6f727545, 0x3820ec8c, 0x3820ec8d,
  10012. 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d,
  10013. 0x3820ec8d, 0x200ddc41, 0x0ddc4139, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920,
  10014. 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0x00663923, 0x48fa0500, 0x00f762f9,
  10015. };
  10016. static void GetDefaultCompressedFontDataTTF(const void** ttf_compressed_data, unsigned int* ttf_compressed_size)
  10017. {
  10018. *ttf_compressed_data = proggy_clean_ttf_compressed_data;
  10019. *ttf_compressed_size = proggy_clean_ttf_compressed_size;
  10020. }
  10021. //-----------------------------------------------------------------------------
  10022. //---- Include imgui_user.inl at the end of imgui.cpp
  10023. //---- So you can include code that extends ImGui using its private data/functions.
  10024. #ifdef IMGUI_INCLUDE_IMGUI_USER_INL
  10025. #include "imgui_user.inl"
  10026. #endif
  10027. //-----------------------------------------------------------------------------