Open Source Tomb Raider Engine
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

imgui.cpp 298KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557
  1. // ImGui library v1.18 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 contributors.
  6. /*
  7. Index
  8. - MISSION STATEMENT
  9. - END-USER GUIDE
  10. - PROGRAMMER GUIDE
  11. - API BREAKING CHANGES
  12. - TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS
  13. - ISSUES & TODO-LIST
  14. - CODE
  15. - SAMPLE CODE
  16. - FONT DATA
  17. MISSION STATEMENT
  18. =================
  19. - easy to use to create code-driven and data-driven tools
  20. - easy to use to create ad hoc short-lived tools and long-lived, more elaborate tools
  21. - easy to hack and improve
  22. - minimize screen real-estate usage
  23. - minimize setup and maintenance
  24. - minimize state storage on user side
  25. - portable, minimize dependencies, run on target (consoles, etc.)
  26. - 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)
  27. - read about immediate-mode GUI principles @ http://mollyrocket.com/861, http://mollyrocket.com/forums/index.html
  28. Designed for developers and content-creators, not the typical end-user! Some of the weaknesses includes:
  29. - doesn't look fancy, doesn't animate
  30. - limited layout features, intricate layouts are typically crafted in code
  31. - occasionally use statically sized buffers for string manipulations - won't crash, but some long text may be clipped
  32. END-USER GUIDE
  33. ==============
  34. - double-click title bar to collapse window
  35. - click upper right corner to close a window, available when 'bool* open' is passed to ImGui::Begin()
  36. - click and drag on lower right corner to resize window
  37. - click and drag on any empty space to move window
  38. - double-click/double-tap on lower right corner grip to auto-fit to content
  39. - TAB/SHIFT+TAB to cycle through keyboard editable fields
  40. - use mouse wheel to scroll
  41. - use CTRL+mouse wheel to zoom window contents (if IO.FontAllowScaling is true)
  42. - CTRL+Click on a slider to input value as text
  43. - text editor:
  44. - Hold SHIFT or use mouse to select text.
  45. - CTRL+Left/Right to word jump
  46. - CTRL+Shift+Left/Right to select words
  47. - CTRL+A our Double-Click to select all
  48. - CTRL+X,CTRL+C,CTRL+V to use OS clipboard
  49. - CTRL+Z,CTRL+Y to undo/redo
  50. - ESCAPE to revert text to its original value
  51. - You can apply arithmetic operators +,*,/ on numerical values. Use +- to subtract (because - would set a negative value!)
  52. PROGRAMMER GUIDE
  53. ================
  54. - your code creates the UI, if your code doesn't run the UI is gone! == dynamic UI, no construction step, less data retention on your side, no state duplication, less sync, less errors.
  55. - see ImGui::ShowTestWindow() for user-side sample code
  56. - see examples/ folder for standalone sample applications.
  57. - getting started:
  58. - initialisation: call ImGui::GetIO() and fill the 'Settings' data.
  59. - every frame:
  60. 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().
  61. 2/ use any ImGui function you want between NewFrame() and Render()
  62. 3/ ImGui::Render() to render all the accumulated command-lists. it will call your RenderDrawListFn handler that you set in the IO structure.
  63. - all rendering information are stored into command-lists until ImGui::Render() is called.
  64. - effectively it means you can create widgets at any time in your code, regardless of "update" vs "render" considerations.
  65. - refer to the examples applications in the examples/ folder for instruction on how to setup your code.
  66. - a typical application skeleton may be:
  67. // Application init
  68. // TODO: Fill all settings fields of the io structure
  69. ImGuiIO& io = ImGui::GetIO();
  70. io.DisplaySize.x = 1920.0f;
  71. io.DisplaySize.y = 1280.0f;
  72. io.DeltaTime = 1.0f/60.0f;
  73. io.IniFilename = "imgui.ini";
  74. // Application main loop
  75. while (true)
  76. {
  77. // 1/ get low-level input
  78. // e.g. on Win32, GetKeyboardState(), or poll your events, etc.
  79. // 2/ TODO: Fill all 'Input' fields of io structure and call NewFrame
  80. ImGuiIO& io = ImGui::GetIO();
  81. io.MousePos = ...
  82. io.KeysDown[i] = ...
  83. ImGui::NewFrame();
  84. // 3/ most of your application code here - you can use any of ImGui::* functions between NewFrame() and Render() calls
  85. GameUpdate();
  86. GameRender();
  87. // 4/ render & swap video buffers
  88. ImGui::Render();
  89. // swap video buffer, etc.
  90. }
  91. API BREAKING CHANGES
  92. ====================
  93. Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix.
  94. 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.
  95. - 2014/11/28 (1.17) moved IO.Font*** options to inside the IO.Font-> structure.
  96. - 2014/11/26 (1.17) reworked syntax of IMGUI_ONCE_UPON_A_FRAME helper macro to increase compiler compatibility
  97. - 2014/11/07 (1.15) renamed IsHovered() to IsItemHovered()
  98. - 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)
  99. - 2014/09/25 (1.13) removed 'text_end' parameter from IO.SetClipboardTextFn (the string is now always zero-terminated for simplicity)
  100. - 2014/09/24 (1.12) renamed SetFontScale() to SetWindowFontScale()
  101. - 2014/09/24 (1.12) moved IM_MALLOC/IM_REALLOC/IM_FREE preprocessor defines to IO.MemAllocFn/IO.MemReallocFn/IO.MemFreeFn
  102. - 2014/08/30 (1.09) removed IO.FontHeight (now computed automatically)
  103. - 2014/08/30 (1.09) moved IMGUI_FONT_TEX_UV_FOR_WHITE preprocessor define to IO.FontTexUvForWhite
  104. - 2014/08/28 (1.09) changed the behavior of IO.PixelCenterOffset following various rendering fixes
  105. TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS
  106. ============================================
  107. If text or lines are blurry when integrating ImGui in your engine:
  108. - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
  109. - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f
  110. If you are confused about the meaning or use of ID in ImGui:
  111. - some widgets requires state to be carried over multiple frames (most typically ImGui often wants remember what is the "active" widget).
  112. to do so they need an unique ID. unique ID are typically derived from a string label, an indice or a pointer.
  113. when you call Button("OK") the button shows "OK" and also use "OK" as an ID.
  114. - ID are uniquely scoped within Windows so no conflict can happen if you have two buttons called "OK" in two different Windows.
  115. within a same Window, use PushID() / PopID() to easily create scopes and avoid ID conflicts.
  116. so if you have a loop creating "multiple" items, you can use PushID() / PopID() with the index of each item, or their pointer, etc.
  117. some functions like TreeNode() implicitly creates a scope for you by calling PushID()
  118. - when dealing with trees, ID are important because you want to preserve the opened/closed state of tree nodes.
  119. depending on your use cases you may want to use strings, indices or pointers as ID. experiment and see what makes more sense!
  120. e.g. When displaying a single object, using a static string as ID will preserve your node open/closed state when the targeted object change
  121. e.g. When displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state per object
  122. - when passing a label you can optionally specify extra unique ID information within the same string using "##". This helps solving the simpler collision cases.
  123. e.g. "Label" display "Label" and uses "Label" as ID
  124. e.g. "Label##Foobar" display "Label" and uses "Label##Foobar" as ID
  125. e.g. "##Foobar" display an empty label and uses "##Foobar" as ID
  126. - read articles about the imgui principles (see web links) to understand the requirement and use of ID.
  127. If you want to use a different font than the default:
  128. - read extra_fonts/README.txt for instructions. Examples fonts are also provided.
  129. - if you can only see text but no solid shapes or lines, make sure io.Font->TexUvForWhite is set to the texture coordinates of a pure white pixel in your texture!
  130. If you want to input Japanese/Chinese/Korean in the text input widget:
  131. - make sure you are using a font that can display the glyphs you want (see above paragraph about fonts)
  132. - to have the Microsoft IME cursor appears at the right location in the screen, setup a handler for the io.ImeSetInputScreenPosFn function:
  133. #include <Windows.h>
  134. #include <Imm.h>
  135. static void ImImpl_ImeSetInputScreenPosFn(int x, int y)
  136. {
  137. // Notify OS Input Method Editor of text input position
  138. HWND hwnd = glfwGetWin32Window(window);
  139. if (HIMC himc = ImmGetContext(hwnd))
  140. {
  141. COMPOSITIONFORM cf;
  142. cf.ptCurrentPos.x = x;
  143. cf.ptCurrentPos.y = y;
  144. cf.dwStyle = CFS_FORCE_POSITION;
  145. ImmSetCompositionWindow(himc, &cf);
  146. }
  147. }
  148. // Set pointer to handler in ImGuiIO structure
  149. io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn;
  150. - tip: the construct 'IMGUI_ONCE_UPON_A_FRAME { ... }' will evaluate to a 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.
  151. - tip: you can call Render() multiple times (e.g for VR renders), up to you to communicate the extra state to your RenderDrawListFn function.
  152. - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug"
  153. - tip: read the ShowTestWindow() code for more example of how to use ImGui!
  154. ISSUES & TODO-LIST
  155. ==================
  156. - misc: merge or clarify ImVec4 / ImGuiAabb, they are essentially duplicate containers
  157. - window: autofit is losing its purpose when user relies on any dynamic layout (window width multiplier, column). maybe just clearly discard autofit?
  158. - window: add horizontal scroll
  159. - window: fix resize grip rendering scaling along with Rounding style setting
  160. - window: better helpers to set pos/size/collapsed with different options (first-run, session only, current value) (github issue #89)
  161. - widgets: switching from "widget-label" to "label-widget" would make it more convenient to integrate widgets in trees
  162. - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay
  163. - main: make IsHovered() 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
  164. - main: make IsHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode?
  165. - scrollbar: use relative mouse movement when first-clicking inside of scroll grab box.
  166. - scrollbar: make the grab visible and a minimum size for long scroll regions
  167. - input number: optional range min/max
  168. - input number: holding [-]/[+] buttons should increase the step non-linearly
  169. - input number: use mouse wheel to step up/down
  170. - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 horrible layout code. item width should include frame padding, then we can have a generic horizontal layout helper.
  171. - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills)
  172. - columns: columns header to act as button (~sort op) and allow resize/reorder
  173. - columns: user specify columns size
  174. - combo: turn child handling code into pop up helper
  175. - list selection, concept of a selectable "block" (that can be multiple widgets)
  176. - menubar, menus
  177. - plot: make it easier for user to draw into the graph (e.g: draw basis, highlight certain points, 2d plots, multiple plots)
  178. - plot: "smooth" automatic scale, user give an input 0.0(full user scale) 1.0(full derived from value)
  179. - 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)
  180. - file selection widget -> build the tool in our codebase to improve model-dialog idioms (may or not lead to ImGui changes)
  181. - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt()
  182. - slider: initial absolute click is imprecise. change to relative movement slider? hide mouse cursor, allow more precise input using less screen-space.
  183. - text edit: clean up the horrible mess caused by converting UTF-8 <> wchar
  184. - text edit: centered text for slider or input text to it matches typical positioning.
  185. - text edit: flag to disable live update of the user buffer.
  186. - text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text?
  187. - text edit: pasting text into a number box should filter the characters the same way direct input does
  188. - text edit: add multi-line text edit
  189. - settings: write more decent code to allow saving/loading new fields
  190. - settings: api for per-tool simple persistent data (bool,int,float) in .ini file
  191. - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope)
  192. - log: be able to right-click and log a window or tree-node into tty/file/clipboard?
  193. - filters: set a current filter that tree node can automatically query to hide themselves
  194. - filters: handle wildcards (with implicit leading/trailing *), regexps
  195. - 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)
  196. ! keyboard: tooltip & combo boxes are messing up / not honoring keyboard tabbing
  197. - keyboard: full keyboard navigation and focus.
  198. - input: rework IO to be able to pass actual events to fix temporal aliasing issues.
  199. - input: support track pad style scrolling & slider edit.
  200. - tooltip: move to fit within screen (e.g. when mouse cursor is right of the screen).
  201. - clipboard: automatically transform \n into \n\r or equivalent for higher compatibility on windows
  202. - portability: big-endian test/support (github issue #81)
  203. - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL
  204. - misc: not thread-safe
  205. - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon?
  206. - misc: CalcTextSize() could benefit from having 'hide_text_after_double_hash' false by default for external use?
  207. - style editor: add a button to output C code.
  208. - examples: integrate dx11 example.
  209. - examples: integrate opengl 3/4 programmable pipeline example.
  210. - optimization/render: use indexed rendering
  211. - optimization/render: move clip-rect to vertex data? would allow merging all commands
  212. - 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)?
  213. - optimization/render: font exported by bmfont is not tight fit on vertical axis, incur unneeded pixel-shading cost.
  214. - optimization: turn some the various stack vectors into statically-sized arrays
  215. - optimization: better clipping for multi-component widgets
  216. - optimization: specialize for height based clipping first (assume widgets never go up + height tests before width tests?)
  217. */
  218. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  219. #define _CRT_SECURE_NO_WARNINGS
  220. #endif
  221. #include "imgui.h"
  222. #include <ctype.h> // toupper
  223. #include <math.h> // sqrtf
  224. #include <stdint.h> // intptr_t
  225. #include <stdio.h> // vsnprintf
  226. #include <string.h> // memset
  227. #include <new> // new (ptr)
  228. #ifdef _MSC_VER
  229. #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
  230. #endif
  231. #ifdef __clang__
  232. #pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse and not scary looking.
  233. #pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants ok.
  234. #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, thank you.
  235. #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.
  236. #pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it.
  237. #endif
  238. //-------------------------------------------------------------------------
  239. // Forward Declarations
  240. //-------------------------------------------------------------------------
  241. static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false);
  242. static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL);
  243. static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true, float wrap_width = 0.0f);
  244. static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
  245. static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale = 1.0f, bool shadow = false);
  246. static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL);
  247. static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL);
  248. static void PushColumnClipRect(int column_index = -1);
  249. static bool IsClipped(const ImGuiAabb& aabb);
  250. static bool ClipAdvance(const ImGuiAabb& aabb);
  251. static bool IsMouseHoveringBox(const ImGuiAabb& box);
  252. static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true);
  253. static bool CloseWindowButton(bool* open = NULL);
  254. static void FocusWindow(ImGuiWindow* window);
  255. static ImGuiWindow* FindWindow(const char* name);
  256. static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs);
  257. //-----------------------------------------------------------------------------
  258. // Platform dependent default implementations
  259. //-----------------------------------------------------------------------------
  260. static const char* GetClipboardTextFn_DefaultImpl();
  261. static void SetClipboardTextFn_DefaultImpl(const char* text);
  262. //-----------------------------------------------------------------------------
  263. // User facing structures
  264. //-----------------------------------------------------------------------------
  265. ImGuiStyle::ImGuiStyle()
  266. {
  267. Alpha = 1.0f; // Global alpha applies to everything in ImGui
  268. WindowPadding = ImVec2(8,8); // Padding within a window
  269. WindowMinSize = ImVec2(48,48); // Minimum window size
  270. FramePadding = ImVec2(5,4); // Padding within a framed rectangle (used by most widgets)
  271. ItemSpacing = ImVec2(10,5); // Horizontal and vertical spacing between widgets/lines
  272. ItemInnerSpacing = ImVec2(5,5); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
  273. TouchExtraPadding = ImVec2(0,0); // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much!
  274. AutoFitPadding = ImVec2(8,8); // Extra space after auto-fit (double-clicking on resize grip)
  275. WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin()
  276. WindowRounding = 10.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
  277. TreeNodeSpacing = 22.0f; // Horizontal spacing when entering a tree node
  278. ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns
  279. ScrollBarWidth = 16.0f; // Width of the vertical scroll bar
  280. Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
  281. Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
  282. Colors[ImGuiCol_Border] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  283. Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.60f);
  284. Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f); // Background of checkbox, radio button, plot, slider, text input
  285. Colors[ImGuiCol_TitleBg] = ImVec4(0.50f, 0.50f, 1.00f, 0.45f);
  286. Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.40f, 0.40f, 0.80f, 0.20f);
  287. Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.40f, 0.40f, 0.80f, 0.15f);
  288. Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.80f, 0.30f);
  289. Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f);
  290. Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 0.40f);
  291. Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f);
  292. Colors[ImGuiCol_CheckHovered] = ImVec4(0.60f, 0.40f, 0.40f, 0.45f);
  293. Colors[ImGuiCol_CheckActive] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f);
  294. Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
  295. Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  296. Colors[ImGuiCol_Button] = ImVec4(0.67f, 0.40f, 0.40f, 0.60f);
  297. Colors[ImGuiCol_ButtonHovered] = ImVec4(0.67f, 0.40f, 0.40f, 1.00f);
  298. Colors[ImGuiCol_ButtonActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  299. Colors[ImGuiCol_Header] = ImVec4(0.40f, 0.40f, 0.90f, 0.45f);
  300. Colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.90f, 0.80f);
  301. Colors[ImGuiCol_HeaderActive] = ImVec4(0.60f, 0.60f, 0.80f, 1.00f);
  302. Colors[ImGuiCol_Column] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  303. Colors[ImGuiCol_ColumnHovered] = ImVec4(0.60f, 0.40f, 0.40f, 1.00f);
  304. Colors[ImGuiCol_ColumnActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  305. Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
  306. Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.00f, 1.00f, 1.00f, 0.60f);
  307. Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.90f);
  308. Colors[ImGuiCol_CloseButton] = ImVec4(0.50f, 0.50f, 0.90f, 0.50f);
  309. Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.70f, 0.70f, 0.90f, 0.60f);
  310. Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.70f, 0.70f, 0.70f, 1.00f);
  311. Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  312. Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  313. Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  314. Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
  315. Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
  316. Colors[ImGuiCol_TooltipBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
  317. }
  318. ImGuiIO::ImGuiIO()
  319. {
  320. memset(this, 0, sizeof(*this));
  321. DeltaTime = 1.0f/60.0f;
  322. IniSavingRate = 5.0f;
  323. IniFilename = "imgui.ini";
  324. LogFilename = "imgui_log.txt";
  325. Font = NULL;
  326. FontGlobalScale = 1.0f;
  327. FontAllowUserScaling = false;
  328. PixelCenterOffset = 0.0f;
  329. MousePos = ImVec2(-1,-1);
  330. MousePosPrev = ImVec2(-1,-1);
  331. MouseDoubleClickTime = 0.30f;
  332. MouseDoubleClickMaxDist = 6.0f;
  333. UserData = NULL;
  334. // User functions
  335. RenderDrawListsFn = NULL;
  336. MemAllocFn = malloc;
  337. MemReallocFn = realloc;
  338. MemFreeFn = free;
  339. GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependant default implementations
  340. SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
  341. ImeSetInputScreenPosFn = NULL;
  342. }
  343. // Pass in translated ASCII characters for text input.
  344. // - with glfw you can get those from the callback set in glfwSetCharCallback()
  345. // - on Windows you can get those using ToAscii+keyboard state, or via the VM_CHAR message
  346. static size_t ImStrlenW(const ImWchar* str);
  347. void ImGuiIO::AddInputCharacter(ImWchar c)
  348. {
  349. const size_t n = ImStrlenW(InputCharacters);
  350. if (n + 1 < sizeof(InputCharacters) / sizeof(InputCharacters[0]))
  351. {
  352. InputCharacters[n] = c;
  353. InputCharacters[n+1] = 0;
  354. }
  355. }
  356. //-----------------------------------------------------------------------------
  357. // Helpers
  358. //-----------------------------------------------------------------------------
  359. #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
  360. #undef PI
  361. const float PI = 3.14159265358979323846f;
  362. #ifdef INT_MAX
  363. #define IM_INT_MAX INT_MAX
  364. #else
  365. #define IM_INT_MAX 2147483647
  366. #endif
  367. // Math bits
  368. // 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.
  369. static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); }
  370. //static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); }
  371. static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); }
  372. static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); }
  373. static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); }
  374. static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); }
  375. static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; }
  376. static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; }
  377. static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; }
  378. //static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; }
  379. static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; }
  380. static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; }
  381. static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; }
  382. static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; }
  383. static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); }
  384. static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); }
  385. static inline float ImClamp(float f, float mn, float mx) { return (f < mn) ? mn : (f > mx) ? mx : f; }
  386. 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)); }
  387. static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; }
  388. static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; }
  389. //static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, float t) { return a + (b - a) * t; }
  390. 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); }
  391. static inline float ImLength(const ImVec2& lhs) { return sqrtf(lhs.x*lhs.x + lhs.y*lhs.y); }
  392. static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int in_char); // return output UTF-8 bytes count
  393. 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
  394. static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count
  395. static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count
  396. static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count)
  397. static int ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points
  398. static int ImStricmp(const char* str1, const char* str2)
  399. {
  400. int d;
  401. while ((d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; }
  402. return d;
  403. }
  404. static int ImStrnicmp(const char* str1, const char* str2, int count)
  405. {
  406. int d = 0;
  407. while (count > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; count--; }
  408. return d;
  409. }
  410. static char* ImStrdup(const char *str)
  411. {
  412. char *buff = (char*)ImGui::MemAlloc(strlen(str) + 1);
  413. IM_ASSERT(buff);
  414. strcpy(buff, str);
  415. return buff;
  416. }
  417. static size_t ImStrlenW(const ImWchar* str)
  418. {
  419. size_t n = 0;
  420. while (*str++)
  421. n++;
  422. return n;
  423. }
  424. static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end)
  425. {
  426. if (!needle_end)
  427. needle_end = needle + strlen(needle);
  428. const char un0 = (char)toupper(*needle);
  429. while (*haystack)
  430. {
  431. if (toupper(*haystack) == un0)
  432. {
  433. const char* b = needle + 1;
  434. for (const char* a = haystack + 1; b < needle_end; a++, b++)
  435. if (toupper(*a) != toupper(*b))
  436. break;
  437. if (b == needle_end)
  438. return haystack;
  439. }
  440. haystack++;
  441. }
  442. return NULL;
  443. }
  444. static ImU32 crc32(const void* data, size_t data_size, ImU32 seed = 0)
  445. {
  446. static ImU32 crc32_lut[256] = { 0 };
  447. if (!crc32_lut[1])
  448. {
  449. const ImU32 polynomial = 0xEDB88320;
  450. for (ImU32 i = 0; i < 256; i++)
  451. {
  452. ImU32 crc = i;
  453. for (ImU32 j = 0; j < 8; j++)
  454. crc = (crc >> 1) ^ (ImU32(-int(crc & 1)) & polynomial);
  455. crc32_lut[i] = crc;
  456. }
  457. }
  458. ImU32 crc = ~seed;
  459. const unsigned char* current = (const unsigned char*)data;
  460. while (data_size--)
  461. crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++];
  462. return ~crc;
  463. }
  464. static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...)
  465. {
  466. va_list args;
  467. va_start(args, fmt);
  468. int w = vsnprintf(buf, buf_size, fmt, args);
  469. va_end(args);
  470. buf[buf_size-1] = 0;
  471. return (w == -1) ? buf_size : (size_t)w;
  472. }
  473. static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args)
  474. {
  475. int w = vsnprintf(buf, buf_size, fmt, args);
  476. buf[buf_size-1] = 0;
  477. return (w == -1) ? buf_size : (size_t)w;
  478. }
  479. static ImU32 ImConvertColorFloat4ToU32(const ImVec4& in)
  480. {
  481. ImU32 out = ((ImU32)(ImSaturate(in.x)*255.f));
  482. out |= ((ImU32)(ImSaturate(in.y)*255.f) << 8);
  483. out |= ((ImU32)(ImSaturate(in.z)*255.f) << 16);
  484. out |= ((ImU32)(ImSaturate(in.w)*255.f) << 24);
  485. return out;
  486. }
  487. // Convert rgb floats ([0-1],[0-1],[0-1]) to hsv floats ([0-1],[0-1],[0-1]), from Foley & van Dam p592
  488. // Optimized http://lolengine.net/blog/2013/01/13/fast-rgb-to-hsv
  489. static void ImConvertColorRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v)
  490. {
  491. float K = 0.f;
  492. if (g < b)
  493. {
  494. const float tmp = g; g = b; b = tmp;
  495. K = -1.f;
  496. }
  497. if (r < g)
  498. {
  499. const float tmp = r; r = g; g = tmp;
  500. K = -2.f / 6.f - K;
  501. }
  502. const float chroma = r - (g < b ? g : b);
  503. out_h = fabsf(K + (g - b) / (6.f * chroma + 1e-20f));
  504. out_s = chroma / (r + 1e-20f);
  505. out_v = r;
  506. }
  507. // Convert hsv floats ([0-1],[0-1],[0-1]) to rgb floats ([0-1],[0-1],[0-1]), from Foley & van Dam p593
  508. // also http://en.wikipedia.org/wiki/HSL_and_HSV
  509. static void ImConvertColorHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b)
  510. {
  511. if (s == 0.0f)
  512. {
  513. // gray
  514. out_r = out_g = out_b = v;
  515. return;
  516. }
  517. h = fmodf(h, 1.0f) / (60.0f/360.0f);
  518. int i = (int)h;
  519. float f = h - (float)i;
  520. float p = v * (1.0f - s);
  521. float q = v * (1.0f - s * f);
  522. float t = v * (1.0f - s * (1.0f - f));
  523. switch (i)
  524. {
  525. case 0: out_r = v; out_g = t; out_b = p; break;
  526. case 1: out_r = q; out_g = v; out_b = p; break;
  527. case 2: out_r = p; out_g = v; out_b = t; break;
  528. case 3: out_r = p; out_g = q; out_b = v; break;
  529. case 4: out_r = t; out_g = p; out_b = v; break;
  530. case 5: default: out_r = v; out_g = p; out_b = q; break;
  531. }
  532. }
  533. //-----------------------------------------------------------------------------
  534. struct ImGuiColMod // Color modifier, backup of modified data so we can restore it
  535. {
  536. ImGuiCol Col;
  537. ImVec4 PreviousValue;
  538. };
  539. struct ImGuiStyleMod // Style modifier, backup of modified data so we can restore it
  540. {
  541. ImGuiStyleVar Var;
  542. ImVec2 PreviousValue;
  543. };
  544. struct ImGuiAabb // 2D axis aligned bounding-box
  545. {
  546. ImVec2 Min;
  547. ImVec2 Max;
  548. ImGuiAabb() { Min = ImVec2(FLT_MAX,FLT_MAX); Max = ImVec2(-FLT_MAX,-FLT_MAX); }
  549. ImGuiAabb(const ImVec2& min, const ImVec2& max) { Min = min; Max = max; }
  550. ImGuiAabb(const ImVec4& v) { Min.x = v.x; Min.y = v.y; Max.x = v.z; Max.y = v.w; }
  551. ImGuiAabb(float x1, float y1, float x2, float y2) { Min.x = x1; Min.y = y1; Max.x = x2; Max.y = y2; }
  552. ImVec2 GetCenter() const { return Min + (Max-Min)*0.5f; }
  553. ImVec2 GetSize() const { return Max-Min; }
  554. float GetWidth() const { return (Max-Min).x; }
  555. float GetHeight() const { return (Max-Min).y; }
  556. ImVec2 GetTL() const { return Min; }
  557. ImVec2 GetTR() const { return ImVec2(Max.x,Min.y); }
  558. ImVec2 GetBL() const { return ImVec2(Min.x,Max.y); }
  559. ImVec2 GetBR() const { return Max; }
  560. bool Contains(ImVec2 p) const { return p.x >= Min.x && p.y >= Min.y && p.x <= Max.x && p.y <= Max.y; }
  561. bool Contains(const ImGuiAabb& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x <= Max.x && r.Max.y <= Max.y; }
  562. bool Overlaps(const ImGuiAabb& r) const { return r.Min.y <= Max.y && r.Max.y >= Min.y && r.Min.x <= Max.x && r.Max.x >= Min.x; }
  563. void Expand(ImVec2 sz) { Min -= sz; Max += sz; }
  564. void Clip(const ImGuiAabb& 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); }
  565. };
  566. // Temporary per-window data, reset at the beginning of the frame
  567. struct ImGuiDrawContext
  568. {
  569. ImVec2 CursorPos;
  570. ImVec2 CursorPosPrevLine;
  571. ImVec2 CursorStartPos;
  572. float CurrentLineHeight;
  573. float PrevLineHeight;
  574. float LogLineHeight;
  575. int TreeDepth;
  576. ImGuiAabb LastItemAabb;
  577. bool LastItemHovered;
  578. bool LastItemFocused;
  579. ImVector<ImGuiWindow*> ChildWindows;
  580. ImVector<bool> AllowKeyboardFocus;
  581. ImVector<float> ItemWidth;
  582. ImVector<float> TextWrapPos;
  583. ImGuiColorEditMode ColorEditMode;
  584. ImGuiStorage* StateStorage;
  585. int OpenNextNode;
  586. float ColumnsStartX; // Start position from left of window (increased by TreePush/TreePop, etc.)
  587. 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.
  588. int ColumnsCurrent;
  589. int ColumnsCount;
  590. ImVec2 ColumnsStartPos;
  591. float ColumnsCellMinY;
  592. float ColumnsCellMaxY;
  593. bool ColumnsShowBorders;
  594. ImGuiID ColumnsSetID;
  595. ImGuiDrawContext()
  596. {
  597. CursorPos = CursorPosPrevLine = CursorStartPos = ImVec2(0.0f, 0.0f);
  598. CurrentLineHeight = PrevLineHeight = 0.0f;
  599. LogLineHeight = -1.0f;
  600. TreeDepth = 0;
  601. LastItemAabb = ImGuiAabb(0.0f,0.0f,0.0f,0.0f);
  602. LastItemHovered = false;
  603. LastItemFocused = true;
  604. StateStorage = NULL;
  605. OpenNextNode = -1;
  606. ColumnsStartX = 0.0f;
  607. ColumnsOffsetX = 0.0f;
  608. ColumnsCurrent = 0;
  609. ColumnsCount = 1;
  610. ColumnsStartPos = ImVec2(0.0f, 0.0f);
  611. ColumnsCellMinY = ColumnsCellMaxY = 0.0f;
  612. ColumnsShowBorders = true;
  613. ColumnsSetID = 0;
  614. }
  615. };
  616. struct ImGuiTextEditState;
  617. #define STB_TEXTEDIT_STRING ImGuiTextEditState
  618. #define STB_TEXTEDIT_CHARTYPE ImWchar
  619. #include "stb_textedit.h"
  620. // Internal state of the currently focused/edited text input box
  621. struct ImGuiTextEditState
  622. {
  623. 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.
  624. char InitialText[1024*3+1]; // backup of end-user buffer at the time of focus (in UTF-8, unconverted)
  625. size_t BufSize; // end-user buffer size, <= 1024 (or increase above)
  626. float Width; // widget width
  627. float ScrollX;
  628. STB_TexteditState StbState;
  629. float CursorAnim;
  630. ImVec2 LastCursorPos; // Cursor position in screen space to be used by IME callback.
  631. bool SelectedAllMouseLock;
  632. ImFont* Font;
  633. float FontSize;
  634. ImGuiTextEditState() { memset(this, 0, sizeof(*this)); }
  635. void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking
  636. bool CursorIsVisible() const { return CursorAnim <= 0.0f || fmodf(CursorAnim, 1.20f) <= 0.80f; } // Blinking
  637. bool HasSelection() const { return StbState.select_start != StbState.select_end; }
  638. void SelectAll() { StbState.select_start = 0; StbState.select_end = (int)ImStrlenW(Text); StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; }
  639. void OnKeyPressed(int key);
  640. void UpdateScrollOffset();
  641. ImVec2 CalcDisplayOffsetFromCharIdx(int i) const;
  642. // Static functions because they are used to render non-focused instances of a text input box
  643. static const char* GetTextPointerClippedA(ImFont* font, float font_size, const char* text, float width, ImVec2* out_text_size = NULL);
  644. static const ImWchar* GetTextPointerClippedW(ImFont* font, float font_size, const ImWchar* text, float width, ImVec2* out_text_size = NULL);
  645. static void RenderTextScrolledClipped(ImFont* font, float font_size, const char* text, ImVec2 pos_base, float width, float scroll_x);
  646. };
  647. struct ImGuiIniData
  648. {
  649. char* Name;
  650. ImVec2 Pos;
  651. ImVec2 Size;
  652. bool Collapsed;
  653. ImGuiIniData() { memset(this, 0, sizeof(*this)); }
  654. ~ImGuiIniData() { if (Name) { ImGui::MemFree(Name); Name = NULL; } }
  655. };
  656. struct ImGuiState
  657. {
  658. bool Initialized;
  659. ImGuiIO IO;
  660. ImGuiStyle Style;
  661. float FontSize; // == IO.FontGlobalScale * IO.Font->Scale * IO.Font->Info->FontSize. Vertical distance between two lines of text, aka == CalcTextSize(" ").y
  662. ImVec2 FontTexUvForWhite; // == IO.Font->FontTexUvForWhite (cached copy)
  663. float Time;
  664. int FrameCount;
  665. int FrameCountRendered;
  666. ImVector<ImGuiWindow*> Windows;
  667. ImGuiWindow* CurrentWindow; // Being drawn into
  668. ImVector<ImGuiWindow*> CurrentWindowStack;
  669. ImGuiWindow* FocusedWindow; // Will catch keyboard inputs
  670. ImGuiWindow* HoveredWindow; // Will catch mouse inputs
  671. ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only)
  672. ImGuiID HoveredId;
  673. ImGuiID ActiveId;
  674. ImGuiID ActiveIdPreviousFrame;
  675. bool ActiveIdIsAlive;
  676. float SettingsDirtyTimer;
  677. ImVector<ImGuiIniData*> Settings;
  678. ImVec2 NewWindowDefaultPos;
  679. ImVector<ImGuiColMod> ColorModifiers;
  680. ImVector<ImGuiStyleMod> StyleModifiers;
  681. // Render
  682. ImVector<ImDrawList*> RenderDrawLists;
  683. // Widget state
  684. ImGuiTextEditState InputTextState;
  685. ImGuiID SliderAsInputTextId;
  686. ImGuiStorage ColorEditModeStorage; // for user selection
  687. ImGuiID ActiveComboID;
  688. char Tooltip[1024];
  689. char* PrivateClipboard; // if no custom clipboard handler is defined
  690. // Logging
  691. bool LogEnabled;
  692. FILE* LogFile;
  693. ImGuiTextBuffer* LogClipboard; // pointer so our GImGui static constructor doesn't call heap allocators.
  694. int LogAutoExpandMaxDepth;
  695. ImGuiState()
  696. {
  697. Initialized = false;
  698. Time = 0.0f;
  699. FrameCount = 0;
  700. FrameCountRendered = -1;
  701. CurrentWindow = NULL;
  702. FocusedWindow = NULL;
  703. HoveredWindow = NULL;
  704. HoveredRootWindow = NULL;
  705. ActiveIdIsAlive = false;
  706. SettingsDirtyTimer = 0.0f;
  707. NewWindowDefaultPos = ImVec2(60, 60);
  708. SliderAsInputTextId = 0;
  709. ActiveComboID = 0;
  710. memset(Tooltip, 0, sizeof(Tooltip));
  711. PrivateClipboard = NULL;
  712. LogEnabled = false;
  713. LogFile = NULL;
  714. LogAutoExpandMaxDepth = 2;
  715. LogClipboard = NULL;
  716. }
  717. };
  718. static ImGuiState GImGui;
  719. struct ImGuiWindow
  720. {
  721. char* Name;
  722. ImGuiID ID;
  723. ImGuiWindowFlags Flags;
  724. ImVec2 PosFloat;
  725. ImVec2 Pos; // Position rounded-up to nearest pixel
  726. ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
  727. ImVec2 SizeFull; // Size when non collapsed
  728. ImVec2 SizeContentsFit; // Size of contents (extents reach by the drawing cursor) - may not fit within Size.
  729. float ScrollY;
  730. float NextScrollY;
  731. bool ScrollbarY;
  732. bool Visible; // Set to true on Begin()
  733. bool Accessed; // Set to true when any widget access the current window
  734. bool Collapsed; // Set when collapsing window to become only title-bar
  735. bool SkipItems; // == Visible && !Collapsed
  736. int AutoFitFrames;
  737. bool AutoFitOnlyGrows;
  738. ImGuiDrawContext DC;
  739. ImVector<ImGuiID> IDStack;
  740. ImVector<ImVec4> ClipRectStack;
  741. int LastFrameDrawn;
  742. float ItemWidthDefault;
  743. ImGuiStorage StateStorage;
  744. float FontWindowScale; // Scale multiplier per-window
  745. ImDrawList* DrawList;
  746. ImGuiWindow* RootWindow;
  747. // Focus
  748. int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister()
  749. int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through)
  750. int FocusIdxAllRequestCurrent; // Item being requested for focus
  751. int FocusIdxTabRequestCurrent; // Tab-able item being requested for focus
  752. 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)
  753. int FocusIdxTabRequestNext; // "
  754. public:
  755. ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_size);
  756. ~ImGuiWindow();
  757. ImGuiID GetID(const char* str);
  758. ImGuiID GetID(const void* ptr);
  759. void AddToRenderList();
  760. bool FocusItemRegister(bool is_active, bool tab_stop = true); // Return true if focus is requested
  761. void FocusItemUnregister();
  762. ImGuiAabb Aabb() const { return ImGuiAabb(Pos, Pos+Size); }
  763. ImFont* Font() const { return GImGui.IO.Font; }
  764. float FontSize() const { return GImGui.FontSize * FontWindowScale; }
  765. ImVec2 CursorPos() const { return DC.CursorPos; }
  766. float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui.Style.FramePadding.y * 2.0f; }
  767. ImGuiAabb TitleBarAabb() const { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); }
  768. ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(1,1) : GImGui.Style.WindowPadding; }
  769. ImU32 Color(ImGuiCol idx, float a=1.f) const { ImVec4 c = GImGui.Style.Colors[idx]; c.w *= GImGui.Style.Alpha * a; return ImConvertColorFloat4ToU32(c); }
  770. ImU32 Color(const ImVec4& col) const { ImVec4 c = col; c.w *= GImGui.Style.Alpha; return ImConvertColorFloat4ToU32(c); }
  771. };
  772. static ImGuiWindow* GetCurrentWindow()
  773. {
  774. IM_ASSERT(GImGui.CurrentWindow != NULL); // ImGui::NewFrame() hasn't been called yet?
  775. GImGui.CurrentWindow->Accessed = true;
  776. return GImGui.CurrentWindow;
  777. }
  778. static void RegisterAliveId(const ImGuiID& id)
  779. {
  780. if (GImGui.ActiveId == id)
  781. GImGui.ActiveIdIsAlive = true;
  782. }
  783. //-----------------------------------------------------------------------------
  784. // Helper: Key->value storage
  785. void ImGuiStorage::Clear()
  786. {
  787. Data.clear();
  788. }
  789. // std::lower_bound but without the bullshit
  790. static ImVector<ImGuiStorage::Pair>::iterator LowerBound(ImVector<ImGuiStorage::Pair>& data, ImU32 key)
  791. {
  792. ImVector<ImGuiStorage::Pair>::iterator first = data.begin();
  793. ImVector<ImGuiStorage::Pair>::iterator last = data.end();
  794. int count = (int)(last - first);
  795. while (count > 0)
  796. {
  797. int count2 = count / 2;
  798. ImVector<ImGuiStorage::Pair>::iterator mid = first + count2;
  799. if (mid->key < key)
  800. {
  801. first = ++mid;
  802. count -= count2 + 1;
  803. }
  804. else
  805. {
  806. count = count2;
  807. }
  808. }
  809. return first;
  810. }
  811. int* ImGuiStorage::Find(ImU32 key)
  812. {
  813. ImVector<Pair>::iterator it = LowerBound(Data, key);
  814. if (it == Data.end())
  815. return NULL;
  816. if (it->key != key)
  817. return NULL;
  818. return &it->val;
  819. }
  820. int ImGuiStorage::GetInt(ImU32 key, int default_val)
  821. {
  822. int* pval = Find(key);
  823. if (!pval)
  824. return default_val;
  825. return *pval;
  826. }
  827. // FIXME-OPT: We are wasting time because all SetInt() are preceeded by GetInt() calls so we should have the result from lower_bound already in place.
  828. // However we only use SetInt() on explicit user action (so that's maximum once a frame) so the optimisation isn't much needed.
  829. void ImGuiStorage::SetInt(ImU32 key, int val)
  830. {
  831. ImVector<Pair>::iterator it = LowerBound(Data, key);
  832. if (it != Data.end() && it->key == key)
  833. {
  834. it->val = val;
  835. }
  836. else
  837. {
  838. Pair pair_key;
  839. pair_key.key = key;
  840. pair_key.val = val;
  841. Data.insert(it, pair_key);
  842. }
  843. }
  844. void ImGuiStorage::SetAllInt(int v)
  845. {
  846. for (size_t i = 0; i < Data.size(); i++)
  847. Data[i].val = v;
  848. }
  849. //-----------------------------------------------------------------------------
  850. // Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
  851. ImGuiTextFilter::ImGuiTextFilter()
  852. {
  853. InputBuf[0] = 0;
  854. CountGrep = 0;
  855. }
  856. void ImGuiTextFilter::Draw(const char* label, float width)
  857. {
  858. ImGuiWindow* window = GetCurrentWindow();
  859. if (width < 0.0f)
  860. {
  861. ImVec2 label_size = ImGui::CalcTextSize(label, NULL);
  862. width = ImMax(window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x - (label_size.x + GImGui.Style.ItemSpacing.x*4), 10.0f);
  863. }
  864. ImGui::PushItemWidth(width);
  865. ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf));
  866. ImGui::PopItemWidth();
  867. Build();
  868. }
  869. void ImGuiTextFilter::TextRange::split(char separator, ImVector<TextRange>& out)
  870. {
  871. out.resize(0);
  872. const char* wb = b;
  873. const char* we = wb;
  874. while (we < e)
  875. {
  876. if (*we == separator)
  877. {
  878. out.push_back(TextRange(wb, we));
  879. wb = we + 1;
  880. }
  881. we++;
  882. }
  883. if (wb != we)
  884. out.push_back(TextRange(wb, we));
  885. }
  886. void ImGuiTextFilter::Build()
  887. {
  888. Filters.resize(0);
  889. TextRange input_range(InputBuf, InputBuf+strlen(InputBuf));
  890. input_range.split(',', Filters);
  891. CountGrep = 0;
  892. for (size_t i = 0; i != Filters.size(); i++)
  893. {
  894. Filters[i].trim_blanks();
  895. if (Filters[i].empty())
  896. continue;
  897. if (Filters[i].front() != '-')
  898. CountGrep += 1;
  899. }
  900. }
  901. bool ImGuiTextFilter::PassFilter(const char* val) const
  902. {
  903. if (Filters.empty())
  904. return true;
  905. if (val == NULL)
  906. val = "";
  907. for (size_t i = 0; i != Filters.size(); i++)
  908. {
  909. const TextRange& f = Filters[i];
  910. if (f.empty())
  911. continue;
  912. if (f.front() == '-')
  913. {
  914. // Subtract
  915. if (ImStristr(val, f.begin()+1, f.end()) != NULL)
  916. return false;
  917. }
  918. else
  919. {
  920. // Grep
  921. if (ImStristr(val, f.begin(), f.end()) != NULL)
  922. return true;
  923. }
  924. }
  925. // Implicit * grep
  926. if (CountGrep == 0)
  927. return true;
  928. return false;
  929. }
  930. //-----------------------------------------------------------------------------
  931. // Helper: Text buffer for logging/accumulating text
  932. void ImGuiTextBuffer::append(const char* fmt, ...)
  933. {
  934. va_list args;
  935. va_start(args, fmt);
  936. int len = vsnprintf(NULL, 0, fmt, args);
  937. va_end(args);
  938. if (len <= 0)
  939. return;
  940. const size_t write_off = Buf.size();
  941. if (write_off + (size_t)len >= Buf.capacity())
  942. Buf.reserve(Buf.capacity() * 2);
  943. Buf.resize(write_off + (size_t)len);
  944. va_start(args, fmt);
  945. ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args);
  946. va_end(args);
  947. }
  948. //-----------------------------------------------------------------------------
  949. ImGuiWindow::ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_size)
  950. {
  951. Name = ImStrdup(name);
  952. ID = GetID(name);
  953. IDStack.push_back(ID);
  954. PosFloat = default_pos;
  955. Pos = ImVec2((float)(int)PosFloat.x, (float)(int)PosFloat.y);
  956. Size = SizeFull = default_size;
  957. SizeContentsFit = ImVec2(0.0f, 0.0f);
  958. ScrollY = 0.0f;
  959. NextScrollY = 0.0f;
  960. ScrollbarY = false;
  961. Visible = false;
  962. Accessed = false;
  963. Collapsed = false;
  964. SkipItems = false;
  965. AutoFitFrames = -1;
  966. AutoFitOnlyGrows = false;
  967. LastFrameDrawn = -1;
  968. ItemWidthDefault = 0.0f;
  969. FontWindowScale = 1.0f;
  970. if (ImLength(Size) < 0.001f)
  971. {
  972. AutoFitFrames = 2;
  973. AutoFitOnlyGrows = true;
  974. }
  975. DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
  976. new(DrawList) ImDrawList();
  977. FocusIdxAllCounter = FocusIdxTabCounter = -1;
  978. FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX;
  979. FocusIdxAllRequestNext = FocusIdxTabRequestNext = IM_INT_MAX;
  980. }
  981. ImGuiWindow::~ImGuiWindow()
  982. {
  983. DrawList->~ImDrawList();
  984. ImGui::MemFree(DrawList);
  985. DrawList = NULL;
  986. ImGui::MemFree(Name);
  987. Name = NULL;
  988. }
  989. ImGuiID ImGuiWindow::GetID(const char* str)
  990. {
  991. const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back();
  992. const ImGuiID id = crc32(str, strlen(str), seed); // FIXME-OPT: crc32 function/variant should handle zero-terminated strings
  993. RegisterAliveId(id);
  994. return id;
  995. }
  996. ImGuiID ImGuiWindow::GetID(const void* ptr)
  997. {
  998. const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back();
  999. const ImGuiID id = crc32(&ptr, sizeof(void*), seed);
  1000. RegisterAliveId(id);
  1001. return id;
  1002. }
  1003. bool ImGuiWindow::FocusItemRegister(bool is_active, bool tab_stop)
  1004. {
  1005. ImGuiState& g = GImGui;
  1006. ImGuiWindow* window = GetCurrentWindow();
  1007. const bool allow_keyboard_focus = window->DC.AllowKeyboardFocus.back();
  1008. FocusIdxAllCounter++;
  1009. if (allow_keyboard_focus)
  1010. FocusIdxTabCounter++;
  1011. if (is_active)
  1012. window->DC.LastItemFocused = true;
  1013. // Process keyboard input at this point: TAB, Shift-TAB switch focus
  1014. // We can always TAB out of a widget that doesn't allow tabbing in.
  1015. if (tab_stop && FocusIdxAllRequestNext == IM_INT_MAX && FocusIdxTabRequestNext == IM_INT_MAX && is_active && IsKeyPressedMap(ImGuiKey_Tab))
  1016. {
  1017. // Modulo on index will be applied at the end of frame once we've got the total counter of items.
  1018. FocusIdxTabRequestNext = FocusIdxTabCounter + (g.IO.KeyShift ? (allow_keyboard_focus ? -1 : 0) : +1);
  1019. }
  1020. if (FocusIdxAllCounter == FocusIdxAllRequestCurrent)
  1021. return true;
  1022. if (allow_keyboard_focus)
  1023. if (FocusIdxTabCounter == FocusIdxTabRequestCurrent)
  1024. return true;
  1025. return false;
  1026. }
  1027. void ImGuiWindow::FocusItemUnregister()
  1028. {
  1029. FocusIdxAllCounter--;
  1030. FocusIdxTabCounter--;
  1031. }
  1032. void ImGuiWindow::AddToRenderList()
  1033. {
  1034. ImGuiState& g = GImGui;
  1035. if (!DrawList->commands.empty() && !DrawList->vtx_buffer.empty())
  1036. {
  1037. if (DrawList->commands.back().vtx_count == 0)
  1038. DrawList->commands.pop_back();
  1039. g.RenderDrawLists.push_back(DrawList);
  1040. }
  1041. for (size_t i = 0; i < DC.ChildWindows.size(); i++)
  1042. {
  1043. ImGuiWindow* child = DC.ChildWindows[i];
  1044. if (child->Visible) // clipped childs may have been marked not Visible
  1045. child->AddToRenderList();
  1046. }
  1047. }
  1048. //-----------------------------------------------------------------------------
  1049. void* ImGui::MemAlloc(size_t sz)
  1050. {
  1051. return GImGui.IO.MemAllocFn(sz);
  1052. }
  1053. void ImGui::MemFree(void* ptr)
  1054. {
  1055. return GImGui.IO.MemFreeFn(ptr);
  1056. }
  1057. void* ImGui::MemRealloc(void* ptr, size_t sz)
  1058. {
  1059. return GImGui.IO.MemReallocFn(ptr, sz);
  1060. }
  1061. static ImGuiIniData* FindWindowSettings(const char* name)
  1062. {
  1063. ImGuiState& g = GImGui;
  1064. for (size_t i = 0; i != g.Settings.size(); i++)
  1065. {
  1066. ImGuiIniData* ini = g.Settings[i];
  1067. if (ImStricmp(ini->Name, name) == 0)
  1068. return ini;
  1069. }
  1070. ImGuiIniData* ini = (ImGuiIniData*)ImGui::MemAlloc(sizeof(ImGuiIniData));
  1071. new(ini) ImGuiIniData();
  1072. ini->Name = ImStrdup(name);
  1073. ini->Collapsed = false;
  1074. ini->Pos = ImVec2(FLT_MAX,FLT_MAX);
  1075. ini->Size = ImVec2(0,0);
  1076. g.Settings.push_back(ini);
  1077. return ini;
  1078. }
  1079. // Zero-tolerance, poor-man .ini parsing
  1080. // FIXME: Write something less rubbish
  1081. static void LoadSettings()
  1082. {
  1083. ImGuiState& g = GImGui;
  1084. const char* filename = g.IO.IniFilename;
  1085. if (!filename)
  1086. return;
  1087. // Load file
  1088. FILE* f;
  1089. if ((f = fopen(filename, "rt")) == NULL)
  1090. return;
  1091. if (fseek(f, 0, SEEK_END))
  1092. {
  1093. fclose(f);
  1094. return;
  1095. }
  1096. const long f_size_signed = ftell(f);
  1097. if (f_size_signed == -1)
  1098. {
  1099. fclose(f);
  1100. return;
  1101. }
  1102. size_t f_size = (size_t)f_size_signed;
  1103. if (fseek(f, 0, SEEK_SET))
  1104. {
  1105. fclose(f);
  1106. return;
  1107. }
  1108. char* f_data = (char*)ImGui::MemAlloc(f_size+1);
  1109. f_size = fread(f_data, 1, f_size, f); // Text conversion alter read size so let's not be fussy about return value
  1110. fclose(f);
  1111. if (f_size == 0)
  1112. {
  1113. ImGui::MemFree(f_data);
  1114. return;
  1115. }
  1116. f_data[f_size] = 0;
  1117. ImGuiIniData* settings = NULL;
  1118. const char* buf_end = f_data + f_size;
  1119. for (const char* line_start = f_data; line_start < buf_end; )
  1120. {
  1121. const char* line_end = line_start;
  1122. while (line_end < buf_end && *line_end != '\n' && *line_end != '\r')
  1123. line_end++;
  1124. if (line_start[0] == '[' && line_end > line_start && line_end[-1] == ']')
  1125. {
  1126. char name[64];
  1127. ImFormatString(name, IM_ARRAYSIZE(name), "%.*s", line_end-line_start-2, line_start+1);
  1128. settings = FindWindowSettings(name);
  1129. }
  1130. else if (settings)
  1131. {
  1132. float x, y;
  1133. int i;
  1134. if (sscanf(line_start, "Pos=%f,%f", &x, &y) == 2)
  1135. settings->Pos = ImVec2(x, y);
  1136. else if (sscanf(line_start, "Size=%f,%f", &x, &y) == 2)
  1137. settings->Size = ImMax(ImVec2(x, y), g.Style.WindowMinSize);
  1138. else if (sscanf(line_start, "Collapsed=%d", &i) == 1)
  1139. settings->Collapsed = (i != 0);
  1140. }
  1141. line_start = line_end+1;
  1142. }
  1143. ImGui::MemFree(f_data);
  1144. }
  1145. static void SaveSettings()
  1146. {
  1147. ImGuiState& g = GImGui;
  1148. const char* filename = g.IO.IniFilename;
  1149. if (!filename)
  1150. return;
  1151. // Gather data from windows that were active during this session
  1152. for (size_t i = 0; i != g.Windows.size(); i++)
  1153. {
  1154. ImGuiWindow* window = g.Windows[i];
  1155. if (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip))
  1156. continue;
  1157. ImGuiIniData* settings = FindWindowSettings(window->Name);
  1158. settings->Pos = window->Pos;
  1159. settings->Size = window->SizeFull;
  1160. settings->Collapsed = window->Collapsed;
  1161. }
  1162. // Write .ini file
  1163. // If a window wasn't opened in this session we preserve its settings
  1164. FILE* f = fopen(filename, "wt");
  1165. if (!f)
  1166. return;
  1167. for (size_t i = 0; i != g.Settings.size(); i++)
  1168. {
  1169. const ImGuiIniData* settings = g.Settings[i];
  1170. if (settings->Pos.x == FLT_MAX)
  1171. continue;
  1172. fprintf(f, "[%s]\n", settings->Name);
  1173. fprintf(f, "Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y);
  1174. fprintf(f, "Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y);
  1175. fprintf(f, "Collapsed=%d\n", settings->Collapsed);
  1176. fprintf(f, "\n");
  1177. }
  1178. fclose(f);
  1179. }
  1180. static void MarkSettingsDirty()
  1181. {
  1182. ImGuiState& g = GImGui;
  1183. if (g.SettingsDirtyTimer <= 0.0f)
  1184. g.SettingsDirtyTimer = g.IO.IniSavingRate;
  1185. }
  1186. ImGuiIO& ImGui::GetIO()
  1187. {
  1188. return GImGui.IO;
  1189. }
  1190. ImGuiStyle& ImGui::GetStyle()
  1191. {
  1192. return GImGui.Style;
  1193. }
  1194. void ImGui::NewFrame()
  1195. {
  1196. ImGuiState& g = GImGui;
  1197. // Check user inputs
  1198. IM_ASSERT(g.IO.DeltaTime > 0.0f);
  1199. IM_ASSERT(g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f);
  1200. IM_ASSERT(g.IO.RenderDrawListsFn != NULL); // Must be implemented
  1201. if (!g.Initialized)
  1202. {
  1203. // Initialize on first frame
  1204. g.LogClipboard = (ImGuiTextBuffer*)ImGui::MemAlloc(sizeof(ImGuiTextBuffer));
  1205. new(g.LogClipboard) ImGuiTextBuffer();
  1206. IM_ASSERT(g.Settings.empty());
  1207. LoadSettings();
  1208. if (!g.IO.Font)
  1209. {
  1210. // Default font
  1211. const void* fnt_data;
  1212. unsigned int fnt_size;
  1213. ImGui::GetDefaultFontData(&fnt_data, &fnt_size, NULL, NULL);
  1214. g.IO.Font = (ImFont*)ImGui::MemAlloc(sizeof(ImFont));
  1215. new(g.IO.Font) ImFont();
  1216. g.IO.Font->LoadFromMemory(fnt_data, fnt_size);
  1217. IM_ASSERT(g.IO.Font->IsLoaded()); // Font failed to load
  1218. g.IO.Font->DisplayOffset = ImVec2(0.0f, +1.0f);
  1219. }
  1220. g.Initialized = true;
  1221. }
  1222. IM_ASSERT(g.IO.Font && g.IO.Font->IsLoaded()); // Font not loaded
  1223. IM_ASSERT(g.IO.Font->Scale > 0.0f);
  1224. g.FontSize = g.IO.FontGlobalScale * (float)g.IO.Font->Info->FontSize * g.IO.Font->Scale;
  1225. g.FontTexUvForWhite = g.IO.Font->TexUvForWhite;
  1226. g.IO.Font->FallbackGlyph = g.IO.Font->FindGlyph(g.IO.Font->FallbackChar);
  1227. g.Time += g.IO.DeltaTime;
  1228. g.FrameCount += 1;
  1229. g.Tooltip[0] = '\0';
  1230. // Update inputs state
  1231. if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
  1232. g.IO.MousePos = ImVec2(-9999.0f, -9999.0f);
  1233. 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
  1234. g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
  1235. else
  1236. g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
  1237. g.IO.MousePosPrev = g.IO.MousePos;
  1238. for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
  1239. {
  1240. 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;
  1241. g.IO.MouseClicked[i] = (g.IO.MouseDownTime[i] == 0.0f);
  1242. g.IO.MouseDoubleClicked[i] = false;
  1243. if (g.IO.MouseClicked[i])
  1244. {
  1245. if (g.Time - g.IO.MouseClickedTime[i] < g.IO.MouseDoubleClickTime)
  1246. {
  1247. if (ImLength(g.IO.MousePos - g.IO.MouseClickedPos[i]) < g.IO.MouseDoubleClickMaxDist)
  1248. g.IO.MouseDoubleClicked[i] = true;
  1249. g.IO.MouseClickedTime[i] = -FLT_MAX; // so the third click isn't turned into a double-click
  1250. }
  1251. else
  1252. {
  1253. g.IO.MouseClickedTime[i] = g.Time;
  1254. g.IO.MouseClickedPos[i] = g.IO.MousePos;
  1255. }
  1256. }
  1257. }
  1258. for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
  1259. 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;
  1260. // Clear reference to active widget if the widget isn't alive anymore
  1261. g.HoveredId = 0;
  1262. if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0)
  1263. g.ActiveId = 0;
  1264. g.ActiveIdPreviousFrame = g.ActiveId;
  1265. g.ActiveIdIsAlive = false;
  1266. // Delay saving settings so we don't spam disk too much
  1267. if (g.SettingsDirtyTimer > 0.0f)
  1268. {
  1269. g.SettingsDirtyTimer -= g.IO.DeltaTime;
  1270. if (g.SettingsDirtyTimer <= 0.0f)
  1271. SaveSettings();
  1272. }
  1273. g.HoveredWindow = FindHoveredWindow(g.IO.MousePos, false);
  1274. g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true);
  1275. // Are we using inputs? Tell user so they can capture/discard them.
  1276. g.IO.WantCaptureMouse = (g.HoveredWindow != NULL) || (g.ActiveId != 0);
  1277. g.IO.WantCaptureKeyboard = (g.ActiveId != 0);
  1278. // Scale & Scrolling
  1279. if (g.HoveredWindow && g.IO.MouseWheel != 0.0f)
  1280. {
  1281. ImGuiWindow* window = g.HoveredWindow;
  1282. if (g.IO.KeyCtrl)
  1283. {
  1284. if (g.IO.FontAllowUserScaling)
  1285. {
  1286. // Zoom / Scale window
  1287. float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
  1288. float scale = new_font_scale / window->FontWindowScale;
  1289. window->FontWindowScale = new_font_scale;
  1290. const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
  1291. window->Pos += offset;
  1292. window->PosFloat += offset;
  1293. window->Size *= scale;
  1294. window->SizeFull *= scale;
  1295. }
  1296. }
  1297. else
  1298. {
  1299. // Scroll
  1300. if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse))
  1301. {
  1302. const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5;
  1303. window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines;
  1304. }
  1305. }
  1306. }
  1307. // Pressing TAB activate widget focus
  1308. // 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.
  1309. if (g.ActiveId == 0 && g.FocusedWindow != NULL && g.FocusedWindow->Visible && IsKeyPressedMap(ImGuiKey_Tab, false))
  1310. {
  1311. g.FocusedWindow->FocusIdxTabRequestNext = 0;
  1312. }
  1313. // Mark all windows as not visible
  1314. for (size_t i = 0; i != g.Windows.size(); i++)
  1315. {
  1316. ImGuiWindow* window = g.Windows[i];
  1317. window->Visible = false;
  1318. window->Accessed = false;
  1319. }
  1320. // No window should be open at the beginning of the frame.
  1321. // But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear.
  1322. g.CurrentWindowStack.clear();
  1323. // Create implicit window - we will only render it if the user has added something to it.
  1324. ImGui::Begin("Debug", NULL, ImVec2(400,400));
  1325. }
  1326. // NB: behaviour of ImGui after Shutdown() is not tested/guaranteed at the moment. This function is merely here to free heap allocations.
  1327. void ImGui::Shutdown()
  1328. {
  1329. ImGuiState& g = GImGui;
  1330. if (!g.Initialized)
  1331. return;
  1332. SaveSettings();
  1333. for (size_t i = 0; i < g.Windows.size(); i++)
  1334. {
  1335. g.Windows[i]->~ImGuiWindow();
  1336. ImGui::MemFree(g.Windows[i]);
  1337. }
  1338. g.Windows.clear();
  1339. g.CurrentWindowStack.clear();
  1340. g.RenderDrawLists.clear();
  1341. g.FocusedWindow = NULL;
  1342. g.HoveredWindow = NULL;
  1343. g.HoveredRootWindow = NULL;
  1344. for (size_t i = 0; i < g.Settings.size(); i++)
  1345. {
  1346. g.Settings[i]->~ImGuiIniData();
  1347. ImGui::MemFree(g.Settings[i]);
  1348. }
  1349. g.Settings.clear();
  1350. g.ColorEditModeStorage.Clear();
  1351. if (g.LogFile && g.LogFile != stdout)
  1352. {
  1353. fclose(g.LogFile);
  1354. g.LogFile = NULL;
  1355. }
  1356. if (g.IO.Font)
  1357. {
  1358. g.IO.Font->~ImFont();
  1359. ImGui::MemFree(g.IO.Font);
  1360. g.IO.Font = NULL;
  1361. }
  1362. if (g.PrivateClipboard)
  1363. {
  1364. ImGui::MemFree(g.PrivateClipboard);
  1365. g.PrivateClipboard = NULL;
  1366. }
  1367. if (g.LogClipboard)
  1368. {
  1369. g.LogClipboard->~ImGuiTextBuffer();
  1370. ImGui::MemFree(g.LogClipboard);
  1371. }
  1372. g.Initialized = false;
  1373. }
  1374. static void AddWindowToSortedBuffer(ImGuiWindow* window, ImVector<ImGuiWindow*>& sorted_windows)
  1375. {
  1376. sorted_windows.push_back(window);
  1377. if (window->Visible)
  1378. {
  1379. for (size_t i = 0; i < window->DC.ChildWindows.size(); i++)
  1380. {
  1381. ImGuiWindow* child = window->DC.ChildWindows[i];
  1382. if (child->Visible)
  1383. AddWindowToSortedBuffer(child, sorted_windows);
  1384. }
  1385. }
  1386. }
  1387. static void PushClipRect(const ImVec4& clip_rect, bool clipped = true)
  1388. {
  1389. ImGuiWindow* window = GetCurrentWindow();
  1390. ImVec4 cr = clip_rect;
  1391. if (clipped && !window->ClipRectStack.empty())
  1392. {
  1393. // Clip to new clip rect
  1394. const ImVec4 cur_cr = window->ClipRectStack.back();
  1395. 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));
  1396. }
  1397. window->ClipRectStack.push_back(cr);
  1398. window->DrawList->PushClipRect(cr);
  1399. }
  1400. static void PopClipRect()
  1401. {
  1402. ImGuiWindow* window = GetCurrentWindow();
  1403. window->ClipRectStack.pop_back();
  1404. window->DrawList->PopClipRect();
  1405. }
  1406. void ImGui::Render()
  1407. {
  1408. ImGuiState& g = GImGui;
  1409. IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
  1410. const bool first_render_of_the_frame = (g.FrameCountRendered != g.FrameCount);
  1411. g.FrameCountRendered = g.FrameCount;
  1412. if (first_render_of_the_frame)
  1413. {
  1414. // Hide implicit window if it hasn't been used
  1415. IM_ASSERT(g.CurrentWindowStack.size() == 1); // Mismatched Begin/End
  1416. if (g.CurrentWindow && !g.CurrentWindow->Accessed)
  1417. g.CurrentWindow->Visible = false;
  1418. ImGui::End();
  1419. // Sort the window list so that all child windows are after their parent
  1420. // We cannot do that on FocusWindow() because childs may not exist yet
  1421. ImVector<ImGuiWindow*> sorted_windows;
  1422. sorted_windows.reserve(g.Windows.size());
  1423. for (size_t i = 0; i != g.Windows.size(); i++)
  1424. {
  1425. ImGuiWindow* window = g.Windows[i];
  1426. if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is visible its parent will add it
  1427. if (window->Visible)
  1428. continue;
  1429. AddWindowToSortedBuffer(window, sorted_windows);
  1430. }
  1431. IM_ASSERT(g.Windows.size() == sorted_windows.size()); // We done something wrong
  1432. g.Windows.swap(sorted_windows);
  1433. // Clear data for next frame
  1434. g.IO.MouseWheel = 0.0f;
  1435. memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
  1436. }
  1437. // Skip render altogether if alpha is 0.0
  1438. // Note that vertex buffers have been created, so it is best practice that you don't call Begin/End in the first place.
  1439. if (g.Style.Alpha > 0.0f)
  1440. {
  1441. // Render tooltip
  1442. if (g.Tooltip[0])
  1443. {
  1444. // Use a dummy window to render the tooltip
  1445. ImGui::BeginTooltip();
  1446. ImGui::TextUnformatted(g.Tooltip);
  1447. ImGui::EndTooltip();
  1448. }
  1449. // Gather windows to render
  1450. g.RenderDrawLists.resize(0);
  1451. for (size_t i = 0; i != g.Windows.size(); i++)
  1452. {
  1453. ImGuiWindow* window = g.Windows[i];
  1454. if (window->Visible && (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) == 0)
  1455. window->AddToRenderList();
  1456. }
  1457. for (size_t i = 0; i != g.Windows.size(); i++)
  1458. {
  1459. ImGuiWindow* window = g.Windows[i];
  1460. if (window->Visible && (window->Flags & ImGuiWindowFlags_Tooltip))
  1461. window->AddToRenderList();
  1462. }
  1463. // Render
  1464. if (!g.RenderDrawLists.empty())
  1465. g.IO.RenderDrawListsFn(&g.RenderDrawLists[0], (int)g.RenderDrawLists.size());
  1466. g.RenderDrawLists.resize(0);
  1467. }
  1468. }
  1469. // Find the optional ## from which we stop displaying text.
  1470. static const char* FindTextDisplayEnd(const char* text, const char* text_end = NULL)
  1471. {
  1472. const char* text_display_end = text;
  1473. while ((!text_end || text_display_end < text_end) && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#'))
  1474. text_display_end++;
  1475. return text_display_end;
  1476. }
  1477. // Log ImGui display into text output (tty or file or clipboard)
  1478. static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end)
  1479. {
  1480. ImGuiState& g = GImGui;
  1481. ImGuiWindow* window = GetCurrentWindow();
  1482. if (!text_end)
  1483. text_end = FindTextDisplayEnd(text, text_end);
  1484. const bool log_new_line = ref_pos.y > window->DC.LogLineHeight+1;
  1485. window->DC.LogLineHeight = ref_pos.y;
  1486. const char* text_remaining = text;
  1487. const int tree_depth = window->DC.TreeDepth;
  1488. while (true)
  1489. {
  1490. const char* line_end = text_remaining;
  1491. while (line_end < text_end)
  1492. if (*line_end == '\n')
  1493. break;
  1494. else
  1495. line_end++;
  1496. if (line_end >= text_end)
  1497. line_end = NULL;
  1498. const bool is_first_line = (text == text_remaining);
  1499. bool is_last_line = false;
  1500. if (line_end == NULL)
  1501. {
  1502. is_last_line = true;
  1503. line_end = text_end;
  1504. }
  1505. if (line_end != NULL && !(is_last_line && (line_end - text_remaining)==0))
  1506. {
  1507. const int char_count = (int)(line_end - text_remaining);
  1508. if (g.LogFile)
  1509. {
  1510. if (log_new_line || !is_first_line)
  1511. fprintf(g.LogFile, "\n%*s%.*s", tree_depth*4, "", char_count, text_remaining);
  1512. else
  1513. fprintf(g.LogFile, " %.*s", char_count, text_remaining);
  1514. }
  1515. else
  1516. {
  1517. if (log_new_line || !is_first_line)
  1518. g.LogClipboard->append("\n%*s%.*s", tree_depth*4, "", char_count, text_remaining);
  1519. else
  1520. g.LogClipboard->append(" %.*s", char_count, text_remaining);
  1521. }
  1522. }
  1523. if (is_last_line)
  1524. break;
  1525. text_remaining = line_end + 1;
  1526. }
  1527. }
  1528. static float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
  1529. {
  1530. if (wrap_pos_x < 0.0f)
  1531. return 0.0f;
  1532. ImGuiWindow* window = GetCurrentWindow();
  1533. if (wrap_pos_x == 0.0f)
  1534. wrap_pos_x = ImGui::GetContentRegionMax().x;
  1535. if (wrap_pos_x > 0.0f)
  1536. wrap_pos_x += window->Pos.x; // wrap_pos_x is provided is window local space
  1537. const float wrap_width = wrap_pos_x > 0.0f ? ImMax(wrap_pos_x - pos.x, 0.00001f) : 0.0f;
  1538. return wrap_width;
  1539. }
  1540. // Internal ImGui function to render text (called from ImGui::Text(), ImGui::TextUnformatted(), etc.)
  1541. // RenderText() calls ImDrawList::AddText() calls ImBitmapFont::RenderText()
  1542. static void RenderText(ImVec2 pos, const char* text, const char* text_end, bool hide_text_after_hash, float wrap_width)
  1543. {
  1544. ImGuiState& g = GImGui;
  1545. ImGuiWindow* window = GetCurrentWindow();
  1546. // Hide anything after a '##' string
  1547. const char* text_display_end;
  1548. if (hide_text_after_hash)
  1549. {
  1550. text_display_end = FindTextDisplayEnd(text, text_end);
  1551. }
  1552. else
  1553. {
  1554. if (!text_end)
  1555. text_end = text + strlen(text); // FIXME-OPT
  1556. text_display_end = text_end;
  1557. }
  1558. const int text_len = (int)(text_display_end - text);
  1559. if (text_len > 0)
  1560. {
  1561. // Render
  1562. window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text + text_len, wrap_width);
  1563. // Log as text. We split text into individual lines to add current tree level padding
  1564. if (g.LogEnabled)
  1565. LogText(pos, text, text_display_end);
  1566. }
  1567. }
  1568. // Render a rectangle shaped with optional rounding and borders
  1569. static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding)
  1570. {
  1571. ImGuiWindow* window = GetCurrentWindow();
  1572. window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding);
  1573. if (border && (window->Flags & ImGuiWindowFlags_ShowBorders))
  1574. {
  1575. // FIXME: This is the best I've found that works on multiple renderer/back ends. Rather dodgy.
  1576. const float offset = GImGui.IO.PixelCenterOffset;
  1577. window->DrawList->AddRect(p_min+ImVec2(1.5f-offset,1.5f-offset), p_max+ImVec2(1.0f-offset*2,1.0f-offset*2), window->Color(ImGuiCol_BorderShadow), rounding);
  1578. window->DrawList->AddRect(p_min+ImVec2(0.5f-offset,0.5f-offset), p_max+ImVec2(0.0f-offset*2,0.0f-offset*2), window->Color(ImGuiCol_Border), rounding);
  1579. }
  1580. }
  1581. // Render a triangle to denote expanded/collapsed state
  1582. static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale, bool shadow)
  1583. {
  1584. ImGuiWindow* window = GetCurrentWindow();
  1585. const float h = window->FontSize() * 1.00f;
  1586. const float r = h * 0.40f * scale;
  1587. ImVec2 center = p_min + ImVec2(h*0.50f, h*0.50f*scale);
  1588. ImVec2 a, b, c;
  1589. if (open)
  1590. {
  1591. center.y -= r*0.25f;
  1592. a = center + ImVec2(0,1)*r;
  1593. b = center + ImVec2(-0.866f,-0.5f)*r;
  1594. c = center + ImVec2(0.866f,-0.5f)*r;
  1595. }
  1596. else
  1597. {
  1598. a = center + ImVec2(1,0)*r;
  1599. b = center + ImVec2(-0.500f,0.866f)*r;
  1600. c = center + ImVec2(-0.500f,-0.866f)*r;
  1601. }
  1602. if (shadow && (window->Flags & ImGuiWindowFlags_ShowBorders) != 0)
  1603. window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow));
  1604. window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Border));
  1605. }
  1606. // Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
  1607. // CalcTextSize("") should return ImVec2(0.0f, GImGui.FontSize)
  1608. ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width)
  1609. {
  1610. ImGuiWindow* window = GetCurrentWindow();
  1611. const char* text_display_end;
  1612. if (hide_text_after_double_hash)
  1613. text_display_end = FindTextDisplayEnd(text, text_end); // Hide anything after a '##' string
  1614. else
  1615. text_display_end = text_end;
  1616. const ImVec2 text_size = window->Font()->CalcTextSizeA(window->FontSize(), FLT_MAX, wrap_width, text, text_display_end, NULL);
  1617. return text_size;
  1618. }
  1619. // Find window given position, search front-to-back
  1620. static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs)
  1621. {
  1622. ImGuiState& g = GImGui;
  1623. for (int i = (int)g.Windows.size()-1; i >= 0; i--)
  1624. {
  1625. ImGuiWindow* window = g.Windows[(size_t)i];
  1626. if (!window->Visible)
  1627. continue;
  1628. if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
  1629. continue;
  1630. ImGuiAabb bb(window->Pos - g.Style.TouchExtraPadding, window->Pos+window->Size + g.Style.TouchExtraPadding);
  1631. if (bb.Contains(pos))
  1632. return window;
  1633. }
  1634. return NULL;
  1635. }
  1636. // Test if mouse cursor is hovering given aabb
  1637. // NB- Box is clipped by our current clip setting
  1638. // NB- Expand the aabb to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
  1639. static bool IsMouseHoveringBox(const ImGuiAabb& box)
  1640. {
  1641. ImGuiState& g = GImGui;
  1642. ImGuiWindow* window = GetCurrentWindow();
  1643. // Clip
  1644. ImGuiAabb box_clipped = box;
  1645. if (!window->ClipRectStack.empty())
  1646. {
  1647. const ImVec4 clip_rect = window->ClipRectStack.back();
  1648. box_clipped.Clip(ImGuiAabb(ImVec2(clip_rect.x, clip_rect.y), ImVec2(clip_rect.z, clip_rect.w)));
  1649. }
  1650. // Expand for touch input
  1651. const ImGuiAabb box_for_touch(box_clipped.Min - g.Style.TouchExtraPadding, box_clipped.Max + g.Style.TouchExtraPadding);
  1652. return box_for_touch.Contains(g.IO.MousePos);
  1653. }
  1654. bool ImGui::IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max)
  1655. {
  1656. return IsMouseHoveringBox(ImGuiAabb(box_min, box_max));
  1657. }
  1658. bool ImGui::IsMouseHoveringWindow()
  1659. {
  1660. ImGuiState& g = GImGui;
  1661. ImGuiWindow* window = GetCurrentWindow();
  1662. return g.HoveredWindow == window;
  1663. }
  1664. bool ImGui::IsMouseHoveringAnyWindow()
  1665. {
  1666. ImGuiState& g = GImGui;
  1667. return g.HoveredWindow != NULL;
  1668. }
  1669. bool ImGui::IsPosHoveringAnyWindow(const ImVec2& pos)
  1670. {
  1671. return FindHoveredWindow(pos, false) != NULL;
  1672. }
  1673. static bool IsKeyPressedMap(ImGuiKey key, bool repeat)
  1674. {
  1675. ImGuiState& g = GImGui;
  1676. const int key_index = g.IO.KeyMap[key];
  1677. return ImGui::IsKeyPressed(key_index, repeat);
  1678. }
  1679. bool ImGui::IsKeyPressed(int key_index, bool repeat)
  1680. {
  1681. ImGuiState& g = GImGui;
  1682. IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
  1683. const float t = g.IO.KeysDownTime[key_index];
  1684. if (t == 0.0f)
  1685. return true;
  1686. // FIXME: Repeat rate should be provided elsewhere?
  1687. const float KEY_REPEAT_DELAY = 0.250f;
  1688. const float KEY_REPEAT_RATE = 0.020f;
  1689. if (repeat && t > KEY_REPEAT_DELAY)
  1690. 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))
  1691. return true;
  1692. return false;
  1693. }
  1694. bool ImGui::IsMouseClicked(int button, bool repeat)
  1695. {
  1696. ImGuiState& g = GImGui;
  1697. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  1698. const float t = g.IO.MouseDownTime[button];
  1699. if (t == 0.0f)
  1700. return true;
  1701. // FIXME: Repeat rate should be provided elsewhere?
  1702. const float MOUSE_REPEAT_DELAY = 0.250f;
  1703. const float MOUSE_REPEAT_RATE = 0.020f;
  1704. if (repeat && t > MOUSE_REPEAT_DELAY)
  1705. 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))
  1706. return true;
  1707. return false;
  1708. }
  1709. bool ImGui::IsMouseDoubleClicked(int button)
  1710. {
  1711. ImGuiState& g = GImGui;
  1712. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  1713. return g.IO.MouseDoubleClicked[button];
  1714. }
  1715. ImVec2 ImGui::GetMousePos()
  1716. {
  1717. return GImGui.IO.MousePos;
  1718. }
  1719. bool ImGui::IsItemHovered()
  1720. {
  1721. ImGuiWindow* window = GetCurrentWindow();
  1722. return window->DC.LastItemHovered;
  1723. }
  1724. bool ImGui::IsItemFocused()
  1725. {
  1726. ImGuiWindow* window = GetCurrentWindow();
  1727. return window->DC.LastItemFocused;
  1728. }
  1729. ImVec2 ImGui::GetItemBoxMin()
  1730. {
  1731. ImGuiWindow* window = GetCurrentWindow();
  1732. return window->DC.LastItemAabb.Min;
  1733. }
  1734. ImVec2 ImGui::GetItemBoxMax()
  1735. {
  1736. ImGuiWindow* window = GetCurrentWindow();
  1737. return window->DC.LastItemAabb.Max;
  1738. }
  1739. // Tooltip is stored and turned into a BeginTooltip()/EndTooltip() sequence at the end of the frame. Each call override previous value.
  1740. void ImGui::SetTooltipV(const char* fmt, va_list args)
  1741. {
  1742. ImGuiState& g = GImGui;
  1743. ImFormatStringV(g.Tooltip, IM_ARRAYSIZE(g.Tooltip), fmt, args);
  1744. }
  1745. void ImGui::SetTooltip(const char* fmt, ...)
  1746. {
  1747. va_list args;
  1748. va_start(args, fmt);
  1749. SetTooltipV(fmt, args);
  1750. va_end(args);
  1751. }
  1752. // Position new window if they don't have position setting in the .ini file. Rarely useful (used by the sample applications).
  1753. void ImGui::SetNewWindowDefaultPos(const ImVec2& pos)
  1754. {
  1755. ImGuiState& g = GImGui;
  1756. g.NewWindowDefaultPos = pos;
  1757. }
  1758. float ImGui::GetTime()
  1759. {
  1760. return GImGui.Time;
  1761. }
  1762. int ImGui::GetFrameCount()
  1763. {
  1764. return GImGui.FrameCount;
  1765. }
  1766. static ImGuiWindow* FindWindow(const char* name)
  1767. {
  1768. ImGuiState& g = GImGui;
  1769. for (size_t i = 0; i != g.Windows.size(); i++)
  1770. if (strcmp(g.Windows[i]->Name, name) == 0)
  1771. return g.Windows[i];
  1772. return NULL;
  1773. }
  1774. void ImGui::BeginTooltip()
  1775. {
  1776. ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), 0.9f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_Tooltip);
  1777. }
  1778. void ImGui::EndTooltip()
  1779. {
  1780. IM_ASSERT(GetCurrentWindow()->Flags & ImGuiWindowFlags_Tooltip);
  1781. ImGui::End();
  1782. }
  1783. void ImGui::BeginChild(const char* str_id, ImVec2 size, bool border, ImGuiWindowFlags extra_flags)
  1784. {
  1785. ImGuiState& g = GImGui;
  1786. ImGuiWindow* window = GetCurrentWindow();
  1787. ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_ChildWindow;
  1788. const ImVec2 content_max = window->Pos + ImGui::GetContentRegionMax();
  1789. const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos();
  1790. if (size.x <= 0.0f)
  1791. {
  1792. if (size.x == 0.0f)
  1793. flags |= ImGuiWindowFlags_ChildWindowAutoFitX;
  1794. size.x = ImMax(content_max.x - cursor_pos.x, g.Style.WindowMinSize.x) - fabsf(size.x);
  1795. }
  1796. if (size.y <= 0.0f)
  1797. {
  1798. if (size.y == 0.0f)
  1799. flags |= ImGuiWindowFlags_ChildWindowAutoFitY;
  1800. size.y = ImMax(content_max.y - cursor_pos.y, g.Style.WindowMinSize.y) - fabsf(size.y);
  1801. }
  1802. if (border)
  1803. flags |= ImGuiWindowFlags_ShowBorders;
  1804. flags |= extra_flags;
  1805. char title[256];
  1806. ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s", window->Name, str_id);
  1807. const float alpha = (flags & ImGuiWindowFlags_ComboBox) ? 1.0f : 0.0f;
  1808. ImGui::Begin(title, NULL, size, alpha, flags);
  1809. if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
  1810. g.CurrentWindow->Flags &= ~ImGuiWindowFlags_ShowBorders;
  1811. }
  1812. void ImGui::EndChild()
  1813. {
  1814. ImGuiWindow* window = GetCurrentWindow();
  1815. if (window->Flags & ImGuiWindowFlags_ComboBox)
  1816. {
  1817. ImGui::End();
  1818. }
  1819. else
  1820. {
  1821. // When using auto-filling child window, we don't provide the width/height to ItemSize so that it doesn't feed back into automatic size-fitting.
  1822. ImVec2 sz = ImGui::GetWindowSize();
  1823. if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitX)
  1824. sz.x = 0;
  1825. if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitY)
  1826. sz.y = 0;
  1827. ImGui::End();
  1828. ItemSize(sz);
  1829. }
  1830. }
  1831. // Push a new ImGui window to add widgets to. This can be called multiple times with the same window to append contents
  1832. bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWindowFlags flags)
  1833. {
  1834. ImGuiState& g = GImGui;
  1835. const ImGuiStyle& style = g.Style;
  1836. IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
  1837. ImGuiWindow* window = FindWindow(name);
  1838. if (!window)
  1839. {
  1840. // Create window the first time, and load settings
  1841. if (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip))
  1842. {
  1843. // Tooltip and child windows don't store settings
  1844. window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow));
  1845. new(window) ImGuiWindow(name, ImVec2(0,0), size);
  1846. }
  1847. else
  1848. {
  1849. // Normal windows store settings in .ini file
  1850. ImGuiIniData* settings = FindWindowSettings(name);
  1851. if (settings && ImLength(settings->Size) > 0.0f && !(flags & ImGuiWindowFlags_NoResize))// && ImLengthsize) == 0.0f)
  1852. size = settings->Size;
  1853. window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow));
  1854. new(window) ImGuiWindow(name, g.NewWindowDefaultPos, size);
  1855. if (settings->Pos.x != FLT_MAX)
  1856. {
  1857. window->PosFloat = settings->Pos;
  1858. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  1859. window->Collapsed = settings->Collapsed;
  1860. }
  1861. }
  1862. g.Windows.push_back(window);
  1863. }
  1864. window->Flags = (ImGuiWindowFlags)flags;
  1865. g.CurrentWindowStack.push_back(window);
  1866. g.CurrentWindow = window;
  1867. // Find root
  1868. size_t root_idx = g.CurrentWindowStack.size() - 1;
  1869. while (root_idx > 0)
  1870. {
  1871. if ((g.CurrentWindowStack[root_idx]->Flags & ImGuiWindowFlags_ChildWindow) == 0)
  1872. break;
  1873. root_idx--;
  1874. }
  1875. window->RootWindow = g.CurrentWindowStack[root_idx];
  1876. // Default alpha
  1877. if (fill_alpha < 0.0f)
  1878. fill_alpha = style.WindowFillAlphaDefault;
  1879. // When reusing window again multiple times a frame, just append content (don't need to setup again)
  1880. const int current_frame = ImGui::GetFrameCount();
  1881. const bool first_begin_of_the_frame = (window->LastFrameDrawn != current_frame);
  1882. if (first_begin_of_the_frame)
  1883. {
  1884. window->DrawList->Clear();
  1885. window->Visible = true;
  1886. // New windows appears in front
  1887. if (window->LastFrameDrawn < current_frame - 1)
  1888. {
  1889. FocusWindow(window);
  1890. if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  1891. {
  1892. // Hide for 1 frame while resizing
  1893. window->AutoFitFrames = 2;
  1894. window->AutoFitOnlyGrows = false;
  1895. window->Visible = false;
  1896. }
  1897. }
  1898. window->LastFrameDrawn = current_frame;
  1899. window->ClipRectStack.resize(0);
  1900. if (flags & ImGuiWindowFlags_ChildWindow)
  1901. {
  1902. ImGuiWindow* parent_window = g.CurrentWindowStack[g.CurrentWindowStack.size()-2];
  1903. parent_window->DC.ChildWindows.push_back(window);
  1904. window->Pos = window->PosFloat = parent_window->DC.CursorPos;
  1905. window->SizeFull = size;
  1906. }
  1907. // Outer clipping rectangle
  1908. if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox))
  1909. PushClipRect(g.CurrentWindowStack[g.CurrentWindowStack.size()-2]->ClipRectStack.back());
  1910. else
  1911. PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y));
  1912. // Seed ID stack with our window pointer
  1913. window->IDStack.resize(0);
  1914. ImGui::PushID(window);
  1915. // Move window (at the beginning of the frame to avoid lag)
  1916. const ImGuiID move_id = window->GetID("#MOVE");
  1917. RegisterAliveId(move_id);
  1918. if (g.ActiveId == move_id)
  1919. {
  1920. if (g.IO.MouseDown[0])
  1921. {
  1922. if (!(window->Flags & ImGuiWindowFlags_NoMove))
  1923. {
  1924. window->PosFloat += g.IO.MouseDelta;
  1925. MarkSettingsDirty();
  1926. }
  1927. FocusWindow(window);
  1928. }
  1929. else
  1930. {
  1931. g.ActiveId = 0;
  1932. }
  1933. }
  1934. // Tooltips always follow mouse
  1935. if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  1936. {
  1937. window->PosFloat = g.IO.MousePos + ImVec2(32,16) - g.Style.FramePadding*2;
  1938. }
  1939. // Clamp into view
  1940. if (!(window->Flags & ImGuiWindowFlags_ChildWindow))
  1941. {
  1942. const ImVec2 pad = ImVec2(window->FontSize()*2.0f, window->FontSize()*2.0f);
  1943. window->PosFloat = ImMax(window->PosFloat + window->Size, pad) - window->Size;
  1944. window->PosFloat = ImMin(window->PosFloat, ImVec2(g.IO.DisplaySize.x, g.IO.DisplaySize.y) - pad);
  1945. window->SizeFull = ImMax(window->SizeFull, pad);
  1946. }
  1947. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  1948. // Default item width
  1949. if (window->Size.x > 0.0f && !(window->Flags & ImGuiWindowFlags_Tooltip) && !(window->Flags & ImGuiWindowFlags_AlwaysAutoResize))
  1950. window->ItemWidthDefault = (float)(int)(window->Size.x * 0.65f);
  1951. else
  1952. window->ItemWidthDefault = 200.0f;
  1953. // Prepare for focus requests
  1954. if (window->FocusIdxAllRequestNext == IM_INT_MAX || window->FocusIdxAllCounter == -1)
  1955. window->FocusIdxAllRequestCurrent = IM_INT_MAX;
  1956. else
  1957. window->FocusIdxAllRequestCurrent = (window->FocusIdxAllRequestNext + (window->FocusIdxAllCounter+1)) % (window->FocusIdxAllCounter+1);
  1958. if (window->FocusIdxTabRequestNext == IM_INT_MAX || window->FocusIdxTabCounter == -1)
  1959. window->FocusIdxTabRequestCurrent = IM_INT_MAX;
  1960. else
  1961. window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext + (window->FocusIdxTabCounter+1)) % (window->FocusIdxTabCounter+1);
  1962. window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1;
  1963. window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = IM_INT_MAX;
  1964. ImGuiAabb title_bar_aabb = window->TitleBarAabb();
  1965. // Apply and ImClamp scrolling
  1966. window->ScrollY = window->NextScrollY;
  1967. window->ScrollY = ImMax(window->ScrollY, 0.0f);
  1968. if (!window->Collapsed && !window->SkipItems)
  1969. window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, (float)window->SizeContentsFit.y - window->SizeFull.y));
  1970. window->NextScrollY = window->ScrollY;
  1971. // At this point we don't have a clipping rectangle setup yet, so we can test and draw in title bar
  1972. // Collapse window by double-clicking on title bar
  1973. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  1974. {
  1975. if (g.HoveredWindow == window && IsMouseHoveringBox(title_bar_aabb) && g.IO.MouseDoubleClicked[0])
  1976. {
  1977. window->Collapsed = !window->Collapsed;
  1978. MarkSettingsDirty();
  1979. FocusWindow(window);
  1980. }
  1981. }
  1982. else
  1983. {
  1984. window->Collapsed = false;
  1985. }
  1986. if (window->Collapsed)
  1987. {
  1988. // Draw title bar only
  1989. window->Size = title_bar_aabb.GetSize();
  1990. window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), g.Style.WindowRounding);
  1991. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  1992. {
  1993. window->DrawList->AddRect(title_bar_aabb.GetTL()+ImVec2(1,1), title_bar_aabb.GetBR()+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), g.Style.WindowRounding);
  1994. window->DrawList->AddRect(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border), g.Style.WindowRounding);
  1995. }
  1996. }
  1997. else
  1998. {
  1999. window->Size = window->SizeFull;
  2000. ImU32 resize_col = 0;
  2001. if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2002. {
  2003. // Tooltip always resize
  2004. if (window->AutoFitFrames > 0)
  2005. {
  2006. window->SizeFull = window->SizeContentsFit + g.Style.WindowPadding - ImVec2(0.0f, g.Style.ItemSpacing.y);
  2007. }
  2008. }
  2009. else
  2010. {
  2011. const ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding);
  2012. if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
  2013. {
  2014. // Don't continuously mark settings as dirty, the size of the window doesn't need to be stored.
  2015. window->SizeFull = size_auto_fit;
  2016. }
  2017. else if (window->AutoFitFrames > 0)
  2018. {
  2019. // Auto-fit only grows during the first few frames
  2020. if (window->AutoFitOnlyGrows)
  2021. window->SizeFull = ImMax(window->SizeFull, size_auto_fit);
  2022. else
  2023. window->SizeFull = size_auto_fit;
  2024. MarkSettingsDirty();
  2025. }
  2026. else if (!(window->Flags & ImGuiWindowFlags_NoResize))
  2027. {
  2028. // Resize grip
  2029. const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
  2030. const ImGuiID resize_id = window->GetID("##RESIZE");
  2031. bool hovered, held;
  2032. ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true);
  2033. resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
  2034. if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0])
  2035. {
  2036. // Manual auto-fit
  2037. window->SizeFull = size_auto_fit;
  2038. window->Size = window->SizeFull;
  2039. MarkSettingsDirty();
  2040. }
  2041. else if (held)
  2042. {
  2043. // Resize
  2044. window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize);
  2045. window->Size = window->SizeFull;
  2046. MarkSettingsDirty();
  2047. }
  2048. }
  2049. // Update aabb immediately so that the rendering below isn't one frame late
  2050. title_bar_aabb = window->TitleBarAabb();
  2051. }
  2052. // Title bar + Window box
  2053. if (fill_alpha > 0.0f)
  2054. {
  2055. if ((window->Flags & ImGuiWindowFlags_ComboBox) != 0)
  2056. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, fill_alpha), 0);
  2057. else
  2058. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, fill_alpha), g.Style.WindowRounding);
  2059. }
  2060. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2061. window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBg), g.Style.WindowRounding, 1|2);
  2062. // Borders
  2063. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  2064. {
  2065. const float rounding = (window->Flags & ImGuiWindowFlags_ComboBox) ? 0.0f : g.Style.WindowRounding;
  2066. window->DrawList->AddRect(window->Pos+ImVec2(1,1), window->Pos+window->Size+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding);
  2067. window->DrawList->AddRect(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_Border), rounding);
  2068. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2069. window->DrawList->AddLine(title_bar_aabb.GetBL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border));
  2070. }
  2071. // Scrollbar
  2072. window->ScrollbarY = (window->SizeContentsFit.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar);
  2073. if (window->ScrollbarY)
  2074. {
  2075. ImGuiAabb scrollbar_bb(window->Aabb().Max.x - style.ScrollBarWidth, title_bar_aabb.Max.y+1, window->Aabb().Max.x, window->Aabb().Max.y-1);
  2076. //window->DrawList->AddLine(scrollbar_bb.GetTL(), scrollbar_bb.GetBL(), g.Colors[ImGuiCol_Border]);
  2077. window->DrawList->AddRectFilled(scrollbar_bb.Min, scrollbar_bb.Max, window->Color(ImGuiCol_ScrollbarBg));
  2078. scrollbar_bb.Expand(ImVec2(-3,-3));
  2079. const float grab_size_y_norm = ImSaturate(window->Size.y / ImMax(window->SizeContentsFit.y, window->Size.y));
  2080. const float grab_size_y = scrollbar_bb.GetHeight() * grab_size_y_norm;
  2081. // Handle input right away (none of the code above is relying on scrolling position)
  2082. bool held = false;
  2083. bool hovered = false;
  2084. if (grab_size_y_norm < 1.0f)
  2085. {
  2086. const ImGuiID scrollbar_id = window->GetID("#SCROLLY");
  2087. ButtonBehaviour(scrollbar_bb, scrollbar_id, &hovered, &held, true);
  2088. if (held)
  2089. {
  2090. g.HoveredId = scrollbar_id;
  2091. const float pos_y_norm = ImSaturate((g.IO.MousePos.y - (scrollbar_bb.Min.y + grab_size_y*0.5f)) / (scrollbar_bb.GetHeight() - grab_size_y)) * (1.0f - grab_size_y_norm);
  2092. window->ScrollY = pos_y_norm * window->SizeContentsFit.y;
  2093. window->NextScrollY = window->ScrollY;
  2094. }
  2095. }
  2096. // Normalized height of the grab
  2097. const float pos_y_norm = ImSaturate(window->ScrollY / ImMax(0.0f, window->SizeContentsFit.y));
  2098. const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab);
  2099. window->DrawList->AddRectFilled(
  2100. ImVec2(scrollbar_bb.Min.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm)),
  2101. ImVec2(scrollbar_bb.Max.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm + grab_size_y_norm)), grab_col);
  2102. }
  2103. // Render resize grip
  2104. // (after the input handling so we don't have a frame of latency)
  2105. if (!(window->Flags & ImGuiWindowFlags_NoResize))
  2106. {
  2107. const float r = style.WindowRounding;
  2108. const ImVec2 br = window->Aabb().GetBR();
  2109. if (r == 0.0f)
  2110. {
  2111. window->DrawList->AddTriangleFilled(br, br-ImVec2(0,14), br-ImVec2(14,0), resize_col);
  2112. }
  2113. else
  2114. {
  2115. // FIXME: We should draw 4 triangles and decide on a size that's not dependant on the rounding size (previously used 18)
  2116. window->DrawList->AddArc(br - ImVec2(r,r), r, resize_col, 6, 9, true);
  2117. window->DrawList->AddTriangleFilled(br+ImVec2(0,-2*r),br+ImVec2(0,-r),br+ImVec2(-r,-r), resize_col);
  2118. window->DrawList->AddTriangleFilled(br+ImVec2(-r,-r), br+ImVec2(-r,0),br+ImVec2(-2*r,0), resize_col);
  2119. }
  2120. }
  2121. }
  2122. // Setup drawing context
  2123. window->DC.ColumnsStartX = window->WindowPadding().x;
  2124. window->DC.ColumnsOffsetX = 0.0f;
  2125. window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.ColumnsStartX + window->DC.ColumnsOffsetX, window->TitleBarHeight() + window->WindowPadding().y) - ImVec2(0.0f, window->ScrollY);
  2126. window->DC.CursorPos = window->DC.CursorStartPos;
  2127. window->DC.CursorPosPrevLine = window->DC.CursorPos;
  2128. window->DC.CurrentLineHeight = window->DC.PrevLineHeight = 0.0f;
  2129. window->DC.LogLineHeight = window->DC.CursorPos.y - 9999.0f;
  2130. window->DC.ChildWindows.resize(0);
  2131. window->DC.ItemWidth.resize(0);
  2132. window->DC.ItemWidth.push_back(window->ItemWidthDefault);
  2133. window->DC.AllowKeyboardFocus.resize(0);
  2134. window->DC.AllowKeyboardFocus.push_back(true);
  2135. window->DC.TextWrapPos.resize(0);
  2136. window->DC.TextWrapPos.push_back(-1.0f); // disabled
  2137. window->DC.ColorEditMode = ImGuiColorEditMode_UserSelect;
  2138. window->DC.ColumnsCurrent = 0;
  2139. window->DC.ColumnsCount = 1;
  2140. window->DC.ColumnsStartPos = window->DC.CursorPos;
  2141. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.ColumnsStartPos.y;
  2142. window->DC.TreeDepth = 0;
  2143. window->DC.StateStorage = &window->StateStorage;
  2144. window->DC.OpenNextNode = -1;
  2145. // Reset contents size for auto-fitting
  2146. window->SizeContentsFit = ImVec2(0.0f, 0.0f);
  2147. if (window->AutoFitFrames > 0)
  2148. window->AutoFitFrames--;
  2149. // Title bar
  2150. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2151. {
  2152. RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true);
  2153. if (open)
  2154. CloseWindowButton(open);
  2155. const ImVec2 text_size = CalcTextSize(name);
  2156. const ImVec2 text_min = window->Pos + style.FramePadding + ImVec2(window->FontSize() + style.ItemInnerSpacing.x, 0.0f);
  2157. const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (open ? (title_bar_aabb.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y + text_size.y);
  2158. const bool clip_title = text_size.x > (text_max.x - text_min.x); // only push a clip rectangle if we need to, because it may turn into a separate draw call
  2159. if (clip_title)
  2160. PushClipRect(ImVec4(text_min.x, text_min.y, text_max.x, text_max.y));
  2161. RenderText(text_min, name);
  2162. if (clip_title)
  2163. PopClipRect();
  2164. }
  2165. }
  2166. else
  2167. {
  2168. // Outer clipping rectangle
  2169. if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox))
  2170. {
  2171. ImGuiWindow* parent_window = g.CurrentWindowStack[g.CurrentWindowStack.size()-2];
  2172. PushClipRect(parent_window->ClipRectStack.back());
  2173. }
  2174. else
  2175. {
  2176. PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y));
  2177. }
  2178. }
  2179. // Inner clipping rectangle
  2180. // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame
  2181. const ImGuiAabb title_bar_aabb = window->TitleBarAabb();
  2182. ImVec4 clip_rect(title_bar_aabb.Min.x+0.5f+window->WindowPadding().x*0.5f, title_bar_aabb.Max.y+0.5f, window->Aabb().Max.x+0.5f-window->WindowPadding().x*0.5f, window->Aabb().Max.y-1.5f);
  2183. if (window->ScrollbarY)
  2184. clip_rect.z -= g.Style.ScrollBarWidth;
  2185. PushClipRect(clip_rect);
  2186. // Clear 'accessed' flag last thing
  2187. if (first_begin_of_the_frame)
  2188. window->Accessed = false;
  2189. // Child window can be out of sight and have "negative" clip windows.
  2190. // Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar).
  2191. if (flags & ImGuiWindowFlags_ChildWindow)
  2192. {
  2193. IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0);
  2194. const ImVec4 clip_rect_t = window->ClipRectStack.back();
  2195. window->Collapsed = (clip_rect_t.x >= clip_rect_t.z || clip_rect_t.y >= clip_rect_t.w);
  2196. // We also hide the window from rendering because we've already added its border to the command list.
  2197. // (we could perform the check earlier in the function but it is simpler at this point)
  2198. if (window->Collapsed)
  2199. window->Visible = false;
  2200. }
  2201. if (g.Style.Alpha <= 0.0f)
  2202. window->Visible = false;
  2203. // Return false if we don't intend to display anything to allow user to perform an early out optimisation
  2204. window->SkipItems = window->Collapsed || (!window->Visible && window->AutoFitFrames == 0);
  2205. return !window->SkipItems;
  2206. }
  2207. void ImGui::End()
  2208. {
  2209. ImGuiState& g = GImGui;
  2210. ImGuiWindow* window = g.CurrentWindow;
  2211. ImGui::Columns(1, "#CloseColumns");
  2212. PopClipRect(); // inner window clip rectangle
  2213. PopClipRect(); // outer window clip rectangle
  2214. // Select window for move/focus when we're done with all our widgets (we only consider non-childs windows here)
  2215. const ImGuiAabb bb(window->Pos, window->Pos+window->Size);
  2216. if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredRootWindow == window && IsMouseHoveringBox(bb) && g.IO.MouseClicked[0])
  2217. g.ActiveId = window->GetID("#MOVE");
  2218. // Stop logging
  2219. if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of logging
  2220. {
  2221. g.LogEnabled = false;
  2222. if (g.LogFile != NULL)
  2223. {
  2224. fprintf(g.LogFile, "\n");
  2225. if (g.LogFile == stdout)
  2226. fflush(g.LogFile);
  2227. else
  2228. fclose(g.LogFile);
  2229. g.LogFile = NULL;
  2230. }
  2231. if (g.LogClipboard->size() > 1)
  2232. {
  2233. g.LogClipboard->append("\n");
  2234. if (g.IO.SetClipboardTextFn)
  2235. g.IO.SetClipboardTextFn(g.LogClipboard->begin());
  2236. g.LogClipboard->clear();
  2237. }
  2238. }
  2239. // Pop
  2240. window->RootWindow = NULL;
  2241. g.CurrentWindowStack.pop_back();
  2242. g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back();
  2243. }
  2244. // Moving window to front
  2245. static void FocusWindow(ImGuiWindow* window)
  2246. {
  2247. ImGuiState& g = GImGui;
  2248. g.FocusedWindow = window;
  2249. for (size_t i = 0; i < g.Windows.size(); i++)
  2250. if (g.Windows[i] == window)
  2251. {
  2252. g.Windows.erase(g.Windows.begin() + i);
  2253. break;
  2254. }
  2255. g.Windows.push_back(window);
  2256. }
  2257. void ImGui::PushItemWidth(float item_width)
  2258. {
  2259. ImGuiWindow* window = GetCurrentWindow();
  2260. item_width = (float)(int)item_width;
  2261. window->DC.ItemWidth.push_back(item_width > 0.0f ? item_width : window->ItemWidthDefault);
  2262. }
  2263. void ImGui::PopItemWidth()
  2264. {
  2265. ImGuiWindow* window = GetCurrentWindow();
  2266. window->DC.ItemWidth.pop_back();
  2267. }
  2268. float ImGui::GetItemWidth()
  2269. {
  2270. ImGuiWindow* window = GetCurrentWindow();
  2271. return window->DC.ItemWidth.back();
  2272. }
  2273. void ImGui::PushAllowKeyboardFocus(bool allow_keyboard_focus)
  2274. {
  2275. ImGuiWindow* window = GetCurrentWindow();
  2276. window->DC.AllowKeyboardFocus.push_back(allow_keyboard_focus);
  2277. }
  2278. void ImGui::PopAllowKeyboardFocus()
  2279. {
  2280. ImGuiWindow* window = GetCurrentWindow();
  2281. window->DC.AllowKeyboardFocus.pop_back();
  2282. }
  2283. void ImGui::PushTextWrapPos(float wrap_x)
  2284. {
  2285. ImGuiWindow* window = GetCurrentWindow();
  2286. window->DC.TextWrapPos.push_back(wrap_x);
  2287. }
  2288. void ImGui::PopTextWrapPos()
  2289. {
  2290. ImGuiWindow* window = GetCurrentWindow();
  2291. window->DC.TextWrapPos.pop_back();
  2292. }
  2293. void ImGui::PushStyleColor(ImGuiCol idx, const ImVec4& col)
  2294. {
  2295. ImGuiState& g = GImGui;
  2296. ImGuiColMod backup;
  2297. backup.Col = idx;
  2298. backup.PreviousValue = g.Style.Colors[idx];
  2299. g.ColorModifiers.push_back(backup);
  2300. g.Style.Colors[idx] = col;
  2301. }
  2302. void ImGui::PopStyleColor(int count)
  2303. {
  2304. ImGuiState& g = GImGui;
  2305. while (count > 0)
  2306. {
  2307. ImGuiColMod& backup = g.ColorModifiers.back();
  2308. g.Style.Colors[backup.Col] = backup.PreviousValue;
  2309. g.ColorModifiers.pop_back();
  2310. count--;
  2311. }
  2312. }
  2313. static float* GetStyleVarFloatAddr(ImGuiStyleVar idx)
  2314. {
  2315. ImGuiState& g = GImGui;
  2316. switch (idx)
  2317. {
  2318. case ImGuiStyleVar_Alpha: return &g.Style.Alpha;
  2319. case ImGuiStyleVar_TreeNodeSpacing: return &g.Style.TreeNodeSpacing;
  2320. case ImGuiStyleVar_ColumnsMinSpacing: return &g.Style.ColumnsMinSpacing;
  2321. }
  2322. return NULL;
  2323. }
  2324. static ImVec2* GetStyleVarVec2Addr(ImGuiStyleVar idx)
  2325. {
  2326. ImGuiState& g = GImGui;
  2327. switch (idx)
  2328. {
  2329. case ImGuiStyleVar_WindowPadding: return &g.Style.WindowPadding;
  2330. case ImGuiStyleVar_FramePadding: return &g.Style.FramePadding;
  2331. case ImGuiStyleVar_ItemSpacing: return &g.Style.ItemSpacing;
  2332. case ImGuiStyleVar_ItemInnerSpacing: return &g.Style.ItemInnerSpacing;
  2333. }
  2334. return NULL;
  2335. }
  2336. void ImGui::PushStyleVar(ImGuiStyleVar idx, float val)
  2337. {
  2338. ImGuiState& g = GImGui;
  2339. float* pvar = GetStyleVarFloatAddr(idx);
  2340. IM_ASSERT(pvar != NULL); // Called wrong function?
  2341. ImGuiStyleMod backup;
  2342. backup.Var = idx;
  2343. backup.PreviousValue = ImVec2(*pvar, 0.0f);
  2344. g.StyleModifiers.push_back(backup);
  2345. *pvar = val;
  2346. }
  2347. void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
  2348. {
  2349. ImGuiState& g = GImGui;
  2350. ImVec2* pvar = GetStyleVarVec2Addr(idx);
  2351. IM_ASSERT(pvar != NULL); // Called wrong function?
  2352. ImGuiStyleMod backup;
  2353. backup.Var = idx;
  2354. backup.PreviousValue = *pvar;
  2355. g.StyleModifiers.push_back(backup);
  2356. *pvar = val;
  2357. }
  2358. void ImGui::PopStyleVar(int count)
  2359. {
  2360. ImGuiState& g = GImGui;
  2361. while (count > 0)
  2362. {
  2363. ImGuiStyleMod& backup = g.StyleModifiers.back();
  2364. if (float* pvar_f = GetStyleVarFloatAddr(backup.Var))
  2365. *pvar_f = backup.PreviousValue.x;
  2366. else if (ImVec2* pvar_v = GetStyleVarVec2Addr(backup.Var))
  2367. *pvar_v = backup.PreviousValue;
  2368. g.StyleModifiers.pop_back();
  2369. count--;
  2370. }
  2371. }
  2372. const char* ImGui::GetStyleColorName(ImGuiCol idx)
  2373. {
  2374. // Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1";
  2375. switch (idx)
  2376. {
  2377. case ImGuiCol_Text: return "Text";
  2378. case ImGuiCol_WindowBg: return "WindowBg";
  2379. case ImGuiCol_Border: return "Border";
  2380. case ImGuiCol_BorderShadow: return "BorderShadow";
  2381. case ImGuiCol_FrameBg: return "FrameBg";
  2382. case ImGuiCol_TitleBg: return "TitleBg";
  2383. case ImGuiCol_TitleBgCollapsed: return "TitleBgCollapsed";
  2384. case ImGuiCol_ScrollbarBg: return "ScrollbarBg";
  2385. case ImGuiCol_ScrollbarGrab: return "ScrollbarGrab";
  2386. case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered";
  2387. case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive";
  2388. case ImGuiCol_ComboBg: return "ComboBg";
  2389. case ImGuiCol_CheckHovered: return "CheckHovered";
  2390. case ImGuiCol_CheckActive: return "CheckActive";
  2391. case ImGuiCol_SliderGrab: return "SliderGrab";
  2392. case ImGuiCol_SliderGrabActive: return "SliderGrabActive";
  2393. case ImGuiCol_Button: return "Button";
  2394. case ImGuiCol_ButtonHovered: return "ButtonHovered";
  2395. case ImGuiCol_ButtonActive: return "ButtonActive";
  2396. case ImGuiCol_Header: return "Header";
  2397. case ImGuiCol_HeaderHovered: return "HeaderHovered";
  2398. case ImGuiCol_HeaderActive: return "HeaderActive";
  2399. case ImGuiCol_Column: return "Column";
  2400. case ImGuiCol_ColumnHovered: return "ColumnHovered";
  2401. case ImGuiCol_ColumnActive: return "ColumnActive";
  2402. case ImGuiCol_ResizeGrip: return "ResizeGrip";
  2403. case ImGuiCol_ResizeGripHovered: return "ResizeGripHovered";
  2404. case ImGuiCol_ResizeGripActive: return "ResizeGripActive";
  2405. case ImGuiCol_CloseButton: return "CloseButton";
  2406. case ImGuiCol_CloseButtonHovered: return "CloseButtonHovered";
  2407. case ImGuiCol_CloseButtonActive: return "CloseButtonActive";
  2408. case ImGuiCol_PlotLines: return "PlotLines";
  2409. case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered";
  2410. case ImGuiCol_PlotHistogram: return "PlotHistogram";
  2411. case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered";
  2412. case ImGuiCol_TextSelectedBg: return "TextSelectedBg";
  2413. case ImGuiCol_TooltipBg: return "TooltipBg";
  2414. }
  2415. IM_ASSERT(0);
  2416. return "Unknown";
  2417. }
  2418. bool ImGui::GetWindowIsFocused()
  2419. {
  2420. ImGuiState& g = GImGui;
  2421. ImGuiWindow* window = GetCurrentWindow();
  2422. return g.FocusedWindow == window;
  2423. }
  2424. float ImGui::GetWindowWidth()
  2425. {
  2426. ImGuiWindow* window = GetCurrentWindow();
  2427. return window->Size.x;
  2428. }
  2429. ImVec2 ImGui::GetWindowPos()
  2430. {
  2431. ImGuiWindow* window = GetCurrentWindow();
  2432. return window->Pos;
  2433. }
  2434. void ImGui::SetWindowPos(const ImVec2& pos)
  2435. {
  2436. ImGuiWindow* window = GetCurrentWindow();
  2437. const ImVec2 old_pos = window->Pos;
  2438. window->PosFloat = pos;
  2439. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  2440. // If 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
  2441. window->DC.CursorPos += (window->Pos - old_pos);
  2442. }
  2443. ImVec2 ImGui::GetWindowSize()
  2444. {
  2445. ImGuiWindow* window = GetCurrentWindow();
  2446. return window->Size;
  2447. }
  2448. void ImGui::SetWindowSize(const ImVec2& size)
  2449. {
  2450. ImGuiWindow* window = GetCurrentWindow();
  2451. if (ImLength(size) < 0.001f)
  2452. {
  2453. window->AutoFitFrames = 2;
  2454. window->AutoFitOnlyGrows = false;
  2455. }
  2456. else
  2457. {
  2458. window->SizeFull = size;
  2459. }
  2460. }
  2461. ImVec2 ImGui::GetContentRegionMax()
  2462. {
  2463. ImGuiWindow* window = GetCurrentWindow();
  2464. ImVec2 m = window->Size - window->WindowPadding();
  2465. if (window->DC.ColumnsCount != 1)
  2466. {
  2467. m.x = GetColumnOffset(window->DC.ColumnsCurrent + 1);
  2468. m.x -= GImGui.Style.WindowPadding.x;
  2469. }
  2470. else
  2471. {
  2472. if (window->ScrollbarY)
  2473. m.x -= GImGui.Style.ScrollBarWidth;
  2474. }
  2475. return m;
  2476. }
  2477. ImVec2 ImGui::GetWindowContentRegionMin()
  2478. {
  2479. ImGuiWindow* window = GetCurrentWindow();
  2480. return ImVec2(0, window->TitleBarHeight()) + window->WindowPadding();
  2481. }
  2482. ImVec2 ImGui::GetWindowContentRegionMax()
  2483. {
  2484. ImGuiWindow* window = GetCurrentWindow();
  2485. ImVec2 m = window->Size - window->WindowPadding();
  2486. if (window->ScrollbarY)
  2487. m.x -= GImGui.Style.ScrollBarWidth;
  2488. return m;
  2489. }
  2490. float ImGui::GetTextLineHeight()
  2491. {
  2492. ImGuiWindow* window = GetCurrentWindow();
  2493. return window->FontSize();
  2494. }
  2495. float ImGui::GetTextLineSpacing()
  2496. {
  2497. ImGuiState& g = GImGui;
  2498. ImGuiWindow* window = GetCurrentWindow();
  2499. return window->FontSize() + g.Style.ItemSpacing.y;
  2500. }
  2501. ImDrawList* ImGui::GetWindowDrawList()
  2502. {
  2503. ImGuiWindow* window = GetCurrentWindow();
  2504. return window->DrawList;
  2505. }
  2506. ImFont* ImGui::GetWindowFont()
  2507. {
  2508. ImGuiWindow* window = GetCurrentWindow();
  2509. return window->Font();
  2510. }
  2511. float ImGui::GetWindowFontSize()
  2512. {
  2513. ImGuiWindow* window = GetCurrentWindow();
  2514. return window->FontSize();
  2515. }
  2516. void ImGui::SetWindowFontScale(float scale)
  2517. {
  2518. ImGuiWindow* window = GetCurrentWindow();
  2519. window->FontWindowScale = scale;
  2520. }
  2521. ImVec2 ImGui::GetCursorPos()
  2522. {
  2523. ImGuiWindow* window = GetCurrentWindow();
  2524. return window->DC.CursorPos - window->Pos;
  2525. }
  2526. void ImGui::SetCursorPos(const ImVec2& pos)
  2527. {
  2528. ImGuiWindow* window = GetCurrentWindow();
  2529. window->DC.CursorPos = window->Pos + pos;
  2530. }
  2531. void ImGui::SetCursorPosX(float x)
  2532. {
  2533. ImGuiWindow* window = GetCurrentWindow();
  2534. window->DC.CursorPos.x = window->Pos.x + x;
  2535. }
  2536. void ImGui::SetCursorPosY(float y)
  2537. {
  2538. ImGuiWindow* window = GetCurrentWindow();
  2539. window->DC.CursorPos.y = window->Pos.y + y;
  2540. }
  2541. ImVec2 ImGui::GetCursorScreenPos()
  2542. {
  2543. ImGuiWindow* window = GetCurrentWindow();
  2544. return window->DC.CursorPos;
  2545. }
  2546. void ImGui::SetScrollPosHere()
  2547. {
  2548. ImGuiWindow* window = GetCurrentWindow();
  2549. window->NextScrollY = (window->DC.CursorPos.y + window->ScrollY) - (window->Pos.y + window->SizeFull.y * 0.5f) - (window->TitleBarHeight() + window->WindowPadding().y);
  2550. }
  2551. void ImGui::SetKeyboardFocusHere(int offset)
  2552. {
  2553. ImGuiWindow* window = GetCurrentWindow();
  2554. window->FocusIdxAllRequestNext = window->FocusIdxAllCounter + 1 + offset;
  2555. window->FocusIdxTabRequestNext = IM_INT_MAX;
  2556. }
  2557. void ImGui::SetTreeStateStorage(ImGuiStorage* tree)
  2558. {
  2559. ImGuiWindow* window = GetCurrentWindow();
  2560. window->DC.StateStorage = tree ? tree : &window->StateStorage;
  2561. }
  2562. ImGuiStorage* ImGui::GetTreeStateStorage()
  2563. {
  2564. ImGuiWindow* window = GetCurrentWindow();
  2565. return window->DC.StateStorage;
  2566. }
  2567. void ImGui::TextV(const char* fmt, va_list args)
  2568. {
  2569. ImGuiWindow* window = GetCurrentWindow();
  2570. if (window->SkipItems)
  2571. return;
  2572. static char buf[1024];
  2573. const char* text_end = buf + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  2574. TextUnformatted(buf, text_end);
  2575. }
  2576. void ImGui::Text(const char* fmt, ...)
  2577. {
  2578. va_list args;
  2579. va_start(args, fmt);
  2580. TextV(fmt, args);
  2581. va_end(args);
  2582. }
  2583. void ImGui::TextColoredV(const ImVec4& col, const char* fmt, va_list args)
  2584. {
  2585. ImGui::PushStyleColor(ImGuiCol_Text, col);
  2586. TextV(fmt, args);
  2587. ImGui::PopStyleColor();
  2588. }
  2589. void ImGui::TextColored(const ImVec4& col, const char* fmt, ...)
  2590. {
  2591. va_list args;
  2592. va_start(args, fmt);
  2593. TextColoredV(col, fmt, args);
  2594. va_end(args);
  2595. }
  2596. void ImGui::TextWrappedV(const char* fmt, va_list args)
  2597. {
  2598. ImGui::PushTextWrapPos(0.0f);
  2599. TextV(fmt, args);
  2600. ImGui::PopTextWrapPos();
  2601. }
  2602. void ImGui::TextWrapped(const char* fmt, ...)
  2603. {
  2604. va_list args;
  2605. va_start(args, fmt);
  2606. TextWrappedV(fmt, args);
  2607. va_end(args);
  2608. }
  2609. void ImGui::TextUnformatted(const char* text, const char* text_end)
  2610. {
  2611. ImGuiState& g = GImGui;
  2612. ImGuiWindow* window = GetCurrentWindow();
  2613. if (window->SkipItems)
  2614. return;
  2615. IM_ASSERT(text != NULL);
  2616. const char* text_begin = text;
  2617. if (text_end == NULL)
  2618. text_end = text + strlen(text); // FIXME-OPT
  2619. const float wrap_pos_x = window->DC.TextWrapPos.back();
  2620. const bool wrap_enabled = wrap_pos_x >= 0.0f;
  2621. if (text_end - text > 2000 && !wrap_enabled)
  2622. {
  2623. // Long text!
  2624. // Perform manual coarse clipping to optimize for long multi-line text
  2625. // From this point we will only compute the width of lines that are visible.
  2626. // Optimization only available when word-wrapping is disabled.
  2627. const char* line = text;
  2628. const float line_height = ImGui::GetTextLineHeight();
  2629. const ImVec2 start_pos = window->DC.CursorPos;
  2630. const ImVec4 clip_rect = window->ClipRectStack.back();
  2631. ImVec2 text_size(0,0);
  2632. if (start_pos.y <= clip_rect.w)
  2633. {
  2634. ImVec2 pos = start_pos;
  2635. // Lines to skip (can't skip when logging text)
  2636. if (!g.LogEnabled)
  2637. {
  2638. int lines_skippable = (int)((clip_rect.y - start_pos.y) / line_height) - 1;
  2639. if (lines_skippable > 0)
  2640. {
  2641. int lines_skipped = 0;
  2642. while (line < text_end && lines_skipped <= lines_skippable)
  2643. {
  2644. const char* line_end = strchr(line, '\n');
  2645. line = line_end + 1;
  2646. lines_skipped++;
  2647. }
  2648. pos.y += lines_skipped * line_height;
  2649. }
  2650. }
  2651. // Lines to render
  2652. if (line < text_end)
  2653. {
  2654. ImGuiAabb line_box(pos, pos + ImVec2(ImGui::GetWindowWidth(), line_height));
  2655. while (line < text_end)
  2656. {
  2657. const char* line_end = strchr(line, '\n');
  2658. if (IsClipped(line_box))
  2659. break;
  2660. const ImVec2 line_size = CalcTextSize(line, line_end, false);
  2661. text_size.x = ImMax(text_size.x, line_size.x);
  2662. RenderText(pos, line, line_end, false);
  2663. if (!line_end)
  2664. line_end = text_end;
  2665. line = line_end + 1;
  2666. line_box.Min.y += line_height;
  2667. line_box.Max.y += line_height;
  2668. pos.y += line_height;
  2669. }
  2670. // Count remaining lines
  2671. int lines_skipped = 0;
  2672. while (line < text_end)
  2673. {
  2674. const char* line_end = strchr(line, '\n');
  2675. if (!line_end)
  2676. line_end = text_end;
  2677. line = line_end + 1;
  2678. lines_skipped++;
  2679. }
  2680. pos.y += lines_skipped * line_height;
  2681. }
  2682. text_size.y += (pos - start_pos).y;
  2683. }
  2684. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size);
  2685. ItemSize(bb);
  2686. ClipAdvance(bb);
  2687. }
  2688. else
  2689. {
  2690. const float wrap_width = wrap_enabled ? CalcWrapWidthForPos(window->DC.CursorPos, wrap_pos_x) : 0.0f;
  2691. const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width);
  2692. ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size);
  2693. ItemSize(bb.GetSize(), &bb.Min);
  2694. if (ClipAdvance(bb))
  2695. return;
  2696. // Render
  2697. // We don't hide text after ## in this end-user function.
  2698. RenderText(bb.Min, text_begin, text_end, false, wrap_width);
  2699. }
  2700. }
  2701. void ImGui::AlignFirstTextHeightToWidgets()
  2702. {
  2703. ImGuiState& g = GImGui;
  2704. ImGuiWindow* window = GetCurrentWindow();
  2705. if (window->SkipItems)
  2706. return;
  2707. // Declare a dummy item size to that upcoming items that are smaller will center-align on the newly expanded line height.
  2708. ItemSize(ImVec2(0, window->FontSize() + g.Style.FramePadding.y*2));
  2709. ImGui::SameLine(0, 0);
  2710. }
  2711. // Add a label+text combo aligned to other label+value widgets
  2712. void ImGui::LabelTextV(const char* label, const char* fmt, va_list args)
  2713. {
  2714. ImGuiState& g = GImGui;
  2715. ImGuiWindow* window = GetCurrentWindow();
  2716. if (window->SkipItems)
  2717. return;
  2718. const ImGuiStyle& style = g.Style;
  2719. const float w = window->DC.ItemWidth.back();
  2720. static char buf[1024];
  2721. const char* text_begin = &buf[0];
  2722. const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  2723. const ImVec2 text_size = CalcTextSize(label);
  2724. const ImGuiAabb value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, text_size.y));
  2725. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + style.ItemInnerSpacing.x, 0.0f) + text_size);
  2726. ItemSize(bb);
  2727. if (ClipAdvance(value_bb))
  2728. return;
  2729. // Render
  2730. RenderText(value_bb.Min, text_begin, text_end);
  2731. RenderText(ImVec2(value_bb.Max.x + style.ItemInnerSpacing.x, value_bb.Min.y), label);
  2732. }
  2733. void ImGui::LabelText(const char* label, const char* fmt, ...)
  2734. {
  2735. va_list args;
  2736. va_start(args, fmt);
  2737. LabelTextV(label, fmt, args);
  2738. va_end(args);
  2739. }
  2740. static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat)
  2741. {
  2742. ImGuiState& g = GImGui;
  2743. ImGuiWindow* window = GetCurrentWindow();
  2744. const bool hovered = (g.HoveredRootWindow == window->RootWindow) && (g.HoveredId == 0) && IsMouseHoveringBox(bb);
  2745. bool pressed = false;
  2746. if (hovered)
  2747. {
  2748. g.HoveredId = id;
  2749. if (allow_key_modifiers || (!g.IO.KeyCtrl && !g.IO.KeyShift))
  2750. {
  2751. if (g.IO.MouseClicked[0])
  2752. {
  2753. g.ActiveId = id;
  2754. }
  2755. else if (repeat && g.ActiveId && ImGui::IsMouseClicked(0, true))
  2756. {
  2757. pressed = true;
  2758. }
  2759. }
  2760. }
  2761. bool held = false;
  2762. if (g.ActiveId == id)
  2763. {
  2764. if (g.IO.MouseDown[0])
  2765. {
  2766. held = true;
  2767. }
  2768. else
  2769. {
  2770. if (hovered)
  2771. pressed = true;
  2772. g.ActiveId = 0;
  2773. }
  2774. }
  2775. if (out_hovered) *out_hovered = hovered;
  2776. if (out_held) *out_held = held;
  2777. return pressed;
  2778. }
  2779. bool ImGui::Button(const char* label, ImVec2 size, bool repeat_when_held)
  2780. {
  2781. ImGuiState& g = GImGui;
  2782. ImGuiWindow* window = GetCurrentWindow();
  2783. if (window->SkipItems)
  2784. return false;
  2785. const ImGuiStyle& style = g.Style;
  2786. const ImGuiID id = window->GetID(label);
  2787. const ImVec2 text_size = CalcTextSize(label);
  2788. if (size.x == 0.0f)
  2789. size.x = text_size.x;
  2790. if (size.y == 0.0f)
  2791. size.y = text_size.y;
  2792. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos+size + style.FramePadding*2.0f);
  2793. ItemSize(bb);
  2794. if (ClipAdvance(bb))
  2795. return false;
  2796. bool hovered, held;
  2797. bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true, repeat_when_held);
  2798. // Render
  2799. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  2800. RenderFrame(bb.Min, bb.Max, col);
  2801. if (size.x < text_size.x || size.y < text_size.y)
  2802. PushClipRect(ImVec4(bb.Min.x+style.FramePadding.x, bb.Min.y+style.FramePadding.y, bb.Max.x, bb.Max.y-style.FramePadding.y)); // Allow extra to draw over the horizontal padding to make it visible that text doesn't fit
  2803. const ImVec2 off = ImVec2(ImMax(0.0f, size.x - text_size.x) * 0.5f, ImMax(0.0f, size.y - text_size.y) * 0.5f);
  2804. RenderText(bb.Min + style.FramePadding + off, label);
  2805. if (size.x < text_size.x || size.y < text_size.y)
  2806. PopClipRect();
  2807. return pressed;
  2808. }
  2809. // Small buttons fits within text without additional spacing.
  2810. bool ImGui::SmallButton(const char* label)
  2811. {
  2812. ImGuiState& g = GImGui;
  2813. ImGuiWindow* window = GetCurrentWindow();
  2814. if (window->SkipItems)
  2815. return false;
  2816. const ImGuiStyle& style = g.Style;
  2817. const ImGuiID id = window->GetID(label);
  2818. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos+CalcTextSize(label) + ImVec2(style.FramePadding.x*2,0));
  2819. ItemSize(bb);
  2820. if (ClipAdvance(bb))
  2821. return false;
  2822. bool hovered, held;
  2823. bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true);
  2824. // Render
  2825. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  2826. RenderFrame(bb.Min, bb.Max, col);
  2827. RenderText(bb.Min + ImVec2(style.FramePadding.x,0), label);
  2828. return pressed;
  2829. }
  2830. // Upper-right button to close a window.
  2831. static bool CloseWindowButton(bool* open)
  2832. {
  2833. ImGuiWindow* window = GetCurrentWindow();
  2834. const ImGuiID id = window->GetID("##CLOSE");
  2835. const float size = window->TitleBarHeight() - 4.0f;
  2836. const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-3.0f-size,2.0f), window->Aabb().GetTR() + ImVec2(-3.0f,2.0f+size));
  2837. bool hovered, held;
  2838. bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true);
  2839. // Render
  2840. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton);
  2841. const ImVec2 center = bb.GetCenter();
  2842. window->DrawList->AddCircleFilled(center, ImMax(2.0f,size*0.5f), col, 16);
  2843. const float cross_extent = (size * 0.5f * 0.7071f) - 1.0f;
  2844. if (hovered)
  2845. {
  2846. window->DrawList->AddLine(center + ImVec2(+cross_extent,+cross_extent), center + ImVec2(-cross_extent,-cross_extent), window->Color(ImGuiCol_Text));
  2847. window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), window->Color(ImGuiCol_Text));
  2848. }
  2849. if (open != NULL && pressed)
  2850. *open = !*open;
  2851. return pressed;
  2852. }
  2853. // Start logging ImGui output to TTY
  2854. void ImGui::LogToTTY(int max_depth)
  2855. {
  2856. ImGuiState& g = GImGui;
  2857. if (g.LogEnabled)
  2858. return;
  2859. g.LogEnabled = true;
  2860. g.LogFile = stdout;
  2861. if (max_depth >= 0)
  2862. g.LogAutoExpandMaxDepth = max_depth;
  2863. }
  2864. // Start logging ImGui output to given file
  2865. void ImGui::LogToFile(int max_depth, const char* filename)
  2866. {
  2867. ImGuiState& g = GImGui;
  2868. if (g.LogEnabled)
  2869. return;
  2870. if (!filename)
  2871. filename = g.IO.LogFilename;
  2872. g.LogEnabled = true;
  2873. g.LogFile = fopen(filename, "at");
  2874. if (max_depth >= 0)
  2875. g.LogAutoExpandMaxDepth = max_depth;
  2876. }
  2877. // Start logging ImGui output to clipboard
  2878. void ImGui::LogToClipboard(int max_depth)
  2879. {
  2880. ImGuiState& g = GImGui;
  2881. if (g.LogEnabled)
  2882. return;
  2883. g.LogEnabled = true;
  2884. g.LogFile = NULL;
  2885. if (max_depth >= 0)
  2886. g.LogAutoExpandMaxDepth = max_depth;
  2887. }
  2888. // Helper to display logging buttons
  2889. void ImGui::LogButtons()
  2890. {
  2891. ImGuiState& g = GImGui;
  2892. ImGui::PushID("LogButtons");
  2893. const bool log_to_tty = ImGui::Button("Log To TTY");
  2894. ImGui::SameLine();
  2895. const bool log_to_file = ImGui::Button("Log To File");
  2896. ImGui::SameLine();
  2897. const bool log_to_clipboard = ImGui::Button("Log To Clipboard");
  2898. ImGui::SameLine();
  2899. ImGui::PushItemWidth(80.0f);
  2900. ImGui::PushAllowKeyboardFocus(false);
  2901. ImGui::SliderInt("Depth", &g.LogAutoExpandMaxDepth, 0, 9, NULL);
  2902. ImGui::PopAllowKeyboardFocus();
  2903. ImGui::PopItemWidth();
  2904. ImGui::PopID();
  2905. // Start logging at the end of the function so that the buttons don't appear in the log
  2906. if (log_to_tty)
  2907. LogToTTY(g.LogAutoExpandMaxDepth);
  2908. if (log_to_file)
  2909. LogToFile(g.LogAutoExpandMaxDepth, g.IO.LogFilename);
  2910. if (log_to_clipboard)
  2911. LogToClipboard(g.LogAutoExpandMaxDepth);
  2912. }
  2913. bool ImGui::CollapsingHeader(const char* label, const char* str_id, const bool display_frame, const bool default_open)
  2914. {
  2915. ImGuiState& g = GImGui;
  2916. ImGuiWindow* window = GetCurrentWindow();
  2917. if (window->SkipItems)
  2918. return false;
  2919. const ImGuiStyle& style = g.Style;
  2920. IM_ASSERT(str_id != NULL || label != NULL);
  2921. if (str_id == NULL)
  2922. str_id = label;
  2923. if (label == NULL)
  2924. label = str_id;
  2925. const ImGuiID id = window->GetID(str_id);
  2926. // We only write to the tree storage if the user clicks
  2927. ImGuiStorage* tree = window->DC.StateStorage;
  2928. bool opened;
  2929. if (window->DC.OpenNextNode != -1)
  2930. {
  2931. opened = window->DC.OpenNextNode > 0;
  2932. tree->SetInt(id, opened);
  2933. window->DC.OpenNextNode = -1;
  2934. }
  2935. else
  2936. {
  2937. opened = tree->GetInt(id, default_open) != 0;
  2938. }
  2939. // Framed header expand a little outside the default padding
  2940. const ImVec2 window_padding = window->WindowPadding();
  2941. const ImVec2 text_size = CalcTextSize(label);
  2942. const ImVec2 pos_min = window->DC.CursorPos;
  2943. const ImVec2 pos_max = window->Pos + GetContentRegionMax();
  2944. ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + text_size.y));
  2945. if (display_frame)
  2946. {
  2947. bb.Min.x -= window_padding.x*0.5f - 1;
  2948. bb.Max.x += window_padding.x*0.5f - 1;
  2949. bb.Max.y += style.FramePadding.y * 2;
  2950. }
  2951. const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + text_size);
  2952. ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit
  2953. // When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behaviour).
  2954. // NB- If we are above max depth we still allow manually opened nodes to be logged.
  2955. if (!display_frame)
  2956. if (g.LogEnabled && window->DC.TreeDepth < g.LogAutoExpandMaxDepth)
  2957. opened = true;
  2958. if (ClipAdvance(bb))
  2959. return opened;
  2960. bool hovered, held;
  2961. bool pressed = ButtonBehaviour(display_frame ? bb : text_bb, id, &hovered, &held, false);
  2962. if (pressed)
  2963. {
  2964. opened = !opened;
  2965. tree->SetInt(id, opened);
  2966. }
  2967. // Render
  2968. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
  2969. if (display_frame)
  2970. {
  2971. // Framed type
  2972. RenderFrame(bb.Min, bb.Max, col, true);
  2973. RenderCollapseTriangle(bb.Min + style.FramePadding, opened, 1.0f, true);
  2974. RenderText(bb.Min + style.FramePadding + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label);
  2975. }
  2976. else
  2977. {
  2978. // Unframed typed for tree nodes
  2979. if ((held && hovered) || hovered)
  2980. RenderFrame(bb.Min, bb.Max, col, false);
  2981. RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f, false);
  2982. RenderText(bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label);
  2983. }
  2984. return opened;
  2985. }
  2986. // Text with a little bullet aligned to the typical tree node.
  2987. void ImGui::BulletTextV(const char* fmt, va_list args)
  2988. {
  2989. ImGuiState& g = GImGui;
  2990. ImGuiWindow* window = GetCurrentWindow();
  2991. if (window->SkipItems)
  2992. return;
  2993. static char buf[1024];
  2994. const char* text_begin = buf;
  2995. const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  2996. const float line_height = window->FontSize();
  2997. const ImVec2 text_size = CalcTextSize(text_begin, text_end);
  2998. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (text_size.x > 0.0f ? (g.Style.FramePadding.x*2) : 0.0f),0) + text_size); // Empty text doesn't add padding
  2999. ItemSize(bb);
  3000. if (ClipAdvance(bb))
  3001. return;
  3002. // Render
  3003. const float bullet_size = line_height*0.15f;
  3004. window->DrawList->AddCircleFilled(bb.Min + ImVec2(g.Style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text));
  3005. RenderText(bb.Min+ImVec2(window->FontSize()+g.Style.FramePadding.x*2,0), text_begin, text_end);
  3006. }
  3007. void ImGui::BulletText(const char* fmt, ...)
  3008. {
  3009. va_list args;
  3010. va_start(args, fmt);
  3011. BulletTextV(fmt, args);
  3012. va_end(args);
  3013. }
  3014. // If returning 'true' the node is open and the user is responsible for calling TreePop
  3015. bool ImGui::TreeNodeV(const char* str_id, const char* fmt, va_list args)
  3016. {
  3017. static char buf[1024];
  3018. ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  3019. if (!str_id || !str_id[0])
  3020. str_id = fmt;
  3021. ImGui::PushID(str_id);
  3022. const bool opened = ImGui::CollapsingHeader(buf, "", false); // do not add to the ID so that TreeNodeSetOpen can access
  3023. ImGui::PopID();
  3024. if (opened)
  3025. ImGui::TreePush(str_id);
  3026. return opened;
  3027. }
  3028. bool ImGui::TreeNode(const char* str_id, const char* fmt, ...)
  3029. {
  3030. va_list args;
  3031. va_start(args, fmt);
  3032. bool s = TreeNodeV(str_id, fmt, args);
  3033. va_end(args);
  3034. return s;
  3035. }
  3036. // If returning 'true' the node is open and the user is responsible for calling TreePop
  3037. bool ImGui::TreeNodeV(const void* ptr_id, const char* fmt, va_list args)
  3038. {
  3039. static char buf[1024];
  3040. ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  3041. if (!ptr_id)
  3042. ptr_id = fmt;
  3043. ImGui::PushID(ptr_id);
  3044. const bool opened = ImGui::CollapsingHeader(buf, "", false);
  3045. ImGui::PopID();
  3046. if (opened)
  3047. ImGui::TreePush(ptr_id);
  3048. return opened;
  3049. }
  3050. bool ImGui::TreeNode(const void* ptr_id, const char* fmt, ...)
  3051. {
  3052. va_list args;
  3053. va_start(args, fmt);
  3054. bool s = TreeNodeV(ptr_id, fmt, args);
  3055. va_end(args);
  3056. return s;
  3057. }
  3058. bool ImGui::TreeNode(const char* str_label_id)
  3059. {
  3060. return TreeNode(str_label_id, "%s", str_label_id);
  3061. }
  3062. void ImGui::OpenNextNode(bool open)
  3063. {
  3064. ImGuiWindow* window = GetCurrentWindow();
  3065. window->DC.OpenNextNode = open ? 1 : 0;
  3066. }
  3067. void ImGui::PushID(const char* str_id)
  3068. {
  3069. ImGuiWindow* window = GetCurrentWindow();
  3070. window->IDStack.push_back(window->GetID(str_id));
  3071. }
  3072. void ImGui::PushID(const void* ptr_id)
  3073. {
  3074. ImGuiWindow* window = GetCurrentWindow();
  3075. window->IDStack.push_back(window->GetID(ptr_id));
  3076. }
  3077. void ImGui::PushID(const int int_id)
  3078. {
  3079. const void* ptr_id = (void*)(intptr_t)int_id;
  3080. ImGuiWindow* window = GetCurrentWindow();
  3081. window->IDStack.push_back(window->GetID(ptr_id));
  3082. }
  3083. void ImGui::PopID()
  3084. {
  3085. ImGuiWindow* window = GetCurrentWindow();
  3086. window->IDStack.pop_back();
  3087. }
  3088. // User can input math operators (e.g. +100) to edit a numerical values.
  3089. // NB: only call right after InputText because we are using its InitialValue storage
  3090. static void ApplyNumericalTextInput(const char* buf, float *v)
  3091. {
  3092. while (*buf == ' ' || *buf == '\t')
  3093. buf++;
  3094. // We don't support '-' op because it would conflict with inputing negative value.
  3095. // Instead you can use +-100 to subtract from an existing value
  3096. char op = buf[0];
  3097. if (op == '+' || op == '*' || op == '/')
  3098. {
  3099. buf++;
  3100. while (*buf == ' ' || *buf == '\t')
  3101. buf++;
  3102. }
  3103. else
  3104. {
  3105. op = 0;
  3106. }
  3107. if (!buf[0])
  3108. return;
  3109. float ref_v = *v;
  3110. if (op)
  3111. if (sscanf(GImGui.InputTextState.InitialText, "%f", &ref_v) < 1)
  3112. return;
  3113. float op_v = 0.0f;
  3114. if (sscanf(buf, "%f", &op_v) < 1)
  3115. return;
  3116. if (op == '+')
  3117. *v = ref_v + op_v;
  3118. else if (op == '*')
  3119. *v = ref_v * op_v;
  3120. else if (op == '/')
  3121. {
  3122. if (op_v == 0.0f)
  3123. return;
  3124. *v = ref_v / op_v;
  3125. }
  3126. else
  3127. *v = op_v;
  3128. }
  3129. // Use power!=1.0 for logarithmic sliders.
  3130. // Adjust display_format to decorate the value with a prefix or a suffix.
  3131. bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format, float power)
  3132. {
  3133. ImGuiState& g = GImGui;
  3134. ImGuiWindow* window = GetCurrentWindow();
  3135. if (window->SkipItems)
  3136. return false;
  3137. const ImGuiStyle& style = g.Style;
  3138. const ImGuiID id = window->GetID(label);
  3139. const float w = window->DC.ItemWidth.back();
  3140. if (!display_format)
  3141. display_format = "%.3f";
  3142. // Parse display precision back from the display format string
  3143. int decimal_precision = 3;
  3144. if (const char* p = strchr(display_format, '%'))
  3145. {
  3146. p++;
  3147. while (*p >= '0' && *p <= '9')
  3148. p++;
  3149. if (*p == '.')
  3150. {
  3151. decimal_precision = atoi(p+1);
  3152. if (decimal_precision < 0 || decimal_precision > 10)
  3153. decimal_precision = 3;
  3154. }
  3155. }
  3156. const ImVec2 text_size = CalcTextSize(label);
  3157. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
  3158. const ImGuiAabb slider_bb(frame_bb.Min+g.Style.FramePadding, frame_bb.Max-g.Style.FramePadding);
  3159. const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x, 0.0f));
  3160. if (IsClipped(slider_bb))
  3161. {
  3162. // NB- we don't use ClipAdvance() in the if() statement because we don't want to submit ItemSize() because we may change into a text edit later which may submit an ItemSize itself
  3163. ItemSize(bb);
  3164. return false;
  3165. }
  3166. const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id);
  3167. const bool is_unbound = v_min == -FLT_MAX || v_min == FLT_MAX || v_max == -FLT_MAX || v_max == FLT_MAX;
  3168. const float grab_size_in_units = 1.0f; // In 'v' units. Probably needs to be parametrized, based on a 'v_step' value? decimal precision?
  3169. float grab_size_in_pixels;
  3170. if (decimal_precision > 0 || is_unbound)
  3171. grab_size_in_pixels = 10.0f;
  3172. else
  3173. grab_size_in_pixels = ImMax(grab_size_in_units * (w / (v_max-v_min+1.0f)), 8.0f); // Integer sliders
  3174. const float slider_effective_w = slider_bb.GetWidth() - grab_size_in_pixels;
  3175. const float slider_effective_x1 = slider_bb.Min.x + grab_size_in_pixels*0.5f;
  3176. const float slider_effective_x2 = slider_bb.Max.x - grab_size_in_pixels*0.5f;
  3177. // For logarithmic sliders that cross over sign boundary we want the exponential increase to be symmetric around 0.0f
  3178. float linear_zero_pos = 0.0f; // 0.0->1.0f
  3179. if (!is_unbound)
  3180. {
  3181. if (v_min * v_max < 0.0f)
  3182. {
  3183. // Different sign
  3184. const float linear_dist_min_to_0 = powf(fabsf(0.0f - v_min), 1.0f/power);
  3185. const float linear_dist_max_to_0 = powf(fabsf(v_max - 0.0f), 1.0f/power);
  3186. linear_zero_pos = linear_dist_min_to_0 / (linear_dist_min_to_0+linear_dist_max_to_0);
  3187. }
  3188. else
  3189. {
  3190. // Same sign
  3191. linear_zero_pos = v_min < 0.0f ? 1.0f : 0.0f;
  3192. }
  3193. }
  3194. const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(slider_bb);
  3195. if (hovered)
  3196. g.HoveredId = id;
  3197. bool start_text_input = false;
  3198. if (tab_focus_requested || (hovered && g.IO.MouseClicked[0]))
  3199. {
  3200. g.ActiveId = id;
  3201. const bool is_ctrl_down = g.IO.KeyCtrl;
  3202. if (tab_focus_requested || is_ctrl_down || is_unbound)
  3203. {
  3204. start_text_input = true;
  3205. g.SliderAsInputTextId = 0;
  3206. }
  3207. }
  3208. // Tabbing or CTRL-clicking through slider turns into an input box
  3209. bool value_changed = false;
  3210. if (start_text_input || (g.ActiveId == id && id == g.SliderAsInputTextId))
  3211. {
  3212. char text_buf[64];
  3213. ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%.*f", decimal_precision, *v);
  3214. g.ActiveId = g.SliderAsInputTextId;
  3215. g.HoveredId = 0;
  3216. window->FocusItemUnregister(); // Our replacement slider will override the focus ID (registered previously to allow for a TAB focus to happen)
  3217. value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll);
  3218. if (g.SliderAsInputTextId == 0)
  3219. {
  3220. // First frame
  3221. IM_ASSERT(g.ActiveId == id); // InputText ID should match the Slider ID (else we'd need to store them both which is also possible)
  3222. g.SliderAsInputTextId = g.ActiveId;
  3223. g.ActiveId = id;
  3224. g.HoveredId = id;
  3225. }
  3226. else
  3227. {
  3228. if (g.ActiveId == g.SliderAsInputTextId)
  3229. g.ActiveId = id;
  3230. else
  3231. g.ActiveId = g.SliderAsInputTextId = 0;
  3232. }
  3233. if (value_changed)
  3234. {
  3235. ApplyNumericalTextInput(text_buf, v);
  3236. }
  3237. return value_changed;
  3238. }
  3239. ItemSize(bb);
  3240. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg));
  3241. // Process clicking on the slider
  3242. if (g.ActiveId == id)
  3243. {
  3244. if (g.IO.MouseDown[0])
  3245. {
  3246. if (!is_unbound)
  3247. {
  3248. const float normalized_pos = ImClamp((g.IO.MousePos.x - slider_effective_x1) / slider_effective_w, 0.0f, 1.0f);
  3249. // Linear slider
  3250. //float new_value = ImLerp(v_min, v_max, normalized_pos);
  3251. // Account for logarithmic scale on both sides of the zero
  3252. float new_value;
  3253. if (normalized_pos < linear_zero_pos)
  3254. {
  3255. // Negative: rescale to the negative range before powering
  3256. float a = 1.0f - (normalized_pos / linear_zero_pos);
  3257. a = powf(a, power);
  3258. new_value = ImLerp(ImMin(v_max,0.f), v_min, a);
  3259. }
  3260. else
  3261. {
  3262. // Positive: rescale to the positive range before powering
  3263. float a;
  3264. if (fabsf(linear_zero_pos - 1.0f) > 1.e-6)
  3265. a = (normalized_pos - linear_zero_pos) / (1.0f - linear_zero_pos);
  3266. else
  3267. a = normalized_pos;
  3268. a = powf(a, power);
  3269. new_value = ImLerp(ImMax(v_min,0.0f), v_max, a);
  3270. }
  3271. // Round past decimal precision
  3272. // 0->1, 1->0.1, 2->0.01, etc.
  3273. // So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0
  3274. const float min_step = 1.0f / powf(10.0f, (float)decimal_precision);
  3275. const float remainder = fmodf(new_value, min_step);
  3276. if (remainder <= min_step*0.5f)
  3277. new_value -= remainder;
  3278. else
  3279. new_value += (min_step - remainder);
  3280. if (*v != new_value)
  3281. {
  3282. *v = new_value;
  3283. value_changed = true;
  3284. }
  3285. }
  3286. }
  3287. else
  3288. {
  3289. g.ActiveId = 0;
  3290. }
  3291. }
  3292. if (!is_unbound)
  3293. {
  3294. // Linear slider
  3295. // const float grab_t = (ImClamp(*v, v_min, v_max) - v_min) / (v_max - v_min);
  3296. // Calculate slider grab positioning
  3297. float grab_t;
  3298. float v_clamped = ImClamp(*v, v_min, v_max);
  3299. if (v_clamped < 0.0f)
  3300. {
  3301. const float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min);
  3302. grab_t = (1.0f - powf(f, 1.0f/power)) * linear_zero_pos;
  3303. }
  3304. else
  3305. {
  3306. const float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min));
  3307. grab_t = linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos);
  3308. }
  3309. // Draw
  3310. const float grab_x = ImLerp(slider_effective_x1, slider_effective_x2, grab_t);
  3311. const ImGuiAabb grab_bb(ImVec2(grab_x-grab_size_in_pixels*0.5f,frame_bb.Min.y+2.0f), ImVec2(grab_x+grab_size_in_pixels*0.5f,frame_bb.Max.y-2.0f));
  3312. window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab));
  3313. }
  3314. // Draw value using user-provided display format so user can add prefix/suffix/decorations to the value.
  3315. char value_buf[64];
  3316. ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
  3317. RenderText(ImVec2(slider_bb.GetCenter().x-CalcTextSize(value_buf).x*0.5f, frame_bb.Min.y + style.FramePadding.y), value_buf);
  3318. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, slider_bb.Min.y), label);
  3319. return value_changed;
  3320. }
  3321. bool ImGui::SliderAngle(const char* label, float* v, float v_degrees_min, float v_degrees_max)
  3322. {
  3323. float v_deg = *v * 360.0f / (2*PI);
  3324. bool value_changed = ImGui::SliderFloat(label, &v_deg, v_degrees_min, v_degrees_max, "%.0f deg", 1.0f);
  3325. *v = v_deg * (2*PI) / 360.0f;
  3326. return value_changed;
  3327. }
  3328. bool ImGui::SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format)
  3329. {
  3330. if (!display_format)
  3331. display_format = "%.0f";
  3332. float v_f = (float)*v;
  3333. bool value_changed = ImGui::SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f);
  3334. *v = (int)v_f;
  3335. return value_changed;
  3336. }
  3337. // Add multiple sliders on 1 line for compact edition of multiple components
  3338. static bool SliderFloatN(const char* label, float v[3], int components, float v_min, float v_max, const char* display_format, float power)
  3339. {
  3340. ImGuiState& g = GImGui;
  3341. ImGuiWindow* window = GetCurrentWindow();
  3342. if (window->SkipItems)
  3343. return false;
  3344. const ImGuiStyle& style = g.Style;
  3345. const float w_full = window->DC.ItemWidth.back();
  3346. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f+style.ItemInnerSpacing.x)*(components-1)) / (float)components));
  3347. 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)));
  3348. bool value_changed = false;
  3349. ImGui::PushID(label);
  3350. ImGui::PushItemWidth(w_item_one);
  3351. for (int i = 0; i < components; i++)
  3352. {
  3353. ImGui::PushID(i);
  3354. if (i + 1 == components)
  3355. {
  3356. ImGui::PopItemWidth();
  3357. ImGui::PushItemWidth(w_item_last);
  3358. }
  3359. value_changed |= ImGui::SliderFloat("##v", &v[i], v_min, v_max, display_format, power);
  3360. ImGui::SameLine(0, 0);
  3361. ImGui::PopID();
  3362. }
  3363. ImGui::PopItemWidth();
  3364. ImGui::PopID();
  3365. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  3366. return value_changed;
  3367. }
  3368. bool ImGui::SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format, float power)
  3369. {
  3370. return SliderFloatN(label, v, 2, v_min, v_max, display_format, power);
  3371. }
  3372. bool ImGui::SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format, float power)
  3373. {
  3374. return SliderFloatN(label, v, 3, v_min, v_max, display_format, power);
  3375. }
  3376. bool ImGui::SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format, float power)
  3377. {
  3378. return SliderFloatN(label, v, 4, v_min, v_max, display_format, power);
  3379. }
  3380. enum ImGuiPlotType
  3381. {
  3382. ImGuiPlotType_Lines,
  3383. ImGuiPlotType_Histogram
  3384. };
  3385. 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)
  3386. {
  3387. ImGuiState& g = GImGui;
  3388. ImGuiWindow* window = GetCurrentWindow();
  3389. if (window->SkipItems)
  3390. return;
  3391. const ImGuiStyle& style = g.Style;
  3392. const ImVec2 text_size = ImGui::CalcTextSize(label);
  3393. if (graph_size.x == 0.0f)
  3394. graph_size.x = window->DC.ItemWidth.back();
  3395. if (graph_size.y == 0.0f)
  3396. graph_size.y = text_size.y;
  3397. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y) + style.FramePadding*2.0f);
  3398. const ImGuiAabb graph_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
  3399. const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0));
  3400. ItemSize(bb);
  3401. if (ClipAdvance(bb))
  3402. return;
  3403. // Determine scale from values if not specified
  3404. if (scale_min == FLT_MAX || scale_max == FLT_MAX)
  3405. {
  3406. float v_min = FLT_MAX;
  3407. float v_max = -FLT_MAX;
  3408. for (int i = 0; i < values_count; i++)
  3409. {
  3410. const float v = values_getter(data, i);
  3411. v_min = ImMin(v_min, v);
  3412. v_max = ImMax(v_max, v);
  3413. }
  3414. if (scale_min == FLT_MAX)
  3415. scale_min = v_min;
  3416. if (scale_max == FLT_MAX)
  3417. scale_max = v_max;
  3418. }
  3419. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg));
  3420. int res_w = ImMin((int)graph_size.x, values_count);
  3421. if (plot_type == ImGuiPlotType_Lines)
  3422. res_w -= 1;
  3423. // Tooltip on hover
  3424. int v_hovered = -1;
  3425. if (IsMouseHoveringBox(graph_bb))
  3426. {
  3427. const float t = ImClamp((g.IO.MousePos.x - graph_bb.Min.x) / (graph_bb.Max.x - graph_bb.Min.x), 0.0f, 0.9999f);
  3428. const int v_idx = (int)(t * (values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0)));
  3429. IM_ASSERT(v_idx >= 0 && v_idx < values_count);
  3430. const float v0 = values_getter(data, (v_idx + values_offset) % values_count);
  3431. const float v1 = values_getter(data, (v_idx + 1 + values_offset) % values_count);
  3432. if (plot_type == ImGuiPlotType_Lines)
  3433. ImGui::SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx+1, v1);
  3434. else if (plot_type == ImGuiPlotType_Histogram)
  3435. ImGui::SetTooltip("%d: %8.4g", v_idx, v0);
  3436. v_hovered = v_idx;
  3437. }
  3438. const float t_step = 1.0f / (float)res_w;
  3439. float v0 = values_getter(data, (0 + values_offset) % values_count);
  3440. float t0 = 0.0f;
  3441. ImVec2 p0 = ImVec2( t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min)) );
  3442. const ImU32 col_base = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram);
  3443. const ImU32 col_hovered = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered);
  3444. for (int n = 0; n < res_w; n++)
  3445. {
  3446. const float t1 = t0 + t_step;
  3447. const int v_idx = (int)(t0 * values_count);
  3448. IM_ASSERT(v_idx >= 0 && v_idx < values_count);
  3449. const float v1 = values_getter(data, (v_idx + values_offset + 1) % values_count);
  3450. const ImVec2 p1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) );
  3451. // NB- Draw calls are merged together by the DrawList system.
  3452. if (plot_type == ImGuiPlotType_Lines)
  3453. window->DrawList->AddLine(ImLerp(graph_bb.Min, graph_bb.Max, p0), ImLerp(graph_bb.Min, graph_bb.Max, p1), v_hovered == v_idx ? col_hovered : col_base);
  3454. else if (plot_type == ImGuiPlotType_Histogram)
  3455. window->DrawList->AddRectFilled(ImLerp(graph_bb.Min, graph_bb.Max, p0), ImLerp(graph_bb.Min, graph_bb.Max, ImVec2(p1.x, 1.0f))+ImVec2(-1,0), v_hovered == v_idx ? col_hovered : col_base);
  3456. t0 = t1;
  3457. p0 = p1;
  3458. }
  3459. // Text overlay
  3460. if (overlay_text)
  3461. RenderText(ImVec2(graph_bb.GetCenter().x - ImGui::CalcTextSize(overlay_text).x*0.5f, frame_bb.Min.y + style.FramePadding.y), overlay_text);
  3462. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, graph_bb.Min.y), label);
  3463. }
  3464. struct ImGuiPlotArrayGetterData
  3465. {
  3466. const float* Values;
  3467. size_t Stride;
  3468. ImGuiPlotArrayGetterData(const float* values, size_t stride) { Values = values; Stride = stride; }
  3469. };
  3470. static float Plot_ArrayGetter(void* data, int idx)
  3471. {
  3472. ImGuiPlotArrayGetterData* plot_data = (ImGuiPlotArrayGetterData*)data;
  3473. const float v = *(float*)(void*)((unsigned char*)plot_data->Values + (size_t)idx * plot_data->Stride);
  3474. return v;
  3475. }
  3476. 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)
  3477. {
  3478. ImGuiPlotArrayGetterData data(values, stride);
  3479. Plot(ImGuiPlotType_Lines, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  3480. }
  3481. 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)
  3482. {
  3483. Plot(ImGuiPlotType_Lines, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  3484. }
  3485. 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)
  3486. {
  3487. ImGuiPlotArrayGetterData data(values, stride);
  3488. Plot(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  3489. }
  3490. 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)
  3491. {
  3492. Plot(ImGuiPlotType_Histogram, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  3493. }
  3494. bool ImGui::Checkbox(const char* label, bool* v)
  3495. {
  3496. ImGuiState& g = GImGui;
  3497. ImGuiWindow* window = GetCurrentWindow();
  3498. if (window->SkipItems)
  3499. return false;
  3500. const ImGuiStyle& style = g.Style;
  3501. const ImGuiID id = window->GetID(label);
  3502. const ImVec2 text_size = CalcTextSize(label);
  3503. const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2, text_size.y + style.FramePadding.y*2));
  3504. ItemSize(check_bb);
  3505. SameLine(0, (int)g.Style.ItemInnerSpacing.x);
  3506. const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + text_size);
  3507. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()));
  3508. const ImGuiAabb total_bb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
  3509. if (ClipAdvance(total_bb))
  3510. return false;
  3511. const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(total_bb);
  3512. const bool pressed = hovered && g.IO.MouseClicked[0];
  3513. if (hovered)
  3514. g.HoveredId = id;
  3515. if (pressed)
  3516. {
  3517. *v = !(*v);
  3518. g.ActiveId = 0; // Clear focus
  3519. }
  3520. RenderFrame(check_bb.Min, check_bb.Max, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg));
  3521. if (*v)
  3522. {
  3523. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  3524. const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f;
  3525. window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), window->Color(ImGuiCol_CheckActive));
  3526. }
  3527. if (g.LogEnabled)
  3528. LogText(text_bb.GetTL(), *v ? "[x]" : "[ ]");
  3529. RenderText(text_bb.GetTL(), label);
  3530. return pressed;
  3531. }
  3532. bool ImGui::CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value)
  3533. {
  3534. bool v = (*flags & flags_value) ? true : false;
  3535. bool pressed = ImGui::Checkbox(label, &v);
  3536. if (v)
  3537. *flags |= flags_value;
  3538. else
  3539. *flags &= ~flags_value;
  3540. return pressed;
  3541. }
  3542. bool ImGui::RadioButton(const char* label, bool active)
  3543. {
  3544. ImGuiState& g = GImGui;
  3545. ImGuiWindow* window = GetCurrentWindow();
  3546. if (window->SkipItems)
  3547. return false;
  3548. const ImGuiStyle& style = g.Style;
  3549. const ImGuiID id = window->GetID(label);
  3550. const ImVec2 text_size = CalcTextSize(label);
  3551. const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2-1, text_size.y + style.FramePadding.y*2-1));
  3552. ItemSize(check_bb);
  3553. SameLine(0, (int)style.ItemInnerSpacing.x);
  3554. const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + text_size);
  3555. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()));
  3556. const ImGuiAabb total_bb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
  3557. if (ClipAdvance(total_bb))
  3558. return false;
  3559. ImVec2 center = check_bb.GetCenter();
  3560. center.x = (float)(int)center.x + 0.5f;
  3561. center.y = (float)(int)center.y + 0.5f;
  3562. const float radius = check_bb.GetHeight() * 0.5f;
  3563. const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(total_bb);
  3564. const bool pressed = hovered && g.IO.MouseClicked[0];
  3565. if (hovered)
  3566. g.HoveredId = id;
  3567. window->DrawList->AddCircleFilled(center, radius, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), 16);
  3568. if (active)
  3569. {
  3570. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  3571. const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f;
  3572. window->DrawList->AddCircleFilled(center, radius-pad, window->Color(ImGuiCol_CheckActive), 16);
  3573. }
  3574. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  3575. {
  3576. window->DrawList->AddCircle(center+ImVec2(1,1), radius, window->Color(ImGuiCol_BorderShadow), 16);
  3577. window->DrawList->AddCircle(center, radius, window->Color(ImGuiCol_Border), 16);
  3578. }
  3579. if (g.LogEnabled)
  3580. LogText(text_bb.GetTL(), active ? "(x)" : "( )");
  3581. RenderText(text_bb.GetTL(), label);
  3582. return pressed;
  3583. }
  3584. bool ImGui::RadioButton(const char* label, int* v, int v_button)
  3585. {
  3586. const bool pressed = ImGui::RadioButton(label, *v == v_button);
  3587. if (pressed)
  3588. {
  3589. *v = v_button;
  3590. }
  3591. return pressed;
  3592. }
  3593. // 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)
  3594. static int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return (int)ImStrlenW(obj->Text); }
  3595. static ImWchar STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return obj->Text[idx]; }
  3596. 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; }
  3597. static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : key; }
  3598. static ImWchar STB_TEXTEDIT_NEWLINE = '\n';
  3599. static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx)
  3600. {
  3601. const ImWchar* text_remaining = NULL;
  3602. const ImVec2 size = obj->Font->CalcTextSizeW(obj->FontSize, FLT_MAX, obj->Text + line_start_idx, NULL, &text_remaining);
  3603. r->x0 = 0.0f;
  3604. r->x1 = size.x;
  3605. r->baseline_y_delta = size.y;
  3606. r->ymin = 0.0f;
  3607. r->ymax = size.y;
  3608. r->num_chars = (int)(text_remaining - (obj->Text + line_start_idx));
  3609. }
  3610. static bool is_white(unsigned int c) { return c==0 || c==' ' || c=='\t' || c=='\r' || c=='\n'; }
  3611. static bool is_separator(unsigned int c) { return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; }
  3612. #define STB_TEXTEDIT_IS_SPACE(CH) ( is_white((unsigned int)CH) || is_separator((unsigned int)CH) )
  3613. static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n) { ImWchar* dst = obj->Text+pos; const ImWchar* src = obj->Text+pos+n; while (ImWchar c = *src++) *dst++ = c; *dst = '\0'; }
  3614. static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len)
  3615. {
  3616. const size_t text_len = ImStrlenW(obj->Text);
  3617. if ((size_t)new_text_len + text_len + 1 >= obj->BufSize)
  3618. return false;
  3619. if (pos != (int)text_len)
  3620. memmove(obj->Text + (size_t)pos + new_text_len, obj->Text + (size_t)pos, (text_len - (size_t)pos) * sizeof(ImWchar));
  3621. memcpy(obj->Text + (size_t)pos, new_text, (size_t)new_text_len * sizeof(ImWchar));
  3622. obj->Text[text_len + (size_t)new_text_len] = '\0';
  3623. return true;
  3624. }
  3625. enum
  3626. {
  3627. STB_TEXTEDIT_K_LEFT = 1 << 16, // keyboard input to move cursor left
  3628. STB_TEXTEDIT_K_RIGHT, // keyboard input to move cursor right
  3629. STB_TEXTEDIT_K_UP, // keyboard input to move cursor up
  3630. STB_TEXTEDIT_K_DOWN, // keyboard input to move cursor down
  3631. STB_TEXTEDIT_K_LINESTART, // keyboard input to move cursor to start of line
  3632. STB_TEXTEDIT_K_LINEEND, // keyboard input to move cursor to end of line
  3633. STB_TEXTEDIT_K_TEXTSTART, // keyboard input to move cursor to start of text
  3634. STB_TEXTEDIT_K_TEXTEND, // keyboard input to move cursor to end of text
  3635. STB_TEXTEDIT_K_DELETE, // keyboard input to delete selection or character under cursor
  3636. STB_TEXTEDIT_K_BACKSPACE, // keyboard input to delete selection or character left of cursor
  3637. STB_TEXTEDIT_K_UNDO, // keyboard input to perform undo
  3638. STB_TEXTEDIT_K_REDO, // keyboard input to perform redo
  3639. STB_TEXTEDIT_K_WORDLEFT, // keyboard input to move cursor left one word
  3640. STB_TEXTEDIT_K_WORDRIGHT, // keyboard input to move cursor right one word
  3641. STB_TEXTEDIT_K_SHIFT = 1 << 17
  3642. };
  3643. #define STB_TEXTEDIT_IMPLEMENTATION
  3644. #include "stb_textedit.h"
  3645. void ImGuiTextEditState::OnKeyPressed(int key)
  3646. {
  3647. stb_textedit_key(this, &StbState, key);
  3648. CursorAnimReset();
  3649. }
  3650. void ImGuiTextEditState::UpdateScrollOffset()
  3651. {
  3652. // Scroll in chunks of quarter width
  3653. const float scroll_x_increment = Width * 0.25f;
  3654. const float cursor_offset_x = Font->CalcTextSizeW(FontSize, FLT_MAX, Text, Text+StbState.cursor, NULL).x;
  3655. if (ScrollX > cursor_offset_x)
  3656. ScrollX = ImMax(0.0f, cursor_offset_x - scroll_x_increment);
  3657. else if (ScrollX < cursor_offset_x - Width)
  3658. ScrollX = cursor_offset_x - Width + scroll_x_increment;
  3659. }
  3660. ImVec2 ImGuiTextEditState::CalcDisplayOffsetFromCharIdx(int i) const
  3661. {
  3662. const ImWchar* text_start = GetTextPointerClippedW(Font, FontSize, Text, ScrollX, NULL);
  3663. const ImWchar* text_end = (Text+i >= text_start) ? Text+i : text_start; // Clip if requested character is outside of display
  3664. IM_ASSERT(text_end >= text_start);
  3665. const ImVec2 offset = Font->CalcTextSizeW(FontSize, Width, text_start, text_end, NULL);
  3666. return offset;
  3667. }
  3668. // [Static]
  3669. const char* ImGuiTextEditState::GetTextPointerClippedA(ImFont* font, float font_size, const char* text, float width, ImVec2* out_text_size)
  3670. {
  3671. if (width <= 0.0f)
  3672. return text;
  3673. const char* text_clipped_end = NULL;
  3674. const ImVec2 text_size = font->CalcTextSizeA(font_size, width, 0.0f, text, NULL, &text_clipped_end);
  3675. if (out_text_size)
  3676. *out_text_size = text_size;
  3677. return text_clipped_end;
  3678. }
  3679. // [Static]
  3680. const ImWchar* ImGuiTextEditState::GetTextPointerClippedW(ImFont* font, float font_size, const ImWchar* text, float width, ImVec2* out_text_size)
  3681. {
  3682. if (width <= 0.0f)
  3683. return text;
  3684. const ImWchar* text_clipped_end = NULL;
  3685. const ImVec2 text_size = font->CalcTextSizeW(font_size, width, text, NULL, &text_clipped_end);
  3686. if (out_text_size)
  3687. *out_text_size = text_size;
  3688. return text_clipped_end;
  3689. }
  3690. // [Static]
  3691. void ImGuiTextEditState::RenderTextScrolledClipped(ImFont* font, float font_size, const char* buf, ImVec2 pos, float width, float scroll_x)
  3692. {
  3693. // NB- We start drawing at character boundary
  3694. ImVec2 text_size;
  3695. const char* text_start = GetTextPointerClippedA(font, font_size, buf, scroll_x, NULL);
  3696. const char* text_end = GetTextPointerClippedA(font, font_size, text_start, width, &text_size);
  3697. // Draw a little clip symbol if we've got text on either left or right of the box
  3698. const char symbol_c = '~';
  3699. const float symbol_w = font_size*0.40f; // FIXME: compute correct width
  3700. const float clip_begin = (text_start > buf && text_start < text_end) ? symbol_w : 0.0f;
  3701. const float clip_end = (text_end[0] != '\0' && text_end > text_start) ? symbol_w : 0.0f;
  3702. // Draw text
  3703. RenderText(pos+ImVec2(clip_begin,0), text_start+(clip_begin>0.0f?1:0), text_end-(clip_end>0.0f?1:0), false);//, &text_params_with_clipping);
  3704. // Draw the clip symbol
  3705. const char s[2] = {symbol_c,'\0'};
  3706. if (clip_begin > 0.0f)
  3707. RenderText(pos, s);
  3708. if (clip_end > 0.0f)
  3709. RenderText(pos+ImVec2(width-clip_end,0.0f), s);
  3710. }
  3711. bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags)
  3712. {
  3713. ImGuiState& g = GImGui;
  3714. ImGuiWindow* window = GetCurrentWindow();
  3715. if (window->SkipItems)
  3716. return false;
  3717. const ImGuiStyle& style = g.Style;
  3718. const float w = window->DC.ItemWidth.back();
  3719. const ImVec2 text_size = CalcTextSize(label);
  3720. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
  3721. ImGui::PushID(label);
  3722. const float button_sz = window->FontSize();
  3723. if (step > 0.0f)
  3724. ImGui::PushItemWidth(ImMax(1.0f, window->DC.ItemWidth.back() - (button_sz+g.Style.FramePadding.x*2.0f+g.Style.ItemInnerSpacing.x)*2));
  3725. char buf[64];
  3726. if (decimal_precision < 0)
  3727. 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?
  3728. else
  3729. ImFormatString(buf, IM_ARRAYSIZE(buf), "%.*f", decimal_precision, *v);
  3730. bool value_changed = false;
  3731. const ImGuiInputTextFlags flags = extra_flags | (ImGuiInputTextFlags_CharsDecimal|ImGuiInputTextFlags_AutoSelectAll);
  3732. if (ImGui::InputText("", buf, IM_ARRAYSIZE(buf), flags))
  3733. {
  3734. ApplyNumericalTextInput(buf, v);
  3735. value_changed = true;
  3736. }
  3737. // Step buttons
  3738. if (step > 0.0f)
  3739. {
  3740. ImGui::PopItemWidth();
  3741. ImGui::SameLine(0, 0);
  3742. if (ImGui::Button("-", ImVec2(button_sz,button_sz), true))
  3743. {
  3744. *v -= g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
  3745. value_changed = true;
  3746. }
  3747. ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
  3748. if (ImGui::Button("+", ImVec2(button_sz,button_sz), true))
  3749. {
  3750. *v += g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
  3751. value_changed = true;
  3752. }
  3753. }
  3754. ImGui::PopID();
  3755. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + g.Style.FramePadding.y), label);
  3756. return value_changed;
  3757. }
  3758. bool ImGui::InputInt(const char* label, int *v, int step, int step_fast, ImGuiInputTextFlags extra_flags)
  3759. {
  3760. float f = (float)*v;
  3761. const bool value_changed = ImGui::InputFloat(label, &f, (float)step, (float)step_fast, 0, extra_flags);
  3762. *v = (int)f;
  3763. return value_changed;
  3764. }
  3765. // Public API to manipulate UTF-8 text
  3766. // We expose UTF-8 to the user (unlike the STB_TEXTEDIT_* functions which are manipulating wchar)
  3767. void ImGuiTextEditCallbackData::DeleteChars(int pos, int bytes_count)
  3768. {
  3769. char* dst = Buf + pos;
  3770. const char* src = Buf + pos + bytes_count;
  3771. while (char c = *src++)
  3772. *dst++ = c;
  3773. *dst = '\0';
  3774. BufDirty = true;
  3775. if (CursorPos + bytes_count >= pos)
  3776. CursorPos -= bytes_count;
  3777. else if (CursorPos >= pos)
  3778. CursorPos = pos;
  3779. SelectionStart = SelectionEnd = CursorPos;
  3780. }
  3781. void ImGuiTextEditCallbackData::InsertChars(int pos, const char* new_text, const char* new_text_end)
  3782. {
  3783. const size_t text_len = strlen(Buf);
  3784. if (!new_text_end)
  3785. new_text_end = new_text + strlen(new_text);
  3786. const size_t new_text_len = (size_t)(new_text_end - new_text);
  3787. if (new_text_len + text_len + 1 >= BufSize)
  3788. return;
  3789. size_t upos = (size_t)pos;
  3790. if (text_len != upos)
  3791. memmove(Buf + upos + new_text_len, Buf + upos, text_len - upos);
  3792. memcpy(Buf + upos, new_text, new_text_len * sizeof(char));
  3793. Buf[text_len + new_text_len] = '\0';
  3794. BufDirty = true;
  3795. if (CursorPos >= pos)
  3796. CursorPos += (int)new_text_len;
  3797. SelectionStart = SelectionEnd = CursorPos;
  3798. }
  3799. // Edit a string of text
  3800. bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, void (*callback)(ImGuiTextEditCallbackData*), void* user_data)
  3801. {
  3802. ImGuiState& g = GImGui;
  3803. ImGuiWindow* window = GetCurrentWindow();
  3804. if (window->SkipItems)
  3805. return false;
  3806. const ImGuiIO& io = g.IO;
  3807. const ImGuiStyle& style = g.Style;
  3808. const ImGuiID id = window->GetID(label);
  3809. const float w = window->DC.ItemWidth.back();
  3810. const ImVec2 text_size = CalcTextSize(label);
  3811. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
  3812. const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x, 0.0f));
  3813. ItemSize(bb);
  3814. if (ClipAdvance(frame_bb))
  3815. return false;
  3816. // NB: we are only allowed to access it if we are the active widget.
  3817. ImGuiTextEditState& edit_state = g.InputTextState;
  3818. const bool is_ctrl_down = io.KeyCtrl;
  3819. const bool is_shift_down = io.KeyShift;
  3820. const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & ImGuiInputTextFlags_CallbackCompletion) == 0); // Using completion callback disable keyboard tabbing
  3821. //const bool align_center = (bool)(flags & ImGuiInputTextFlags_AlignCenter); // FIXME: Unsupported
  3822. const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(frame_bb);
  3823. if (hovered)
  3824. g.HoveredId = id;
  3825. bool select_all = (g.ActiveId != id) && (flags & ImGuiInputTextFlags_AutoSelectAll) != 0;
  3826. if (tab_focus_requested || (hovered && io.MouseClicked[0]))
  3827. {
  3828. if (g.ActiveId != id)
  3829. {
  3830. // Start edition
  3831. // Take a copy of the initial buffer value (both in original UTF-8 format and converted to wchar)
  3832. ImFormatString(edit_state.InitialText, IM_ARRAYSIZE(edit_state.InitialText), "%s", buf);
  3833. ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), buf, NULL);
  3834. edit_state.ScrollX = 0.0f;
  3835. edit_state.Width = w;
  3836. stb_textedit_initialize_state(&edit_state.StbState, true);
  3837. edit_state.CursorAnimReset();
  3838. edit_state.LastCursorPos = ImVec2(-1.f,-1.f);
  3839. if (tab_focus_requested || is_ctrl_down)
  3840. select_all = true;
  3841. }
  3842. g.ActiveId = id;
  3843. }
  3844. else if (io.MouseClicked[0])
  3845. {
  3846. // Release focus when we click outside
  3847. if (g.ActiveId == id)
  3848. {
  3849. g.ActiveId = 0;
  3850. }
  3851. }
  3852. bool value_changed = false;
  3853. bool cancel_edit = false;
  3854. bool enter_pressed = false;
  3855. static char text_tmp_utf8[IM_ARRAYSIZE(edit_state.InitialText)];
  3856. if (g.ActiveId == id)
  3857. {
  3858. // Edit in progress
  3859. edit_state.BufSize = buf_size < IM_ARRAYSIZE(edit_state.Text) ? buf_size : IM_ARRAYSIZE(edit_state.Text);
  3860. edit_state.Font = window->Font();
  3861. edit_state.FontSize = window->FontSize();
  3862. const float mx = g.IO.MousePos.x - frame_bb.Min.x - style.FramePadding.x;
  3863. const float my = window->FontSize()*0.5f; // Flatten mouse because we are doing a single-line edit
  3864. edit_state.UpdateScrollOffset();
  3865. if (select_all || (hovered && io.MouseDoubleClicked[0]))
  3866. {
  3867. edit_state.SelectAll();
  3868. edit_state.SelectedAllMouseLock = true;
  3869. }
  3870. else if (io.MouseClicked[0] && !edit_state.SelectedAllMouseLock)
  3871. {
  3872. stb_textedit_click(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my);
  3873. edit_state.CursorAnimReset();
  3874. }
  3875. else if (io.MouseDown[0] && !edit_state.SelectedAllMouseLock)
  3876. {
  3877. stb_textedit_drag(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my);
  3878. edit_state.CursorAnimReset();
  3879. }
  3880. if (edit_state.SelectedAllMouseLock && !io.MouseDown[0])
  3881. edit_state.SelectedAllMouseLock = false;
  3882. const int k_mask = (is_shift_down ? STB_TEXTEDIT_K_SHIFT : 0);
  3883. if (IsKeyPressedMap(ImGuiKey_LeftArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDLEFT | k_mask : STB_TEXTEDIT_K_LEFT | k_mask); }
  3884. else if (IsKeyPressedMap(ImGuiKey_RightArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDRIGHT | k_mask : STB_TEXTEDIT_K_RIGHT | k_mask); }
  3885. else if (IsKeyPressedMap(ImGuiKey_Home)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); }
  3886. else if (IsKeyPressedMap(ImGuiKey_End)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); }
  3887. else if (IsKeyPressedMap(ImGuiKey_Delete)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); }
  3888. else if (IsKeyPressedMap(ImGuiKey_Backspace)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask); }
  3889. else if (IsKeyPressedMap(ImGuiKey_Enter)) { g.ActiveId = 0; enter_pressed = true; }
  3890. else if (IsKeyPressedMap(ImGuiKey_Escape)) { g.ActiveId = 0; cancel_edit = true; }
  3891. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Z)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_UNDO); }
  3892. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Y)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_REDO); }
  3893. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_A)) { edit_state.SelectAll(); }
  3894. else if (is_ctrl_down && (IsKeyPressedMap(ImGuiKey_X) || IsKeyPressedMap(ImGuiKey_C)))
  3895. {
  3896. // Cut, Copy
  3897. const bool cut = IsKeyPressedMap(ImGuiKey_X);
  3898. if (cut && !edit_state.HasSelection())
  3899. edit_state.SelectAll();
  3900. if (g.IO.SetClipboardTextFn)
  3901. {
  3902. const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0;
  3903. const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : (int)ImStrlenW(edit_state.Text);
  3904. ImTextStrToUtf8(text_tmp_utf8, IM_ARRAYSIZE(text_tmp_utf8), edit_state.Text+ib, edit_state.Text+ie);
  3905. g.IO.SetClipboardTextFn(text_tmp_utf8);
  3906. }
  3907. if (cut)
  3908. stb_textedit_cut(&edit_state, &edit_state.StbState);
  3909. }
  3910. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_V))
  3911. {
  3912. // Paste
  3913. if (g.IO.GetClipboardTextFn)
  3914. {
  3915. if (const char* clipboard = g.IO.GetClipboardTextFn())
  3916. {
  3917. // Remove new-line from pasted buffer
  3918. size_t clipboard_len = strlen(clipboard);
  3919. ImWchar* clipboard_filtered = (ImWchar*)ImGui::MemAlloc((clipboard_len+1) * sizeof(ImWchar));
  3920. int clipboard_filtered_len = 0;
  3921. for (const char* s = clipboard; *s; )
  3922. {
  3923. unsigned int c;
  3924. const int bytes_count = ImTextCharFromUtf8(&c, s, NULL);
  3925. if (bytes_count <= 0)
  3926. break;
  3927. s += bytes_count;
  3928. if (c == '\n' || c == '\r')
  3929. continue;
  3930. if (c >= 0x10000)
  3931. continue;
  3932. clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c;
  3933. }
  3934. clipboard_filtered[clipboard_filtered_len] = 0;
  3935. stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len);
  3936. ImGui::MemFree(clipboard_filtered);
  3937. }
  3938. }
  3939. }
  3940. else if (g.IO.InputCharacters[0])
  3941. {
  3942. // Text input
  3943. for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++)
  3944. {
  3945. const ImWchar c = g.IO.InputCharacters[n];
  3946. if (c)
  3947. {
  3948. // Filter
  3949. if (c < 256 && !isprint((char)(c & 0xFF)) && c != ' ')
  3950. continue;
  3951. if (flags & ImGuiInputTextFlags_CharsDecimal)
  3952. if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
  3953. continue;
  3954. if (flags & ImGuiInputTextFlags_CharsHexadecimal)
  3955. if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
  3956. continue;
  3957. // Insert character!
  3958. edit_state.OnKeyPressed(c);
  3959. }
  3960. }
  3961. }
  3962. edit_state.CursorAnim += g.IO.DeltaTime;
  3963. edit_state.UpdateScrollOffset();
  3964. if (cancel_edit)
  3965. {
  3966. // Restore initial value
  3967. ImFormatString(buf, buf_size, "%s", edit_state.InitialText);
  3968. value_changed = true;
  3969. }
  3970. else
  3971. {
  3972. // Apply new value immediately - copy modified buffer back
  3973. // 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
  3974. // FIXME: We actually always render 'buf' in RenderTextScrolledClipped
  3975. // FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks
  3976. ImTextStrToUtf8(text_tmp_utf8, IM_ARRAYSIZE(text_tmp_utf8), edit_state.Text, NULL);
  3977. // User callback
  3978. if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways)) != 0)
  3979. {
  3980. IM_ASSERT(callback != NULL);
  3981. // The reason we specify the usage semantic (Completion/History) is that Completion needs to disable keyboard TABBING at the moment.
  3982. ImGuiKey event_key = ImGuiKey_COUNT;
  3983. if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && IsKeyPressedMap(ImGuiKey_Tab))
  3984. event_key = ImGuiKey_Tab;
  3985. else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_UpArrow))
  3986. event_key = ImGuiKey_UpArrow;
  3987. else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_DownArrow))
  3988. event_key = ImGuiKey_DownArrow;
  3989. if (event_key != ImGuiKey_COUNT || (flags & ImGuiInputTextFlags_CallbackAlways) != 0)
  3990. {
  3991. ImGuiTextEditCallbackData callback_data;
  3992. callback_data.EventKey = event_key;
  3993. callback_data.Buf = text_tmp_utf8;
  3994. callback_data.BufSize = edit_state.BufSize;
  3995. callback_data.BufDirty = false;
  3996. callback_data.Flags = flags;
  3997. callback_data.UserData = user_data;
  3998. // We have to convert from position from wchar to UTF-8 positions
  3999. const int utf8_cursor_pos = callback_data.CursorPos = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.cursor);
  4000. const int utf8_selection_start = callback_data.SelectionStart = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.select_start);
  4001. const int utf8_selection_end = callback_data.SelectionEnd = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.select_end);
  4002. // Call user code
  4003. callback(&callback_data);
  4004. // Read back what user may have modified
  4005. IM_ASSERT(callback_data.Buf == text_tmp_utf8); // Invalid to modify those fields
  4006. IM_ASSERT(callback_data.BufSize == edit_state.BufSize);
  4007. IM_ASSERT(callback_data.Flags == flags);
  4008. if (callback_data.CursorPos != utf8_cursor_pos) edit_state.StbState.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos);
  4009. if (callback_data.SelectionStart != utf8_selection_start) edit_state.StbState.select_start = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionStart);
  4010. if (callback_data.SelectionEnd != utf8_selection_end) edit_state.StbState.select_end = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionEnd);
  4011. if (callback_data.BufDirty)
  4012. {
  4013. ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), text_tmp_utf8, NULL);
  4014. edit_state.CursorAnimReset();
  4015. }
  4016. }
  4017. }
  4018. if (strcmp(text_tmp_utf8, buf) != 0)
  4019. {
  4020. ImFormatString(buf, buf_size, "%s", text_tmp_utf8);
  4021. value_changed = true;
  4022. }
  4023. }
  4024. }
  4025. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true);
  4026. const ImVec2 font_off_up = ImVec2(0.0f,window->FontSize()+1.0f); // FIXME: those offsets are part of the style or font API
  4027. const ImVec2 font_off_dn = ImVec2(0.0f,2.0f);
  4028. if (g.ActiveId == id)
  4029. {
  4030. // Draw selection
  4031. const int select_begin_idx = edit_state.StbState.select_start;
  4032. const int select_end_idx = edit_state.StbState.select_end;
  4033. if (select_begin_idx != select_end_idx)
  4034. {
  4035. const ImVec2 select_begin_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMin(select_begin_idx,select_end_idx));
  4036. const ImVec2 select_end_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMax(select_begin_idx,select_end_idx));
  4037. window->DrawList->AddRectFilled(select_begin_pos - font_off_up, select_end_pos + font_off_dn, window->Color(ImGuiCol_TextSelectedBg));
  4038. }
  4039. }
  4040. // FIXME: 'align_center' unsupported
  4041. ImGuiTextEditState::RenderTextScrolledClipped(window->Font(), window->FontSize(), buf, frame_bb.Min + style.FramePadding, w, (g.ActiveId == id) ? edit_state.ScrollX : 0.0f);
  4042. if (g.ActiveId == id)
  4043. {
  4044. const ImVec2 cursor_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(edit_state.StbState.cursor);
  4045. // Draw blinking cursor
  4046. if (g.InputTextState.CursorIsVisible())
  4047. window->DrawList->AddRect(cursor_pos - font_off_up + ImVec2(0,2), cursor_pos + font_off_dn - ImVec2(0,3), window->Color(ImGuiCol_Text));
  4048. // Notify OS of text input position
  4049. if (io.ImeSetInputScreenPosFn && ImLength(edit_state.LastCursorPos - cursor_pos) > 0.01f)
  4050. io.ImeSetInputScreenPosFn((int)cursor_pos.x - 1, (int)(cursor_pos.y - window->FontSize())); // -1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety.
  4051. edit_state.LastCursorPos = cursor_pos;
  4052. }
  4053. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  4054. if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0)
  4055. return enter_pressed;
  4056. else
  4057. return value_changed;
  4058. }
  4059. static bool InputFloatN(const char* label, float* v, int components, int decimal_precision)
  4060. {
  4061. ImGuiState& g = GImGui;
  4062. ImGuiWindow* window = GetCurrentWindow();
  4063. if (window->SkipItems)
  4064. return false;
  4065. const ImGuiStyle& style = g.Style;
  4066. const float w_full = window->DC.ItemWidth.back();
  4067. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f+style.ItemInnerSpacing.x) * (components-1)) / (float)components));
  4068. 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)));
  4069. bool value_changed = false;
  4070. ImGui::PushID(label);
  4071. ImGui::PushItemWidth(w_item_one);
  4072. for (int i = 0; i < components; i++)
  4073. {
  4074. ImGui::PushID(i);
  4075. if (i + 1 == components)
  4076. {
  4077. ImGui::PopItemWidth();
  4078. ImGui::PushItemWidth(w_item_last);
  4079. }
  4080. value_changed |= ImGui::InputFloat("##v", &v[i], 0, 0, decimal_precision);
  4081. ImGui::SameLine(0, 0);
  4082. ImGui::PopID();
  4083. }
  4084. ImGui::PopItemWidth();
  4085. ImGui::PopID();
  4086. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4087. return value_changed;
  4088. }
  4089. bool ImGui::InputFloat2(const char* label, float v[2], int decimal_precision)
  4090. {
  4091. return InputFloatN(label, v, 2, decimal_precision);
  4092. }
  4093. bool ImGui::InputFloat3(const char* label, float v[3], int decimal_precision)
  4094. {
  4095. return InputFloatN(label, v, 3, decimal_precision);
  4096. }
  4097. bool ImGui::InputFloat4(const char* label, float v[4], int decimal_precision)
  4098. {
  4099. return InputFloatN(label, v, 4, decimal_precision);
  4100. }
  4101. static bool Combo_ArrayGetter(void* data, int idx, const char** out_text)
  4102. {
  4103. const char** items = (const char**)data;
  4104. if (out_text)
  4105. *out_text = items[idx];
  4106. return true;
  4107. }
  4108. // Combo box helper allowing to pass an array of strings.
  4109. bool ImGui::Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items)
  4110. {
  4111. const bool value_changed = Combo(label, current_item, Combo_ArrayGetter, (void*)items, items_count, popup_height_items);
  4112. return value_changed;
  4113. }
  4114. static bool Combo_StringListGetter(void* data, int idx, const char** out_text)
  4115. {
  4116. // FIXME-OPT: we could precompute the indices to fasten this. But only 1 active combo means the waste is limited.
  4117. const char* items_separated_by_zeros = (const char*)data;
  4118. int items_count = 0;
  4119. const char* p = items_separated_by_zeros;
  4120. while (*p)
  4121. {
  4122. if (idx == items_count)
  4123. break;
  4124. p += strlen(p) + 1;
  4125. items_count++;
  4126. }
  4127. if (!*p)
  4128. return false;
  4129. if (out_text)
  4130. *out_text = p;
  4131. return true;
  4132. }
  4133. // Combo box helper allowing to pass all items in a single string.
  4134. bool ImGui::Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_height_items)
  4135. {
  4136. int items_count = 0;
  4137. const char* p = items_separated_by_zeros;
  4138. while (*p)
  4139. {
  4140. p += strlen(p) + 1;
  4141. items_count++;
  4142. }
  4143. bool value_changed = Combo(label, current_item, Combo_StringListGetter, (void*)items_separated_by_zeros, items_count, popup_height_items);
  4144. return value_changed;
  4145. }
  4146. // Combo box function.
  4147. bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int popup_height_items)
  4148. {
  4149. ImGuiState& g = GImGui;
  4150. ImGuiWindow* window = GetCurrentWindow();
  4151. if (window->SkipItems)
  4152. return false;
  4153. const ImGuiStyle& style = g.Style;
  4154. const ImGuiID id = window->GetID(label);
  4155. const ImVec2 text_size = CalcTextSize(label);
  4156. const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f);
  4157. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(window->DC.ItemWidth.back(), text_size.y) + style.FramePadding*2.0f);
  4158. const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0));
  4159. if (ClipAdvance(frame_bb))
  4160. return false;
  4161. const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb);
  4162. bool value_changed = false;
  4163. ItemSize(frame_bb);
  4164. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg));
  4165. RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, window->Color(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button));
  4166. RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true);
  4167. if (*current_item >= 0 && *current_item < items_count)
  4168. {
  4169. const char* item_text;
  4170. if (items_getter(data, *current_item, &item_text))
  4171. RenderText(frame_bb.Min + style.FramePadding, item_text, NULL, false);
  4172. }
  4173. ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
  4174. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4175. ImGui::PushID((int)id);
  4176. bool menu_toggled = false;
  4177. if (hovered)
  4178. {
  4179. g.HoveredId = id;
  4180. if (g.IO.MouseClicked[0])
  4181. {
  4182. menu_toggled = true;
  4183. g.ActiveComboID = (g.ActiveComboID == id) ? 0 : id;
  4184. }
  4185. }
  4186. if (g.ActiveComboID == id)
  4187. {
  4188. const ImVec2 backup_pos = ImGui::GetCursorPos();
  4189. const float popup_off_x = 0.0f;//g.Style.ItemInnerSpacing.x;
  4190. const float popup_height = (text_size.y + g.Style.ItemSpacing.y) * ImMin(items_count, popup_height_items) + g.Style.WindowPadding.y;
  4191. const ImGuiAabb popup_aabb(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));
  4192. ImGui::SetCursorPos(popup_aabb.Min - window->Pos);
  4193. const ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ((window->Flags & ImGuiWindowFlags_ShowBorders) ? ImGuiWindowFlags_ShowBorders : 0);
  4194. ImGui::BeginChild("#ComboBox", popup_aabb.GetSize(), false, flags);
  4195. ImGuiWindow* child_window = GetCurrentWindow();
  4196. ImGui::Spacing();
  4197. bool combo_item_active = false;
  4198. combo_item_active |= (g.ActiveId == child_window->GetID("#SCROLLY"));
  4199. // Display items
  4200. for (int item_idx = 0; item_idx < items_count; item_idx++)
  4201. {
  4202. const float item_h = child_window->FontSize();
  4203. const float spacing_up = (float)(int)(g.Style.ItemSpacing.y/2);
  4204. const float spacing_dn = g.Style.ItemSpacing.y - spacing_up;
  4205. const ImGuiAabb item_aabb(ImVec2(popup_aabb.Min.x, child_window->DC.CursorPos.y - spacing_up), ImVec2(popup_aabb.Max.x, child_window->DC.CursorPos.y + item_h + spacing_dn));
  4206. const ImGuiID item_id = child_window->GetID((void*)(intptr_t)item_idx);
  4207. bool item_hovered, item_held;
  4208. bool item_pressed = ButtonBehaviour(item_aabb, item_id, &item_hovered, &item_held, true);
  4209. bool item_selected = (item_idx == *current_item);
  4210. if (item_hovered || item_selected)
  4211. {
  4212. const ImU32 col = window->Color((item_held && item_hovered) ? ImGuiCol_HeaderActive : item_hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
  4213. RenderFrame(item_aabb.Min, item_aabb.Max, col, false);
  4214. }
  4215. const char* item_text;
  4216. if (!items_getter(data, item_idx, &item_text))
  4217. item_text = "*Unknown item*";
  4218. ImGui::Text("%s", item_text);
  4219. if (item_selected)
  4220. {
  4221. if (menu_toggled)
  4222. ImGui::SetScrollPosHere();
  4223. }
  4224. if (item_pressed)
  4225. {
  4226. g.ActiveId = 0;
  4227. g.ActiveComboID = 0;
  4228. value_changed = true;
  4229. *current_item = item_idx;
  4230. }
  4231. combo_item_active |= (g.ActiveId == item_id);
  4232. }
  4233. ImGui::EndChild();
  4234. ImGui::SetCursorPos(backup_pos);
  4235. if (!combo_item_active && g.ActiveId != 0)
  4236. g.ActiveComboID = 0;
  4237. }
  4238. ImGui::PopID();
  4239. return value_changed;
  4240. }
  4241. // A little colored square. Return true when clicked.
  4242. bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_border)
  4243. {
  4244. ImGuiState& g = GImGui;
  4245. ImGuiWindow* window = GetCurrentWindow();
  4246. if (window->SkipItems)
  4247. return false;
  4248. const ImGuiStyle& style = g.Style;
  4249. const float square_size = window->FontSize();
  4250. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(square_size + style.FramePadding.x*2, square_size + (small_height ? 0 : style.FramePadding.y*2)));
  4251. ItemSize(bb);
  4252. if (ClipAdvance(bb))
  4253. return false;
  4254. const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb);
  4255. const bool pressed = hovered && g.IO.MouseClicked[0];
  4256. RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border);
  4257. if (hovered)
  4258. {
  4259. int ix = (int)(col.x * 255.0f + 0.5f);
  4260. int iy = (int)(col.y * 255.0f + 0.5f);
  4261. int iz = (int)(col.z * 255.0f + 0.5f);
  4262. int iw = (int)(col.w * 255.0f + 0.5f);
  4263. 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);
  4264. }
  4265. return pressed;
  4266. }
  4267. bool ImGui::ColorEdit3(const char* label, float col[3])
  4268. {
  4269. float col4[4];
  4270. col4[0] = col[0];
  4271. col4[1] = col[1];
  4272. col4[2] = col[2];
  4273. col4[3] = 1.0f;
  4274. const bool value_changed = ImGui::ColorEdit4(label, col4, false);
  4275. col[0] = col4[0];
  4276. col[1] = col4[1];
  4277. col[2] = col4[2];
  4278. return value_changed;
  4279. }
  4280. // Edit colors components (each component in 0.0f..1.0f range
  4281. // Use CTRL-Click to input value and TAB to go to next item.
  4282. bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha)
  4283. {
  4284. ImGuiState& g = GImGui;
  4285. ImGuiWindow* window = GetCurrentWindow();
  4286. if (window->SkipItems)
  4287. return false;
  4288. const ImGuiStyle& style = g.Style;
  4289. const ImGuiID id = window->GetID(label);
  4290. const float w_full = window->DC.ItemWidth.back();
  4291. const float square_sz = (window->FontSize() + style.FramePadding.x * 2.0f);
  4292. ImGuiColorEditMode edit_mode = window->DC.ColorEditMode;
  4293. if (edit_mode == ImGuiColorEditMode_UserSelect)
  4294. edit_mode = g.ColorEditModeStorage.GetInt(id, 0) % 3;
  4295. float fx = col[0];
  4296. float fy = col[1];
  4297. float fz = col[2];
  4298. float fw = col[3];
  4299. const ImVec4 col_display(fx, fy, fz, 1.0f);
  4300. if (edit_mode == ImGuiColorEditMode_HSV)
  4301. ImConvertColorRGBtoHSV(fx, fy, fz, fx, fy, fz);
  4302. int ix = (int)(fx * 255.0f + 0.5f);
  4303. int iy = (int)(fy * 255.0f + 0.5f);
  4304. int iz = (int)(fz * 255.0f + 0.5f);
  4305. int iw = (int)(fw * 255.0f + 0.5f);
  4306. int components = alpha ? 4 : 3;
  4307. bool value_changed = false;
  4308. ImGui::PushID(label);
  4309. bool hsv = (edit_mode == 1);
  4310. switch (edit_mode)
  4311. {
  4312. case ImGuiColorEditMode_RGB:
  4313. case ImGuiColorEditMode_HSV:
  4314. {
  4315. // 0: RGB 0..255
  4316. // 1: HSV 0.255 Sliders
  4317. const float w_items_all = w_full - (square_sz + style.ItemInnerSpacing.x);
  4318. 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));
  4319. 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)));
  4320. ImGui::PushItemWidth(w_item_one);
  4321. value_changed |= ImGui::SliderInt("##X", &ix, 0, 255, hsv ? "H:%3.0f" : "R:%3.0f");
  4322. ImGui::SameLine(0, 0);
  4323. value_changed |= ImGui::SliderInt("##Y", &iy, 0, 255, hsv ? "S:%3.0f" : "G:%3.0f");
  4324. ImGui::SameLine(0, 0);
  4325. if (alpha)
  4326. {
  4327. value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f");
  4328. ImGui::SameLine(0, 0);
  4329. ImGui::PushItemWidth(w_item_last);
  4330. value_changed |= ImGui::SliderInt("##W", &iw, 0, 255, "A:%3.0f");
  4331. }
  4332. else
  4333. {
  4334. ImGui::PushItemWidth(w_item_last);
  4335. value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f");
  4336. }
  4337. ImGui::PopItemWidth();
  4338. ImGui::PopItemWidth();
  4339. }
  4340. break;
  4341. case ImGuiColorEditMode_HEX:
  4342. {
  4343. // 2: RGB Hexadecimal
  4344. const float w_slider_all = w_full - square_sz;
  4345. char buf[64];
  4346. if (alpha)
  4347. sprintf(buf, "#%02X%02X%02X%02X", ix, iy, iz, iw);
  4348. else
  4349. sprintf(buf, "#%02X%02X%02X", ix, iy, iz);
  4350. ImGui::PushItemWidth(w_slider_all - g.Style.ItemInnerSpacing.x);
  4351. value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal);
  4352. ImGui::PopItemWidth();
  4353. char* p = buf;
  4354. while (*p == '#' || *p == ' ' || *p == '\t')
  4355. p++;
  4356. // Treat at unsigned (%X is unsigned)
  4357. ix = iy = iz = iw = 0;
  4358. if (alpha)
  4359. sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz, (unsigned int*)&iw);
  4360. else
  4361. sscanf(p, "%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz);
  4362. }
  4363. break;
  4364. }
  4365. ImGui::SameLine(0, 0);
  4366. ImGui::ColorButton(col_display);
  4367. if (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelect)
  4368. {
  4369. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4370. const char* button_titles[3] = { "RGB", "HSV", "HEX" };
  4371. if (ImGui::Button(button_titles[edit_mode]))
  4372. {
  4373. // Don't set local copy of 'edit_mode' right away!
  4374. g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3);
  4375. }
  4376. }
  4377. ImGui::SameLine();
  4378. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4379. // Convert back
  4380. fx = ix / 255.0f;
  4381. fy = iy / 255.0f;
  4382. fz = iz / 255.0f;
  4383. fw = iw / 255.0f;
  4384. if (edit_mode == 1)
  4385. ImConvertColorHSVtoRGB(fx, fy, fz, fx, fy, fz);
  4386. if (value_changed)
  4387. {
  4388. col[0] = fx;
  4389. col[1] = fy;
  4390. col[2] = fz;
  4391. if (alpha)
  4392. col[3] = fw;
  4393. }
  4394. ImGui::PopID();
  4395. return value_changed;
  4396. }
  4397. void ImGui::ColorEditMode(ImGuiColorEditMode mode)
  4398. {
  4399. ImGuiWindow* window = GetCurrentWindow();
  4400. window->DC.ColorEditMode = mode;
  4401. }
  4402. // Horizontal separating line.
  4403. void ImGui::Separator()
  4404. {
  4405. ImGuiWindow* window = GetCurrentWindow();
  4406. if (window->SkipItems)
  4407. return;
  4408. if (window->DC.ColumnsCount > 1)
  4409. PopClipRect();
  4410. const ImGuiAabb bb(ImVec2(window->Pos.x, window->DC.CursorPos.y), ImVec2(window->Pos.x + window->Size.x, window->DC.CursorPos.y));
  4411. ItemSize(ImVec2(0.0f, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit
  4412. if (ClipAdvance(bb))
  4413. {
  4414. if (window->DC.ColumnsCount > 1)
  4415. PushColumnClipRect();
  4416. return;
  4417. }
  4418. window->DrawList->AddLine(bb.Min, bb.Max, window->Color(ImGuiCol_Border));
  4419. if (window->DC.ColumnsCount > 1)
  4420. PushColumnClipRect();
  4421. }
  4422. // A little vertical spacing.
  4423. void ImGui::Spacing()
  4424. {
  4425. ImGuiWindow* window = GetCurrentWindow();
  4426. if (window->SkipItems)
  4427. return;
  4428. ItemSize(ImVec2(0,0));
  4429. }
  4430. // Advance cursor given item size.
  4431. static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset)
  4432. {
  4433. ImGuiState& g = GImGui;
  4434. ImGuiWindow* window = GetCurrentWindow();
  4435. if (window->SkipItems)
  4436. return;
  4437. const float line_height = ImMax(window->DC.CurrentLineHeight, size.y);
  4438. if (adjust_start_offset)
  4439. adjust_start_offset->y = adjust_start_offset->y + (line_height - size.y) * 0.5f;
  4440. // Always align ourselves on pixel boundaries
  4441. window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y);
  4442. 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));
  4443. window->SizeContentsFit = ImMax(window->SizeContentsFit, ImVec2(window->DC.CursorPosPrevLine.x, window->DC.CursorPos.y) - window->Pos + ImVec2(0.0f, window->ScrollY));
  4444. window->DC.PrevLineHeight = line_height;
  4445. window->DC.CurrentLineHeight = 0.0f;
  4446. }
  4447. static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset)
  4448. {
  4449. ItemSize(aabb.GetSize(), adjust_start_offset);
  4450. }
  4451. void ImGui::NextColumn()
  4452. {
  4453. ImGuiState& g = GImGui;
  4454. ImGuiWindow* window = GetCurrentWindow();
  4455. if (window->SkipItems)
  4456. return;
  4457. if (window->DC.ColumnsCount > 1)
  4458. {
  4459. ImGui::PopItemWidth();
  4460. PopClipRect();
  4461. window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
  4462. if (++window->DC.ColumnsCurrent < window->DC.ColumnsCount)
  4463. {
  4464. window->DC.ColumnsOffsetX = ImGui::GetColumnOffset(window->DC.ColumnsCurrent) - window->DC.ColumnsStartX + g.Style.ItemSpacing.x;
  4465. }
  4466. else
  4467. {
  4468. window->DC.ColumnsCurrent = 0;
  4469. window->DC.ColumnsOffsetX = 0.0f;
  4470. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY;
  4471. }
  4472. window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX);
  4473. window->DC.CursorPos.y = window->DC.ColumnsCellMinY;
  4474. window->DC.CurrentLineHeight = 0.0f;
  4475. PushColumnClipRect();
  4476. ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);
  4477. }
  4478. }
  4479. static bool IsClipped(const ImGuiAabb& bb)
  4480. {
  4481. ImGuiState& g = GImGui;
  4482. ImGuiWindow* window = GetCurrentWindow();
  4483. if (!bb.Overlaps(ImGuiAabb(window->ClipRectStack.back())) && !g.LogEnabled)
  4484. return true;
  4485. return false;
  4486. }
  4487. bool ImGui::IsClipped(const ImVec2& item_size)
  4488. {
  4489. ImGuiWindow* window = GetCurrentWindow();
  4490. return IsClipped(ImGuiAabb(window->DC.CursorPos, window->DC.CursorPos + item_size));
  4491. }
  4492. static bool ClipAdvance(const ImGuiAabb& bb)
  4493. {
  4494. ImGuiWindow* window = GetCurrentWindow();
  4495. window->DC.LastItemAabb = bb;
  4496. window->DC.LastItemFocused = false;
  4497. if (IsClipped(bb))
  4498. {
  4499. window->DC.LastItemHovered = false;
  4500. return true;
  4501. }
  4502. window->DC.LastItemHovered = IsMouseHoveringBox(bb); // this is a sensible default but widgets are free to override it after calling ClipAdvance
  4503. return false;
  4504. }
  4505. // Gets back to previous line and continue with horizontal layout
  4506. // column_x == 0 : follow on previous item
  4507. // columm_x != 0 : align to specified column
  4508. // spacing_w < 0 : use default spacing if column_x==0, no spacing if column_x!=0
  4509. // spacing_w >= 0 : enforce spacing
  4510. void ImGui::SameLine(int column_x, int spacing_w)
  4511. {
  4512. ImGuiState& g = GImGui;
  4513. ImGuiWindow* window = GetCurrentWindow();
  4514. if (window->SkipItems)
  4515. return;
  4516. float x, y;
  4517. if (column_x != 0)
  4518. {
  4519. if (spacing_w < 0) spacing_w = 0;
  4520. x = window->Pos.x + (float)column_x + (float)spacing_w;
  4521. y = window->DC.CursorPosPrevLine.y;
  4522. }
  4523. else
  4524. {
  4525. if (spacing_w < 0) spacing_w = (int)g.Style.ItemSpacing.x;
  4526. x = window->DC.CursorPosPrevLine.x + (float)spacing_w;
  4527. y = window->DC.CursorPosPrevLine.y;
  4528. }
  4529. window->DC.CurrentLineHeight = window->DC.PrevLineHeight;
  4530. window->DC.CursorPos = ImVec2(x, y);
  4531. }
  4532. float ImGui::GetColumnOffset(int column_index)
  4533. {
  4534. ImGuiState& g = GImGui;
  4535. ImGuiWindow* window = GetCurrentWindow();
  4536. if (column_index < 0)
  4537. column_index = window->DC.ColumnsCurrent;
  4538. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  4539. RegisterAliveId(column_id);
  4540. const float default_t = column_index / (float)window->DC.ColumnsCount;
  4541. const float t = (float)window->StateStorage.GetInt(column_id, (int)(default_t * 8192)) / 8192; // Cheaply store our floating point value inside the integer (could store an union into the map?)
  4542. const float offset = window->DC.ColumnsStartX + t * (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX);
  4543. return offset;
  4544. }
  4545. void ImGui::SetColumnOffset(int column_index, float offset)
  4546. {
  4547. ImGuiState& g = GImGui;
  4548. ImGuiWindow* window = GetCurrentWindow();
  4549. if (column_index < 0)
  4550. column_index = window->DC.ColumnsCurrent;
  4551. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  4552. const float t = (offset - window->DC.ColumnsStartX) / (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX);
  4553. window->StateStorage.SetInt(column_id, (int)(t*8192));
  4554. }
  4555. float ImGui::GetColumnWidth(int column_index)
  4556. {
  4557. ImGuiWindow* window = GetCurrentWindow();
  4558. if (column_index < 0)
  4559. column_index = window->DC.ColumnsCurrent;
  4560. const float w = GetColumnOffset(column_index+1) - GetColumnOffset(column_index);
  4561. return w;
  4562. }
  4563. static void PushColumnClipRect(int column_index)
  4564. {
  4565. ImGuiWindow* window = GetCurrentWindow();
  4566. if (column_index < 0)
  4567. column_index = window->DC.ColumnsCurrent;
  4568. const float x1 = window->Pos.x + ImGui::GetColumnOffset(column_index) - 1;
  4569. const float x2 = window->Pos.x + ImGui::GetColumnOffset(column_index+1) - 1;
  4570. PushClipRect(ImVec4(x1,-FLT_MAX,x2,+FLT_MAX));
  4571. }
  4572. void ImGui::Columns(int columns_count, const char* id, bool border)
  4573. {
  4574. ImGuiState& g = GImGui;
  4575. ImGuiWindow* window = GetCurrentWindow();
  4576. if (window->SkipItems)
  4577. return;
  4578. if (window->DC.ColumnsCount != 1)
  4579. {
  4580. if (window->DC.ColumnsCurrent != 0)
  4581. ItemSize(ImVec2(0,0)); // Advance to column 0
  4582. ImGui::PopItemWidth();
  4583. PopClipRect();
  4584. window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
  4585. window->DC.CursorPos.y = window->DC.ColumnsCellMaxY;
  4586. }
  4587. // Draw columns borders and handle resize at the time of "closing" a columns set
  4588. if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders)
  4589. {
  4590. const float y1 = window->DC.ColumnsStartPos.y;
  4591. const float y2 = window->DC.CursorPos.y;
  4592. for (int i = 1; i < window->DC.ColumnsCount; i++)
  4593. {
  4594. float x = window->Pos.x + GetColumnOffset(i);
  4595. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(i);
  4596. const ImGuiAabb column_aabb(ImVec2(x-4,y1),ImVec2(x+4,y2));
  4597. if (IsClipped(column_aabb))
  4598. continue;
  4599. bool hovered, held;
  4600. ButtonBehaviour(column_aabb, column_id, &hovered, &held, true);
  4601. // Draw before resize so our items positioning are in sync with the line being drawn
  4602. const ImU32 col = window->Color(held ? ImGuiCol_ColumnActive : hovered ? ImGuiCol_ColumnHovered : ImGuiCol_Column);
  4603. const float xi = (float)(int)x;
  4604. window->DrawList->AddLine(ImVec2(xi, y1), ImVec2(xi, y2), col);
  4605. if (held)
  4606. {
  4607. x -= window->Pos.x;
  4608. x = ImClamp(x + g.IO.MouseDelta.x, ImGui::GetColumnOffset(i-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(i+1)-g.Style.ColumnsMinSpacing);
  4609. SetColumnOffset(i, x);
  4610. x += window->Pos.x;
  4611. }
  4612. }
  4613. }
  4614. // Set state for first column
  4615. window->DC.ColumnsSetID = window->GetID(id ? id : "");
  4616. window->DC.ColumnsCurrent = 0;
  4617. window->DC.ColumnsCount = columns_count;
  4618. window->DC.ColumnsShowBorders = border;
  4619. window->DC.ColumnsStartPos = window->DC.CursorPos;
  4620. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.CursorPos.y;
  4621. window->DC.ColumnsOffsetX = 0.0f;
  4622. window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX);
  4623. if (window->DC.ColumnsCount != 1)
  4624. {
  4625. PushColumnClipRect();
  4626. ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);
  4627. }
  4628. }
  4629. void ImGui::TreePush(const char* str_id)
  4630. {
  4631. ImGuiState& g = GImGui;
  4632. ImGuiWindow* window = GetCurrentWindow();
  4633. window->DC.ColumnsStartX += g.Style.TreeNodeSpacing;
  4634. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  4635. window->DC.TreeDepth++;
  4636. PushID(str_id ? str_id : "#TreePush");
  4637. }
  4638. void ImGui::TreePush(const void* ptr_id)
  4639. {
  4640. ImGuiState& g = GImGui;
  4641. ImGuiWindow* window = GetCurrentWindow();
  4642. window->DC.ColumnsStartX += g.Style.TreeNodeSpacing;
  4643. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  4644. window->DC.TreeDepth++;
  4645. PushID(ptr_id ? ptr_id : (const void*)"#TreePush");
  4646. }
  4647. void ImGui::TreePop()
  4648. {
  4649. ImGuiState& g = GImGui;
  4650. ImGuiWindow* window = GetCurrentWindow();
  4651. window->DC.ColumnsStartX -= g.Style.TreeNodeSpacing;
  4652. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  4653. window->DC.TreeDepth--;
  4654. PopID();
  4655. }
  4656. void ImGui::Value(const char* prefix, bool b)
  4657. {
  4658. ImGui::Text("%s: %s", prefix, (b ? "true" : "false"));
  4659. }
  4660. void ImGui::Value(const char* prefix, int v)
  4661. {
  4662. ImGui::Text("%s: %d", prefix, v);
  4663. }
  4664. void ImGui::Value(const char* prefix, unsigned int v)
  4665. {
  4666. ImGui::Text("%s: %d", prefix, v);
  4667. }
  4668. void ImGui::Value(const char* prefix, float v, const char* float_format)
  4669. {
  4670. if (float_format)
  4671. {
  4672. char fmt[64];
  4673. sprintf(fmt, "%%s: %s", float_format);
  4674. ImGui::Text(fmt, prefix, v);
  4675. }
  4676. else
  4677. {
  4678. ImGui::Text("%s: %.3f", prefix, v);
  4679. }
  4680. }
  4681. void ImGui::Color(const char* prefix, const ImVec4& v)
  4682. {
  4683. ImGui::Text("%s: (%.2f,%.2f,%.2f,%.2f)", prefix, v.x, v.y, v.z, v.w);
  4684. ImGui::SameLine();
  4685. ImGui::ColorButton(v, true);
  4686. }
  4687. void ImGui::Color(const char* prefix, unsigned int v)
  4688. {
  4689. ImGui::Text("%s: %08X", prefix, v);
  4690. ImGui::SameLine();
  4691. ImVec4 col;
  4692. col.x = (float)((v >> 0) & 0xFF) / 255.0f;
  4693. col.y = (float)((v >> 8) & 0xFF) / 255.0f;
  4694. col.z = (float)((v >> 16) & 0xFF) / 255.0f;
  4695. col.w = (float)((v >> 24) & 0xFF) / 255.0f;
  4696. ImGui::ColorButton(col, true);
  4697. }
  4698. //-----------------------------------------------------------------------------
  4699. // ImDrawList
  4700. //-----------------------------------------------------------------------------
  4701. void ImDrawList::Clear()
  4702. {
  4703. commands.resize(0);
  4704. vtx_buffer.resize(0);
  4705. vtx_write = NULL;
  4706. clip_rect_stack.resize(0);
  4707. }
  4708. void ImDrawList::PushClipRect(const ImVec4& clip_rect)
  4709. {
  4710. if (!commands.empty() && commands.back().vtx_count == 0)
  4711. {
  4712. // Reuse empty command because high-level clipping may have discarded the other vertices already
  4713. commands.back().clip_rect = clip_rect;
  4714. }
  4715. else
  4716. {
  4717. ImDrawCmd draw_cmd;
  4718. draw_cmd.vtx_count = 0;
  4719. draw_cmd.clip_rect = clip_rect;
  4720. commands.push_back(draw_cmd);
  4721. }
  4722. clip_rect_stack.push_back(clip_rect);
  4723. }
  4724. void ImDrawList::PopClipRect()
  4725. {
  4726. clip_rect_stack.pop_back();
  4727. const ImVec4 clip_rect = clip_rect_stack.empty() ? ImVec4(-9999.0f,-9999.0f, +9999.0f, +9999.0f) : clip_rect_stack.back();
  4728. if (!commands.empty() && commands.back().vtx_count == 0)
  4729. {
  4730. // Reuse empty command because high-level clipping may have discarded the other vertices already
  4731. commands.back().clip_rect = clip_rect;
  4732. }
  4733. else
  4734. {
  4735. ImDrawCmd draw_cmd;
  4736. draw_cmd.vtx_count = 0;
  4737. draw_cmd.clip_rect = clip_rect;
  4738. commands.push_back(draw_cmd);
  4739. }
  4740. }
  4741. void ImDrawList::ReserveVertices(unsigned int vtx_count)
  4742. {
  4743. if (vtx_count > 0)
  4744. {
  4745. ImDrawCmd& draw_cmd = commands.back();
  4746. draw_cmd.vtx_count += vtx_count;
  4747. vtx_buffer.resize(vtx_buffer.size() + vtx_count);
  4748. vtx_write = &vtx_buffer[vtx_buffer.size() - vtx_count];
  4749. }
  4750. }
  4751. void ImDrawList::AddVtx(const ImVec2& pos, ImU32 col)
  4752. {
  4753. vtx_write->pos = pos;
  4754. vtx_write->col = col;
  4755. vtx_write->uv = GImGui.FontTexUvForWhite;
  4756. vtx_write++;
  4757. }
  4758. void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col)
  4759. {
  4760. const float offset = GImGui.IO.PixelCenterOffset;
  4761. const ImVec2 hn = (b - a) * (0.50f / ImLength(b - a)); // half normal
  4762. const ImVec2 hp0 = ImVec2(offset + hn.y, offset - hn.x); // half perpendiculars + user offset
  4763. const ImVec2 hp1 = ImVec2(offset - hn.y, offset + hn.x);
  4764. // Two triangles makes up one line. Using triangles allows us to reduce amount of draw calls.
  4765. AddVtx(a + hp0, col);
  4766. AddVtx(b + hp0, col);
  4767. AddVtx(a + hp1, col);
  4768. AddVtx(b + hp0, col);
  4769. AddVtx(b + hp1, col);
  4770. AddVtx(a + hp1, col);
  4771. }
  4772. void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col)
  4773. {
  4774. if ((col >> 24) == 0)
  4775. return;
  4776. ReserveVertices(6);
  4777. AddVtxLine(a, b, col);
  4778. }
  4779. void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris, const ImVec2& third_point_offset)
  4780. {
  4781. if ((col >> 24) == 0)
  4782. return;
  4783. static ImVec2 circle_vtx[12];
  4784. static bool circle_vtx_builds = false;
  4785. if (!circle_vtx_builds)
  4786. {
  4787. for (int i = 0; i < IM_ARRAYSIZE(circle_vtx); i++)
  4788. {
  4789. const float a = ((float)i / (float)IM_ARRAYSIZE(circle_vtx)) * 2*PI;
  4790. circle_vtx[i].x = cosf(a + PI);
  4791. circle_vtx[i].y = sinf(a + PI);
  4792. }
  4793. circle_vtx_builds = true;
  4794. }
  4795. if (tris)
  4796. {
  4797. ReserveVertices((unsigned int)(a_max-a_min) * 3);
  4798. for (int a = a_min; a < a_max; a++)
  4799. {
  4800. AddVtx(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, col);
  4801. AddVtx(center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col);
  4802. AddVtx(center + third_point_offset, col);
  4803. }
  4804. }
  4805. else
  4806. {
  4807. ReserveVertices((unsigned int)(a_max-a_min) * 6);
  4808. for (int a = a_min; a < a_max; a++)
  4809. AddVtxLine(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col);
  4810. }
  4811. }
  4812. void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
  4813. {
  4814. if ((col >> 24) == 0)
  4815. return;
  4816. float r = rounding;
  4817. r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
  4818. r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
  4819. if (r == 0.0f || rounding_corners == 0)
  4820. {
  4821. ReserveVertices(4*6);
  4822. AddVtxLine(ImVec2(a.x,a.y), ImVec2(b.x,a.y), col);
  4823. AddVtxLine(ImVec2(b.x,a.y), ImVec2(b.x,b.y), col);
  4824. AddVtxLine(ImVec2(b.x,b.y), ImVec2(a.x,b.y), col);
  4825. AddVtxLine(ImVec2(a.x,b.y), ImVec2(a.x,a.y), col);
  4826. }
  4827. else
  4828. {
  4829. ReserveVertices(4*6);
  4830. AddVtxLine(ImVec2(a.x + ((rounding_corners & 1)?r:0), a.y), ImVec2(b.x - ((rounding_corners & 2)?r:0), a.y), col);
  4831. AddVtxLine(ImVec2(b.x, a.y + ((rounding_corners & 2)?r:0)), ImVec2(b.x, b.y - ((rounding_corners & 4)?r:0)), col);
  4832. AddVtxLine(ImVec2(b.x - ((rounding_corners & 4)?r:0), b.y), ImVec2(a.x + ((rounding_corners & 8)?r:0), b.y), col);
  4833. AddVtxLine(ImVec2(a.x, b.y - ((rounding_corners & 8)?r:0)), ImVec2(a.x, a.y + ((rounding_corners & 1)?r:0)), col);
  4834. if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3);
  4835. if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6);
  4836. if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9);
  4837. if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12);
  4838. }
  4839. }
  4840. void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
  4841. {
  4842. if ((col >> 24) == 0)
  4843. return;
  4844. float r = rounding;
  4845. r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
  4846. r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
  4847. if (r == 0.0f || rounding_corners == 0)
  4848. {
  4849. // Use triangle so we can merge more draw calls together (at the cost of extra vertices)
  4850. ReserveVertices(6);
  4851. AddVtx(ImVec2(a.x,a.y), col);
  4852. AddVtx(ImVec2(b.x,a.y), col);
  4853. AddVtx(ImVec2(b.x,b.y), col);
  4854. AddVtx(ImVec2(a.x,a.y), col);
  4855. AddVtx(ImVec2(b.x,b.y), col);
  4856. AddVtx(ImVec2(a.x,b.y), col);
  4857. }
  4858. else
  4859. {
  4860. ReserveVertices(6+6*2);
  4861. AddVtx(ImVec2(a.x+r,a.y), col);
  4862. AddVtx(ImVec2(b.x-r,a.y), col);
  4863. AddVtx(ImVec2(b.x-r,b.y), col);
  4864. AddVtx(ImVec2(a.x+r,a.y), col);
  4865. AddVtx(ImVec2(b.x-r,b.y), col);
  4866. AddVtx(ImVec2(a.x+r,b.y), col);
  4867. float top_y = (rounding_corners & 1) ? a.y+r : a.y;
  4868. float bot_y = (rounding_corners & 8) ? b.y-r : b.y;
  4869. AddVtx(ImVec2(a.x,top_y), col);
  4870. AddVtx(ImVec2(a.x+r,top_y), col);
  4871. AddVtx(ImVec2(a.x+r,bot_y), col);
  4872. AddVtx(ImVec2(a.x,top_y), col);
  4873. AddVtx(ImVec2(a.x+r,bot_y), col);
  4874. AddVtx(ImVec2(a.x,bot_y), col);
  4875. top_y = (rounding_corners & 2) ? a.y+r : a.y;
  4876. bot_y = (rounding_corners & 4) ? b.y-r : b.y;
  4877. AddVtx(ImVec2(b.x-r,top_y), col);
  4878. AddVtx(ImVec2(b.x,top_y), col);
  4879. AddVtx(ImVec2(b.x,bot_y), col);
  4880. AddVtx(ImVec2(b.x-r,top_y), col);
  4881. AddVtx(ImVec2(b.x,bot_y), col);
  4882. AddVtx(ImVec2(b.x-r,bot_y), col);
  4883. if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3, true);
  4884. if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6, true);
  4885. if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9, true);
  4886. if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12,true);
  4887. }
  4888. }
  4889. void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col)
  4890. {
  4891. if ((col >> 24) == 0)
  4892. return;
  4893. const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset);
  4894. ReserveVertices(3);
  4895. AddVtx(a + offset, col);
  4896. AddVtx(b + offset, col);
  4897. AddVtx(c + offset, col);
  4898. }
  4899. void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments)
  4900. {
  4901. if ((col >> 24) == 0)
  4902. return;
  4903. const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset);
  4904. ReserveVertices((unsigned int)num_segments*6);
  4905. const float a_step = 2*PI/(float)num_segments;
  4906. float a0 = 0.0f;
  4907. for (int i = 0; i < num_segments; i++)
  4908. {
  4909. const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
  4910. AddVtxLine(centre + offset + ImVec2(cosf(a0), sinf(a0))*radius, centre + ImVec2(cosf(a1), sinf(a1))*radius, col);
  4911. a0 = a1;
  4912. }
  4913. }
  4914. void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments)
  4915. {
  4916. if ((col >> 24) == 0)
  4917. return;
  4918. const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset);
  4919. ReserveVertices((unsigned int)num_segments*3);
  4920. const float a_step = 2*PI/(float)num_segments;
  4921. float a0 = 0.0f;
  4922. for (int i = 0; i < num_segments; i++)
  4923. {
  4924. const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
  4925. AddVtx(centre + offset + ImVec2(cosf(a0), sinf(a0))*radius, col);
  4926. AddVtx(centre + offset + ImVec2(cosf(a1), sinf(a1))*radius, col);
  4927. AddVtx(centre + offset, col);
  4928. a0 = a1;
  4929. }
  4930. }
  4931. void ImDrawList::AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width)
  4932. {
  4933. if ((col >> 24) == 0)
  4934. return;
  4935. if (text_end == NULL)
  4936. text_end = text_begin + strlen(text_begin); // FIXME-OPT
  4937. // reserve vertices for worse case
  4938. const unsigned int char_count = (unsigned int)(text_end - text_begin);
  4939. const unsigned int vtx_count_max = char_count * 6;
  4940. const size_t vtx_begin = vtx_buffer.size();
  4941. ReserveVertices(vtx_count_max);
  4942. font->RenderText(font_size, pos, col, clip_rect_stack.back(), text_begin, text_end, vtx_write, wrap_width);
  4943. // give back unused vertices
  4944. vtx_buffer.resize((size_t)(vtx_write - &vtx_buffer.front()));
  4945. const size_t vtx_count = vtx_buffer.size() - vtx_begin;
  4946. commands.back().vtx_count -= (unsigned int)(vtx_count_max - vtx_count);
  4947. vtx_write -= (vtx_count_max - vtx_count);
  4948. }
  4949. //-----------------------------------------------------------------------------
  4950. // ImBitmapFont
  4951. //-----------------------------------------------------------------------------
  4952. ImFont::ImFont()
  4953. {
  4954. Scale = 1.0f;
  4955. DisplayOffset = ImVec2(0.0f,0.0f);
  4956. TexUvForWhite = ImVec2(0.0f,0.0f);
  4957. FallbackChar = (ImWchar)'?';
  4958. Data = NULL;
  4959. DataSize = 0;
  4960. DataOwned = false;
  4961. Info = NULL;
  4962. Common = NULL;
  4963. Glyphs = NULL;
  4964. GlyphsCount = 0;
  4965. Kerning = NULL;
  4966. KerningCount = 0;
  4967. }
  4968. void ImFont::Clear()
  4969. {
  4970. if (Data && DataOwned)
  4971. ImGui::MemFree(Data);
  4972. Data = NULL;
  4973. DataOwned = false;
  4974. Info = NULL;
  4975. Common = NULL;
  4976. Glyphs = NULL;
  4977. GlyphsCount = 0;
  4978. Filenames.clear();
  4979. IndexLookup.clear();
  4980. }
  4981. bool ImFont::LoadFromFile(const char* filename)
  4982. {
  4983. IM_ASSERT(!IsLoaded()); // Call Clear()
  4984. // Load file
  4985. FILE* f;
  4986. if ((f = fopen(filename, "rb")) == NULL)
  4987. return false;
  4988. if (fseek(f, 0, SEEK_END))
  4989. {
  4990. fclose(f);
  4991. return false;
  4992. }
  4993. const long f_size = ftell(f);
  4994. if (f_size == -1)
  4995. {
  4996. fclose(f);
  4997. return false;
  4998. }
  4999. DataSize = (size_t)f_size;
  5000. if (fseek(f, 0, SEEK_SET))
  5001. {
  5002. fclose(f);
  5003. return false;
  5004. }
  5005. if ((Data = (unsigned char*)ImGui::MemAlloc(DataSize)) == NULL)
  5006. {
  5007. fclose(f);
  5008. return false;
  5009. }
  5010. if (fread(Data, 1, DataSize, f) != DataSize)
  5011. {
  5012. fclose(f);
  5013. ImGui::MemFree(Data);
  5014. return false;
  5015. }
  5016. fclose(f);
  5017. DataOwned = true;
  5018. return LoadFromMemory(Data, DataSize);
  5019. }
  5020. bool ImFont::LoadFromMemory(const void* data, size_t data_size)
  5021. {
  5022. IM_ASSERT(!IsLoaded()); // Call Clear()
  5023. Data = (unsigned char*)data;
  5024. DataSize = data_size;
  5025. // Parse data
  5026. if (DataSize < 4 || Data[0] != 'B' || Data[1] != 'M' || Data[2] != 'F' || Data[3] != 0x03)
  5027. return false;
  5028. for (const unsigned char* p = Data+4; p < Data + DataSize; )
  5029. {
  5030. const unsigned char block_type = *(unsigned char*)p;
  5031. p += sizeof(unsigned char);
  5032. ImU32 block_size; // use memcpy to read 4-byte because they may be unaligned. This seems to break when compiling for Emscripten.
  5033. memcpy(&block_size, p, sizeof(ImU32));
  5034. p += sizeof(ImU32);
  5035. switch (block_type)
  5036. {
  5037. case 1:
  5038. IM_ASSERT(Info == NULL);
  5039. Info = (FntInfo*)p;
  5040. break;
  5041. case 2:
  5042. IM_ASSERT(Common == NULL);
  5043. Common = (FntCommon*)p;
  5044. break;
  5045. case 3:
  5046. for (const unsigned char* s = p; s < p+block_size && s < Data+DataSize; s = s + strlen((const char*)s) + 1)
  5047. Filenames.push_back((const char*)s);
  5048. break;
  5049. case 4:
  5050. IM_ASSERT(Glyphs == NULL && GlyphsCount == 0);
  5051. Glyphs = (FntGlyph*)p;
  5052. GlyphsCount = block_size / sizeof(FntGlyph);
  5053. break;
  5054. case 5:
  5055. IM_ASSERT(Kerning == NULL && KerningCount == 0);
  5056. Kerning = (FntKerning*)p;
  5057. KerningCount = block_size / sizeof(FntKerning);
  5058. break;
  5059. default:
  5060. break;
  5061. }
  5062. p += block_size;
  5063. }
  5064. BuildLookupTable();
  5065. return true;
  5066. }
  5067. void ImFont::BuildLookupTable()
  5068. {
  5069. ImU32 max_c = 0;
  5070. for (size_t i = 0; i != GlyphsCount; i++)
  5071. if (max_c < Glyphs[i].Id)
  5072. max_c = Glyphs[i].Id;
  5073. IndexLookup.clear();
  5074. IndexLookup.resize(max_c + 1);
  5075. for (size_t i = 0; i < IndexLookup.size(); i++)
  5076. IndexLookup[i] = -1;
  5077. for (size_t i = 0; i < GlyphsCount; i++)
  5078. IndexLookup[Glyphs[i].Id] = (int)i;
  5079. }
  5080. const ImFont::FntGlyph* ImFont::FindGlyph(unsigned short c) const
  5081. {
  5082. if (c < (int)IndexLookup.size())
  5083. {
  5084. const int i = IndexLookup[c];
  5085. if (i >= 0 && i < (int)GlyphsCount)
  5086. return &Glyphs[i];
  5087. }
  5088. return FallbackGlyph;
  5089. }
  5090. // Convert UTF-8 to 32-bits character, process single character input.
  5091. // Based on stb_from_utf8() from github.com/nothings/stb/
  5092. static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end)
  5093. {
  5094. if (*in_text != 0)
  5095. {
  5096. unsigned int c = (unsigned int)-1;
  5097. const unsigned char* str = (const unsigned char*)in_text;
  5098. if (!(*str & 0x80))
  5099. {
  5100. c = (unsigned int)(*str++);
  5101. *out_char = c;
  5102. return 1;
  5103. }
  5104. if ((*str & 0xe0) == 0xc0)
  5105. {
  5106. if (in_text_end && in_text_end - (const char*)str < 2) return -1;
  5107. if (*str < 0xc2) return -1;
  5108. c = (unsigned int)((*str++ & 0x1f) << 6);
  5109. if ((*str & 0xc0) != 0x80) return -1;
  5110. c += (*str++ & 0x3f);
  5111. *out_char = c;
  5112. return 2;
  5113. }
  5114. if ((*str & 0xf0) == 0xe0)
  5115. {
  5116. if (in_text_end && in_text_end - (const char*)str < 3) return -1;
  5117. if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return -1;
  5118. if (*str == 0xed && str[1] > 0x9f) return -1; // str[1] < 0x80 is checked below
  5119. c = (unsigned int)((*str++ & 0x0f) << 12);
  5120. if ((*str & 0xc0) != 0x80) return -1;
  5121. c += (unsigned int)((*str++ & 0x3f) << 6);
  5122. if ((*str & 0xc0) != 0x80) return -1;
  5123. c += (*str++ & 0x3f);
  5124. *out_char = c;
  5125. return 3;
  5126. }
  5127. if ((*str & 0xf8) == 0xf0)
  5128. {
  5129. if (in_text_end && in_text_end - (const char*)str < 4) return -1;
  5130. if (*str > 0xf4) return -1;
  5131. if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return -1;
  5132. if (*str == 0xf4 && str[1] > 0x8f) return -1; // str[1] < 0x80 is checked below
  5133. c = (unsigned int)((*str++ & 0x07) << 18);
  5134. if ((*str & 0xc0) != 0x80) return -1;
  5135. c += (unsigned int)((*str++ & 0x3f) << 12);
  5136. if ((*str & 0xc0) != 0x80) return -1;
  5137. c += (unsigned int)((*str++ & 0x3f) << 6);
  5138. if ((*str & 0xc0) != 0x80) return -1;
  5139. c += (*str++ & 0x3f);
  5140. // utf-8 encodings of values used in surrogate pairs are invalid
  5141. if ((c & 0xFFFFF800) == 0xD800) return -1;
  5142. *out_char = c;
  5143. return 4;
  5144. }
  5145. }
  5146. *out_char = 0;
  5147. return 0;
  5148. }
  5149. static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end)
  5150. {
  5151. ImWchar* buf_out = buf;
  5152. ImWchar* buf_end = buf + buf_size;
  5153. while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text)
  5154. {
  5155. unsigned int c;
  5156. in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
  5157. if (c < 0x10000) // FIXME: Losing characters that don't fit in 2 bytes
  5158. *buf_out++ = (ImWchar)c;
  5159. }
  5160. *buf_out = 0;
  5161. return buf_out - buf;
  5162. }
  5163. static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end)
  5164. {
  5165. int char_count = 0;
  5166. while ((!in_text_end || in_text < in_text_end) && *in_text)
  5167. {
  5168. unsigned int c;
  5169. in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
  5170. if (c < 0x10000)
  5171. char_count++;
  5172. }
  5173. return char_count;
  5174. }
  5175. // Based on stb_to_utf8() from github.com/nothings/stb/
  5176. static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int c)
  5177. {
  5178. if (c)
  5179. {
  5180. size_t i = 0;
  5181. size_t n = buf_size;
  5182. if (c < 0x80)
  5183. {
  5184. if (i+1 > n) return 0;
  5185. buf[i++] = (char)c;
  5186. return 1;
  5187. }
  5188. else if (c < 0x800)
  5189. {
  5190. if (i+2 > n) return 0;
  5191. buf[i++] = (char)(0xc0 + (c >> 6));
  5192. buf[i++] = (char)(0x80 + (c & 0x3f));
  5193. return 2;
  5194. }
  5195. else if (c >= 0xdc00 && c < 0xe000)
  5196. {
  5197. return 0;
  5198. }
  5199. else if (c >= 0xd800 && c < 0xdc00)
  5200. {
  5201. if (i+4 > n) return 0;
  5202. buf[i++] = (char)(0xf0 + (c >> 18));
  5203. buf[i++] = (char)(0x80 + ((c >> 12) & 0x3f));
  5204. buf[i++] = (char)(0x80 + ((c >> 6) & 0x3f));
  5205. buf[i++] = (char)(0x80 + ((c ) & 0x3f));
  5206. return 4;
  5207. }
  5208. //else if (c < 0x10000)
  5209. {
  5210. if (i+3 > n) return 0;
  5211. buf[i++] = (char)(0xe0 + (c >> 12));
  5212. buf[i++] = (char)(0x80 + ((c>> 6) & 0x3f));
  5213. buf[i++] = (char)(0x80 + ((c ) & 0x3f));
  5214. return 3;
  5215. }
  5216. }
  5217. return 0;
  5218. }
  5219. static ptrdiff_t ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end)
  5220. {
  5221. char* buf_out = buf;
  5222. const char* buf_end = buf + buf_size;
  5223. while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text)
  5224. {
  5225. buf_out += ImTextCharToUtf8(buf_out, (uintptr_t)(buf_end-buf_out-1), (unsigned int)*in_text);
  5226. in_text++;
  5227. }
  5228. *buf_out = 0;
  5229. return buf_out - buf;
  5230. }
  5231. static int ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end)
  5232. {
  5233. int bytes_count = 0;
  5234. while ((!in_text_end || in_text < in_text_end) && *in_text)
  5235. {
  5236. char dummy[5]; // FIXME-OPT
  5237. bytes_count += ImTextCharToUtf8(dummy, 5, (unsigned int)*in_text);
  5238. in_text++;
  5239. }
  5240. return bytes_count;
  5241. }
  5242. const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const
  5243. {
  5244. // Simple word-wrapping for English, not full-featured. Please submit failing cases!
  5245. // 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.)
  5246. // For references, possible wrap point marked with ^
  5247. // "aaa bbb, ccc,ddd. eee fff. ggg!"
  5248. // ^ ^ ^ ^ ^__ ^ ^
  5249. // List of hardcoded separators: .,;!?'"
  5250. // Skip extra blanks after a line returns (that includes not counting them in width computation)
  5251. // e.g. "Hello world"
  5252. // -->
  5253. // "Hello"
  5254. // "world"
  5255. // Cut words that cannot possibly fit within one line.
  5256. // e.g.: "The tropical fish" with ~5 characters worth of width
  5257. // -->
  5258. // "The tr"
  5259. // "opical"
  5260. // "fish"
  5261. float line_width = 0.0f;
  5262. float word_width = 0.0f;
  5263. float blank_width = 0.0f;
  5264. const char* word_end = text;
  5265. const char* prev_word_end = NULL;
  5266. bool inside_word = true;
  5267. const char* s = text;
  5268. while (s < text_end)
  5269. {
  5270. unsigned int c;
  5271. const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
  5272. const char* next_s = s + (bytes_count > 0 ? bytes_count : 1);
  5273. if (c == '\n')
  5274. {
  5275. line_width = word_width = blank_width = 0.0f;
  5276. inside_word = true;
  5277. s = next_s;
  5278. continue;
  5279. }
  5280. float char_width = 0.0f;
  5281. if (c == '\t')
  5282. {
  5283. if (const FntGlyph* glyph = FindGlyph((unsigned short)' '))
  5284. char_width = (glyph->XAdvance + Info->SpacingHoriz) * 4 * scale;
  5285. }
  5286. else
  5287. {
  5288. if (const FntGlyph* glyph = FindGlyph((unsigned short)c))
  5289. char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale;
  5290. }
  5291. if (c == ' ' || c == '\t')
  5292. {
  5293. if (inside_word)
  5294. {
  5295. line_width += blank_width;
  5296. blank_width = 0.0f;
  5297. }
  5298. blank_width += char_width;
  5299. inside_word = false;
  5300. }
  5301. else
  5302. {
  5303. word_width += char_width;
  5304. if (inside_word)
  5305. {
  5306. word_end = next_s;
  5307. }
  5308. else
  5309. {
  5310. prev_word_end = word_end;
  5311. line_width += word_width + blank_width;
  5312. word_width = blank_width = 0.0f;
  5313. }
  5314. // Allow wrapping after punctuation.
  5315. inside_word = !(c == '.' || c == ',' || c == ';' || c == '!' || c == '?' || c == '\"');
  5316. }
  5317. // We ignore blank width at the end of the line (they can be skipped)
  5318. if (line_width + word_width >= wrap_width)
  5319. {
  5320. // Words that cannot possibly fit within an entire line will be cut anywhere.
  5321. if (word_width < wrap_width)
  5322. s = prev_word_end ? prev_word_end : word_end;
  5323. break;
  5324. }
  5325. s = next_s;
  5326. }
  5327. return s;
  5328. }
  5329. ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining) const
  5330. {
  5331. if (!text_end)
  5332. text_end = text_begin + strlen(text_begin); // FIXME-OPT
  5333. const float scale = size / (float)Info->FontSize;
  5334. const float line_height = (float)Info->FontSize * scale;
  5335. ImVec2 text_size = ImVec2(0,0);
  5336. float line_width = 0.0f;
  5337. const bool word_wrap_enabled = (wrap_width > 0.0f);
  5338. const char* word_wrap_eol = NULL;
  5339. const char* s = text_begin;
  5340. while (s < text_end)
  5341. {
  5342. if (word_wrap_enabled)
  5343. {
  5344. // 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.
  5345. if (!word_wrap_eol)
  5346. {
  5347. word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - line_width);
  5348. if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
  5349. 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
  5350. }
  5351. if (s >= word_wrap_eol)
  5352. {
  5353. if (text_size.x < line_width)
  5354. text_size.x = line_width;
  5355. text_size.y += line_height;
  5356. line_width = 0.0f;
  5357. word_wrap_eol = NULL;
  5358. // Wrapping skips upcoming blanks
  5359. while (s < text_end)
  5360. {
  5361. const char c = *s;
  5362. if (c == ' ' || c == '\t') { s++; } else if (c == '\n') { s++; break; } else { break; }
  5363. }
  5364. continue;
  5365. }
  5366. }
  5367. // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
  5368. unsigned int c;
  5369. const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
  5370. s += bytes_count > 0 ? bytes_count : 1;
  5371. if (c == '\n')
  5372. {
  5373. if (text_size.x < line_width)
  5374. text_size.x = line_width;
  5375. text_size.y += line_height;
  5376. line_width = 0.0f;
  5377. continue;
  5378. }
  5379. float char_width = 0.0f;
  5380. if (c == '\t')
  5381. {
  5382. // FIXME: Better TAB handling
  5383. if (const FntGlyph* glyph = FindGlyph((unsigned short)' '))
  5384. char_width = (glyph->XAdvance + Info->SpacingHoriz) * 4 * scale;
  5385. }
  5386. else if (const FntGlyph* glyph = FindGlyph((unsigned short)c))
  5387. {
  5388. char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale;
  5389. }
  5390. if (line_width + char_width >= max_width)
  5391. break;
  5392. line_width += char_width;
  5393. }
  5394. if (line_width > 0 || text_size.y == 0.0f)
  5395. {
  5396. if (text_size.x < line_width)
  5397. text_size.x = line_width;
  5398. text_size.y += line_height;
  5399. }
  5400. if (remaining)
  5401. *remaining = s;
  5402. return text_size;
  5403. }
  5404. ImVec2 ImFont::CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining) const
  5405. {
  5406. if (!text_end)
  5407. text_end = text_begin + ImStrlenW(text_begin);
  5408. const float scale = size / (float)Info->FontSize;
  5409. const float line_height = (float)Info->FontSize * scale;
  5410. ImVec2 text_size = ImVec2(0,0);
  5411. float line_width = 0.0f;
  5412. const ImWchar* s = text_begin;
  5413. while (s < text_end)
  5414. {
  5415. const unsigned int c = (unsigned int)(*s++);
  5416. if (c == '\n')
  5417. {
  5418. if (text_size.x < line_width)
  5419. text_size.x = line_width;
  5420. text_size.y += line_height;
  5421. line_width = 0.0f;
  5422. continue;
  5423. }
  5424. float char_width = 0.0f;
  5425. if (c == '\t')
  5426. {
  5427. // FIXME: Better TAB handling
  5428. if (const FntGlyph* glyph = FindGlyph((unsigned short)' '))
  5429. char_width = (glyph->XAdvance + Info->SpacingHoriz) * 4 * scale;
  5430. }
  5431. else
  5432. {
  5433. if (const FntGlyph* glyph = FindGlyph((unsigned short)c))
  5434. char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale;
  5435. }
  5436. if (line_width + char_width >= max_width)
  5437. break;
  5438. line_width += char_width;
  5439. }
  5440. if (line_width > 0 || text_size.y == 0.0f)
  5441. {
  5442. if (text_size.x < line_width)
  5443. text_size.x = line_width;
  5444. text_size.y += line_height;
  5445. }
  5446. if (remaining)
  5447. *remaining = s;
  5448. return text_size;
  5449. }
  5450. void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect_ref, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices, float wrap_width) const
  5451. {
  5452. if (!text_end)
  5453. text_end = text_begin + strlen(text_begin);
  5454. const float line_height = (float)Info->FontSize;
  5455. const float scale = size / (float)Info->FontSize;
  5456. const float tex_scale_x = 1.0f / (float)Common->ScaleW;
  5457. const float tex_scale_y = 1.0f / (float)(Common->ScaleH);
  5458. const float outline = (float)Info->Outline;
  5459. // Align to be pixel perfect
  5460. pos.x = (float)(int)pos.x + DisplayOffset.x;
  5461. pos.y = (float)(int)pos.y + DisplayOffset.y;
  5462. const bool word_wrap_enabled = (wrap_width > 0.0f);
  5463. const char* word_wrap_eol = NULL;
  5464. const ImVec4 clip_rect = clip_rect_ref;
  5465. float x = pos.x;
  5466. float y = pos.y;
  5467. const char* s = text_begin;
  5468. while (s < text_end)
  5469. {
  5470. if (word_wrap_enabled)
  5471. {
  5472. // 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.
  5473. if (!word_wrap_eol)
  5474. {
  5475. word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - pos.x));
  5476. if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
  5477. 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
  5478. }
  5479. if (s >= word_wrap_eol)
  5480. {
  5481. x = pos.x;
  5482. y += line_height * scale;
  5483. word_wrap_eol = NULL;
  5484. // Wrapping skips upcoming blanks
  5485. while (s < text_end)
  5486. {
  5487. const char c = *s;
  5488. if (c == ' ' || c == '\t') { s++; } else if (c == '\n') { s++; break; } else { break; }
  5489. }
  5490. continue;
  5491. }
  5492. }
  5493. // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
  5494. unsigned int c;
  5495. const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
  5496. s += bytes_count > 0 ? bytes_count : 1;
  5497. if (c == '\n')
  5498. {
  5499. x = pos.x;
  5500. y += line_height * scale;
  5501. continue;
  5502. }
  5503. float char_width = 0.0f;
  5504. if (c == '\t')
  5505. {
  5506. // FIXME: Better TAB handling
  5507. if (const FntGlyph* glyph = FindGlyph((unsigned short)' '))
  5508. char_width += (glyph->XAdvance + Info->SpacingHoriz) * 4 * scale;
  5509. }
  5510. else if (const FntGlyph* glyph = FindGlyph((unsigned short)c))
  5511. {
  5512. char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale;
  5513. if (c != ' ')
  5514. {
  5515. // Clipping on Y is more likely
  5516. const float y1 = (float)(y + (glyph->YOffset + outline*2) * scale);
  5517. const float y2 = (float)(y1 + glyph->Height * scale);
  5518. if (y1 <= clip_rect.w && y2 >= clip_rect.y)
  5519. {
  5520. const float x1 = (float)(x + (glyph->XOffset + outline) * scale);
  5521. const float x2 = (float)(x1 + glyph->Width * scale);
  5522. if (x1 <= clip_rect.z && x2 >= clip_rect.x)
  5523. {
  5524. // Render a character
  5525. const float s1 = (glyph->X) * tex_scale_x;
  5526. const float t1 = (glyph->Y) * tex_scale_y;
  5527. const float s2 = (glyph->X + glyph->Width) * tex_scale_x;
  5528. const float t2 = (glyph->Y + glyph->Height) * tex_scale_y;
  5529. out_vertices[0].pos = ImVec2(x1, y1);
  5530. out_vertices[0].uv = ImVec2(s1, t1);
  5531. out_vertices[0].col = col;
  5532. out_vertices[1].pos = ImVec2(x2, y1);
  5533. out_vertices[1].uv = ImVec2(s2, t1);
  5534. out_vertices[1].col = col;
  5535. out_vertices[2].pos = ImVec2(x2, y2);
  5536. out_vertices[2].uv = ImVec2(s2, t2);
  5537. out_vertices[2].col = col;
  5538. out_vertices[3] = out_vertices[0];
  5539. out_vertices[4] = out_vertices[2];
  5540. out_vertices[5].pos = ImVec2(x1, y2);
  5541. out_vertices[5].uv = ImVec2(s1, t2);
  5542. out_vertices[5].col = col;
  5543. out_vertices += 6;
  5544. }
  5545. }
  5546. }
  5547. }
  5548. x += char_width;
  5549. }
  5550. }
  5551. //-----------------------------------------------------------------------------
  5552. // PLATFORM DEPENDANT HELPERS
  5553. //-----------------------------------------------------------------------------
  5554. #if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS)
  5555. #define WIN32_LEAN_AND_MEAN
  5556. #include <windows.h>
  5557. // Win32 API clipboard implementation
  5558. static const char* GetClipboardTextFn_DefaultImpl()
  5559. {
  5560. static char* buf_local = NULL;
  5561. if (buf_local)
  5562. {
  5563. ImGui::MemFree(buf_local);
  5564. buf_local = NULL;
  5565. }
  5566. if (!OpenClipboard(NULL))
  5567. return NULL;
  5568. HANDLE buf_handle = GetClipboardData(CF_TEXT);
  5569. if (buf_handle == NULL)
  5570. return NULL;
  5571. if (char* buf_global = (char*)GlobalLock(buf_handle))
  5572. buf_local = ImStrdup(buf_global);
  5573. GlobalUnlock(buf_handle);
  5574. CloseClipboard();
  5575. return buf_local;
  5576. }
  5577. // Win32 API clipboard implementation
  5578. static void SetClipboardTextFn_DefaultImpl(const char* text)
  5579. {
  5580. if (!OpenClipboard(NULL))
  5581. return;
  5582. const char* text_end = text + strlen(text);
  5583. const int buf_length = (int)(text_end - text) + 1;
  5584. HGLOBAL buf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)buf_length * sizeof(char));
  5585. if (buf_handle == NULL)
  5586. return;
  5587. char* buf_global = (char *)GlobalLock(buf_handle);
  5588. memcpy(buf_global, text, (size_t)(text_end - text));
  5589. buf_global[text_end - text] = 0;
  5590. GlobalUnlock(buf_handle);
  5591. EmptyClipboard();
  5592. SetClipboardData(CF_TEXT, buf_handle);
  5593. CloseClipboard();
  5594. }
  5595. #else
  5596. // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
  5597. static const char* GetClipboardTextFn_DefaultImpl()
  5598. {
  5599. return GImGui.PrivateClipboard;
  5600. }
  5601. // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
  5602. static void SetClipboardTextFn_DefaultImpl(const char* text)
  5603. {
  5604. if (GImGui.PrivateClipboard)
  5605. {
  5606. ImGui::MemFree(GImGui.PrivateClipboard);
  5607. GImGui.PrivateClipboard = NULL;
  5608. }
  5609. const char* text_end = text + strlen(text);
  5610. GImGui.PrivateClipboard = (char*)ImGui::MemAlloc((size_t)(text_end - text) + 1);
  5611. memcpy(GImGui.PrivateClipboard, text, (size_t)(text_end - text));
  5612. GImGui.PrivateClipboard[(size_t)(text_end - text)] = 0;
  5613. }
  5614. #endif
  5615. //-----------------------------------------------------------------------------
  5616. // HELP
  5617. //-----------------------------------------------------------------------------
  5618. void ImGui::ShowUserGuide()
  5619. {
  5620. ImGuiState& g = GImGui;
  5621. ImGui::BulletText("Double-click on title bar to collapse window.");
  5622. ImGui::BulletText("Click and drag on lower right corner to resize window.");
  5623. ImGui::BulletText("Click and drag on any empty space to move window.");
  5624. ImGui::BulletText("Mouse Wheel to scroll.");
  5625. if (g.IO.FontAllowUserScaling)
  5626. ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents.");
  5627. ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields.");
  5628. ImGui::BulletText("CTRL+Click on a slider to input text.");
  5629. ImGui::BulletText(
  5630. "While editing text:\n"
  5631. "- Hold SHIFT or use mouse to select text\n"
  5632. "- CTRL+Left/Right to word jump\n"
  5633. "- CTRL+A select all\n"
  5634. "- CTRL+X,CTRL+C,CTRL+V clipboard\n"
  5635. "- CTRL+Z,CTRL+Y undo/redo\n"
  5636. "- ESCAPE to revert\n"
  5637. "- You can apply arithmetic operators +,*,/ on numerical values.\n"
  5638. " Use +- to subtract.\n");
  5639. }
  5640. void ImGui::ShowStyleEditor(ImGuiStyle* ref)
  5641. {
  5642. ImGuiState& g = GImGui;
  5643. ImGuiStyle& style = g.Style;
  5644. const ImGuiStyle def;
  5645. if (ImGui::Button("Revert Style"))
  5646. g.Style = ref ? *ref : def;
  5647. if (ref)
  5648. {
  5649. ImGui::SameLine();
  5650. if (ImGui::Button("Save Style"))
  5651. *ref = g.Style;
  5652. }
  5653. ImGui::PushItemWidth(ImGui::GetWindowWidth()*0.55f);
  5654. if (ImGui::TreeNode("Sizes"))
  5655. {
  5656. 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.
  5657. ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f");
  5658. ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f");
  5659. ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f");
  5660. ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f");
  5661. ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f");
  5662. ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 20.0f, "%.0f");
  5663. ImGui::SliderFloat("TreeNodeSpacing", &style.TreeNodeSpacing, 0.0f, 20.0f, "%.0f");
  5664. ImGui::SliderFloat("ScrollBarWidth", &style.ScrollBarWidth, 0.0f, 20.0f, "%.0f");
  5665. ImGui::TreePop();
  5666. }
  5667. if (ImGui::TreeNode("Colors"))
  5668. {
  5669. static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB;
  5670. ImGui::RadioButton("RGB", &edit_mode, ImGuiColorEditMode_RGB);
  5671. ImGui::SameLine();
  5672. ImGui::RadioButton("HSV", &edit_mode, ImGuiColorEditMode_HSV);
  5673. ImGui::SameLine();
  5674. ImGui::RadioButton("HEX", &edit_mode, ImGuiColorEditMode_HEX);
  5675. static ImGuiTextFilter filter;
  5676. filter.Draw("Filter colors", 200);
  5677. ImGui::BeginChild("#colors", ImVec2(0, 300), true);
  5678. ImGui::ColorEditMode(edit_mode);
  5679. for (int i = 0; i < ImGuiCol_COUNT; i++)
  5680. {
  5681. const char* name = GetStyleColorName(i);
  5682. if (!filter.PassFilter(name))
  5683. continue;
  5684. ImGui::PushID(i);
  5685. ImGui::ColorEdit4(name, (float*)&style.Colors[i], true);
  5686. if (memcmp(&style.Colors[i], (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0)
  5687. {
  5688. ImGui::SameLine(); if (ImGui::Button("Revert")) style.Colors[i] = ref ? ref->Colors[i] : def.Colors[i];
  5689. if (ref) { ImGui::SameLine(); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i]; }
  5690. }
  5691. ImGui::PopID();
  5692. }
  5693. ImGui::EndChild();
  5694. ImGui::TreePop();
  5695. }
  5696. /*
  5697. // Font scaling options
  5698. // Note that those are not actually part of the style.
  5699. if (ImGui::TreeNode("Font"))
  5700. {
  5701. static float window_scale = 1.0f;
  5702. ImGui::SliderFloat("window scale", &window_scale, 0.3f, 2.0f, "%.1f"); // scale only this window
  5703. ImGui::SliderFloat("font scale", &ImGui::GetIO().Font->Scale, 0.3f, 2.0f, "%.1f"); // scale only this font
  5704. ImGui::SliderFloat("global scale", &ImGui::GetIO().FontGlobalScale, 0.3f, 2.0f, "%.1f"); // scale everything
  5705. ImGui::SetWindowFontScale(window_scale);
  5706. ImGui::TreePop();
  5707. }
  5708. */
  5709. ImGui::PopItemWidth();
  5710. }
  5711. //-----------------------------------------------------------------------------
  5712. // SAMPLE CODE
  5713. //-----------------------------------------------------------------------------
  5714. static void ShowExampleAppConsole(bool* open);
  5715. static void ShowExampleAppLongText(bool* open);
  5716. static void ShowExampleAppAutoResize(bool* open);
  5717. // Demonstrate ImGui features (unfortunately this makes this function a little bloated!)
  5718. void ImGui::ShowTestWindow(bool* open)
  5719. {
  5720. static bool no_titlebar = false;
  5721. static bool no_border = true;
  5722. static bool no_resize = false;
  5723. static bool no_move = false;
  5724. static bool no_scrollbar = false;
  5725. static float fill_alpha = 0.65f;
  5726. const ImGuiWindowFlags layout_flags = (no_titlebar ? ImGuiWindowFlags_NoTitleBar : 0) | (no_border ? 0 : ImGuiWindowFlags_ShowBorders) | (no_resize ? ImGuiWindowFlags_NoResize : 0) | (no_move ? ImGuiWindowFlags_NoMove : 0) | (no_scrollbar ? ImGuiWindowFlags_NoScrollbar : 0);
  5727. ImGui::Begin("ImGui Test", open, ImVec2(550,680), fill_alpha, layout_flags);
  5728. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f);
  5729. ImGui::Text("ImGui says hello.");
  5730. //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
  5731. //ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel);
  5732. ImGui::Spacing();
  5733. if (ImGui::CollapsingHeader("Help"))
  5734. {
  5735. ImGui::TextWrapped("This window is being created by the ShowTestWindow() function. Please refer to the code for programming reference.\n\nUser Guide:");
  5736. ImGui::ShowUserGuide();
  5737. }
  5738. if (ImGui::CollapsingHeader("Window options"))
  5739. {
  5740. ImGui::Checkbox("no titlebar", &no_titlebar); ImGui::SameLine(150);
  5741. ImGui::Checkbox("no border", &no_border); ImGui::SameLine(300);
  5742. ImGui::Checkbox("no resize", &no_resize);
  5743. ImGui::Checkbox("no move", &no_move); ImGui::SameLine(150);
  5744. ImGui::Checkbox("no scrollbar", &no_scrollbar);
  5745. ImGui::SliderFloat("fill alpha", &fill_alpha, 0.0f, 1.0f);
  5746. if (ImGui::TreeNode("Style Editor"))
  5747. {
  5748. ImGui::ShowStyleEditor();
  5749. ImGui::TreePop();
  5750. }
  5751. if (ImGui::TreeNode("Logging"))
  5752. {
  5753. ImGui::LogButtons();
  5754. ImGui::TreePop();
  5755. }
  5756. }
  5757. if (ImGui::CollapsingHeader("Widgets"))
  5758. {
  5759. static bool a=false;
  5760. if (ImGui::Button("Button")) { printf("Clicked\n"); a ^= 1; }
  5761. if (a)
  5762. {
  5763. ImGui::SameLine();
  5764. ImGui::Text("Thanks for clicking me!");
  5765. }
  5766. if (ImGui::TreeNode("Tree"))
  5767. {
  5768. for (size_t i = 0; i < 5; i++)
  5769. {
  5770. if (ImGui::TreeNode((void*)i, "Child %d", i))
  5771. {
  5772. ImGui::Text("blah blah");
  5773. ImGui::SameLine();
  5774. if (ImGui::SmallButton("print"))
  5775. printf("Child %d pressed", (int)i);
  5776. ImGui::TreePop();
  5777. }
  5778. }
  5779. ImGui::TreePop();
  5780. }
  5781. if (ImGui::TreeNode("Bullets"))
  5782. {
  5783. ImGui::BulletText("Bullet point 1");
  5784. ImGui::BulletText("Bullet point 2\nOn multiple lines");
  5785. ImGui::BulletText("Bullet point 3");
  5786. ImGui::TreePop();
  5787. }
  5788. if (ImGui::TreeNode("Colored Text"))
  5789. {
  5790. // Using shortcut. You can use PushStyleColor()/PopStyleColor() for more flexibility.
  5791. ImGui::TextColored(ImVec4(1.0f,0.0f,1.0f,1.0f), "Pink");
  5792. ImGui::TextColored(ImVec4(1.0f,1.0f,0.0f,1.0f), "Yellow");
  5793. ImGui::TreePop();
  5794. }
  5795. if (ImGui::TreeNode("Word Wrapping"))
  5796. {
  5797. // Using shortcut. You can use PushTextWrapPos()/PopTextWrapPos() for more flexibility.
  5798. ImGui::TextWrapped("This is a long paragraph. The text should automatically wrap on the edge of the window. The current implementation follows simple rules that works for English and possibly other languages.");
  5799. ImGui::Spacing();
  5800. static float wrap_width = 200.0f;
  5801. ImGui::SliderFloat("Wrap width", &wrap_width, -20, 600, "%.0f");
  5802. ImGui::Text("Test paragraph 1:");
  5803. ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF);
  5804. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  5805. ImGui::Text("lazy dog. This paragraph is made to fit within %.0f pixels. The quick brown fox jumps over the lazy dog.", wrap_width);
  5806. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemBoxMin(), ImGui::GetItemBoxMax(), 0xFF00FFFF);
  5807. ImGui::PopTextWrapPos();
  5808. ImGui::Text("Test paragraph 2:");
  5809. ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF);
  5810. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  5811. ImGui::Text("aaaaaaaa bbbbbbbb, cccccccc,dddddddd. eeeeeeee ffffffff. gggggggg!hhhhhhhh");
  5812. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemBoxMin(), ImGui::GetItemBoxMax(), 0xFF00FFFF);
  5813. ImGui::PopTextWrapPos();
  5814. ImGui::TreePop();
  5815. }
  5816. if (ImGui::TreeNode("UTF-8 Text"))
  5817. {
  5818. // UTF-8 test (need a suitable font, try extra_fonts/mplus* files for example)
  5819. // Most compiler appears to support UTF-8 in source code (with Visual Studio you need to save your file as 'UTF-8 without signature')
  5820. // 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.
  5821. // In your own application please be reasonable and use UTF-8 in the source or get the data from external files! :)
  5822. ImGui::TextWrapped("(CJK text will only appears if the font supports it. Please check in the extra_fonts/ folder if you intend to use non-ASCII characters. Note that characters values are preserved even if the font cannot be displayed, so you can safely copy & paste garbled characters.)");
  5823. ImGui::Text("Hiragana: \xe3\x81\x8b\xe3\x81\x8d\xe3\x81\x8f\xe3\x81\x91\xe3\x81\x93 (kakikukeko)");
  5824. ImGui::Text("Kanjis: \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e (nihongo)");
  5825. static char buf[32] = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e";
  5826. ImGui::InputText("UTF-8 input", buf, IM_ARRAYSIZE(buf));
  5827. ImGui::TreePop();
  5828. }
  5829. static bool check = true;
  5830. ImGui::Checkbox("checkbox", &check);
  5831. static int e = 0;
  5832. ImGui::RadioButton("radio a", &e, 0); ImGui::SameLine();
  5833. ImGui::RadioButton("radio b", &e, 1); ImGui::SameLine();
  5834. ImGui::RadioButton("radio c", &e, 2);
  5835. ImGui::Text("Hover me");
  5836. if (ImGui::IsItemHovered())
  5837. ImGui::SetTooltip("I am a tooltip");
  5838. ImGui::SameLine();
  5839. ImGui::Text("- or me");
  5840. if (ImGui::IsItemHovered())
  5841. {
  5842. ImGui::BeginTooltip();
  5843. ImGui::Text("I am a fancy tooltip");
  5844. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  5845. ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr));
  5846. ImGui::EndTooltip();
  5847. }
  5848. // Testing IMGUI_ONCE_UPON_A_FRAME macro
  5849. //for (int i = 0; i < 5; i++)
  5850. //{
  5851. // IMGUI_ONCE_UPON_A_FRAME
  5852. // {
  5853. // ImGui::Text("This will be displayed only once.");
  5854. // }
  5855. //}
  5856. ImGui::Separator();
  5857. static int item = 1;
  5858. ImGui::Combo("combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0");
  5859. const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK" };
  5860. static int item2 = -1;
  5861. ImGui::Combo("combo scroll", &item2, items, IM_ARRAYSIZE(items));
  5862. static char str0[128] = "Hello, world!";
  5863. static int i0=123;
  5864. static float f0=0.001f;
  5865. ImGui::InputText("string", str0, IM_ARRAYSIZE(str0));
  5866. ImGui::InputInt("input int", &i0);
  5867. ImGui::InputFloat("input float", &f0, 0.01f, 1.0f);
  5868. //static float vec2a[3] = { 0.10f, 0.20f };
  5869. //ImGui::InputFloat2("input float2", vec2a);
  5870. static float vec3a[3] = { 0.10f, 0.20f, 0.30f };
  5871. ImGui::InputFloat3("input float3", vec3a);
  5872. //static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
  5873. //ImGui::InputFloat4("input float4", vec4a);
  5874. static int i1=0;
  5875. static int i2=42;
  5876. ImGui::SliderInt("int 0..3", &i1, 0, 3);
  5877. ImGui::SliderInt("int -100..100", &i2, -100, 100);
  5878. static float f1=1.123f;
  5879. static float f2=0;
  5880. static float f3=0;
  5881. static float f4=123456789.0f;
  5882. ImGui::SliderFloat("float", &f1, 0.0f, 2.0f);
  5883. ImGui::SliderFloat("log float", &f2, 0.0f, 10.0f, "%.4f", 2.0f);
  5884. ImGui::SliderFloat("signed log float", &f3, -10.0f, 10.0f, "%.4f", 3.0f);
  5885. ImGui::SliderFloat("unbound float", &f4, -FLT_MAX, FLT_MAX, "%.4f");
  5886. static float angle = 0.0f;
  5887. ImGui::SliderAngle("angle", &angle);
  5888. //static float vec2b[3] = { 0.10f, 0.20f };
  5889. //ImGui::SliderFloat2("slider float2", vec2b, 0.0f, 1.0f);
  5890. static float vec3b[3] = { 0.10f, 0.20f, 0.30f };
  5891. ImGui::SliderFloat3("slider float3", vec3b, 0.0f, 1.0f);
  5892. //static float vec4b[4] = { 0.10f, 0.20f, 0.30f, 0.40f };
  5893. //ImGui::SliderFloat4("slider float4", vec4b, 0.0f, 1.0f);
  5894. static float col1[3] = { 1.0f,0.0f,0.2f };
  5895. static float col2[4] = { 0.4f,0.7f,0.0f,0.5f };
  5896. ImGui::ColorEdit3("color 1", col1);
  5897. ImGui::ColorEdit4("color 2", col2);
  5898. }
  5899. if (ImGui::CollapsingHeader("Graphs widgets"))
  5900. {
  5901. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  5902. ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr));
  5903. static bool pause;
  5904. static ImVector<float> values; if (values.empty()) { values.resize(100); memset(&values.front(), 0, values.size()*sizeof(float)); }
  5905. static size_t values_offset = 0;
  5906. if (!pause)
  5907. {
  5908. // create dummy data at fixed 60 hz rate
  5909. static float refresh_time = -1.0f;
  5910. if (ImGui::GetTime() > refresh_time + 1.0f/60.0f)
  5911. {
  5912. refresh_time = ImGui::GetTime();
  5913. static float phase = 0.0f;
  5914. values[values_offset] = cosf(phase);
  5915. values_offset = (values_offset+1)%values.size();
  5916. phase += 0.10f*values_offset;
  5917. }
  5918. }
  5919. ImGui::PlotLines("Frame Times", &values.front(), (int)values.size(), (int)values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,70));
  5920. ImGui::SameLine(); ImGui::Checkbox("pause", &pause);
  5921. ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,70));
  5922. }
  5923. if (ImGui::CollapsingHeader("Widgets on same line"))
  5924. {
  5925. // Text
  5926. ImGui::Text("Hello");
  5927. ImGui::SameLine();
  5928. ImGui::Text("World");
  5929. // Button
  5930. if (ImGui::Button("Banana")) printf("Pressed!\n");
  5931. ImGui::SameLine();
  5932. ImGui::Button("Apple");
  5933. ImGui::SameLine();
  5934. ImGui::Button("Corniflower");
  5935. // Button
  5936. ImGui::SmallButton("Banana");
  5937. ImGui::SameLine();
  5938. ImGui::SmallButton("Apple");
  5939. ImGui::SameLine();
  5940. ImGui::SmallButton("Corniflower");
  5941. ImGui::SameLine();
  5942. ImGui::Text("Small buttons fit in a text block");
  5943. // Checkbox
  5944. static bool c1=false,c2=false,c3=false,c4=false;
  5945. ImGui::Checkbox("My", &c1);
  5946. ImGui::SameLine();
  5947. ImGui::Checkbox("Tailor", &c2);
  5948. ImGui::SameLine();
  5949. ImGui::Checkbox("Is", &c3);
  5950. ImGui::SameLine();
  5951. ImGui::Checkbox("Rich", &c4);
  5952. // SliderFloat
  5953. static float f0=1.0f, f1=2.0f, f2=3.0f;
  5954. ImGui::PushItemWidth(80);
  5955. ImGui::SliderFloat("f0", &f0, 0.0f,5.0f);
  5956. ImGui::SameLine();
  5957. ImGui::SliderFloat("f1", &f1, 0.0f,5.0f);
  5958. ImGui::SameLine();
  5959. ImGui::SliderFloat("f2", &f2, 0.0f,5.0f);
  5960. // InputText
  5961. static char s0[128] = "one", s1[128] = "two", s2[128] = "three";
  5962. ImGui::InputText("s0", s0, 128);
  5963. ImGui::SameLine();
  5964. ImGui::InputText("s1", s1, 128);
  5965. ImGui::SameLine();
  5966. ImGui::InputText("s2", s2, 128);
  5967. // LabelText
  5968. ImGui::LabelText("l0", "one");
  5969. ImGui::SameLine();
  5970. ImGui::LabelText("l0", "two");
  5971. ImGui::SameLine();
  5972. ImGui::LabelText("l0", "three");
  5973. ImGui::PopItemWidth();
  5974. }
  5975. if (ImGui::CollapsingHeader("Child regions"))
  5976. {
  5977. ImGui::Text("Without border");
  5978. static int line = 50;
  5979. bool goto_line = ImGui::Button("Goto");
  5980. ImGui::SameLine();
  5981. ImGui::PushItemWidth(100);
  5982. goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue);
  5983. ImGui::PopItemWidth();
  5984. ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowWidth()*0.5f,300));
  5985. for (int i = 0; i < 100; i++)
  5986. {
  5987. ImGui::Text("%04d: scrollable region", i);
  5988. if (goto_line && line == i)
  5989. ImGui::SetScrollPosHere();
  5990. }
  5991. if (goto_line && line >= 100)
  5992. ImGui::SetScrollPosHere();
  5993. ImGui::EndChild();
  5994. ImGui::SameLine();
  5995. ImGui::BeginChild("Sub2", ImVec2(0,300), true);
  5996. ImGui::Text("With border");
  5997. ImGui::Columns(2);
  5998. for (int i = 0; i < 100; i++)
  5999. {
  6000. char buf[32];
  6001. ImFormatString(buf, IM_ARRAYSIZE(buf), "%08x", i*5731);
  6002. ImGui::Button(buf);
  6003. ImGui::NextColumn();
  6004. }
  6005. ImGui::EndChild();
  6006. }
  6007. if (ImGui::CollapsingHeader("Columns"))
  6008. {
  6009. ImGui::Columns(4, "data", true);
  6010. ImGui::Text("ID"); ImGui::NextColumn();
  6011. ImGui::Text("Name"); ImGui::NextColumn();
  6012. ImGui::Text("Path"); ImGui::NextColumn();
  6013. ImGui::Text("Flags"); ImGui::NextColumn();
  6014. ImGui::Separator();
  6015. ImGui::Text("0000"); ImGui::NextColumn();
  6016. ImGui::Text("Robert"); ImGui::NextColumn();
  6017. ImGui::Text("/path/robert"); ImGui::NextColumn();
  6018. ImGui::Text("...."); ImGui::NextColumn();
  6019. ImGui::Text("0001"); ImGui::NextColumn();
  6020. ImGui::Text("Stephanie"); ImGui::NextColumn();
  6021. ImGui::Text("/path/stephanie"); ImGui::NextColumn();
  6022. ImGui::Text("line 1"); ImGui::Text("line 2"); ImGui::NextColumn(); // two lines, two items
  6023. ImGui::Text("0002"); ImGui::NextColumn();
  6024. ImGui::Text("C64"); ImGui::NextColumn();
  6025. ImGui::Text("/path/computer"); ImGui::NextColumn();
  6026. ImGui::Text("...."); ImGui::NextColumn();
  6027. ImGui::Columns(1);
  6028. ImGui::Separator();
  6029. ImGui::Columns(3, "mixed");
  6030. // Create multiple items in a same cell because switching to next column
  6031. static int e = 0;
  6032. ImGui::Text("Hello");
  6033. ImGui::Button("Banana");
  6034. ImGui::RadioButton("radio a", &e, 0);
  6035. ImGui::NextColumn();
  6036. ImGui::Text("ImGui");
  6037. ImGui::Button("Apple");
  6038. ImGui::RadioButton("radio b", &e, 1);
  6039. ImGui::Text("An extra line here.");
  6040. ImGui::NextColumn();
  6041. ImGui::Text("World!");
  6042. ImGui::Button("Corniflower");
  6043. ImGui::RadioButton("radio c", &e, 2);
  6044. ImGui::NextColumn();
  6045. if (ImGui::CollapsingHeader("Category A")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  6046. if (ImGui::CollapsingHeader("Category B")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  6047. if (ImGui::CollapsingHeader("Category C")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  6048. ImGui::Columns(1);
  6049. ImGui::Separator();
  6050. ImGui::Columns(2, "multiple components");
  6051. static float foo = 1.0f;
  6052. ImGui::InputFloat("red", &foo, 0.05f, 0, 3); ImGui::NextColumn();
  6053. static float bar = 1.0f;
  6054. ImGui::InputFloat("blue", &bar, 0.05f, 0, 3); ImGui::NextColumn();
  6055. ImGui::Columns(1);
  6056. ImGui::Separator();
  6057. ImGui::Columns(2, "word wrapping");
  6058. ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
  6059. ImGui::Text("Hello Left");
  6060. ImGui::NextColumn();
  6061. ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
  6062. ImGui::Text("Hello Right");
  6063. ImGui::Columns(1);
  6064. ImGui::Separator();
  6065. if (ImGui::TreeNode("Inside a tree.."))
  6066. {
  6067. if (ImGui::TreeNode("node 1 (with borders)"))
  6068. {
  6069. ImGui::Columns(4);
  6070. ImGui::Text("aaa"); ImGui::NextColumn();
  6071. ImGui::Text("bbb"); ImGui::NextColumn();
  6072. ImGui::Text("ccc"); ImGui::NextColumn();
  6073. ImGui::Text("ddd"); ImGui::NextColumn();
  6074. ImGui::Text("eee"); ImGui::NextColumn();
  6075. ImGui::Text("fff"); ImGui::NextColumn();
  6076. ImGui::Text("ggg"); ImGui::NextColumn();
  6077. ImGui::Text("hhh"); ImGui::NextColumn();
  6078. ImGui::Columns(1);
  6079. ImGui::TreePop();
  6080. }
  6081. if (ImGui::TreeNode("node 2 (without borders)"))
  6082. {
  6083. ImGui::Columns(4, NULL, false);
  6084. ImGui::Text("aaa"); ImGui::NextColumn();
  6085. ImGui::Text("bbb"); ImGui::NextColumn();
  6086. ImGui::Text("ccc"); ImGui::NextColumn();
  6087. ImGui::Text("ddd"); ImGui::NextColumn();
  6088. ImGui::Text("eee"); ImGui::NextColumn();
  6089. ImGui::Text("fff"); ImGui::NextColumn();
  6090. ImGui::Text("ggg"); ImGui::NextColumn();
  6091. ImGui::Text("hhh"); ImGui::NextColumn();
  6092. ImGui::Columns(1);
  6093. ImGui::TreePop();
  6094. }
  6095. ImGui::TreePop();
  6096. }
  6097. }
  6098. if (ImGui::CollapsingHeader("Filtering"))
  6099. {
  6100. static ImGuiTextFilter filter;
  6101. ImGui::Text("Filter usage:\n"
  6102. " \"\" display all lines\n"
  6103. " \"xxx\" display lines containing \"xxx\"\n"
  6104. " \"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n"
  6105. " \"-xxx\" hide lines containing \"xxx\"");
  6106. filter.Draw();
  6107. const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" };
  6108. for (size_t i = 0; i < IM_ARRAYSIZE(lines); i++)
  6109. if (filter.PassFilter(lines[i]))
  6110. ImGui::BulletText("%s", lines[i]);
  6111. }
  6112. if (ImGui::CollapsingHeader("Keyboard & Focus"))
  6113. {
  6114. if (ImGui::TreeNode("Tabbing"))
  6115. {
  6116. ImGui::Text("Use TAB/SHIFT+TAB to cycle thru keyboard editable fields.");
  6117. static char buf[32] = "dummy";
  6118. ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
  6119. ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
  6120. ImGui::InputText("3", buf, IM_ARRAYSIZE(buf));
  6121. ImGui::PushAllowKeyboardFocus(false);
  6122. ImGui::InputText("4 (tab skip)", buf, IM_ARRAYSIZE(buf));
  6123. //ImGui::SameLine(); ImGui::Text("(?)"); if (ImGui::IsHovered()) ImGui::SetTooltip("Use ImGui::PushAllowKeyboardFocus(bool)\nto disable tabbing through certain widgets.");
  6124. ImGui::PopAllowKeyboardFocus();
  6125. ImGui::InputText("5", buf, IM_ARRAYSIZE(buf));
  6126. ImGui::TreePop();
  6127. }
  6128. if (ImGui::TreeNode("Focus from code"))
  6129. {
  6130. bool focus_1 = ImGui::Button("Focus on 1"); ImGui::SameLine();
  6131. bool focus_2 = ImGui::Button("Focus on 2"); ImGui::SameLine();
  6132. bool focus_3 = ImGui::Button("Focus on 3");
  6133. int has_focus = 0;
  6134. static char buf[128] = "click on a button to set focus";
  6135. if (focus_1) ImGui::SetKeyboardFocusHere();
  6136. ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
  6137. if (ImGui::IsItemFocused()) has_focus = 1;
  6138. if (focus_2) ImGui::SetKeyboardFocusHere();
  6139. ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
  6140. if (ImGui::IsItemFocused()) has_focus = 2;
  6141. ImGui::PushAllowKeyboardFocus(false);
  6142. if (focus_3) ImGui::SetKeyboardFocusHere();
  6143. ImGui::InputText("3 (tab skip)", buf, IM_ARRAYSIZE(buf));
  6144. if (ImGui::IsItemFocused()) has_focus = 3;
  6145. ImGui::PopAllowKeyboardFocus();
  6146. if (has_focus)
  6147. ImGui::Text("Item with focus: %d", has_focus);
  6148. else
  6149. ImGui::Text("Item with focus: <none>");
  6150. ImGui::TreePop();
  6151. }
  6152. }
  6153. static bool show_app_console = false;
  6154. static bool show_app_long_text = false;
  6155. static bool show_app_auto_resize = false;
  6156. if (ImGui::CollapsingHeader("App Examples"))
  6157. {
  6158. ImGui::Checkbox("Console", &show_app_console);
  6159. ImGui::Checkbox("Long text display", &show_app_long_text);
  6160. ImGui::Checkbox("Auto-resizing window", &show_app_auto_resize);
  6161. }
  6162. if (show_app_console)
  6163. ShowExampleAppConsole(&show_app_console);
  6164. if (show_app_long_text)
  6165. ShowExampleAppLongText(&show_app_long_text);
  6166. if (show_app_auto_resize)
  6167. ShowExampleAppAutoResize(&show_app_auto_resize);
  6168. ImGui::End();
  6169. }
  6170. static void ShowExampleAppAutoResize(bool* open)
  6171. {
  6172. if (!ImGui::Begin("Example: Auto-Resizing Window", open, ImVec2(0,0), -1.0f, ImGuiWindowFlags_AlwaysAutoResize))
  6173. {
  6174. ImGui::End();
  6175. return;
  6176. }
  6177. static int lines = 10;
  6178. 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.");
  6179. ImGui::SliderInt("Number of lines", &lines, 1, 20);
  6180. for (int i = 0; i < lines; i++)
  6181. ImGui::Text("%*sThis is line %d", i*4, "", i); // Pad with space to extend size horizontally
  6182. ImGui::End();
  6183. }
  6184. struct ExampleAppConsole
  6185. {
  6186. ImVector<char*> Items;
  6187. bool NewItems;
  6188. void Clear()
  6189. {
  6190. for (size_t i = 0; i < Items.size(); i++)
  6191. ImGui::MemFree(Items[i]);
  6192. Items.clear();
  6193. NewItems = true;
  6194. }
  6195. void AddLog(const char* fmt, ...)
  6196. {
  6197. char buf[512];
  6198. va_list args;
  6199. va_start(args, fmt);
  6200. ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  6201. va_end(args);
  6202. Items.push_back(ImStrdup(buf));
  6203. NewItems = true;
  6204. }
  6205. void TextEditCallback(ImGuiTextEditCallbackData* data)
  6206. {
  6207. //AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
  6208. switch (data->EventKey)
  6209. {
  6210. case ImGuiKey_Tab:
  6211. {
  6212. // Example of TEXT COMPLETION
  6213. // Locate beginning of current word
  6214. const char* word_end = data->Buf + data->CursorPos;
  6215. const char* word_start = word_end;
  6216. while (word_start > data->Buf)
  6217. {
  6218. const char c = word_start[-1];
  6219. if (c == ' ' || c == '\t' || c == ',' || c == ';')
  6220. break;
  6221. word_start--;
  6222. }
  6223. // Build a list of candidates
  6224. const char* commands[] = { "HELP", "CLEAR", "CLASSIFY" };
  6225. ImVector<const char*> candidates;
  6226. for (size_t i = 0; i < IM_ARRAYSIZE(commands); i++)
  6227. if (ImStrnicmp(commands[i], word_start, word_end-word_start) == 0)
  6228. candidates.push_back(commands[i]);
  6229. if (candidates.size() == 0)
  6230. {
  6231. // No match
  6232. AddLog("No match for \"%.*s\"!\n", word_end-word_start, word_start);
  6233. }
  6234. else if (candidates.size() == 1)
  6235. {
  6236. // Single match. Delete the beginning of the word and replace it entirely so we've got nice casing
  6237. data->DeleteChars(word_start-data->Buf, word_end-word_start);
  6238. data->InsertChars(data->CursorPos, candidates[0]);
  6239. data->InsertChars(data->CursorPos, " ");
  6240. }
  6241. else
  6242. {
  6243. // Multiple matches. Complete as much as we can, so inputing "C" will complete to "CL" and display "CLEAR" and "CLASSIFY"
  6244. int match_len = word_end - word_start;
  6245. while (true)
  6246. {
  6247. int c = 0;
  6248. bool all_candidates_matches = true;
  6249. for (size_t i = 0; i < candidates.size() && all_candidates_matches; i++)
  6250. {
  6251. if (i == 0)
  6252. c = toupper(candidates[i][match_len]);
  6253. else if (c != toupper(candidates[i][match_len]))
  6254. all_candidates_matches = false;
  6255. }
  6256. if (!all_candidates_matches)
  6257. break;
  6258. match_len++;
  6259. }
  6260. if (match_len > 0)
  6261. {
  6262. data->DeleteChars(word_start - data->Buf, word_end-word_start);
  6263. data->InsertChars(data->CursorPos, candidates[0], candidates[0] + match_len);
  6264. }
  6265. // List matches
  6266. AddLog("Possible matches:\n");
  6267. for (size_t i = 0; i < candidates.size(); i++)
  6268. AddLog("- %s\n", candidates[i]);
  6269. }
  6270. break;
  6271. }
  6272. }
  6273. }
  6274. };
  6275. static void ShowExampleAppConsole_TextEditCallback(ImGuiTextEditCallbackData* data)
  6276. {
  6277. ExampleAppConsole* console = (ExampleAppConsole*)data->UserData;
  6278. console->TextEditCallback(data);
  6279. }
  6280. static void ShowExampleAppConsole(bool* open)
  6281. {
  6282. if (!ImGui::Begin("Example: Console", open, ImVec2(520,600)))
  6283. {
  6284. ImGui::End();
  6285. return;
  6286. }
  6287. ImGui::TextWrapped("This example implement a simple console. A more elaborate implementation may want to store individual entries along with extra data such as timestamp, emitter, etc.");
  6288. ImGui::TextWrapped("Press TAB to use text completion.");
  6289. // TODO: display from bottom
  6290. // TODO: clip manually
  6291. // TODO: history
  6292. static ExampleAppConsole console;
  6293. static char input[256] = "";
  6294. if (ImGui::SmallButton("Add Dummy Text")) console.AddLog("some text\nsome more text");
  6295. ImGui::SameLine();
  6296. if (ImGui::SmallButton("Add Dummy Error")) console.AddLog("[error] something went wrong");
  6297. ImGui::SameLine();
  6298. if (ImGui::SmallButton("Clear all")) console.Clear();
  6299. ImGui::Separator();
  6300. ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
  6301. static ImGuiTextFilter filter;
  6302. filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
  6303. if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover
  6304. ImGui::PopStyleVar();
  6305. ImGui::Separator();
  6306. ImGui::BeginChild("ScrollingRegion", ImVec2(0,-ImGui::GetTextLineSpacing()*2));
  6307. // 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());
  6308. // NB- if you have lots of text this approach may be too inefficient. You can seek and display only the lines that are on display using a technique similar to what TextUnformatted() does,
  6309. // or faster if your entries are already stored into a table.
  6310. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // tighten spacing
  6311. ImGui::GetStyle().ItemSpacing.y = 1; // tighten spacing
  6312. for (size_t i = 0; i < console.Items.size(); i++)
  6313. {
  6314. const char* item = console.Items[i];
  6315. if (!filter.PassFilter(item))
  6316. continue;
  6317. ImVec4 col(1,1,1,1);
  6318. if (strstr(item, "[error]")) col = ImVec4(1.0f,0.4f,0.4f,1.0f);
  6319. else if (strncmp(item, "# ", 2) == 0) col = ImVec4(1.0f,0.8f,0.6f,1.0f);
  6320. ImGui::PushStyleColor(ImGuiCol_Text, col);
  6321. ImGui::TextUnformatted(item);
  6322. ImGui::PopStyleColor();
  6323. }
  6324. ImGui::PopStyleVar();
  6325. if (console.NewItems)
  6326. {
  6327. ImGui::SetScrollPosHere();
  6328. console.NewItems = false;
  6329. }
  6330. ImGui::EndChild();
  6331. ImGui::Separator();
  6332. if (ImGui::InputText("Input", input, IM_ARRAYSIZE(input), ImGuiInputTextFlags_EnterReturnsTrue|ImGuiInputTextFlags_CallbackCompletion, &ShowExampleAppConsole_TextEditCallback, (void*)&console))
  6333. {
  6334. const char* input_trimmed_end = input+strlen(input);
  6335. while (input_trimmed_end > input && input_trimmed_end[-1] == ' ')
  6336. input_trimmed_end--;
  6337. if (input_trimmed_end > input)
  6338. {
  6339. console.AddLog("# %s\n", input);
  6340. console.AddLog("Unknown command: '%.*s'\n", input_trimmed_end-input, input); // NB: we don't actually handle any command in this sample code
  6341. }
  6342. strcpy(input, "");
  6343. }
  6344. if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover
  6345. ImGui::End();
  6346. }
  6347. static void ShowExampleAppLongText(bool* open)
  6348. {
  6349. if (!ImGui::Begin("Example: Long text display", open, ImVec2(520,600)))
  6350. {
  6351. ImGui::End();
  6352. return;
  6353. }
  6354. static ImGuiTextBuffer log;
  6355. static int lines = 0;
  6356. ImGui::Text("Printing unusually long amount of text.");
  6357. ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size());
  6358. if (ImGui::Button("Clear")) { log.clear(); lines = 0; }
  6359. ImGui::SameLine();
  6360. if (ImGui::Button("Add 1000 lines"))
  6361. {
  6362. for (int i = 0; i < 1000; i++)
  6363. log.append("%i The quick brown fox jumps over the lazy dog\n", lines+i);
  6364. lines += 1000;
  6365. }
  6366. ImGui::BeginChild("Log");
  6367. ImGui::TextUnformatted(log.begin(), log.end());
  6368. ImGui::EndChild();
  6369. ImGui::End();
  6370. }
  6371. // End of Sample code
  6372. //-----------------------------------------------------------------------------
  6373. // Font data
  6374. // Bitmap exported from proggy_clean.fon (c) by Tristan Grimmer http://upperbounds.net/
  6375. // Also available on unofficial ProggyFonts mirror http://www.proggyfonts.net
  6376. //-----------------------------------------------------------------------------
  6377. /*
  6378. // Copyright (c) 2004, 2005 Tristan Grimmer
  6379. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6380. // of this software and associated documentation files (the "Software"), to deal
  6381. // in the Software without restriction, including without limitation the rights
  6382. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  6383. // copies of the Software, and to permit persons to whom the Software is
  6384. // furnished to do so, subject to the following conditions:
  6385. // The above copyright notice and this permission notice shall be included in all
  6386. // copies or substantial portions of the Software.
  6387. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  6388. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  6389. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  6390. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  6391. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  6392. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  6393. // SOFTWARE.
  6394. */
  6395. //-----------------------------------------------------------------------------
  6396. // Fonts exported with BMFont http://www.angelcode.com/products/bmfont
  6397. // We are using bmfont format and you can load your own font from a file by setting up ImGui::GetIO().Font
  6398. // PNG further compressed with pngout.exe http://advsys.net/ken/utils.htm
  6399. // Manually converted to C++ array using the following program:
  6400. /*
  6401. static void binary_to_c(const char* name_in, const char* symbol)
  6402. {
  6403. FILE* fi = fopen(name_in, "rb"); fseek(fi, 0, SEEK_END); long sz = ftell(fi); fseek(fi, 0, SEEK_SET);
  6404. fprintf(stdout, "static const unsigned int %s_size = %d;\n", symbol, sz);
  6405. fprintf(stdout, "static const unsigned int %s_data[%d/4] =\n{", symbol, ((sz+3)/4)*4);
  6406. int column = 0;
  6407. for (unsigned int data = 0; fread(&data, 1, 4, fi); data = 0)
  6408. if ((column++ % 12) == 0)
  6409. fprintf(stdout, "\n 0x%08x, ", data);
  6410. else
  6411. fprintf(stdout, "0x%08x, ", data);
  6412. fprintf(stdout, "\n};\n\n");
  6413. fclose(fi);
  6414. }
  6415. int main(int argc, char** argv)
  6416. {
  6417. binary_to_c("proggy_clean_13.fnt", "proggy_clean_13_fnt");
  6418. binary_to_c("proggy_clean_13.png", "proggy_clean_13_png");
  6419. return 1;
  6420. }
  6421. */
  6422. //-----------------------------------------------------------------------------
  6423. static const unsigned int proggy_clean_13_png_size = 1557;
  6424. static const unsigned int proggy_clean_13_png_data[1560/4] =
  6425. {
  6426. 0x474e5089, 0x0a1a0a0d, 0x0d000000, 0x52444849, 0x00010000, 0x80000000, 0x00000308, 0x476bd300, 0x00000038, 0x544c5006, 0x00000045, 0xa5ffffff,
  6427. 0x00dd9fd9, 0x74010000, 0x00534e52, 0x66d8e640, 0xbd050000, 0x54414449, 0x9bed5e78, 0x30e36e51, 0xeef5440c, 0x31fde97f, 0x584ec0f0, 0x681ace39,
  6428. 0xca120e6b, 0x1c5a28a6, 0xc5d98a89, 0x1a3d602e, 0x323c0043, 0xf6bc9e68, 0xbe3ad62c, 0x3d60260f, 0x82d60096, 0xe0bfc707, 0xfb9bf1d1, 0xbf0267ac,
  6429. 0x1600260f, 0x061229c0, 0x0000c183, 0x37162c58, 0xdfa088fc, 0xde7d5704, 0x77fcbb80, 0x48e5c3f1, 0x73d8b8f8, 0xc4af7802, 0x1ca111ad, 0x0001ed7a,
  6430. 0x76eda3ef, 0xb78d3e00, 0x801c7203, 0x0215c0b1, 0x0410b044, 0xa85100d4, 0x07627ec7, 0x0cf83fa8, 0x94001a22, 0xf87347f1, 0xdcb5cfc1, 0x1c3880cc,
  6431. 0xd4e034ca, 0xfa928d9d, 0xb0167e31, 0x325cc570, 0x4bbd584b, 0xbd4e6574, 0x70bae084, 0xf0c0008a, 0x3f601ddb, 0x0bba506a, 0xa58a0082, 0x5b46946e,
  6432. 0x720a4ccd, 0xdfaaed39, 0x25dc8042, 0x7ee403f4, 0x2ad69cc9, 0x6c4b3009, 0x429037ed, 0x0293f875, 0x1a69dced, 0xab120198, 0x61c01d88, 0xcf2e43dc,
  6433. 0xfc3c00ef, 0xc049a270, 0xdbbea582, 0x0d592601, 0xc3c9a8dd, 0x5013d143, 0x19a47bbb, 0xf89253dd, 0x0a9901dc, 0x38900ecd, 0xb2dec9d7, 0xc2b91230,
  6434. 0xb8e0106f, 0x976404cb, 0x5d83c3f3, 0x6e8086fd, 0x5c9ab007, 0xf50354f6, 0xe7e72002, 0x4bc870ca, 0xab49736f, 0xc137c6e0, 0xa9aa6ff3, 0xbff84f2f,
  6435. 0x673e6e20, 0xf6e3c7e0, 0x618fe05a, 0x39ca2a00, 0x93ca03b4, 0x3a9d2728, 0xbbebba41, 0xce0e3681, 0x6e29ec05, 0x111eca83, 0xfdfe7ec1, 0xa7c8a75b,
  6436. 0xac6bc3ab, 0x72a5bc25, 0x9f612c1c, 0x378ec05e, 0x7202b157, 0x789e5a82, 0x5256bc0e, 0xcb900996, 0x10721105, 0x00823ce0, 0x69ab59fb, 0x39c72084,
  6437. 0xf5e37b25, 0xd1794700, 0x538d0637, 0x9a2bff4f, 0xce0d43a4, 0xa6da7ed2, 0xd7095132, 0xf5ad6232, 0x9aaa8e9c, 0xd8d1d3ed, 0x058940a1, 0x21f00d64,
  6438. 0x89a5c9de, 0x021b3f24, 0x77a97aac, 0x714be65a, 0x5e2d57ae, 0x27e3610f, 0x28809288, 0x36b9559f, 0xd00e347a, 0x0094e385, 0x565d034d, 0x7f52d5f2,
  6439. 0x9aea81de, 0x5e804909, 0x010d7f0a, 0x8f0d3fb1, 0xbbce23bc, 0x375e85ac, 0x01fa03b9, 0xc0526c3a, 0xf7866870, 0x9d46d804, 0x158ebf64, 0x7bd534c5,
  6440. 0xd80cf202, 0x410ee80f, 0x79419915, 0x74a844ae, 0x94119881, 0xcbbcc0fc, 0xa263d471, 0x013d0269, 0x67f6a0f8, 0x3e4474d0, 0xd1e50cb5, 0x56fd0e60,
  6441. 0xc4c0fd4c, 0x940629ff, 0xe18a7a16, 0xcca0330f, 0xb8ed50b7, 0x6935778b, 0x3735c791, 0x3909eb94, 0x0be36620, 0x0ac0d7aa, 0xefe942c9, 0xf0092727,
  6442. 0x5c020ee2, 0x0246da53, 0xa24be8bc, 0xa891ab94, 0xd012c7e2, 0x9c115954, 0xde0dac8e, 0x555dc022, 0x59e84f77, 0xbed2cf80, 0xe9af2cda, 0x4b600716,
  6443. 0x8955bd80, 0x7098c3f3, 0x25a8466a, 0x4ddbf26a, 0x5f554753, 0xf4890f28, 0x886a27ab, 0x54a00413, 0x0a157ca9, 0x52909a80, 0x7122a312, 0x0024a75c,
  6444. 0xe6d72935, 0xecde29cf, 0x025de009, 0x7995a6aa, 0x4a180491, 0x013df0d8, 0xe009edba, 0xd40019dc, 0x45b36b2a, 0x0122eb0d, 0x6e80a79f, 0x746590f5,
  6445. 0xd1a6dd49, 0xc05954b6, 0x83d4b957, 0xa00fe5b1, 0x59695ad7, 0xcff8433d, 0x44a0f340, 0xdd226c73, 0x5537f08c, 0xe1e89c32, 0x431056af, 0x233eb000,
  6446. 0x60773f40, 0xed7e490a, 0xc160091f, 0x12829db5, 0x43fbe6cf, 0x0a6b26c2, 0xd5f0f35a, 0xfc09fda8, 0x73525f8c, 0x2ea38cf9, 0x32bc410b, 0x94a60a22,
  6447. 0x1f62a42b, 0x5f290034, 0x07beaa91, 0x1e8ccb40, 0x17d6b0f9, 0xa2a017c9, 0x4c79a610, 0xa1de6525, 0xe975029f, 0xe063585f, 0x6246cfbb, 0x04acad44,
  6448. 0xe6a05138, 0xd03d8434, 0xc9950013, 0x5d4c809e, 0xfd26932d, 0x739213ac, 0xe260d8ef, 0xe4164617, 0x16fc60aa, 0x1d0b21e7, 0x445004b4, 0x13fd1b59,
  6449. 0x56b0f804, 0xaa936a3a, 0x335459c1, 0xb37f8caa, 0x06b68e03, 0x14d5eb01, 0x8300c78c, 0x9674792a, 0x20ba791b, 0x4d88024d, 0xef747354, 0x451e673e,
  6450. 0xc4dafc9a, 0xe53b9cd1, 0x32b4011a, 0x3d702c0f, 0x09bc0b40, 0x220d277d, 0x47eb7809, 0x8a946500, 0x7a28c4bd, 0x96e00f99, 0xc04365da, 0x05edcf46,
  6451. 0x7dee2c27, 0xe6020b7f, 0x159ecedf, 0xcbdb00ff, 0x516bb9e3, 0xd0716161, 0xeba75956, 0xf17fc22b, 0x5c578beb, 0xfe474a09, 0xc1750a87, 0xe384c189,
  6452. 0x5df54e26, 0xa6f76b79, 0xd4b172be, 0x3e8d5ceb, 0x832d90ec, 0x180368e7, 0x354c724d, 0x1a8b1412, 0x8de07be9, 0xaf009efe, 0x4616c621, 0x2860eb01,
  6453. 0x244f1404, 0xc3de724b, 0x6497a802, 0xab2f4419, 0x4e02910d, 0xe3ecf410, 0x7a6404a8, 0x8c72b112, 0xde5bc706, 0xd4f8ffe9, 0x50176344, 0x7b49fe7d,
  6454. 0x02c1d88c, 0x25634a40, 0x194804f7, 0x03b76d84, 0x392bde58, 0xdeebad27, 0xc160c021, 0xa97a72db, 0xa8040b83, 0x78804f3e, 0x046b9433, 0x178cc824,
  6455. 0x62800897, 0x7010370b, 0x21cfe7e4, 0x8053ec40, 0xf9d60526, 0xae9d353f, 0x069b40c7, 0x80496f14, 0x57e682b3, 0x6e0273e0, 0x974e2e28, 0x60ab7c3d,
  6456. 0x2025ba33, 0x507b3a8c, 0x12b70173, 0xd095c400, 0xee012d96, 0x6e194c9a, 0xe5933f89, 0x43b70102, 0xf30306aa, 0xc5802189, 0x53c077c3, 0x86029009,
  6457. 0xa0c1e780, 0xa4c04c1f, 0x93dbd580, 0xf8149809, 0x06021893, 0x3060c183, 0x83060c18, 0x183060c1, 0xc183060c, 0x0c183060, 0x60c18306, 0xfe0c1830,
  6458. 0x0cb69501, 0x7a40d9df, 0x000000dd, 0x4e454900, 0x6042ae44, 0x00000082,
  6459. };
  6460. static const unsigned int proggy_clean_13_fnt_size = 4647;
  6461. static const unsigned int proggy_clean_13_fnt_data[4648/4] =
  6462. {
  6463. 0x03464d42, 0x00001a01, 0x40000d00, 0x01006400, 0x00000000, 0x50000101, 0x67676f72, 0x656c4379, 0x02006e61, 0x0000000f, 0x000a000d, 0x00800100,
  6464. 0x01000001, 0x03000000, 0x00000016, 0x676f7270, 0x635f7967, 0x6e61656c, 0x5f33315f, 0x6e702e30, 0xd0040067, 0x00000011, 0x2e000000, 0x07000e00,
  6465. 0x00000d00, 0x07000000, 0x010f0000, 0x36000000, 0x05003800, 0x01000d00, 0x07000000, 0x020f0000, 0x86000000, 0x07000e00, 0x00000d00, 0x07000000,
  6466. 0x030f0000, 0x07000000, 0x06001c00, 0x01000d00, 0x07000000, 0x040f0000, 0x15000000, 0x06001c00, 0x01000d00, 0x07000000, 0x050f0000, 0x23000000,
  6467. 0x06001c00, 0x01000d00, 0x07000000, 0x060f0000, 0x31000000, 0x06001c00, 0x01000d00, 0x07000000, 0x070f0000, 0xfc000000, 0x03003800, 0x02000d00,
  6468. 0x07000000, 0x080f0000, 0x54000000, 0x05003800, 0x01000d00, 0x07000000, 0x090f0000, 0x4d000000, 0x06001c00, 0x01000d00, 0x07000000, 0x0a0f0000,
  6469. 0xa8000000, 0x06001c00, 0x01000d00, 0x07000000, 0x0b0f0000, 0x6a000000, 0x04004600, 0x00000d00, 0x07000000, 0x0c0f0000, 0x74000000, 0x04004600,
  6470. 0x00000d00, 0x07000000, 0x0d0f0000, 0x88000000, 0x04004600, 0x03000d00, 0x07000000, 0x0e0f0000, 0x65000000, 0x04004600, 0x03000d00, 0x07000000,
  6471. 0x0f0f0000, 0x36000000, 0x07000e00, 0x00000d00, 0x07000000, 0x100f0000, 0x5a000000, 0x05003800, 0x00000d00, 0x07000000, 0x110f0000, 0x60000000,
  6472. 0x05003800, 0x00000d00, 0x07000000, 0x120f0000, 0xe4000000, 0x03004600, 0x01000d00, 0x07000000, 0x130f0000, 0xe0000000, 0x03004600, 0x01000d00,
  6473. 0x07000000, 0x140f0000, 0x66000000, 0x05003800, 0x00000d00, 0x07000000, 0x150f0000, 0x6c000000, 0x05003800, 0x00000d00, 0x07000000, 0x160f0000,
  6474. 0x72000000, 0x05003800, 0x00000d00, 0x07000000, 0x170f0000, 0xd8000000, 0x03004600, 0x00000d00, 0x07000000, 0x180f0000, 0xcc000000, 0x03004600,
  6475. 0x01000d00, 0x07000000, 0x190f0000, 0xc8000000, 0x03004600, 0x02000d00, 0x07000000, 0x1a0f0000, 0x78000000, 0x05003800, 0x00000d00, 0x07000000,
  6476. 0x1b0f0000, 0x84000000, 0x05003800, 0x00000d00, 0x07000000, 0x1c0f0000, 0x00000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x1d0f0000, 0xb0000000,
  6477. 0x15000000, 0xf9000d00, 0x070000ff, 0x1e0f0000, 0x2c000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x200f0000, 0x9a000000, 0x15000000, 0xf9000d00,
  6478. 0x070000ff, 0x210f0000, 0x0c000000, 0x01005400, 0x03000d00, 0x07000000, 0x220f0000, 0xbc000000, 0x03004600, 0x02000d00, 0x07000000, 0x230f0000,
  6479. 0x4e000000, 0x07000e00, 0x00000d00, 0x07000000, 0x240f0000, 0x8a000000, 0x05003800, 0x01000d00, 0x07000000, 0x250f0000, 0xa6000000, 0x07000e00,
  6480. 0x00000d00, 0x07000000, 0x260f0000, 0xf4000000, 0x06000e00, 0x01000d00, 0x07000000, 0x270f0000, 0x06000000, 0x01005400, 0x03000d00, 0x07000000,
  6481. 0x280f0000, 0xb8000000, 0x03004600, 0x02000d00, 0x07000000, 0x290f0000, 0xb4000000, 0x03004600, 0x02000d00, 0x07000000, 0x2a0f0000, 0x90000000,
  6482. 0x05003800, 0x01000d00, 0x07000000, 0x2b0f0000, 0x96000000, 0x05003800, 0x01000d00, 0x07000000, 0x2c0f0000, 0xe8000000, 0x02004600, 0x01000d00,
  6483. 0x07000000, 0x2d0f0000, 0x9c000000, 0x05003800, 0x01000d00, 0x07000000, 0x2e0f0000, 0x04000000, 0x01005400, 0x02000d00, 0x07000000, 0x2f0f0000,
  6484. 0xa2000000, 0x05003800, 0x01000d00, 0x07000000, 0x300f0000, 0xae000000, 0x05003800, 0x01000d00, 0x07000000, 0x310f0000, 0xd8000000, 0x05003800,
  6485. 0x01000d00, 0x07000000, 0x320f0000, 0xfa000000, 0x05000000, 0x01000d00, 0x07000000, 0x330f0000, 0x31000000, 0x05002a00, 0x01000d00, 0x07000000,
  6486. 0x340f0000, 0x3f000000, 0x06001c00, 0x01000d00, 0x07000000, 0x350f0000, 0x37000000, 0x05002a00, 0x01000d00, 0x07000000, 0x360f0000, 0x3d000000,
  6487. 0x05002a00, 0x01000d00, 0x07000000, 0x370f0000, 0x43000000, 0x05002a00, 0x01000d00, 0x07000000, 0x380f0000, 0x49000000, 0x05002a00, 0x01000d00,
  6488. 0x07000000, 0x390f0000, 0x4f000000, 0x05002a00, 0x01000d00, 0x07000000, 0x3a0f0000, 0x02000000, 0x01005400, 0x03000d00, 0x07000000, 0x3b0f0000,
  6489. 0xfa000000, 0x02004600, 0x01000d00, 0x07000000, 0x3c0f0000, 0x77000000, 0x06001c00, 0x00000d00, 0x07000000, 0x3d0f0000, 0x7e000000, 0x06001c00,
  6490. 0x01000d00, 0x07000000, 0x3e0f0000, 0x85000000, 0x06001c00, 0x01000d00, 0x07000000, 0x3f0f0000, 0x55000000, 0x05002a00, 0x01000d00, 0x07000000,
  6491. 0x400f0000, 0xae000000, 0x07000e00, 0x00000d00, 0x07000000, 0x410f0000, 0xe0000000, 0x06001c00, 0x01000d00, 0x07000000, 0x420f0000, 0xa1000000,
  6492. 0x06001c00, 0x01000d00, 0x07000000, 0x430f0000, 0x5b000000, 0x05002a00, 0x01000d00, 0x07000000, 0x440f0000, 0xaf000000, 0x06001c00, 0x01000d00,
  6493. 0x07000000, 0x450f0000, 0x61000000, 0x05002a00, 0x01000d00, 0x07000000, 0x460f0000, 0x67000000, 0x05002a00, 0x01000d00, 0x07000000, 0x470f0000,
  6494. 0x38000000, 0x06001c00, 0x01000d00, 0x07000000, 0x480f0000, 0x8c000000, 0x06001c00, 0x01000d00, 0x07000000, 0x490f0000, 0xa0000000, 0x03004600,
  6495. 0x02000d00, 0x07000000, 0x4a0f0000, 0x97000000, 0x04004600, 0x01000d00, 0x07000000, 0x4b0f0000, 0xb6000000, 0x06001c00, 0x01000d00, 0x07000000,
  6496. 0x4c0f0000, 0x6d000000, 0x05002a00, 0x01000d00, 0x07000000, 0x4d0f0000, 0x1e000000, 0x07000e00, 0x00000d00, 0x07000000, 0x4e0f0000, 0x23000000,
  6497. 0x06002a00, 0x01000d00, 0x07000000, 0x4f0f0000, 0xed000000, 0x06000e00, 0x01000d00, 0x07000000, 0x500f0000, 0x73000000, 0x05002a00, 0x01000d00,
  6498. 0x07000000, 0x510f0000, 0x00000000, 0x06001c00, 0x01000d00, 0x07000000, 0x520f0000, 0x0e000000, 0x06001c00, 0x01000d00, 0x07000000, 0x530f0000,
  6499. 0x1c000000, 0x06001c00, 0x01000d00, 0x07000000, 0x540f0000, 0x66000000, 0x07000e00, 0x00000d00, 0x07000000, 0x550f0000, 0x2a000000, 0x06001c00,
  6500. 0x01000d00, 0x07000000, 0x560f0000, 0x6e000000, 0x07000e00, 0x00000d00, 0x07000000, 0x570f0000, 0x76000000, 0x07000e00, 0x00000d00, 0x07000000,
  6501. 0x580f0000, 0x46000000, 0x06001c00, 0x01000d00, 0x07000000, 0x590f0000, 0x7e000000, 0x07000e00, 0x00000d00, 0x07000000, 0x5a0f0000, 0x54000000,
  6502. 0x06001c00, 0x01000d00, 0x07000000, 0x5b0f0000, 0x9c000000, 0x03004600, 0x02000d00, 0x07000000, 0x5c0f0000, 0x79000000, 0x05002a00, 0x01000d00,
  6503. 0x07000000, 0x5d0f0000, 0xdc000000, 0x03004600, 0x02000d00, 0x07000000, 0x5e0f0000, 0x7f000000, 0x05002a00, 0x01000d00, 0x07000000, 0x5f0f0000,
  6504. 0xc6000000, 0x07000e00, 0x00000d00, 0x07000000, 0x600f0000, 0xfd000000, 0x02004600, 0x02000d00, 0x07000000, 0x610f0000, 0x85000000, 0x05002a00,
  6505. 0x01000d00, 0x07000000, 0x620f0000, 0x8b000000, 0x05002a00, 0x01000d00, 0x07000000, 0x630f0000, 0x91000000, 0x05002a00, 0x01000d00, 0x07000000,
  6506. 0x640f0000, 0x97000000, 0x05002a00, 0x01000d00, 0x07000000, 0x650f0000, 0x9d000000, 0x05002a00, 0x01000d00, 0x07000000, 0x660f0000, 0xa3000000,
  6507. 0x05002a00, 0x01000d00, 0x07000000, 0x670f0000, 0xa9000000, 0x05002a00, 0x01000d00, 0x07000000, 0x680f0000, 0xaf000000, 0x05002a00, 0x01000d00,
  6508. 0x07000000, 0x690f0000, 0xee000000, 0x02004600, 0x02000d00, 0x07000000, 0x6a0f0000, 0x92000000, 0x04004600, 0x01000d00, 0x07000000, 0x6b0f0000,
  6509. 0xb5000000, 0x05002a00, 0x01000d00, 0x07000000, 0x6c0f0000, 0xfd000000, 0x02002a00, 0x02000d00, 0x07000000, 0x6d0f0000, 0x8e000000, 0x07000e00,
  6510. 0x00000d00, 0x07000000, 0x6e0f0000, 0xbb000000, 0x05002a00, 0x01000d00, 0x07000000, 0x6f0f0000, 0xc1000000, 0x05002a00, 0x01000d00, 0x07000000,
  6511. 0x700f0000, 0xc7000000, 0x05002a00, 0x01000d00, 0x07000000, 0x710f0000, 0xcd000000, 0x05002a00, 0x01000d00, 0x07000000, 0x720f0000, 0xd3000000,
  6512. 0x05002a00, 0x01000d00, 0x07000000, 0x730f0000, 0xd9000000, 0x05002a00, 0x01000d00, 0x07000000, 0x740f0000, 0x7e000000, 0x04004600, 0x02000d00,
  6513. 0x07000000, 0x750f0000, 0xdf000000, 0x05002a00, 0x01000d00, 0x07000000, 0x760f0000, 0xe5000000, 0x05002a00, 0x01000d00, 0x07000000, 0x770f0000,
  6514. 0xbe000000, 0x07000e00, 0x00000d00, 0x07000000, 0x780f0000, 0xeb000000, 0x05002a00, 0x01000d00, 0x07000000, 0x790f0000, 0xf1000000, 0x05002a00,
  6515. 0x01000d00, 0x07000000, 0x7a0f0000, 0xf7000000, 0x05002a00, 0x01000d00, 0x07000000, 0x7b0f0000, 0x00000000, 0x05003800, 0x01000d00, 0x07000000,
  6516. 0x7c0f0000, 0x00000000, 0x01005400, 0x03000d00, 0x07000000, 0x7d0f0000, 0x06000000, 0x05003800, 0x01000d00, 0x07000000, 0x7e0f0000, 0x16000000,
  6517. 0x07000e00, 0x00000d00, 0x07000000, 0x7f0f0000, 0x58000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x810f0000, 0x16000000, 0x15000000, 0xf9000d00,
  6518. 0x070000ff, 0x8d0f0000, 0x00000000, 0x15000e00, 0xf9000d00, 0x070000ff, 0x8f0f0000, 0xc6000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x900f0000,
  6519. 0x6e000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x9d0f0000, 0x84000000, 0x15000000, 0xf9000d00, 0x070000ff, 0xa00f0000, 0xdc000000, 0x15000000,
  6520. 0xf9000d00, 0x070000ff, 0xa10f0000, 0x0a000000, 0x01005400, 0x03000d00, 0x07000000, 0xa20f0000, 0x0c000000, 0x05003800, 0x01000d00, 0x07000000,
  6521. 0xa30f0000, 0x12000000, 0x05003800, 0x01000d00, 0x07000000, 0xa40f0000, 0x96000000, 0x07000e00, 0x00000d00, 0x07000000, 0xa50f0000, 0x5e000000,
  6522. 0x07000e00, 0x00000d00, 0x07000000, 0xa60f0000, 0x08000000, 0x01005400, 0x03000d00, 0x07000000, 0xa70f0000, 0x18000000, 0x05003800, 0x01000d00,
  6523. 0x07000000, 0xa80f0000, 0xac000000, 0x03004600, 0x02000d00, 0x07000000, 0xa90f0000, 0x56000000, 0x07000e00, 0x00000d00, 0x07000000, 0xaa0f0000,
  6524. 0x8d000000, 0x04004600, 0x01000d00, 0x07000000, 0xab0f0000, 0x1e000000, 0x05003800, 0x01000d00, 0x07000000, 0xac0f0000, 0xfb000000, 0x04000e00,
  6525. 0x01000d00, 0x07000000, 0xad0f0000, 0x42000000, 0x15000000, 0xf9000d00, 0x070000ff, 0xae0f0000, 0x3e000000, 0x07000e00, 0x00000d00, 0x07000000,
  6526. 0xaf0f0000, 0x26000000, 0x07000e00, 0x00000d00, 0x07000000, 0xb00f0000, 0x6f000000, 0x04004600, 0x01000d00, 0x07000000, 0xb10f0000, 0x24000000,
  6527. 0x05003800, 0x01000d00, 0x07000000, 0xb20f0000, 0x79000000, 0x04004600, 0x01000d00, 0x07000000, 0xb30f0000, 0x83000000, 0x04004600, 0x01000d00,
  6528. 0x07000000, 0xb40f0000, 0xeb000000, 0x02004600, 0x03000d00, 0x07000000, 0xb50f0000, 0x46000000, 0x07000e00, 0x00000d00, 0x07000000, 0xb60f0000,
  6529. 0xe6000000, 0x06000e00, 0x01000d00, 0x07000000, 0xb70f0000, 0xc0000000, 0x03004600, 0x02000d00, 0x07000000, 0xb80f0000, 0xf7000000, 0x02004600,
  6530. 0x03000d00, 0x07000000, 0xb90f0000, 0xc4000000, 0x03004600, 0x01000d00, 0x07000000, 0xba0f0000, 0x60000000, 0x04004600, 0x01000d00, 0x07000000,
  6531. 0xbb0f0000, 0x2a000000, 0x05003800, 0x01000d00, 0x07000000, 0xbc0f0000, 0x1c000000, 0x06002a00, 0x01000d00, 0x07000000, 0xbd0f0000, 0xc4000000,
  6532. 0x06001c00, 0x01000d00, 0x07000000, 0xbe0f0000, 0x9e000000, 0x07000e00, 0x00000d00, 0x07000000, 0xbf0f0000, 0x30000000, 0x05003800, 0x01000d00,
  6533. 0x07000000, 0xc00f0000, 0x9a000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc10f0000, 0x93000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc20f0000,
  6534. 0x70000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc30f0000, 0x69000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc40f0000, 0x62000000, 0x06001c00,
  6535. 0x01000d00, 0x07000000, 0xc50f0000, 0x5b000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc60f0000, 0xf2000000, 0x07000000, 0x00000d00, 0x07000000,
  6536. 0xc70f0000, 0xbd000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc80f0000, 0x3c000000, 0x05003800, 0x01000d00, 0x07000000, 0xc90f0000, 0x42000000,
  6537. 0x05003800, 0x01000d00, 0x07000000, 0xca0f0000, 0x48000000, 0x05003800, 0x01000d00, 0x07000000, 0xcb0f0000, 0x4e000000, 0x05003800, 0x01000d00,
  6538. 0x07000000, 0xcc0f0000, 0xa4000000, 0x03004600, 0x02000d00, 0x07000000, 0xcd0f0000, 0xb0000000, 0x03004600, 0x02000d00, 0x07000000, 0xce0f0000,
  6539. 0xa8000000, 0x03004600, 0x02000d00, 0x07000000, 0xcf0f0000, 0xfc000000, 0x03001c00, 0x02000d00, 0x07000000, 0xd00f0000, 0xce000000, 0x07000e00,
  6540. 0x00000d00, 0x07000000, 0xd10f0000, 0xcb000000, 0x06001c00, 0x01000d00, 0x07000000, 0xd20f0000, 0xd2000000, 0x06001c00, 0x01000d00, 0x07000000,
  6541. 0xd30f0000, 0xd9000000, 0x06001c00, 0x01000d00, 0x07000000, 0xd40f0000, 0x2a000000, 0x06002a00, 0x01000d00, 0x07000000, 0xd50f0000, 0xe7000000,
  6542. 0x06001c00, 0x01000d00, 0x07000000, 0xd60f0000, 0xee000000, 0x06001c00, 0x01000d00, 0x07000000, 0xd70f0000, 0x7e000000, 0x05003800, 0x01000d00,
  6543. 0x07000000, 0xd80f0000, 0xf5000000, 0x06001c00, 0x01000d00, 0x07000000, 0xd90f0000, 0x00000000, 0x06002a00, 0x01000d00, 0x07000000, 0xda0f0000,
  6544. 0x07000000, 0x06002a00, 0x01000d00, 0x07000000, 0xdb0f0000, 0x0e000000, 0x06002a00, 0x01000d00, 0x07000000, 0xdc0f0000, 0x15000000, 0x06002a00,
  6545. 0x01000d00, 0x07000000, 0xdd0f0000, 0xd6000000, 0x07000e00, 0x00000d00, 0x07000000, 0xde0f0000, 0xa8000000, 0x05003800, 0x01000d00, 0x07000000,
  6546. 0xdf0f0000, 0xde000000, 0x07000e00, 0x00000d00, 0x07000000, 0xe00f0000, 0xb4000000, 0x05003800, 0x01000d00, 0x07000000, 0xe10f0000, 0xba000000,
  6547. 0x05003800, 0x01000d00, 0x07000000, 0xe20f0000, 0xc0000000, 0x05003800, 0x01000d00, 0x07000000, 0xe30f0000, 0xc6000000, 0x05003800, 0x01000d00,
  6548. 0x07000000, 0xe40f0000, 0xcc000000, 0x05003800, 0x01000d00, 0x07000000, 0xe50f0000, 0xd2000000, 0x05003800, 0x01000d00, 0x07000000, 0xe60f0000,
  6549. 0xb6000000, 0x07000e00, 0x00000d00, 0x07000000, 0xe70f0000, 0xde000000, 0x05003800, 0x01000d00, 0x07000000, 0xe80f0000, 0xe4000000, 0x05003800,
  6550. 0x01000d00, 0x07000000, 0xe90f0000, 0xea000000, 0x05003800, 0x01000d00, 0x07000000, 0xea0f0000, 0xf0000000, 0x05003800, 0x01000d00, 0x07000000,
  6551. 0xeb0f0000, 0xf6000000, 0x05003800, 0x01000d00, 0x07000000, 0xec0f0000, 0xf1000000, 0x02004600, 0x02000d00, 0x07000000, 0xed0f0000, 0xf4000000,
  6552. 0x02004600, 0x02000d00, 0x07000000, 0xee0f0000, 0xd0000000, 0x03004600, 0x02000d00, 0x07000000, 0xef0f0000, 0xd4000000, 0x03004600, 0x02000d00,
  6553. 0x07000000, 0xf00f0000, 0x00000000, 0x05004600, 0x01000d00, 0x07000000, 0xf10f0000, 0x06000000, 0x05004600, 0x01000d00, 0x07000000, 0xf20f0000,
  6554. 0x0c000000, 0x05004600, 0x01000d00, 0x07000000, 0xf30f0000, 0x12000000, 0x05004600, 0x01000d00, 0x07000000, 0xf40f0000, 0x18000000, 0x05004600,
  6555. 0x01000d00, 0x07000000, 0xf50f0000, 0x1e000000, 0x05004600, 0x01000d00, 0x07000000, 0xf60f0000, 0x24000000, 0x05004600, 0x01000d00, 0x07000000,
  6556. 0xf70f0000, 0x2a000000, 0x05004600, 0x01000d00, 0x07000000, 0xf80f0000, 0x30000000, 0x05004600, 0x01000d00, 0x07000000, 0xf90f0000, 0x36000000,
  6557. 0x05004600, 0x01000d00, 0x07000000, 0xfa0f0000, 0x3c000000, 0x05004600, 0x01000d00, 0x07000000, 0xfb0f0000, 0x42000000, 0x05004600, 0x01000d00,
  6558. 0x07000000, 0xfc0f0000, 0x48000000, 0x05004600, 0x01000d00, 0x07000000, 0xfd0f0000, 0x4e000000, 0x05004600, 0x01000d00, 0x07000000, 0xfe0f0000,
  6559. 0x54000000, 0x05004600, 0x01000d00, 0x07000000, 0xff0f0000, 0x5a000000, 0x05004600, 0x01000d00, 0x07000000, 0x000f0000,
  6560. };
  6561. void ImGui::GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size)
  6562. {
  6563. if (fnt_data) *fnt_data = (const void*)proggy_clean_13_fnt_data;
  6564. if (fnt_size) *fnt_size = proggy_clean_13_fnt_size;
  6565. if (png_data) *png_data = (const void*)proggy_clean_13_png_data;
  6566. if (png_size) *png_size = proggy_clean_13_png_size;
  6567. }
  6568. //-----------------------------------------------------------------------------
  6569. //---- Include imgui_user.inl at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions.
  6570. #ifdef IMGUI_INCLUDE_IMGUI_USER_INL
  6571. #include "imgui_user.inl"
  6572. #endif
  6573. //-----------------------------------------------------------------------------