imgui.cpp 547 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998
  1. // ImGui library v1.42 wip
  2. // See ImGui::ShowTestWindow() for sample code.
  3. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
  4. // Get latest version at https://github.com/ocornut/imgui
  5. // Developed by Omar Cornut and ImGui contributors.
  6. /*
  7. Index
  8. - MISSION STATEMENT
  9. - END-USER GUIDE
  10. - PROGRAMMER GUIDE (read me!)
  11. - API BREAKING CHANGES (read me when you update!)
  12. - FREQUENTLY ASKED QUESTIONS (FAQ), TIPS
  13. - How do I update to a newer version of ImGui?
  14. - Can I have multiple widgets with the same label? Can I have widget without a label? (Yes)
  15. - Why is my text output blurry?
  16. - How can I load a different font than the default?
  17. - How can I load multiple fonts?
  18. - How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic?
  19. - ISSUES & TODO-LIST
  20. - CODE
  21. - SAMPLE CODE
  22. - FONT DATA
  23. MISSION STATEMENT
  24. =================
  25. - easy to use to create code-driven and data-driven tools
  26. - easy to use to create ad hoc short-lived tools and long-lived, more elaborate tools
  27. - easy to hack and improve
  28. - minimize screen real-estate usage
  29. - minimize setup and maintenance
  30. - minimize state storage on user side
  31. - portable, minimize dependencies, run on target (consoles, phones, etc.)
  32. - efficient runtime (NB- we do allocate when "growing" content - creating a window / opening a tree node for the first time, etc. - but a typical frame won't allocate anything)
  33. - read about immediate-mode gui principles @ http://mollyrocket.com/861, http://mollyrocket.com/forums/index.html
  34. Designed for developers and content-creators, not the typical end-user! Some of the weaknesses includes:
  35. - doesn't look fancy, doesn't animate
  36. - limited layout features, intricate layouts are typically crafted in code
  37. - occasionally uses statically sized buffers for string manipulations - won't crash, but some very long pieces of text may be clipped. functions like ImGui::TextUnformatted() don't have such restriction.
  38. END-USER GUIDE
  39. ==============
  40. - double-click title bar to collapse window
  41. - click upper right corner to close a window, available when 'bool* p_opened' is passed to ImGui::Begin()
  42. - click and drag on lower right corner to resize window
  43. - click and drag on any empty space to move window
  44. - double-click/double-tap on lower right corner grip to auto-fit to content
  45. - TAB/SHIFT+TAB to cycle through keyboard editable fields
  46. - use mouse wheel to scroll
  47. - use CTRL+mouse wheel to zoom window contents (if IO.FontAllowScaling is true)
  48. - CTRL+Click on a slider or drag box to input value as text
  49. - text editor:
  50. - Hold SHIFT or use mouse to select text.
  51. - CTRL+Left/Right to word jump
  52. - CTRL+Shift+Left/Right to select words
  53. - CTRL+A our Double-Click to select all
  54. - CTRL+X,CTRL+C,CTRL+V to use OS clipboard
  55. - CTRL+Z,CTRL+Y to undo/redo
  56. - ESCAPE to revert text to its original value
  57. - You can apply arithmetic operators +,*,/ on numerical values. Use +- to subtract (because - would set a negative value!)
  58. PROGRAMMER GUIDE
  59. ================
  60. - read the FAQ below this section!
  61. - your code creates the UI, if your code doesn't run the UI is gone! == very dynamic UI, no construction/destructions steps, less data retention on your side, no state duplication, less sync, less bugs.
  62. - call and read ImGui::ShowTestWindow() for sample code demonstrating most features.
  63. - see examples/ folder for standalone sample applications. e.g. examples/opengl_example/
  64. - customization: PushStyleColor()/PushStyleVar() or the style editor to tweak the look of the interface (e.g. if you want a more compact UI or a different color scheme).
  65. - getting started:
  66. - initialisation: call ImGui::GetIO() to retrieve the ImGuiIO structure and fill the 'Settings' data.
  67. - every frame:
  68. 1/ in your mainloop or right after you got your keyboard/mouse info, call ImGui::GetIO() and fill the 'Input' data, then call ImGui::NewFrame().
  69. 2/ use any ImGui function you want between NewFrame() and Render()
  70. 3/ ImGui::Render() to render all the accumulated command-lists. it will call your RenderDrawListFn handler that you set in the IO structure.
  71. - all rendering information are stored into command-lists until ImGui::Render() is called.
  72. - ImGui never touches or know about your GPU state. the only function that knows about GPU is the RenderDrawListFn handler that you must provide.
  73. - effectively it means you can create widgets at any time in your code, regardless of "update" vs "render" considerations.
  74. - refer to the examples applications in the examples/ folder for instruction on how to setup your code.
  75. - a typical application skeleton may be:
  76. // Application init
  77. ImGuiIO& io = ImGui::GetIO();
  78. io.DisplaySize.x = 1920.0f;
  79. io.DisplaySize.y = 1280.0f;
  80. io.DeltaTime = 1.0f/60.0f;
  81. io.IniFilename = "imgui.ini";
  82. // TODO: Fill others settings of the io structure
  83. // Load texture
  84. unsigned char* pixels;
  85. int width, height, bytes_per_pixels;
  86. io.Fonts->GetTexDataAsRGBA32(pixels, &width, &height, &bytes_per_pixels);
  87. // TODO: copy texture to graphics memory.
  88. // TODO: store your texture pointer/identifier in 'io.Fonts->TexID'
  89. // Application main loop
  90. while (true)
  91. {
  92. // 1) get low-level input
  93. // e.g. on Win32, GetKeyboardState(), or poll your events, etc.
  94. // 2) TODO: fill all fields of IO structure and call NewFrame
  95. ImGuiIO& io = ImGui::GetIO();
  96. io.MousePos = mouse_pos;
  97. io.MouseDown[0] = mouse_button_0;
  98. io.KeysDown[i] = ...
  99. ImGui::NewFrame();
  100. // 3) most of your application code here - you can use any of ImGui::* functions at any point in the frame
  101. ImGui::Begin("My window");
  102. ImGui::Text("Hello, world.");
  103. ImGui::End();
  104. GameUpdate();
  105. GameRender();
  106. // 4) render & swap video buffers
  107. ImGui::Render();
  108. // swap video buffer, etc.
  109. }
  110. - after calling ImGui::NewFrame() you can read back 'io.WantCaptureMouse' and 'io.WantCaptureKeyboard' to tell if ImGui
  111. wants to use your inputs. if it does you can discard/hide the inputs from the rest of your application.
  112. API BREAKING CHANGES
  113. ====================
  114. Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix.
  115. Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code.
  116. - 2015/07/02 (1.42) - renamed SetScrollPosHere() to SetScrollFromCursorPos(). Kept inline redirection function (will obsolete).
  117. - 2015/07/02 (1.42) - renamed GetScrollPosY() to GetScrollY(). Necessary to reduce confusion along with other scrolling functions, because positions (e.g. cursor position) are not equivalent to scrolling amount.
  118. - 2015/06/14 (1.41) - changed ImageButton() default bg_col parameter from (0,0,0,1) (black) to (0,0,0,0) (transparent) - makes a difference when texture have transparence
  119. - 2015/06/14 (1.41) - changed Selectable() API from (label, selected, size) to (label, selected, flags, size). Size override should have been rarely be used. Sorry!
  120. - 2015/05/31 (1.40) - renamed GetWindowCollapsed() to IsWindowCollapsed() for consistency. Kept inline redirection function (will obsolete).
  121. - 2015/05/31 (1.40) - renamed IsRectClipped() to IsRectVisible() for consistency. Note that return value is opposite! Kept inline redirection function (will obsolete).
  122. - 2015/05/27 (1.40) - removed the third 'repeat_if_held' parameter from Button() - sorry! it was rarely used and inconsistent. Use PushButtonRepeat(true) / PopButtonRepeat() to enable repeat on desired buttons.
  123. - 2015/05/11 (1.40) - changed BeginPopup() API, takes a string identifier instead of a bool. ImGui needs to manage the open/closed state of popups. Call OpenPopup() to actually set the "opened" state of a popup. BeginPopup() returns true if the popup is opened.
  124. - 2015/05/03 (1.40) - removed style.AutoFitPadding, using style.WindowPadding makes more sense (the default values were already the same).
  125. - 2015/04/13 (1.38) - renamed IsClipped() to IsRectClipped(). Kept inline redirection function (will obsolete).
  126. - 2015/04/09 (1.38) - renamed ImDrawList::AddArc() to ImDrawList::AddArcFast() for compatibility with future API
  127. - 2015/04/03 (1.38) - removed ImGuiCol_CheckHovered, ImGuiCol_CheckActive, replaced with the more general ImGuiCol_FrameBgHovered, ImGuiCol_FrameBgActive.
  128. - 2014/04/03 (1.38) - removed support for passing -FLT_MAX..+FLT_MAX as the range for a SliderFloat(). Use DragFloat() or Inputfloat() instead.
  129. - 2015/03/17 (1.36) - renamed GetItemBoxMin()/GetItemBoxMax()/IsMouseHoveringBox() to GetItemRectMin()/GetItemRectMax()/IsMouseHoveringRect(). Kept inline redirection function (will obsolete).
  130. - 2015/03/15 (1.36) - renamed style.TreeNodeSpacing to style.IndentSpacing, ImGuiStyleVar_TreeNodeSpacing to ImGuiStyleVar_IndentSpacing
  131. - 2015/03/13 (1.36) - renamed GetWindowIsFocused() to IsWindowFocused(). Kept inline redirection function (will obsolete).
  132. - 2015/03/08 (1.35) - renamed style.ScrollBarWidth to style.ScrollbarWidth
  133. - 2015/02/27 (1.34) - renamed OpenNextNode(bool) to SetNextTreeNodeOpened(bool, ImGuiSetCond). Kept inline redirection function (will obsolete).
  134. - 2015/02/27 (1.34) - renamed ImGuiSetCondition_*** to ImGuiSetCond_***, and _FirstUseThisSession becomes _Once.
  135. - 2015/02/11 (1.32) - changed text input callback ImGuiTextEditCallback return type from void-->int. reserved for future use, return 0 for now.
  136. - 2015/02/10 (1.32) - renamed GetItemWidth() to CalcItemWidth() to clarify its evolving behavior
  137. - 2015/02/08 (1.31) - renamed GetTextLineSpacing() to GetTextLineHeightWithSpacing()
  138. - 2015/02/01 (1.31) - removed IO.MemReallocFn (unused)
  139. - 2015/01/19 (1.30) - renamed ImGuiStorage::GetIntPtr()/GetFloatPtr() to GetIntRef()/GetIntRef() because Ptr was conflicting with actual pointer storage functions.
  140. - 2015/01/11 (1.30) - big font/image API change! now loads TTF file. allow for multiple fonts. no need for a PNG loader.
  141. (1.30) - removed GetDefaultFontData(). uses io.Fonts->GetTextureData*() API to retrieve uncompressed pixels.
  142. this sequence:
  143. const void* png_data;
  144. unsigned int png_size;
  145. ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
  146. // <Copy to GPU>
  147. became:
  148. unsigned char* pixels;
  149. int width, height;
  150. io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
  151. // <Copy to GPU>
  152. io.Fonts->TexID = (your_texture_identifier);
  153. you now have much more flexibility to load multiple TTF fonts and manage the texture buffer for internal needs.
  154. it is now recommended your sample the font texture with bilinear interpolation.
  155. (1.30) - added texture identifier in ImDrawCmd passed to your render function (we can now render images). make sure to set io.Fonts->TexID.
  156. (1.30) - removed IO.PixelCenterOffset (unnecessary, can be handled in user projection matrix)
  157. (1.30) - removed ImGui::IsItemFocused() in favor of ImGui::IsItemActive() which handles all widgets
  158. - 2014/12/10 (1.18) - removed SetNewWindowDefaultPos() in favor of new generic API SetNextWindowPos(pos, ImGuiSetCondition_FirstUseEver)
  159. - 2014/11/28 (1.17) - moved IO.Font*** options to inside the IO.Font-> structure (FontYOffset, FontTexUvForWhite, FontBaseScale, FontFallbackGlyph)
  160. - 2014/11/26 (1.17) - reworked syntax of IMGUI_ONCE_UPON_A_FRAME helper macro to increase compiler compatibility
  161. - 2014/11/07 (1.15) - renamed IsHovered() to IsItemHovered()
  162. - 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)
  163. - 2014/09/25 (1.13) - removed 'text_end' parameter from IO.SetClipboardTextFn (the string is now always zero-terminated for simplicity)
  164. - 2014/09/24 (1.12) - renamed SetFontScale() to SetWindowFontScale()
  165. - 2014/09/24 (1.12) - moved IM_MALLOC/IM_REALLOC/IM_FREE preprocessor defines to IO.MemAllocFn/IO.MemReallocFn/IO.MemFreeFn
  166. - 2014/08/30 (1.09) - removed IO.FontHeight (now computed automatically)
  167. - 2014/08/30 (1.09) - moved IMGUI_FONT_TEX_UV_FOR_WHITE preprocessor define to IO.FontTexUvForWhite
  168. - 2014/08/28 (1.09) - changed the behavior of IO.PixelCenterOffset following various rendering fixes
  169. FREQUENTLY ASKED QUESTIONS (FAQ), TIPS
  170. ======================================
  171. Q: How do I update to a newer version of ImGui?
  172. A: Overwrite the following files:
  173. imgui.cpp
  174. imgui.h
  175. stb_rect_pack.h
  176. stb_textedit.h
  177. stb_truetype.h
  178. Check the "API BREAKING CHANGES" sections for a list of occasional API breaking changes. If you have a problem with a function, search for its name
  179. in the code, there will likely be a comment about it. Please report any issue to the GitHub page!
  180. Q: Can I have multiple widgets with the same label? Can I have widget without a label? (Yes)
  181. A: Yes. A primer on the use of labels/IDs in ImGui..
  182. - Elements that are not clickable, such as Text() items don't need an ID.
  183. - Interactive widgets require state to be carried over multiple frames (most typically ImGui often needs to remember what is the "active" widget).
  184. to do so they need an unique ID. unique ID are typically derived from a string label, an integer index or a pointer.
  185. Button("OK"); // Label = "OK", ID = hash of "OK"
  186. Button("Cancel"); // Label = "Cancel", ID = hash of "Cancel"
  187. - ID are uniquely scoped within windows, tree nodes, etc. so no conflict can happen if you have two buttons called "OK" in two different windows
  188. or in two different locations of a tree.
  189. - if you have a same ID twice in the same location, you'll have a conflict:
  190. Button("OK");
  191. Button("OK"); // ID collision! Both buttons will be treated as the same.
  192. Fear not! this is easy to solve and there are many ways to solve it!
  193. - when passing a label you can optionally specify extra unique ID information within string itself. This helps solving the simpler collision cases.
  194. use "##" to pass a complement to the ID that won't be visible to the end-user:
  195. Button("Play##0"); // Label = "Play", ID = hash of "Play##0"
  196. Button("Play##1"); // Label = "Play", ID = hash of "Play##1" (different from above)
  197. - so if you want to hide the label but need an ID:
  198. Checkbox("##On", &b); // Label = "", ID = hash of "##On"
  199. - occasionally (rarely) you might want change a label while preserving a constant ID. This allows you to animate labels.
  200. use "###" to pass a label that isn't part of ID:
  201. Button("Hello###ID"; // Label = "Hello", ID = hash of "ID"
  202. Button("World###ID"; // Label = "World", ID = hash of "ID" (same as above)
  203. - use PushID() / PopID() to create scopes and avoid ID conflicts within the same Window.
  204. this is the most convenient way of distinguish ID if you are iterating and creating many UI elements.
  205. you can push a pointer, a string or an integer value. remember that ID are formed from the addition of everything in the ID stack!
  206. for (int i = 0; i < 100; i++)
  207. {
  208. PushID(i);
  209. Button("Click"); // Label = "Click", ID = hash of integer + "label" (unique)
  210. PopID();
  211. }
  212. for (int i = 0; i < 100; i++)
  213. {
  214. MyObject* obj = Objects[i];
  215. PushID(obj);
  216. Button("Click"); // Label = "Click", ID = hash of pointer + "label" (unique)
  217. PopID();
  218. }
  219. for (int i = 0; i < 100; i++)
  220. {
  221. MyObject* obj = Objects[i];
  222. PushID(obj->Name);
  223. Button("Click"); // Label = "Click", ID = hash of string + "label" (unique)
  224. PopID();
  225. }
  226. - more example showing that you can stack multiple prefixes into the ID stack:
  227. Button("Click"); // Label = "Click", ID = hash of "Click"
  228. PushID("node");
  229. Button("Click"); // Label = "Click", ID = hash of "node" + "Click"
  230. PushID(my_ptr);
  231. Button("Click"); // Label = "Click", ID = hash of "node" + ptr + "Click"
  232. PopID();
  233. PopID();
  234. - tree nodes implicitly creates a scope for you by calling PushID().
  235. Button("Click"); // Label = "Click", ID = hash of "Click"
  236. if (TreeNode("node"))
  237. {
  238. Button("Click"); // Label = "Click", ID = hash of "node" + "Click"
  239. TreePop();
  240. }
  241. - when working with trees, ID are used to preserve the opened/closed state of each tree node.
  242. depending on your use cases you may want to use strings, indices or pointers as ID.
  243. e.g. when displaying a single object that may change over time (1-1 relationship), using a static string as ID will preserve your node open/closed state when the targeted object change.
  244. e.g. when displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state differently. experiment and see what makes more sense!
  245. Q: Why is my text output blurry?
  246. A: In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
  247. Q: How can I load a different font than the default? (default is an embedded version of ProggyClean.ttf, rendered at size 13)
  248. A: Use the font atlas to load the TTF file you want:
  249. io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
  250. io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
  251. Q: How can I load multiple fonts?
  252. A: Use the font atlas to pack them into a single texture:
  253. ImFont* font0 = io.Fonts->AddFontDefault();
  254. ImFont* font1 = io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
  255. ImFont* font2 = io.Fonts->AddFontFromFileTTF("myfontfile2.ttf", size_in_pixels);
  256. io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
  257. // the first loaded font gets used by default
  258. // use ImGui::PushFont()/ImGui::PopFont() to change the font at runtime
  259. Q: How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic?
  260. A: When loading a font, pass custom Unicode ranges to specify the glyphs to load. ImGui will support UTF-8 encoding across the board.
  261. Character input depends on you passing the right character code to io.AddInputCharacter(). The example applications do that.
  262. io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, io.Fonts->GetGlyphRangesJapanese()); // Load Japanese characters
  263. io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
  264. io.ImeWindowHandle = MY_HWND; // To input using Microsoft IME, give ImGui the hwnd of your application
  265. - tip: the construct 'IMGUI_ONCE_UPON_A_FRAME { ... }' will run the block of code only once a frame. You can use it to quickly add custom UI in the middle of a deep nested inner loop in your code.
  266. - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug"
  267. - tip: you can call Begin() multiple times with the same name during the same frame, it will keep appending to the same window.
  268. - tip: you can call Render() multiple times (e.g for VR renders).
  269. - tip: call and read the ShowTestWindow() code for more example of how to use ImGui!
  270. ISSUES & TODO-LIST
  271. ==================
  272. Issue numbers (#) refer to github issues.
  273. - misc: merge or clarify ImVec4 vs ImRect?
  274. - window: fix resize grip rendering scaling along with Rounding style setting
  275. - window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit?
  276. - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list.
  277. - window: allow resizing of child windows (possibly given min/max for each axis?)
  278. - window: background options for child windows, border option (disable rounding)
  279. - window: resizing from any sides? + mouse cursor directives for app.
  280. - window: get size/pos helpers given names (see discussion in #249)
  281. - scrolling: add horizontal scroll
  282. !- scrolling: allow immediately effective change of scroll if we haven't appended items yet
  283. - widgets: display mode: widget-label, label-widget (aligned on column or using fixed size), label-newline-tab-widget etc.
  284. - widgets: clean up widgets internal toward exposing everything.
  285. - main: considering adding EndFrame()/Init(). some constructs are awkward in the implementation because of the lack of them.
  286. - main: IsItemHovered() make it more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes
  287. - main: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode?
  288. - input text: add ImGuiInputTextFlags_EnterToApply? (off #218)
  289. - input text multi-line: way to dynamically grow the buffer without forcing the user to initially allocate for worse case (follow up on #200)
  290. - input text multi-line: line numbers? status bar? (follow up on #200)
  291. !- input number: large int not reliably supported because of int<>float conversions.
  292. - input number: optional range min/max for Input*() functions
  293. - input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled)
  294. - input number: use mouse wheel to step up/down
  295. - input number: non-decimal input.
  296. - text: proper alignment options
  297. - layout: horizontal layout helper (#97)
  298. - layout: more generic alignment state (left/right/centered) for single items?
  299. - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding.
  300. - columns: separator function or parameter that works within the column (currently Separator() bypass all columns) (#125)
  301. - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills) (#125)
  302. - columns: columns header to act as button (~sort op) and allow resize/reorder (#125)
  303. - columns: user specify columns size (#125)
  304. - popup: border options. richer api like BeginChild() perhaps? (#197)
  305. - combo: sparse combo boxes (via function call?)
  306. - combo: turn child handling code into pop up helper
  307. - combo: contents should extends to fit label if combo widget is small
  308. - combo/listbox: keyboard control. need inputtext like non-active focus + key handling. considering keybord for custom listbox (pr #203)
  309. - listbox: multiple selection
  310. - listbox: user may want to initial scroll to focus on the one selected value?
  311. - listbox: keyboard navigation.
  312. - listbox: scrolling should track modified selection.
  313. - menus: local shortcuts, global shortcuts (#126)
  314. - menus: icons
  315. - menus: menubars: some sort of priority / effect of main menu-bar on desktop size?
  316. - tabs
  317. - separator: separator on the initial position of a window is not visible (cursorpos.y <= clippos.y)
  318. - gauge: various forms of gauge/loading bars widgets
  319. - color: better color editor.
  320. - plot: make it easier for user to draw extra stuff into the graph (e.g: draw basis, highlight certain points, 2d plots, multiple plots)
  321. - plot: "smooth" automatic scale over time, user give an input 0.0(full user scale) 1.0(full derived from value)
  322. - 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)
  323. - file selection widget -> build the tool in our codebase to improve model-dialog idioms
  324. - inputfloat: applying arithmetics ops (+,-,*,/) messes up with text edit undo stack.
  325. - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt()
  326. - slider: initial absolute click is imprecise. change to relative movement slider (same as scrollbar).
  327. - slider: add dragging-based widgets to edit values with mouse (on 2 axises), saving screen real-estate.
  328. - dragfloat: up/down axis
  329. - text edit: clean up the mess caused by converting UTF-8 <> wchar. the code is rather inefficient right now.
  330. - text edit: centered text for slider as input text so it matches typical positioning.
  331. - text edit: flag to disable live update of the user buffer.
  332. - text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text?
  333. - text edit: add multi-line text edit
  334. - tree: add treenode/treepush int variants? because (void*) cast from int warns on some platforms/settings
  335. - textwrapped: figure out better way to use TextWrapped() in an always auto-resize context (tooltip, etc.) (git issue #249)
  336. - settings: write more decent code to allow saving/loading new fields
  337. - settings: api for per-tool simple persistent data (bool,int,float,columns sizes,etc.) in .ini file
  338. - style: store rounded corners in texture to use 1 quad per corner (filled and wireframe). so rounding have minor cost.
  339. - style: checkbox: padding for "active" color should be a multiplier of the
  340. - style: colorbox not always square?
  341. - text: simple markup language for color change?
  342. - log: LogButtons() options for specifying depth and/or hiding depth slider
  343. - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope)
  344. - log: be able to log anything (e.g. right-click on a window/tree-node, shows context menu? log into tty/file/clipboard)
  345. - log: let user copy any window content to clipboard easily (CTRL+C on windows? while moving it? context menu?). code is commented because it fails with multiple Begin/End pairs.
  346. - filters: set a current filter that tree node can automatically query to hide themselves
  347. - filters: handle wildcards (with implicit leading/trailing *), regexps
  348. - 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)
  349. !- keyboard: tooltip & combo boxes are messing up / not honoring keyboard tabbing
  350. - keyboard: full keyboard navigation and focus.
  351. - input: rework IO to be able to pass actual events to fix temporal aliasing issues.
  352. - input: support track pad style scrolling & slider edit.
  353. - portability: big-endian test/support (#81)
  354. - memory: add a way to discard allocs of unused/transient windows. with the current architecture new windows (including popup, opened combos, listbox) perform at least 3 allocs.
  355. - misc: mark printf compiler attributes on relevant functions
  356. - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL)
  357. - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon?
  358. - style editor: have a more global HSV setter (e.g. alter hue on all elements). consider replacing active/hovered by offset in HSV space?
  359. - style editor: color child window height expressed in multiple of line height.
  360. - optimization/render: use indexed rendering to reduce vertex data cost (e.g. for remote/networked imgui)
  361. - 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)?
  362. - optimization: turn some the various stack vectors into statically-sized arrays
  363. - optimization: better clipping for multi-component widgets
  364. */
  365. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  366. #define _CRT_SECURE_NO_WARNINGS
  367. #endif
  368. #include "imgui.h"
  369. #include <ctype.h> // toupper, isprint
  370. #include <math.h> // sqrtf, fabsf, fmodf, powf, cosf, sinf, floorf, ceilf
  371. #include <stdio.h> // vsnprintf, sscanf, printf
  372. #include <new> // new (ptr)
  373. #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
  374. #include <stddef.h> // intptr_t
  375. #else
  376. #include <stdint.h> // intptr_t
  377. #endif
  378. #ifdef _MSC_VER
  379. #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
  380. #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
  381. #endif
  382. // Clang warnings with -Weverything
  383. #ifdef __clang__
  384. #pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
  385. #pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants ok.
  386. #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.
  387. #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.
  388. #pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it.
  389. #pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness //
  390. #pragma clang diagnostic ignored "-Wmissing-noreturn" // warning : function xx could be declared with attribute 'noreturn' warning // GetDefaultFontData() asserts which some implementation makes it never return.
  391. #endif
  392. #ifdef __GNUC__
  393. #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
  394. #endif
  395. //-------------------------------------------------------------------------
  396. // STB libraries implementation
  397. //-------------------------------------------------------------------------
  398. struct ImGuiTextEditState;
  399. //#define IMGUI_STB_NAMESPACE ImStb
  400. //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
  401. //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
  402. #ifdef IMGUI_STB_NAMESPACE
  403. namespace IMGUI_STB_NAMESPACE
  404. {
  405. #endif
  406. #ifdef __clang__
  407. #pragma clang diagnostic push
  408. #pragma clang diagnostic ignored "-Wunused-function"
  409. #pragma clang diagnostic ignored "-Wmissing-prototypes"
  410. #endif
  411. #define STBRP_ASSERT(x) IM_ASSERT(x)
  412. #ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
  413. #define STBRP_STATIC
  414. #define STB_RECT_PACK_IMPLEMENTATION
  415. #endif
  416. #include "stb_rect_pack.h"
  417. #define STBTT_malloc(x,u) ((void)(u), ImGui::MemAlloc(x))
  418. #define STBTT_free(x,u) ((void)(u), ImGui::MemFree(x))
  419. #define STBTT_assert(x) IM_ASSERT(x)
  420. #ifndef IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
  421. #define STBTT_STATIC
  422. #define STB_TRUETYPE_IMPLEMENTATION
  423. #else
  424. #define STBTT_DEF extern
  425. #endif
  426. #include "stb_truetype.h"
  427. #undef STB_TEXTEDIT_STRING
  428. #undef STB_TEXTEDIT_CHARTYPE
  429. #define STB_TEXTEDIT_STRING ImGuiTextEditState
  430. #define STB_TEXTEDIT_CHARTYPE ImWchar
  431. #define STB_TEXTEDIT_GETWIDTH_NEWLINE -1.0f
  432. #include "stb_textedit.h"
  433. #ifdef __clang__
  434. #pragma clang diagnostic pop
  435. #endif
  436. #ifdef IMGUI_STB_NAMESPACE
  437. } // namespace ImStb
  438. using namespace IMGUI_STB_NAMESPACE;
  439. #endif
  440. //-------------------------------------------------------------------------
  441. // Forward Declarations
  442. //-------------------------------------------------------------------------
  443. struct ImRect;
  444. struct ImGuiColMod;
  445. struct ImGuiStyleMod;
  446. struct ImGuiDrawContext;
  447. struct ImGuiTextEditState;
  448. struct ImGuiIniData;
  449. struct ImGuiState;
  450. struct ImGuiWindow;
  451. typedef int ImGuiLayoutType; // enum ImGuiLayoutType_
  452. typedef int ImGuiButtonFlags; // enum ImGuiButtonFlags_
  453. static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, ImGuiButtonFlags flags = 0);
  454. static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL);
  455. static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true);
  456. static void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width);
  457. static void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, ImGuiAlign align = ImGuiAlign_Default, const ImVec2* clip_min = NULL, const ImVec2* clip_max = NULL);
  458. static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
  459. static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false);
  460. static void RenderCheckMark(ImVec2 pos, ImU32 col);
  461. static void SetFont(ImFont* font);
  462. static bool ItemAdd(const ImRect& bb, const ImGuiID* id);
  463. static void ItemSize(ImVec2 size, float text_offset_y = 0.0f);
  464. static void ItemSize(const ImRect& bb, float text_offset_y = 0.0f);
  465. static void PushColumnClipRect(int column_index = -1);
  466. static bool IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged);
  467. static bool IsMouseHoveringRect(const ImRect& bb);
  468. static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true);
  469. static void Scrollbar(ImGuiWindow* window);
  470. static bool CloseWindowButton(bool* p_opened = NULL);
  471. static void FocusWindow(ImGuiWindow* window);
  472. static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs);
  473. static void CloseInactivePopups();
  474. static ImGuiWindow* GetFrontMostModalRootWindow();
  475. static void SetWindowScrollY(ImGuiWindow* window, float scroll_y);
  476. // Helpers: String
  477. static int ImStricmp(const char* str1, const char* str2);
  478. static int ImStrnicmp(const char* str1, const char* str2, int count);
  479. static char* ImStrdup(const char* str);
  480. static size_t ImStrlenW(const ImWchar* str);
  481. static const ImWchar* ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin); // Find beginning-of-line
  482. static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end);
  483. static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...);
  484. static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args);
  485. // Helpers: Misc
  486. static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed);
  487. static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes = 0);
  488. static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; }
  489. static inline bool ImCharIsSpace(int c) { return c == ' ' || c == '\t' || c == 0x3000; }
  490. // Helpers: UTF-8 <> wchar
  491. static inline int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int in_char); // return output UTF-8 bytes count
  492. 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
  493. static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count
  494. static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end, const char** in_remaining = NULL); // return input UTF-8 bytes count
  495. static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count)
  496. static inline int ImTextCountUtf8BytesFromChar(unsigned int in_char); // return output UTF-8 bytes count
  497. static int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points
  498. //-----------------------------------------------------------------------------
  499. // Platform dependent default implementations
  500. //-----------------------------------------------------------------------------
  501. static const char* GetClipboardTextFn_DefaultImpl();
  502. static void SetClipboardTextFn_DefaultImpl(const char* text);
  503. static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y);
  504. //-----------------------------------------------------------------------------
  505. // User facing structures
  506. //-----------------------------------------------------------------------------
  507. ImGuiStyle::ImGuiStyle()
  508. {
  509. Alpha = 1.0f; // Global alpha applies to everything in ImGui
  510. WindowPadding = ImVec2(8,8); // Padding within a window
  511. WindowMinSize = ImVec2(32,32); // Minimum window size
  512. WindowRounding = 9.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
  513. WindowTitleAlign = ImGuiAlign_Left; // Alignment for title bar text
  514. ChildWindowRounding = 0.0f; // Radius of child window corners rounding. Set to 0.0f to have rectangular windows
  515. FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets)
  516. FrameRounding = 0.0f; // Radius of frame corners rounding. Set to 0.0f to have rectangular frames (used by most widgets).
  517. ItemSpacing = ImVec2(8,4); // Horizontal and vertical spacing between widgets/lines
  518. ItemInnerSpacing = ImVec2(4,4); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
  519. TouchExtraPadding = ImVec2(0,0); // Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much!
  520. WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin()
  521. IndentSpacing = 22.0f; // Horizontal spacing when e.g. entering a tree node
  522. ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns
  523. ScrollbarWidth = 16.0f; // Width of the vertical scrollbar
  524. ScrollbarRounding = 0.0f; // Radius of grab corners rounding for scrollbar
  525. GrabMinSize = 10.0f; // Minimum width/height of a grab box for slider/scrollbar
  526. DisplayWindowPadding = ImVec2(22,22); // Window positions are clamped to be visible within the display area by at least this amount. Only covers regular windows.
  527. DisplaySafeAreaPadding = ImVec2(4,4); // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows.
  528. Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
  529. Colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
  530. Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
  531. Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  532. Colors[ImGuiCol_Border] = ImVec4(0.70f, 0.70f, 0.70f, 0.65f);
  533. Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.60f);
  534. Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f); // Background of checkbox, radio button, plot, slider, text input
  535. Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.90f, 0.80f, 0.80f, 0.40f);
  536. Colors[ImGuiCol_FrameBgActive] = ImVec4(0.90f, 0.65f, 0.65f, 0.45f);
  537. Colors[ImGuiCol_TitleBg] = ImVec4(0.50f, 0.50f, 1.00f, 0.45f);
  538. Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.40f, 0.40f, 0.80f, 0.20f);
  539. Colors[ImGuiCol_TitleBgActive] = ImVec4(0.50f, 0.50f, 1.00f, 0.55f);
  540. Colors[ImGuiCol_MenuBarBg] = ImVec4(0.40f, 0.40f, 0.55f, 0.60f);
  541. Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.40f, 0.40f, 0.80f, 0.15f);
  542. Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.80f, 0.30f);
  543. Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f);
  544. Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 0.40f);
  545. Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f);
  546. Colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f);
  547. Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
  548. Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  549. Colors[ImGuiCol_Button] = ImVec4(0.67f, 0.40f, 0.40f, 0.60f);
  550. Colors[ImGuiCol_ButtonHovered] = ImVec4(0.67f, 0.40f, 0.40f, 1.00f);
  551. Colors[ImGuiCol_ButtonActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  552. Colors[ImGuiCol_Header] = ImVec4(0.40f, 0.40f, 0.90f, 0.45f);
  553. Colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.90f, 0.80f);
  554. Colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.87f, 0.80f);
  555. Colors[ImGuiCol_Column] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
  556. Colors[ImGuiCol_ColumnHovered] = ImVec4(0.70f, 0.60f, 0.60f, 1.00f);
  557. Colors[ImGuiCol_ColumnActive] = ImVec4(0.90f, 0.70f, 0.70f, 1.00f);
  558. Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
  559. Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.00f, 1.00f, 1.00f, 0.60f);
  560. Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.90f);
  561. Colors[ImGuiCol_CloseButton] = ImVec4(0.50f, 0.50f, 0.90f, 0.50f);
  562. Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.70f, 0.70f, 0.90f, 0.60f);
  563. Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.70f, 0.70f, 0.70f, 1.00f);
  564. Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  565. Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  566. Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  567. Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
  568. Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
  569. Colors[ImGuiCol_TooltipBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
  570. Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
  571. }
  572. // Statically allocated font atlas. This is merely a maneuver to keep ImFontAtlas definition at the bottom of the .h file (otherwise it'd be inside ImGuiIO)
  573. // Also we wouldn't be able to new() one at this point, before users may define IO.MemAllocFn.
  574. static ImFontAtlas GDefaultFontAtlas;
  575. ImGuiIO::ImGuiIO()
  576. {
  577. // Most fields are initialized with zero
  578. memset(this, 0, sizeof(*this));
  579. DisplaySize = ImVec2(-1.0f, -1.0f);
  580. DeltaTime = 1.0f/60.0f;
  581. IniSavingRate = 5.0f;
  582. IniFilename = "imgui.ini";
  583. LogFilename = "imgui_log.txt";
  584. Fonts = &GDefaultFontAtlas;
  585. FontGlobalScale = 1.0f;
  586. MousePos = ImVec2(-1,-1);
  587. MousePosPrev = ImVec2(-1,-1);
  588. MouseDoubleClickTime = 0.30f;
  589. MouseDoubleClickMaxDist = 6.0f;
  590. MouseDragThreshold = 6.0f;
  591. for (int i = 0; i < ImGuiKey_COUNT; i++)
  592. KeyMap[i] = -1;
  593. KeyRepeatDelay = 0.250f;
  594. KeyRepeatRate = 0.050f;
  595. UserData = NULL;
  596. // User functions
  597. RenderDrawListsFn = NULL;
  598. MemAllocFn = malloc;
  599. MemFreeFn = free;
  600. GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations
  601. SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
  602. ImeSetInputScreenPosFn = ImeSetInputScreenPosFn_DefaultImpl;
  603. }
  604. // Pass in translated ASCII characters for text input.
  605. // - with glfw you can get those from the callback set in glfwSetCharCallback()
  606. // - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message
  607. void ImGuiIO::AddInputCharacter(ImWchar c)
  608. {
  609. const size_t n = ImStrlenW(InputCharacters);
  610. if (n + 1 < sizeof(InputCharacters) / sizeof(InputCharacters[0]))
  611. {
  612. InputCharacters[n] = c;
  613. InputCharacters[n+1] = 0;
  614. }
  615. }
  616. //-----------------------------------------------------------------------------
  617. // Helpers
  618. //-----------------------------------------------------------------------------
  619. #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
  620. const float IM_PI = 3.14159265358979323846f;
  621. #ifdef INT_MAX
  622. #define IM_INT_MIN INT_MIN
  623. #define IM_INT_MAX INT_MAX
  624. #else
  625. #define IM_INT_MIN (-2147483647-1)
  626. #define IM_INT_MAX (2147483647)
  627. #endif
  628. // Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n.
  629. #ifdef _MSC_VER
  630. #define IM_NEWLINE "\r\n"
  631. #else
  632. #define IM_NEWLINE "\n"
  633. #endif
  634. // Math bits
  635. // 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.
  636. static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); }
  637. //static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); }
  638. static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); }
  639. static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); }
  640. static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); }
  641. static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); }
  642. static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; }
  643. //static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; }
  644. static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; }
  645. //static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; }
  646. static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x-rhs.x, lhs.y-rhs.y, lhs.z-rhs.z, lhs.w-lhs.w); }
  647. static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; }
  648. static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; }
  649. static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; }
  650. static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; }
  651. static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); }
  652. static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); }
  653. static inline int ImClamp(int v, int mn, int mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
  654. static inline float ImClamp(float v, float mn, float mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
  655. 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)); }
  656. static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; }
  657. static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; }
  658. 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); }
  659. static inline float ImLengthSqr(const ImVec2& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y; }
  660. static inline float ImLengthSqr(const ImVec4& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y + lhs.z*lhs.z + lhs.w*lhs.w; }
  661. static bool ImIsPointInTriangle(const ImVec2& p, const ImVec2& a, const ImVec2& b, const ImVec2& c)
  662. {
  663. bool b1 = ((p.x - b.x) * (a.y - b.y) - (p.y - b.y) * (a.x - b.x)) < 0.0f;
  664. bool b2 = ((p.x - c.x) * (b.y - c.y) - (p.y - c.y) * (b.x - c.x)) < 0.0f;
  665. bool b3 = ((p.x - a.x) * (c.y - a.y) - (p.y - a.y) * (c.x - a.x)) < 0.0f;
  666. return ((b1 == b2) && (b2 == b3));
  667. }
  668. static int ImStricmp(const char* str1, const char* str2)
  669. {
  670. int d;
  671. while ((d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; }
  672. return d;
  673. }
  674. static int ImStrnicmp(const char* str1, const char* str2, int count)
  675. {
  676. int d = 0;
  677. while (count > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; count--; }
  678. return d;
  679. }
  680. static char* ImStrdup(const char *str)
  681. {
  682. char *buff = (char*)ImGui::MemAlloc(strlen(str) + 1);
  683. IM_ASSERT(buff);
  684. strcpy(buff, str);
  685. return buff;
  686. }
  687. static size_t ImStrlenW(const ImWchar* str)
  688. {
  689. size_t n = 0;
  690. while (*str++) n++;
  691. return n;
  692. }
  693. static const ImWchar* ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin) // find beginning-of-line
  694. {
  695. while (buf_mid_line > buf_begin && buf_mid_line[-1] != '\n')
  696. buf_mid_line--;
  697. return buf_mid_line;
  698. }
  699. static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end)
  700. {
  701. if (!needle_end)
  702. needle_end = needle + strlen(needle);
  703. const char un0 = (char)toupper(*needle);
  704. while (*haystack)
  705. {
  706. if (toupper(*haystack) == un0)
  707. {
  708. const char* b = needle + 1;
  709. for (const char* a = haystack + 1; b < needle_end; a++, b++)
  710. if (toupper(*a) != toupper(*b))
  711. break;
  712. if (b == needle_end)
  713. return haystack;
  714. }
  715. haystack++;
  716. }
  717. return NULL;
  718. }
  719. // Pass data_size==0 for zero-terminated string
  720. // Try to replace with FNV1a hash?
  721. static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed = 0)
  722. {
  723. static ImU32 crc32_lut[256] = { 0 };
  724. if (!crc32_lut[1])
  725. {
  726. const ImU32 polynomial = 0xEDB88320;
  727. for (ImU32 i = 0; i < 256; i++)
  728. {
  729. ImU32 crc = i;
  730. for (ImU32 j = 0; j < 8; j++)
  731. crc = (crc >> 1) ^ (ImU32(-int(crc & 1)) & polynomial);
  732. crc32_lut[i] = crc;
  733. }
  734. }
  735. seed = ~seed;
  736. ImU32 crc = seed;
  737. const unsigned char* current = (const unsigned char*)data;
  738. if (data_size > 0)
  739. {
  740. // Known size
  741. while (data_size--)
  742. crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++];
  743. }
  744. else
  745. {
  746. // Zero-terminated string
  747. while (unsigned char c = *current++)
  748. {
  749. // We support a syntax of "label###id" where only "###id" is included in the hash, and only "label" gets displayed.
  750. // Because this syntax is rarely used we are optimizing for the common case.
  751. // - If we reach ### in the string we discard the hash so far and reset to the seed.
  752. // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller.
  753. if (c == '#' && current[0] == '#' && current[1] == '#')
  754. crc = seed;
  755. crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
  756. }
  757. }
  758. return ~crc;
  759. }
  760. static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...)
  761. {
  762. va_list args;
  763. va_start(args, fmt);
  764. int w = vsnprintf(buf, buf_size, fmt, args);
  765. va_end(args);
  766. buf[buf_size-1] = 0;
  767. return (w == -1) ? buf_size : (size_t)w;
  768. }
  769. static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args)
  770. {
  771. int w = vsnprintf(buf, buf_size, fmt, args);
  772. buf[buf_size-1] = 0;
  773. return (w == -1) ? buf_size : (size_t)w;
  774. }
  775. ImU32 ImGui::ColorConvertFloat4ToU32(const ImVec4& in)
  776. {
  777. ImU32 out = ((ImU32)(ImSaturate(in.x)*255.f));
  778. out |= ((ImU32)(ImSaturate(in.y)*255.f) << 8);
  779. out |= ((ImU32)(ImSaturate(in.z)*255.f) << 16);
  780. out |= ((ImU32)(ImSaturate(in.w)*255.f) << 24);
  781. return out;
  782. }
  783. // Convert rgb floats ([0-1],[0-1],[0-1]) to hsv floats ([0-1],[0-1],[0-1]), from Foley & van Dam p592
  784. // Optimized http://lolengine.net/blog/2013/01/13/fast-rgb-to-hsv
  785. void ImGui::ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v)
  786. {
  787. float K = 0.f;
  788. if (g < b)
  789. {
  790. const float tmp = g; g = b; b = tmp;
  791. K = -1.f;
  792. }
  793. if (r < g)
  794. {
  795. const float tmp = r; r = g; g = tmp;
  796. K = -2.f / 6.f - K;
  797. }
  798. const float chroma = r - (g < b ? g : b);
  799. out_h = fabsf(K + (g - b) / (6.f * chroma + 1e-20f));
  800. out_s = chroma / (r + 1e-20f);
  801. out_v = r;
  802. }
  803. // Convert hsv floats ([0-1],[0-1],[0-1]) to rgb floats ([0-1],[0-1],[0-1]), from Foley & van Dam p593
  804. // also http://en.wikipedia.org/wiki/HSL_and_HSV
  805. void ImGui::ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b)
  806. {
  807. if (s == 0.0f)
  808. {
  809. // gray
  810. out_r = out_g = out_b = v;
  811. return;
  812. }
  813. h = fmodf(h, 1.0f) / (60.0f/360.0f);
  814. int i = (int)h;
  815. float f = h - (float)i;
  816. float p = v * (1.0f - s);
  817. float q = v * (1.0f - s * f);
  818. float t = v * (1.0f - s * (1.0f - f));
  819. switch (i)
  820. {
  821. case 0: out_r = v; out_g = t; out_b = p; break;
  822. case 1: out_r = q; out_g = v; out_b = p; break;
  823. case 2: out_r = p; out_g = v; out_b = t; break;
  824. case 3: out_r = p; out_g = q; out_b = v; break;
  825. case 4: out_r = t; out_g = p; out_b = v; break;
  826. case 5: default: out_r = v; out_g = p; out_b = q; break;
  827. }
  828. }
  829. // Load file content into memory
  830. // Memory allocated with ImGui::MemAlloc(), must be freed by user using ImGui::MemFree()
  831. static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes)
  832. {
  833. IM_ASSERT(filename && file_open_mode && out_file_data && out_file_size);
  834. *out_file_data = NULL;
  835. *out_file_size = 0;
  836. FILE* f;
  837. if ((f = fopen(filename, file_open_mode)) == NULL)
  838. return false;
  839. long file_size_signed;
  840. if (fseek(f, 0, SEEK_END) || (file_size_signed = ftell(f)) == -1 || fseek(f, 0, SEEK_SET))
  841. {
  842. fclose(f);
  843. return false;
  844. }
  845. size_t file_size = (size_t)file_size_signed;
  846. void* file_data = ImGui::MemAlloc(file_size + padding_bytes);
  847. if (file_data == NULL)
  848. {
  849. fclose(f);
  850. return false;
  851. }
  852. if (fread(file_data, 1, file_size, f) != file_size)
  853. {
  854. fclose(f);
  855. ImGui::MemFree(file_data);
  856. return false;
  857. }
  858. if (padding_bytes > 0)
  859. memset((void *)(((char*)file_data) + file_size), 0, padding_bytes);
  860. fclose(f);
  861. *out_file_data = file_data;
  862. *out_file_size = file_size;
  863. return true;
  864. }
  865. //-----------------------------------------------------------------------------
  866. enum ImGuiLayoutType_
  867. {
  868. ImGuiLayoutType_Vertical,
  869. ImGuiLayoutType_Horizontal // FIXME: this is in development, not exposed/functional as a generic feature yet.
  870. };
  871. enum ImGuiButtonFlags_
  872. {
  873. ImGuiButtonFlags_Repeat = 1 << 0,
  874. ImGuiButtonFlags_PressedOnClick = 1 << 1, // return pressed on click only (default requires click+release)
  875. ImGuiButtonFlags_PressedOnRelease = 1 << 2, // return pressed on release only (default requires click+release)
  876. ImGuiButtonFlags_FlattenChilds = 1 << 3,
  877. ImGuiButtonFlags_DontClosePopups = 1 << 4,
  878. ImGuiButtonFlags_Disabled = 1 << 5,
  879. ImGuiButtonFlags_AlignTextBaseLine = 1 << 6
  880. };
  881. enum ImGuiSelectableFlagsPrivate_
  882. {
  883. // NB: need to be in sync with last value of ImGuiSelectableFlags_
  884. ImGuiSelectableFlags_Menu = 1 << 2,
  885. ImGuiSelectableFlags_MenuItem = 1 << 3,
  886. ImGuiSelectableFlags_Disabled = 1 << 4,
  887. ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 5
  888. };
  889. struct ImGuiColMod // Color modifier, backup of modified data so we can restore it
  890. {
  891. ImGuiCol Col;
  892. ImVec4 PreviousValue;
  893. };
  894. struct ImGuiStyleMod // Style modifier, backup of modified data so we can restore it
  895. {
  896. ImGuiStyleVar Var;
  897. ImVec2 PreviousValue;
  898. };
  899. struct ImRect // 2D axis aligned bounding-box
  900. {
  901. ImVec2 Min;
  902. ImVec2 Max;
  903. ImRect() { Min = ImVec2(FLT_MAX,FLT_MAX); Max = ImVec2(-FLT_MAX,-FLT_MAX); }
  904. ImRect(const ImVec2& min, const ImVec2& max) { Min = min; Max = max; }
  905. ImRect(const ImVec4& v) { Min.x = v.x; Min.y = v.y; Max.x = v.z; Max.y = v.w; }
  906. ImRect(float x1, float y1, float x2, float y2) { Min.x = x1; Min.y = y1; Max.x = x2; Max.y = y2; }
  907. ImVec2 GetCenter() const { return ImVec2((Min.x+Max.x)*0.5f, (Min.y+Max.y)*0.5f); }
  908. ImVec2 GetSize() const { return ImVec2(Max.x-Min.x,Max.y-Min.y); }
  909. float GetWidth() const { return Max.x-Min.x; }
  910. float GetHeight() const { return Max.y-Min.y; }
  911. ImVec2 GetTL() const { return Min; }
  912. ImVec2 GetTR() const { return ImVec2(Max.x,Min.y); }
  913. ImVec2 GetBL() const { return ImVec2(Min.x,Max.y); }
  914. ImVec2 GetBR() const { return Max; }
  915. bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x < Max.x && p.y < Max.y; }
  916. bool Contains(const ImRect& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x < Max.x && r.Max.y < Max.y; }
  917. bool Overlaps(const ImRect& r) const { return r.Min.y < Max.y && r.Max.y > Min.y && r.Min.x < Max.x && r.Max.x > Min.x; }
  918. void Add(const ImVec2& rhs) { Min.x = ImMin(Min.x, rhs.x); Min.y = ImMin(Min.y, rhs.y); Max.x = ImMax(Max.x, rhs.x); Max.y = ImMax(Max.x, rhs.x); }
  919. void Add(const ImRect& rhs) { Min.x = ImMin(Min.x, rhs.Min.x); Min.y = ImMin(Min.y, rhs.Min.y); Max.x = ImMax(Max.x, rhs.Max.x); Max.y = ImMax(Max.y, rhs.Max.y); }
  920. void Expand(const float amount) { Min.x -= amount; Min.y -= amount; Max.x += amount; Max.y += amount; }
  921. void Expand(const ImVec2& amount) { Min.x -= amount.x; Min.y -= amount.y; Max.x += amount.x; Max.y += amount.y; }
  922. void Reduce(const ImVec2& amount) { Min.x += amount.x; Min.y += amount.y; Max.x -= amount.x; Max.y -= amount.y; }
  923. void Clip(const ImRect& clip) { Min.x = ImMax(Min.x, clip.Min.x); Min.y = ImMax(Min.y, clip.Min.y); Max.x = ImMin(Max.x, clip.Max.x); Max.y = ImMin(Max.y, clip.Max.y); }
  924. ImVec2 GetClosestPoint(ImVec2 p, bool on_edge) const
  925. {
  926. if (!on_edge && Contains(p))
  927. return p;
  928. if (p.x > Max.x) p.x = Max.x;
  929. else if (p.x < Min.x) p.x = Min.x;
  930. if (p.y > Max.y) p.y = Max.y;
  931. else if (p.y < Min.y) p.y = Min.y;
  932. return p;
  933. }
  934. };
  935. struct ImGuiGroupData
  936. {
  937. ImVec2 BackupCursorPos;
  938. ImVec2 BackupCursorMaxPos;
  939. float BackupColumnsStartX;
  940. float BackupCurrentLineHeight;
  941. float BackupCurrentLineTextBaseOffset;
  942. float BackupLogLinePosY;
  943. bool AdvanceCursor;
  944. };
  945. // Simple column measurement currently used for menu items. This is very short-sighted for now.
  946. struct ImGuiSimpleColumns
  947. {
  948. int Count;
  949. float Spacing;
  950. float Width, NextWidth;
  951. float Pos[8], NextWidths[8];
  952. ImGuiSimpleColumns() { Count = 0; Spacing = 0.0f; Width = 0.0f; NextWidth = 0.0f; memset(Pos, 0, sizeof(Pos)); memset(NextWidths, 0, sizeof(NextWidths)); }
  953. void Update(int count, float spacing, bool clear)
  954. {
  955. IM_ASSERT(Count <= IM_ARRAYSIZE(Pos));
  956. Count = count;
  957. Width = NextWidth = 0.0f;
  958. Spacing = spacing;
  959. if (clear) memset(NextWidths, 0, sizeof(NextWidths));
  960. for (int i = 0; i < Count; i++)
  961. {
  962. if (i > 0 && NextWidths[i] > 0.0f)
  963. Width += Spacing;
  964. Pos[i] = (float)(int)Width;
  965. Width += NextWidths[i];
  966. NextWidths[i] = 0.0f;
  967. }
  968. }
  969. float DeclColumns(float w0, float w1, float w2) // not using va_arg because they promote float to double
  970. {
  971. NextWidth = 0.0f;
  972. NextWidths[0] = ImMax(NextWidths[0], w0);
  973. NextWidths[1] = ImMax(NextWidths[1], w1);
  974. NextWidths[2] = ImMax(NextWidths[2], w2);
  975. for (int i = 0; i < 3; i++)
  976. NextWidth += NextWidths[i] + ((i > 0 && NextWidths[i] > 0.0f) ? Spacing : 0.0f);
  977. return ImMax(Width, NextWidth);
  978. }
  979. float CalcExtraSpace(float avail_w)
  980. {
  981. return ImMax(0.0f, avail_w - Width);
  982. }
  983. };
  984. // Temporary per-window data, reset at the beginning of the frame
  985. struct ImGuiDrawContext
  986. {
  987. ImVec2 CursorPos;
  988. ImVec2 CursorPosPrevLine;
  989. ImVec2 CursorStartPos;
  990. ImVec2 CursorMaxPos; // Implicitly calculate the size of our contents, always extending. Saved into window->SizeContents at the end of the frame
  991. float CurrentLineHeight;
  992. float CurrentLineTextBaseOffset;
  993. float PrevLineHeight;
  994. float PrevLineTextBaseOffset;
  995. float LogLinePosY;
  996. int TreeDepth;
  997. ImGuiID LastItemID;
  998. ImRect LastItemRect;
  999. bool LastItemHoveredAndUsable;
  1000. bool LastItemHoveredRect;
  1001. bool MenuBarAppending;
  1002. float MenuBarOffsetX;
  1003. ImVector<ImGuiWindow*> ChildWindows;
  1004. ImGuiStorage* StateStorage;
  1005. ImGuiLayoutType LayoutType;
  1006. // We store the current settings outside of the vectors to increase memory locality (reduce cache misses). The vectors are rarely modified. Also it allows us to not heap allocate for short-lived windows which are not using those settings.
  1007. bool ButtonRepeat; // == ButtonRepeatStack.back() [empty == false]
  1008. bool AllowKeyboardFocus; // == AllowKeyboardFocusStack.back() [empty == true]
  1009. float ItemWidth; // == ItemWidthStack.back(). 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window
  1010. float TextWrapPos; // == TextWrapPosStack.back() [empty == -1.0f]
  1011. ImVector<bool> ButtonRepeatStack;
  1012. ImVector<bool> AllowKeyboardFocusStack;
  1013. ImVector<float> ItemWidthStack;
  1014. ImVector<float> TextWrapPosStack;
  1015. ImVector<ImGuiGroupData>GroupStack;
  1016. ImGuiColorEditMode ColorEditMode;
  1017. int StackSizesBackup[6]; // Store size of various stacks for asserting
  1018. float ColumnsStartX; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.)
  1019. 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.
  1020. int ColumnsCurrent;
  1021. int ColumnsCount;
  1022. ImVec2 ColumnsStartPos;
  1023. float ColumnsCellMinY;
  1024. float ColumnsCellMaxY;
  1025. bool ColumnsShowBorders;
  1026. ImGuiID ColumnsSetID;
  1027. ImVector<float> ColumnsOffsetsT; // Columns offset normalized 0.0 (far left) -> 1.0 (far right)
  1028. ImGuiDrawContext()
  1029. {
  1030. CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f);
  1031. CurrentLineHeight = PrevLineHeight = 0.0f;
  1032. CurrentLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f;
  1033. LogLinePosY = -1.0f;
  1034. TreeDepth = 0;
  1035. LastItemID = 0;
  1036. LastItemRect = ImRect(0.0f,0.0f,0.0f,0.0f);
  1037. LastItemHoveredAndUsable = LastItemHoveredRect = false;
  1038. MenuBarAppending = false;
  1039. MenuBarOffsetX = 0.0f;
  1040. StateStorage = NULL;
  1041. LayoutType = ImGuiLayoutType_Vertical;
  1042. ItemWidth = 0.0f;
  1043. ButtonRepeat = false;
  1044. AllowKeyboardFocus = true;
  1045. TextWrapPos = -1.0f;
  1046. ColorEditMode = ImGuiColorEditMode_RGB;
  1047. memset(StackSizesBackup, 0, sizeof(StackSizesBackup));
  1048. ColumnsStartX = 0.0f;
  1049. ColumnsOffsetX = 0.0f;
  1050. ColumnsCurrent = 0;
  1051. ColumnsCount = 1;
  1052. ColumnsStartPos = ImVec2(0.0f, 0.0f);
  1053. ColumnsCellMinY = ColumnsCellMaxY = 0.0f;
  1054. ColumnsShowBorders = true;
  1055. ColumnsSetID = 0;
  1056. }
  1057. };
  1058. // Internal state of the currently focused/edited text input box
  1059. struct ImGuiTextEditState
  1060. {
  1061. ImGuiID Id; // widget id owning the text state
  1062. ImVector<ImWchar> Text; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer.
  1063. ImVector<char> InitialText; // backup of end-user buffer at the time of focus (in UTF-8, unaltered)
  1064. ImVector<char> TempTextBuffer;
  1065. size_t CurLenA, CurLenW; // we need to maintain our buffer length in both UTF-8 and wchar format.
  1066. size_t BufSizeA; // end-user buffer size
  1067. float ScrollX;
  1068. STB_TexteditState StbState;
  1069. float CursorAnim;
  1070. bool CursorFollow;
  1071. ImVec2 InputCursorScreenPos; // Cursor position in screen space to be used by IME callback.
  1072. bool SelectedAllMouseLock;
  1073. ImGuiTextEditState() { memset(this, 0, sizeof(*this)); }
  1074. void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking
  1075. bool CursorIsVisible() const { return CursorAnim <= 0.0f || fmodf(CursorAnim, 1.20f) <= 0.80f; } // Blinking
  1076. bool HasSelection() const { return StbState.select_start != StbState.select_end; }
  1077. void ClearSelection() { StbState.select_start = StbState.select_end = StbState.cursor; }
  1078. void SelectAll() { StbState.select_start = 0; StbState.select_end = (int)CurLenW; StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; }
  1079. void OnKeyPressed(int key);
  1080. };
  1081. // Data saved in imgui.ini file
  1082. struct ImGuiIniData
  1083. {
  1084. char* Name;
  1085. ImGuiID ID;
  1086. ImVec2 Pos;
  1087. ImVec2 Size;
  1088. bool Collapsed;
  1089. };
  1090. struct ImGuiMouseCursorData
  1091. {
  1092. ImGuiMouseCursor Type;
  1093. ImVec2 Offset;
  1094. ImVec2 Size;
  1095. ImVec2 TexUvMin[2];
  1096. ImVec2 TexUvMax[2];
  1097. };
  1098. struct ImGuiPopupRef
  1099. {
  1100. ImGuiID PopupID; // Set on OpenPopup()
  1101. ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup()
  1102. ImGuiWindow* ParentWindow; // Set on OpenPopup()
  1103. ImGuiID ParentMenuSet; // Set on OpenPopup()
  1104. ImGuiPopupRef(ImGuiID id, ImGuiWindow* parent_window, ImGuiID parent_menu_set) { PopupID = id; Window = NULL; ParentWindow = parent_window; ParentMenuSet = parent_menu_set; }
  1105. };
  1106. // Main state for ImGui
  1107. struct ImGuiState
  1108. {
  1109. bool Initialized;
  1110. ImGuiIO IO;
  1111. ImGuiStyle Style;
  1112. ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
  1113. float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize()
  1114. float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters.
  1115. ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvForWhite
  1116. float Time;
  1117. int FrameCount;
  1118. int FrameCountRendered;
  1119. ImVector<ImGuiWindow*> Windows;
  1120. ImVector<ImGuiWindow*> WindowsSortBuffer;
  1121. ImGuiWindow* CurrentWindow; // Being drawn into
  1122. ImVector<ImGuiWindow*> CurrentWindowStack;
  1123. ImGuiWindow* FocusedWindow; // Will catch keyboard inputs
  1124. ImGuiWindow* HoveredWindow; // Will catch mouse inputs
  1125. ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only)
  1126. ImGuiID HoveredId; // Hovered widget
  1127. ImGuiID HoveredIdPreviousFrame;
  1128. ImGuiID ActiveId; // Active widget
  1129. ImGuiID ActiveIdPreviousFrame;
  1130. bool ActiveIdIsAlive;
  1131. bool ActiveIdIsJustActivated; // Set at the time of activation for one frame
  1132. bool ActiveIdIsFocusedOnly; // Set only by active widget. Denote focus but no active interaction
  1133. ImGuiWindow* ActiveIdWindow;
  1134. ImGuiWindow* MovedWindow; // Track the child window we clicked on to move a window. Only valid if ActiveID is the "#MOVE" identifier of a window.
  1135. float SettingsDirtyTimer;
  1136. ImVector<ImGuiIniData> Settings;
  1137. int DisableHideTextAfterDoubleHash;
  1138. ImVector<ImGuiColMod> ColorModifiers;
  1139. ImVector<ImGuiStyleMod> StyleModifiers;
  1140. ImVector<ImFont*> FontStack;
  1141. ImVector<ImGuiPopupRef> OpenedPopupStack; // Which popups are open
  1142. ImVector<ImGuiPopupRef> CurrentPopupStack; // Which level of BeginPopup() we are in (reset every frame)
  1143. ImVec2 SetNextWindowPosVal;
  1144. ImGuiSetCond SetNextWindowPosCond;
  1145. ImVec2 SetNextWindowSizeVal;
  1146. ImGuiSetCond SetNextWindowSizeCond;
  1147. bool SetNextWindowCollapsedVal;
  1148. ImGuiSetCond SetNextWindowCollapsedCond;
  1149. bool SetNextWindowFocus;
  1150. bool SetNextTreeNodeOpenedVal;
  1151. ImGuiSetCond SetNextTreeNodeOpenedCond;
  1152. // Render
  1153. ImVector<ImDrawList*> RenderDrawLists[3];
  1154. float ModalWindowDarkeningRatio;
  1155. // Mouse cursor
  1156. ImGuiMouseCursor MouseCursor;
  1157. ImDrawList MouseCursorDrawList; // Optional software render of mouse cursors, if io.MouseDrawCursor is set
  1158. ImGuiMouseCursorData MouseCursorData[ImGuiMouseCursor_Count_];
  1159. // Widget state
  1160. ImGuiTextEditState InputTextState;
  1161. ImGuiID ScalarAsInputTextId; // Temporary text input when CTRL+clicking on a slider, etc.
  1162. ImGuiStorage ColorEditModeStorage; // Store user selection of color edit mode
  1163. ImVec2 ActiveClickDeltaToCenter;
  1164. float DragCurrentValue; // current dragged value, always float, not rounded by end-user precision settings
  1165. ImVec2 DragLastMouseDelta;
  1166. float DragSpeedDefaultRatio; // if speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio
  1167. float DragSpeedScaleSlow;
  1168. float DragSpeedScaleFast;
  1169. float ScrollbarClickDeltaToGrabCenter; // distance between mouse and center of grab box, normalized in parent space
  1170. char Tooltip[1024];
  1171. char* PrivateClipboard; // if no custom clipboard handler is defined
  1172. // Logging
  1173. bool LogEnabled;
  1174. FILE* LogFile;
  1175. ImGuiTextBuffer* LogClipboard; // pointer so our GImGui static constructor doesn't call heap allocators.
  1176. int LogStartDepth;
  1177. int LogAutoExpandMaxDepth;
  1178. // Misc
  1179. float FramerateSecPerFrame[120]; // calculate estimate of framerate for user
  1180. int FramerateSecPerFrameIdx;
  1181. float FramerateSecPerFrameAccum;
  1182. bool CaptureMouseNextFrame; // explicit capture via CaptureInputs() sets those flags
  1183. bool CaptureKeyboardNextFrame;
  1184. char TempBuffer[1024*3+1]; // temporary text buffer
  1185. ImGuiState()
  1186. {
  1187. Initialized = false;
  1188. Font = NULL;
  1189. FontSize = FontBaseSize = 0.0f;
  1190. FontTexUvWhitePixel = ImVec2(0.0f, 0.0f);
  1191. Time = 0.0f;
  1192. FrameCount = 0;
  1193. FrameCountRendered = -1;
  1194. CurrentWindow = NULL;
  1195. FocusedWindow = NULL;
  1196. HoveredWindow = NULL;
  1197. HoveredRootWindow = NULL;
  1198. HoveredId = 0;
  1199. HoveredIdPreviousFrame = 0;
  1200. ActiveId = 0;
  1201. ActiveIdPreviousFrame = 0;
  1202. ActiveIdIsAlive = false;
  1203. ActiveIdIsJustActivated = false;
  1204. ActiveIdIsFocusedOnly = false;
  1205. ActiveIdWindow = NULL;
  1206. MovedWindow = NULL;
  1207. SettingsDirtyTimer = 0.0f;
  1208. DisableHideTextAfterDoubleHash = 0;
  1209. SetNextWindowPosVal = ImVec2(0.0f, 0.0f);
  1210. SetNextWindowPosCond = 0;
  1211. SetNextWindowSizeVal = ImVec2(0.0f, 0.0f);
  1212. SetNextWindowSizeCond = 0;
  1213. SetNextWindowCollapsedVal = false;
  1214. SetNextWindowCollapsedCond = 0;
  1215. SetNextWindowFocus = false;
  1216. SetNextTreeNodeOpenedVal = false;
  1217. SetNextTreeNodeOpenedCond = 0;
  1218. ScalarAsInputTextId = 0;
  1219. ActiveClickDeltaToCenter = ImVec2(0.0f, 0.0f);
  1220. DragCurrentValue = 0.0f;
  1221. DragLastMouseDelta = ImVec2(0.0f, 0.0f);
  1222. DragSpeedDefaultRatio = 0.01f;
  1223. DragSpeedScaleSlow = 0.01f;
  1224. DragSpeedScaleFast = 10.0f;
  1225. ScrollbarClickDeltaToGrabCenter = 0.0f;
  1226. memset(Tooltip, 0, sizeof(Tooltip));
  1227. PrivateClipboard = NULL;
  1228. ModalWindowDarkeningRatio = 0.0f;
  1229. MouseCursor = ImGuiMouseCursor_Arrow;
  1230. LogEnabled = false;
  1231. LogFile = NULL;
  1232. LogClipboard = NULL;
  1233. LogStartDepth = 0;
  1234. LogAutoExpandMaxDepth = 2;
  1235. memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame));
  1236. FramerateSecPerFrameIdx = 0;
  1237. FramerateSecPerFrameAccum = 0.0f;
  1238. CaptureMouseNextFrame = CaptureKeyboardNextFrame = false;
  1239. }
  1240. };
  1241. static ImGuiState GImDefaultState; // Internal state storage
  1242. static ImGuiState* GImGui = &GImDefaultState; // We access everything through this pointer. NB: this pointer is always assumed to be != NULL
  1243. struct ImGuiWindow
  1244. {
  1245. char* Name;
  1246. ImGuiID ID;
  1247. ImGuiWindowFlags Flags;
  1248. ImVec2 PosFloat;
  1249. ImVec2 Pos; // Position rounded-up to nearest pixel
  1250. ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
  1251. ImVec2 SizeFull; // Size when non collapsed
  1252. ImVec2 SizeContents; // Size of contents (== extents reach of the drawing cursor) from previous frame
  1253. ImVec2 WindowPadding; // Window padding at the time of begin. We need to lock it, in particular manipulation of the ShowBorder would have an effect
  1254. ImGuiID MoveID; // == window->GetID("#MOVE")
  1255. float ScrollY;
  1256. float ScrollTargetRelY; // target scroll position. stored as cursor position with scrolling canceled out, so the highest point is always 0.0f. (FLT_MAX for no change)
  1257. float ScrollTargetCenterRatioY; // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered
  1258. bool ScrollbarY;
  1259. bool Active; // Set to true on Begin()
  1260. bool WasActive;
  1261. bool Accessed; // Set to true when any widget access the current window
  1262. bool Collapsed; // Set when collapsing window to become only title-bar
  1263. bool SkipItems; // == Visible && !Collapsed
  1264. int BeginCount; // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs)
  1265. ImGuiID PopupID; // ID in the popup stack when this window is used as a popup/menu (because we use generic Name/ID for recycling)
  1266. int AutoFitFramesX, AutoFitFramesY;
  1267. bool AutoFitOnlyGrows;
  1268. int AutoPosLastDirection;
  1269. int HiddenFrames;
  1270. int SetWindowPosAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowPos() call will succeed with this particular flag.
  1271. int SetWindowSizeAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowSize() call will succeed with this particular flag.
  1272. int SetWindowCollapsedAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowCollapsed() call will succeed with this particular flag.
  1273. bool SetWindowPosCenterWanted;
  1274. ImGuiDrawContext DC; // Temporary per-window data, reset at the beginning of the frame
  1275. ImVector<ImGuiID> IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack
  1276. ImVector<ImVec4> ClipRectStack; // Scissoring / clipping rectangle. x1, y1, x2, y2.
  1277. ImRect ClippedRect; // = ClipRectStack.front() after setup in Begin()
  1278. int LastFrameDrawn;
  1279. float ItemWidthDefault;
  1280. ImGuiSimpleColumns MenuColumns; // Simplified columns storage for menu items
  1281. ImGuiStorage StateStorage;
  1282. float FontWindowScale; // Scale multiplier per-window
  1283. ImDrawList* DrawList;
  1284. ImGuiWindow* RootWindow;
  1285. ImGuiWindow* RootNonPopupWindow;
  1286. // Focus
  1287. int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister()
  1288. int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through)
  1289. int FocusIdxAllRequestCurrent; // Item being requested for focus
  1290. int FocusIdxTabRequestCurrent; // Tab-able item being requested for focus
  1291. 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)
  1292. int FocusIdxTabRequestNext; // "
  1293. public:
  1294. ImGuiWindow(const char* name);
  1295. ~ImGuiWindow();
  1296. ImGuiID GetID(const char* str, const char* str_end = NULL);
  1297. ImGuiID GetID(const void* ptr);
  1298. bool FocusItemRegister(bool is_active, bool tab_stop = true); // Return true if focus is requested
  1299. void FocusItemUnregister();
  1300. ImRect Rect() const { return ImRect(Pos, Pos+Size); }
  1301. float CalcFontSize() const { return GImGui->FontBaseSize * FontWindowScale; }
  1302. float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f; }
  1303. ImRect TitleBarRect() const { return ImRect(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); }
  1304. float MenuBarHeight() const { return (Flags & ImGuiWindowFlags_MenuBar) ? CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f : 0.0f; }
  1305. ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); }
  1306. float ScrollbarWidth() const { return ScrollbarY ? GImGui->Style.ScrollbarWidth : 0.0f; }
  1307. ImU32 Color(ImGuiCol idx, float a=1.f) const { ImVec4 c = GImGui->Style.Colors[idx]; c.w *= GImGui->Style.Alpha * a; return ImGui::ColorConvertFloat4ToU32(c); }
  1308. ImU32 Color(const ImVec4& col) const { ImVec4 c = col; c.w *= GImGui->Style.Alpha; return ImGui::ColorConvertFloat4ToU32(c); }
  1309. };
  1310. static inline ImGuiWindow* GetCurrentWindow()
  1311. {
  1312. // If this ever crash it probably means that ImGui::NewFrame() hasn't been called. We should always have a CurrentWindow in the stack (there is an implicit "Debug" window)
  1313. ImGuiState& g = *GImGui;
  1314. g.CurrentWindow->Accessed = true;
  1315. return g.CurrentWindow;
  1316. }
  1317. static inline void SetCurrentWindow(ImGuiWindow* window)
  1318. {
  1319. ImGuiState& g = *GImGui;
  1320. g.CurrentWindow = window;
  1321. if (window)
  1322. g.FontSize = window->CalcFontSize();
  1323. }
  1324. static inline ImGuiWindow* GetParentWindow()
  1325. {
  1326. ImGuiState& g = *GImGui;
  1327. IM_ASSERT(g.CurrentWindowStack.size() >= 2);
  1328. return g.CurrentWindowStack[g.CurrentWindowStack.size() - 2];
  1329. }
  1330. static void SetActiveId(ImGuiID id, ImGuiWindow* window = NULL)
  1331. {
  1332. ImGuiState& g = *GImGui;
  1333. g.ActiveId = id;
  1334. g.ActiveIdIsFocusedOnly = false;
  1335. g.ActiveIdIsJustActivated = true;
  1336. g.ActiveIdWindow = window;
  1337. }
  1338. static void RegisterAliveId(ImGuiID id)
  1339. {
  1340. ImGuiState& g = *GImGui;
  1341. if (g.ActiveId == id)
  1342. g.ActiveIdIsAlive = true;
  1343. }
  1344. //-----------------------------------------------------------------------------
  1345. // Helper: Key->value storage
  1346. void ImGuiStorage::Clear()
  1347. {
  1348. Data.clear();
  1349. }
  1350. // std::lower_bound but without the bullshit
  1351. static ImVector<ImGuiStorage::Pair>::iterator LowerBound(ImVector<ImGuiStorage::Pair>& data, ImU32 key)
  1352. {
  1353. ImVector<ImGuiStorage::Pair>::iterator first = data.begin();
  1354. ImVector<ImGuiStorage::Pair>::iterator last = data.end();
  1355. int count = (int)(last - first);
  1356. while (count > 0)
  1357. {
  1358. int count2 = count / 2;
  1359. ImVector<ImGuiStorage::Pair>::iterator mid = first + count2;
  1360. if (mid->key < key)
  1361. {
  1362. first = ++mid;
  1363. count -= count2 + 1;
  1364. }
  1365. else
  1366. {
  1367. count = count2;
  1368. }
  1369. }
  1370. return first;
  1371. }
  1372. int ImGuiStorage::GetInt(ImU32 key, int default_val) const
  1373. {
  1374. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  1375. if (it == Data.end() || it->key != key)
  1376. return default_val;
  1377. return it->val_i;
  1378. }
  1379. float ImGuiStorage::GetFloat(ImU32 key, float default_val) const
  1380. {
  1381. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  1382. if (it == Data.end() || it->key != key)
  1383. return default_val;
  1384. return it->val_f;
  1385. }
  1386. void* ImGuiStorage::GetVoidPtr(ImGuiID key) const
  1387. {
  1388. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  1389. if (it == Data.end() || it->key != key)
  1390. return NULL;
  1391. return it->val_p;
  1392. }
  1393. // References are only valid until a new value is added to the storage. Calling a Set***() function or a Get***Ref() function invalidates the pointer.
  1394. int* ImGuiStorage::GetIntRef(ImGuiID key, int default_val)
  1395. {
  1396. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1397. if (it == Data.end() || it->key != key)
  1398. it = Data.insert(it, Pair(key, default_val));
  1399. return &it->val_i;
  1400. }
  1401. float* ImGuiStorage::GetFloatRef(ImGuiID key, float default_val)
  1402. {
  1403. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1404. if (it == Data.end() || it->key != key)
  1405. it = Data.insert(it, Pair(key, default_val));
  1406. return &it->val_f;
  1407. }
  1408. void** ImGuiStorage::GetVoidPtrRef(ImGuiID key, void* default_val)
  1409. {
  1410. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1411. if (it == Data.end() || it->key != key)
  1412. it = Data.insert(it, Pair(key, default_val));
  1413. return &it->val_p;
  1414. }
  1415. // FIXME-OPT: Need a way to reuse the result of lower_bound when doing GetInt()/SetInt() - not too bad because it only happens on explicit interaction (maximum one a frame)
  1416. void ImGuiStorage::SetInt(ImU32 key, int val)
  1417. {
  1418. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1419. if (it == Data.end() || it->key != key)
  1420. {
  1421. Data.insert(it, Pair(key, val));
  1422. return;
  1423. }
  1424. it->val_i = val;
  1425. }
  1426. void ImGuiStorage::SetFloat(ImU32 key, float val)
  1427. {
  1428. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1429. if (it == Data.end() || it->key != key)
  1430. {
  1431. Data.insert(it, Pair(key, val));
  1432. return;
  1433. }
  1434. it->val_f = val;
  1435. }
  1436. void ImGuiStorage::SetVoidPtr(ImU32 key, void* val)
  1437. {
  1438. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1439. if (it == Data.end() || it->key != key)
  1440. {
  1441. Data.insert(it, Pair(key, val));
  1442. return;
  1443. }
  1444. it->val_p = val;
  1445. }
  1446. void ImGuiStorage::SetAllInt(int v)
  1447. {
  1448. for (size_t i = 0; i < Data.size(); i++)
  1449. Data[i].val_i = v;
  1450. }
  1451. //-----------------------------------------------------------------------------
  1452. // Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
  1453. ImGuiTextFilter::ImGuiTextFilter(const char* default_filter)
  1454. {
  1455. if (default_filter)
  1456. {
  1457. ImFormatString(InputBuf, IM_ARRAYSIZE(InputBuf), "%s", default_filter);
  1458. Build();
  1459. }
  1460. else
  1461. {
  1462. InputBuf[0] = 0;
  1463. CountGrep = 0;
  1464. }
  1465. }
  1466. void ImGuiTextFilter::Draw(const char* label, float width)
  1467. {
  1468. if (width > 0.0f)
  1469. ImGui::PushItemWidth(width);
  1470. ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf));
  1471. if (width > 0.0f)
  1472. ImGui::PopItemWidth();
  1473. Build();
  1474. }
  1475. void ImGuiTextFilter::TextRange::split(char separator, ImVector<TextRange>& out)
  1476. {
  1477. out.resize(0);
  1478. const char* wb = b;
  1479. const char* we = wb;
  1480. while (we < e)
  1481. {
  1482. if (*we == separator)
  1483. {
  1484. out.push_back(TextRange(wb, we));
  1485. wb = we + 1;
  1486. }
  1487. we++;
  1488. }
  1489. if (wb != we)
  1490. out.push_back(TextRange(wb, we));
  1491. }
  1492. void ImGuiTextFilter::Build()
  1493. {
  1494. Filters.resize(0);
  1495. TextRange input_range(InputBuf, InputBuf+strlen(InputBuf));
  1496. input_range.split(',', Filters);
  1497. CountGrep = 0;
  1498. for (size_t i = 0; i != Filters.size(); i++)
  1499. {
  1500. Filters[i].trim_blanks();
  1501. if (Filters[i].empty())
  1502. continue;
  1503. if (Filters[i].front() != '-')
  1504. CountGrep += 1;
  1505. }
  1506. }
  1507. bool ImGuiTextFilter::PassFilter(const char* val) const
  1508. {
  1509. if (Filters.empty())
  1510. return true;
  1511. if (val == NULL)
  1512. val = "";
  1513. for (size_t i = 0; i != Filters.size(); i++)
  1514. {
  1515. const TextRange& f = Filters[i];
  1516. if (f.empty())
  1517. continue;
  1518. if (f.front() == '-')
  1519. {
  1520. // Subtract
  1521. if (ImStristr(val, f.begin()+1, f.end()) != NULL)
  1522. return false;
  1523. }
  1524. else
  1525. {
  1526. // Grep
  1527. if (ImStristr(val, f.begin(), f.end()) != NULL)
  1528. return true;
  1529. }
  1530. }
  1531. // Implicit * grep
  1532. if (CountGrep == 0)
  1533. return true;
  1534. return false;
  1535. }
  1536. // On some platform vsnprintf() takes va_list by reference and modifies it.
  1537. // va_copy is the 'correct' way to copy a va_list but Visual Studio prior to 2013 doesn't have it.
  1538. #ifndef va_copy
  1539. #define va_copy(dest, src) (dest = src)
  1540. #endif
  1541. // Helper: Text buffer for logging/accumulating text
  1542. void ImGuiTextBuffer::appendv(const char* fmt, va_list args)
  1543. {
  1544. va_list args_copy;
  1545. va_copy(args_copy, args);
  1546. int len = vsnprintf(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass.
  1547. if (len <= 0)
  1548. return;
  1549. const size_t write_off = Buf.size();
  1550. const size_t needed_sz = write_off + (size_t)len;
  1551. if (write_off + (size_t)len >= Buf.capacity())
  1552. {
  1553. const size_t double_capacity = Buf.capacity() * 2;
  1554. Buf.reserve(needed_sz > double_capacity ? needed_sz : double_capacity);
  1555. }
  1556. Buf.resize(needed_sz);
  1557. ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args_copy);
  1558. }
  1559. void ImGuiTextBuffer::append(const char* fmt, ...)
  1560. {
  1561. va_list args;
  1562. va_start(args, fmt);
  1563. appendv(fmt, args);
  1564. va_end(args);
  1565. }
  1566. //-----------------------------------------------------------------------------
  1567. ImGuiWindow::ImGuiWindow(const char* name)
  1568. {
  1569. Name = ImStrdup(name);
  1570. ID = ImHash(name, 0);
  1571. IDStack.push_back(ID);
  1572. MoveID = GetID("#MOVE");
  1573. Flags = 0;
  1574. PosFloat = Pos = ImVec2(0.0f, 0.0f);
  1575. Size = SizeFull = ImVec2(0.0f, 0.0f);
  1576. SizeContents = ImVec2(0.0f, 0.0f);
  1577. WindowPadding = ImVec2(0.0f, 0.0f);
  1578. ScrollY = 0.0f;
  1579. ScrollTargetRelY = FLT_MAX;
  1580. ScrollTargetCenterRatioY = 0.5f;
  1581. ScrollbarY = false;
  1582. Active = WasActive = false;
  1583. Accessed = false;
  1584. Collapsed = false;
  1585. SkipItems = false;
  1586. BeginCount = 0;
  1587. PopupID = 0;
  1588. AutoFitFramesX = AutoFitFramesY = -1;
  1589. AutoFitOnlyGrows = false;
  1590. AutoPosLastDirection = -1;
  1591. HiddenFrames = 0;
  1592. SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCond_Always | ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver | ImGuiSetCond_Appearing;
  1593. SetWindowPosCenterWanted = false;
  1594. LastFrameDrawn = -1;
  1595. ItemWidthDefault = 0.0f;
  1596. FontWindowScale = 1.0f;
  1597. DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
  1598. new(DrawList) ImDrawList();
  1599. RootWindow = NULL;
  1600. RootNonPopupWindow = NULL;
  1601. FocusIdxAllCounter = FocusIdxTabCounter = -1;
  1602. FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX;
  1603. FocusIdxAllRequestNext = FocusIdxTabRequestNext = IM_INT_MAX;
  1604. }
  1605. ImGuiWindow::~ImGuiWindow()
  1606. {
  1607. DrawList->~ImDrawList();
  1608. ImGui::MemFree(DrawList);
  1609. DrawList = NULL;
  1610. ImGui::MemFree(Name);
  1611. Name = NULL;
  1612. }
  1613. ImGuiID ImGuiWindow::GetID(const char* str, const char* str_end)
  1614. {
  1615. ImGuiID seed = IDStack.back();
  1616. const ImGuiID id = ImHash(str, str_end ? str_end - str : 0, seed);
  1617. RegisterAliveId(id);
  1618. return id;
  1619. }
  1620. ImGuiID ImGuiWindow::GetID(const void* ptr)
  1621. {
  1622. ImGuiID seed = IDStack.back();
  1623. const ImGuiID id = ImHash(&ptr, sizeof(void*), seed);
  1624. RegisterAliveId(id);
  1625. return id;
  1626. }
  1627. bool ImGuiWindow::FocusItemRegister(bool is_active, bool tab_stop)
  1628. {
  1629. ImGuiState& g = *GImGui;
  1630. ImGuiWindow* window = GetCurrentWindow();
  1631. const bool allow_keyboard_focus = window->DC.AllowKeyboardFocus;
  1632. FocusIdxAllCounter++;
  1633. if (allow_keyboard_focus)
  1634. FocusIdxTabCounter++;
  1635. // Process keyboard input at this point: TAB, Shift-TAB switch focus
  1636. // We can always TAB out of a widget that doesn't allow tabbing in.
  1637. if (tab_stop && FocusIdxAllRequestNext == IM_INT_MAX && FocusIdxTabRequestNext == IM_INT_MAX && is_active && IsKeyPressedMap(ImGuiKey_Tab))
  1638. {
  1639. // Modulo on index will be applied at the end of frame once we've got the total counter of items.
  1640. FocusIdxTabRequestNext = FocusIdxTabCounter + (g.IO.KeyShift ? (allow_keyboard_focus ? -1 : 0) : +1);
  1641. }
  1642. if (FocusIdxAllCounter == FocusIdxAllRequestCurrent)
  1643. return true;
  1644. if (allow_keyboard_focus)
  1645. if (FocusIdxTabCounter == FocusIdxTabRequestCurrent)
  1646. return true;
  1647. return false;
  1648. }
  1649. void ImGuiWindow::FocusItemUnregister()
  1650. {
  1651. FocusIdxAllCounter--;
  1652. FocusIdxTabCounter--;
  1653. }
  1654. static inline void AddDrawListToRenderList(ImVector<ImDrawList*>& out_render_list, ImDrawList* draw_list)
  1655. {
  1656. if (!draw_list->commands.empty() && !draw_list->vtx_buffer.empty())
  1657. {
  1658. if (draw_list->commands.back().vtx_count == 0)
  1659. draw_list->commands.pop_back();
  1660. out_render_list.push_back(draw_list);
  1661. GImGui->IO.MetricsRenderVertices += (int)draw_list->vtx_buffer.size();
  1662. }
  1663. }
  1664. static void AddWindowToRenderList(ImVector<ImDrawList*>& out_render_list, ImGuiWindow* window)
  1665. {
  1666. AddDrawListToRenderList(out_render_list, window->DrawList);
  1667. for (size_t i = 0; i < window->DC.ChildWindows.size(); i++)
  1668. {
  1669. ImGuiWindow* child = window->DC.ChildWindows[i];
  1670. if (!child->Active) // clipped children may have been marked not active
  1671. continue;
  1672. if ((child->Flags & ImGuiWindowFlags_Popup) && child->HiddenFrames > 0)
  1673. continue;
  1674. AddWindowToRenderList(out_render_list, child);
  1675. }
  1676. }
  1677. //-----------------------------------------------------------------------------
  1678. void* ImGui::MemAlloc(size_t sz)
  1679. {
  1680. GImGui->IO.MetricsAllocs++;
  1681. return GImGui->IO.MemAllocFn(sz);
  1682. }
  1683. void ImGui::MemFree(void* ptr)
  1684. {
  1685. if (ptr) GImGui->IO.MetricsAllocs--;
  1686. return GImGui->IO.MemFreeFn(ptr);
  1687. }
  1688. static ImGuiIniData* FindWindowSettings(const char* name)
  1689. {
  1690. ImGuiState& g = *GImGui;
  1691. ImGuiID id = ImHash(name, 0);
  1692. for (size_t i = 0; i != g.Settings.size(); i++)
  1693. {
  1694. ImGuiIniData* ini = &g.Settings[i];
  1695. if (ini->ID == id)
  1696. return ini;
  1697. }
  1698. return NULL;
  1699. }
  1700. static ImGuiIniData* AddWindowSettings(const char* name)
  1701. {
  1702. GImGui->Settings.resize(GImGui->Settings.size() + 1);
  1703. ImGuiIniData* ini = &GImGui->Settings.back();
  1704. ini->Name = ImStrdup(name);
  1705. ini->ID = ImHash(name, 0);
  1706. ini->Collapsed = false;
  1707. ini->Pos = ImVec2(FLT_MAX,FLT_MAX);
  1708. ini->Size = ImVec2(0,0);
  1709. return ini;
  1710. }
  1711. // Zero-tolerance, poor-man .ini parsing
  1712. // FIXME: Write something less rubbish
  1713. static void LoadSettings()
  1714. {
  1715. ImGuiState& g = *GImGui;
  1716. const char* filename = g.IO.IniFilename;
  1717. if (!filename)
  1718. return;
  1719. char* file_data;
  1720. size_t file_size;
  1721. if (!ImLoadFileToMemory(filename, "rb", (void**)&file_data, &file_size, 1))
  1722. return;
  1723. ImGuiIniData* settings = NULL;
  1724. const char* buf_end = file_data + file_size;
  1725. for (const char* line_start = file_data; line_start < buf_end; )
  1726. {
  1727. const char* line_end = line_start;
  1728. while (line_end < buf_end && *line_end != '\n' && *line_end != '\r')
  1729. line_end++;
  1730. if (line_start[0] == '[' && line_end > line_start && line_end[-1] == ']')
  1731. {
  1732. char name[64];
  1733. ImFormatString(name, IM_ARRAYSIZE(name), "%.*s", line_end-line_start-2, line_start+1);
  1734. settings = FindWindowSettings(name);
  1735. if (!settings)
  1736. settings = AddWindowSettings(name);
  1737. }
  1738. else if (settings)
  1739. {
  1740. float x, y;
  1741. int i;
  1742. if (sscanf(line_start, "Pos=%f,%f", &x, &y) == 2)
  1743. settings->Pos = ImVec2(x, y);
  1744. else if (sscanf(line_start, "Size=%f,%f", &x, &y) == 2)
  1745. settings->Size = ImMax(ImVec2(x, y), g.Style.WindowMinSize);
  1746. else if (sscanf(line_start, "Collapsed=%d", &i) == 1)
  1747. settings->Collapsed = (i != 0);
  1748. }
  1749. line_start = line_end+1;
  1750. }
  1751. ImGui::MemFree(file_data);
  1752. }
  1753. static void SaveSettings()
  1754. {
  1755. ImGuiState& g = *GImGui;
  1756. const char* filename = g.IO.IniFilename;
  1757. if (!filename)
  1758. return;
  1759. // Gather data from windows that were active during this session
  1760. for (size_t i = 0; i != g.Windows.size(); i++)
  1761. {
  1762. ImGuiWindow* window = g.Windows[i];
  1763. if (window->Flags & ImGuiWindowFlags_NoSavedSettings)
  1764. continue;
  1765. ImGuiIniData* settings = FindWindowSettings(window->Name);
  1766. settings->Pos = window->Pos;
  1767. settings->Size = window->SizeFull;
  1768. settings->Collapsed = window->Collapsed;
  1769. }
  1770. // Write .ini file
  1771. // If a window wasn't opened in this session we preserve its settings
  1772. FILE* f = fopen(filename, "wt");
  1773. if (!f)
  1774. return;
  1775. for (size_t i = 0; i != g.Settings.size(); i++)
  1776. {
  1777. const ImGuiIniData* settings = &g.Settings[i];
  1778. if (settings->Pos.x == FLT_MAX)
  1779. continue;
  1780. const char* name = settings->Name;
  1781. if (const char* p = strstr(name, "###")) // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID()
  1782. name = p;
  1783. fprintf(f, "[%s]\n", name);
  1784. fprintf(f, "Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y);
  1785. fprintf(f, "Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y);
  1786. fprintf(f, "Collapsed=%d\n", settings->Collapsed);
  1787. fprintf(f, "\n");
  1788. }
  1789. fclose(f);
  1790. }
  1791. static void MarkSettingsDirty()
  1792. {
  1793. ImGuiState& g = *GImGui;
  1794. if (g.SettingsDirtyTimer <= 0.0f)
  1795. g.SettingsDirtyTimer = g.IO.IniSavingRate;
  1796. }
  1797. const char* ImGui::GetVersion()
  1798. {
  1799. return IMGUI_VERSION;
  1800. }
  1801. // Internal state access - if you want to share ImGui state between modules (e.g. DLL) or allocate it yourself
  1802. // Note that we still point to some static data and members (such as GFontAtlas), so the state instance you end up using will point to the static data within its module
  1803. void* ImGui::GetInternalState()
  1804. {
  1805. return GImGui;
  1806. }
  1807. size_t ImGui::GetInternalStateSize()
  1808. {
  1809. return sizeof(ImGuiState);
  1810. }
  1811. void ImGui::SetInternalState(void* state, bool construct)
  1812. {
  1813. if (construct)
  1814. new (state) ImGuiState();
  1815. GImGui = (ImGuiState*)state;
  1816. }
  1817. ImGuiIO& ImGui::GetIO()
  1818. {
  1819. return GImGui->IO;
  1820. }
  1821. ImGuiStyle& ImGui::GetStyle()
  1822. {
  1823. return GImGui->Style;
  1824. }
  1825. void ImGui::NewFrame()
  1826. {
  1827. ImGuiState& g = *GImGui;
  1828. // Check user data
  1829. IM_ASSERT(g.IO.DeltaTime > 0.0f);
  1830. IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f);
  1831. IM_ASSERT(g.IO.RenderDrawListsFn != NULL); // Must be implemented
  1832. IM_ASSERT(g.IO.Fonts->Fonts.size() > 0); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
  1833. IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded()); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
  1834. if (!g.Initialized)
  1835. {
  1836. // Initialize on first frame
  1837. g.LogClipboard = (ImGuiTextBuffer*)ImGui::MemAlloc(sizeof(ImGuiTextBuffer));
  1838. new(g.LogClipboard) ImGuiTextBuffer();
  1839. IM_ASSERT(g.Settings.empty());
  1840. LoadSettings();
  1841. g.Initialized = true;
  1842. }
  1843. SetFont(g.IO.Fonts->Fonts[0]);
  1844. g.Time += g.IO.DeltaTime;
  1845. g.FrameCount += 1;
  1846. g.Tooltip[0] = '\0';
  1847. // Update inputs state
  1848. if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
  1849. g.IO.MousePos = ImVec2(-9999.0f, -9999.0f);
  1850. 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
  1851. g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
  1852. else
  1853. g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
  1854. g.IO.MousePosPrev = g.IO.MousePos;
  1855. for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
  1856. {
  1857. g.IO.MouseDownDurationPrev[i] = g.IO.MouseDownDuration[i];
  1858. g.IO.MouseDownDuration[i] = g.IO.MouseDown[i] ? (g.IO.MouseDownDuration[i] < 0.0f ? 0.0f : g.IO.MouseDownDuration[i] + g.IO.DeltaTime) : -1.0f;
  1859. g.IO.MouseClicked[i] = g.IO.MouseDownDuration[i] == 0.0f;
  1860. g.IO.MouseReleased[i] = g.IO.MouseDownDurationPrev[i] >= 0.0f && !g.IO.MouseDown[i];
  1861. g.IO.MouseDoubleClicked[i] = false;
  1862. if (g.IO.MouseClicked[i])
  1863. {
  1864. if (g.Time - g.IO.MouseClickedTime[i] < g.IO.MouseDoubleClickTime)
  1865. {
  1866. if (ImLengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist)
  1867. g.IO.MouseDoubleClicked[i] = true;
  1868. g.IO.MouseClickedTime[i] = -FLT_MAX; // so the third click isn't turned into a double-click
  1869. }
  1870. else
  1871. {
  1872. g.IO.MouseClickedTime[i] = g.Time;
  1873. }
  1874. g.IO.MouseClickedPos[i] = g.IO.MousePos;
  1875. g.IO.MouseDragMaxDistanceSqr[i] = 0.0f;
  1876. }
  1877. else if (g.IO.MouseDown[i])
  1878. {
  1879. g.IO.MouseDragMaxDistanceSqr[i] = ImMax(g.IO.MouseDragMaxDistanceSqr[i], ImLengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]));
  1880. }
  1881. }
  1882. memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration));
  1883. for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
  1884. g.IO.KeysDownDuration[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownDuration[i] < 0.0f ? 0.0f : g.IO.KeysDownDuration[i] + g.IO.DeltaTime) : -1.0f;
  1885. // Calculate frame-rate for the user, as a purely luxurious feature
  1886. g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx];
  1887. g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx] = g.IO.DeltaTime;
  1888. g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % IM_ARRAYSIZE(g.FramerateSecPerFrame);
  1889. g.IO.Framerate = 1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame));
  1890. // Clear reference to active widget if the widget isn't alive anymore
  1891. g.HoveredIdPreviousFrame = g.HoveredId;
  1892. g.HoveredId = 0;
  1893. if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0)
  1894. SetActiveId(0);
  1895. g.ActiveIdPreviousFrame = g.ActiveId;
  1896. g.ActiveIdIsAlive = false;
  1897. g.ActiveIdIsJustActivated = false;
  1898. if (!g.ActiveId)
  1899. g.MovedWindow = NULL;
  1900. // Delay saving settings so we don't spam disk too much
  1901. if (g.SettingsDirtyTimer > 0.0f)
  1902. {
  1903. g.SettingsDirtyTimer -= g.IO.DeltaTime;
  1904. if (g.SettingsDirtyTimer <= 0.0f)
  1905. SaveSettings();
  1906. }
  1907. // Find the window we are hovering. Child windows can extend beyond the limit of their parent so we need to derive HoveredRootWindow from HoveredWindow
  1908. g.HoveredWindow = FindHoveredWindow(g.IO.MousePos, false);
  1909. if (g.HoveredWindow && (g.HoveredWindow->Flags & ImGuiWindowFlags_ChildWindow))
  1910. g.HoveredRootWindow = g.HoveredWindow->RootWindow;
  1911. else
  1912. g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true);
  1913. if (ImGuiWindow* modal_window = GetFrontMostModalRootWindow())
  1914. {
  1915. g.ModalWindowDarkeningRatio = ImMin(g.ModalWindowDarkeningRatio + g.IO.DeltaTime * 6.0f, 1.0f);
  1916. if (g.HoveredRootWindow != modal_window)
  1917. g.HoveredRootWindow = g.HoveredWindow = NULL;
  1918. }
  1919. else
  1920. {
  1921. g.ModalWindowDarkeningRatio = 0.0f;
  1922. }
  1923. // Are we using inputs? Tell user so they can capture/discard the inputs away from the rest of their application.
  1924. // When clicking outside of a window we assume the click is owned by the application and won't request capture.
  1925. int mouse_earliest_button_down = -1;
  1926. bool mouse_any_down = false;
  1927. for (int i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
  1928. {
  1929. if (g.IO.MouseClicked[i])
  1930. g.IO.MouseDownOwned[i] = (g.HoveredWindow != NULL) || (!g.OpenedPopupStack.empty());
  1931. mouse_any_down |= g.IO.MouseDown[i];
  1932. if (g.IO.MouseDown[i])
  1933. if (mouse_earliest_button_down == -1 || g.IO.MouseClickedTime[mouse_earliest_button_down] > g.IO.MouseClickedTime[i])
  1934. mouse_earliest_button_down = i;
  1935. }
  1936. bool mouse_owned_by_application = mouse_earliest_button_down != -1 && !g.IO.MouseDownOwned[mouse_earliest_button_down];
  1937. g.IO.WantCaptureMouse = (!mouse_owned_by_application && g.HoveredWindow != NULL) || (!mouse_owned_by_application && mouse_any_down) || (g.ActiveId != 0) || (!g.OpenedPopupStack.empty()) || (g.CaptureMouseNextFrame);
  1938. g.IO.WantCaptureKeyboard = (g.ActiveId != 0) || (g.CaptureKeyboardNextFrame);
  1939. g.MouseCursor = ImGuiMouseCursor_Arrow;
  1940. g.CaptureMouseNextFrame = g.CaptureKeyboardNextFrame = false;
  1941. // If mouse was first clicked outside of ImGui bounds we also cancel out hovering.
  1942. if (mouse_owned_by_application)
  1943. g.HoveredWindow = g.HoveredRootWindow = NULL;
  1944. // Scale & Scrolling
  1945. if (g.HoveredWindow && g.IO.MouseWheel != 0.0f && !g.HoveredWindow->Collapsed)
  1946. {
  1947. ImGuiWindow* window = g.HoveredWindow;
  1948. if (g.IO.KeyCtrl)
  1949. {
  1950. if (g.IO.FontAllowUserScaling)
  1951. {
  1952. // Zoom / Scale window
  1953. float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
  1954. float scale = new_font_scale / window->FontWindowScale;
  1955. window->FontWindowScale = new_font_scale;
  1956. const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
  1957. window->Pos += offset;
  1958. window->PosFloat += offset;
  1959. window->Size *= scale;
  1960. window->SizeFull *= scale;
  1961. }
  1962. }
  1963. else
  1964. {
  1965. // Scroll
  1966. if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse))
  1967. {
  1968. const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5;
  1969. SetWindowScrollY(window, window->ScrollY - g.IO.MouseWheel * window->CalcFontSize() * scroll_lines);
  1970. }
  1971. }
  1972. }
  1973. // Pressing TAB activate widget focus
  1974. // 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.
  1975. if (g.ActiveId == 0 && g.FocusedWindow != NULL && g.FocusedWindow->Active && IsKeyPressedMap(ImGuiKey_Tab, false))
  1976. {
  1977. g.FocusedWindow->FocusIdxTabRequestNext = 0;
  1978. }
  1979. // Mark all windows as not visible
  1980. for (size_t i = 0; i != g.Windows.size(); i++)
  1981. {
  1982. ImGuiWindow* window = g.Windows[i];
  1983. window->WasActive = window->Active;
  1984. window->Active = false;
  1985. window->Accessed = false;
  1986. }
  1987. // No window should be open at the beginning of the frame.
  1988. // But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear.
  1989. g.CurrentWindowStack.resize(0);
  1990. g.CurrentPopupStack.resize(0);
  1991. CloseInactivePopups();
  1992. // Create implicit window - we will only render it if the user has added something to it.
  1993. ImGui::SetNextWindowSize(ImVec2(400,400), ImGuiSetCond_FirstUseEver);
  1994. ImGui::Begin("Debug");
  1995. }
  1996. // NB: behavior of ImGui after Shutdown() is not tested/guaranteed at the moment. This function is merely here to free heap allocations.
  1997. void ImGui::Shutdown()
  1998. {
  1999. ImGuiState& g = *GImGui;
  2000. if (!g.Initialized)
  2001. return;
  2002. SaveSettings();
  2003. for (size_t i = 0; i < g.Windows.size(); i++)
  2004. {
  2005. g.Windows[i]->~ImGuiWindow();
  2006. ImGui::MemFree(g.Windows[i]);
  2007. }
  2008. g.Windows.clear();
  2009. g.WindowsSortBuffer.clear();
  2010. g.CurrentWindowStack.clear();
  2011. g.FocusedWindow = NULL;
  2012. g.HoveredWindow = NULL;
  2013. g.HoveredRootWindow = NULL;
  2014. for (size_t i = 0; i < g.Settings.size(); i++)
  2015. ImGui::MemFree(g.Settings[i].Name);
  2016. g.Settings.clear();
  2017. g.ColorModifiers.clear();
  2018. g.StyleModifiers.clear();
  2019. g.FontStack.clear();
  2020. g.OpenedPopupStack.clear();
  2021. g.CurrentPopupStack.clear();
  2022. for (size_t i = 0; i < IM_ARRAYSIZE(g.RenderDrawLists); i++)
  2023. g.RenderDrawLists[i].clear();
  2024. g.MouseCursorDrawList.ClearFreeMemory();
  2025. g.ColorEditModeStorage.Clear();
  2026. if (g.PrivateClipboard)
  2027. {
  2028. ImGui::MemFree(g.PrivateClipboard);
  2029. g.PrivateClipboard = NULL;
  2030. }
  2031. g.InputTextState.Text.clear();
  2032. g.InputTextState.InitialText.clear();
  2033. g.InputTextState.TempTextBuffer.clear();
  2034. if (g.LogFile && g.LogFile != stdout)
  2035. {
  2036. fclose(g.LogFile);
  2037. g.LogFile = NULL;
  2038. }
  2039. if (g.LogClipboard)
  2040. {
  2041. g.LogClipboard->~ImGuiTextBuffer();
  2042. ImGui::MemFree(g.LogClipboard);
  2043. }
  2044. if (g.IO.Fonts) // Testing for NULL to allow user to NULLify in case of running Shutdown() on multiple contexts. Bit hacky.
  2045. g.IO.Fonts->Clear();
  2046. g.Initialized = false;
  2047. }
  2048. // FIXME: Add a more explicit sort order in the window structure.
  2049. static int ChildWindowComparer(const void* lhs, const void* rhs)
  2050. {
  2051. const ImGuiWindow* a = *(const ImGuiWindow**)lhs;
  2052. const ImGuiWindow* b = *(const ImGuiWindow**)rhs;
  2053. if (int d = (a->Flags & ImGuiWindowFlags_Popup) - (b->Flags & ImGuiWindowFlags_Popup))
  2054. return d;
  2055. if (int d = (a->Flags & ImGuiWindowFlags_Tooltip) - (b->Flags & ImGuiWindowFlags_Tooltip))
  2056. return d;
  2057. if (int d = (a->Flags & ImGuiWindowFlags_ComboBox) - (b->Flags & ImGuiWindowFlags_ComboBox))
  2058. return d;
  2059. return 0;
  2060. }
  2061. static void AddWindowToSortedBuffer(ImVector<ImGuiWindow*>& out_sorted_windows, ImGuiWindow* window)
  2062. {
  2063. out_sorted_windows.push_back(window);
  2064. if (window->Active)
  2065. {
  2066. const size_t count = window->DC.ChildWindows.size();
  2067. if (count > 1)
  2068. qsort(window->DC.ChildWindows.begin(), count, sizeof(ImGuiWindow*), ChildWindowComparer);
  2069. for (size_t i = 0; i < count; i++)
  2070. {
  2071. ImGuiWindow* child = window->DC.ChildWindows[i];
  2072. if (child->Active)
  2073. AddWindowToSortedBuffer(out_sorted_windows, child);
  2074. }
  2075. }
  2076. }
  2077. static void PushClipRect(const ImVec4& clip_rect, bool clipped = true)
  2078. {
  2079. ImGuiWindow* window = GetCurrentWindow();
  2080. ImVec4 cr = clip_rect;
  2081. if (clipped && !window->ClipRectStack.empty())
  2082. {
  2083. // Clip with existing clip rect
  2084. const ImVec4 cur_cr = window->ClipRectStack.back();
  2085. 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));
  2086. }
  2087. cr.z = ImMax(cr.x, cr.z);
  2088. cr.w = ImMax(cr.y, cr.w);
  2089. IM_ASSERT(cr.x <= cr.z && cr.y <= cr.w);
  2090. window->ClipRectStack.push_back(cr);
  2091. window->DrawList->PushClipRect(cr);
  2092. }
  2093. static void PopClipRect()
  2094. {
  2095. ImGuiWindow* window = GetCurrentWindow();
  2096. window->ClipRectStack.pop_back();
  2097. window->DrawList->PopClipRect();
  2098. }
  2099. void ImGui::Render()
  2100. {
  2101. ImGuiState& g = *GImGui;
  2102. IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
  2103. const bool first_render_of_the_frame = (g.FrameCountRendered != g.FrameCount);
  2104. g.FrameCountRendered = g.FrameCount;
  2105. if (first_render_of_the_frame)
  2106. {
  2107. // Hide implicit "Debug" window if it hasn't been used
  2108. IM_ASSERT(g.CurrentWindowStack.size() == 1); // Mismatched Begin/End
  2109. if (g.CurrentWindow && !g.CurrentWindow->Accessed)
  2110. g.CurrentWindow->Active = false;
  2111. ImGui::End();
  2112. // Click to focus window and start moving (after we're done with all our widgets)
  2113. if (g.ActiveId == 0 && g.HoveredId == 0 && g.IO.MouseClicked[0])
  2114. {
  2115. if (!(g.FocusedWindow && !g.FocusedWindow->WasActive && g.FocusedWindow->Active)) // Unless we just made a popup appear
  2116. {
  2117. if (g.HoveredRootWindow != NULL)
  2118. {
  2119. IM_ASSERT(g.MovedWindow == NULL);
  2120. g.MovedWindow = g.HoveredWindow;
  2121. SetActiveId(g.HoveredRootWindow->MoveID, g.HoveredRootWindow);
  2122. }
  2123. else if (g.FocusedWindow != NULL && GetFrontMostModalRootWindow() == NULL)
  2124. {
  2125. // Clicking on void disable focus
  2126. FocusWindow(NULL);
  2127. }
  2128. }
  2129. }
  2130. // Sort the window list so that all child windows are after their parent
  2131. // We cannot do that on FocusWindow() because childs may not exist yet
  2132. g.WindowsSortBuffer.resize(0);
  2133. g.WindowsSortBuffer.reserve(g.Windows.size());
  2134. for (size_t i = 0; i != g.Windows.size(); i++)
  2135. {
  2136. ImGuiWindow* window = g.Windows[i];
  2137. if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is active its parent will add it
  2138. if (window->Active)
  2139. continue;
  2140. AddWindowToSortedBuffer(g.WindowsSortBuffer, window);
  2141. }
  2142. IM_ASSERT(g.Windows.size() == g.WindowsSortBuffer.size()); // we done something wrong
  2143. g.Windows.swap(g.WindowsSortBuffer);
  2144. // Clear Input data for next frame
  2145. g.IO.MouseWheel = 0.0f;
  2146. memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
  2147. }
  2148. // Skip render altogether if alpha is 0.0
  2149. // Note that vertex buffers have been created, so it is best practice that you don't create windows in the first place, or respond to Begin() returning false
  2150. if (g.Style.Alpha > 0.0f)
  2151. {
  2152. // Render tooltip
  2153. if (g.Tooltip[0])
  2154. {
  2155. ImGui::BeginTooltip();
  2156. ImGui::TextUnformatted(g.Tooltip);
  2157. ImGui::EndTooltip();
  2158. }
  2159. // Gather windows to render
  2160. g.IO.MetricsRenderVertices = 0;
  2161. g.IO.MetricsActiveWindows = 0;
  2162. for (size_t i = 0; i < IM_ARRAYSIZE(g.RenderDrawLists); i++)
  2163. g.RenderDrawLists[i].resize(0);
  2164. for (size_t i = 0; i != g.Windows.size(); i++)
  2165. {
  2166. ImGuiWindow* window = g.Windows[i];
  2167. if (window->Active && window->HiddenFrames <= 0 && (window->Flags & (ImGuiWindowFlags_ChildWindow)) == 0)
  2168. {
  2169. // FIXME: Generalize this with a proper layering system so we can stack.
  2170. g.IO.MetricsActiveWindows++;
  2171. if (window->Flags & ImGuiWindowFlags_Popup)
  2172. AddWindowToRenderList(g.RenderDrawLists[1], window);
  2173. else if (window->Flags & ImGuiWindowFlags_Tooltip)
  2174. AddWindowToRenderList(g.RenderDrawLists[2], window);
  2175. else
  2176. AddWindowToRenderList(g.RenderDrawLists[0], window);
  2177. }
  2178. }
  2179. // Flatten layers
  2180. size_t n = g.RenderDrawLists[0].size();
  2181. size_t flattened_size = n;
  2182. for (size_t i = 1; i < IM_ARRAYSIZE(g.RenderDrawLists); i++)
  2183. flattened_size += g.RenderDrawLists[i].size();
  2184. g.RenderDrawLists[0].resize(flattened_size);
  2185. for (size_t i = 1; i < IM_ARRAYSIZE(g.RenderDrawLists); i++)
  2186. {
  2187. ImVector<ImDrawList*>& layer = g.RenderDrawLists[i];
  2188. if (!layer.empty())
  2189. {
  2190. memcpy(&g.RenderDrawLists[0][n], &layer[0], layer.size() * sizeof(ImDrawList*));
  2191. n += layer.size();
  2192. }
  2193. }
  2194. if (g.IO.MouseDrawCursor)
  2195. {
  2196. const ImGuiMouseCursorData& cursor_data = g.MouseCursorData[g.MouseCursor];
  2197. const ImVec2 pos = g.IO.MousePos - cursor_data.Offset;
  2198. const ImVec2 size = cursor_data.Size;
  2199. const ImTextureID tex_id = g.IO.Fonts->TexID;
  2200. g.MouseCursorDrawList.Clear();
  2201. g.MouseCursorDrawList.PushTextureID(tex_id);
  2202. g.MouseCursorDrawList.AddImage(tex_id, pos+ImVec2(1,0), pos+ImVec2(1,0) + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], 0x30000000); // Shadow
  2203. g.MouseCursorDrawList.AddImage(tex_id, pos+ImVec2(2,0), pos+ImVec2(2,0) + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], 0x30000000); // Shadow
  2204. g.MouseCursorDrawList.AddImage(tex_id, pos, pos + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], 0xFF000000); // Black border
  2205. g.MouseCursorDrawList.AddImage(tex_id, pos, pos + size, cursor_data.TexUvMin[0], cursor_data.TexUvMax[0], 0xFFFFFFFF); // White fill
  2206. g.MouseCursorDrawList.PopTextureID();
  2207. AddDrawListToRenderList(g.RenderDrawLists[0], &g.MouseCursorDrawList);
  2208. }
  2209. // Render
  2210. if (!g.RenderDrawLists[0].empty())
  2211. g.IO.RenderDrawListsFn(&g.RenderDrawLists[0][0], (int)g.RenderDrawLists[0].size());
  2212. }
  2213. }
  2214. // Find the optional ## from which we stop displaying text.
  2215. static const char* FindTextDisplayEnd(const char* text, const char* text_end = NULL)
  2216. {
  2217. const char* text_display_end = text;
  2218. if (!text_end)
  2219. text_end = (const char*)-1;
  2220. ImGuiState& g = *GImGui;
  2221. if (g.DisableHideTextAfterDoubleHash > 0)
  2222. {
  2223. while (text_display_end < text_end && *text_display_end != '\0')
  2224. text_display_end++;
  2225. }
  2226. else
  2227. {
  2228. while (text_display_end < text_end && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#'))
  2229. text_display_end++;
  2230. }
  2231. return text_display_end;
  2232. }
  2233. // Pass text data straight to log (without being displayed)
  2234. void ImGui::LogText(const char* fmt, ...)
  2235. {
  2236. ImGuiState& g = *GImGui;
  2237. if (!g.LogEnabled)
  2238. return;
  2239. va_list args;
  2240. va_start(args, fmt);
  2241. if (g.LogFile)
  2242. {
  2243. vfprintf(g.LogFile, fmt, args);
  2244. }
  2245. else
  2246. {
  2247. g.LogClipboard->appendv(fmt, args);
  2248. }
  2249. va_end(args);
  2250. }
  2251. // Internal version that takes a position to decide on newline placement and pad items according to their depth.
  2252. // We split text into individual lines to add current tree level padding
  2253. static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end)
  2254. {
  2255. ImGuiState& g = *GImGui;
  2256. ImGuiWindow* window = GetCurrentWindow();
  2257. if (!text_end)
  2258. text_end = FindTextDisplayEnd(text, text_end);
  2259. const bool log_new_line = ref_pos.y > window->DC.LogLinePosY+1;
  2260. window->DC.LogLinePosY = ref_pos.y;
  2261. const char* text_remaining = text;
  2262. if (g.LogStartDepth > window->DC.TreeDepth) // Re-adjust padding if we have popped out of our starting depth
  2263. g.LogStartDepth = window->DC.TreeDepth;
  2264. const int tree_depth = (window->DC.TreeDepth - g.LogStartDepth);
  2265. for (;;)
  2266. {
  2267. // Split the string. Each new line (after a '\n') is followed by spacing corresponding to the current depth of our log entry.
  2268. const char* line_end = text_remaining;
  2269. while (line_end < text_end)
  2270. if (*line_end == '\n')
  2271. break;
  2272. else
  2273. line_end++;
  2274. if (line_end >= text_end)
  2275. line_end = NULL;
  2276. const bool is_first_line = (text == text_remaining);
  2277. bool is_last_line = false;
  2278. if (line_end == NULL)
  2279. {
  2280. is_last_line = true;
  2281. line_end = text_end;
  2282. }
  2283. if (line_end != NULL && !(is_last_line && (line_end - text_remaining)==0))
  2284. {
  2285. const int char_count = (int)(line_end - text_remaining);
  2286. if (log_new_line || !is_first_line)
  2287. ImGui::LogText(IM_NEWLINE "%*s%.*s", tree_depth*4, "", char_count, text_remaining);
  2288. else
  2289. ImGui::LogText(" %.*s", char_count, text_remaining);
  2290. }
  2291. if (is_last_line)
  2292. break;
  2293. text_remaining = line_end + 1;
  2294. }
  2295. }
  2296. static float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
  2297. {
  2298. if (wrap_pos_x < 0.0f)
  2299. return 0.0f;
  2300. ImGuiWindow* window = GetCurrentWindow();
  2301. if (wrap_pos_x == 0.0f)
  2302. wrap_pos_x = ImGui::GetContentRegionMax().x;
  2303. if (wrap_pos_x > 0.0f)
  2304. wrap_pos_x += window->Pos.x; // wrap_pos_x is provided is window local space
  2305. const float wrap_width = wrap_pos_x > 0.0f ? ImMax(wrap_pos_x - pos.x, 0.00001f) : 0.0f;
  2306. return wrap_width;
  2307. }
  2308. // Internal ImGui functions to render text
  2309. // RenderText***() functions calls ImDrawList::AddText() calls ImBitmapFont::RenderText()
  2310. static void RenderText(ImVec2 pos, const char* text, const char* text_end, bool hide_text_after_hash)
  2311. {
  2312. ImGuiState& g = *GImGui;
  2313. ImGuiWindow* window = GetCurrentWindow();
  2314. // Hide anything after a '##' string
  2315. const char* text_display_end;
  2316. if (hide_text_after_hash)
  2317. {
  2318. text_display_end = FindTextDisplayEnd(text, text_end);
  2319. }
  2320. else
  2321. {
  2322. if (!text_end)
  2323. text_end = text + strlen(text); // FIXME-OPT
  2324. text_display_end = text_end;
  2325. }
  2326. const int text_len = (int)(text_display_end - text);
  2327. if (text_len > 0)
  2328. {
  2329. // Render
  2330. window->DrawList->AddText(g.Font, g.FontSize, pos, window->Color(ImGuiCol_Text), text, text_display_end);
  2331. // Log as text
  2332. if (g.LogEnabled)
  2333. LogText(pos, text, text_display_end);
  2334. }
  2335. }
  2336. static void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width)
  2337. {
  2338. ImGuiState& g = *GImGui;
  2339. ImGuiWindow* window = GetCurrentWindow();
  2340. if (!text_end)
  2341. text_end = text + strlen(text); // FIXME-OPT
  2342. const int text_len = (int)(text_end - text);
  2343. if (text_len > 0)
  2344. {
  2345. window->DrawList->AddText(g.Font, g.FontSize, pos, window->Color(ImGuiCol_Text), text, text_end, wrap_width);
  2346. if (g.LogEnabled)
  2347. LogText(pos, text, text_end);
  2348. }
  2349. }
  2350. static void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, ImGuiAlign align, const ImVec2* clip_min, const ImVec2* clip_max)
  2351. {
  2352. // Hide anything after a '##' string
  2353. const char* text_display_end = FindTextDisplayEnd(text, text_end);
  2354. const int text_len = (int)(text_display_end - text);
  2355. if (text_len == 0)
  2356. return;
  2357. ImGuiState& g = *GImGui;
  2358. ImGuiWindow* window = GetCurrentWindow();
  2359. // Perform CPU side clipping for single clipped element to avoid using scissor state
  2360. ImVec2 pos = pos_min;
  2361. const ImVec2 text_size = text_size_if_known ? *text_size_if_known : ImGui::CalcTextSize(text, text_display_end, false, 0.0f);
  2362. if (!clip_max) clip_max = &pos_max;
  2363. bool need_clipping = (pos.x + text_size.x >= clip_max->x) || (pos.y + text_size.y >= clip_max->y);
  2364. if (!clip_min) clip_min = &pos_min; else need_clipping |= (pos.x < clip_min->x) || (pos.y < clip_min->y);
  2365. // Align
  2366. if (align & ImGuiAlign_Center) pos.x = ImMax(pos.x, (pos.x + pos_max.x - text_size.x) * 0.5f);
  2367. else if (align & ImGuiAlign_Right) pos.x = ImMax(pos.x, pos_max.x - text_size.x);
  2368. if (align & ImGuiAlign_VCenter) pos.y = ImMax(pos.y, (pos.y + pos_max.y - text_size.y) * 0.5f);
  2369. // Render
  2370. if (need_clipping)
  2371. {
  2372. ImVec4 fine_clip_rect(clip_min->x, clip_min->y, clip_max->x, clip_max->y);
  2373. window->DrawList->AddText(g.Font, g.FontSize, pos, window->Color(ImGuiCol_Text), text, text_display_end, 0.0f, &fine_clip_rect);
  2374. }
  2375. else
  2376. {
  2377. window->DrawList->AddText(g.Font, g.FontSize, pos, window->Color(ImGuiCol_Text), text, text_display_end, 0.0f, NULL);
  2378. }
  2379. if (g.LogEnabled)
  2380. LogText(pos, text, text_display_end);
  2381. }
  2382. // Render a rectangle shaped with optional rounding and borders
  2383. static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding)
  2384. {
  2385. ImGuiWindow* window = GetCurrentWindow();
  2386. window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding);
  2387. if (border && (window->Flags & ImGuiWindowFlags_ShowBorders))
  2388. {
  2389. // FIXME: This is the best I've found that works on multiple renderer/back ends. Bit dodgy.
  2390. window->DrawList->AddRect(p_min+ImVec2(1.5f,1.5f), p_max+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding);
  2391. window->DrawList->AddRect(p_min+ImVec2(0.5f,0.5f), p_max+ImVec2(0,0), window->Color(ImGuiCol_Border), rounding);
  2392. }
  2393. }
  2394. // Render a triangle to denote expanded/collapsed state
  2395. static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale, bool shadow)
  2396. {
  2397. ImGuiState& g = *GImGui;
  2398. ImGuiWindow* window = GetCurrentWindow();
  2399. const float h = g.FontSize * 1.00f;
  2400. const float r = h * 0.40f * scale;
  2401. ImVec2 center = p_min + ImVec2(h*0.50f, h*0.50f*scale);
  2402. ImVec2 a, b, c;
  2403. if (opened)
  2404. {
  2405. center.y -= r*0.25f;
  2406. a = center + ImVec2(0,1)*r;
  2407. b = center + ImVec2(-0.866f,-0.5f)*r;
  2408. c = center + ImVec2(0.866f,-0.5f)*r;
  2409. }
  2410. else
  2411. {
  2412. a = center + ImVec2(1,0)*r;
  2413. b = center + ImVec2(-0.500f,0.866f)*r;
  2414. c = center + ImVec2(-0.500f,-0.866f)*r;
  2415. }
  2416. if (shadow && (window->Flags & ImGuiWindowFlags_ShowBorders) != 0)
  2417. window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow));
  2418. window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Text));
  2419. }
  2420. static void RenderCheckMark(ImVec2 pos, ImU32 col)
  2421. {
  2422. ImGuiState& g = *GImGui;
  2423. ImGuiWindow* window = GetCurrentWindow();
  2424. ImVec2 a, b, c;
  2425. float start_x = (float)(int)(g.FontSize * 0.307f + 0.5f);
  2426. float rem_third = (float)(int)((g.FontSize - start_x) / 3.0f);
  2427. a.x = pos.x + start_x;
  2428. b.x = a.x + rem_third;
  2429. c.x = a.x + rem_third * 3.0f;
  2430. b.y = pos.y + (float)(int)(g.Font->Ascent * (g.FontSize / g.Font->FontSize) + 0.5f) + (float)(int)(g.Font->DisplayOffset.y);
  2431. a.y = b.y - rem_third;
  2432. c.y = b.y - rem_third * 2.0f;
  2433. window->DrawList->AddLine(a, b, col);
  2434. window->DrawList->AddLine(b, c, col);
  2435. }
  2436. // Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
  2437. // CalcTextSize("") should return ImVec2(0.0f, GImGui->FontSize)
  2438. ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width)
  2439. {
  2440. ImGuiState& g = *GImGui;
  2441. const char* text_display_end;
  2442. if (hide_text_after_double_hash)
  2443. text_display_end = FindTextDisplayEnd(text, text_end); // Hide anything after a '##' string
  2444. else
  2445. text_display_end = text_end;
  2446. ImFont* font = g.Font;
  2447. const float font_size = g.FontSize;
  2448. ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL);
  2449. // Cancel out character spacing for the last character of a line (it is baked into glyph->XAdvance field)
  2450. const float font_scale = font_size / font->FontSize;
  2451. const float character_spacing_x = 1.0f * font_scale;
  2452. if (text_size.x > 0.0f)
  2453. text_size.x -= character_spacing_x;
  2454. return text_size;
  2455. }
  2456. // Helper to calculate coarse clipping of large list of evenly sized items.
  2457. // NB: Prefer using the ImGuiListClipper higher-level helper if you can!
  2458. // If you are displaying thousands of items and you have a random access to the list, you can perform clipping yourself to save on CPU.
  2459. // {
  2460. // float item_height = ImGui::GetTextLineHeightWithSpacing();
  2461. // int display_start, display_end;
  2462. // ImGui::CalcListClipping(count, item_height, &display_start, &display_end); // calculate how many to clip/display
  2463. // ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (display_start) * item_height); // advance cursor
  2464. // for (int i = display_start; i < display_end; i++) // display only visible items
  2465. // // TODO: display visible item
  2466. // ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (count - display_end) * item_height); // advance cursor
  2467. // }
  2468. void ImGui::CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end)
  2469. {
  2470. ImGuiState& g = *GImGui;
  2471. ImGuiWindow* window = GetCurrentWindow();
  2472. if (g.LogEnabled)
  2473. {
  2474. // If logging is active, do not perform any clipping
  2475. *out_items_display_start = 0;
  2476. *out_items_display_end = items_count;
  2477. return;
  2478. }
  2479. const ImVec2 pos = window->DC.CursorPos;
  2480. const ImVec4 clip_rect = window->ClipRectStack.back();
  2481. const float clip_y1 = clip_rect.y;
  2482. const float clip_y2 = clip_rect.w;
  2483. int start = (int)((clip_y1 - pos.y) / items_height);
  2484. int end = (int)((clip_y2 - pos.y) / items_height);
  2485. start = ImClamp(start, 0, items_count);
  2486. end = ImClamp(end + 1, start, items_count);
  2487. *out_items_display_start = start;
  2488. *out_items_display_end = end;
  2489. }
  2490. // Find window given position, search front-to-back
  2491. static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs)
  2492. {
  2493. ImGuiState& g = *GImGui;
  2494. for (int i = (int)g.Windows.size()-1; i >= 0; i--)
  2495. {
  2496. ImGuiWindow* window = g.Windows[(size_t)i];
  2497. if (!window->Active)
  2498. continue;
  2499. if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
  2500. continue;
  2501. // Using the clipped AABB so a child window will typically be clipped by its parent.
  2502. ImRect bb(window->ClippedRect.Min - g.Style.TouchExtraPadding, window->ClippedRect.Max + g.Style.TouchExtraPadding);
  2503. if (bb.Contains(pos))
  2504. return window;
  2505. }
  2506. return NULL;
  2507. }
  2508. // Test if mouse cursor is hovering given rectangle
  2509. // NB- Rectangle is clipped by our current clip setting
  2510. // NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
  2511. static bool IsMouseHoveringRect(const ImRect& rect)
  2512. {
  2513. ImGuiState& g = *GImGui;
  2514. ImGuiWindow* window = GetCurrentWindow();
  2515. // Clip
  2516. ImRect rect_clipped = rect;
  2517. if (!window->ClipRectStack.empty())
  2518. {
  2519. const ImVec4 clip_rect = window->ClipRectStack.back();
  2520. rect_clipped.Clip(ImRect(ImVec2(clip_rect.x, clip_rect.y), ImVec2(clip_rect.z, clip_rect.w)));
  2521. }
  2522. // Expand for touch input
  2523. const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding);
  2524. return rect_for_touch.Contains(g.IO.MousePos);
  2525. }
  2526. bool ImGui::IsMouseHoveringRect(const ImVec2& rect_min, const ImVec2& rect_max)
  2527. {
  2528. return IsMouseHoveringRect(ImRect(rect_min, rect_max));
  2529. }
  2530. bool ImGui::IsMouseHoveringWindow()
  2531. {
  2532. ImGuiState& g = *GImGui;
  2533. ImGuiWindow* window = GetCurrentWindow();
  2534. return g.HoveredWindow == window;
  2535. }
  2536. bool ImGui::IsMouseHoveringAnyWindow()
  2537. {
  2538. ImGuiState& g = *GImGui;
  2539. return g.HoveredWindow != NULL;
  2540. }
  2541. bool ImGui::IsPosHoveringAnyWindow(const ImVec2& pos)
  2542. {
  2543. return FindHoveredWindow(pos, false) != NULL;
  2544. }
  2545. static bool IsKeyPressedMap(ImGuiKey key, bool repeat)
  2546. {
  2547. const int key_index = GImGui->IO.KeyMap[key];
  2548. return ImGui::IsKeyPressed(key_index, repeat);
  2549. }
  2550. int ImGui::GetKeyIndex(ImGuiKey key)
  2551. {
  2552. IM_ASSERT(key >= 0 && key < ImGuiKey_COUNT);
  2553. return GImGui->IO.KeyMap[key];
  2554. }
  2555. bool ImGui::IsKeyDown(int key_index)
  2556. {
  2557. if (key_index < 0) return false;
  2558. IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(GImGui->IO.KeysDown));
  2559. return GImGui->IO.KeysDown[key_index];
  2560. }
  2561. bool ImGui::IsKeyPressed(int key_index, bool repeat)
  2562. {
  2563. ImGuiState& g = *GImGui;
  2564. if (key_index < 0) return false;
  2565. IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
  2566. const float t = g.IO.KeysDownDuration[key_index];
  2567. if (t == 0.0f)
  2568. return true;
  2569. if (repeat && t > g.IO.KeyRepeatDelay)
  2570. {
  2571. float delay = g.IO.KeyRepeatDelay, rate = g.IO.KeyRepeatRate;
  2572. if ((fmodf(t - delay, rate) > rate*0.5f) != (fmodf(t - delay - g.IO.DeltaTime, rate) > rate*0.5f))
  2573. return true;
  2574. }
  2575. return false;
  2576. }
  2577. bool ImGui::IsKeyReleased(int key_index)
  2578. {
  2579. ImGuiState& g = *GImGui;
  2580. if (key_index < 0) return false;
  2581. IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
  2582. if (g.IO.KeysDownDurationPrev[key_index] >= 0.0f && !g.IO.KeysDown[key_index])
  2583. return true;
  2584. return false;
  2585. }
  2586. bool ImGui::IsMouseDown(int button)
  2587. {
  2588. ImGuiState& g = *GImGui;
  2589. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2590. return g.IO.MouseDown[button];
  2591. }
  2592. bool ImGui::IsMouseClicked(int button, bool repeat)
  2593. {
  2594. ImGuiState& g = *GImGui;
  2595. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2596. const float t = g.IO.MouseDownDuration[button];
  2597. if (t == 0.0f)
  2598. return true;
  2599. if (repeat && t > g.IO.KeyRepeatDelay)
  2600. {
  2601. float delay = g.IO.KeyRepeatDelay, rate = g.IO.KeyRepeatRate;
  2602. if ((fmodf(t - delay, rate) > rate*0.5f) != (fmodf(t - delay - g.IO.DeltaTime, rate) > rate*0.5f))
  2603. return true;
  2604. }
  2605. return false;
  2606. }
  2607. bool ImGui::IsMouseReleased(int button)
  2608. {
  2609. ImGuiState& g = *GImGui;
  2610. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2611. return g.IO.MouseReleased[button];
  2612. }
  2613. bool ImGui::IsMouseDoubleClicked(int button)
  2614. {
  2615. ImGuiState& g = *GImGui;
  2616. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2617. return g.IO.MouseDoubleClicked[button];
  2618. }
  2619. bool ImGui::IsMouseDragging(int button, float lock_threshold)
  2620. {
  2621. ImGuiState& g = *GImGui;
  2622. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2623. if (!g.IO.MouseDown[button])
  2624. return false;
  2625. if (lock_threshold < 0.0f)
  2626. lock_threshold = g.IO.MouseDragThreshold;
  2627. return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold;
  2628. }
  2629. ImVec2 ImGui::GetMousePos()
  2630. {
  2631. return GImGui->IO.MousePos;
  2632. }
  2633. ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold)
  2634. {
  2635. ImGuiState& g = *GImGui;
  2636. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2637. if (lock_threshold < 0.0f)
  2638. lock_threshold = g.IO.MouseDragThreshold;
  2639. if (g.IO.MouseDown[button])
  2640. if (g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold)
  2641. return g.IO.MousePos - g.IO.MouseClickedPos[button]; // Assume we can only get active with left-mouse button (at the moment).
  2642. return ImVec2(0.0f, 0.0f);
  2643. }
  2644. void ImGui::ResetMouseDragDelta(int button)
  2645. {
  2646. ImGuiState& g = *GImGui;
  2647. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  2648. // NB: We don't need to reset g.IO.MouseDragMaxDistanceSqr
  2649. g.IO.MouseClickedPos[button] = g.IO.MousePos;
  2650. }
  2651. ImGuiMouseCursor ImGui::GetMouseCursor()
  2652. {
  2653. return GImGui->MouseCursor;
  2654. }
  2655. void ImGui::SetMouseCursor(ImGuiMouseCursor cursor_type)
  2656. {
  2657. GImGui->MouseCursor = cursor_type;
  2658. }
  2659. void ImGui::CaptureKeyboardFromApp()
  2660. {
  2661. GImGui->CaptureKeyboardNextFrame = true;
  2662. }
  2663. void ImGui::CaptureMouseFromApp()
  2664. {
  2665. GImGui->CaptureMouseNextFrame = true;
  2666. }
  2667. bool ImGui::IsItemHovered()
  2668. {
  2669. ImGuiWindow* window = GetCurrentWindow();
  2670. return window->DC.LastItemHoveredAndUsable;
  2671. }
  2672. bool ImGui::IsItemHoveredRect()
  2673. {
  2674. ImGuiWindow* window = GetCurrentWindow();
  2675. return window->DC.LastItemHoveredRect;
  2676. }
  2677. bool ImGui::IsItemActive()
  2678. {
  2679. ImGuiState& g = *GImGui;
  2680. if (g.ActiveId)
  2681. {
  2682. ImGuiWindow* window = GetCurrentWindow();
  2683. return g.ActiveId == window->DC.LastItemID;
  2684. }
  2685. return false;
  2686. }
  2687. bool ImGui::IsAnyItemHovered()
  2688. {
  2689. return GImGui->HoveredId != 0 || GImGui->HoveredIdPreviousFrame != 0;
  2690. }
  2691. bool ImGui::IsAnyItemActive()
  2692. {
  2693. return GImGui->ActiveId != 0;
  2694. }
  2695. bool ImGui::IsItemVisible()
  2696. {
  2697. ImGuiWindow* window = GetCurrentWindow();
  2698. ImRect r(window->ClipRectStack.back());
  2699. return r.Overlaps(window->DC.LastItemRect);
  2700. }
  2701. ImVec2 ImGui::GetItemRectMin()
  2702. {
  2703. ImGuiWindow* window = GetCurrentWindow();
  2704. return window->DC.LastItemRect.Min;
  2705. }
  2706. ImVec2 ImGui::GetItemRectMax()
  2707. {
  2708. ImGuiWindow* window = GetCurrentWindow();
  2709. return window->DC.LastItemRect.Max;
  2710. }
  2711. ImVec2 ImGui::GetItemRectSize()
  2712. {
  2713. ImGuiWindow* window = GetCurrentWindow();
  2714. return window->DC.LastItemRect.GetSize();
  2715. }
  2716. ImVec2 ImGui::CalcItemRectClosestPoint(const ImVec2& pos, bool on_edge, float outward)
  2717. {
  2718. ImGuiWindow* window = GetCurrentWindow();
  2719. ImRect rect = window->DC.LastItemRect;
  2720. rect.Expand(outward);
  2721. return rect.GetClosestPoint(pos, on_edge);
  2722. }
  2723. // Tooltip is stored and turned into a BeginTooltip()/EndTooltip() sequence at the end of the frame. Each call override previous value.
  2724. void ImGui::SetTooltipV(const char* fmt, va_list args)
  2725. {
  2726. ImGuiState& g = *GImGui;
  2727. ImFormatStringV(g.Tooltip, IM_ARRAYSIZE(g.Tooltip), fmt, args);
  2728. }
  2729. void ImGui::SetTooltip(const char* fmt, ...)
  2730. {
  2731. va_list args;
  2732. va_start(args, fmt);
  2733. SetTooltipV(fmt, args);
  2734. va_end(args);
  2735. }
  2736. float ImGui::GetTime()
  2737. {
  2738. return GImGui->Time;
  2739. }
  2740. int ImGui::GetFrameCount()
  2741. {
  2742. return GImGui->FrameCount;
  2743. }
  2744. static ImVec4 GetVisibleRect()
  2745. {
  2746. ImGuiState& g = *GImGui;
  2747. if (g.IO.DisplayVisibleMin.x != g.IO.DisplayVisibleMax.x && g.IO.DisplayVisibleMin.y != g.IO.DisplayVisibleMax.y)
  2748. return ImVec4(g.IO.DisplayVisibleMin.x, g.IO.DisplayVisibleMin.y, g.IO.DisplayVisibleMax.x, g.IO.DisplayVisibleMax.y);
  2749. return ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y);
  2750. }
  2751. void ImGui::BeginTooltip()
  2752. {
  2753. ImGuiState& g = *GImGui;
  2754. ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize;
  2755. ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), g.Style.Colors[ImGuiCol_TooltipBg].w, flags);
  2756. }
  2757. void ImGui::EndTooltip()
  2758. {
  2759. IM_ASSERT(GetCurrentWindow()->Flags & ImGuiWindowFlags_Tooltip);
  2760. ImGui::End();
  2761. }
  2762. static bool IsPopupOpen(ImGuiID id)
  2763. {
  2764. ImGuiState& g = *GImGui;
  2765. const bool opened = g.OpenedPopupStack.size() > g.CurrentPopupStack.size() && g.OpenedPopupStack[g.CurrentPopupStack.size()].PopupID == id;
  2766. return opened;
  2767. }
  2768. // One open popup per level of the popup hierarchy (NB: when assigning we reset the Window member of ImGuiPopupRef to NULL)
  2769. void ImGui::OpenPopup(const char* str_id)
  2770. {
  2771. ImGuiState& g = *GImGui;
  2772. ImGuiWindow* window = GetCurrentWindow();
  2773. const ImGuiID id = window->GetID(str_id);
  2774. size_t current_stack_size = g.CurrentPopupStack.size();
  2775. ImGuiPopupRef popup_ref = ImGuiPopupRef(id, window, window->GetID("##menus")); // Tagged as new ref because constructor sets Window to NULL (we are passing the ParentWindow info here)
  2776. if (g.OpenedPopupStack.size() < current_stack_size + 1)
  2777. g.OpenedPopupStack.push_back(popup_ref);
  2778. else if (g.OpenedPopupStack[current_stack_size].PopupID != id)
  2779. {
  2780. g.OpenedPopupStack.resize(current_stack_size+1);
  2781. g.OpenedPopupStack[current_stack_size] = popup_ref;
  2782. }
  2783. }
  2784. static void CloseInactivePopups()
  2785. {
  2786. ImGuiState& g = *GImGui;
  2787. if (g.OpenedPopupStack.empty())
  2788. return;
  2789. // When popups are stacked, clicking on a lower level popups puts focus back to it and close popups above it
  2790. // Don't close our own child popup windows
  2791. int n = 0;
  2792. if (g.FocusedWindow)
  2793. {
  2794. for (n = 0; n < (int)g.OpenedPopupStack.size(); n++)
  2795. {
  2796. ImGuiPopupRef& popup = g.OpenedPopupStack[n];
  2797. if (!popup.Window)
  2798. continue;
  2799. IM_ASSERT((popup.Window->Flags & ImGuiWindowFlags_Popup) != 0);
  2800. if (popup.Window->Flags & ImGuiWindowFlags_ChildWindow)
  2801. {
  2802. if (g.FocusedWindow->RootWindow != popup.Window->RootWindow)
  2803. break;
  2804. }
  2805. else
  2806. {
  2807. bool has_focus = false;
  2808. for (int m = n; m < (int)g.OpenedPopupStack.size() && !has_focus; m++)
  2809. has_focus = (g.OpenedPopupStack[m].Window && g.OpenedPopupStack[m].Window->RootWindow == g.FocusedWindow->RootWindow);
  2810. if (!has_focus)
  2811. break;
  2812. }
  2813. }
  2814. }
  2815. g.OpenedPopupStack.resize(n);
  2816. }
  2817. static ImGuiWindow* GetFrontMostModalRootWindow()
  2818. {
  2819. ImGuiState& g = *GImGui;
  2820. if (!g.OpenedPopupStack.empty())
  2821. if (ImGuiWindow* front_most_popup = g.OpenedPopupStack.back().Window)
  2822. if (front_most_popup->Flags & ImGuiWindowFlags_Modal)
  2823. return front_most_popup;
  2824. return NULL;
  2825. }
  2826. static void ClosePopupToLevel(int remaining)
  2827. {
  2828. ImGuiState& g = *GImGui;
  2829. if (remaining > 0)
  2830. FocusWindow(g.OpenedPopupStack[remaining-1].Window);
  2831. else
  2832. FocusWindow(g.OpenedPopupStack[0].ParentWindow);
  2833. g.OpenedPopupStack.resize(remaining);
  2834. }
  2835. static void ClosePopup(ImGuiID id)
  2836. {
  2837. if (!IsPopupOpen(id))
  2838. return;
  2839. ImGuiState& g = *GImGui;
  2840. ClosePopupToLevel((int)g.OpenedPopupStack.size() - 1);
  2841. }
  2842. // Close the popup we have begin-ed into.
  2843. void ImGui::CloseCurrentPopup()
  2844. {
  2845. ImGuiState& g = *GImGui;
  2846. int popup_idx = (int)g.CurrentPopupStack.size() - 1;
  2847. if (popup_idx < 0 || popup_idx > (int)g.OpenedPopupStack.size() || g.CurrentPopupStack[popup_idx].PopupID != g.OpenedPopupStack[popup_idx].PopupID)
  2848. return;
  2849. while (popup_idx > 0 && g.OpenedPopupStack[popup_idx].Window && (g.OpenedPopupStack[popup_idx].Window->Flags & ImGuiWindowFlags_ChildMenu))
  2850. popup_idx--;
  2851. ClosePopupToLevel(popup_idx);
  2852. }
  2853. static void ClearSetNextWindowData()
  2854. {
  2855. ImGuiState& g = *GImGui;
  2856. g.SetNextWindowPosCond = g.SetNextWindowSizeCond = g.SetNextWindowCollapsedCond = g.SetNextWindowFocus = 0;
  2857. }
  2858. static bool BeginPopupEx(const char* str_id, ImGuiWindowFlags extra_flags)
  2859. {
  2860. ImGuiState& g = *GImGui;
  2861. ImGuiWindow* window = g.CurrentWindow;
  2862. const ImGuiID id = window->GetID(str_id);
  2863. if (!IsPopupOpen(id))
  2864. {
  2865. ClearSetNextWindowData(); // We behave like Begin() and need to consume those values
  2866. return false;
  2867. }
  2868. ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
  2869. ImGuiWindowFlags flags = extra_flags|ImGuiWindowFlags_Popup|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize;
  2870. char name[32];
  2871. if (flags & ImGuiWindowFlags_ChildMenu)
  2872. ImFormatString(name, 20, "##menu_%d", g.CurrentPopupStack.size()); // Recycle windows based on depth
  2873. else
  2874. ImFormatString(name, 20, "##popup_%08x", id); // Not recycling, so we can close/open during the same frame
  2875. float alpha = 1.0f;
  2876. bool opened = ImGui::Begin(name, NULL, ImVec2(0.0f, 0.0f), alpha, flags);
  2877. if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
  2878. GetCurrentWindow()->Flags &= ~ImGuiWindowFlags_ShowBorders;
  2879. if (!opened) // opened can be 'false' when the popup is completely clipped (e.g. zero size display)
  2880. ImGui::EndPopup();
  2881. return opened;
  2882. }
  2883. bool ImGui::BeginPopup(const char* str_id)
  2884. {
  2885. return BeginPopupEx(str_id, ImGuiWindowFlags_ShowBorders);
  2886. }
  2887. bool ImGui::BeginPopupModal(const char* name, bool* p_opened, ImGuiWindowFlags extra_flags)
  2888. {
  2889. ImGuiState& g = *GImGui;
  2890. ImGuiWindow* window = g.CurrentWindow;
  2891. const ImGuiID id = window->GetID(name);
  2892. if (!IsPopupOpen(id))
  2893. {
  2894. ClearSetNextWindowData(); // We behave like Begin() and need to consume those values
  2895. return false;
  2896. }
  2897. ImGuiWindowFlags flags = extra_flags|ImGuiWindowFlags_Popup|ImGuiWindowFlags_Modal|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoSavedSettings;
  2898. bool opened = ImGui::Begin(name, p_opened, ImVec2(0.0f, 0.0f), -1.0f, flags);
  2899. if (!opened || (p_opened && !*p_opened)) // Opened can be 'false' when the popup is completely clipped (e.g. zero size display)
  2900. {
  2901. ImGui::EndPopup();
  2902. if (opened)
  2903. ClosePopup(id);
  2904. return false;
  2905. }
  2906. return opened;
  2907. }
  2908. void ImGui::EndPopup()
  2909. {
  2910. ImGuiWindow* window = GetCurrentWindow();
  2911. IM_ASSERT(window->Flags & ImGuiWindowFlags_Popup);
  2912. IM_ASSERT(GImGui->CurrentPopupStack.size() > 0);
  2913. ImGui::End();
  2914. if (!(window->Flags & ImGuiWindowFlags_Modal))
  2915. ImGui::PopStyleVar();
  2916. }
  2917. bool ImGui::BeginPopupContextItem(const char* str_id, int mouse_button)
  2918. {
  2919. if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(mouse_button))
  2920. ImGui::OpenPopup(str_id);
  2921. return ImGui::BeginPopup(str_id);
  2922. }
  2923. bool ImGui::BeginPopupContextWindow(bool also_over_items, const char* str_id, int mouse_button)
  2924. {
  2925. if (!str_id) str_id = "window_context_menu";
  2926. if (ImGui::IsMouseHoveringWindow() && ImGui::IsMouseClicked(mouse_button))
  2927. if (also_over_items || !ImGui::IsAnyItemHovered())
  2928. ImGui::OpenPopup(str_id);
  2929. return ImGui::BeginPopup(str_id);
  2930. }
  2931. bool ImGui::BeginPopupContextVoid(const char* str_id, int mouse_button)
  2932. {
  2933. if (!str_id) str_id = "void_context_menu";
  2934. if (!ImGui::IsMouseHoveringAnyWindow() && ImGui::IsMouseClicked(mouse_button))
  2935. ImGui::OpenPopup(str_id);
  2936. return ImGui::BeginPopup(str_id);
  2937. }
  2938. bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags)
  2939. {
  2940. ImGuiWindow* window = GetCurrentWindow();
  2941. ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow;
  2942. const ImVec2 content_max = window->Pos + ImGui::GetContentRegionMax();
  2943. const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos();
  2944. ImVec2 size = size_arg;
  2945. if (size.x <= 0.0f)
  2946. {
  2947. if (size.x == 0.0f)
  2948. flags |= ImGuiWindowFlags_ChildWindowAutoFitX;
  2949. size.x = ImMax(content_max.x - cursor_pos.x, 4.0f) - fabsf(size.x); // Arbitrary minimum zeroish child size of 4.0f
  2950. }
  2951. if (size.y <= 0.0f)
  2952. {
  2953. if (size.y == 0.0f)
  2954. flags |= ImGuiWindowFlags_ChildWindowAutoFitY;
  2955. size.y = ImMax(content_max.y - cursor_pos.y, 4.0f) - fabsf(size.y);
  2956. }
  2957. if (border)
  2958. flags |= ImGuiWindowFlags_ShowBorders;
  2959. flags |= extra_flags;
  2960. char title[256];
  2961. ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s", window->Name, str_id);
  2962. const float alpha = 1.0f;
  2963. bool ret = ImGui::Begin(title, NULL, size, alpha, flags);
  2964. if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
  2965. GetCurrentWindow()->Flags &= ~ImGuiWindowFlags_ShowBorders;
  2966. return ret;
  2967. }
  2968. bool ImGui::BeginChild(ImGuiID id, const ImVec2& size, bool border, ImGuiWindowFlags extra_flags)
  2969. {
  2970. char str_id[32];
  2971. ImFormatString(str_id, IM_ARRAYSIZE(str_id), "child_%08x", id);
  2972. bool ret = ImGui::BeginChild(str_id, size, border, extra_flags);
  2973. return ret;
  2974. }
  2975. void ImGui::EndChild()
  2976. {
  2977. ImGuiWindow* window = GetCurrentWindow();
  2978. IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow);
  2979. if ((window->Flags & ImGuiWindowFlags_ComboBox) || window->BeginCount > 1)
  2980. {
  2981. ImGui::End();
  2982. }
  2983. else
  2984. {
  2985. // When using auto-filling child window, we don't provide full width/height to ItemSize so that it doesn't feed back into automatic size-fitting.
  2986. ImGuiState& g = *GImGui;
  2987. ImVec2 sz = ImGui::GetWindowSize();
  2988. if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitX) // Arbitrary minimum zeroish child size of 4.0f
  2989. sz.x = ImMax(4.0f, sz.x - g.Style.WindowPadding.x);
  2990. if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitY)
  2991. sz.y = ImMax(4.0f, sz.y - g.Style.WindowPadding.y);
  2992. ImGui::End();
  2993. window = GetCurrentWindow();
  2994. ImRect bb(window->DC.CursorPos, window->DC.CursorPos + sz);
  2995. ItemSize(sz);
  2996. ItemAdd(bb, NULL);
  2997. }
  2998. }
  2999. // Helper to create a child window / scrolling region that looks like a normal widget frame.
  3000. bool ImGui::BeginChildFrame(ImGuiID id, const ImVec2& size)
  3001. {
  3002. ImGuiState& g = *GImGui;
  3003. const ImGuiStyle& style = g.Style;
  3004. ImGui::PushStyleColor(ImGuiCol_ChildWindowBg, style.Colors[ImGuiCol_FrameBg]);
  3005. ImGui::PushStyleVar(ImGuiStyleVar_ChildWindowRounding, style.FrameRounding);
  3006. return ImGui::BeginChild(id, size);
  3007. }
  3008. void ImGui::EndChildFrame()
  3009. {
  3010. ImGui::EndChild();
  3011. ImGui::PopStyleVar();
  3012. ImGui::PopStyleColor();
  3013. }
  3014. // Save and compare stack sizes on Begin()/End() to detect usage errors
  3015. static void CheckStacksSize(ImGuiWindow* window, bool write)
  3016. {
  3017. // NOT checking: DC.ItemWidth, DC.AllowKeyboardFocus, DC.ButtonRepeat, DC.TextWrapPos (per window) to allow user to conveniently push once and not pop (they are cleared on Begin)
  3018. ImGuiState& g = *GImGui;
  3019. int* p_backup = &window->DC.StackSizesBackup[0];
  3020. { int current = (int)window->IDStack.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopID()
  3021. { int current = (int)window->DC.GroupStack.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot EndGroup()
  3022. { int current = (int)g.CurrentPopupStack.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot EndPopup()/EndMenu()
  3023. { int current = (int)g.ColorModifiers.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopStyleColor()
  3024. { int current = (int)g.StyleModifiers.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopStyleVar()
  3025. { int current = (int)g.FontStack.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopFont()
  3026. IM_ASSERT(p_backup == window->DC.StackSizesBackup + IM_ARRAYSIZE(window->DC.StackSizesBackup));
  3027. }
  3028. static ImVec2 FindBestPopupWindowPos(const ImVec2& base_pos, const ImVec2& size, ImGuiWindowFlags flags, int* last_dir, const ImRect& r_inner)
  3029. {
  3030. const ImGuiStyle& style = GImGui->Style;
  3031. // Clamp into visible area while not overlapping the cursor
  3032. ImRect r_outer(GetVisibleRect());
  3033. r_outer.Reduce(style.DisplaySafeAreaPadding);
  3034. ImVec2 base_pos_clamped = ImClamp(base_pos, r_outer.Min, r_outer.Max - size);
  3035. for (int n = (*last_dir != -1) ? -1 : 0; n < 4; n++) // Right, down, up, left. Favor last used direction.
  3036. {
  3037. const int dir = (n == -1) ? *last_dir : n;
  3038. ImRect rect(dir == 0 ? r_inner.Max.x : r_outer.Min.x, dir == 1 ? r_inner.Max.y : r_outer.Min.y, dir == 3 ? r_inner.Min.x : r_outer.Max.x, dir == 2 ? r_inner.Min.y : r_outer.Max.y);
  3039. if (rect.GetWidth() < size.x || rect.GetHeight() < size.y)
  3040. continue;
  3041. *last_dir = dir;
  3042. return ImVec2(dir == 0 ? r_inner.Max.x : dir == 3 ? r_inner.Min.x - size.x : base_pos_clamped.x, dir == 1 ? r_inner.Max.y : dir == 2 ? r_inner.Min.y - size.y : base_pos_clamped.y);
  3043. }
  3044. // Fallback
  3045. *last_dir = -1;
  3046. if (flags & ImGuiWindowFlags_Tooltip) // For tooltip we prefer avoiding the cursor at all cost even if it means that part of the tooltip won't be visible.
  3047. return base_pos + ImVec2(2,2);
  3048. // Otherwise try to keep within display
  3049. ImVec2 pos = base_pos;
  3050. pos.x = ImMax(ImMin(pos.x + size.x, r_outer.Max.x) - size.x, r_outer.Min.x);
  3051. pos.y = ImMax(ImMin(pos.y + size.y, r_outer.Max.y) - size.y, r_outer.Min.y);
  3052. return pos;
  3053. }
  3054. static ImGuiWindow* FindWindowByName(const char* name)
  3055. {
  3056. // FIXME-OPT: Store sorted hashes -> pointers.
  3057. ImGuiState& g = *GImGui;
  3058. ImGuiID id = ImHash(name, 0);
  3059. for (size_t i = 0; i < g.Windows.size(); i++)
  3060. if (g.Windows[i]->ID == id)
  3061. return g.Windows[i];
  3062. return NULL;
  3063. }
  3064. static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags)
  3065. {
  3066. ImGuiState& g = *GImGui;
  3067. // Create window the first time
  3068. ImGuiWindow* window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow));
  3069. new(window) ImGuiWindow(name);
  3070. window->Flags = flags;
  3071. if (flags & ImGuiWindowFlags_NoSavedSettings)
  3072. {
  3073. // User can disable loading and saving of settings. Tooltip and child windows also don't store settings.
  3074. window->Size = window->SizeFull = size;
  3075. }
  3076. else
  3077. {
  3078. // Retrieve settings from .ini file
  3079. // Use SetWindowPos() or SetNextWindowPos() with the appropriate condition flag to change the initial position of a window.
  3080. window->PosFloat = ImVec2(60, 60);
  3081. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  3082. ImGuiIniData* settings = FindWindowSettings(name);
  3083. if (!settings)
  3084. {
  3085. settings = AddWindowSettings(name);
  3086. }
  3087. else
  3088. {
  3089. window->SetWindowPosAllowFlags &= ~ImGuiSetCond_FirstUseEver;
  3090. window->SetWindowSizeAllowFlags &= ~ImGuiSetCond_FirstUseEver;
  3091. window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCond_FirstUseEver;
  3092. }
  3093. if (settings->Pos.x != FLT_MAX)
  3094. {
  3095. window->PosFloat = settings->Pos;
  3096. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  3097. window->Collapsed = settings->Collapsed;
  3098. }
  3099. if (ImLengthSqr(settings->Size) > 0.00001f && !(flags & ImGuiWindowFlags_NoResize))
  3100. size = settings->Size;
  3101. window->Size = window->SizeFull = size;
  3102. }
  3103. if ((flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
  3104. {
  3105. window->AutoFitFramesX = window->AutoFitFramesY = 2;
  3106. window->AutoFitOnlyGrows = false;
  3107. }
  3108. else
  3109. {
  3110. if (window->Size.x <= 0.0f)
  3111. window->AutoFitFramesX = 2;
  3112. if (window->Size.y <= 0.0f)
  3113. window->AutoFitFramesY = 2;
  3114. window->AutoFitOnlyGrows = (window->AutoFitFramesX > 0) || (window->AutoFitFramesY > 0);
  3115. }
  3116. g.Windows.push_back(window);
  3117. return window;
  3118. }
  3119. // Push a new ImGui window to add widgets to.
  3120. // - A default window called "Debug" is automatically stacked at the beginning of every frame so you can use widgets without explicitly calling a Begin/End pair.
  3121. // - Begin/End can be called multiple times during the frame with the same window name to append content.
  3122. // - 'size_on_first_use' for a regular window denote the initial size for first-time creation (no saved data) and isn't that useful. Use SetNextWindowSize() prior to calling Begin() for more flexible window manipulation.
  3123. // - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file).
  3124. // You can use the "##" or "###" markers to use the same label with different id, or same id with different label. See documentation at the top of this file.
  3125. // - Return false when window is collapsed, so you can early out in your code. You always need to call ImGui::End() even if false is returned.
  3126. // - Passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed.
  3127. // - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCond_FirstUseEver) prior to calling Begin().
  3128. bool ImGui::Begin(const char* name, bool* p_opened, ImGuiWindowFlags flags)
  3129. {
  3130. return ImGui::Begin(name, p_opened, ImVec2(0.f, 0.f), -1.0f, flags);
  3131. }
  3132. bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_use, float bg_alpha, ImGuiWindowFlags flags)
  3133. {
  3134. ImGuiState& g = *GImGui;
  3135. const ImGuiStyle& style = g.Style;
  3136. IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
  3137. IM_ASSERT(name != NULL); // Must pass a name
  3138. // Find or create
  3139. bool window_is_new = false;
  3140. ImGuiWindow* window = FindWindowByName(name);
  3141. if (!window)
  3142. {
  3143. window = CreateNewWindow(name, size_on_first_use, flags);
  3144. window_is_new = true;
  3145. }
  3146. window->Flags = (ImGuiWindowFlags)flags;
  3147. // Add to stack
  3148. ImGuiWindow* parent_window = !g.CurrentWindowStack.empty() ? g.CurrentWindowStack.back() : NULL;
  3149. g.CurrentWindowStack.push_back(window);
  3150. SetCurrentWindow(window);
  3151. CheckStacksSize(window, true);
  3152. IM_ASSERT(parent_window != NULL || !(flags & ImGuiWindowFlags_ChildWindow));
  3153. const int current_frame = ImGui::GetFrameCount();
  3154. bool window_was_visible = (window->LastFrameDrawn == current_frame - 1); // Not using !WasActive because the implicit "Debug" window would always toggle off->on
  3155. if (flags & ImGuiWindowFlags_Popup)
  3156. {
  3157. ImGuiPopupRef& popup_ref = g.OpenedPopupStack[g.CurrentPopupStack.size()];
  3158. window_was_visible &= (window->PopupID == popup_ref.PopupID);
  3159. window_was_visible &= (window == popup_ref.Window);
  3160. popup_ref.Window = window;
  3161. g.CurrentPopupStack.push_back(popup_ref);
  3162. window->PopupID = popup_ref.PopupID;
  3163. }
  3164. // Process SetNextWindow***() calls
  3165. bool window_pos_set_by_api = false, window_size_set_by_api = false;
  3166. if (g.SetNextWindowPosCond)
  3167. {
  3168. const ImVec2 backup_cursor_pos = window->DC.CursorPos; // FIXME: not sure of the exact reason of this anymore :( need to look into that.
  3169. if (!window_was_visible) window->SetWindowPosAllowFlags |= ImGuiSetCond_Appearing;
  3170. window_pos_set_by_api = (window->SetWindowPosAllowFlags & g.SetNextWindowPosCond) != 0;
  3171. if (window_pos_set_by_api && ImLengthSqr(g.SetNextWindowPosVal - ImVec2(-FLT_MAX,-FLT_MAX)) < 0.001f)
  3172. {
  3173. window->SetWindowPosCenterWanted = true; // May be processed on the next frame if this is our first frame and we are measuring size
  3174. window->SetWindowPosAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver | ImGuiSetCond_Appearing);
  3175. }
  3176. else
  3177. {
  3178. ImGui::SetWindowPos(g.SetNextWindowPosVal, g.SetNextWindowPosCond);
  3179. }
  3180. window->DC.CursorPos = backup_cursor_pos;
  3181. g.SetNextWindowPosCond = 0;
  3182. }
  3183. if (g.SetNextWindowSizeCond)
  3184. {
  3185. if (!window_was_visible) window->SetWindowSizeAllowFlags |= ImGuiSetCond_Appearing;
  3186. window_size_set_by_api = (window->SetWindowSizeAllowFlags & g.SetNextWindowSizeCond) != 0;
  3187. ImGui::SetWindowSize(g.SetNextWindowSizeVal, g.SetNextWindowSizeCond);
  3188. g.SetNextWindowSizeCond = 0;
  3189. }
  3190. if (g.SetNextWindowCollapsedCond)
  3191. {
  3192. if (!window_was_visible) window->SetWindowCollapsedAllowFlags |= ImGuiSetCond_Appearing;
  3193. ImGui::SetWindowCollapsed(g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond);
  3194. g.SetNextWindowCollapsedCond = 0;
  3195. }
  3196. if (g.SetNextWindowFocus)
  3197. {
  3198. ImGui::SetWindowFocus();
  3199. g.SetNextWindowFocus = false;
  3200. }
  3201. // Update known root window (if we are a child window, otherwise window == window->RootWindow)
  3202. size_t root_idx, root_non_popup_idx;
  3203. for (root_idx = g.CurrentWindowStack.size() - 1; root_idx > 0; root_idx--)
  3204. if (!(g.CurrentWindowStack[root_idx]->Flags & ImGuiWindowFlags_ChildWindow))
  3205. break;
  3206. for (root_non_popup_idx = root_idx; root_non_popup_idx > 0; root_non_popup_idx--)
  3207. if (!(g.CurrentWindowStack[root_non_popup_idx]->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup)))
  3208. break;
  3209. window->RootWindow = g.CurrentWindowStack[root_idx];
  3210. window->RootNonPopupWindow = g.CurrentWindowStack[root_non_popup_idx]; // This is merely for displaying the TitleBgActive color.
  3211. // Default alpha
  3212. if (bg_alpha < 0.0f)
  3213. bg_alpha = style.WindowFillAlphaDefault;
  3214. // When reusing window again multiple times a frame, just append content (don't need to setup again)
  3215. const bool first_begin_of_the_frame = (window->LastFrameDrawn != current_frame);
  3216. if (first_begin_of_the_frame)
  3217. {
  3218. window->Active = true;
  3219. window->BeginCount = 0;
  3220. window->DrawList->Clear();
  3221. window->ClipRectStack.resize(0);
  3222. window->LastFrameDrawn = current_frame;
  3223. window->IDStack.resize(1);
  3224. // Setup texture, outer clipping rectangle
  3225. window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID);
  3226. if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_ComboBox|ImGuiWindowFlags_Popup)))
  3227. PushClipRect(parent_window->ClipRectStack.back());
  3228. else
  3229. PushClipRect(GetVisibleRect());
  3230. // New windows appears in front
  3231. if (!window_was_visible)
  3232. {
  3233. window->AutoPosLastDirection = -1;
  3234. if (!(flags & (ImGuiWindowFlags_ChildWindow|ImGuiWindowFlags_Tooltip)) || (flags & ImGuiWindowFlags_Popup))
  3235. FocusWindow(window);
  3236. // Popup first latch mouse position, will position itself when it appears next frame
  3237. if ((flags & ImGuiWindowFlags_Popup) != 0 && !window_pos_set_by_api)
  3238. window->PosFloat = g.IO.MousePos;
  3239. }
  3240. // Collapse window by double-clicking on title bar
  3241. // At this point we don't have a clipping rectangle setup yet, so we can use the title bar area for hit detection and drawing
  3242. if (!(flags & ImGuiWindowFlags_NoTitleBar) && !(flags & ImGuiWindowFlags_NoCollapse))
  3243. {
  3244. if (g.HoveredWindow == window && IsMouseHoveringRect(window->TitleBarRect()) && g.IO.MouseDoubleClicked[0])
  3245. {
  3246. window->Collapsed = !window->Collapsed;
  3247. if (!(flags & ImGuiWindowFlags_NoSavedSettings))
  3248. MarkSettingsDirty();
  3249. FocusWindow(window);
  3250. }
  3251. }
  3252. else
  3253. {
  3254. window->Collapsed = false;
  3255. }
  3256. const bool window_appearing_after_being_hidden = (window->HiddenFrames == 1);
  3257. if (window->HiddenFrames > 0)
  3258. window->HiddenFrames--;
  3259. // SIZE
  3260. // Save contents size from last frame for auto-fitting
  3261. window->SizeContents = window_is_new ? ImVec2(0.0f, 0.0f) : window->DC.CursorMaxPos - window->Pos;
  3262. window->SizeContents.y += window->ScrollY;
  3263. // Hide popup/tooltip window when first appearing while we measure size (because we recycle them)
  3264. if ((flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) != 0 && !window_was_visible)
  3265. {
  3266. window->HiddenFrames = 1;
  3267. if (flags & ImGuiWindowFlags_AlwaysAutoResize)
  3268. {
  3269. if (!window_size_set_by_api)
  3270. window->Size = window->SizeFull = ImVec2(0.f, 0.f);
  3271. window->SizeContents = ImVec2(0.f, 0.f);
  3272. }
  3273. }
  3274. // Lock window padding so that altering the ShowBorders flag for childs doesn't have side-effects.
  3275. window->WindowPadding = ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_ShowBorders | ImGuiWindowFlags_ComboBox | ImGuiWindowFlags_Popup))) ? ImVec2(0,0) : style.WindowPadding;
  3276. // Calculate auto-fit size
  3277. ImVec2 size_auto_fit;
  3278. if ((flags & ImGuiWindowFlags_Tooltip) != 0)
  3279. {
  3280. // Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose.
  3281. size_auto_fit = window->SizeContents + window->WindowPadding - ImVec2(0.0f, style.ItemSpacing.y);
  3282. }
  3283. else
  3284. {
  3285. size_auto_fit = ImClamp(window->SizeContents + window->WindowPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - window->WindowPadding));
  3286. if (size_auto_fit.y < window->SizeContents.y && !(flags & ImGuiWindowFlags_NoScrollbar))
  3287. size_auto_fit.x += style.ScrollbarWidth;
  3288. size_auto_fit.y = ImMax(size_auto_fit.y - style.ItemSpacing.y, 0.0f);
  3289. }
  3290. // Handle automatic resize
  3291. if (window->Collapsed)
  3292. {
  3293. // We still process initial auto-fit on collapsed windows to get a window width,
  3294. // But otherwise we don't honor ImGuiWindowFlags_AlwaysAutoResize when collapsed.
  3295. if (window->AutoFitFramesX > 0)
  3296. window->SizeFull.x = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.x, size_auto_fit.x) : size_auto_fit.x;
  3297. if (window->AutoFitFramesY > 0)
  3298. window->SizeFull.y = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.y, size_auto_fit.y) : size_auto_fit.y;
  3299. window->Size = window->TitleBarRect().GetSize();
  3300. }
  3301. else
  3302. {
  3303. if ((flags & ImGuiWindowFlags_AlwaysAutoResize) && !window_size_set_by_api)
  3304. {
  3305. window->SizeFull = size_auto_fit;
  3306. }
  3307. else if ((window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0) && !window_size_set_by_api)
  3308. {
  3309. // Auto-fit only grows during the first few frames
  3310. if (window->AutoFitFramesX > 0)
  3311. window->SizeFull.x = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.x, size_auto_fit.x) : size_auto_fit.x;
  3312. if (window->AutoFitFramesY > 0)
  3313. window->SizeFull.y = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.y, size_auto_fit.y) : size_auto_fit.y;
  3314. if (!(flags & ImGuiWindowFlags_NoSavedSettings))
  3315. MarkSettingsDirty();
  3316. }
  3317. window->Size = window->SizeFull;
  3318. }
  3319. // Minimum window size
  3320. if (!(flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysAutoResize)))
  3321. {
  3322. window->SizeFull = ImMax(window->SizeFull, style.WindowMinSize);
  3323. if (!window->Collapsed)
  3324. window->Size = window->SizeFull;
  3325. }
  3326. // POSITION
  3327. // Position child window
  3328. if (flags & ImGuiWindowFlags_ChildWindow)
  3329. parent_window->DC.ChildWindows.push_back(window);
  3330. if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup))
  3331. {
  3332. window->Pos = window->PosFloat = parent_window->DC.CursorPos;
  3333. window->Size = window->SizeFull = size_on_first_use; // NB: argument name 'size_on_first_use' misleading here, it's really just 'size' as provided by user.
  3334. }
  3335. bool window_pos_center = false;
  3336. window_pos_center |= (window->SetWindowPosCenterWanted && window->HiddenFrames == 0);
  3337. window_pos_center |= ((flags & ImGuiWindowFlags_Modal) && !window_pos_set_by_api && window_appearing_after_being_hidden);
  3338. if (window_pos_center)
  3339. {
  3340. // Center (any sort of window)
  3341. ImRect fullscreen_rect(GetVisibleRect());
  3342. SetWindowPos(ImMax(style.DisplaySafeAreaPadding, fullscreen_rect.GetCenter() - window->SizeFull * 0.5f));
  3343. }
  3344. else if (flags & ImGuiWindowFlags_ChildMenu)
  3345. {
  3346. IM_ASSERT(window_pos_set_by_api);
  3347. ImRect rect_to_avoid;
  3348. if (parent_window->DC.MenuBarAppending)
  3349. rect_to_avoid = ImRect(-FLT_MAX, parent_window->Pos.y + parent_window->TitleBarHeight(), FLT_MAX, parent_window->Pos.y + parent_window->TitleBarHeight() + parent_window->MenuBarHeight());
  3350. else
  3351. rect_to_avoid = ImRect(parent_window->Pos.x + style.ItemSpacing.x, -FLT_MAX, parent_window->Pos.x + parent_window->Size.x - style.ItemSpacing.x - parent_window->ScrollbarWidth(), FLT_MAX); // We want some overlap to convey the relative depth of each popup (here hard-coded to 4)
  3352. window->PosFloat = FindBestPopupWindowPos(window->PosFloat, window->Size, flags, &window->AutoPosLastDirection, rect_to_avoid);
  3353. }
  3354. else if ((flags & ImGuiWindowFlags_Popup) != 0 && !window_pos_set_by_api && window_appearing_after_being_hidden)
  3355. {
  3356. ImRect rect_to_avoid(window->PosFloat.x - 1, window->PosFloat.y - 1, window->PosFloat.x + 1, window->PosFloat.y + 1);
  3357. window->PosFloat = FindBestPopupWindowPos(window->PosFloat, window->Size, flags, &window->AutoPosLastDirection, rect_to_avoid);
  3358. }
  3359. // Position tooltip (always follows mouse)
  3360. if ((flags & ImGuiWindowFlags_Tooltip) != 0 && !window_pos_set_by_api)
  3361. {
  3362. ImRect rect_to_avoid(g.IO.MousePos.x - 16, g.IO.MousePos.y - 8, g.IO.MousePos.x + 24, g.IO.MousePos.y + 24); // FIXME: Completely hard-coded. Perhaps center on cursor hit-point instead?
  3363. window->PosFloat = FindBestPopupWindowPos(g.IO.MousePos, window->Size, flags, &window->AutoPosLastDirection, rect_to_avoid);
  3364. }
  3365. // User moving window (at the beginning of the frame to avoid input lag or sheering). Only valid for root windows.
  3366. RegisterAliveId(window->MoveID);
  3367. if (g.ActiveId == window->MoveID)
  3368. {
  3369. if (g.IO.MouseDown[0])
  3370. {
  3371. if (!(flags & ImGuiWindowFlags_NoMove))
  3372. {
  3373. window->PosFloat += g.IO.MouseDelta;
  3374. if (!(flags & ImGuiWindowFlags_NoSavedSettings))
  3375. MarkSettingsDirty();
  3376. }
  3377. IM_ASSERT(g.MovedWindow != NULL);
  3378. FocusWindow(g.MovedWindow);
  3379. }
  3380. else
  3381. {
  3382. SetActiveId(0);
  3383. g.MovedWindow = NULL; // Not strictly necessary but doing it for sanity.
  3384. }
  3385. }
  3386. // Clamp position so it stays visible
  3387. if (!(flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Tooltip))
  3388. {
  3389. if (!window_pos_set_by_api && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing.
  3390. {
  3391. ImVec2 padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding);
  3392. window->PosFloat = ImMax(window->PosFloat + window->Size, padding) - window->Size;
  3393. window->PosFloat = ImMin(window->PosFloat, g.IO.DisplaySize - padding);
  3394. }
  3395. }
  3396. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  3397. // Default item width. Make it proportional to window size if window manually resizes
  3398. if (window->Size.x > 0.0f && !(flags & ImGuiWindowFlags_Tooltip) && !(flags & ImGuiWindowFlags_AlwaysAutoResize))
  3399. window->ItemWidthDefault = (float)(int)(window->Size.x * 0.65f);
  3400. else
  3401. window->ItemWidthDefault = (float)(int)(g.FontSize * 16.0f);
  3402. // Prepare for focus requests
  3403. window->FocusIdxAllRequestCurrent = (window->FocusIdxAllRequestNext == IM_INT_MAX || window->FocusIdxAllCounter == -1) ? IM_INT_MAX : (window->FocusIdxAllRequestNext + (window->FocusIdxAllCounter+1)) % (window->FocusIdxAllCounter+1);
  3404. window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext == IM_INT_MAX || window->FocusIdxTabCounter == -1) ? IM_INT_MAX : (window->FocusIdxTabRequestNext + (window->FocusIdxTabCounter+1)) % (window->FocusIdxTabCounter+1);
  3405. window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1;
  3406. window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = IM_INT_MAX;
  3407. // Apply scrolling
  3408. if (window->ScrollTargetRelY < FLT_MAX)
  3409. {
  3410. float center_ratio_y = window->ScrollTargetCenterRatioY;
  3411. window->ScrollY = window->ScrollTargetRelY - ((1.0f - center_ratio_y) * window->TitleBarHeight()) - (center_ratio_y * window->SizeFull.y);
  3412. window->ScrollTargetRelY = FLT_MAX;
  3413. }
  3414. window->ScrollY = ImMax(window->ScrollY, 0.0f);
  3415. if (!window->Collapsed && !window->SkipItems)
  3416. window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, window->SizeContents.y - window->SizeFull.y));
  3417. // Modal window darkens what is behind them
  3418. if ((flags & ImGuiWindowFlags_Modal) != 0 && window == GetFrontMostModalRootWindow())
  3419. {
  3420. ImRect fullscreen_rect = GetVisibleRect();
  3421. window->DrawList->AddRectFilled(fullscreen_rect.Min, fullscreen_rect.Max, window->Color(ImGuiCol_ModalWindowDarkening, g.ModalWindowDarkeningRatio));
  3422. }
  3423. // Draw window + handle manual resize
  3424. ImRect title_bar_rect = window->TitleBarRect();
  3425. const float window_rounding = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildWindowRounding : style.WindowRounding;
  3426. if (window->Collapsed)
  3427. {
  3428. // Draw title bar only
  3429. window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), window_rounding);
  3430. if (flags & ImGuiWindowFlags_ShowBorders)
  3431. {
  3432. window->DrawList->AddRect(title_bar_rect.GetTL()+ImVec2(1,1), title_bar_rect.GetBR()+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), window_rounding);
  3433. window->DrawList->AddRect(title_bar_rect.GetTL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_Border), window_rounding);
  3434. }
  3435. }
  3436. else
  3437. {
  3438. ImU32 resize_col = 0;
  3439. if (!(flags & ImGuiWindowFlags_AlwaysAutoResize) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && !(flags & ImGuiWindowFlags_NoResize))
  3440. {
  3441. // Manual resize
  3442. const ImRect resize_rect(window->Rect().GetBR()-ImVec2(14,14), window->Rect().GetBR());
  3443. const ImGuiID resize_id = window->GetID("#RESIZE");
  3444. bool hovered, held;
  3445. ButtonBehavior(resize_rect, resize_id, &hovered, &held, true, ImGuiButtonFlags_FlattenChilds);
  3446. resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
  3447. if (hovered || held)
  3448. g.MouseCursor = ImGuiMouseCursor_ResizeNWSE;
  3449. if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0])
  3450. {
  3451. // Manual auto-fit when double-clicking
  3452. window->SizeFull = size_auto_fit;
  3453. if (!(flags & ImGuiWindowFlags_NoSavedSettings))
  3454. MarkSettingsDirty();
  3455. SetActiveId(0);
  3456. }
  3457. else if (held)
  3458. {
  3459. window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize);
  3460. if (!(flags & ImGuiWindowFlags_NoSavedSettings))
  3461. MarkSettingsDirty();
  3462. }
  3463. window->Size = window->SizeFull;
  3464. title_bar_rect = window->TitleBarRect();
  3465. }
  3466. // Scrollbar
  3467. window->ScrollbarY = (window->SizeContents.y > window->Size.y + style.ItemSpacing.y) && !(flags & ImGuiWindowFlags_NoScrollbar);
  3468. // Window background
  3469. if (bg_alpha > 0.0f)
  3470. {
  3471. if ((flags & ImGuiWindowFlags_ComboBox) != 0)
  3472. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, bg_alpha), window_rounding);
  3473. else if ((flags & ImGuiWindowFlags_Tooltip) != 0)
  3474. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_TooltipBg, bg_alpha), window_rounding);
  3475. else if ((flags & ImGuiWindowFlags_Popup) != 0)
  3476. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, bg_alpha), window_rounding);
  3477. else if ((flags & ImGuiWindowFlags_ChildWindow) != 0)
  3478. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size-ImVec2(window->ScrollbarWidth(),0.0f), window->Color(ImGuiCol_ChildWindowBg, bg_alpha), window_rounding, window->ScrollbarY ? (1|8) : (0xF));
  3479. else
  3480. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, bg_alpha), window_rounding);
  3481. }
  3482. // Title bar
  3483. if (!(flags & ImGuiWindowFlags_NoTitleBar))
  3484. window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), window->Color((g.FocusedWindow && window->RootNonPopupWindow == g.FocusedWindow->RootNonPopupWindow) ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg), window_rounding, 1|2);
  3485. // Menu bar
  3486. if (flags & ImGuiWindowFlags_MenuBar)
  3487. {
  3488. ImRect menu_bar_rect = window->MenuBarRect();
  3489. window->DrawList->AddRectFilled(menu_bar_rect.GetTL(), menu_bar_rect.GetBR(), window->Color(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, 1|2);
  3490. }
  3491. // Borders
  3492. if (flags & ImGuiWindowFlags_ShowBorders)
  3493. {
  3494. window->DrawList->AddRect(window->Pos+ImVec2(1,1), window->Pos+window->Size+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), window_rounding);
  3495. window->DrawList->AddRect(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_Border), window_rounding);
  3496. if (!(flags & ImGuiWindowFlags_NoTitleBar))
  3497. window->DrawList->AddLine(title_bar_rect.GetBL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_Border));
  3498. }
  3499. // Scrollbar
  3500. if (window->ScrollbarY)
  3501. Scrollbar(window);
  3502. // Render resize grip
  3503. // (after the input handling so we don't have a frame of latency)
  3504. if (!(flags & ImGuiWindowFlags_NoResize))
  3505. {
  3506. const float r = window_rounding;
  3507. const ImVec2 br = window->Rect().GetBR();
  3508. if (r == 0.0f)
  3509. {
  3510. window->DrawList->AddTriangleFilled(br, br-ImVec2(0,14), br-ImVec2(14,0), resize_col);
  3511. }
  3512. else
  3513. {
  3514. // FIXME: We should draw 4 triangles and decide on a size that's not dependent on the rounding size (previously used 18)
  3515. window->DrawList->AddArcFast(br - ImVec2(r,r), r, resize_col, 6, 9, true);
  3516. window->DrawList->AddTriangleFilled(br+ImVec2(0,-2*r),br+ImVec2(0,-r),br+ImVec2(-r,-r), resize_col);
  3517. window->DrawList->AddTriangleFilled(br+ImVec2(-r,-r), br+ImVec2(-r,0),br+ImVec2(-2*r,0), resize_col);
  3518. }
  3519. }
  3520. }
  3521. // Setup drawing context
  3522. window->DC.ColumnsStartX = window->WindowPadding.x;
  3523. window->DC.ColumnsOffsetX = 0.0f;
  3524. window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.ColumnsStartX + window->DC.ColumnsOffsetX, window->TitleBarHeight() + window->MenuBarHeight() + window->WindowPadding.y) - ImVec2(0.0f, window->ScrollY);
  3525. window->DC.CursorPos = window->DC.CursorStartPos;
  3526. window->DC.CursorPosPrevLine = window->DC.CursorPos;
  3527. window->DC.CursorMaxPos = window->DC.CursorStartPos;
  3528. window->DC.CurrentLineHeight = window->DC.PrevLineHeight = 0.0f;
  3529. window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f;
  3530. window->DC.MenuBarAppending = false;
  3531. window->DC.MenuBarOffsetX = ImMax(window->DC.ColumnsStartX, style.ItemSpacing.x);
  3532. window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f;
  3533. window->DC.ChildWindows.resize(0);
  3534. window->DC.LayoutType = ImGuiLayoutType_Vertical;
  3535. window->DC.ItemWidth = window->ItemWidthDefault;
  3536. window->DC.ItemWidthStack.resize(0);
  3537. window->DC.ButtonRepeat = false;
  3538. window->DC.ButtonRepeatStack.resize(0);
  3539. window->DC.AllowKeyboardFocus = true;
  3540. window->DC.AllowKeyboardFocusStack.resize(0);
  3541. window->DC.TextWrapPos = -1.0f; // disabled
  3542. window->DC.TextWrapPosStack.resize(0);
  3543. window->DC.ColorEditMode = ImGuiColorEditMode_UserSelect;
  3544. window->DC.ColumnsCurrent = 0;
  3545. window->DC.ColumnsCount = 1;
  3546. window->DC.ColumnsStartPos = window->DC.CursorPos;
  3547. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.ColumnsStartPos.y;
  3548. window->DC.TreeDepth = 0;
  3549. window->DC.StateStorage = &window->StateStorage;
  3550. window->DC.GroupStack.resize(0);
  3551. window->MenuColumns.Update(3, style.ItemSpacing.x, !window_was_visible);
  3552. if (window->AutoFitFramesX > 0)
  3553. window->AutoFitFramesX--;
  3554. if (window->AutoFitFramesY > 0)
  3555. window->AutoFitFramesY--;
  3556. // Title bar
  3557. if (!(flags & ImGuiWindowFlags_NoTitleBar))
  3558. {
  3559. if (p_opened != NULL)
  3560. CloseWindowButton(p_opened);
  3561. const ImVec2 text_size = CalcTextSize(name, NULL, true);
  3562. if (!(flags & ImGuiWindowFlags_NoCollapse))
  3563. RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true);
  3564. ImVec2 text_min = window->Pos + style.FramePadding;
  3565. ImVec2 text_max = window->Pos + ImVec2(window->Size.x - style.FramePadding.x, style.FramePadding.y*2 + text_size.y);
  3566. ImVec2 clip_max = ImVec2(window->Pos.x + window->Size.x - (p_opened ? title_bar_rect.GetHeight() - 3 : style.FramePadding.x), text_max.y); // Match the size of CloseWindowButton()
  3567. bool pad_left = (flags & ImGuiWindowFlags_NoCollapse) == 0;
  3568. bool pad_right = (p_opened != NULL);
  3569. if (style.WindowTitleAlign & ImGuiAlign_Center) pad_right = pad_left;
  3570. if (pad_left) text_min.x += g.FontSize + style.ItemInnerSpacing.x;
  3571. if (pad_right) text_max.x -= g.FontSize + style.ItemInnerSpacing.x;
  3572. RenderTextClipped(text_min, text_max, name, NULL, &text_size, style.WindowTitleAlign, NULL, &clip_max);
  3573. }
  3574. // Save clipped aabb so we can access it in constant-time in FindHoveredWindow()
  3575. window->ClippedRect = window->Rect();
  3576. window->ClippedRect.Clip(window->ClipRectStack.front());
  3577. // Pressing CTRL+C while holding on a window copy its content to the clipboard
  3578. // This works but 1. doesn't handle multiple Begin/End pairs, 2. recursing into another Begin/End pair - so we need to work that out and add better logging scope.
  3579. // Maybe we can support CTRL+C on every element?
  3580. /*
  3581. if (g.ActiveId == move_id)
  3582. if (g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_C))
  3583. ImGui::LogToClipboard();
  3584. */
  3585. }
  3586. window->BeginCount++;
  3587. // Inner clipping rectangle
  3588. // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame
  3589. // Note that if our window is collapsed we will end up with a null clipping rectangle which is the correct behavior.
  3590. const ImRect title_bar_rect = window->TitleBarRect();
  3591. ImVec4 clip_rect(title_bar_rect.Min.x+0.5f+window->WindowPadding.x*0.5f, title_bar_rect.Max.y+window->MenuBarHeight()+0.5f, window->Rect().Max.x+0.5f-window->WindowPadding.x*0.5f, window->Rect().Max.y-1.5f);
  3592. if (window->ScrollbarY)
  3593. clip_rect.z -= style.ScrollbarWidth;
  3594. PushClipRect(clip_rect);
  3595. // Clear 'accessed' flag last thing
  3596. if (first_begin_of_the_frame)
  3597. window->Accessed = false;
  3598. // Child window can be out of sight and have "negative" clip windows.
  3599. // Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar).
  3600. if (flags & ImGuiWindowFlags_ChildWindow)
  3601. {
  3602. IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0);
  3603. window->Collapsed = parent_window && parent_window->Collapsed;
  3604. if (!(flags & ImGuiWindowFlags_AlwaysAutoResize) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
  3605. {
  3606. const ImVec4 clip_rect_t = window->ClipRectStack.back();
  3607. window->Collapsed |= (clip_rect_t.x >= clip_rect_t.z || clip_rect_t.y >= clip_rect_t.w);
  3608. }
  3609. // We also hide the window from rendering because we've already added its border to the command list.
  3610. // (we could perform the check earlier in the function but it is simpler at this point)
  3611. if (window->Collapsed)
  3612. window->Active = false;
  3613. }
  3614. if (style.Alpha <= 0.0f)
  3615. window->Active = false;
  3616. // Return false if we don't intend to display anything to allow user to perform an early out optimization
  3617. window->SkipItems = (window->Collapsed || !window->Active) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0;
  3618. return !window->SkipItems;
  3619. }
  3620. void ImGui::End()
  3621. {
  3622. ImGuiState& g = *GImGui;
  3623. ImGuiWindow* window = g.CurrentWindow;
  3624. ImGui::Columns(1, "#CloseColumns");
  3625. PopClipRect(); // inner window clip rectangle
  3626. // Stop logging
  3627. if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of logging
  3628. ImGui::LogFinish();
  3629. // Pop
  3630. // NB: we don't clear 'window->RootWindow'. The pointer is allowed to live until the next call to Begin().
  3631. g.CurrentWindowStack.pop_back();
  3632. if (window->Flags & ImGuiWindowFlags_Popup)
  3633. g.CurrentPopupStack.pop_back();
  3634. CheckStacksSize(window, false);
  3635. SetCurrentWindow(g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back());
  3636. }
  3637. // Vertical scrollbar
  3638. // The entire piece of code below is rather confusing because:
  3639. // - We handle absolute seeking (when first clicking outside the grab) and relative manipulation (afterward or when clicking inside the grab)
  3640. // - We store values as ratio and in a form that allows the window content to change while we are holding on a scrollbar
  3641. static void Scrollbar(ImGuiWindow* window)
  3642. {
  3643. ImGuiState& g = *GImGui;
  3644. const ImGuiStyle& style = g.Style;
  3645. const ImGuiID id = window->GetID("#SCROLLY");
  3646. // Render background
  3647. ImRect bb(window->Rect().Max.x - style.ScrollbarWidth, window->Pos.y + window->TitleBarHeight()+1, window->Rect().Max.x, window->Rect().Max.y-1);
  3648. window->DrawList->AddRectFilled(bb.Min, bb.Max, window->Color(ImGuiCol_ScrollbarBg));
  3649. bb.Expand(-3.0f);
  3650. const float scrollbar_height = bb.GetHeight();
  3651. // The grabable box size generally represent the amount visible (vs the total scrollable amount)
  3652. // But we maintain a minimum size in pixel to allow for the user to still aim inside.
  3653. const float grab_h_pixels = ImMin(ImMax(scrollbar_height * ImSaturate(window->Size.y / ImMax(window->SizeContents.y, window->Size.y)), style.GrabMinSize), scrollbar_height);
  3654. const float grab_h_norm = grab_h_pixels / scrollbar_height;
  3655. // Handle input right away. None of the code of Begin() is relying on scrolling position before calling Scrollbar().
  3656. bool held = false;
  3657. bool hovered = false;
  3658. const bool previously_held = (g.ActiveId == id);
  3659. ButtonBehavior(bb, id, &hovered, &held, true);
  3660. const float scroll_max = ImMax(1.0f, window->SizeContents.y - window->Size.y);
  3661. float scroll_ratio = ImSaturate(window->ScrollY / scroll_max);
  3662. float grab_y_norm = scroll_ratio * (scrollbar_height - grab_h_pixels) / scrollbar_height;
  3663. if (held)
  3664. {
  3665. const float clicked_y_norm = ImSaturate((g.IO.MousePos.y - bb.Min.y) / scrollbar_height); // Click position in scrollbar space (0.0f->1.0f)
  3666. g.HoveredId = id;
  3667. bool seek_absolute = false;
  3668. if (!previously_held)
  3669. {
  3670. // On initial click calculate the distance between mouse and the center of the grab
  3671. if (clicked_y_norm >= grab_y_norm && clicked_y_norm <= grab_y_norm + grab_h_norm)
  3672. {
  3673. g.ScrollbarClickDeltaToGrabCenter = clicked_y_norm - grab_y_norm - grab_h_norm*0.5f;
  3674. }
  3675. else
  3676. {
  3677. seek_absolute = true;
  3678. g.ScrollbarClickDeltaToGrabCenter = 0;
  3679. }
  3680. }
  3681. // Apply scroll
  3682. // It is ok to modify ScrollY here because we are being called in Begin() after the calculation of SizeContents and before setting up our starting position
  3683. const float scroll_y_norm = ImSaturate((clicked_y_norm - g.ScrollbarClickDeltaToGrabCenter - grab_h_norm*0.5f) / (1.0f - grab_h_norm));
  3684. window->ScrollY = (float)(int)(0.5f + scroll_y_norm * (window->SizeContents.y - window->Size.y));
  3685. // Update values for rendering
  3686. scroll_ratio = ImSaturate(window->ScrollY / scroll_max);
  3687. grab_y_norm = scroll_ratio * (scrollbar_height - grab_h_pixels) / scrollbar_height;
  3688. // Update distance to grab now that we have seeked and saturated
  3689. if (seek_absolute)
  3690. g.ScrollbarClickDeltaToGrabCenter = clicked_y_norm - grab_y_norm - grab_h_norm*0.5f;
  3691. }
  3692. // Render
  3693. const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab);
  3694. window->DrawList->AddRectFilled(ImVec2(bb.Min.x, ImLerp(bb.Min.y, bb.Max.y, grab_y_norm)), ImVec2(bb.Max.x, ImLerp(bb.Min.y, bb.Max.y, grab_y_norm) + grab_h_pixels), grab_col, style.ScrollbarRounding);
  3695. }
  3696. // Moving window to front of display (which happens to be back of our sorted list)
  3697. static void FocusWindow(ImGuiWindow* window)
  3698. {
  3699. ImGuiState& g = *GImGui;
  3700. // Always mark the window we passed as focused. This is used for keyboard interactions such as tabbing.
  3701. g.FocusedWindow = window;
  3702. // Passing NULL allow to disable keyboard focus
  3703. if (!window)
  3704. return;
  3705. // And move its root window to the top of the pile
  3706. if (window->RootWindow)
  3707. window = window->RootWindow;
  3708. // Steal focus on active widgets
  3709. if (window->Flags & ImGuiWindowFlags_Popup) // FIXME: This statement should be unnecessary. Need further testing before removing it..
  3710. if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindow != window)
  3711. SetActiveId(0);
  3712. if (g.Windows.back() == window)
  3713. return;
  3714. for (size_t i = 0; i < g.Windows.size(); i++)
  3715. if (g.Windows[i] == window)
  3716. {
  3717. g.Windows.erase(g.Windows.begin() + i);
  3718. break;
  3719. }
  3720. g.Windows.push_back(window);
  3721. }
  3722. void ImGui::PushItemWidth(float item_width)
  3723. {
  3724. ImGuiWindow* window = GetCurrentWindow();
  3725. window->DC.ItemWidth = (item_width == 0.0f ? window->ItemWidthDefault : item_width);
  3726. window->DC.ItemWidthStack.push_back(window->DC.ItemWidth);
  3727. }
  3728. static void PushMultiItemsWidths(int components, float w_full = 0.0f)
  3729. {
  3730. ImGuiWindow* window = GetCurrentWindow();
  3731. const ImGuiStyle& style = GImGui->Style;
  3732. if (w_full <= 0.0f)
  3733. w_full = ImGui::CalcItemWidth();
  3734. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components));
  3735. 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)));
  3736. window->DC.ItemWidthStack.push_back(w_item_last);
  3737. for (int i = 0; i < components-1; i++)
  3738. window->DC.ItemWidthStack.push_back(w_item_one);
  3739. window->DC.ItemWidth = window->DC.ItemWidthStack.back();
  3740. }
  3741. void ImGui::PopItemWidth()
  3742. {
  3743. ImGuiWindow* window = GetCurrentWindow();
  3744. window->DC.ItemWidthStack.pop_back();
  3745. window->DC.ItemWidth = window->DC.ItemWidthStack.empty() ? window->ItemWidthDefault : window->DC.ItemWidthStack.back();
  3746. }
  3747. float ImGui::CalcItemWidth()
  3748. {
  3749. ImGuiWindow* window = GetCurrentWindow();
  3750. float w = window->DC.ItemWidth;
  3751. if (w < 0.0f)
  3752. {
  3753. // Align to a right-side limit. We include 1 frame padding in the calculation because this is how the width is always used (we add 2 frame padding to it), but we could move that responsibility to the widget as well.
  3754. ImGuiState& g = *GImGui;
  3755. float width_to_right_edge = window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x;
  3756. w = ImMax(1.0f, width_to_right_edge + w - g.Style.FramePadding.x * 2.0f);
  3757. }
  3758. w = (float)(int)w;
  3759. return w;
  3760. }
  3761. static void SetFont(ImFont* font)
  3762. {
  3763. ImGuiState& g = *GImGui;
  3764. IM_ASSERT(font && font->IsLoaded());
  3765. IM_ASSERT(font->Scale > 0.0f);
  3766. g.Font = font;
  3767. g.FontBaseSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale;
  3768. g.FontSize = g.CurrentWindow ? g.CurrentWindow->CalcFontSize() : 0.0f;
  3769. g.FontTexUvWhitePixel = g.Font->ContainerAtlas->TexUvWhitePixel;
  3770. }
  3771. void ImGui::PushFont(ImFont* font)
  3772. {
  3773. ImGuiState& g = *GImGui;
  3774. if (!font)
  3775. font = g.IO.Fonts->Fonts[0];
  3776. SetFont(font);
  3777. g.FontStack.push_back(font);
  3778. g.CurrentWindow->DrawList->PushTextureID(font->ContainerAtlas->TexID);
  3779. }
  3780. void ImGui::PopFont()
  3781. {
  3782. ImGuiState& g = *GImGui;
  3783. g.CurrentWindow->DrawList->PopTextureID();
  3784. g.FontStack.pop_back();
  3785. SetFont(g.FontStack.empty() ? g.IO.Fonts->Fonts[0] : g.FontStack.back());
  3786. }
  3787. void ImGui::PushAllowKeyboardFocus(bool allow_keyboard_focus)
  3788. {
  3789. ImGuiWindow* window = GetCurrentWindow();
  3790. window->DC.AllowKeyboardFocus = allow_keyboard_focus;
  3791. window->DC.AllowKeyboardFocusStack.push_back(allow_keyboard_focus);
  3792. }
  3793. void ImGui::PopAllowKeyboardFocus()
  3794. {
  3795. ImGuiWindow* window = GetCurrentWindow();
  3796. window->DC.AllowKeyboardFocusStack.pop_back();
  3797. window->DC.AllowKeyboardFocus = window->DC.AllowKeyboardFocusStack.empty() ? true : window->DC.AllowKeyboardFocusStack.back();
  3798. }
  3799. void ImGui::PushButtonRepeat(bool repeat)
  3800. {
  3801. ImGuiWindow* window = GetCurrentWindow();
  3802. window->DC.ButtonRepeat = repeat;
  3803. window->DC.ButtonRepeatStack.push_back(repeat);
  3804. }
  3805. void ImGui::PopButtonRepeat()
  3806. {
  3807. ImGuiWindow* window = GetCurrentWindow();
  3808. window->DC.ButtonRepeatStack.pop_back();
  3809. window->DC.ButtonRepeat = window->DC.ButtonRepeatStack.empty() ? false : window->DC.ButtonRepeatStack.back();
  3810. }
  3811. void ImGui::PushTextWrapPos(float wrap_pos_x)
  3812. {
  3813. ImGuiWindow* window = GetCurrentWindow();
  3814. window->DC.TextWrapPos = wrap_pos_x;
  3815. window->DC.TextWrapPosStack.push_back(wrap_pos_x);
  3816. }
  3817. void ImGui::PopTextWrapPos()
  3818. {
  3819. ImGuiWindow* window = GetCurrentWindow();
  3820. window->DC.TextWrapPosStack.pop_back();
  3821. window->DC.TextWrapPos = window->DC.TextWrapPosStack.empty() ? -1.0f : window->DC.TextWrapPosStack.back();
  3822. }
  3823. void ImGui::PushStyleColor(ImGuiCol idx, const ImVec4& col)
  3824. {
  3825. ImGuiState& g = *GImGui;
  3826. ImGuiColMod backup;
  3827. backup.Col = idx;
  3828. backup.PreviousValue = g.Style.Colors[idx];
  3829. g.ColorModifiers.push_back(backup);
  3830. g.Style.Colors[idx] = col;
  3831. }
  3832. void ImGui::PopStyleColor(int count)
  3833. {
  3834. ImGuiState& g = *GImGui;
  3835. while (count > 0)
  3836. {
  3837. ImGuiColMod& backup = g.ColorModifiers.back();
  3838. g.Style.Colors[backup.Col] = backup.PreviousValue;
  3839. g.ColorModifiers.pop_back();
  3840. count--;
  3841. }
  3842. }
  3843. static float* GetStyleVarFloatAddr(ImGuiStyleVar idx)
  3844. {
  3845. ImGuiState& g = *GImGui;
  3846. switch (idx)
  3847. {
  3848. case ImGuiStyleVar_Alpha: return &g.Style.Alpha;
  3849. case ImGuiStyleVar_WindowRounding: return &g.Style.WindowRounding;
  3850. case ImGuiStyleVar_ChildWindowRounding: return &g.Style.ChildWindowRounding;
  3851. case ImGuiStyleVar_FrameRounding: return &g.Style.FrameRounding;
  3852. case ImGuiStyleVar_IndentSpacing: return &g.Style.IndentSpacing;
  3853. case ImGuiStyleVar_GrabMinSize: return &g.Style.GrabMinSize;
  3854. }
  3855. return NULL;
  3856. }
  3857. static ImVec2* GetStyleVarVec2Addr(ImGuiStyleVar idx)
  3858. {
  3859. ImGuiState& g = *GImGui;
  3860. switch (idx)
  3861. {
  3862. case ImGuiStyleVar_WindowPadding: return &g.Style.WindowPadding;
  3863. case ImGuiStyleVar_WindowMinSize: return &g.Style.WindowMinSize;
  3864. case ImGuiStyleVar_FramePadding: return &g.Style.FramePadding;
  3865. case ImGuiStyleVar_ItemSpacing: return &g.Style.ItemSpacing;
  3866. case ImGuiStyleVar_ItemInnerSpacing: return &g.Style.ItemInnerSpacing;
  3867. }
  3868. return NULL;
  3869. }
  3870. void ImGui::PushStyleVar(ImGuiStyleVar idx, float val)
  3871. {
  3872. ImGuiState& g = *GImGui;
  3873. float* pvar = GetStyleVarFloatAddr(idx);
  3874. IM_ASSERT(pvar != NULL); // Called function with wrong-type? Variable is not a float.
  3875. ImGuiStyleMod backup;
  3876. backup.Var = idx;
  3877. backup.PreviousValue = ImVec2(*pvar, 0.0f);
  3878. g.StyleModifiers.push_back(backup);
  3879. *pvar = val;
  3880. }
  3881. void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
  3882. {
  3883. ImGuiState& g = *GImGui;
  3884. ImVec2* pvar = GetStyleVarVec2Addr(idx);
  3885. IM_ASSERT(pvar != NULL); // Called function with wrong-type? Variable is not a ImVec2.
  3886. ImGuiStyleMod backup;
  3887. backup.Var = idx;
  3888. backup.PreviousValue = *pvar;
  3889. g.StyleModifiers.push_back(backup);
  3890. *pvar = val;
  3891. }
  3892. void ImGui::PopStyleVar(int count)
  3893. {
  3894. ImGuiState& g = *GImGui;
  3895. while (count > 0)
  3896. {
  3897. ImGuiStyleMod& backup = g.StyleModifiers.back();
  3898. if (float* pvar_f = GetStyleVarFloatAddr(backup.Var))
  3899. *pvar_f = backup.PreviousValue.x;
  3900. else if (ImVec2* pvar_v = GetStyleVarVec2Addr(backup.Var))
  3901. *pvar_v = backup.PreviousValue;
  3902. g.StyleModifiers.pop_back();
  3903. count--;
  3904. }
  3905. }
  3906. const char* ImGui::GetStyleColName(ImGuiCol idx)
  3907. {
  3908. // Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1";
  3909. switch (idx)
  3910. {
  3911. case ImGuiCol_Text: return "Text";
  3912. case ImGuiCol_TextDisabled: return "TextDisabled";
  3913. case ImGuiCol_WindowBg: return "WindowBg";
  3914. case ImGuiCol_ChildWindowBg: return "ChildWindowBg";
  3915. case ImGuiCol_Border: return "Border";
  3916. case ImGuiCol_BorderShadow: return "BorderShadow";
  3917. case ImGuiCol_FrameBg: return "FrameBg";
  3918. case ImGuiCol_FrameBgHovered: return "FrameBgHovered";
  3919. case ImGuiCol_FrameBgActive: return "FrameBgActive";
  3920. case ImGuiCol_TitleBg: return "TitleBg";
  3921. case ImGuiCol_TitleBgCollapsed: return "TitleBgCollapsed";
  3922. case ImGuiCol_TitleBgActive: return "TitleBgActive";
  3923. case ImGuiCol_MenuBarBg: return "MenuBarBg";
  3924. case ImGuiCol_ScrollbarBg: return "ScrollbarBg";
  3925. case ImGuiCol_ScrollbarGrab: return "ScrollbarGrab";
  3926. case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered";
  3927. case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive";
  3928. case ImGuiCol_ComboBg: return "ComboBg";
  3929. case ImGuiCol_CheckMark: return "CheckMark";
  3930. case ImGuiCol_SliderGrab: return "SliderGrab";
  3931. case ImGuiCol_SliderGrabActive: return "SliderGrabActive";
  3932. case ImGuiCol_Button: return "Button";
  3933. case ImGuiCol_ButtonHovered: return "ButtonHovered";
  3934. case ImGuiCol_ButtonActive: return "ButtonActive";
  3935. case ImGuiCol_Header: return "Header";
  3936. case ImGuiCol_HeaderHovered: return "HeaderHovered";
  3937. case ImGuiCol_HeaderActive: return "HeaderActive";
  3938. case ImGuiCol_Column: return "Column";
  3939. case ImGuiCol_ColumnHovered: return "ColumnHovered";
  3940. case ImGuiCol_ColumnActive: return "ColumnActive";
  3941. case ImGuiCol_ResizeGrip: return "ResizeGrip";
  3942. case ImGuiCol_ResizeGripHovered: return "ResizeGripHovered";
  3943. case ImGuiCol_ResizeGripActive: return "ResizeGripActive";
  3944. case ImGuiCol_CloseButton: return "CloseButton";
  3945. case ImGuiCol_CloseButtonHovered: return "CloseButtonHovered";
  3946. case ImGuiCol_CloseButtonActive: return "CloseButtonActive";
  3947. case ImGuiCol_PlotLines: return "PlotLines";
  3948. case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered";
  3949. case ImGuiCol_PlotHistogram: return "PlotHistogram";
  3950. case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered";
  3951. case ImGuiCol_TextSelectedBg: return "TextSelectedBg";
  3952. case ImGuiCol_TooltipBg: return "TooltipBg";
  3953. case ImGuiCol_ModalWindowDarkening: return "ModalWindowDarkening";
  3954. }
  3955. IM_ASSERT(0);
  3956. return "Unknown";
  3957. }
  3958. bool ImGui::IsWindowHovered()
  3959. {
  3960. ImGuiState& g = *GImGui;
  3961. return g.HoveredWindow == g.CurrentWindow;
  3962. }
  3963. bool ImGui::IsWindowFocused()
  3964. {
  3965. ImGuiState& g = *GImGui;
  3966. return g.FocusedWindow == g.CurrentWindow;
  3967. }
  3968. bool ImGui::IsRootWindowFocused()
  3969. {
  3970. ImGuiState& g = *GImGui;
  3971. ImGuiWindow* root_window = g.CurrentWindow->RootWindow;
  3972. return g.FocusedWindow == root_window;
  3973. }
  3974. bool ImGui::IsRootWindowOrAnyChildFocused()
  3975. {
  3976. ImGuiState& g = *GImGui;
  3977. ImGuiWindow* root_window = g.CurrentWindow->RootWindow;
  3978. return g.FocusedWindow && g.FocusedWindow->RootWindow == root_window;
  3979. }
  3980. float ImGui::GetWindowWidth()
  3981. {
  3982. ImGuiWindow* window = GImGui->CurrentWindow;
  3983. return window->Size.x;
  3984. }
  3985. ImVec2 ImGui::GetWindowPos()
  3986. {
  3987. ImGuiState& g = *GImGui;
  3988. ImGuiWindow* window = g.CurrentWindow;
  3989. return window->Pos;
  3990. }
  3991. static void SetWindowScrollY(ImGuiWindow* window, float new_scroll_y)
  3992. {
  3993. window->DC.CursorMaxPos.y += window->ScrollY;
  3994. window->ScrollY = new_scroll_y;
  3995. window->DC.CursorMaxPos.y -= window->ScrollY;
  3996. }
  3997. static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiSetCond cond)
  3998. {
  3999. // Test condition (NB: bit 0 is always true) and clear flags for next time
  4000. if (cond && (window->SetWindowPosAllowFlags & cond) == 0)
  4001. return;
  4002. window->SetWindowPosAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver | ImGuiSetCond_Appearing);
  4003. window->SetWindowPosCenterWanted = false;
  4004. // Set
  4005. const ImVec2 old_pos = window->Pos;
  4006. window->PosFloat = pos;
  4007. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  4008. window->DC.CursorPos += (window->Pos - old_pos); // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor
  4009. window->DC.CursorMaxPos += (window->Pos - old_pos); // And more importantly we need to adjust this so size calculation doesn't get affected.
  4010. }
  4011. void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCond cond)
  4012. {
  4013. ImGuiWindow* window = GetCurrentWindow();
  4014. SetWindowPos(window, pos, cond);
  4015. }
  4016. void ImGui::SetWindowPos(const char* name, const ImVec2& pos, ImGuiSetCond cond)
  4017. {
  4018. ImGuiWindow* window = FindWindowByName(name);
  4019. if (window)
  4020. SetWindowPos(window, pos, cond);
  4021. }
  4022. ImVec2 ImGui::GetWindowSize()
  4023. {
  4024. ImGuiWindow* window = GetCurrentWindow();
  4025. return window->Size;
  4026. }
  4027. static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiSetCond cond)
  4028. {
  4029. // Test condition (NB: bit 0 is always true) and clear flags for next time
  4030. if (cond && (window->SetWindowSizeAllowFlags & cond) == 0)
  4031. return;
  4032. window->SetWindowSizeAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver | ImGuiSetCond_Appearing);
  4033. // Set
  4034. if (size.x > 0.0f)
  4035. {
  4036. window->AutoFitFramesX = 0;
  4037. window->SizeFull.x = size.x;
  4038. }
  4039. else
  4040. {
  4041. window->AutoFitFramesX = 2;
  4042. window->AutoFitOnlyGrows = false;
  4043. }
  4044. if (size.y > 0.0f)
  4045. {
  4046. window->AutoFitFramesY = 0;
  4047. window->SizeFull.y = size.y;
  4048. }
  4049. else
  4050. {
  4051. window->AutoFitFramesY = 2;
  4052. window->AutoFitOnlyGrows = false;
  4053. }
  4054. }
  4055. void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCond cond)
  4056. {
  4057. ImGuiWindow* window = GetCurrentWindow();
  4058. SetWindowSize(window, size, cond);
  4059. }
  4060. void ImGui::SetWindowSize(const char* name, const ImVec2& size, ImGuiSetCond cond)
  4061. {
  4062. ImGuiWindow* window = FindWindowByName(name);
  4063. if (window)
  4064. SetWindowSize(window, size, cond);
  4065. }
  4066. static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiSetCond cond)
  4067. {
  4068. // Test condition (NB: bit 0 is always true) and clear flags for next time
  4069. if (cond && (window->SetWindowCollapsedAllowFlags & cond) == 0)
  4070. return;
  4071. window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver | ImGuiSetCond_Appearing);
  4072. // Set
  4073. window->Collapsed = collapsed;
  4074. }
  4075. void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCond cond)
  4076. {
  4077. ImGuiWindow* window = GetCurrentWindow();
  4078. SetWindowCollapsed(window, collapsed, cond);
  4079. }
  4080. bool ImGui::IsWindowCollapsed()
  4081. {
  4082. return GImGui->CurrentWindow->Collapsed;
  4083. }
  4084. void ImGui::SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCond cond)
  4085. {
  4086. ImGuiWindow* window = FindWindowByName(name);
  4087. if (window)
  4088. SetWindowCollapsed(window, collapsed, cond);
  4089. }
  4090. void ImGui::SetWindowFocus()
  4091. {
  4092. ImGuiWindow* window = GetCurrentWindow();
  4093. FocusWindow(window);
  4094. }
  4095. void ImGui::SetWindowFocus(const char* name)
  4096. {
  4097. if (name)
  4098. {
  4099. ImGuiWindow* window = FindWindowByName(name);
  4100. if (window)
  4101. FocusWindow(window);
  4102. }
  4103. else
  4104. {
  4105. FocusWindow(NULL);
  4106. }
  4107. }
  4108. void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond)
  4109. {
  4110. ImGuiState& g = *GImGui;
  4111. g.SetNextWindowPosVal = pos;
  4112. g.SetNextWindowPosCond = cond ? cond : ImGuiSetCond_Always;
  4113. }
  4114. void ImGui::SetNextWindowPosCenter(ImGuiSetCond cond)
  4115. {
  4116. ImGuiState& g = *GImGui;
  4117. g.SetNextWindowPosVal = ImVec2(-FLT_MAX, -FLT_MAX);
  4118. g.SetNextWindowPosCond = cond ? cond : ImGuiSetCond_Always;
  4119. }
  4120. void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond)
  4121. {
  4122. ImGuiState& g = *GImGui;
  4123. g.SetNextWindowSizeVal = size;
  4124. g.SetNextWindowSizeCond = cond ? cond : ImGuiSetCond_Always;
  4125. }
  4126. void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond)
  4127. {
  4128. ImGuiState& g = *GImGui;
  4129. g.SetNextWindowCollapsedVal = collapsed;
  4130. g.SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCond_Always;
  4131. }
  4132. void ImGui::SetNextWindowFocus()
  4133. {
  4134. ImGuiState& g = *GImGui;
  4135. g.SetNextWindowFocus = true;
  4136. }
  4137. ImVec2 ImGui::GetContentRegionMax()
  4138. {
  4139. ImGuiWindow* window = GetCurrentWindow();
  4140. ImVec2 mx = window->Size - window->WindowPadding;
  4141. if (window->DC.ColumnsCount != 1)
  4142. {
  4143. mx.x = ImGui::GetColumnOffset(window->DC.ColumnsCurrent + 1);
  4144. mx.x -= window->WindowPadding.x;
  4145. }
  4146. else
  4147. {
  4148. mx.x -= window->ScrollbarWidth();
  4149. }
  4150. return mx;
  4151. }
  4152. ImVec2 ImGui::GetWindowContentRegionMin()
  4153. {
  4154. ImGuiWindow* window = GetCurrentWindow();
  4155. return ImVec2(0, window->TitleBarHeight() + window->MenuBarHeight()) + window->WindowPadding;
  4156. }
  4157. ImVec2 ImGui::GetWindowContentRegionMax()
  4158. {
  4159. ImGuiWindow* window = GetCurrentWindow();
  4160. ImVec2 m = window->Size - window->WindowPadding;
  4161. m.x -= window->ScrollbarWidth();
  4162. return m;
  4163. }
  4164. float ImGui::GetTextLineHeight()
  4165. {
  4166. ImGuiState& g = *GImGui;
  4167. return g.FontSize;
  4168. }
  4169. float ImGui::GetTextLineHeightWithSpacing()
  4170. {
  4171. ImGuiState& g = *GImGui;
  4172. return g.FontSize + g.Style.ItemSpacing.y;
  4173. }
  4174. float ImGui::GetItemsLineHeightWithSpacing()
  4175. {
  4176. ImGuiState& g = *GImGui;
  4177. return g.FontSize + g.Style.FramePadding.y * 2.0f + g.Style.ItemSpacing.y;
  4178. }
  4179. ImDrawList* ImGui::GetWindowDrawList()
  4180. {
  4181. ImGuiWindow* window = GetCurrentWindow();
  4182. return window->DrawList;
  4183. }
  4184. ImFont* ImGui::GetWindowFont()
  4185. {
  4186. ImGuiState& g = *GImGui;
  4187. return g.Font;
  4188. }
  4189. float ImGui::GetWindowFontSize()
  4190. {
  4191. ImGuiState& g = *GImGui;
  4192. return g.FontSize;
  4193. }
  4194. void ImGui::SetWindowFontScale(float scale)
  4195. {
  4196. ImGuiState& g = *GImGui;
  4197. ImGuiWindow* window = GetCurrentWindow();
  4198. window->FontWindowScale = scale;
  4199. g.FontSize = window->CalcFontSize();
  4200. }
  4201. // User generally sees positions in window coordinates. Internally we store CursorPos in absolute screen coordinates because it is more convenient.
  4202. // Conversion happens as we pass the value to user, but it makes our naming convention confusing because GetCursorPos() == (DC.CursorPos - window.Pos). May want to rename 'DC.CursorPos'.
  4203. ImVec2 ImGui::GetCursorPos()
  4204. {
  4205. ImGuiWindow* window = GetCurrentWindow();
  4206. return window->DC.CursorPos - window->Pos;
  4207. }
  4208. float ImGui::GetCursorPosX()
  4209. {
  4210. return ImGui::GetCursorPos().x;
  4211. }
  4212. float ImGui::GetCursorPosY()
  4213. {
  4214. return ImGui::GetCursorPos().y;
  4215. }
  4216. void ImGui::SetCursorPos(const ImVec2& pos)
  4217. {
  4218. ImGuiWindow* window = GetCurrentWindow();
  4219. window->DC.CursorPos = window->Pos + pos;
  4220. window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos);
  4221. }
  4222. void ImGui::SetCursorPosX(float x)
  4223. {
  4224. ImGuiWindow* window = GetCurrentWindow();
  4225. window->DC.CursorPos.x = window->Pos.x + x;
  4226. window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPos.x);
  4227. }
  4228. void ImGui::SetCursorPosY(float y)
  4229. {
  4230. ImGuiWindow* window = GetCurrentWindow();
  4231. window->DC.CursorPos.y = window->Pos.y + y;
  4232. window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y);
  4233. }
  4234. ImVec2 ImGui::GetCursorStartPos()
  4235. {
  4236. ImGuiWindow* window = GetCurrentWindow();
  4237. return window->DC.CursorStartPos - window->Pos;
  4238. }
  4239. ImVec2 ImGui::GetCursorScreenPos()
  4240. {
  4241. ImGuiWindow* window = GetCurrentWindow();
  4242. return window->DC.CursorPos;
  4243. }
  4244. void ImGui::SetCursorScreenPos(const ImVec2& screen_pos)
  4245. {
  4246. ImGuiWindow* window = GetCurrentWindow();
  4247. window->DC.CursorPos = screen_pos;
  4248. }
  4249. float ImGui::GetScrollY()
  4250. {
  4251. ImGuiWindow* window = GetCurrentWindow();
  4252. return window->ScrollY;
  4253. }
  4254. float ImGui::GetScrollMaxY()
  4255. {
  4256. ImGuiWindow* window = GetCurrentWindow();
  4257. return window->SizeContents.y - window->SizeFull.y;
  4258. }
  4259. void ImGui::SetScrollY(float scroll_y)
  4260. {
  4261. ImGuiWindow* window = GetCurrentWindow();
  4262. window->ScrollTargetRelY = scroll_y + window->TitleBarHeight(); // title bar height cancelled out when using ScrollTargetRelY
  4263. window->ScrollTargetCenterRatioY = 0.0f;
  4264. }
  4265. void ImGui::SetScrollFromPosY(float pos_y, float center_y_ratio)
  4266. {
  4267. // We store a target position so centering can occur on the next frame when we are guaranteed to have a known window size
  4268. ImGuiWindow* window = GetCurrentWindow();
  4269. IM_ASSERT(center_y_ratio >= 0.0f && center_y_ratio <= 1.0f);
  4270. window->ScrollTargetRelY = (float)(int)(pos_y + window->ScrollY);
  4271. if (center_y_ratio <= 0.0f && window->ScrollTargetRelY <= window->WindowPadding.y) // Minor hack to make "scroll to top" take account of WindowPadding, else it would scroll to (WindowPadding.y - ItemSpacing.y)
  4272. window->ScrollTargetRelY = 0.0f;
  4273. window->ScrollTargetCenterRatioY = center_y_ratio;
  4274. }
  4275. void ImGui::SetScrollHere(float center_y_ratio)
  4276. {
  4277. ImGuiWindow* window = GetCurrentWindow();
  4278. float target_y = window->DC.CursorPosPrevLine.y + (window->DC.PrevLineHeight * center_y_ratio) + (GImGui->Style.ItemSpacing.y * (center_y_ratio - 0.5f) * 2.0f); // Precisely aim above, in the middle or below the last line.
  4279. ImGui::SetScrollFromPosY(target_y - window->Pos.y, center_y_ratio);
  4280. }
  4281. void ImGui::SetKeyboardFocusHere(int offset)
  4282. {
  4283. ImGuiWindow* window = GetCurrentWindow();
  4284. window->FocusIdxAllRequestNext = window->FocusIdxAllCounter + 1 + offset;
  4285. window->FocusIdxTabRequestNext = IM_INT_MAX;
  4286. }
  4287. void ImGui::SetStateStorage(ImGuiStorage* tree)
  4288. {
  4289. ImGuiWindow* window = GetCurrentWindow();
  4290. window->DC.StateStorage = tree ? tree : &window->StateStorage;
  4291. }
  4292. ImGuiStorage* ImGui::GetStateStorage()
  4293. {
  4294. ImGuiWindow* window = GetCurrentWindow();
  4295. return window->DC.StateStorage;
  4296. }
  4297. void ImGui::TextV(const char* fmt, va_list args)
  4298. {
  4299. ImGuiState& g = *GImGui;
  4300. ImGuiWindow* window = GetCurrentWindow();
  4301. if (window->SkipItems)
  4302. return;
  4303. const char* text_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  4304. TextUnformatted(g.TempBuffer, text_end);
  4305. }
  4306. void ImGui::Text(const char* fmt, ...)
  4307. {
  4308. va_list args;
  4309. va_start(args, fmt);
  4310. TextV(fmt, args);
  4311. va_end(args);
  4312. }
  4313. void ImGui::TextColoredV(const ImVec4& col, const char* fmt, va_list args)
  4314. {
  4315. ImGui::PushStyleColor(ImGuiCol_Text, col);
  4316. TextV(fmt, args);
  4317. ImGui::PopStyleColor();
  4318. }
  4319. void ImGui::TextColored(const ImVec4& col, const char* fmt, ...)
  4320. {
  4321. va_list args;
  4322. va_start(args, fmt);
  4323. TextColoredV(col, fmt, args);
  4324. va_end(args);
  4325. }
  4326. void ImGui::TextDisabledV(const char* fmt, va_list args)
  4327. {
  4328. ImGui::PushStyleColor(ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled]);
  4329. TextV(fmt, args);
  4330. ImGui::PopStyleColor();
  4331. }
  4332. void ImGui::TextDisabled(const char* fmt, ...)
  4333. {
  4334. va_list args;
  4335. va_start(args, fmt);
  4336. TextDisabledV(fmt, args);
  4337. va_end(args);
  4338. }
  4339. void ImGui::TextWrappedV(const char* fmt, va_list args)
  4340. {
  4341. ImGui::PushTextWrapPos(0.0f);
  4342. TextV(fmt, args);
  4343. ImGui::PopTextWrapPos();
  4344. }
  4345. void ImGui::TextWrapped(const char* fmt, ...)
  4346. {
  4347. va_list args;
  4348. va_start(args, fmt);
  4349. TextWrappedV(fmt, args);
  4350. va_end(args);
  4351. }
  4352. void ImGui::TextUnformatted(const char* text, const char* text_end)
  4353. {
  4354. ImGuiState& g = *GImGui;
  4355. ImGuiWindow* window = GetCurrentWindow();
  4356. if (window->SkipItems)
  4357. return;
  4358. IM_ASSERT(text != NULL);
  4359. const char* text_begin = text;
  4360. if (text_end == NULL)
  4361. text_end = text + strlen(text); // FIXME-OPT
  4362. const float wrap_pos_x = window->DC.TextWrapPos;
  4363. const bool wrap_enabled = wrap_pos_x >= 0.0f;
  4364. if (text_end - text > 2000 && !wrap_enabled)
  4365. {
  4366. // Long text!
  4367. // Perform manual coarse clipping to optimize for long multi-line text
  4368. // From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled.
  4369. // We also don't vertically center the text within the line full height, which is unlikely to matter because we are likely the biggest and only item on the line.
  4370. const char* line = text;
  4371. const float line_height = ImGui::GetTextLineHeight();
  4372. const ImVec2 text_pos = window->DC.CursorPos + ImVec2(0.0f, window->DC.CurrentLineTextBaseOffset);
  4373. const ImVec4 clip_rect = window->ClipRectStack.back();
  4374. ImVec2 text_size(0,0);
  4375. if (text_pos.y <= clip_rect.w)
  4376. {
  4377. ImVec2 pos = text_pos;
  4378. // Lines to skip (can't skip when logging text)
  4379. if (!g.LogEnabled)
  4380. {
  4381. int lines_skippable = (int)((clip_rect.y - text_pos.y) / line_height);
  4382. if (lines_skippable > 0)
  4383. {
  4384. int lines_skipped = 0;
  4385. while (line < text_end && lines_skipped < lines_skippable)
  4386. {
  4387. const char* line_end = strchr(line, '\n');
  4388. line = line_end + 1;
  4389. lines_skipped++;
  4390. }
  4391. pos.y += lines_skipped * line_height;
  4392. }
  4393. }
  4394. // Lines to render
  4395. if (line < text_end)
  4396. {
  4397. ImRect line_rect(pos, pos + ImVec2(ImGui::GetWindowWidth(), line_height));
  4398. while (line < text_end)
  4399. {
  4400. const char* line_end = strchr(line, '\n');
  4401. if (IsClippedEx(line_rect, NULL, false))
  4402. break;
  4403. const ImVec2 line_size = CalcTextSize(line, line_end, false);
  4404. text_size.x = ImMax(text_size.x, line_size.x);
  4405. RenderText(pos, line, line_end, false);
  4406. if (!line_end)
  4407. line_end = text_end;
  4408. line = line_end + 1;
  4409. line_rect.Min.y += line_height;
  4410. line_rect.Max.y += line_height;
  4411. pos.y += line_height;
  4412. }
  4413. // Count remaining lines
  4414. int lines_skipped = 0;
  4415. while (line < text_end)
  4416. {
  4417. const char* line_end = strchr(line, '\n');
  4418. if (!line_end)
  4419. line_end = text_end;
  4420. line = line_end + 1;
  4421. lines_skipped++;
  4422. }
  4423. pos.y += lines_skipped * line_height;
  4424. }
  4425. text_size.y += (pos - text_pos).y;
  4426. }
  4427. ImRect bb(text_pos, text_pos + text_size);
  4428. ItemSize(bb);
  4429. ItemAdd(bb, NULL);
  4430. }
  4431. else
  4432. {
  4433. const float wrap_width = wrap_enabled ? CalcWrapWidthForPos(window->DC.CursorPos, wrap_pos_x) : 0.0f;
  4434. const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width);
  4435. // Account of baseline offset
  4436. ImVec2 text_pos = window->DC.CursorPos;
  4437. text_pos.y += window->DC.CurrentLineTextBaseOffset;
  4438. ImRect bb(text_pos, text_pos + text_size);
  4439. ItemSize(bb.GetSize());
  4440. if (!ItemAdd(bb, NULL))
  4441. return;
  4442. // Render (we don't hide text after ## in this end-user function)
  4443. RenderTextWrapped(bb.Min, text_begin, text_end, wrap_width);
  4444. }
  4445. }
  4446. void ImGui::AlignFirstTextHeightToWidgets()
  4447. {
  4448. ImGuiState& g = *GImGui;
  4449. ImGuiWindow* window = GetCurrentWindow();
  4450. if (window->SkipItems)
  4451. return;
  4452. // Declare a dummy item size to that upcoming items that are smaller will center-align on the newly expanded line height.
  4453. ItemSize(ImVec2(0, g.FontSize + g.Style.FramePadding.y*2), g.Style.FramePadding.y);
  4454. ImGui::SameLine(0, 0);
  4455. }
  4456. // Add a label+text combo aligned to other label+value widgets
  4457. void ImGui::LabelTextV(const char* label, const char* fmt, va_list args)
  4458. {
  4459. ImGuiState& g = *GImGui;
  4460. ImGuiWindow* window = GetCurrentWindow();
  4461. if (window->SkipItems)
  4462. return;
  4463. const ImGuiStyle& style = g.Style;
  4464. const float w = ImGui::CalcItemWidth();
  4465. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  4466. const ImRect value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, label_size.y + style.FramePadding.y*2));
  4467. const ImRect total_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + (label_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), style.FramePadding.y*2) + label_size);
  4468. ItemSize(total_bb, style.FramePadding.y);
  4469. if (!ItemAdd(total_bb, NULL))
  4470. return;
  4471. // Render
  4472. const char* value_text_begin = &g.TempBuffer[0];
  4473. const char* value_text_end = value_text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  4474. RenderTextClipped(value_bb.Min, value_bb.Max, value_text_begin, value_text_end, NULL, ImGuiAlign_VCenter);
  4475. RenderText(ImVec2(value_bb.Max.x + style.ItemInnerSpacing.x, value_bb.Min.y + style.FramePadding.y), label);
  4476. }
  4477. void ImGui::LabelText(const char* label, const char* fmt, ...)
  4478. {
  4479. va_list args;
  4480. va_start(args, fmt);
  4481. LabelTextV(label, fmt, args);
  4482. va_end(args);
  4483. }
  4484. static inline bool IsWindowContentHoverable(ImGuiWindow* window)
  4485. {
  4486. // An active popup disable hovering on other windows (apart from its own children)
  4487. ImGuiState& g = *GImGui;
  4488. if (ImGuiWindow* focused_window = g.FocusedWindow)
  4489. if (ImGuiWindow* focused_root_window = focused_window->RootWindow)
  4490. if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) != 0 && focused_root_window->WasActive && focused_root_window != window->RootWindow)
  4491. return false;
  4492. return true;
  4493. }
  4494. static bool IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs = false)
  4495. {
  4496. ImGuiState& g = *GImGui;
  4497. if (g.HoveredId == 0 || g.HoveredId == id)
  4498. {
  4499. ImGuiWindow* window = GetCurrentWindow();
  4500. if (g.HoveredWindow == window || (flatten_childs && g.HoveredRootWindow == window->RootWindow))
  4501. if ((g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdIsFocusedOnly) && IsMouseHoveringRect(bb))
  4502. if (IsWindowContentHoverable(g.HoveredRootWindow))
  4503. return true;
  4504. }
  4505. return false;
  4506. }
  4507. static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, ImGuiButtonFlags flags)
  4508. {
  4509. ImGuiState& g = *GImGui;
  4510. ImGuiWindow* window = GetCurrentWindow();
  4511. if (flags & ImGuiButtonFlags_Disabled)
  4512. {
  4513. if (out_hovered) *out_hovered = false;
  4514. if (out_held) *out_held = false;
  4515. if (g.ActiveId == id) SetActiveId(0);
  4516. return false;
  4517. }
  4518. bool pressed = false;
  4519. const bool hovered = IsHovered(bb, id, (flags & ImGuiButtonFlags_FlattenChilds) != 0);
  4520. if (hovered)
  4521. {
  4522. g.HoveredId = id;
  4523. if (allow_key_modifiers || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt))
  4524. {
  4525. if (g.IO.MouseClicked[0])
  4526. {
  4527. if (flags & ImGuiButtonFlags_PressedOnClick)
  4528. {
  4529. pressed = true;
  4530. SetActiveId(0);
  4531. }
  4532. else
  4533. {
  4534. SetActiveId(id, window);
  4535. }
  4536. FocusWindow(window);
  4537. }
  4538. else if (g.IO.MouseReleased[0] && (flags & ImGuiButtonFlags_PressedOnRelease))
  4539. {
  4540. pressed = true;
  4541. SetActiveId(0);
  4542. }
  4543. else if ((flags & ImGuiButtonFlags_Repeat) && g.ActiveId == id && ImGui::IsMouseClicked(0, true))
  4544. {
  4545. pressed = true;
  4546. }
  4547. }
  4548. }
  4549. bool held = false;
  4550. if (g.ActiveId == id)
  4551. {
  4552. if (g.IO.MouseDown[0])
  4553. {
  4554. held = true;
  4555. }
  4556. else
  4557. {
  4558. if (hovered)
  4559. pressed = true;
  4560. SetActiveId(0);
  4561. }
  4562. }
  4563. if (out_hovered) *out_hovered = hovered;
  4564. if (out_held) *out_held = held;
  4565. return pressed;
  4566. }
  4567. static bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0)
  4568. {
  4569. ImGuiWindow* window = GetCurrentWindow();
  4570. if (window->SkipItems)
  4571. return false;
  4572. ImGuiState& g = *GImGui;
  4573. const ImGuiStyle& style = g.Style;
  4574. const ImGuiID id = window->GetID(label);
  4575. const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
  4576. ImVec2 pos = window->DC.CursorPos;
  4577. if ((flags & ImGuiButtonFlags_AlignTextBaseLine) && style.FramePadding.y < window->DC.CurrentLineTextBaseOffset)
  4578. pos.y += window->DC.CurrentLineTextBaseOffset - style.FramePadding.y;
  4579. const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : (label_size.x + style.FramePadding.x*2), size_arg.y != 0.0f ? size_arg.y : (label_size.y + style.FramePadding.y*2));
  4580. const ImRect bb(pos, pos + size);
  4581. ItemSize(bb, style.FramePadding.y);
  4582. if (!ItemAdd(bb, &id))
  4583. return false;
  4584. if (window->DC.ButtonRepeat) flags |= ImGuiButtonFlags_Repeat;
  4585. bool hovered, held;
  4586. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true, flags);
  4587. // Render
  4588. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  4589. RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
  4590. RenderTextClipped(bb.Min, bb.Max, label, NULL, &label_size, ImGuiAlign_Center | ImGuiAlign_VCenter);
  4591. // Automatically close popups
  4592. //if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
  4593. // ImGui::CloseCurrentPopup();
  4594. return pressed;
  4595. }
  4596. bool ImGui::Button(const char* label, const ImVec2& size_arg)
  4597. {
  4598. return ButtonEx(label, size_arg, 0);
  4599. }
  4600. // Small buttons fits within text without additional vertical spacing.
  4601. bool ImGui::SmallButton(const char* label)
  4602. {
  4603. ImGuiState& g = *GImGui;
  4604. float backup_padding_y = g.Style.FramePadding.y;
  4605. g.Style.FramePadding.y = 0.0f;
  4606. bool pressed = ButtonEx(label, ImVec2(0,0), ImGuiButtonFlags_AlignTextBaseLine);
  4607. g.Style.FramePadding.y = backup_padding_y;
  4608. return pressed;
  4609. }
  4610. // Tip: use ImGui::PushID()/PopID() to push indices or pointers in the ID stack.
  4611. // Then you can keep 'str_id' empty or the same for all your buttons (instead of creating a string based on a non-string id)
  4612. bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size)
  4613. {
  4614. ImGuiWindow* window = GetCurrentWindow();
  4615. if (window->SkipItems)
  4616. return false;
  4617. const ImGuiID id = window->GetID(str_id);
  4618. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
  4619. ItemSize(bb);
  4620. if (!ItemAdd(bb, &id))
  4621. return false;
  4622. bool hovered, held;
  4623. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  4624. return pressed;
  4625. }
  4626. // Upper-right button to close a window.
  4627. static bool CloseWindowButton(bool* p_opened)
  4628. {
  4629. ImGuiWindow* window = GetCurrentWindow();
  4630. const ImGuiID id = window->GetID("#CLOSE");
  4631. const float size = window->TitleBarHeight() - 4.0f;
  4632. const ImRect bb(window->Rect().GetTR() + ImVec2(-3.0f-size,2.0f), window->Rect().GetTR() + ImVec2(-3.0f,2.0f+size));
  4633. bool hovered, held;
  4634. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  4635. // Render
  4636. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton);
  4637. const ImVec2 center = bb.GetCenter();
  4638. window->DrawList->AddCircleFilled(center, ImMax(2.0f,size*0.5f), col, 16);
  4639. const float cross_extent = (size * 0.5f * 0.7071f) - 1.0f;
  4640. if (hovered)
  4641. {
  4642. window->DrawList->AddLine(center + ImVec2(+cross_extent,+cross_extent), center + ImVec2(-cross_extent,-cross_extent), window->Color(ImGuiCol_Text));
  4643. window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), window->Color(ImGuiCol_Text));
  4644. }
  4645. if (p_opened != NULL && pressed)
  4646. *p_opened = !*p_opened;
  4647. return pressed;
  4648. }
  4649. void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col)
  4650. {
  4651. ImGuiWindow* window = GetCurrentWindow();
  4652. if (window->SkipItems)
  4653. return;
  4654. ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
  4655. if (border_col.w > 0.0f)
  4656. bb.Max += ImVec2(2,2);
  4657. ItemSize(bb);
  4658. if (!ItemAdd(bb, NULL))
  4659. return;
  4660. if (border_col.w > 0.0f)
  4661. {
  4662. window->DrawList->AddRect(bb.Min, bb.Max, window->Color(border_col), 0.0f);
  4663. window->DrawList->AddImage(user_texture_id, bb.Min+ImVec2(1,1), bb.Max-ImVec2(1,1), uv0, uv1, window->Color(tint_col));
  4664. }
  4665. else
  4666. {
  4667. window->DrawList->AddImage(user_texture_id, bb.Min, bb.Max, uv0, uv1, window->Color(tint_col));
  4668. }
  4669. }
  4670. // frame_padding < 0: uses FramePadding from style (default)
  4671. // frame_padding = 0: no framing
  4672. // frame_padding > 0: set framing size
  4673. // The color used are the button colors.
  4674. bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col)
  4675. {
  4676. ImGuiState& g = *GImGui;
  4677. ImGuiWindow* window = GetCurrentWindow();
  4678. if (window->SkipItems)
  4679. return false;
  4680. const ImGuiStyle& style = g.Style;
  4681. // Default to using texture ID as ID. User can still push string/integer prefixes.
  4682. // We could hash the size/uv to create a unique ID but that would prevent the user from animating UV.
  4683. ImGui::PushID((void *)user_texture_id);
  4684. const ImGuiID id = window->GetID("#image");
  4685. ImGui::PopID();
  4686. const ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : style.FramePadding;
  4687. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding*2);
  4688. const ImRect image_bb(window->DC.CursorPos + padding, window->DC.CursorPos + padding + size);
  4689. ItemSize(bb);
  4690. if (!ItemAdd(bb, &id))
  4691. return false;
  4692. bool hovered, held;
  4693. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  4694. // Render
  4695. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  4696. RenderFrame(bb.Min, bb.Max, col);
  4697. if (bg_col.w > 0.0f)
  4698. window->DrawList->AddRectFilled(image_bb.Min, image_bb.Max, window->Color(bg_col));
  4699. window->DrawList->AddImage(user_texture_id, image_bb.Min, image_bb.Max, uv0, uv1, window->Color(tint_col));
  4700. return pressed;
  4701. }
  4702. // Start logging ImGui output to TTY
  4703. void ImGui::LogToTTY(int max_depth)
  4704. {
  4705. ImGuiState& g = *GImGui;
  4706. ImGuiWindow* window = GetCurrentWindow();
  4707. if (g.LogEnabled)
  4708. return;
  4709. g.LogEnabled = true;
  4710. g.LogFile = stdout;
  4711. g.LogStartDepth = window->DC.TreeDepth;
  4712. if (max_depth >= 0)
  4713. g.LogAutoExpandMaxDepth = max_depth;
  4714. }
  4715. // Start logging ImGui output to given file
  4716. void ImGui::LogToFile(int max_depth, const char* filename)
  4717. {
  4718. ImGuiState& g = *GImGui;
  4719. ImGuiWindow* window = GetCurrentWindow();
  4720. if (g.LogEnabled)
  4721. return;
  4722. if (!filename)
  4723. {
  4724. filename = g.IO.LogFilename;
  4725. if (!filename)
  4726. return;
  4727. }
  4728. g.LogFile = fopen(filename, "ab");
  4729. if (!g.LogFile)
  4730. {
  4731. IM_ASSERT(g.LogFile != NULL); // Consider this an error
  4732. return;
  4733. }
  4734. g.LogEnabled = true;
  4735. g.LogStartDepth = window->DC.TreeDepth;
  4736. if (max_depth >= 0)
  4737. g.LogAutoExpandMaxDepth = max_depth;
  4738. }
  4739. // Start logging ImGui output to clipboard
  4740. void ImGui::LogToClipboard(int max_depth)
  4741. {
  4742. ImGuiWindow* window = GetCurrentWindow();
  4743. ImGuiState& g = *GImGui;
  4744. if (g.LogEnabled)
  4745. return;
  4746. g.LogEnabled = true;
  4747. g.LogFile = NULL;
  4748. g.LogStartDepth = window->DC.TreeDepth;
  4749. if (max_depth >= 0)
  4750. g.LogAutoExpandMaxDepth = max_depth;
  4751. }
  4752. void ImGui::LogFinish()
  4753. {
  4754. ImGuiState& g = *GImGui;
  4755. if (!g.LogEnabled)
  4756. return;
  4757. ImGui::LogText(IM_NEWLINE);
  4758. g.LogEnabled = false;
  4759. if (g.LogFile != NULL)
  4760. {
  4761. if (g.LogFile == stdout)
  4762. fflush(g.LogFile);
  4763. else
  4764. fclose(g.LogFile);
  4765. g.LogFile = NULL;
  4766. }
  4767. if (g.LogClipboard->size() > 1)
  4768. {
  4769. if (g.IO.SetClipboardTextFn)
  4770. g.IO.SetClipboardTextFn(g.LogClipboard->begin());
  4771. g.LogClipboard->clear();
  4772. }
  4773. }
  4774. // Helper to display logging buttons
  4775. void ImGui::LogButtons()
  4776. {
  4777. ImGuiState& g = *GImGui;
  4778. ImGui::PushID("LogButtons");
  4779. const bool log_to_tty = ImGui::Button("Log To TTY");
  4780. ImGui::SameLine();
  4781. const bool log_to_file = ImGui::Button("Log To File");
  4782. ImGui::SameLine();
  4783. const bool log_to_clipboard = ImGui::Button("Log To Clipboard");
  4784. ImGui::SameLine();
  4785. ImGui::PushItemWidth(80.0f);
  4786. ImGui::PushAllowKeyboardFocus(false);
  4787. ImGui::SliderInt("Depth", &g.LogAutoExpandMaxDepth, 0, 9, NULL);
  4788. ImGui::PopAllowKeyboardFocus();
  4789. ImGui::PopItemWidth();
  4790. ImGui::PopID();
  4791. // Start logging at the end of the function so that the buttons don't appear in the log
  4792. if (log_to_tty)
  4793. LogToTTY(g.LogAutoExpandMaxDepth);
  4794. if (log_to_file)
  4795. LogToFile(g.LogAutoExpandMaxDepth, g.IO.LogFilename);
  4796. if (log_to_clipboard)
  4797. LogToClipboard(g.LogAutoExpandMaxDepth);
  4798. }
  4799. bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display_frame, bool default_open)
  4800. {
  4801. ImGuiState& g = *GImGui;
  4802. ImGuiWindow* window = GetCurrentWindow();
  4803. if (window->SkipItems)
  4804. return false;
  4805. const ImGuiStyle& style = g.Style;
  4806. IM_ASSERT(str_id != NULL || label != NULL);
  4807. if (str_id == NULL)
  4808. str_id = label;
  4809. if (label == NULL)
  4810. label = str_id;
  4811. const ImGuiID id = window->GetID(str_id);
  4812. // We only write to the tree storage if the user clicks (or explicitely use SetNextTreeNode*** functions)
  4813. ImGuiStorage* storage = window->DC.StateStorage;
  4814. bool opened;
  4815. if (g.SetNextTreeNodeOpenedCond != 0)
  4816. {
  4817. if (g.SetNextTreeNodeOpenedCond & ImGuiSetCond_Always)
  4818. {
  4819. opened = g.SetNextTreeNodeOpenedVal;
  4820. storage->SetInt(id, opened);
  4821. }
  4822. else
  4823. {
  4824. // We treat ImGuiSetCondition_Once and ImGuiSetCondition_FirstUseEver the same because tree node state are not saved persistently.
  4825. const int stored_value = storage->GetInt(id, -1);
  4826. if (stored_value == -1)
  4827. {
  4828. opened = g.SetNextTreeNodeOpenedVal;
  4829. storage->SetInt(id, opened);
  4830. }
  4831. else
  4832. {
  4833. opened = stored_value != 0;
  4834. }
  4835. }
  4836. g.SetNextTreeNodeOpenedCond = 0;
  4837. }
  4838. else
  4839. {
  4840. opened = storage->GetInt(id, default_open) != 0;
  4841. }
  4842. // Framed header expand a little outside the default padding
  4843. const ImVec2 window_padding = window->WindowPadding;
  4844. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  4845. const ImVec2 pos_min = window->DC.CursorPos;
  4846. const ImVec2 pos_max = window->Pos + GetContentRegionMax();
  4847. ImRect bb = ImRect(pos_min, ImVec2(pos_max.x, pos_min.y + label_size.y));
  4848. if (display_frame)
  4849. {
  4850. bb.Min.x -= window_padding.x*0.5f - 1;
  4851. bb.Max.x += window_padding.x*0.5f - 1;
  4852. bb.Max.y += style.FramePadding.y * 2;
  4853. }
  4854. // FIXME: we don't provide our width so that it doesn't get feed back into AutoFit. Should manage that better so we can still hover without extending ContentsSize
  4855. const ImRect text_bb(bb.Min, bb.Min + ImVec2(g.FontSize + style.FramePadding.x*2*2,0) + label_size);
  4856. ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y), display_frame ? style.FramePadding.y : 0.0f);
  4857. // When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behavior).
  4858. // NB- If we are above max depth we still allow manually opened nodes to be logged.
  4859. if (g.LogEnabled && !display_frame && window->DC.TreeDepth < g.LogAutoExpandMaxDepth)
  4860. opened = true;
  4861. if (!ItemAdd(bb, &id))
  4862. return opened;
  4863. bool hovered, held;
  4864. bool pressed = ButtonBehavior(display_frame ? bb : text_bb, id, &hovered, &held, false);
  4865. if (pressed)
  4866. {
  4867. opened = !opened;
  4868. storage->SetInt(id, opened);
  4869. }
  4870. // Render
  4871. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
  4872. if (display_frame)
  4873. {
  4874. // Framed type
  4875. RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
  4876. RenderCollapseTriangle(bb.Min + style.FramePadding, opened, 1.0f, true);
  4877. if (g.LogEnabled)
  4878. {
  4879. // NB: '##' is normally used to hide text (as a library-wide feature), so we need to specify the text range to make sure the ## aren't stripped out here.
  4880. const char log_prefix[] = "\n##";
  4881. LogText(bb.Min + style.FramePadding, log_prefix, log_prefix+3);
  4882. }
  4883. RenderText(bb.Min + style.FramePadding + ImVec2(g.FontSize + style.FramePadding.x*2,0), label);
  4884. if (g.LogEnabled)
  4885. {
  4886. const char log_suffix[] = "##";
  4887. LogText(bb.Min + style.FramePadding, log_suffix, log_suffix+2);
  4888. }
  4889. }
  4890. else
  4891. {
  4892. // Unframed typed for tree nodes
  4893. if ((held && hovered) || hovered)
  4894. RenderFrame(bb.Min, bb.Max, col, false);
  4895. RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, g.FontSize*0.15f), opened, 0.70f, false);
  4896. if (g.LogEnabled)
  4897. LogText(bb.Min, ">");
  4898. RenderText(bb.Min + ImVec2(g.FontSize + style.FramePadding.x*2,0), label);
  4899. }
  4900. return opened;
  4901. }
  4902. void ImGui::Bullet()
  4903. {
  4904. ImGuiState& g = *GImGui;
  4905. ImGuiWindow* window = GetCurrentWindow();
  4906. if (window->SkipItems)
  4907. return;
  4908. const ImGuiStyle& style = g.Style;
  4909. const float line_height = g.FontSize;
  4910. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height, line_height));
  4911. ItemSize(bb);
  4912. if (!ItemAdd(bb, NULL))
  4913. return;
  4914. // Render
  4915. const float bullet_size = line_height*0.15f;
  4916. window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text));
  4917. // Stay on same line
  4918. ImGui::SameLine(0, -1);
  4919. }
  4920. // Text with a little bullet aligned to the typical tree node.
  4921. void ImGui::BulletTextV(const char* fmt, va_list args)
  4922. {
  4923. ImGuiState& g = *GImGui;
  4924. ImGuiWindow* window = GetCurrentWindow();
  4925. if (window->SkipItems)
  4926. return;
  4927. const char* text_begin = g.TempBuffer;
  4928. const char* text_end = text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  4929. const ImGuiStyle& style = g.Style;
  4930. const float line_height = g.FontSize;
  4931. const ImVec2 label_size = CalcTextSize(text_begin, text_end, true);
  4932. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (label_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + label_size); // Empty text doesn't add padding
  4933. ItemSize(bb);
  4934. if (!ItemAdd(bb, NULL))
  4935. return;
  4936. // Render
  4937. const float bullet_size = line_height*0.15f;
  4938. window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text));
  4939. RenderText(bb.Min+ImVec2(g.FontSize + style.FramePadding.x*2,0), text_begin, text_end);
  4940. }
  4941. void ImGui::BulletText(const char* fmt, ...)
  4942. {
  4943. va_list args;
  4944. va_start(args, fmt);
  4945. BulletTextV(fmt, args);
  4946. va_end(args);
  4947. }
  4948. // If returning 'true' the node is open and the user is responsible for calling TreePop
  4949. bool ImGui::TreeNodeV(const char* str_id, const char* fmt, va_list args)
  4950. {
  4951. ImGuiState& g = *GImGui;
  4952. ImGuiWindow* window = GetCurrentWindow();
  4953. if (window->SkipItems)
  4954. return false;
  4955. ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  4956. if (!str_id || !str_id[0])
  4957. str_id = fmt;
  4958. ImGui::PushID(str_id);
  4959. const bool opened = ImGui::CollapsingHeader(g.TempBuffer, "", false);
  4960. ImGui::PopID();
  4961. if (opened)
  4962. ImGui::TreePush(str_id);
  4963. return opened;
  4964. }
  4965. bool ImGui::TreeNode(const char* str_id, const char* fmt, ...)
  4966. {
  4967. va_list args;
  4968. va_start(args, fmt);
  4969. bool s = TreeNodeV(str_id, fmt, args);
  4970. va_end(args);
  4971. return s;
  4972. }
  4973. // If returning 'true' the node is open and the user is responsible for calling TreePop
  4974. bool ImGui::TreeNodeV(const void* ptr_id, const char* fmt, va_list args)
  4975. {
  4976. ImGuiState& g = *GImGui;
  4977. ImGuiWindow* window = GetCurrentWindow();
  4978. if (window->SkipItems)
  4979. return false;
  4980. ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
  4981. if (!ptr_id)
  4982. ptr_id = fmt;
  4983. ImGui::PushID(ptr_id);
  4984. const bool opened = ImGui::CollapsingHeader(g.TempBuffer, "", false);
  4985. ImGui::PopID();
  4986. if (opened)
  4987. ImGui::TreePush(ptr_id);
  4988. return opened;
  4989. }
  4990. bool ImGui::TreeNode(const void* ptr_id, const char* fmt, ...)
  4991. {
  4992. va_list args;
  4993. va_start(args, fmt);
  4994. bool s = TreeNodeV(ptr_id, fmt, args);
  4995. va_end(args);
  4996. return s;
  4997. }
  4998. bool ImGui::TreeNode(const char* str_label_id)
  4999. {
  5000. return TreeNode(str_label_id, "%s", str_label_id);
  5001. }
  5002. void ImGui::SetNextTreeNodeOpened(bool opened, ImGuiSetCond cond)
  5003. {
  5004. ImGuiState& g = *GImGui;
  5005. g.SetNextTreeNodeOpenedVal = opened;
  5006. g.SetNextTreeNodeOpenedCond = cond ? cond : ImGuiSetCond_Always;
  5007. }
  5008. void ImGui::PushID(const char* str_id)
  5009. {
  5010. ImGuiWindow* window = GetCurrentWindow();
  5011. window->IDStack.push_back(window->GetID(str_id));
  5012. }
  5013. void ImGui::PushID(const char* str_id_begin, const char* str_id_end)
  5014. {
  5015. ImGuiWindow* window = GetCurrentWindow();
  5016. window->IDStack.push_back(window->GetID(str_id_begin, str_id_end));
  5017. }
  5018. void ImGui::PushID(const void* ptr_id)
  5019. {
  5020. ImGuiWindow* window = GetCurrentWindow();
  5021. window->IDStack.push_back(window->GetID(ptr_id));
  5022. }
  5023. void ImGui::PushID(const int int_id)
  5024. {
  5025. const void* ptr_id = (void*)(intptr_t)int_id;
  5026. ImGuiWindow* window = GetCurrentWindow();
  5027. window->IDStack.push_back(window->GetID(ptr_id));
  5028. }
  5029. void ImGui::PopID()
  5030. {
  5031. ImGuiWindow* window = GetCurrentWindow();
  5032. window->IDStack.pop_back();
  5033. }
  5034. ImGuiID ImGui::GetID(const char* str_id)
  5035. {
  5036. return GImGui->CurrentWindow->GetID(str_id);
  5037. }
  5038. ImGuiID ImGui::GetID(const char* str_id_begin, const char* str_id_end)
  5039. {
  5040. return GImGui->CurrentWindow->GetID(str_id_begin, str_id_end);
  5041. }
  5042. ImGuiID ImGui::GetID(const void* ptr_id)
  5043. {
  5044. return GImGui->CurrentWindow->GetID(ptr_id);
  5045. }
  5046. // User can input math operators (e.g. +100) to edit a numerical values.
  5047. // NB: only call right after InputText because we are using its InitialValue storage
  5048. static void InputTextApplyArithmeticOp(const char* buf, float *v)
  5049. {
  5050. while (ImCharIsSpace(*buf))
  5051. buf++;
  5052. // We don't support '-' op because it would conflict with inputing negative value.
  5053. // Instead you can use +-100 to subtract from an existing value
  5054. char op = buf[0];
  5055. if (op == '+' || op == '*' || op == '/')
  5056. {
  5057. buf++;
  5058. while (ImCharIsSpace(*buf))
  5059. buf++;
  5060. }
  5061. else
  5062. {
  5063. op = 0;
  5064. }
  5065. if (!buf[0])
  5066. return;
  5067. float ref_v = *v;
  5068. if (op)
  5069. if (sscanf(GImGui->InputTextState.InitialText.begin(), "%f", &ref_v) < 1)
  5070. return;
  5071. float op_v = 0.0f;
  5072. if (sscanf(buf, "%f", &op_v) < 1)
  5073. return;
  5074. if (op == '+')
  5075. *v = ref_v + op_v; // add (uses "+-" to substract)
  5076. else if (op == '*')
  5077. *v = ref_v * op_v; // multiply
  5078. else if (op == '/')
  5079. {
  5080. if (op_v == 0.0f) // divide
  5081. return;
  5082. *v = ref_v / op_v;
  5083. }
  5084. else
  5085. *v = op_v; // Constant
  5086. }
  5087. // Create text input in place of a slider (when CTRL+Clicking on slider)
  5088. static bool SliderFloatAsInputText(const char* label, float* v, ImGuiID id, int decimal_precision)
  5089. {
  5090. ImGuiState& g = *GImGui;
  5091. ImGuiWindow* window = GetCurrentWindow();
  5092. char text_buf[64];
  5093. ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%.*f", decimal_precision, *v);
  5094. SetActiveId(g.ScalarAsInputTextId, window);
  5095. g.HoveredId = 0;
  5096. // Our replacement widget will override the focus ID (registered previously to allow for a TAB focus to happen)
  5097. window->FocusItemUnregister();
  5098. bool value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll);
  5099. if (g.ScalarAsInputTextId == 0)
  5100. {
  5101. // First frame
  5102. IM_ASSERT(g.ActiveId == id); // InputText ID expected to match the Slider ID (else we'd need to store them both, which is also possible)
  5103. g.ScalarAsInputTextId = g.ActiveId;
  5104. g.HoveredId = id;
  5105. }
  5106. else if (g.ActiveId != g.ScalarAsInputTextId)
  5107. {
  5108. // Release
  5109. g.ScalarAsInputTextId = 0;
  5110. }
  5111. if (value_changed)
  5112. {
  5113. InputTextApplyArithmeticOp(text_buf, v);
  5114. }
  5115. return value_changed;
  5116. }
  5117. // Parse display precision back from the display format string
  5118. static inline void ParseFormatPrecision(const char* fmt, int& decimal_precision)
  5119. {
  5120. while ((fmt = strchr(fmt, '%')) != NULL)
  5121. {
  5122. fmt++;
  5123. if (fmt[0] == '%') { fmt++; continue; } // Ignore "%%"
  5124. while (*fmt >= '0' && *fmt <= '9')
  5125. fmt++;
  5126. if (*fmt == '.')
  5127. {
  5128. decimal_precision = atoi(fmt + 1);
  5129. if (decimal_precision < 0 || decimal_precision > 10)
  5130. decimal_precision = 3;
  5131. }
  5132. break;
  5133. }
  5134. }
  5135. static inline float RoundScalar(float value, int decimal_precision)
  5136. {
  5137. // Round past decimal precision
  5138. // 0: 1, 1: 0.1, 2: 0.01, etc.
  5139. // So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0
  5140. // FIXME: Investigate better rounding methods
  5141. float min_step = 1.0f / powf(10.0f, (float)decimal_precision);
  5142. bool negative = value < 0.0f;
  5143. value = fabsf(value);
  5144. float remainder = fmodf(value, min_step);
  5145. if (remainder <= min_step*0.5f)
  5146. value -= remainder;
  5147. else
  5148. value += (min_step - remainder);
  5149. return negative ? -value : value;
  5150. }
  5151. static bool SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, bool horizontal)
  5152. {
  5153. ImGuiState& g = *GImGui;
  5154. ImGuiWindow* window = GetCurrentWindow();
  5155. const ImGuiStyle& style = g.Style;
  5156. // Draw frame
  5157. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  5158. const bool is_non_linear = fabsf(power - 1.0f) > 0.0001f;
  5159. const float padding = horizontal ? style.FramePadding.x : style.FramePadding.y;
  5160. const float slider_sz = horizontal ? (frame_bb.GetWidth() - padding * 2.0f) : (frame_bb.GetHeight() - padding * 2.0f);
  5161. float grab_sz;
  5162. if (decimal_precision > 0)
  5163. grab_sz = ImMin(style.GrabMinSize, slider_sz);
  5164. else
  5165. grab_sz = ImMin(ImMax(1.0f * (slider_sz / (v_max-v_min+1.0f)), style.GrabMinSize), slider_sz); // Integer sliders, if possible have the grab size represent 1 unit
  5166. const float slider_usable_sz = slider_sz - grab_sz;
  5167. const float slider_usable_pos_min = (horizontal ? frame_bb.Min.x : frame_bb.Min.y) + padding + grab_sz*0.5f;
  5168. const float slider_usable_pos_max = (horizontal ? frame_bb.Max.x : frame_bb.Max.y) - padding - grab_sz*0.5f;
  5169. bool value_changed = false;
  5170. // For logarithmic sliders that cross over sign boundary we want the exponential increase to be symmetric around 0.0f
  5171. float linear_zero_pos = 0.0f; // 0.0->1.0f
  5172. if (v_min * v_max < 0.0f)
  5173. {
  5174. // Different sign
  5175. const float linear_dist_min_to_0 = powf(fabsf(0.0f - v_min), 1.0f/power);
  5176. const float linear_dist_max_to_0 = powf(fabsf(v_max - 0.0f), 1.0f/power);
  5177. linear_zero_pos = linear_dist_min_to_0 / (linear_dist_min_to_0+linear_dist_max_to_0);
  5178. }
  5179. else
  5180. {
  5181. // Same sign
  5182. linear_zero_pos = v_min < 0.0f ? 1.0f : 0.0f;
  5183. }
  5184. // Process clicking on the slider
  5185. if (g.ActiveId == id)
  5186. {
  5187. if (g.IO.MouseDown[0])
  5188. {
  5189. const float mouse_abs_pos = horizontal ? g.IO.MousePos.x : g.IO.MousePos.y;
  5190. float normalized_pos = ImClamp((mouse_abs_pos - slider_usable_pos_min) / slider_usable_sz, 0.0f, 1.0f);
  5191. if (!horizontal)
  5192. normalized_pos = 1.0f - normalized_pos;
  5193. float new_value;
  5194. if (is_non_linear)
  5195. {
  5196. // Account for logarithmic scale on both sides of the zero
  5197. if (normalized_pos < linear_zero_pos)
  5198. {
  5199. // Negative: rescale to the negative range before powering
  5200. float a = 1.0f - (normalized_pos / linear_zero_pos);
  5201. a = powf(a, power);
  5202. new_value = ImLerp(ImMin(v_max,0.0f), v_min, a);
  5203. }
  5204. else
  5205. {
  5206. // Positive: rescale to the positive range before powering
  5207. float a;
  5208. if (fabsf(linear_zero_pos - 1.0f) > 1.e-6)
  5209. a = (normalized_pos - linear_zero_pos) / (1.0f - linear_zero_pos);
  5210. else
  5211. a = normalized_pos;
  5212. a = powf(a, power);
  5213. new_value = ImLerp(ImMax(v_min,0.0f), v_max, a);
  5214. }
  5215. }
  5216. else
  5217. {
  5218. // Linear slider
  5219. new_value = ImLerp(v_min, v_max, normalized_pos);
  5220. }
  5221. // Round past decimal precision
  5222. new_value = RoundScalar(new_value, decimal_precision);
  5223. if (*v != new_value)
  5224. {
  5225. *v = new_value;
  5226. value_changed = true;
  5227. }
  5228. }
  5229. else
  5230. {
  5231. SetActiveId(0);
  5232. }
  5233. }
  5234. // Calculate slider grab positioning
  5235. float grab_t;
  5236. if (is_non_linear)
  5237. {
  5238. float v_clamped = ImClamp(*v, v_min, v_max);
  5239. if (v_clamped < 0.0f)
  5240. {
  5241. const float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min);
  5242. grab_t = (1.0f - powf(f, 1.0f/power)) * linear_zero_pos;
  5243. }
  5244. else
  5245. {
  5246. const float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min));
  5247. grab_t = linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos);
  5248. }
  5249. }
  5250. else
  5251. {
  5252. // Linear slider
  5253. grab_t = (ImClamp(*v, v_min, v_max) - v_min) / (v_max - v_min);
  5254. }
  5255. // Draw
  5256. if (!horizontal)
  5257. grab_t = 1.0f - grab_t;
  5258. const float grab_pos = ImLerp(slider_usable_pos_min, slider_usable_pos_max, grab_t);
  5259. ImRect grab_bb;
  5260. if (horizontal)
  5261. grab_bb = ImRect(ImVec2(grab_pos - grab_sz*0.5f, frame_bb.Min.y + 2.0f), ImVec2(grab_pos + grab_sz*0.5f, frame_bb.Max.y - 2.0f));
  5262. else
  5263. grab_bb = ImRect(ImVec2(frame_bb.Min.x + 2.0f, grab_pos - grab_sz*0.5f), ImVec2(frame_bb.Max.x - 2.0f, grab_pos + grab_sz*0.5f));
  5264. window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab));
  5265. return value_changed;
  5266. }
  5267. // Use power!=1.0 for logarithmic sliders.
  5268. // Adjust display_format to decorate the value with a prefix or a suffix.
  5269. // "%.3f" 1.234
  5270. // "%5.2f secs" 01.23 secs
  5271. // "Gold: %.0f" Gold: 1
  5272. bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format, float power)
  5273. {
  5274. ImGuiState& g = *GImGui;
  5275. ImGuiWindow* window = GetCurrentWindow();
  5276. if (window->SkipItems)
  5277. return false;
  5278. const ImGuiStyle& style = g.Style;
  5279. const ImGuiID id = window->GetID(label);
  5280. const float w = ImGui::CalcItemWidth();
  5281. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5282. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
  5283. const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
  5284. // NB- we don't call ItemSize() yet because we may turn into a text edit box below
  5285. if (!ItemAdd(total_bb, &id))
  5286. {
  5287. ItemSize(total_bb, style.FramePadding.y);
  5288. return false;
  5289. }
  5290. const bool hovered = IsHovered(frame_bb, id);
  5291. if (hovered)
  5292. g.HoveredId = id;
  5293. if (!display_format)
  5294. display_format = "%.3f";
  5295. int decimal_precision = 3;
  5296. ParseFormatPrecision(display_format, decimal_precision);
  5297. // Tabbing or CTRL-clicking on Slider turns it into an input box
  5298. bool start_text_input = false;
  5299. const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id);
  5300. if (tab_focus_requested || (hovered && g.IO.MouseClicked[0]))
  5301. {
  5302. SetActiveId(id, window);
  5303. FocusWindow(window);
  5304. const bool is_ctrl_down = g.IO.KeyCtrl;
  5305. if (tab_focus_requested || is_ctrl_down)
  5306. {
  5307. start_text_input = true;
  5308. g.ScalarAsInputTextId = 0;
  5309. }
  5310. }
  5311. if (start_text_input || (g.ActiveId == id && g.ScalarAsInputTextId == id))
  5312. return SliderFloatAsInputText(label, v, id, decimal_precision);
  5313. ItemSize(total_bb, style.FramePadding.y);
  5314. // Actual slider behavior + render grab
  5315. const bool value_changed = SliderBehavior(frame_bb, id, v, v_min, v_max, power, decimal_precision, true);
  5316. // Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
  5317. char value_buf[64];
  5318. const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
  5319. RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImGuiAlign_Center|ImGuiAlign_VCenter);
  5320. if (label_size.x > 0.0f)
  5321. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  5322. return value_changed;
  5323. }
  5324. bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format, float power)
  5325. {
  5326. ImGuiState& g = *GImGui;
  5327. ImGuiWindow* window = GetCurrentWindow();
  5328. if (window->SkipItems)
  5329. return false;
  5330. const ImGuiStyle& style = g.Style;
  5331. const ImGuiID id = window->GetID(label);
  5332. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5333. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size);
  5334. const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
  5335. ItemSize(bb, style.FramePadding.y);
  5336. if (!ItemAdd(frame_bb, &id))
  5337. return false;
  5338. const bool hovered = IsHovered(frame_bb, id);
  5339. if (hovered)
  5340. g.HoveredId = id;
  5341. if (!display_format)
  5342. display_format = "%.3f";
  5343. int decimal_precision = 3;
  5344. ParseFormatPrecision(display_format, decimal_precision);
  5345. if (hovered && g.IO.MouseClicked[0])
  5346. {
  5347. SetActiveId(id, window);
  5348. FocusWindow(window);
  5349. }
  5350. // Actual slider behavior + render grab
  5351. bool value_changed = SliderBehavior(frame_bb, id, v, v_min, v_max, power, decimal_precision, false);
  5352. // Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
  5353. // For the vertical slider we allow centered text to overlap the frame padding
  5354. char value_buf[64];
  5355. char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
  5356. RenderTextClipped(ImVec2(frame_bb.Min.x, frame_bb.Min.y + style.FramePadding.y), frame_bb.Max, value_buf, value_buf_end, NULL, ImGuiAlign_Center);
  5357. if (label_size.x > 0.0f)
  5358. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  5359. return value_changed;
  5360. }
  5361. bool ImGui::SliderAngle(const char* label, float* v_rad, float v_degrees_min, float v_degrees_max)
  5362. {
  5363. float v_deg = (*v_rad) * 360.0f / (2*IM_PI);
  5364. bool value_changed = ImGui::SliderFloat(label, &v_deg, v_degrees_min, v_degrees_max, "%.0f deg", 1.0f);
  5365. *v_rad = v_deg * (2*IM_PI) / 360.0f;
  5366. return value_changed;
  5367. }
  5368. bool ImGui::SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format)
  5369. {
  5370. if (!display_format)
  5371. display_format = "%.0f";
  5372. float v_f = (float)*v;
  5373. bool value_changed = ImGui::SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f);
  5374. *v = (int)v_f;
  5375. return value_changed;
  5376. }
  5377. bool ImGui::VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format)
  5378. {
  5379. if (!display_format)
  5380. display_format = "%.0f";
  5381. float v_f = (float)*v;
  5382. bool value_changed = ImGui::VSliderFloat(label, size, &v_f, (float)v_min, (float)v_max, display_format, 1.0f);
  5383. *v = (int)v_f;
  5384. return value_changed;
  5385. }
  5386. // Add multiple sliders on 1 line for compact edition of multiple components
  5387. static bool SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* display_format, float power)
  5388. {
  5389. ImGuiState& g = *GImGui;
  5390. ImGuiWindow* window = GetCurrentWindow();
  5391. if (window->SkipItems)
  5392. return false;
  5393. bool value_changed = false;
  5394. ImGui::BeginGroup();
  5395. ImGui::PushID(label);
  5396. PushMultiItemsWidths(components);
  5397. for (int i = 0; i < components; i++)
  5398. {
  5399. ImGui::PushID(i);
  5400. value_changed |= ImGui::SliderFloat("##v", &v[i], v_min, v_max, display_format, power);
  5401. ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
  5402. ImGui::PopID();
  5403. ImGui::PopItemWidth();
  5404. }
  5405. ImGui::PopID();
  5406. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  5407. ImGui::EndGroup();
  5408. return value_changed;
  5409. }
  5410. bool ImGui::SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format, float power)
  5411. {
  5412. return SliderFloatN(label, v, 2, v_min, v_max, display_format, power);
  5413. }
  5414. bool ImGui::SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format, float power)
  5415. {
  5416. return SliderFloatN(label, v, 3, v_min, v_max, display_format, power);
  5417. }
  5418. bool ImGui::SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format, float power)
  5419. {
  5420. return SliderFloatN(label, v, 4, v_min, v_max, display_format, power);
  5421. }
  5422. static bool SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* display_format)
  5423. {
  5424. ImGuiState& g = *GImGui;
  5425. ImGuiWindow* window = GetCurrentWindow();
  5426. if (window->SkipItems)
  5427. return false;
  5428. bool value_changed = false;
  5429. ImGui::BeginGroup();
  5430. ImGui::PushID(label);
  5431. PushMultiItemsWidths(components);
  5432. for (int i = 0; i < components; i++)
  5433. {
  5434. ImGui::PushID(i);
  5435. value_changed |= ImGui::SliderInt("##v", &v[i], v_min, v_max, display_format);
  5436. ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
  5437. ImGui::PopID();
  5438. ImGui::PopItemWidth();
  5439. }
  5440. ImGui::PopID();
  5441. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  5442. ImGui::EndGroup();
  5443. return value_changed;
  5444. }
  5445. bool ImGui::SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format)
  5446. {
  5447. return SliderIntN(label, v, 2, v_min, v_max, display_format);
  5448. }
  5449. bool ImGui::SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format)
  5450. {
  5451. return SliderIntN(label, v, 3, v_min, v_max, display_format);
  5452. }
  5453. bool ImGui::SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format)
  5454. {
  5455. return SliderIntN(label, v, 4, v_min, v_max, display_format);
  5456. }
  5457. // FIXME-WIP: Work in progress. May change API / behavior.
  5458. static bool DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_speed, float v_min, float v_max, int decimal_precision, float power)
  5459. {
  5460. ImGuiState& g = *GImGui;
  5461. ImGuiWindow* window = GetCurrentWindow();
  5462. const ImGuiStyle& style = g.Style;
  5463. // Draw frame
  5464. const ImU32 frame_col = window->Color(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
  5465. RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, style.FrameRounding);
  5466. bool value_changed = false;
  5467. // Process clicking on the drag
  5468. if (g.ActiveId == id)
  5469. {
  5470. if (g.IO.MouseDown[0])
  5471. {
  5472. if (g.ActiveIdIsJustActivated)
  5473. {
  5474. // Lock current value on click
  5475. g.DragCurrentValue = *v;
  5476. g.DragLastMouseDelta = ImVec2(0.f, 0.f);
  5477. }
  5478. const ImVec2 mouse_drag_delta = ImGui::GetMouseDragDelta(0, 1.0f);
  5479. if (fabsf(mouse_drag_delta.x - g.DragLastMouseDelta.x) > 0.0f)
  5480. {
  5481. float speed = v_speed;
  5482. if (speed == 0.0f && (v_max - v_min) != 0.0f && (v_max - v_min) < FLT_MAX)
  5483. speed = (v_max - v_min) * g.DragSpeedDefaultRatio;
  5484. if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f)
  5485. speed = speed * g.DragSpeedScaleFast;
  5486. if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f)
  5487. speed = speed * g.DragSpeedScaleSlow;
  5488. float v_cur = g.DragCurrentValue;
  5489. float delta = (mouse_drag_delta.x - g.DragLastMouseDelta.x) * speed;
  5490. if (fabsf(power - 1.0f) > 0.001f)
  5491. {
  5492. // Logarithmic curve on both side of 0.0
  5493. float v0_abs = v_cur >= 0.0f ? v_cur : -v_cur;
  5494. float v0_sign = v_cur >= 0.0f ? 1.0f : -1.0f;
  5495. float v1 = powf(v0_abs, 1.0f / power) + (delta * v0_sign);
  5496. float v1_abs = v1 >= 0.0f ? v1 : -v1;
  5497. float v1_sign = v1 >= 0.0f ? 1.0f : -1.0f; // Crossed sign line
  5498. v_cur = powf(v1_abs, power) * v0_sign * v1_sign; // Reapply sign
  5499. }
  5500. else
  5501. {
  5502. v_cur += delta;
  5503. }
  5504. g.DragLastMouseDelta.x = mouse_drag_delta.x;
  5505. // Clamp
  5506. if (v_min < v_max)
  5507. v_cur = ImClamp(v_cur, v_min, v_max);
  5508. g.DragCurrentValue = v_cur;
  5509. // Round to user desired precision, then apply
  5510. v_cur = RoundScalar(v_cur, decimal_precision);
  5511. if (*v != v_cur)
  5512. {
  5513. *v = v_cur;
  5514. value_changed = true;
  5515. }
  5516. }
  5517. }
  5518. else
  5519. {
  5520. SetActiveId(0);
  5521. }
  5522. }
  5523. return value_changed;
  5524. }
  5525. bool ImGui::DragFloat(const char* label, float *v, float v_speed, float v_min, float v_max, const char* display_format, float power)
  5526. {
  5527. ImGuiState& g = *GImGui;
  5528. ImGuiWindow* window = GetCurrentWindow();
  5529. if (window->SkipItems)
  5530. return false;
  5531. const ImGuiStyle& style = g.Style;
  5532. const ImGuiID id = window->GetID(label);
  5533. const float w = ImGui::CalcItemWidth();
  5534. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5535. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
  5536. const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
  5537. const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
  5538. // NB- we don't call ItemSize() yet because we may turn into a text edit box below
  5539. if (!ItemAdd(total_bb, &id))
  5540. {
  5541. ItemSize(total_bb, style.FramePadding.y);
  5542. return false;
  5543. }
  5544. const bool hovered = IsHovered(frame_bb, id);
  5545. if (hovered)
  5546. g.HoveredId = id;
  5547. if (!display_format)
  5548. display_format = "%.3f";
  5549. int decimal_precision = 3;
  5550. ParseFormatPrecision(display_format, decimal_precision);
  5551. // Tabbing or CTRL-clicking on Drag turns it into an input box
  5552. bool start_text_input = false;
  5553. const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id);
  5554. if (tab_focus_requested || (hovered && (g.IO.MouseClicked[0] | g.IO.MouseDoubleClicked[0])))
  5555. {
  5556. SetActiveId(id, window);
  5557. FocusWindow(window);
  5558. if (tab_focus_requested || g.IO.KeyCtrl || g.IO.MouseDoubleClicked[0])
  5559. {
  5560. start_text_input = true;
  5561. g.ScalarAsInputTextId = 0;
  5562. }
  5563. }
  5564. if (start_text_input || (g.ActiveId == id && g.ScalarAsInputTextId == id))
  5565. return SliderFloatAsInputText(label, v, id, decimal_precision);
  5566. ItemSize(total_bb, style.FramePadding.y);
  5567. // Actual drag behavior
  5568. const bool value_changed = DragBehavior(frame_bb, id, v, v_speed, v_min, v_max, decimal_precision, power);
  5569. // Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
  5570. char value_buf[64];
  5571. const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
  5572. RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImGuiAlign_Center|ImGuiAlign_VCenter);
  5573. if (label_size.x > 0.0f)
  5574. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label);
  5575. return value_changed;
  5576. }
  5577. static bool DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* display_format, float power)
  5578. {
  5579. ImGuiState& g = *GImGui;
  5580. ImGuiWindow* window = GetCurrentWindow();
  5581. if (window->SkipItems)
  5582. return false;
  5583. bool value_changed = false;
  5584. ImGui::BeginGroup();
  5585. ImGui::PushID(label);
  5586. PushMultiItemsWidths(components);
  5587. for (int i = 0; i < components; i++)
  5588. {
  5589. ImGui::PushID(i);
  5590. value_changed |= ImGui::DragFloat("##v", &v[i], v_speed, v_min, v_max, display_format, power);
  5591. ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
  5592. ImGui::PopID();
  5593. ImGui::PopItemWidth();
  5594. }
  5595. ImGui::PopID();
  5596. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  5597. ImGui::EndGroup();
  5598. return value_changed;
  5599. }
  5600. bool ImGui::DragFloat2(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power)
  5601. {
  5602. return DragFloatN(label, v, 2, v_speed, v_min, v_max, display_format, power);
  5603. }
  5604. bool ImGui::DragFloat3(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power)
  5605. {
  5606. return DragFloatN(label, v, 3, v_speed, v_min, v_max, display_format, power);
  5607. }
  5608. bool ImGui::DragFloat4(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power)
  5609. {
  5610. return DragFloatN(label, v, 4, v_speed, v_min, v_max, display_format, power);
  5611. }
  5612. bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_current_max, float v_speed, float v_min, float v_max, const char* display_format, const char* display_format_max, float power)
  5613. {
  5614. ImGuiState& g = *GImGui;
  5615. ImGuiWindow* window = GetCurrentWindow();
  5616. if (window->SkipItems)
  5617. return false;
  5618. ImGui::PushID(label);
  5619. ImGui::BeginGroup();
  5620. PushMultiItemsWidths(2);
  5621. bool value_changed = ImGui::DragFloat("##min", v_current_min, v_speed, (v_min >= v_max) ? -FLT_MAX : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), display_format, power);
  5622. ImGui::PopItemWidth();
  5623. ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
  5624. value_changed |= ImGui::DragFloat("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? FLT_MAX : v_max, display_format_max ? display_format_max : display_format, power);
  5625. ImGui::PopItemWidth();
  5626. ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
  5627. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  5628. ImGui::EndGroup();
  5629. ImGui::PopID();
  5630. return value_changed;
  5631. }
  5632. // NB: v_speed is float to allow adjusting the drag speed with more precision
  5633. bool ImGui::DragInt(const char* label, int* v, float v_speed, int v_min, int v_max, const char* display_format)
  5634. {
  5635. if (!display_format)
  5636. display_format = "%.0f";
  5637. float v_f = (float)*v;
  5638. bool value_changed = ImGui::DragFloat(label, &v_f, v_speed, (float)v_min, (float)v_max, display_format);
  5639. *v = (int)v_f;
  5640. return value_changed;
  5641. }
  5642. static bool DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* display_format)
  5643. {
  5644. ImGuiState& g = *GImGui;
  5645. ImGuiWindow* window = GetCurrentWindow();
  5646. if (window->SkipItems)
  5647. return false;
  5648. bool value_changed = false;
  5649. ImGui::BeginGroup();
  5650. ImGui::PushID(label);
  5651. PushMultiItemsWidths(components);
  5652. for (int i = 0; i < components; i++)
  5653. {
  5654. ImGui::PushID(i);
  5655. value_changed |= ImGui::DragInt("##v", &v[i], v_speed, v_min, v_max, display_format);
  5656. ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
  5657. ImGui::PopID();
  5658. ImGui::PopItemWidth();
  5659. }
  5660. ImGui::PopID();
  5661. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  5662. ImGui::EndGroup();
  5663. return value_changed;
  5664. }
  5665. bool ImGui::DragInt2(const char* label, int v[2], float v_speed, int v_min, int v_max, const char* display_format)
  5666. {
  5667. return DragIntN(label, v, 2, v_speed, v_min, v_max, display_format);
  5668. }
  5669. bool ImGui::DragInt3(const char* label, int v[3], float v_speed, int v_min, int v_max, const char* display_format)
  5670. {
  5671. return DragIntN(label, v, 3, v_speed, v_min, v_max, display_format);
  5672. }
  5673. bool ImGui::DragInt4(const char* label, int v[4], float v_speed, int v_min, int v_max, const char* display_format)
  5674. {
  5675. return DragIntN(label, v, 4, v_speed, v_min, v_max, display_format);
  5676. }
  5677. bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_max, float v_speed, int v_min, int v_max, const char* display_format, const char* display_format_max)
  5678. {
  5679. ImGuiState& g = *GImGui;
  5680. ImGuiWindow* window = GetCurrentWindow();
  5681. if (window->SkipItems)
  5682. return false;
  5683. ImGui::PushID(label);
  5684. ImGui::BeginGroup();
  5685. PushMultiItemsWidths(2);
  5686. bool value_changed = ImGui::DragInt("##min", v_current_min, v_speed, (v_min >= v_max) ? IM_INT_MIN : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), display_format);
  5687. ImGui::PopItemWidth();
  5688. ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
  5689. value_changed |= ImGui::DragInt("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? IM_INT_MAX : v_max, display_format_max ? display_format_max : display_format);
  5690. ImGui::PopItemWidth();
  5691. ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
  5692. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  5693. ImGui::EndGroup();
  5694. ImGui::PopID();
  5695. return value_changed;
  5696. }
  5697. enum ImGuiPlotType
  5698. {
  5699. ImGuiPlotType_Lines,
  5700. ImGuiPlotType_Histogram
  5701. };
  5702. 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)
  5703. {
  5704. ImGuiState& g = *GImGui;
  5705. ImGuiWindow* window = GetCurrentWindow();
  5706. if (window->SkipItems)
  5707. return;
  5708. const ImGuiStyle& style = g.Style;
  5709. const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
  5710. if (graph_size.x == 0.0f)
  5711. graph_size.x = ImGui::CalcItemWidth() + (style.FramePadding.x * 2);
  5712. if (graph_size.y == 0.0f)
  5713. graph_size.y = label_size.y + (style.FramePadding.y * 2);
  5714. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y));
  5715. const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
  5716. const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0));
  5717. ItemSize(total_bb, style.FramePadding.y);
  5718. if (!ItemAdd(total_bb, NULL))
  5719. return;
  5720. // Determine scale from values if not specified
  5721. if (scale_min == FLT_MAX || scale_max == FLT_MAX)
  5722. {
  5723. float v_min = FLT_MAX;
  5724. float v_max = -FLT_MAX;
  5725. for (int i = 0; i < values_count; i++)
  5726. {
  5727. const float v = values_getter(data, i);
  5728. v_min = ImMin(v_min, v);
  5729. v_max = ImMax(v_max, v);
  5730. }
  5731. if (scale_min == FLT_MAX)
  5732. scale_min = v_min;
  5733. if (scale_max == FLT_MAX)
  5734. scale_max = v_max;
  5735. }
  5736. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  5737. int res_w = ImMin((int)graph_size.x, values_count);
  5738. if (plot_type == ImGuiPlotType_Lines)
  5739. res_w -= 1;
  5740. // Tooltip on hover
  5741. int v_hovered = -1;
  5742. if (IsMouseHoveringRect(inner_bb))
  5743. {
  5744. const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f);
  5745. const int v_idx = (int)(t * (values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0)));
  5746. IM_ASSERT(v_idx >= 0 && v_idx < values_count);
  5747. const float v0 = values_getter(data, (v_idx + values_offset) % values_count);
  5748. const float v1 = values_getter(data, (v_idx + 1 + values_offset) % values_count);
  5749. if (plot_type == ImGuiPlotType_Lines)
  5750. ImGui::SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx+1, v1);
  5751. else if (plot_type == ImGuiPlotType_Histogram)
  5752. ImGui::SetTooltip("%d: %8.4g", v_idx, v0);
  5753. v_hovered = v_idx;
  5754. }
  5755. const float t_step = 1.0f / (float)res_w;
  5756. float v0 = values_getter(data, (0 + values_offset) % values_count);
  5757. float t0 = 0.0f;
  5758. ImVec2 p0 = ImVec2( t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min)) );
  5759. const ImU32 col_base = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram);
  5760. const ImU32 col_hovered = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered);
  5761. for (int n = 0; n < res_w; n++)
  5762. {
  5763. const float t1 = t0 + t_step;
  5764. const int v_idx = (int)(t0 * values_count);
  5765. IM_ASSERT(v_idx >= 0 && v_idx < values_count);
  5766. const float v1 = values_getter(data, (v_idx + values_offset + 1) % values_count);
  5767. const ImVec2 p1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) );
  5768. // NB- Draw calls are merged together by the DrawList system.
  5769. if (plot_type == ImGuiPlotType_Lines)
  5770. window->DrawList->AddLine(ImLerp(inner_bb.Min, inner_bb.Max, p0), ImLerp(inner_bb.Min, inner_bb.Max, p1), v_hovered == v_idx ? col_hovered : col_base);
  5771. else if (plot_type == ImGuiPlotType_Histogram)
  5772. window->DrawList->AddRectFilled(ImLerp(inner_bb.Min, inner_bb.Max, p0), ImLerp(inner_bb.Min, inner_bb.Max, ImVec2(p1.x, 1.0f))+ImVec2(-1,0), v_hovered == v_idx ? col_hovered : col_base);
  5773. t0 = t1;
  5774. p0 = p1;
  5775. }
  5776. // Text overlay
  5777. if (overlay_text)
  5778. RenderTextClipped(ImVec2(frame_bb.Min.x, frame_bb.Min.y + style.FramePadding.y), frame_bb.Max, overlay_text, NULL, NULL, ImGuiAlign_Center);
  5779. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label);
  5780. }
  5781. struct ImGuiPlotArrayGetterData
  5782. {
  5783. const float* Values;
  5784. size_t Stride;
  5785. ImGuiPlotArrayGetterData(const float* values, size_t stride) { Values = values; Stride = stride; }
  5786. };
  5787. static float Plot_ArrayGetter(void* data, int idx)
  5788. {
  5789. ImGuiPlotArrayGetterData* plot_data = (ImGuiPlotArrayGetterData*)data;
  5790. const float v = *(float*)(void*)((unsigned char*)plot_data->Values + (size_t)idx * plot_data->Stride);
  5791. return v;
  5792. }
  5793. 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)
  5794. {
  5795. ImGuiPlotArrayGetterData data(values, stride);
  5796. Plot(ImGuiPlotType_Lines, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  5797. }
  5798. 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)
  5799. {
  5800. Plot(ImGuiPlotType_Lines, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  5801. }
  5802. 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)
  5803. {
  5804. ImGuiPlotArrayGetterData data(values, stride);
  5805. Plot(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  5806. }
  5807. 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)
  5808. {
  5809. Plot(ImGuiPlotType_Histogram, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  5810. }
  5811. bool ImGui::Checkbox(const char* label, bool* v)
  5812. {
  5813. ImGuiState& g = *GImGui;
  5814. ImGuiWindow* window = GetCurrentWindow();
  5815. if (window->SkipItems)
  5816. return false;
  5817. const ImGuiStyle& style = g.Style;
  5818. const ImGuiID id = window->GetID(label);
  5819. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5820. const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2, label_size.y + style.FramePadding.y*2));
  5821. ItemSize(check_bb, style.FramePadding.y);
  5822. ImRect total_bb = check_bb;
  5823. if (label_size.x > 0)
  5824. SameLine(0, (int)style.ItemInnerSpacing.x);
  5825. const ImRect text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + label_size);
  5826. if (label_size.x > 0)
  5827. {
  5828. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
  5829. total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
  5830. }
  5831. if (!ItemAdd(total_bb, &id))
  5832. return false;
  5833. bool hovered, held;
  5834. bool pressed = ButtonBehavior(total_bb, id, &hovered, &held, true);
  5835. if (pressed)
  5836. *v = !(*v);
  5837. RenderFrame(check_bb.Min, check_bb.Max, window->Color((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), true, style.FrameRounding);
  5838. if (*v)
  5839. {
  5840. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  5841. const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f;
  5842. window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), window->Color(ImGuiCol_CheckMark), style.FrameRounding);
  5843. }
  5844. if (g.LogEnabled)
  5845. LogText(text_bb.GetTL(), *v ? "[x]" : "[ ]");
  5846. RenderText(text_bb.GetTL(), label);
  5847. return pressed;
  5848. }
  5849. bool ImGui::CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value)
  5850. {
  5851. bool v = (*flags & flags_value) ? true : false;
  5852. bool pressed = ImGui::Checkbox(label, &v);
  5853. if (v)
  5854. *flags |= flags_value;
  5855. else
  5856. *flags &= ~flags_value;
  5857. return pressed;
  5858. }
  5859. bool ImGui::RadioButton(const char* label, bool active)
  5860. {
  5861. ImGuiState& g = *GImGui;
  5862. ImGuiWindow* window = GetCurrentWindow();
  5863. if (window->SkipItems)
  5864. return false;
  5865. const ImGuiStyle& style = g.Style;
  5866. const ImGuiID id = window->GetID(label);
  5867. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  5868. const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2-1, label_size.y + style.FramePadding.y*2-1));
  5869. ItemSize(check_bb, style.FramePadding.y);
  5870. ImRect total_bb = check_bb;
  5871. if (label_size.x > 0)
  5872. SameLine(0, (int)style.ItemInnerSpacing.x);
  5873. const ImRect text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size);
  5874. if (label_size.x > 0)
  5875. {
  5876. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
  5877. total_bb.Add(text_bb);
  5878. }
  5879. if (!ItemAdd(total_bb, &id))
  5880. return false;
  5881. ImVec2 center = check_bb.GetCenter();
  5882. center.x = (float)(int)center.x + 0.5f;
  5883. center.y = (float)(int)center.y + 0.5f;
  5884. const float radius = check_bb.GetHeight() * 0.5f;
  5885. bool hovered, held;
  5886. bool pressed = ButtonBehavior(total_bb, id, &hovered, &held, true);
  5887. window->DrawList->AddCircleFilled(center, radius, window->Color((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), 16);
  5888. if (active)
  5889. {
  5890. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  5891. const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f;
  5892. window->DrawList->AddCircleFilled(center, radius-pad, window->Color(ImGuiCol_CheckMark), 16);
  5893. }
  5894. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  5895. {
  5896. window->DrawList->AddCircle(center+ImVec2(1,1), radius, window->Color(ImGuiCol_BorderShadow), 16);
  5897. window->DrawList->AddCircle(center, radius, window->Color(ImGuiCol_Border), 16);
  5898. }
  5899. if (g.LogEnabled)
  5900. LogText(text_bb.GetTL(), active ? "(x)" : "( )");
  5901. RenderText(text_bb.GetTL(), label);
  5902. return pressed;
  5903. }
  5904. bool ImGui::RadioButton(const char* label, int* v, int v_button)
  5905. {
  5906. const bool pressed = ImGui::RadioButton(label, *v == v_button);
  5907. if (pressed)
  5908. {
  5909. *v = v_button;
  5910. }
  5911. return pressed;
  5912. }
  5913. static int InputTextCalcTextLenAndLineCount(const char* text_begin, const char** out_text_end)
  5914. {
  5915. int line_count = 0;
  5916. const char* s = text_begin;
  5917. while (char c = *s++) // We are only matching for \n so we can ignore UTF-8 decoding
  5918. if (c == '\n')
  5919. line_count++;
  5920. s--;
  5921. if (s[0] != '\n' && s[0] != '\r')
  5922. line_count++;
  5923. *out_text_end = s;
  5924. return line_count;
  5925. }
  5926. static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL, ImVec2* out_offset = NULL, bool stop_on_new_line = false)
  5927. {
  5928. ImFont* font = GImGui->Font;
  5929. const float line_height = GImGui->FontSize;
  5930. const float scale = line_height / font->FontSize;
  5931. ImVec2 text_size = ImVec2(0,0);
  5932. float line_width = 0.0f;
  5933. const ImWchar* s = text_begin;
  5934. while (s < text_end)
  5935. {
  5936. unsigned int c = (unsigned int)(*s++);
  5937. if (c == '\n')
  5938. {
  5939. text_size.x = ImMax(text_size.x, line_width);
  5940. text_size.y += line_height;
  5941. line_width = 0.0f;
  5942. if (stop_on_new_line)
  5943. break;
  5944. continue;
  5945. }
  5946. if (c == '\r')
  5947. continue;
  5948. const float char_width = font->GetCharAdvance((unsigned short)c) * scale;
  5949. line_width += char_width;
  5950. }
  5951. if (text_size.x < line_width)
  5952. text_size.x = line_width;
  5953. if (out_offset)
  5954. *out_offset = ImVec2(line_width, text_size.y + line_height); // offset allow for the possibility of sitting after a trailing \n
  5955. if (line_width > 0 || text_size.y == 0.0f) // whereas size.y will ignore the trailing \n
  5956. text_size.y += line_height;
  5957. if (remaining)
  5958. *remaining = s;
  5959. return text_size;
  5960. }
  5961. // 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)
  5962. static int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return (int)obj->CurLenW; }
  5963. static ImWchar STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return obj->Text[idx]; }
  5964. static float STB_TEXTEDIT_GETWIDTH(STB_TEXTEDIT_STRING* obj, int line_start_idx, int char_idx) { ImWchar c = obj->Text[line_start_idx+char_idx]; if (c == '\n') return STB_TEXTEDIT_GETWIDTH_NEWLINE; return GImGui->Font->GetCharAdvance(c) * (GImGui->FontSize / GImGui->Font->FontSize); }
  5965. static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : key; }
  5966. static ImWchar STB_TEXTEDIT_NEWLINE = '\n';
  5967. static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx)
  5968. {
  5969. const ImWchar* text = obj->Text.begin();
  5970. const ImWchar* text_remaining = NULL;
  5971. const ImVec2 size = InputTextCalcTextSizeW(text + line_start_idx, text + obj->CurLenW, &text_remaining, NULL, true);
  5972. r->x0 = 0.0f;
  5973. r->x1 = size.x;
  5974. r->baseline_y_delta = size.y;
  5975. r->ymin = 0.0f;
  5976. r->ymax = size.y;
  5977. r->num_chars = (int)(text_remaining - (text + line_start_idx));
  5978. }
  5979. static bool is_separator(unsigned int c) { return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; }
  5980. #define STB_TEXTEDIT_IS_SPACE(CH) ( ImCharIsSpace((unsigned int)CH) || is_separator((unsigned int)CH) )
  5981. static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n)
  5982. {
  5983. ImWchar* dst = obj->Text.begin() + pos;
  5984. // We maintain our buffer length in both UTF-8 and wchar formats
  5985. obj->CurLenA -= ImTextCountUtf8BytesFromStr(dst, dst + n);
  5986. obj->CurLenW -= n;
  5987. // Offset remaining text
  5988. const ImWchar* src = obj->Text.begin() + pos + n;
  5989. while (ImWchar c = *src++)
  5990. *dst++ = c;
  5991. *dst = '\0';
  5992. }
  5993. static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len)
  5994. {
  5995. const size_t text_len = obj->CurLenW;
  5996. if ((size_t)new_text_len + text_len + 1 > obj->Text.size())
  5997. return false;
  5998. const int new_text_len_utf8 = ImTextCountUtf8BytesFromStr(new_text, new_text + new_text_len);
  5999. if ((size_t)new_text_len_utf8 + obj->CurLenA + 1 > obj->BufSizeA)
  6000. return false;
  6001. ImWchar* text = obj->Text.begin();
  6002. if (pos != (int)text_len)
  6003. memmove(text + (size_t)pos + new_text_len, text + (size_t)pos, (text_len - (size_t)pos) * sizeof(ImWchar));
  6004. memcpy(text + (size_t)pos, new_text, (size_t)new_text_len * sizeof(ImWchar));
  6005. obj->CurLenW += new_text_len;
  6006. obj->CurLenA += new_text_len_utf8;
  6007. obj->Text[obj->CurLenW] = '\0';
  6008. return true;
  6009. }
  6010. // We don't use an enum so we can build even with conflicting symbols (if another user of stb_textedit.h leak their STB_TEXTEDIT_K_* symbols)
  6011. #define STB_TEXTEDIT_K_LEFT 0x10000 // keyboard input to move cursor left
  6012. #define STB_TEXTEDIT_K_RIGHT 0x10001 // keyboard input to move cursor right
  6013. #define STB_TEXTEDIT_K_UP 0x10002 // keyboard input to move cursor up
  6014. #define STB_TEXTEDIT_K_DOWN 0x10003 // keyboard input to move cursor down
  6015. #define STB_TEXTEDIT_K_LINESTART 0x10004 // keyboard input to move cursor to start of line
  6016. #define STB_TEXTEDIT_K_LINEEND 0x10005 // keyboard input to move cursor to end of line
  6017. #define STB_TEXTEDIT_K_TEXTSTART 0x10006 // keyboard input to move cursor to start of text
  6018. #define STB_TEXTEDIT_K_TEXTEND 0x10007 // keyboard input to move cursor to end of text
  6019. #define STB_TEXTEDIT_K_DELETE 0x10008 // keyboard input to delete selection or character under cursor
  6020. #define STB_TEXTEDIT_K_BACKSPACE 0x10009 // keyboard input to delete selection or character left of cursor
  6021. #define STB_TEXTEDIT_K_UNDO 0x1000A // keyboard input to perform undo
  6022. #define STB_TEXTEDIT_K_REDO 0x1000B // keyboard input to perform redo
  6023. #define STB_TEXTEDIT_K_WORDLEFT 0x1000C // keyboard input to move cursor left one word
  6024. #define STB_TEXTEDIT_K_WORDRIGHT 0x1000D // keyboard input to move cursor right one word
  6025. #define STB_TEXTEDIT_K_SHIFT 0x20000
  6026. #ifdef IMGUI_STB_NAMESPACE
  6027. namespace IMGUI_STB_NAMESPACE
  6028. {
  6029. #endif
  6030. #define STB_TEXTEDIT_IMPLEMENTATION
  6031. #include "stb_textedit.h"
  6032. #ifdef IMGUI_STB_NAMESPACE
  6033. }
  6034. #endif
  6035. void ImGuiTextEditState::OnKeyPressed(int key)
  6036. {
  6037. stb_textedit_key(this, &StbState, key);
  6038. CursorFollow = true;
  6039. CursorAnimReset();
  6040. }
  6041. // Public API to manipulate UTF-8 text
  6042. // We expose UTF-8 to the user (unlike the STB_TEXTEDIT_* functions which are manipulating wchar)
  6043. void ImGuiTextEditCallbackData::DeleteChars(int pos, int bytes_count)
  6044. {
  6045. char* dst = Buf + pos;
  6046. const char* src = Buf + pos + bytes_count;
  6047. while (char c = *src++)
  6048. *dst++ = c;
  6049. *dst = '\0';
  6050. BufDirty = true;
  6051. if (CursorPos + bytes_count >= pos)
  6052. CursorPos -= bytes_count;
  6053. else if (CursorPos >= pos)
  6054. CursorPos = pos;
  6055. SelectionStart = SelectionEnd = CursorPos;
  6056. }
  6057. void ImGuiTextEditCallbackData::InsertChars(int pos, const char* new_text, const char* new_text_end)
  6058. {
  6059. const size_t text_len = strlen(Buf);
  6060. if (!new_text_end)
  6061. new_text_end = new_text + strlen(new_text);
  6062. const size_t new_text_len = (size_t)(new_text_end - new_text);
  6063. if (new_text_len + text_len + 1 >= BufSize)
  6064. return;
  6065. size_t upos = (size_t)pos;
  6066. if (text_len != upos)
  6067. memmove(Buf + upos + new_text_len, Buf + upos, text_len - upos);
  6068. memcpy(Buf + upos, new_text, new_text_len * sizeof(char));
  6069. Buf[text_len + new_text_len] = '\0';
  6070. BufDirty = true;
  6071. if (CursorPos >= pos)
  6072. CursorPos += (int)new_text_len;
  6073. SelectionStart = SelectionEnd = CursorPos;
  6074. }
  6075. // Return false to discard a character.
  6076. static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data)
  6077. {
  6078. unsigned int c = *p_char;
  6079. if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF)))
  6080. {
  6081. bool pass = false;
  6082. pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline));
  6083. pass |= (c == '\t' && (flags & ImGuiInputTextFlags_AllowTabInput));
  6084. if (!pass)
  6085. return false;
  6086. }
  6087. if (c >= 0xE000 && c <= 0xF8FF) // Filter private Unicode range. I don't imagine anybody would want to input them. GLFW on OSX seems to send private characters for special keys like arrow keys.
  6088. return false;
  6089. if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank))
  6090. {
  6091. if (flags & ImGuiInputTextFlags_CharsDecimal)
  6092. if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
  6093. return false;
  6094. if (flags & ImGuiInputTextFlags_CharsHexadecimal)
  6095. if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
  6096. return false;
  6097. if (flags & ImGuiInputTextFlags_CharsUppercase)
  6098. if (c >= 'a' && c <= 'z')
  6099. *p_char = (c += (unsigned int)('A'-'a'));
  6100. if (flags & ImGuiInputTextFlags_CharsNoBlank)
  6101. if (ImCharIsSpace(c))
  6102. return false;
  6103. }
  6104. if (flags & ImGuiInputTextFlags_CallbackCharFilter)
  6105. {
  6106. ImGuiTextEditCallbackData callback_data;
  6107. memset(&callback_data, 0, sizeof(ImGuiTextEditCallbackData));
  6108. callback_data.EventFlag = ImGuiInputTextFlags_CallbackCharFilter;
  6109. callback_data.EventChar = (ImWchar)c;
  6110. callback_data.Flags = flags;
  6111. callback_data.UserData = user_data;
  6112. if (callback(&callback_data) != 0)
  6113. return false;
  6114. *p_char = callback_data.EventChar;
  6115. if (!callback_data.EventChar)
  6116. return false;
  6117. }
  6118. return true;
  6119. }
  6120. // Edit a string of text
  6121. static bool InputTextEx(const char* label, char* buf, size_t buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data)
  6122. {
  6123. ImGuiWindow* window = GetCurrentWindow();
  6124. if (window->SkipItems)
  6125. return false;
  6126. IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackHistory) && (flags & ImGuiInputTextFlags_Multiline))); // Can't use both together (they both use up/down keys)
  6127. IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackCompletion) && (flags & ImGuiInputTextFlags_AllowTabInput))); // Can't use both together (they both use tab key)
  6128. ImGuiState& g = *GImGui;
  6129. const ImGuiIO& io = g.IO;
  6130. const ImGuiStyle& style = g.Style;
  6131. const ImGuiID id = window->GetID(label);
  6132. const bool is_multiline = (flags & ImGuiInputTextFlags_Multiline) != 0;
  6133. ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
  6134. ImVec2 size;
  6135. size.x = (size_arg.x != 0.0f) ? size_arg.x : ImGui::CalcItemWidth();
  6136. size.y = (size_arg.y != 0.0f) ? size_arg.y : is_multiline ? ImGui::GetTextLineHeight() * 8.0f : label_size.y; // Arbitrary default of 8 lines high for multi-line
  6137. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size + style.FramePadding*2.0f);
  6138. const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f));
  6139. ImGuiWindow* draw_window = window;
  6140. if (is_multiline)
  6141. {
  6142. ImGui::BeginGroup();
  6143. if (!ImGui::BeginChildFrame(id, frame_bb.GetSize()))
  6144. {
  6145. ImGui::EndChildFrame();
  6146. ImGui::EndGroup();
  6147. return false;
  6148. }
  6149. draw_window = GetCurrentWindow();
  6150. draw_window->DC.CursorPos += style.FramePadding;
  6151. size.x -= draw_window->ScrollbarWidth();
  6152. }
  6153. else
  6154. {
  6155. ItemSize(total_bb, style.FramePadding.y);
  6156. if (!ItemAdd(total_bb, &id))
  6157. return false;
  6158. }
  6159. // NB: we are only allowed to access 'edit_state' if we are the active widget.
  6160. ImGuiTextEditState& edit_state = g.InputTextState;
  6161. const bool is_ctrl_down = io.KeyCtrl;
  6162. const bool is_shift_down = io.KeyShift;
  6163. const bool is_alt_down = io.KeyAlt;
  6164. const bool focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & (ImGuiInputTextFlags_CallbackCompletion|ImGuiInputTextFlags_AllowTabInput)) == 0); // Using completion callback disable keyboard tabbing
  6165. const bool focus_requested_by_code = focus_requested && (window->FocusIdxAllCounter == window->FocusIdxAllRequestCurrent);
  6166. const bool focus_requested_by_tab = focus_requested && !focus_requested_by_code;
  6167. const bool hovered = IsHovered(frame_bb, id);
  6168. if (hovered)
  6169. {
  6170. g.HoveredId = id;
  6171. g.MouseCursor = ImGuiMouseCursor_TextInput;
  6172. }
  6173. const bool user_clicked = hovered && io.MouseClicked[0];
  6174. const bool user_scrolled = is_multiline && g.ActiveId == 0 && edit_state.Id == id && g.ActiveIdPreviousFrame == draw_window->GetID("#SCROLLY");
  6175. bool select_all = (g.ActiveId != id) && (flags & ImGuiInputTextFlags_AutoSelectAll) != 0;
  6176. if (focus_requested || user_clicked || user_scrolled)
  6177. {
  6178. if (g.ActiveId != id)
  6179. {
  6180. // Start edition
  6181. // Take a copy of the initial buffer value (both in original UTF-8 format and converted to wchar)
  6182. // From the moment we focused we are ignoring the content of 'buf'
  6183. edit_state.Text.resize(buf_size); // wchar count <= utf-8 count
  6184. edit_state.InitialText.resize(buf_size); // utf-8
  6185. ImFormatString(edit_state.InitialText.begin(), edit_state.InitialText.size(), "%s", buf);
  6186. const char* buf_end = NULL;
  6187. edit_state.CurLenW = ImTextStrFromUtf8(edit_state.Text.begin(), edit_state.Text.size(), buf, NULL, &buf_end);
  6188. edit_state.CurLenA = buf_end - buf; // We can't get the result from ImFormatString() above because it is not UTF-8 aware. Here we'll cut off malformed UTF-8.
  6189. edit_state.InputCursorScreenPos = ImVec2(-1.f, -1.f);
  6190. edit_state.CursorAnimReset();
  6191. if (edit_state.Id != id)
  6192. {
  6193. edit_state.Id = id;
  6194. edit_state.ScrollX = 0.f;
  6195. stb_textedit_initialize_state(&edit_state.StbState, !is_multiline);
  6196. if (!is_multiline && focus_requested_by_code)
  6197. select_all = true;
  6198. }
  6199. else
  6200. {
  6201. // Recycle existing cursor/selection/undo stack but clamp position
  6202. // Note a single mouse click will override the cursor/position immediately by calling stb_textedit_click handler.
  6203. edit_state.StbState.cursor = ImMin(edit_state.StbState.cursor, (int)edit_state.CurLenW);
  6204. edit_state.StbState.select_start = ImMin(edit_state.StbState.select_start, (int)edit_state.CurLenW);
  6205. edit_state.StbState.select_end = ImMin(edit_state.StbState.select_end, (int)edit_state.CurLenW);
  6206. }
  6207. if (!is_multiline && (focus_requested_by_tab || (user_clicked && is_ctrl_down)))
  6208. select_all = true;
  6209. }
  6210. SetActiveId(id, window);
  6211. FocusWindow(window);
  6212. }
  6213. else if (io.MouseClicked[0])
  6214. {
  6215. // Release focus when we click outside
  6216. if (g.ActiveId == id)
  6217. SetActiveId(0);
  6218. }
  6219. bool value_changed = false;
  6220. bool cancel_edit = false;
  6221. bool enter_pressed = false;
  6222. if (g.ActiveId == id)
  6223. {
  6224. edit_state.BufSizeA = buf_size;
  6225. // Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget.
  6226. // Down the line we should have a cleaner concept of focused vs active in the library.
  6227. g.ActiveIdIsFocusedOnly = !io.MouseDown[0];
  6228. // Edit in progress
  6229. const float mouse_x = (g.IO.MousePos.x - frame_bb.Min.x - style.FramePadding.x) + edit_state.ScrollX;
  6230. const float mouse_y = (is_multiline ? (g.IO.MousePos.y - draw_window->DC.CursorPos.y - style.FramePadding.y) : (g.FontSize*0.5f));
  6231. if (select_all || (hovered && io.MouseDoubleClicked[0]))
  6232. {
  6233. edit_state.SelectAll();
  6234. edit_state.SelectedAllMouseLock = true;
  6235. }
  6236. else if (io.MouseClicked[0] && !edit_state.SelectedAllMouseLock)
  6237. {
  6238. stb_textedit_click(&edit_state, &edit_state.StbState, mouse_x, mouse_y);
  6239. edit_state.CursorAnimReset();
  6240. }
  6241. else if (io.MouseDown[0] && !edit_state.SelectedAllMouseLock)
  6242. {
  6243. stb_textedit_drag(&edit_state, &edit_state.StbState, mouse_x, mouse_y);
  6244. edit_state.CursorAnimReset();
  6245. }
  6246. if (edit_state.SelectedAllMouseLock && !io.MouseDown[0])
  6247. edit_state.SelectedAllMouseLock = false;
  6248. if (g.IO.InputCharacters[0])
  6249. {
  6250. // Process text input (before we check for Return because using some IME will effectively send a Return?)
  6251. for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++)
  6252. {
  6253. if (unsigned int c = (unsigned int)g.IO.InputCharacters[n])
  6254. {
  6255. // Insert character if they pass filtering
  6256. if (!InputTextFilterCharacter(&c, flags, callback, user_data))
  6257. continue;
  6258. edit_state.OnKeyPressed((int)c);
  6259. }
  6260. }
  6261. // Consume characters
  6262. memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
  6263. }
  6264. const int k_mask = (is_shift_down ? STB_TEXTEDIT_K_SHIFT : 0);
  6265. const bool is_ctrl_only = is_ctrl_down && !is_alt_down && !is_shift_down;
  6266. if (IsKeyPressedMap(ImGuiKey_LeftArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDLEFT | k_mask : STB_TEXTEDIT_K_LEFT | k_mask); }
  6267. else if (IsKeyPressedMap(ImGuiKey_RightArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDRIGHT | k_mask : STB_TEXTEDIT_K_RIGHT | k_mask); }
  6268. else if (is_multiline && IsKeyPressedMap(ImGuiKey_UpArrow)) { if (is_ctrl_down) SetWindowScrollY(draw_window, draw_window->ScrollY - g.FontSize); else edit_state.OnKeyPressed(STB_TEXTEDIT_K_UP | k_mask); }
  6269. else if (is_multiline && IsKeyPressedMap(ImGuiKey_DownArrow)) { if (is_ctrl_down) SetWindowScrollY(draw_window, draw_window->ScrollY + g.FontSize); else edit_state.OnKeyPressed(STB_TEXTEDIT_K_DOWN| k_mask); }
  6270. else if (IsKeyPressedMap(ImGuiKey_Home)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); }
  6271. else if (IsKeyPressedMap(ImGuiKey_End)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); }
  6272. else if (IsKeyPressedMap(ImGuiKey_Delete)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); }
  6273. else if (IsKeyPressedMap(ImGuiKey_Backspace)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask); }
  6274. else if (IsKeyPressedMap(ImGuiKey_Enter))
  6275. {
  6276. bool ctrl_enter_for_new_line = (flags & ImGuiInputTextFlags_CtrlEnterForNewLine) != 0;
  6277. if (!is_multiline || (ctrl_enter_for_new_line && !is_ctrl_down) || (!ctrl_enter_for_new_line && is_ctrl_down))
  6278. {
  6279. SetActiveId(0);
  6280. enter_pressed = true;
  6281. }
  6282. else // New line
  6283. {
  6284. unsigned int c = '\n';
  6285. if (InputTextFilterCharacter(&c, flags, callback, user_data))
  6286. edit_state.OnKeyPressed((int)c);
  6287. }
  6288. }
  6289. else if ((flags & ImGuiInputTextFlags_AllowTabInput) && IsKeyPressedMap(ImGuiKey_Tab) && !is_ctrl_down && !is_shift_down && !is_alt_down)
  6290. {
  6291. unsigned int c = '\t';
  6292. if (InputTextFilterCharacter(&c, flags, callback, user_data))
  6293. edit_state.OnKeyPressed((int)c);
  6294. }
  6295. else if (IsKeyPressedMap(ImGuiKey_Escape)) { SetActiveId(0); cancel_edit = true; }
  6296. else if (is_ctrl_only && IsKeyPressedMap(ImGuiKey_Z)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_UNDO); edit_state.ClearSelection(); }
  6297. else if (is_ctrl_only && IsKeyPressedMap(ImGuiKey_Y)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_REDO); edit_state.ClearSelection(); }
  6298. else if (is_ctrl_only && IsKeyPressedMap(ImGuiKey_A)) { edit_state.SelectAll(); edit_state.CursorFollow = true; }
  6299. else if (is_ctrl_only && (IsKeyPressedMap(ImGuiKey_X) || IsKeyPressedMap(ImGuiKey_C)) && (!is_multiline || edit_state.HasSelection()))
  6300. {
  6301. // Cut, Copy
  6302. const bool cut = IsKeyPressedMap(ImGuiKey_X);
  6303. if (cut && !edit_state.HasSelection())
  6304. edit_state.SelectAll();
  6305. if (g.IO.SetClipboardTextFn)
  6306. {
  6307. const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0;
  6308. const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : (int)edit_state.CurLenW;
  6309. edit_state.TempTextBuffer.resize((ie-ib) * 4 + 1);
  6310. ImTextStrToUtf8(edit_state.TempTextBuffer.begin(), edit_state.TempTextBuffer.size(), edit_state.Text.begin()+ib, edit_state.Text.begin()+ie);
  6311. g.IO.SetClipboardTextFn(edit_state.TempTextBuffer.begin());
  6312. }
  6313. if (cut)
  6314. {
  6315. edit_state.CursorFollow = true;
  6316. stb_textedit_cut(&edit_state, &edit_state.StbState);
  6317. }
  6318. }
  6319. else if (is_ctrl_only && IsKeyPressedMap(ImGuiKey_V))
  6320. {
  6321. // Paste
  6322. if (g.IO.GetClipboardTextFn)
  6323. {
  6324. if (const char* clipboard = g.IO.GetClipboardTextFn())
  6325. {
  6326. // Remove new-line from pasted buffer
  6327. const size_t clipboard_len = strlen(clipboard);
  6328. ImWchar* clipboard_filtered = (ImWchar*)ImGui::MemAlloc((clipboard_len+1) * sizeof(ImWchar));
  6329. int clipboard_filtered_len = 0;
  6330. for (const char* s = clipboard; *s; )
  6331. {
  6332. unsigned int c;
  6333. s += ImTextCharFromUtf8(&c, s, NULL);
  6334. if (c == 0)
  6335. break;
  6336. if (c >= 0x10000 || !InputTextFilterCharacter(&c, flags, callback, user_data))
  6337. continue;
  6338. clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c;
  6339. }
  6340. clipboard_filtered[clipboard_filtered_len] = 0;
  6341. if (clipboard_filtered_len > 0) // If everything was filtered, ignore the pasting operation
  6342. {
  6343. stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len);
  6344. edit_state.CursorFollow = true;
  6345. }
  6346. ImGui::MemFree(clipboard_filtered);
  6347. }
  6348. }
  6349. }
  6350. if (cancel_edit)
  6351. {
  6352. // Restore initial value
  6353. ImFormatString(buf, buf_size, "%s", edit_state.InitialText.begin());
  6354. value_changed = true;
  6355. }
  6356. else
  6357. {
  6358. // Apply new value immediately - copy modified buffer back
  6359. // 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
  6360. // FIXME: We actually always render 'buf' in RenderTextScrolledClipped
  6361. // FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks
  6362. edit_state.TempTextBuffer.resize(edit_state.Text.size() * 4);
  6363. ImTextStrToUtf8(edit_state.TempTextBuffer.begin(), edit_state.TempTextBuffer.size(), edit_state.Text.begin(), NULL);
  6364. // User callback
  6365. if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways)) != 0)
  6366. {
  6367. IM_ASSERT(callback != NULL);
  6368. // The reason we specify the usage semantic (Completion/History) is that Completion needs to disable keyboard TABBING at the moment.
  6369. ImGuiInputTextFlags event_flag = 0;
  6370. ImGuiKey event_key = ImGuiKey_COUNT;
  6371. if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && IsKeyPressedMap(ImGuiKey_Tab))
  6372. {
  6373. event_flag = ImGuiInputTextFlags_CallbackCompletion;
  6374. event_key = ImGuiKey_Tab;
  6375. }
  6376. else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_UpArrow))
  6377. {
  6378. event_flag = ImGuiInputTextFlags_CallbackHistory;
  6379. event_key = ImGuiKey_UpArrow;
  6380. }
  6381. else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_DownArrow))
  6382. {
  6383. event_flag = ImGuiInputTextFlags_CallbackHistory;
  6384. event_key = ImGuiKey_DownArrow;
  6385. }
  6386. if (event_key != ImGuiKey_COUNT || (flags & ImGuiInputTextFlags_CallbackAlways) != 0)
  6387. {
  6388. ImGuiTextEditCallbackData callback_data;
  6389. callback_data.EventFlag = event_flag;
  6390. callback_data.EventKey = event_key;
  6391. callback_data.Buf = edit_state.TempTextBuffer.begin();
  6392. callback_data.BufSize = edit_state.BufSizeA;
  6393. callback_data.BufDirty = false;
  6394. callback_data.Flags = flags;
  6395. callback_data.UserData = user_data;
  6396. // We have to convert from position from wchar to UTF-8 positions
  6397. ImWchar* text = edit_state.Text.begin();
  6398. const int utf8_cursor_pos = callback_data.CursorPos = ImTextCountUtf8BytesFromStr(text, text + edit_state.StbState.cursor);
  6399. const int utf8_selection_start = callback_data.SelectionStart = ImTextCountUtf8BytesFromStr(text, text + edit_state.StbState.select_start);
  6400. const int utf8_selection_end = callback_data.SelectionEnd = ImTextCountUtf8BytesFromStr(text, text + edit_state.StbState.select_end);
  6401. // Call user code
  6402. callback(&callback_data);
  6403. // Read back what user may have modified
  6404. IM_ASSERT(callback_data.Buf == edit_state.TempTextBuffer.begin()); // Invalid to modify those fields
  6405. IM_ASSERT(callback_data.BufSize == edit_state.BufSizeA);
  6406. IM_ASSERT(callback_data.Flags == flags);
  6407. if (callback_data.CursorPos != utf8_cursor_pos) edit_state.StbState.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos);
  6408. if (callback_data.SelectionStart != utf8_selection_start) edit_state.StbState.select_start = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionStart);
  6409. if (callback_data.SelectionEnd != utf8_selection_end) edit_state.StbState.select_end = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionEnd);
  6410. if (callback_data.BufDirty)
  6411. {
  6412. edit_state.CurLenW = ImTextStrFromUtf8(text, edit_state.Text.size(), edit_state.TempTextBuffer.begin(), NULL);
  6413. edit_state.CurLenA = strlen(edit_state.TempTextBuffer.begin());
  6414. edit_state.CursorAnimReset();
  6415. }
  6416. }
  6417. }
  6418. if (strcmp(edit_state.TempTextBuffer.begin(), buf) != 0)
  6419. {
  6420. ImFormatString(buf, buf_size, "%s", edit_state.TempTextBuffer.begin());
  6421. value_changed = true;
  6422. }
  6423. }
  6424. }
  6425. if (!is_multiline)
  6426. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  6427. ImVec2 render_pos = is_multiline ? draw_window->DC.CursorPos : frame_bb.Min + style.FramePadding;
  6428. ImVec4 clip_rect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + size.x + style.FramePadding.x*2.0f, frame_bb.Min.y + size.y + style.FramePadding.y*2.0f);
  6429. ImVec2 text_size(0.f, 0.f);
  6430. if (g.ActiveId == id || (edit_state.Id == id && is_multiline && g.ActiveId == draw_window->GetID("#SCROLLY")))
  6431. {
  6432. edit_state.CursorAnim += g.IO.DeltaTime;
  6433. // We need to:
  6434. // - Display the text (this can be more easily clipped)
  6435. // - Handle scrolling, highlight selection, display cursor (those all requires some form of 1d->2d cursor position calculation)
  6436. // - Measure text height (for scrollbar)
  6437. // We are attempting to do most of that in one main pass to minimize the computation cost (non-negligible for large amount of text) + 2nd pass for selection rendering (we could merge them by an extra refactoring effort)
  6438. const ImWchar* text_begin = edit_state.Text.begin();
  6439. const ImWchar* text_end = text_begin + edit_state.CurLenW;
  6440. ImVec2 cursor_offset, select_start_offset;
  6441. {
  6442. // Count lines + find lines numbers of cursor and select_start
  6443. int matches_remaining = 0;
  6444. int matches_line_no[2] = { -1, -999 };
  6445. const ImWchar* matches_ptr[2];
  6446. matches_ptr[0] = text_begin + edit_state.StbState.cursor; matches_remaining++;
  6447. if (edit_state.StbState.select_start != edit_state.StbState.select_end)
  6448. {
  6449. matches_ptr[1] = text_begin + ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end);
  6450. matches_line_no[1] = -1;
  6451. matches_remaining++;
  6452. }
  6453. matches_remaining += is_multiline ? 1 : 0; // So that we never exit the loop until all lines are counted.
  6454. int line_count = 0;
  6455. for (const ImWchar* s = text_begin; s < text_end+1; s++)
  6456. if ((*s) == '\n' || s == text_end)
  6457. {
  6458. line_count++;
  6459. if (matches_line_no[0] == -1 && s >= matches_ptr[0]) { matches_line_no[0] = line_count; if (--matches_remaining <= 0) break; }
  6460. if (matches_line_no[1] == -1 && s >= matches_ptr[1]) { matches_line_no[1] = line_count; if (--matches_remaining <= 0) break; }
  6461. }
  6462. // Calculate 2d position
  6463. IM_ASSERT(matches_line_no[0] != -1);
  6464. cursor_offset.x = InputTextCalcTextSizeW(ImStrbolW(matches_ptr[0], text_begin), matches_ptr[0]).x;
  6465. cursor_offset.y = matches_line_no[0] * g.FontSize;
  6466. if (matches_line_no[1] >= 0)
  6467. {
  6468. select_start_offset.x = InputTextCalcTextSizeW(ImStrbolW(matches_ptr[1], text_begin), matches_ptr[1]).x;
  6469. select_start_offset.y = matches_line_no[1] * g.FontSize;
  6470. }
  6471. // Calculate text height
  6472. if (is_multiline)
  6473. text_size = ImVec2(size.x, line_count * g.FontSize);
  6474. }
  6475. // Scroll
  6476. if (edit_state.CursorFollow)
  6477. {
  6478. // Horizontal scroll in chunks of quarter width
  6479. const float scroll_increment_x = size.x * 0.25f;
  6480. if (cursor_offset.x < edit_state.ScrollX)
  6481. edit_state.ScrollX = ImMax(0.0f, cursor_offset.x - scroll_increment_x);
  6482. else if (cursor_offset.x - size.x >= edit_state.ScrollX)
  6483. edit_state.ScrollX = cursor_offset.x - size.x + scroll_increment_x;
  6484. // Vertical scroll
  6485. if (is_multiline)
  6486. {
  6487. float scroll_y = draw_window->ScrollY;
  6488. if (cursor_offset.y - g.FontSize < scroll_y)
  6489. scroll_y = ImMax(0.0f, cursor_offset.y - g.FontSize);
  6490. else if (cursor_offset.y - size.y >= scroll_y)
  6491. scroll_y = cursor_offset.y - size.y;
  6492. draw_window->DC.CursorPos.y += (draw_window->ScrollY - scroll_y); // To avoid a frame of lag
  6493. draw_window->ScrollY = scroll_y;
  6494. render_pos.y = draw_window->DC.CursorPos.y;
  6495. }
  6496. }
  6497. edit_state.CursorFollow = false;
  6498. ImVec2 render_scroll = ImVec2(edit_state.ScrollX, 0.0f);
  6499. // Draw selection
  6500. if (edit_state.StbState.select_start != edit_state.StbState.select_end)
  6501. {
  6502. const ImWchar* text_selected_begin = text_begin + ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end);
  6503. const ImWchar* text_selected_end = text_begin + ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end);
  6504. float bg_offy_up = is_multiline ? 0.0f : -1.0f; // FIXME: those offsets should be part of the style? they don't play so well with multi-line selection.
  6505. float bg_offy_dn = is_multiline ? 0.0f : 2.0f;
  6506. ImU32 bg_color = draw_window->Color(ImGuiCol_TextSelectedBg);
  6507. ImVec2 rect_pos = render_pos + select_start_offset - render_scroll;
  6508. for (const ImWchar* p = text_selected_begin; p < text_selected_end; )
  6509. {
  6510. if (rect_pos.y > clip_rect.w + g.FontSize)
  6511. break;
  6512. if (rect_pos.y < clip_rect.y)
  6513. {
  6514. while (p < text_selected_end)
  6515. if (*p++ == '\n')
  6516. break;
  6517. }
  6518. else
  6519. {
  6520. ImVec2 rect_size = InputTextCalcTextSizeW(p, text_selected_end, &p, NULL, true);
  6521. if (rect_size.x <= 0.0f) rect_size.x = (float)(int)(g.Font->GetCharAdvance((unsigned short)' ') * 0.50f); // So we can see selected empty lines
  6522. ImRect rect(rect_pos + ImVec2(0.0f, bg_offy_up - g.FontSize), rect_pos +ImVec2(rect_size.x, bg_offy_dn));
  6523. rect.Clip(clip_rect);
  6524. if (rect.Overlaps(clip_rect))
  6525. draw_window->DrawList->AddRectFilled(rect.Min, rect.Max, bg_color);
  6526. }
  6527. rect_pos.x = render_pos.x - render_scroll.x;
  6528. rect_pos.y += g.FontSize;
  6529. }
  6530. }
  6531. draw_window->DrawList->AddText(g.Font, g.FontSize, render_pos - render_scroll, draw_window->Color(ImGuiCol_Text), buf, buf+edit_state.CurLenA, 0.0f, is_multiline ? NULL : &clip_rect);
  6532. // Draw blinking cursor
  6533. ImVec2 cursor_screen_pos = render_pos + cursor_offset - render_scroll;
  6534. if (g.InputTextState.CursorIsVisible())
  6535. draw_window->DrawList->AddLine(cursor_screen_pos + ImVec2(0,-g.FontSize+1), cursor_screen_pos + ImVec2(0,-1), window->Color(ImGuiCol_Text));
  6536. // Notify OS of text input position for advanced IME
  6537. if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.InputCursorScreenPos - cursor_screen_pos) > 0.0001f)
  6538. io.ImeSetInputScreenPosFn((int)cursor_screen_pos.x - 1, (int)(cursor_screen_pos.y - g.FontSize)); // -1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety.
  6539. edit_state.InputCursorScreenPos = cursor_screen_pos;
  6540. }
  6541. else
  6542. {
  6543. // Render text only
  6544. const char* buf_end = NULL;
  6545. if (is_multiline)
  6546. text_size = ImVec2(size.x, InputTextCalcTextLenAndLineCount(buf, &buf_end) * g.FontSize); // We don't need width
  6547. draw_window->DrawList->AddText(g.Font, g.FontSize, render_pos, draw_window->Color(ImGuiCol_Text), buf, buf_end, 0.0f, is_multiline ? NULL : &clip_rect);
  6548. }
  6549. if (is_multiline)
  6550. {
  6551. ImGui::Dummy(text_size + ImVec2(0.0f, g.FontSize)); // Always add room to scroll an extra line
  6552. ImGui::EndChildFrame();
  6553. ImGui::EndGroup();
  6554. }
  6555. // Log as text
  6556. if (GImGui->LogEnabled)
  6557. LogText(render_pos, buf, NULL);
  6558. if (label_size.x > 0)
  6559. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  6560. if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0)
  6561. return enter_pressed;
  6562. else
  6563. return value_changed;
  6564. }
  6565. bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data)
  6566. {
  6567. IM_ASSERT(!(flags & ImGuiInputTextFlags_Multiline)); // call InputTextMultiline()
  6568. bool ret = InputTextEx(label, buf, buf_size, ImVec2(0,0), flags, callback, user_data);
  6569. return ret;
  6570. }
  6571. bool ImGui::InputTextMultiline(const char* label, char* buf, size_t buf_size, const ImVec2& size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data)
  6572. {
  6573. bool ret = InputTextEx(label, buf, buf_size, size, flags | ImGuiInputTextFlags_Multiline, callback, user_data);
  6574. return ret;
  6575. }
  6576. bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags)
  6577. {
  6578. ImGuiState& g = *GImGui;
  6579. ImGuiWindow* window = GetCurrentWindow();
  6580. if (window->SkipItems)
  6581. return false;
  6582. const ImGuiStyle& style = g.Style;
  6583. const float w = ImGui::CalcItemWidth();
  6584. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  6585. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
  6586. ImGui::BeginGroup();
  6587. ImGui::PushID(label);
  6588. const ImVec2 button_sz = ImVec2(g.FontSize, g.FontSize) + style.FramePadding * 2;
  6589. if (step > 0.0f)
  6590. ImGui::PushItemWidth(ImMax(1.0f, w - (button_sz.x + style.ItemInnerSpacing.x)*2));
  6591. char buf[64];
  6592. if (decimal_precision < 0)
  6593. 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?
  6594. else
  6595. ImFormatString(buf, IM_ARRAYSIZE(buf), "%.*f", decimal_precision, *v);
  6596. bool value_changed = false;
  6597. const ImGuiInputTextFlags flags = extra_flags | (ImGuiInputTextFlags_CharsDecimal|ImGuiInputTextFlags_AutoSelectAll);
  6598. if (ImGui::InputText("", buf, IM_ARRAYSIZE(buf), flags))
  6599. {
  6600. InputTextApplyArithmeticOp(buf, v);
  6601. value_changed = true;
  6602. }
  6603. // Step buttons
  6604. if (step > 0.0f)
  6605. {
  6606. ImGui::PopItemWidth();
  6607. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  6608. if (ButtonEx("-", button_sz, ImGuiButtonFlags_Repeat | ImGuiButtonFlags_DontClosePopups))
  6609. {
  6610. *v -= g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
  6611. value_changed = true;
  6612. }
  6613. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  6614. if (ButtonEx("+", button_sz, ImGuiButtonFlags_Repeat | ImGuiButtonFlags_DontClosePopups))
  6615. {
  6616. *v += g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
  6617. value_changed = true;
  6618. }
  6619. }
  6620. ImGui::PopID();
  6621. if (label_size.x > 0)
  6622. {
  6623. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  6624. RenderText(ImVec2(window->DC.CursorPos.x, window->DC.CursorPos.y + style.FramePadding.y), label);
  6625. ItemSize(label_size, style.FramePadding.y);
  6626. }
  6627. ImGui::EndGroup();
  6628. return value_changed;
  6629. }
  6630. bool ImGui::InputInt(const char* label, int *v, int step, int step_fast, ImGuiInputTextFlags extra_flags)
  6631. {
  6632. float f = (float)*v;
  6633. const bool value_changed = ImGui::InputFloat(label, &f, (float)step, (float)step_fast, 0, extra_flags);
  6634. if (value_changed)
  6635. *v = (int)f;
  6636. return value_changed;
  6637. }
  6638. static bool InputFloatN(const char* label, float* v, int components, int decimal_precision, ImGuiInputTextFlags extra_flags)
  6639. {
  6640. ImGuiState& g = *GImGui;
  6641. ImGuiWindow* window = GetCurrentWindow();
  6642. if (window->SkipItems)
  6643. return false;
  6644. bool value_changed = false;
  6645. ImGui::BeginGroup();
  6646. ImGui::PushID(label);
  6647. PushMultiItemsWidths(components);
  6648. for (int i = 0; i < components; i++)
  6649. {
  6650. ImGui::PushID(i);
  6651. value_changed |= ImGui::InputFloat("##v", &v[i], 0, 0, decimal_precision, extra_flags);
  6652. ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
  6653. ImGui::PopID();
  6654. ImGui::PopItemWidth();
  6655. }
  6656. ImGui::PopID();
  6657. window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y);
  6658. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  6659. ImGui::EndGroup();
  6660. return value_changed;
  6661. }
  6662. bool ImGui::InputFloat2(const char* label, float v[2], int decimal_precision, ImGuiInputTextFlags extra_flags)
  6663. {
  6664. return InputFloatN(label, v, 2, decimal_precision, extra_flags);
  6665. }
  6666. bool ImGui::InputFloat3(const char* label, float v[3], int decimal_precision, ImGuiInputTextFlags extra_flags)
  6667. {
  6668. return InputFloatN(label, v, 3, decimal_precision, extra_flags);
  6669. }
  6670. bool ImGui::InputFloat4(const char* label, float v[4], int decimal_precision, ImGuiInputTextFlags extra_flags)
  6671. {
  6672. return InputFloatN(label, v, 4, decimal_precision, extra_flags);
  6673. }
  6674. static bool InputIntN(const char* label, int* v, int components, ImGuiInputTextFlags extra_flags)
  6675. {
  6676. ImGuiState& g = *GImGui;
  6677. ImGuiWindow* window = GetCurrentWindow();
  6678. if (window->SkipItems)
  6679. return false;
  6680. bool value_changed = false;
  6681. ImGui::BeginGroup();
  6682. ImGui::PushID(label);
  6683. PushMultiItemsWidths(components);
  6684. for (int i = 0; i < components; i++)
  6685. {
  6686. ImGui::PushID(i);
  6687. value_changed |= ImGui::InputInt("##v", &v[i], 0, 0, extra_flags);
  6688. ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
  6689. ImGui::PopID();
  6690. ImGui::PopItemWidth();
  6691. }
  6692. ImGui::PopID();
  6693. window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y);
  6694. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  6695. ImGui::EndGroup();
  6696. return value_changed;
  6697. }
  6698. bool ImGui::InputInt2(const char* label, int v[2], ImGuiInputTextFlags extra_flags)
  6699. {
  6700. return InputIntN(label, v, 2, extra_flags);
  6701. }
  6702. bool ImGui::InputInt3(const char* label, int v[3], ImGuiInputTextFlags extra_flags)
  6703. {
  6704. return InputIntN(label, v, 3, extra_flags);
  6705. }
  6706. bool ImGui::InputInt4(const char* label, int v[4], ImGuiInputTextFlags extra_flags)
  6707. {
  6708. return InputIntN(label, v, 4, extra_flags);
  6709. }
  6710. static bool Items_ArrayGetter(void* data, int idx, const char** out_text)
  6711. {
  6712. const char** items = (const char**)data;
  6713. if (out_text)
  6714. *out_text = items[idx];
  6715. return true;
  6716. }
  6717. static bool Items_SingleStringGetter(void* data, int idx, const char** out_text)
  6718. {
  6719. // FIXME-OPT: we could pre-compute the indices to fasten this. But only 1 active combo means the waste is limited.
  6720. const char* items_separated_by_zeros = (const char*)data;
  6721. int items_count = 0;
  6722. const char* p = items_separated_by_zeros;
  6723. while (*p)
  6724. {
  6725. if (idx == items_count)
  6726. break;
  6727. p += strlen(p) + 1;
  6728. items_count++;
  6729. }
  6730. if (!*p)
  6731. return false;
  6732. if (out_text)
  6733. *out_text = p;
  6734. return true;
  6735. }
  6736. // Combo box helper allowing to pass an array of strings.
  6737. bool ImGui::Combo(const char* label, int* current_item, const char** items, int items_count, int height_in_items)
  6738. {
  6739. const bool value_changed = Combo(label, current_item, Items_ArrayGetter, (void*)items, items_count, height_in_items);
  6740. return value_changed;
  6741. }
  6742. // Combo box helper allowing to pass all items in a single string.
  6743. bool ImGui::Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int height_in_items)
  6744. {
  6745. int items_count = 0;
  6746. const char* p = items_separated_by_zeros; // FIXME-OPT: Avoid computing this, or at least only when combo is open
  6747. while (*p)
  6748. {
  6749. p += strlen(p) + 1;
  6750. items_count++;
  6751. }
  6752. bool value_changed = Combo(label, current_item, Items_SingleStringGetter, (void*)items_separated_by_zeros, items_count, height_in_items);
  6753. return value_changed;
  6754. }
  6755. // Combo box function.
  6756. bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int height_in_items)
  6757. {
  6758. ImGuiState& g = *GImGui;
  6759. ImGuiWindow* window = GetCurrentWindow();
  6760. if (window->SkipItems)
  6761. return false;
  6762. const ImGuiStyle& style = g.Style;
  6763. const ImGuiID id = window->GetID(label);
  6764. const float w = ImGui::CalcItemWidth();
  6765. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  6766. const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
  6767. const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
  6768. ItemSize(total_bb, style.FramePadding.y);
  6769. if (!ItemAdd(total_bb, &id))
  6770. return false;
  6771. const float arrow_size = (g.FontSize + style.FramePadding.x * 2.0f);
  6772. const bool hovered = IsHovered(frame_bb, id);
  6773. const ImRect value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f));
  6774. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  6775. RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, window->Color(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button), true, style.FrameRounding); // FIXME-ROUNDING
  6776. RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true);
  6777. if (*current_item >= 0 && *current_item < items_count)
  6778. {
  6779. const char* item_text;
  6780. if (items_getter(data, *current_item, &item_text))
  6781. RenderTextClipped(frame_bb.Min + style.FramePadding, value_bb.Max, item_text, NULL, NULL);
  6782. }
  6783. if (label_size.x > 0)
  6784. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  6785. bool menu_toggled = false;
  6786. if (hovered)
  6787. {
  6788. g.HoveredId = id;
  6789. if (g.IO.MouseClicked[0])
  6790. {
  6791. SetActiveId(0);
  6792. if (IsPopupOpen(id))
  6793. {
  6794. ClosePopup(id);
  6795. }
  6796. else
  6797. {
  6798. FocusWindow(window);
  6799. ImGui::OpenPopup(label);
  6800. menu_toggled = true;
  6801. }
  6802. }
  6803. }
  6804. bool value_changed = false;
  6805. if (IsPopupOpen(id))
  6806. {
  6807. // Size default to hold ~7 items
  6808. if (height_in_items < 0)
  6809. height_in_items = 7;
  6810. const float popup_height = (label_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + (style.FramePadding.y * 3);
  6811. const ImRect popup_rect(ImVec2(frame_bb.Min.x, frame_bb.Max.y), ImVec2(frame_bb.Max.x, frame_bb.Max.y + popup_height));
  6812. ImGui::SetNextWindowPos(popup_rect.Min);
  6813. ImGui::SetNextWindowSize(popup_rect.GetSize());
  6814. ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.FramePadding);
  6815. const ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ((window->Flags & ImGuiWindowFlags_ShowBorders) ? ImGuiWindowFlags_ShowBorders : 0);
  6816. if (BeginPopupEx(label, flags))
  6817. {
  6818. // Display items
  6819. ImGui::Spacing();
  6820. for (int i = 0; i < items_count; i++)
  6821. {
  6822. ImGui::PushID((void*)(intptr_t)i);
  6823. const bool item_selected = (i == *current_item);
  6824. const char* item_text;
  6825. if (!items_getter(data, i, &item_text))
  6826. item_text = "*Unknown item*";
  6827. if (ImGui::Selectable(item_text, item_selected))
  6828. {
  6829. SetActiveId(0);
  6830. value_changed = true;
  6831. *current_item = i;
  6832. }
  6833. if (item_selected && menu_toggled)
  6834. ImGui::SetScrollHere();
  6835. ImGui::PopID();
  6836. }
  6837. ImGui::EndPopup();
  6838. }
  6839. ImGui::PopStyleVar();
  6840. }
  6841. return value_changed;
  6842. }
  6843. // Tip: pass an empty label (e.g. "##dummy") then you can use the space to draw other text or image.
  6844. // But you need to make sure the ID is unique, e.g. enclose calls in PushID/PopID.
  6845. bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags flags, const ImVec2& size_arg)
  6846. {
  6847. ImGuiState& g = *GImGui;
  6848. ImGuiWindow* window = GetCurrentWindow();
  6849. if (window->SkipItems)
  6850. return false;
  6851. if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.ColumnsCount > 1)
  6852. PopClipRect();
  6853. const ImGuiStyle& style = g.Style;
  6854. ImGuiID id = window->GetID(label);
  6855. ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
  6856. ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y);
  6857. ImVec2 pos = window->DC.CursorPos;
  6858. pos.y += window->DC.CurrentLineTextBaseOffset;
  6859. ImRect bb(pos, pos + size);
  6860. ItemSize(bb);
  6861. // Fill horizontal space.
  6862. ImVec2 window_padding = window->WindowPadding;
  6863. float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? ImGui::GetWindowContentRegionMax().x : ImGui::GetContentRegionMax().x;
  6864. float w_draw = ImMax(label_size.x, window->Pos.x + max_x - window_padding.x - window->DC.CursorPos.x);
  6865. ImVec2 size_draw((size_arg.x != 0 && !(flags & ImGuiSelectableFlags_DrawFillAvailWidth)) ? size_arg.x : w_draw, size_arg.y != 0.0f ? size_arg.y : size.y);
  6866. ImRect bb_with_spacing(pos, pos + size_draw);
  6867. if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_DrawFillAvailWidth))
  6868. bb_with_spacing.Max.x += window_padding.x;
  6869. // Selectables are tightly packed together, we extend the box to cover spacing between selectable.
  6870. float spacing_L = (float)(int)(style.ItemSpacing.x * 0.5f);
  6871. float spacing_U = (float)(int)(style.ItemSpacing.y * 0.5f);
  6872. float spacing_R = style.ItemSpacing.x - spacing_L;
  6873. float spacing_D = style.ItemSpacing.y - spacing_U;
  6874. bb_with_spacing.Min.x -= spacing_L;
  6875. bb_with_spacing.Min.y -= spacing_U;
  6876. bb_with_spacing.Max.x += spacing_R;
  6877. bb_with_spacing.Max.y += spacing_D;
  6878. if (!ItemAdd(bb_with_spacing, &id))
  6879. {
  6880. if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.ColumnsCount > 1)
  6881. PushColumnClipRect();
  6882. return false;
  6883. }
  6884. ImGuiButtonFlags button_flags = 0;
  6885. if (flags & ImGuiSelectableFlags_Menu) button_flags |= ImGuiButtonFlags_PressedOnClick;
  6886. if (flags & ImGuiSelectableFlags_MenuItem) button_flags |= ImGuiButtonFlags_PressedOnClick|ImGuiButtonFlags_PressedOnRelease;
  6887. if (flags & ImGuiSelectableFlags_Disabled) button_flags |= ImGuiButtonFlags_Disabled;
  6888. bool hovered, held;
  6889. bool pressed = ButtonBehavior(bb_with_spacing, id, &hovered, &held, true, button_flags);
  6890. if (flags & ImGuiSelectableFlags_Disabled)
  6891. selected = false;
  6892. // Render
  6893. if (hovered || selected)
  6894. {
  6895. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
  6896. RenderFrame(bb_with_spacing.Min, bb_with_spacing.Max, col, false, 0.0f);
  6897. }
  6898. if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.ColumnsCount > 1)
  6899. {
  6900. PushColumnClipRect();
  6901. bb_with_spacing.Max.x -= (ImGui::GetContentRegionMax().x - max_x);
  6902. }
  6903. if (flags & ImGuiSelectableFlags_Disabled) ImGui::PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
  6904. RenderTextClipped(bb.Min, bb_with_spacing.Max, label, NULL, &label_size);
  6905. if (flags & ImGuiSelectableFlags_Disabled) ImGui::PopStyleColor();
  6906. // Automatically close popups
  6907. if (pressed && !(flags & ImGuiSelectableFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
  6908. ImGui::CloseCurrentPopup();
  6909. return pressed;
  6910. }
  6911. bool ImGui::Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags flags, const ImVec2& size_arg)
  6912. {
  6913. if (ImGui::Selectable(label, *p_selected, flags, size_arg))
  6914. {
  6915. *p_selected = !*p_selected;
  6916. return true;
  6917. }
  6918. return false;
  6919. }
  6920. // Helper to calculate the size of a listbox and display a label on the right.
  6921. // Tip: To have a list filling the entire window width, PushItemWidth(-1) and pass an empty label "##empty"
  6922. bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg)
  6923. {
  6924. ImGuiWindow* window = GetCurrentWindow();
  6925. if (window->SkipItems)
  6926. return false;
  6927. const ImGuiStyle& style = ImGui::GetStyle();
  6928. const ImGuiID id = ImGui::GetID(label);
  6929. const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
  6930. // Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar.
  6931. ImVec2 size;
  6932. size.x = (size_arg.x != 0.0f) ? (size_arg.x) : ImGui::CalcItemWidth() + style.FramePadding.x * 2.0f;
  6933. size.y = (size_arg.y != 0.0f) ? (size_arg.y) : ImGui::GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y;
  6934. ImVec2 frame_size = ImVec2(size.x, ImMax(size.y, label_size.y));
  6935. ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
  6936. ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
  6937. window->DC.LastItemRect = bb;
  6938. ImGui::BeginGroup();
  6939. if (label_size.x > 0)
  6940. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  6941. ImGui::BeginChildFrame(id, frame_bb.GetSize());
  6942. return true;
  6943. }
  6944. bool ImGui::ListBoxHeader(const char* label, int items_count, int height_in_items)
  6945. {
  6946. // Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar.
  6947. // However we don't add +0.40f if items_count <= height_in_items. It is slightly dodgy, because it means a dynamic list of items will make the widget resize occasionally when it crosses that size.
  6948. // I am expecting that someone will come and complain about this behavior in a remote future, then we can advise on a better solution.
  6949. if (height_in_items < 0)
  6950. height_in_items = ImMin(items_count, 7);
  6951. float height_in_items_f = height_in_items < items_count ? (height_in_items + 0.40f) : (height_in_items + 0.00f);
  6952. // We include ItemSpacing.y so that a list sized for the exact number of items doesn't make a scrollbar appears. We could also enforce that by passing a flag to BeginChild().
  6953. ImVec2 size;
  6954. size.x = 0.0f;
  6955. size.y = ImGui::GetTextLineHeightWithSpacing() * height_in_items_f + ImGui::GetStyle().ItemSpacing.y;
  6956. return ImGui::ListBoxHeader(label, size);
  6957. }
  6958. void ImGui::ListBoxFooter()
  6959. {
  6960. ImGuiWindow* parent_window = GetParentWindow();
  6961. const ImRect bb = parent_window->DC.LastItemRect;
  6962. const ImGuiStyle& style = ImGui::GetStyle();
  6963. ImGui::EndChildFrame();
  6964. // Redeclare item size so that it includes the label (we have stored the full size in LastItemRect)
  6965. // We call SameLine() to restore DC.CurrentLine* data
  6966. ImGui::SameLine();
  6967. parent_window->DC.CursorPos = bb.Min;
  6968. ItemSize(bb, style.FramePadding.y);
  6969. ImGui::EndGroup();
  6970. }
  6971. bool ImGui::ListBox(const char* label, int* current_item, const char** items, int items_count, int height_items)
  6972. {
  6973. const bool value_changed = ListBox(label, current_item, Items_ArrayGetter, (void*)items, items_count, height_items);
  6974. return value_changed;
  6975. }
  6976. bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int height_in_items)
  6977. {
  6978. if (!ImGui::ListBoxHeader(label, items_count, height_in_items))
  6979. return false;
  6980. // Assume all items have even height (= 1 line of text). If you need items of different or variable sizes you can create a custom version of ListBox() in your code without using the clipper.
  6981. bool value_changed = false;
  6982. ImGuiListClipper clipper(items_count, ImGui::GetTextLineHeightWithSpacing());
  6983. for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
  6984. {
  6985. const bool item_selected = (i == *current_item);
  6986. const char* item_text;
  6987. if (!items_getter(data, i, &item_text))
  6988. item_text = "*Unknown item*";
  6989. ImGui::PushID(i);
  6990. if (ImGui::Selectable(item_text, item_selected))
  6991. {
  6992. *current_item = i;
  6993. value_changed = true;
  6994. }
  6995. ImGui::PopID();
  6996. }
  6997. clipper.End();
  6998. ImGui::ListBoxFooter();
  6999. return value_changed;
  7000. }
  7001. bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, bool enabled)
  7002. {
  7003. ImGuiState& g = *GImGui;
  7004. ImGuiWindow* window = GetCurrentWindow();
  7005. if (window->SkipItems)
  7006. return false;
  7007. ImVec2 pos = ImGui::GetCursorScreenPos();
  7008. ImVec2 label_size = CalcTextSize(label, NULL, true);
  7009. ImVec2 shortcut_size = shortcut ? CalcTextSize(shortcut, NULL) : ImVec2(0.0f, 0.0f);
  7010. float w = window->MenuColumns.DeclColumns(label_size.x, shortcut_size.x, (float)(int)(g.FontSize * 1.20f)); // Feedback for next frame
  7011. float extra_w = ImMax(0.0f, window->Pos.x + ImGui::GetContentRegionMax().x - pos.x - w);
  7012. bool pressed = ImGui::Selectable(label, false, ImGuiSelectableFlags_MenuItem | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f));
  7013. if (shortcut_size.x > 0.0f)
  7014. {
  7015. ImGui::PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
  7016. RenderText(pos + ImVec2(window->MenuColumns.Pos[1] + extra_w, 0.0f), shortcut, NULL, false);
  7017. ImGui::PopStyleColor();
  7018. }
  7019. if (selected)
  7020. RenderCheckMark(pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * 0.20f, 0.0f), window->Color(ImGuiCol_Text));
  7021. return pressed;
  7022. }
  7023. bool ImGui::MenuItem(const char* label, const char* shortcut, bool* p_selected, bool enabled)
  7024. {
  7025. if (ImGui::MenuItem(label, shortcut, p_selected ? *p_selected : false, enabled))
  7026. {
  7027. if (p_selected)
  7028. *p_selected = !*p_selected;
  7029. return true;
  7030. }
  7031. return false;
  7032. }
  7033. bool ImGui::BeginMainMenuBar()
  7034. {
  7035. ImGuiState& g = *GImGui;
  7036. ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
  7037. ImGui::SetNextWindowSize(ImVec2(g.IO.DisplaySize.x, g.FontBaseSize + g.Style.FramePadding.y * 2.0f));
  7038. ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
  7039. ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0,0));
  7040. if (!ImGui::Begin("##MainMenuBar", NULL, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_MenuBar)
  7041. || !ImGui::BeginMenuBar())
  7042. {
  7043. ImGui::End();
  7044. ImGui::PopStyleVar(2);
  7045. return false;
  7046. }
  7047. g.CurrentWindow->DC.MenuBarOffsetX += g.Style.DisplaySafeAreaPadding.x;
  7048. return true;
  7049. }
  7050. void ImGui::EndMainMenuBar()
  7051. {
  7052. ImGui::EndMenuBar();
  7053. ImGui::End();
  7054. ImGui::PopStyleVar(2);
  7055. }
  7056. bool ImGui::BeginMenuBar()
  7057. {
  7058. ImGuiWindow* window = GetCurrentWindow();
  7059. if (window->SkipItems)
  7060. return false;
  7061. if (!(window->Flags & ImGuiWindowFlags_MenuBar))
  7062. return false;
  7063. IM_ASSERT(!window->DC.MenuBarAppending);
  7064. ImGui::BeginGroup(); // Save position
  7065. ImGui::PushID("##menubar");
  7066. ImRect rect = window->MenuBarRect();
  7067. PushClipRect(ImVec4(rect.Min.x+0.5f, rect.Min.y-0.5f, rect.Max.x+0.5f, rect.Max.y-1.5f), false);
  7068. window->DC.CursorPos = ImVec2(rect.Min.x + window->DC.MenuBarOffsetX, rect.Min.y);// + g.Style.FramePadding.y);
  7069. window->DC.LayoutType = ImGuiLayoutType_Horizontal;
  7070. window->DC.MenuBarAppending = true;
  7071. ImGui::AlignFirstTextHeightToWidgets();
  7072. return true;
  7073. }
  7074. void ImGui::EndMenuBar()
  7075. {
  7076. ImGuiWindow* window = GetCurrentWindow();
  7077. if (window->SkipItems)
  7078. return;
  7079. IM_ASSERT(window->Flags & ImGuiWindowFlags_MenuBar);
  7080. IM_ASSERT(window->DC.MenuBarAppending);
  7081. PopClipRect();
  7082. ImGui::PopID();
  7083. window->DC.MenuBarOffsetX = window->DC.CursorPos.x - window->MenuBarRect().Min.x;
  7084. window->DC.GroupStack.back().AdvanceCursor = false;
  7085. ImGui::EndGroup();
  7086. window->DC.LayoutType = ImGuiLayoutType_Vertical;
  7087. window->DC.MenuBarAppending = false;
  7088. }
  7089. bool ImGui::BeginMenu(const char* label, bool enabled)
  7090. {
  7091. ImGuiWindow* window = GetCurrentWindow();
  7092. if (window->SkipItems)
  7093. return false;
  7094. ImGuiState& g = *GImGui;
  7095. const ImGuiStyle& style = g.Style;
  7096. const ImGuiID id = window->GetID(label);
  7097. ImVec2 label_size = CalcTextSize(label, NULL, true);
  7098. ImGuiWindow* backed_focused_window = g.FocusedWindow;
  7099. bool pressed;
  7100. bool opened = IsPopupOpen(id);
  7101. bool menuset_opened = !(window->Flags & ImGuiWindowFlags_Popup) && (g.OpenedPopupStack.size() > g.CurrentPopupStack.size() && g.OpenedPopupStack[g.CurrentPopupStack.size()].ParentMenuSet == window->GetID("##menus"));
  7102. if (menuset_opened)
  7103. g.FocusedWindow = window;
  7104. ImVec2 popup_pos, pos = window->DC.CursorPos;
  7105. if (window->DC.LayoutType == ImGuiLayoutType_Horizontal)
  7106. {
  7107. popup_pos = ImVec2(pos.x - window->WindowPadding.x, pos.y - style.FramePadding.y + window->MenuBarHeight());
  7108. window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * 0.5f);
  7109. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing * 2.0f);
  7110. float w = label_size.x;
  7111. pressed = ImGui::Selectable(label, opened, ImGuiSelectableFlags_Menu | ImGuiSelectableFlags_DontClosePopups | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f));
  7112. ImGui::PopStyleVar();
  7113. ImGui::SameLine();
  7114. window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * 0.5f);
  7115. }
  7116. else
  7117. {
  7118. popup_pos = ImVec2(pos.x, pos.y - style.WindowPadding.y);
  7119. float w = window->MenuColumns.DeclColumns(label_size.x, 0.0f, (float)(int)(g.FontSize * 1.20f)); // Feedback to next frame
  7120. float extra_w = ImMax(0.0f, window->Pos.x + ImGui::GetContentRegionMax().x - pos.x - w);
  7121. pressed = ImGui::Selectable(label, opened, ImGuiSelectableFlags_Menu | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f));
  7122. if (!enabled) ImGui::PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
  7123. RenderCollapseTriangle(pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * 0.20f, 0.0f), false);
  7124. if (!enabled) ImGui::PopStyleColor();
  7125. }
  7126. bool hovered = enabled && IsHovered(window->DC.LastItemRect, id);
  7127. if (menuset_opened)
  7128. g.FocusedWindow = backed_focused_window;
  7129. bool want_open = false, want_close = false;
  7130. if (window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu))
  7131. {
  7132. // Implement http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown to avoid using timers so menus feel more reactive.
  7133. bool moving_within_opened_triangle = false;
  7134. if (g.HoveredWindow == window && g.OpenedPopupStack.size() > g.CurrentPopupStack.size() && g.OpenedPopupStack[g.CurrentPopupStack.size()].ParentWindow == window)
  7135. {
  7136. if (ImGuiWindow* next_window = g.OpenedPopupStack[g.CurrentPopupStack.size()].Window)
  7137. {
  7138. ImRect next_window_rect = next_window->Rect();
  7139. ImVec2 ta = g.IO.MousePos - g.IO.MouseDelta;
  7140. ImVec2 tb = (window->Pos.x < next_window->Pos.x) ? next_window_rect.GetTL() : next_window_rect.GetTR();
  7141. ImVec2 tc = (window->Pos.x < next_window->Pos.x) ? next_window_rect.GetBL() : next_window_rect.GetBR();
  7142. float extra = ImClamp(fabsf(ta.x - tb.x) * 0.30f, 5.0f, 30.0f); // add a bit of extra slack.
  7143. ta.x += (window->Pos.x < next_window->Pos.x) ? -0.5f : +0.5f; // to avoid numerical issues
  7144. tb.y = ta.y + ImMax((tb.y - extra) - ta.y, -100.0f); // triangle is maximum 200 high to limit the slope and the bias toward large sub-menus
  7145. tc.y = ta.y + ImMin((tc.y + extra) - ta.y, +100.0f);
  7146. moving_within_opened_triangle = ImIsPointInTriangle(g.IO.MousePos, ta, tb, tc);
  7147. //window->DrawList->PushClipRectFullScreen(); window->DrawList->AddTriangleFilled(ta, tb, tc, moving_within_opened_triangle ? 0x80008000 : 0x80000080); window->DrawList->PopClipRect(); // Debug
  7148. }
  7149. }
  7150. want_close = (opened && !hovered && g.HoveredWindow == window && g.HoveredIdPreviousFrame != 0 && g.HoveredIdPreviousFrame != id && !moving_within_opened_triangle);
  7151. want_open = (!opened && hovered && !moving_within_opened_triangle) || (!opened && hovered && pressed);
  7152. }
  7153. else if (opened && pressed && menuset_opened) // menu-bar: click open menu to close
  7154. {
  7155. want_close = true;
  7156. want_open = opened = false;
  7157. }
  7158. else if (pressed || (hovered && menuset_opened && !opened)) // menu-bar: first click to open, then hover to open others
  7159. want_open = true;
  7160. if (want_close && IsPopupOpen(id))
  7161. ClosePopupToLevel((int)GImGui->CurrentPopupStack.size());
  7162. if (!opened && want_open && g.OpenedPopupStack.size() > g.CurrentPopupStack.size())
  7163. {
  7164. // Don't recycle same menu level in the same frame, first close the other menu and yield for a frame.
  7165. ImGui::OpenPopup(label);
  7166. return false;
  7167. }
  7168. opened |= want_open;
  7169. if (want_open)
  7170. ImGui::OpenPopup(label);
  7171. if (opened)
  7172. {
  7173. ImGui::SetNextWindowPos(popup_pos, ImGuiSetCond_Always);
  7174. ImGuiWindowFlags flags = ImGuiWindowFlags_ShowBorders | ((window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) ? ImGuiWindowFlags_ChildMenu|ImGuiWindowFlags_ChildWindow : ImGuiWindowFlags_ChildMenu);
  7175. opened = BeginPopupEx(label, flags); // opened can be 'false' when the popup is completely clipped (e.g. zero size display)
  7176. }
  7177. return opened;
  7178. }
  7179. void ImGui::EndMenu()
  7180. {
  7181. ImGui::EndPopup();
  7182. }
  7183. // A little colored square. Return true when clicked.
  7184. bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_border)
  7185. {
  7186. ImGuiState& g = *GImGui;
  7187. ImGuiWindow* window = GetCurrentWindow();
  7188. if (window->SkipItems)
  7189. return false;
  7190. const ImGuiStyle& style = g.Style;
  7191. const ImGuiID id = window->GetID("#colorbutton");
  7192. const float square_size = g.FontSize;
  7193. const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(square_size + style.FramePadding.y*2, square_size + (small_height ? 0 : style.FramePadding.y*2)));
  7194. ItemSize(bb, small_height ? 0.0f : style.FramePadding.y);
  7195. if (!ItemAdd(bb, &id))
  7196. return false;
  7197. bool hovered, held;
  7198. bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
  7199. RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border, style.FrameRounding);
  7200. if (hovered)
  7201. {
  7202. int ix = (int)(col.x * 255.0f + 0.5f);
  7203. int iy = (int)(col.y * 255.0f + 0.5f);
  7204. int iz = (int)(col.z * 255.0f + 0.5f);
  7205. int iw = (int)(col.w * 255.0f + 0.5f);
  7206. 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);
  7207. }
  7208. return pressed;
  7209. }
  7210. bool ImGui::ColorEdit3(const char* label, float col[3])
  7211. {
  7212. float col4[4];
  7213. col4[0] = col[0];
  7214. col4[1] = col[1];
  7215. col4[2] = col[2];
  7216. col4[3] = 1.0f;
  7217. const bool value_changed = ImGui::ColorEdit4(label, col4, false);
  7218. col[0] = col4[0];
  7219. col[1] = col4[1];
  7220. col[2] = col4[2];
  7221. return value_changed;
  7222. }
  7223. // Edit colors components (each component in 0.0f..1.0f range
  7224. // Use CTRL-Click to input value and TAB to go to next item.
  7225. bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha)
  7226. {
  7227. ImGuiState& g = *GImGui;
  7228. ImGuiWindow* window = GetCurrentWindow();
  7229. if (window->SkipItems)
  7230. return false;
  7231. const ImGuiStyle& style = g.Style;
  7232. const ImGuiID id = window->GetID(label);
  7233. const float w_full = ImGui::CalcItemWidth();
  7234. const float square_sz = (g.FontSize + style.FramePadding.y * 2.0f);
  7235. ImGuiColorEditMode edit_mode = window->DC.ColorEditMode;
  7236. if (edit_mode == ImGuiColorEditMode_UserSelect || edit_mode == ImGuiColorEditMode_UserSelectShowButton)
  7237. edit_mode = g.ColorEditModeStorage.GetInt(id, 0) % 3;
  7238. float f[4] = { col[0], col[1], col[2], col[3] };
  7239. if (edit_mode == ImGuiColorEditMode_HSV)
  7240. ImGui::ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]);
  7241. int i[4] = { (int)(f[0] * 255.0f + 0.5f), (int)(f[1] * 255.0f + 0.5f), (int)(f[2] * 255.0f + 0.5f), (int)(f[3] * 255.0f + 0.5f) };
  7242. int components = alpha ? 4 : 3;
  7243. bool value_changed = false;
  7244. ImGui::BeginGroup();
  7245. ImGui::PushID(label);
  7246. const bool hsv = (edit_mode == 1);
  7247. switch (edit_mode)
  7248. {
  7249. case ImGuiColorEditMode_RGB:
  7250. case ImGuiColorEditMode_HSV:
  7251. {
  7252. // RGB/HSV 0..255 Sliders
  7253. const float w_items_all = w_full - (square_sz + style.ItemInnerSpacing.x);
  7254. 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));
  7255. 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)));
  7256. const bool hide_prefix = (w_item_one <= CalcTextSize("M:999").x);
  7257. const char* ids[4] = { "##X", "##Y", "##Z", "##W" };
  7258. const char* fmt_table[3][4] =
  7259. {
  7260. { "%3.0f", "%3.0f", "%3.0f", "%3.0f" },
  7261. { "R:%3.0f", "G:%3.0f", "B:%3.0f", "A:%3.0f" },
  7262. { "H:%3.0f", "S:%3.0f", "V:%3.0f", "A:%3.0f" }
  7263. };
  7264. const char** fmt = hide_prefix ? fmt_table[0] : hsv ? fmt_table[2] : fmt_table[1];
  7265. ImGui::PushItemWidth(w_item_one);
  7266. for (int n = 0; n < components; n++)
  7267. {
  7268. if (n > 0)
  7269. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  7270. if (n + 1 == components)
  7271. ImGui::PushItemWidth(w_item_last);
  7272. value_changed |= ImGui::DragInt(ids[n], &i[n], 1.0f, 0, 255, fmt[n]);
  7273. }
  7274. ImGui::PopItemWidth();
  7275. ImGui::PopItemWidth();
  7276. }
  7277. break;
  7278. case ImGuiColorEditMode_HEX:
  7279. {
  7280. // RGB Hexadecimal Input
  7281. const float w_slider_all = w_full - square_sz;
  7282. char buf[64];
  7283. if (alpha)
  7284. ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X%02X", i[0], i[1], i[2], i[3]);
  7285. else
  7286. ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X", i[0], i[1], i[2]);
  7287. ImGui::PushItemWidth(w_slider_all - style.ItemInnerSpacing.x);
  7288. value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
  7289. ImGui::PopItemWidth();
  7290. char* p = buf;
  7291. while (*p == '#' || ImCharIsSpace(*p))
  7292. p++;
  7293. // Treat at unsigned (%X is unsigned)
  7294. i[0] = i[1] = i[2] = i[3] = 0;
  7295. if (alpha)
  7296. sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2], (unsigned int*)&i[3]);
  7297. else
  7298. sscanf(p, "%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2]);
  7299. }
  7300. break;
  7301. }
  7302. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  7303. const ImVec4 col_display(col[0], col[1], col[2], 1.0f);
  7304. if (ImGui::ColorButton(col_display))
  7305. g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); // Don't set local copy of 'edit_mode' right away!
  7306. if (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelectShowButton)
  7307. {
  7308. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  7309. const char* button_titles[3] = { "RGB", "HSV", "HEX" };
  7310. if (ButtonEx(button_titles[edit_mode], ImVec2(0,0), ImGuiButtonFlags_DontClosePopups))
  7311. g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); // Don't set local copy of 'edit_mode' right away!
  7312. ImGui::SameLine();
  7313. }
  7314. else
  7315. {
  7316. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  7317. }
  7318. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  7319. // Convert back
  7320. for (int n = 0; n < 4; n++)
  7321. f[n] = i[n] / 255.0f;
  7322. if (edit_mode == 1)
  7323. ImGui::ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]);
  7324. if (value_changed)
  7325. {
  7326. col[0] = f[0];
  7327. col[1] = f[1];
  7328. col[2] = f[2];
  7329. if (alpha)
  7330. col[3] = f[3];
  7331. }
  7332. ImGui::PopID();
  7333. ImGui::EndGroup();
  7334. return value_changed;
  7335. }
  7336. void ImGui::ColorEditMode(ImGuiColorEditMode mode)
  7337. {
  7338. ImGuiWindow* window = GetCurrentWindow();
  7339. window->DC.ColorEditMode = mode;
  7340. }
  7341. // Horizontal separating line.
  7342. void ImGui::Separator()
  7343. {
  7344. ImGuiWindow* window = GetCurrentWindow();
  7345. if (window->SkipItems)
  7346. return;
  7347. if (window->DC.ColumnsCount > 1)
  7348. PopClipRect();
  7349. float x1 = window->Pos.x;
  7350. float x2 = window->Pos.x + window->Size.x;
  7351. if (!window->DC.GroupStack.empty())
  7352. x1 += window->DC.ColumnsStartX;
  7353. const ImRect bb(ImVec2(x1, window->DC.CursorPos.y), ImVec2(x2, window->DC.CursorPos.y));
  7354. ItemSize(ImVec2(0.0f, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit
  7355. if (!ItemAdd(bb, NULL))
  7356. {
  7357. if (window->DC.ColumnsCount > 1)
  7358. PushColumnClipRect();
  7359. return;
  7360. }
  7361. window->DrawList->AddLine(bb.Min, bb.Max, window->Color(ImGuiCol_Border));
  7362. ImGuiState& g = *GImGui;
  7363. if (g.LogEnabled)
  7364. ImGui::LogText(IM_NEWLINE "--------------------------------");
  7365. if (window->DC.ColumnsCount > 1)
  7366. {
  7367. PushColumnClipRect();
  7368. window->DC.ColumnsCellMinY = window->DC.CursorPos.y;
  7369. }
  7370. }
  7371. void ImGui::Spacing()
  7372. {
  7373. ImGuiWindow* window = GetCurrentWindow();
  7374. if (window->SkipItems)
  7375. return;
  7376. ItemSize(ImVec2(0,0));
  7377. }
  7378. void ImGui::Dummy(const ImVec2& size)
  7379. {
  7380. ImGuiWindow* window = GetCurrentWindow();
  7381. if (window->SkipItems)
  7382. return;
  7383. ItemSize(size);
  7384. }
  7385. // Advance cursor given item size for layout.
  7386. static void ItemSize(ImVec2 size, float text_offset_y)
  7387. {
  7388. ImGuiState& g = *GImGui;
  7389. ImGuiWindow* window = GetCurrentWindow();
  7390. if (window->SkipItems)
  7391. return;
  7392. // Always align ourselves on pixel boundaries
  7393. const float line_height = ImMax(window->DC.CurrentLineHeight, size.y);
  7394. const float text_base_offset = ImMax(window->DC.CurrentLineTextBaseOffset, text_offset_y);
  7395. window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y);
  7396. 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));
  7397. window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x);
  7398. window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y);
  7399. //window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, 0xFF0000FF, 4); // Debug
  7400. window->DC.PrevLineHeight = line_height;
  7401. window->DC.PrevLineTextBaseOffset = text_base_offset;
  7402. window->DC.CurrentLineHeight = window->DC.CurrentLineTextBaseOffset = 0.0f;
  7403. }
  7404. static inline void ItemSize(const ImRect& bb, float text_offset_y)
  7405. {
  7406. ItemSize(bb.GetSize(), text_offset_y);
  7407. }
  7408. static bool IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged)
  7409. {
  7410. ImGuiState& g = *GImGui;
  7411. ImGuiWindow* window = GetCurrentWindow();
  7412. if (!bb.Overlaps(ImRect(window->ClipRectStack.back())))
  7413. {
  7414. if (!id || *id != GImGui->ActiveId)
  7415. if (clip_even_when_logged || !g.LogEnabled)
  7416. return true;
  7417. }
  7418. return false;
  7419. }
  7420. bool ImGui::IsRectVisible(const ImVec2& size)
  7421. {
  7422. ImGuiWindow* window = GetCurrentWindow();
  7423. ImRect r(window->ClipRectStack.back());
  7424. return r.Overlaps(ImRect(window->DC.CursorPos, window->DC.CursorPos + size));
  7425. }
  7426. // Declare item bounding box for clipping and interaction.
  7427. // Note that the size can be different than the one provided to ItemSize(). Typically, widgets that spread over available surface
  7428. // declares their minimum size requirement to ItemSize() and then use a larger region for drawing/interaction, which is passed to ItemAdd().
  7429. static bool ItemAdd(const ImRect& bb, const ImGuiID* id)
  7430. {
  7431. ImGuiWindow* window = GetCurrentWindow();
  7432. window->DC.LastItemID = id ? *id : 0;
  7433. window->DC.LastItemRect = bb;
  7434. if (IsClippedEx(bb, id, false))
  7435. {
  7436. window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = false;
  7437. return false;
  7438. }
  7439. // This is a sensible default, but widgets are free to override it after calling ItemAdd()
  7440. ImGuiState& g = *GImGui;
  7441. if (IsMouseHoveringRect(bb))
  7442. {
  7443. // Matching the behavior of IsHovered() but ignore if ActiveId==window->MoveID (we clicked on the window background)
  7444. // So that clicking on items with no active id such as Text() still returns true with IsItemHovered()
  7445. window->DC.LastItemHoveredRect = true;
  7446. window->DC.LastItemHoveredAndUsable = false;
  7447. if (g.HoveredRootWindow == window->RootWindow)
  7448. if (g.ActiveId == 0 || (id && g.ActiveId == *id) || g.ActiveIdIsFocusedOnly || (g.ActiveId == window->MoveID))
  7449. if (IsWindowContentHoverable(window))
  7450. window->DC.LastItemHoveredAndUsable = true;
  7451. }
  7452. else
  7453. {
  7454. window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = false;
  7455. }
  7456. return true;
  7457. }
  7458. void ImGui::BeginGroup()
  7459. {
  7460. ImGuiWindow* window = GetCurrentWindow();
  7461. window->DC.GroupStack.resize(window->DC.GroupStack.size() + 1);
  7462. ImGuiGroupData& group_data = window->DC.GroupStack.back();
  7463. group_data.BackupCursorPos = window->DC.CursorPos;
  7464. group_data.BackupCursorMaxPos = window->DC.CursorMaxPos;
  7465. group_data.BackupColumnsStartX = window->DC.ColumnsStartX;
  7466. group_data.BackupCurrentLineHeight = window->DC.CurrentLineHeight;
  7467. group_data.BackupCurrentLineTextBaseOffset = window->DC.CurrentLineTextBaseOffset;
  7468. group_data.BackupLogLinePosY = window->DC.LogLinePosY;
  7469. group_data.AdvanceCursor = true;
  7470. window->DC.ColumnsStartX = window->DC.CursorPos.x - window->Pos.x;
  7471. window->DC.CursorMaxPos = window->DC.CursorPos;
  7472. window->DC.CurrentLineHeight = 0.0f;
  7473. window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f;
  7474. }
  7475. void ImGui::EndGroup()
  7476. {
  7477. ImGuiWindow* window = GetCurrentWindow();
  7478. ImGuiStyle& style = ImGui::GetStyle();
  7479. IM_ASSERT(!window->DC.GroupStack.empty());
  7480. ImGuiGroupData& group_data = window->DC.GroupStack.back();
  7481. ImRect group_bb(group_data.BackupCursorPos, window->DC.CursorMaxPos);
  7482. group_bb.Max.y -= style.ItemSpacing.y; // Cancel out last vertical spacing because we are adding one ourselves.
  7483. group_bb.Max = ImMax(group_bb.Min, group_bb.Max);
  7484. window->DC.CursorPos = group_data.BackupCursorPos;
  7485. window->DC.CursorMaxPos = ImMax(group_data.BackupCursorMaxPos, window->DC.CursorMaxPos);
  7486. window->DC.CurrentLineHeight = group_data.BackupCurrentLineHeight;
  7487. window->DC.CurrentLineTextBaseOffset = group_data.BackupCurrentLineTextBaseOffset;
  7488. window->DC.ColumnsStartX = group_data.BackupColumnsStartX;
  7489. window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f;
  7490. if (group_data.AdvanceCursor)
  7491. {
  7492. window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.PrevLineTextBaseOffset, group_data.BackupCurrentLineTextBaseOffset); // FIXME: Incorrect, we should grab the base offset from the *first line* of the group but it is hard to obtain now.
  7493. ItemSize(group_bb.GetSize(), group_data.BackupCurrentLineTextBaseOffset);
  7494. ItemAdd(group_bb, NULL);
  7495. }
  7496. window->DC.GroupStack.pop_back();
  7497. //window->DrawList->AddRect(group_bb.Min, group_bb.Max, 0xFFFF00FF); // Debug
  7498. }
  7499. // Gets back to previous line and continue with horizontal layout
  7500. // column_x == 0 : follow on previous item
  7501. // columm_x != 0 : align to specified column
  7502. // spacing_w < 0 : use default spacing if column_x==0, no spacing if column_x!=0
  7503. // spacing_w >= 0 : enforce spacing
  7504. void ImGui::SameLine(int column_x, int spacing_w)
  7505. {
  7506. ImGuiState& g = *GImGui;
  7507. ImGuiWindow* window = GetCurrentWindow();
  7508. if (window->SkipItems)
  7509. return;
  7510. float x, y;
  7511. if (column_x != 0)
  7512. {
  7513. if (spacing_w < 0) spacing_w = 0;
  7514. x = window->Pos.x + (float)column_x + (float)spacing_w;
  7515. y = window->DC.CursorPosPrevLine.y;
  7516. }
  7517. else
  7518. {
  7519. if (spacing_w < 0) spacing_w = (int)g.Style.ItemSpacing.x;
  7520. x = window->DC.CursorPosPrevLine.x + (float)spacing_w;
  7521. y = window->DC.CursorPosPrevLine.y;
  7522. }
  7523. window->DC.CurrentLineHeight = window->DC.PrevLineHeight;
  7524. window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset;
  7525. window->DC.CursorPos = ImVec2(x, y);
  7526. }
  7527. void ImGui::NextColumn()
  7528. {
  7529. ImGuiState& g = *GImGui;
  7530. ImGuiWindow* window = GetCurrentWindow();
  7531. if (window->SkipItems)
  7532. return;
  7533. if (window->DC.ColumnsCount > 1)
  7534. {
  7535. ImGui::PopItemWidth();
  7536. PopClipRect();
  7537. window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
  7538. if (++window->DC.ColumnsCurrent < window->DC.ColumnsCount)
  7539. {
  7540. window->DC.ColumnsOffsetX = ImGui::GetColumnOffset(window->DC.ColumnsCurrent) - window->DC.ColumnsStartX + g.Style.ItemSpacing.x;
  7541. }
  7542. else
  7543. {
  7544. window->DC.ColumnsCurrent = 0;
  7545. window->DC.ColumnsOffsetX = 0.0f;
  7546. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY;
  7547. }
  7548. window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX);
  7549. window->DC.CursorPos.y = window->DC.ColumnsCellMinY;
  7550. window->DC.CurrentLineHeight = 0.0f;
  7551. window->DC.CurrentLineTextBaseOffset = 0.0f;
  7552. PushColumnClipRect();
  7553. ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f); // FIXME
  7554. }
  7555. }
  7556. int ImGui::GetColumnIndex()
  7557. {
  7558. ImGuiWindow* window = GetCurrentWindow();
  7559. return window->DC.ColumnsCurrent;
  7560. }
  7561. int ImGui::GetColumnsCount()
  7562. {
  7563. ImGuiWindow* window = GetCurrentWindow();
  7564. return window->DC.ColumnsCount;
  7565. }
  7566. static float GetDraggedColumnOffset(int column_index)
  7567. {
  7568. // Active (dragged) column always follow mouse. The reason we need this is that dragging a column to the right edge of an auto-resizing
  7569. // window creates a feedback loop because we store normalized positions/ So while dragging we enforce absolute positioning
  7570. ImGuiState& g = *GImGui;
  7571. ImGuiWindow* window = GetCurrentWindow();
  7572. IM_ASSERT(column_index > 0); // We cannot drag column 0. If you get this assert you may have a conflict between the ID of your columns and another widgets.
  7573. IM_ASSERT(g.ActiveId == window->DC.ColumnsSetID + ImGuiID(column_index));
  7574. float x = g.IO.MousePos.x + g.ActiveClickDeltaToCenter.x;
  7575. x -= window->Pos.x;
  7576. x = ImClamp(x, ImGui::GetColumnOffset(column_index-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(column_index+1)-g.Style.ColumnsMinSpacing);
  7577. return x;
  7578. }
  7579. float ImGui::GetColumnOffset(int column_index)
  7580. {
  7581. ImGuiState& g = *GImGui;
  7582. ImGuiWindow* window = GetCurrentWindow();
  7583. if (column_index < 0)
  7584. column_index = window->DC.ColumnsCurrent;
  7585. if (g.ActiveId)
  7586. {
  7587. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  7588. if (g.ActiveId == column_id)
  7589. return GetDraggedColumnOffset(column_index);
  7590. }
  7591. // Read from cache
  7592. IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size());
  7593. const float t = window->DC.ColumnsOffsetsT[column_index];
  7594. const float min_x = window->DC.ColumnsStartX;
  7595. const float max_x = window->Size.x - (g.Style.ScrollbarWidth);// - window->WindowPadding().x;
  7596. const float offset = min_x + t * (max_x - min_x);
  7597. return offset;
  7598. }
  7599. void ImGui::SetColumnOffset(int column_index, float offset)
  7600. {
  7601. ImGuiState& g = *GImGui;
  7602. ImGuiWindow* window = GetCurrentWindow();
  7603. if (column_index < 0)
  7604. column_index = window->DC.ColumnsCurrent;
  7605. IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size());
  7606. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  7607. const float min_x = window->DC.ColumnsStartX;
  7608. const float max_x = window->Size.x - (g.Style.ScrollbarWidth);// - window->WindowPadding().x;
  7609. const float t = (offset - min_x) / (max_x - min_x);
  7610. window->DC.StateStorage->SetFloat(column_id, t);
  7611. window->DC.ColumnsOffsetsT[column_index] = t;
  7612. }
  7613. float ImGui::GetColumnWidth(int column_index)
  7614. {
  7615. ImGuiWindow* window = GetCurrentWindow();
  7616. if (column_index < 0)
  7617. column_index = window->DC.ColumnsCurrent;
  7618. const float w = GetColumnOffset(column_index+1) - GetColumnOffset(column_index);
  7619. return w;
  7620. }
  7621. static void PushColumnClipRect(int column_index)
  7622. {
  7623. ImGuiWindow* window = GetCurrentWindow();
  7624. if (column_index < 0)
  7625. column_index = window->DC.ColumnsCurrent;
  7626. const float x1 = window->Pos.x + ImGui::GetColumnOffset(column_index) - 1;
  7627. const float x2 = window->Pos.x + ImGui::GetColumnOffset(column_index+1) - 1;
  7628. PushClipRect(ImVec4(x1,-FLT_MAX,x2,+FLT_MAX));
  7629. }
  7630. void ImGui::Columns(int columns_count, const char* id, bool border)
  7631. {
  7632. ImGuiState& g = *GImGui;
  7633. ImGuiWindow* window = GetCurrentWindow();
  7634. if (window->DC.ColumnsCount != 1)
  7635. {
  7636. if (window->DC.ColumnsCurrent != 0)
  7637. ItemSize(ImVec2(0,0)); // Advance to column 0
  7638. ImGui::PopItemWidth();
  7639. PopClipRect();
  7640. window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
  7641. window->DC.CursorPos.y = window->DC.ColumnsCellMaxY;
  7642. }
  7643. // Draw columns borders and handle resize at the time of "closing" a columns set
  7644. if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders && !window->SkipItems)
  7645. {
  7646. const float y1 = window->DC.ColumnsStartPos.y;
  7647. const float y2 = window->DC.CursorPos.y;
  7648. for (int i = 1; i < window->DC.ColumnsCount; i++)
  7649. {
  7650. float x = window->Pos.x + GetColumnOffset(i);
  7651. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(i);
  7652. const ImRect column_rect(ImVec2(x-4,y1),ImVec2(x+4,y2));
  7653. if (IsClippedEx(column_rect, &column_id, false))
  7654. continue;
  7655. bool hovered, held;
  7656. ButtonBehavior(column_rect, column_id, &hovered, &held, true);
  7657. if (hovered || held)
  7658. g.MouseCursor = ImGuiMouseCursor_ResizeEW;
  7659. // Draw before resize so our items positioning are in sync with the line being drawn
  7660. const ImU32 col = window->Color(held ? ImGuiCol_ColumnActive : hovered ? ImGuiCol_ColumnHovered : ImGuiCol_Column);
  7661. const float xi = (float)(int)x;
  7662. window->DrawList->AddLine(ImVec2(xi, y1), ImVec2(xi, y2), col);
  7663. if (held)
  7664. {
  7665. if (g.ActiveIdIsJustActivated)
  7666. g.ActiveClickDeltaToCenter.x = x - g.IO.MousePos.x;
  7667. x = GetDraggedColumnOffset(i);
  7668. SetColumnOffset(i, x);
  7669. }
  7670. }
  7671. }
  7672. // Set state for first column
  7673. ImGui::PushID(0x11223344); // Differentiate column ID with an arbitrary/random prefix for cases where users name their columns set the same as another non-scope widget
  7674. window->DC.ColumnsSetID = window->GetID(id ? id : "");
  7675. ImGui::PopID();
  7676. window->DC.ColumnsCurrent = 0;
  7677. window->DC.ColumnsCount = columns_count;
  7678. window->DC.ColumnsShowBorders = border;
  7679. window->DC.ColumnsStartPos = window->DC.CursorPos;
  7680. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.CursorPos.y;
  7681. window->DC.ColumnsOffsetX = 0.0f;
  7682. window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX);
  7683. if (window->DC.ColumnsCount != 1)
  7684. {
  7685. // Cache column offsets
  7686. window->DC.ColumnsOffsetsT.resize((size_t)columns_count + 1);
  7687. for (int column_index = 0; column_index < columns_count + 1; column_index++)
  7688. {
  7689. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  7690. RegisterAliveId(column_id);
  7691. const float default_t = column_index / (float)window->DC.ColumnsCount;
  7692. const float t = window->DC.StateStorage->GetFloat(column_id, default_t); // Cheaply store our floating point value inside the integer (could store an union into the map?)
  7693. window->DC.ColumnsOffsetsT[column_index] = t;
  7694. }
  7695. PushColumnClipRect();
  7696. ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);
  7697. }
  7698. else
  7699. {
  7700. window->DC.ColumnsOffsetsT.resize(2);
  7701. window->DC.ColumnsOffsetsT[0] = 0.0f;
  7702. window->DC.ColumnsOffsetsT[1] = 1.0f;
  7703. }
  7704. }
  7705. void ImGui::Indent()
  7706. {
  7707. ImGuiState& g = *GImGui;
  7708. ImGuiWindow* window = GetCurrentWindow();
  7709. window->DC.ColumnsStartX += g.Style.IndentSpacing;
  7710. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  7711. }
  7712. void ImGui::Unindent()
  7713. {
  7714. ImGuiState& g = *GImGui;
  7715. ImGuiWindow* window = GetCurrentWindow();
  7716. window->DC.ColumnsStartX -= g.Style.IndentSpacing;
  7717. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  7718. }
  7719. void ImGui::TreePush(const char* str_id)
  7720. {
  7721. ImGuiWindow* window = GetCurrentWindow();
  7722. ImGui::Indent();
  7723. window->DC.TreeDepth++;
  7724. PushID(str_id ? str_id : "#TreePush");
  7725. }
  7726. void ImGui::TreePush(const void* ptr_id)
  7727. {
  7728. ImGuiWindow* window = GetCurrentWindow();
  7729. ImGui::Indent();
  7730. window->DC.TreeDepth++;
  7731. PushID(ptr_id ? ptr_id : (const void*)"#TreePush");
  7732. }
  7733. void ImGui::TreePop()
  7734. {
  7735. ImGuiWindow* window = GetCurrentWindow();
  7736. ImGui::Unindent();
  7737. window->DC.TreeDepth--;
  7738. PopID();
  7739. }
  7740. void ImGui::Value(const char* prefix, bool b)
  7741. {
  7742. ImGui::Text("%s: %s", prefix, (b ? "true" : "false"));
  7743. }
  7744. void ImGui::Value(const char* prefix, int v)
  7745. {
  7746. ImGui::Text("%s: %d", prefix, v);
  7747. }
  7748. void ImGui::Value(const char* prefix, unsigned int v)
  7749. {
  7750. ImGui::Text("%s: %d", prefix, v);
  7751. }
  7752. void ImGui::Value(const char* prefix, float v, const char* float_format)
  7753. {
  7754. if (float_format)
  7755. {
  7756. char fmt[64];
  7757. ImFormatString(fmt, IM_ARRAYSIZE(fmt), "%%s: %s", float_format);
  7758. ImGui::Text(fmt, prefix, v);
  7759. }
  7760. else
  7761. {
  7762. ImGui::Text("%s: %.3f", prefix, v);
  7763. }
  7764. }
  7765. void ImGui::Color(const char* prefix, const ImVec4& v)
  7766. {
  7767. ImGui::Text("%s: (%.2f,%.2f,%.2f,%.2f)", prefix, v.x, v.y, v.z, v.w);
  7768. ImGui::SameLine();
  7769. ImGui::ColorButton(v, true);
  7770. }
  7771. void ImGui::Color(const char* prefix, unsigned int v)
  7772. {
  7773. ImGui::Text("%s: %08X", prefix, v);
  7774. ImGui::SameLine();
  7775. ImVec4 col;
  7776. col.x = (float)((v >> 0) & 0xFF) / 255.0f;
  7777. col.y = (float)((v >> 8) & 0xFF) / 255.0f;
  7778. col.z = (float)((v >> 16) & 0xFF) / 255.0f;
  7779. col.w = (float)((v >> 24) & 0xFF) / 255.0f;
  7780. ImGui::ColorButton(col, true);
  7781. }
  7782. //-----------------------------------------------------------------------------
  7783. // ImDrawList
  7784. //-----------------------------------------------------------------------------
  7785. static ImVec4 GNullClipRect(-9999.0f,-9999.0f, +9999.0f, +9999.0f);
  7786. void ImDrawList::Clear()
  7787. {
  7788. commands.resize(0);
  7789. vtx_buffer.resize(0);
  7790. vtx_write = NULL;
  7791. clip_rect_stack.resize(0);
  7792. texture_id_stack.resize(0);
  7793. }
  7794. void ImDrawList::ClearFreeMemory()
  7795. {
  7796. commands.clear();
  7797. vtx_buffer.clear();
  7798. vtx_write = NULL;
  7799. clip_rect_stack.clear();
  7800. texture_id_stack.clear();
  7801. }
  7802. void ImDrawList::AddDrawCmd()
  7803. {
  7804. ImDrawCmd draw_cmd;
  7805. draw_cmd.vtx_count = 0;
  7806. draw_cmd.clip_rect = clip_rect_stack.empty() ? GNullClipRect : clip_rect_stack.back();
  7807. draw_cmd.texture_id = texture_id_stack.empty() ? NULL : texture_id_stack.back();
  7808. draw_cmd.user_callback = NULL;
  7809. draw_cmd.user_callback_data = NULL;
  7810. IM_ASSERT(draw_cmd.clip_rect.x <= draw_cmd.clip_rect.z && draw_cmd.clip_rect.y <= draw_cmd.clip_rect.w);
  7811. commands.push_back(draw_cmd);
  7812. }
  7813. void ImDrawList::AddCallback(ImDrawCallback callback, void* callback_data)
  7814. {
  7815. ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back();
  7816. if (!current_cmd || current_cmd->vtx_count != 0 || current_cmd->user_callback != NULL)
  7817. {
  7818. AddDrawCmd();
  7819. current_cmd = &commands.back();
  7820. }
  7821. current_cmd->user_callback = callback;
  7822. current_cmd->user_callback_data = callback_data;
  7823. // Force a new command after us
  7824. // We function this way so that the most common calls (AddLine, AddRect..) always have a command to add to without doing any check.
  7825. AddDrawCmd();
  7826. }
  7827. void ImDrawList::UpdateClipRect()
  7828. {
  7829. ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back();
  7830. if (!current_cmd || (current_cmd->vtx_count != 0) || current_cmd->user_callback != NULL)
  7831. {
  7832. AddDrawCmd();
  7833. }
  7834. else
  7835. {
  7836. ImVec4 current_clip_rect = clip_rect_stack.empty() ? GNullClipRect : clip_rect_stack.back();
  7837. if (commands.size() > 2 && ImLengthSqr(commands[commands.size()-2].clip_rect - current_clip_rect) < 0.00001f)
  7838. commands.pop_back();
  7839. else
  7840. current_cmd->clip_rect = current_clip_rect;
  7841. }
  7842. }
  7843. // Scissoring. The values in clip_rect are x1, y1, x2, y2.
  7844. void ImDrawList::PushClipRect(const ImVec4& clip_rect)
  7845. {
  7846. clip_rect_stack.push_back(clip_rect);
  7847. UpdateClipRect();
  7848. }
  7849. void ImDrawList::PushClipRectFullScreen()
  7850. {
  7851. PushClipRect(GNullClipRect);
  7852. // This would be more correct but we're not supposed to access ImGuiState from here?
  7853. //ImGuiState& g = *GImGui;
  7854. //PushClipRect(GetVisibleRect());
  7855. }
  7856. void ImDrawList::PopClipRect()
  7857. {
  7858. IM_ASSERT(clip_rect_stack.size() > 0);
  7859. clip_rect_stack.pop_back();
  7860. UpdateClipRect();
  7861. }
  7862. void ImDrawList::UpdateTextureID()
  7863. {
  7864. ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back();
  7865. const ImTextureID texture_id = texture_id_stack.empty() ? NULL : texture_id_stack.back();
  7866. if (!current_cmd || (current_cmd->vtx_count != 0 && current_cmd->texture_id != texture_id) || current_cmd->user_callback != NULL)
  7867. {
  7868. AddDrawCmd();
  7869. }
  7870. else
  7871. {
  7872. current_cmd->texture_id = texture_id;
  7873. }
  7874. }
  7875. void ImDrawList::PushTextureID(const ImTextureID& texture_id)
  7876. {
  7877. texture_id_stack.push_back(texture_id);
  7878. UpdateTextureID();
  7879. }
  7880. void ImDrawList::PopTextureID()
  7881. {
  7882. IM_ASSERT(texture_id_stack.size() > 0);
  7883. texture_id_stack.pop_back();
  7884. UpdateTextureID();
  7885. }
  7886. void ImDrawList::PrimReserve(unsigned int vtx_count)
  7887. {
  7888. ImDrawCmd& draw_cmd = commands.back();
  7889. draw_cmd.vtx_count += vtx_count;
  7890. size_t vtx_buffer_size = vtx_buffer.size();
  7891. vtx_buffer.resize(vtx_buffer_size + vtx_count);
  7892. vtx_write = &vtx_buffer[vtx_buffer_size];
  7893. }
  7894. void ImDrawList::PrimTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col)
  7895. {
  7896. const ImVec2 uv = GImGui->FontTexUvWhitePixel;
  7897. vtx_write[0].pos = a; vtx_write[0].uv = uv; vtx_write[0].col = col;
  7898. vtx_write[1].pos = b; vtx_write[1].uv = uv; vtx_write[1].col = col;
  7899. vtx_write[2].pos = c; vtx_write[2].uv = uv; vtx_write[2].col = col;
  7900. vtx_write += 3;
  7901. }
  7902. void ImDrawList::PrimRect(const ImVec2& a, const ImVec2& c, ImU32 col)
  7903. {
  7904. const ImVec2 uv = GImGui->FontTexUvWhitePixel;
  7905. const ImVec2 b(c.x, a.y);
  7906. const ImVec2 d(a.x, c.y);
  7907. vtx_write[0].pos = a; vtx_write[0].uv = uv; vtx_write[0].col = col;
  7908. vtx_write[1].pos = b; vtx_write[1].uv = uv; vtx_write[1].col = col;
  7909. vtx_write[2].pos = c; vtx_write[2].uv = uv; vtx_write[2].col = col;
  7910. vtx_write[3].pos = a; vtx_write[3].uv = uv; vtx_write[3].col = col;
  7911. vtx_write[4].pos = c; vtx_write[4].uv = uv; vtx_write[4].col = col;
  7912. vtx_write[5].pos = d; vtx_write[5].uv = uv; vtx_write[5].col = col;
  7913. vtx_write += 6;
  7914. }
  7915. void ImDrawList::PrimRectUV(const ImVec2& a, const ImVec2& c, const ImVec2& uv_a, const ImVec2& uv_c, ImU32 col)
  7916. {
  7917. const ImVec2 b(c.x, a.y);
  7918. const ImVec2 d(a.x, c.y);
  7919. const ImVec2 uv_b(uv_c.x, uv_a.y);
  7920. const ImVec2 uv_d(uv_a.x, uv_c.y);
  7921. vtx_write[0].pos = a; vtx_write[0].uv = uv_a; vtx_write[0].col = col;
  7922. vtx_write[1].pos = b; vtx_write[1].uv = uv_b; vtx_write[1].col = col;
  7923. vtx_write[2].pos = c; vtx_write[2].uv = uv_c; vtx_write[2].col = col;
  7924. vtx_write[3].pos = a; vtx_write[3].uv = uv_a; vtx_write[3].col = col;
  7925. vtx_write[4].pos = c; vtx_write[4].uv = uv_c; vtx_write[4].col = col;
  7926. vtx_write[5].pos = d; vtx_write[5].uv = uv_d; vtx_write[5].col = col;
  7927. vtx_write += 6;
  7928. }
  7929. void ImDrawList::PrimQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col)
  7930. {
  7931. const ImVec2 uv = GImGui->FontTexUvWhitePixel;
  7932. vtx_write[0].pos = a; vtx_write[0].uv = uv; vtx_write[0].col = col;
  7933. vtx_write[1].pos = b; vtx_write[1].uv = uv; vtx_write[1].col = col;
  7934. vtx_write[2].pos = c; vtx_write[2].uv = uv; vtx_write[2].col = col;
  7935. vtx_write[3].pos = a; vtx_write[3].uv = uv; vtx_write[3].col = col;
  7936. vtx_write[4].pos = c; vtx_write[4].uv = uv; vtx_write[4].col = col;
  7937. vtx_write[5].pos = d; vtx_write[5].uv = uv; vtx_write[5].col = col;
  7938. vtx_write += 6;
  7939. }
  7940. // FIXME-OPT: In many instances the caller could provide a normal.
  7941. void ImDrawList::PrimLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness)
  7942. {
  7943. const float inv_length = 1.0f / sqrtf(ImLengthSqr(b - a));
  7944. const float dx = (b.x - a.x) * (thickness * 0.5f * inv_length); // line direction, halved
  7945. const float dy = (b.y - a.y) * (thickness * 0.5f * inv_length); // line direction, halved
  7946. const ImVec2 pa(a.x + dy, a.y - dx);
  7947. const ImVec2 pb(b.x + dy, b.y - dx);
  7948. const ImVec2 pc(b.x - dy, b.y + dx);
  7949. const ImVec2 pd(a.x - dy, a.y + dx);
  7950. PrimQuad(pa, pb, pc, pd, col);
  7951. }
  7952. void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness)
  7953. {
  7954. if ((col >> 24) == 0)
  7955. return;
  7956. PrimReserve(6);
  7957. PrimLine(a, b, col, thickness);
  7958. }
  7959. void ImDrawList::AddArcFast(const ImVec2& center, float radius, ImU32 col, int a_min, int a_max, bool filled, const ImVec2& third_point_offset)
  7960. {
  7961. if ((col >> 24) == 0)
  7962. return;
  7963. const int SAMPLES = 12;
  7964. static ImVec2 circle_vtx[SAMPLES];
  7965. static bool circle_vtx_builds = false;
  7966. if (!circle_vtx_builds)
  7967. {
  7968. for (int i = 0; i < SAMPLES; i++)
  7969. {
  7970. const float a = ((float)i / (float)SAMPLES) * 2*IM_PI;
  7971. circle_vtx[i].x = cosf(a + IM_PI);
  7972. circle_vtx[i].y = sinf(a + IM_PI);
  7973. }
  7974. circle_vtx_builds = true;
  7975. }
  7976. const ImVec2 uv = GImGui->FontTexUvWhitePixel;
  7977. if (filled)
  7978. {
  7979. PrimReserve((unsigned int)(a_max-a_min) * 3);
  7980. for (int a0 = a_min; a0 < a_max; a0++)
  7981. {
  7982. int a1 = (a0 + 1 == SAMPLES) ? 0 : a0 + 1;
  7983. PrimVtx(center + circle_vtx[a0] * radius, uv, col);
  7984. PrimVtx(center + circle_vtx[a1] * radius, uv, col);
  7985. PrimVtx(center + third_point_offset, uv, col);
  7986. }
  7987. }
  7988. else
  7989. {
  7990. PrimReserve((unsigned int)(a_max-a_min) * 6);
  7991. for (int a0 = a_min; a0 < a_max; a0++)
  7992. {
  7993. int a1 = (a0 + 1 == SAMPLES) ? 0 : a0 + 1;
  7994. PrimLine(center + circle_vtx[a0] * radius, center + circle_vtx[a1] * radius, col);
  7995. }
  7996. }
  7997. }
  7998. void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
  7999. {
  8000. if ((col >> 24) == 0)
  8001. return;
  8002. float r = rounding;
  8003. r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
  8004. r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
  8005. if (r == 0.0f || rounding_corners == 0)
  8006. {
  8007. PrimReserve(4*6);
  8008. PrimLine(ImVec2(a.x,a.y), ImVec2(b.x,a.y), col);
  8009. PrimLine(ImVec2(b.x,a.y), ImVec2(b.x,b.y), col);
  8010. PrimLine(ImVec2(b.x,b.y), ImVec2(a.x,b.y), col);
  8011. PrimLine(ImVec2(a.x,b.y), ImVec2(a.x,a.y), col);
  8012. }
  8013. else
  8014. {
  8015. PrimReserve(4*6);
  8016. PrimLine(ImVec2(a.x + ((rounding_corners & 1)?r:0), a.y), ImVec2(b.x - ((rounding_corners & 2)?r:0), a.y), col);
  8017. PrimLine(ImVec2(b.x, a.y + ((rounding_corners & 2)?r:0)), ImVec2(b.x, b.y - ((rounding_corners & 4)?r:0)), col);
  8018. PrimLine(ImVec2(b.x - ((rounding_corners & 4)?r:0), b.y), ImVec2(a.x + ((rounding_corners & 8)?r:0), b.y), col);
  8019. PrimLine(ImVec2(a.x, b.y - ((rounding_corners & 8)?r:0)), ImVec2(a.x, a.y + ((rounding_corners & 1)?r:0)), col);
  8020. if (rounding_corners & 1) AddArcFast(ImVec2(a.x+r,a.y+r), r, col, 0, 3);
  8021. if (rounding_corners & 2) AddArcFast(ImVec2(b.x-r,a.y+r), r, col, 3, 6);
  8022. if (rounding_corners & 4) AddArcFast(ImVec2(b.x-r,b.y-r), r, col, 6, 9);
  8023. if (rounding_corners & 8) AddArcFast(ImVec2(a.x+r,b.y-r), r, col, 9, 12);
  8024. }
  8025. }
  8026. void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
  8027. {
  8028. if ((col >> 24) == 0)
  8029. return;
  8030. float r = rounding;
  8031. r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
  8032. r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
  8033. if (r == 0.0f || rounding_corners == 0)
  8034. {
  8035. // Use triangle so we can merge more draw calls together (at the cost of extra vertices)
  8036. PrimReserve(6);
  8037. PrimRect(a, b, col);
  8038. }
  8039. else
  8040. {
  8041. PrimReserve(6+6*2);
  8042. PrimRect(ImVec2(a.x+r,a.y), ImVec2(b.x-r,b.y), col);
  8043. float top_y = (rounding_corners & 1) ? a.y+r : a.y;
  8044. float bot_y = (rounding_corners & 8) ? b.y-r : b.y;
  8045. PrimRect(ImVec2(a.x,top_y), ImVec2(a.x+r,bot_y), col);
  8046. top_y = (rounding_corners & 2) ? a.y+r : a.y;
  8047. bot_y = (rounding_corners & 4) ? b.y-r : b.y;
  8048. PrimRect(ImVec2(b.x-r,top_y), ImVec2(b.x,bot_y), col);
  8049. if (rounding_corners & 1) AddArcFast(ImVec2(a.x+r,a.y+r), r, col, 0, 3, true);
  8050. if (rounding_corners & 2) AddArcFast(ImVec2(b.x-r,a.y+r), r, col, 3, 6, true);
  8051. if (rounding_corners & 4) AddArcFast(ImVec2(b.x-r,b.y-r), r, col, 6, 9, true);
  8052. if (rounding_corners & 8) AddArcFast(ImVec2(a.x+r,b.y-r), r, col, 9, 12, true);
  8053. }
  8054. }
  8055. void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col)
  8056. {
  8057. if ((col >> 24) == 0)
  8058. return;
  8059. PrimReserve(3);
  8060. PrimTriangle(a, b, c, col);
  8061. }
  8062. void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments)
  8063. {
  8064. if ((col >> 24) == 0)
  8065. return;
  8066. PrimReserve((unsigned int)num_segments*6);
  8067. const float a_step = 2*IM_PI/(float)num_segments;
  8068. float a0 = 0.0f;
  8069. for (int i = 0; i < num_segments; i++)
  8070. {
  8071. const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
  8072. PrimLine(centre + ImVec2(cosf(a0), sinf(a0))*radius, centre + ImVec2(cosf(a1), sinf(a1))*radius, col);
  8073. a0 = a1;
  8074. }
  8075. }
  8076. void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments)
  8077. {
  8078. if ((col >> 24) == 0)
  8079. return;
  8080. const ImVec2 uv = GImGui->FontTexUvWhitePixel;
  8081. PrimReserve((unsigned int)num_segments*3);
  8082. const float a_step = 2*IM_PI/(float)num_segments;
  8083. float a0 = 0.0f;
  8084. for (int i = 0; i < num_segments; i++)
  8085. {
  8086. const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
  8087. PrimVtx(centre + ImVec2(cosf(a0), sinf(a0))*radius, uv, col);
  8088. PrimVtx(centre + ImVec2(cosf(a1), sinf(a1))*radius, uv, col);
  8089. PrimVtx(centre, uv, col);
  8090. a0 = a1;
  8091. }
  8092. }
  8093. void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width, const ImVec4* cpu_fine_clip_rect)
  8094. {
  8095. if ((col >> 24) == 0)
  8096. return;
  8097. if (text_end == NULL)
  8098. text_end = text_begin + strlen(text_begin);
  8099. if (text_begin == text_end)
  8100. return;
  8101. IM_ASSERT(font->ContainerAtlas->TexID == texture_id_stack.back()); // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
  8102. // reserve vertices for worse case
  8103. const unsigned int char_count = (unsigned int)(text_end - text_begin);
  8104. const unsigned int vtx_count_max = char_count * 6;
  8105. const size_t vtx_begin = vtx_buffer.size();
  8106. PrimReserve(vtx_count_max);
  8107. ImVec4 clip_rect = clip_rect_stack.back();
  8108. if (cpu_fine_clip_rect)
  8109. {
  8110. clip_rect.x = ImMax(clip_rect.x, cpu_fine_clip_rect->x);
  8111. clip_rect.y = ImMax(clip_rect.y, cpu_fine_clip_rect->y);
  8112. clip_rect.z = ImMin(clip_rect.z, cpu_fine_clip_rect->z);
  8113. clip_rect.w = ImMin(clip_rect.w, cpu_fine_clip_rect->w);
  8114. }
  8115. font->RenderText(font_size, pos, col, clip_rect, text_begin, text_end, this, wrap_width, cpu_fine_clip_rect != NULL);
  8116. // give back unused vertices
  8117. vtx_buffer.resize((size_t)(vtx_write - &vtx_buffer.front()));
  8118. const size_t vtx_count = vtx_buffer.size() - vtx_begin;
  8119. commands.back().vtx_count -= (unsigned int)(vtx_count_max - vtx_count);
  8120. vtx_write -= (vtx_count_max - vtx_count);
  8121. }
  8122. void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col)
  8123. {
  8124. if ((col >> 24) == 0)
  8125. return;
  8126. // FIXME-OPT: This is wasting draw calls.
  8127. const bool push_texture_id = texture_id_stack.empty() || user_texture_id != texture_id_stack.back();
  8128. if (push_texture_id)
  8129. PushTextureID(user_texture_id);
  8130. PrimReserve(6);
  8131. PrimRectUV(a, b, uv0, uv1, col);
  8132. if (push_texture_id)
  8133. PopTextureID();
  8134. }
  8135. //-----------------------------------------------------------------------------
  8136. // ImFontAtlias
  8137. //-----------------------------------------------------------------------------
  8138. struct ImFontAtlas::ImFontAtlasData
  8139. {
  8140. // Input
  8141. ImFont* OutFont; // Load into this font
  8142. void* TTFData; // TTF data, we own the memory
  8143. size_t TTFDataSize; // TTF data size, in bytes
  8144. float SizePixels; // Desired output size, in pixels
  8145. const ImWchar* GlyphRanges; // List of Unicode range (2 value per range, values are inclusive, zero-terminated list)
  8146. int FontNo; // Index of font within .TTF file (0)
  8147. // Temporary Build Data
  8148. stbtt_fontinfo FontInfo;
  8149. stbrp_rect* Rects;
  8150. stbtt_pack_range* Ranges;
  8151. int RangesCount;
  8152. };
  8153. ImFontAtlas::ImFontAtlas()
  8154. {
  8155. TexID = NULL;
  8156. TexPixelsAlpha8 = NULL;
  8157. TexPixelsRGBA32 = NULL;
  8158. TexWidth = TexHeight = 0;
  8159. TexUvWhitePixel = ImVec2(0, 0);
  8160. }
  8161. ImFontAtlas::~ImFontAtlas()
  8162. {
  8163. Clear();
  8164. }
  8165. void ImFontAtlas::ClearInputData()
  8166. {
  8167. for (size_t i = 0; i < InputData.size(); i++)
  8168. {
  8169. if (InputData[i]->TTFData)
  8170. ImGui::MemFree(InputData[i]->TTFData);
  8171. ImGui::MemFree(InputData[i]);
  8172. }
  8173. InputData.clear();
  8174. }
  8175. void ImFontAtlas::ClearTexData()
  8176. {
  8177. if (TexPixelsAlpha8)
  8178. ImGui::MemFree(TexPixelsAlpha8);
  8179. if (TexPixelsRGBA32)
  8180. ImGui::MemFree(TexPixelsRGBA32);
  8181. TexPixelsAlpha8 = NULL;
  8182. TexPixelsRGBA32 = NULL;
  8183. }
  8184. void ImFontAtlas::ClearFonts()
  8185. {
  8186. for (size_t i = 0; i < Fonts.size(); i++)
  8187. {
  8188. Fonts[i]->~ImFont();
  8189. ImGui::MemFree(Fonts[i]);
  8190. }
  8191. Fonts.clear();
  8192. }
  8193. void ImFontAtlas::Clear()
  8194. {
  8195. ClearInputData();
  8196. ClearTexData();
  8197. ClearFonts();
  8198. }
  8199. #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
  8200. void ImGui::GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size)
  8201. {
  8202. printf("GetDefaultFontData() is obsoleted in ImGui 1.30.\n");
  8203. printf("Please use ImGui::GetIO().Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() functions to retrieve uncompressed texture data.\n");
  8204. if (fnt_data) *fnt_data = NULL;
  8205. if (fnt_size) *fnt_size = 0;
  8206. if (png_data) *png_data = NULL;
  8207. if (png_size) *png_size = 0;
  8208. IM_ASSERT(false);
  8209. }
  8210. #endif
  8211. void ImFontAtlas::GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel)
  8212. {
  8213. // Lazily build
  8214. if (TexPixelsAlpha8 == NULL)
  8215. {
  8216. if (InputData.empty())
  8217. AddFontDefault();
  8218. Build();
  8219. }
  8220. *out_pixels = TexPixelsAlpha8;
  8221. if (out_width) *out_width = TexWidth;
  8222. if (out_height) *out_height = TexHeight;
  8223. if (out_bytes_per_pixel) *out_bytes_per_pixel = 1;
  8224. }
  8225. void ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel)
  8226. {
  8227. // Lazily convert to RGBA32 format
  8228. // Although it is likely to be the most commonly used format, our font rendering is 8 bpp
  8229. if (!TexPixelsRGBA32)
  8230. {
  8231. unsigned char* pixels;
  8232. GetTexDataAsAlpha8(&pixels, NULL, NULL);
  8233. TexPixelsRGBA32 = (unsigned int*)ImGui::MemAlloc((size_t)(TexWidth * TexHeight * 4));
  8234. const unsigned char* src = pixels;
  8235. unsigned int* dst = TexPixelsRGBA32;
  8236. for (int n = TexWidth * TexHeight; n > 0; n--)
  8237. *dst++ = ((unsigned int)(*src++) << 24) | 0x00FFFFFF;
  8238. }
  8239. *out_pixels = (unsigned char*)TexPixelsRGBA32;
  8240. if (out_width) *out_width = TexWidth;
  8241. if (out_height) *out_height = TexHeight;
  8242. if (out_bytes_per_pixel) *out_bytes_per_pixel = 4;
  8243. }
  8244. static void GetDefaultCompressedFontDataTTF(const void** ttf_compressed_data, unsigned int* ttf_compressed_size);
  8245. static unsigned int stb_decompress_length(unsigned char *input);
  8246. static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length);
  8247. // Load embedded ProggyClean.ttf at size 13
  8248. ImFont* ImFontAtlas::AddFontDefault()
  8249. {
  8250. unsigned int ttf_compressed_size;
  8251. const void* ttf_compressed;
  8252. GetDefaultCompressedFontDataTTF(&ttf_compressed, &ttf_compressed_size);
  8253. ImFont* font = AddFontFromMemoryCompressedTTF(ttf_compressed, ttf_compressed_size, 13.0f, GetGlyphRangesDefault(), 0);
  8254. font->DisplayOffset.y += 1;
  8255. return font;
  8256. }
  8257. ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImWchar* glyph_ranges, int font_no)
  8258. {
  8259. void* data = NULL;
  8260. size_t data_size = 0;
  8261. if (!ImLoadFileToMemory(filename, "rb", (void**)&data, &data_size))
  8262. {
  8263. IM_ASSERT(0); // Could not load file.
  8264. return NULL;
  8265. }
  8266. ImFont* font = AddFontFromMemoryTTF(data, (unsigned int)data_size, size_pixels, glyph_ranges, font_no);
  8267. return font;
  8268. }
  8269. // Transfer ownership of 'ttf_data' to ImFontAtlas, will be deleted after Build()
  8270. ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, const ImWchar* glyph_ranges, int font_no)
  8271. {
  8272. // Create new font
  8273. ImFont* font = (ImFont*)ImGui::MemAlloc(sizeof(ImFont));
  8274. new (font) ImFont();
  8275. Fonts.push_back(font);
  8276. // Add to build list
  8277. ImFontAtlasData* data = (ImFontAtlasData*)ImGui::MemAlloc(sizeof(ImFontAtlasData));
  8278. memset(data, 0, sizeof(ImFontAtlasData));
  8279. data->OutFont = font;
  8280. data->TTFData = ttf_data;
  8281. data->TTFDataSize = (size_t)ttf_size;
  8282. data->SizePixels = size_pixels;
  8283. data->GlyphRanges = glyph_ranges;
  8284. data->FontNo = font_no;
  8285. InputData.push_back(data);
  8286. // Invalidate texture
  8287. ClearTexData();
  8288. return font;
  8289. }
  8290. ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImWchar* glyph_ranges, int font_no)
  8291. {
  8292. // Decompress
  8293. const size_t buf_decompressed_size = stb_decompress_length((unsigned char*)compressed_ttf_data);
  8294. unsigned char* buf_decompressed_data = (unsigned char *)ImGui::MemAlloc(buf_decompressed_size);
  8295. stb_decompress(buf_decompressed_data, (unsigned char*)compressed_ttf_data, (unsigned int)compressed_ttf_size);
  8296. // Add
  8297. ImFont* font = AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, size_pixels, glyph_ranges, font_no);
  8298. return font;
  8299. }
  8300. bool ImFontAtlas::Build()
  8301. {
  8302. IM_ASSERT(InputData.size() > 0);
  8303. TexID = NULL;
  8304. TexWidth = TexHeight = 0;
  8305. TexUvWhitePixel = ImVec2(0, 0);
  8306. ClearTexData();
  8307. // Initialize font information early (so we can error without any cleanup) + count glyphs
  8308. int total_glyph_count = 0;
  8309. int total_glyph_range_count = 0;
  8310. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  8311. {
  8312. ImFontAtlasData& data = *InputData[input_i];
  8313. IM_ASSERT(data.OutFont && (!data.OutFont->IsLoaded() || data.OutFont->ContainerAtlas == this));
  8314. const int font_offset = stbtt_GetFontOffsetForIndex((unsigned char*)data.TTFData, data.FontNo);
  8315. IM_ASSERT(font_offset >= 0);
  8316. if (!stbtt_InitFont(&data.FontInfo, (unsigned char*)data.TTFData, font_offset))
  8317. return false;
  8318. if (!data.GlyphRanges)
  8319. data.GlyphRanges = GetGlyphRangesDefault();
  8320. for (const ImWchar* in_range = data.GlyphRanges; in_range[0] && in_range[1]; in_range += 2)
  8321. {
  8322. total_glyph_count += (in_range[1] - in_range[0]) + 1;
  8323. total_glyph_range_count++;
  8324. }
  8325. }
  8326. // Start packing
  8327. TexWidth = (total_glyph_count > 1000) ? 1024 : 512; // Width doesn't actually matters.
  8328. TexHeight = 0;
  8329. const int max_tex_height = 1024*32;
  8330. stbtt_pack_context spc;
  8331. int ret = stbtt_PackBegin(&spc, NULL, TexWidth, max_tex_height, 0, 1, NULL);
  8332. IM_ASSERT(ret);
  8333. stbtt_PackSetOversampling(&spc, 1, 1);
  8334. // Pack our extra data rectangles first, so it will be on the upper-left corner of our texture (UV will have small values).
  8335. ImVector<stbrp_rect> extra_rects;
  8336. RenderCustomTexData(0, &extra_rects);
  8337. stbrp_pack_rects((stbrp_context*)spc.pack_info, &extra_rects[0], (int)extra_rects.size());
  8338. for (size_t i = 0; i < extra_rects.size(); i++)
  8339. if (extra_rects[i].was_packed)
  8340. TexHeight = ImMax(TexHeight, extra_rects[i].y + extra_rects[i].h);
  8341. // Allocate packing character data and flag packed characters buffer as non-packed (x0=y0=x1=y1=0)
  8342. int buf_packedchars_n = 0, buf_rects_n = 0, buf_ranges_n = 0;
  8343. stbtt_packedchar* buf_packedchars = (stbtt_packedchar*)ImGui::MemAlloc(total_glyph_count * sizeof(stbtt_packedchar));
  8344. stbrp_rect* buf_rects = (stbrp_rect*)ImGui::MemAlloc(total_glyph_count * sizeof(stbrp_rect));
  8345. stbtt_pack_range* buf_ranges = (stbtt_pack_range*)ImGui::MemAlloc(total_glyph_range_count * sizeof(stbtt_pack_range));
  8346. memset(buf_packedchars, 0, total_glyph_count * sizeof(stbtt_packedchar));
  8347. memset(buf_rects, 0, total_glyph_count * sizeof(stbrp_rect)); // Unnecessary but let's clear this for the sake of sanity.
  8348. memset(buf_ranges, 0, total_glyph_range_count * sizeof(stbtt_pack_range));
  8349. // First font pass: pack all glyphs (no rendering at this point, we are working with glyph sizes only)
  8350. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  8351. {
  8352. ImFontAtlasData& data = *InputData[input_i];
  8353. // Setup ranges
  8354. int glyph_count = 0;
  8355. int glyph_ranges_count = 0;
  8356. for (const ImWchar* in_range = data.GlyphRanges; in_range[0] && in_range[1]; in_range += 2)
  8357. {
  8358. glyph_count += (in_range[1] - in_range[0]) + 1;
  8359. glyph_ranges_count++;
  8360. }
  8361. data.Ranges = buf_ranges + buf_ranges_n;
  8362. data.RangesCount = glyph_ranges_count;
  8363. buf_ranges_n += glyph_ranges_count;
  8364. for (int i = 0; i < glyph_ranges_count; i++)
  8365. {
  8366. const ImWchar* in_range = &data.GlyphRanges[i * 2];
  8367. stbtt_pack_range& range = data.Ranges[i];
  8368. range.font_size = data.SizePixels;
  8369. range.first_unicode_char_in_range = in_range[0];
  8370. range.num_chars_in_range = (in_range[1] - in_range[0]) + 1;
  8371. range.chardata_for_range = buf_packedchars + buf_packedchars_n;
  8372. buf_packedchars_n += range.num_chars_in_range;
  8373. }
  8374. // Pack
  8375. data.Rects = buf_rects + buf_rects_n;
  8376. buf_rects_n += glyph_count;
  8377. const int n = stbtt_PackFontRangesGatherRects(&spc, &data.FontInfo, data.Ranges, data.RangesCount, data.Rects);
  8378. stbrp_pack_rects((stbrp_context*)spc.pack_info, data.Rects, n);
  8379. // Extend texture height
  8380. for (int i = 0; i < n; i++)
  8381. if (data.Rects[i].was_packed)
  8382. TexHeight = ImMax(TexHeight, data.Rects[i].y + data.Rects[i].h);
  8383. }
  8384. IM_ASSERT(buf_rects_n == total_glyph_count);
  8385. IM_ASSERT(buf_packedchars_n == total_glyph_count);
  8386. IM_ASSERT(buf_ranges_n == total_glyph_range_count);
  8387. // Create texture
  8388. TexHeight = ImUpperPowerOfTwo(TexHeight);
  8389. TexPixelsAlpha8 = (unsigned char*)ImGui::MemAlloc(TexWidth * TexHeight);
  8390. memset(TexPixelsAlpha8, 0, TexWidth * TexHeight);
  8391. spc.pixels = TexPixelsAlpha8;
  8392. spc.height = TexHeight;
  8393. // Second pass: render characters
  8394. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  8395. {
  8396. ImFontAtlasData& data = *InputData[input_i];
  8397. ret = stbtt_PackFontRangesRenderIntoRects(&spc, &data.FontInfo, data.Ranges, data.RangesCount, data.Rects);
  8398. data.Rects = NULL;
  8399. }
  8400. // End packing
  8401. stbtt_PackEnd(&spc);
  8402. ImGui::MemFree(buf_rects);
  8403. buf_rects = NULL;
  8404. // Third pass: setup ImFont and glyphs for runtime
  8405. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  8406. {
  8407. ImFontAtlasData& data = *InputData[input_i];
  8408. data.OutFont->ContainerAtlas = this;
  8409. data.OutFont->FontSize = data.SizePixels;
  8410. const float font_scale = stbtt_ScaleForPixelHeight(&data.FontInfo, data.SizePixels);
  8411. int font_ascent, font_descent, font_line_gap;
  8412. stbtt_GetFontVMetrics(&data.FontInfo, &font_ascent, &font_descent, &font_line_gap);
  8413. data.OutFont->Ascent = (font_ascent * font_scale);
  8414. data.OutFont->Descent = (font_descent * font_scale);
  8415. data.OutFont->Glyphs.resize(0);
  8416. const float uv_scale_x = 1.0f / TexWidth;
  8417. const float uv_scale_y = 1.0f / TexHeight;
  8418. const int character_spacing_x = 1;
  8419. for (int i = 0; i < data.RangesCount; i++)
  8420. {
  8421. stbtt_pack_range& range = data.Ranges[i];
  8422. for (int char_idx = 0; char_idx < range.num_chars_in_range; char_idx += 1)
  8423. {
  8424. const stbtt_packedchar& pc = range.chardata_for_range[char_idx];
  8425. if (!pc.x0 && !pc.x1 && !pc.y0 && !pc.y1)
  8426. continue;
  8427. data.OutFont->Glyphs.resize(data.OutFont->Glyphs.size() + 1);
  8428. ImFont::Glyph& glyph = data.OutFont->Glyphs.back();
  8429. glyph.Codepoint = (ImWchar)(range.first_unicode_char_in_range + char_idx);
  8430. glyph.Width = (signed short)pc.x1 - pc.x0 + 1;
  8431. glyph.Height = (signed short)pc.y1 - pc.y0 + 1;
  8432. glyph.XOffset = (signed short)(pc.xoff);
  8433. glyph.YOffset = (signed short)(pc.yoff + (int)(font_ascent * font_scale));
  8434. glyph.XAdvance = (signed short)(pc.xadvance + character_spacing_x); // Bake spacing into XAdvance
  8435. glyph.U0 = ((float)pc.x0 - 0.5f) * uv_scale_x;
  8436. glyph.V0 = ((float)pc.y0 - 0.5f) * uv_scale_y;
  8437. glyph.U1 = ((float)pc.x0 - 0.5f + glyph.Width) * uv_scale_x;
  8438. glyph.V1 = ((float)pc.y0 - 0.5f + glyph.Height) * uv_scale_y;
  8439. }
  8440. }
  8441. data.OutFont->BuildLookupTable();
  8442. }
  8443. // Cleanup temporaries
  8444. ImGui::MemFree(buf_packedchars);
  8445. ImGui::MemFree(buf_ranges);
  8446. buf_packedchars = NULL;
  8447. buf_ranges = NULL;
  8448. // Render into our custom data block
  8449. RenderCustomTexData(1, &extra_rects);
  8450. return true;
  8451. }
  8452. void ImFontAtlas::RenderCustomTexData(int pass, void* p_rects)
  8453. {
  8454. // . = white layer, X = black layer, others are blank
  8455. const int TEX_DATA_W = 90;
  8456. const int TEX_DATA_H = 27;
  8457. const char texture_data[TEX_DATA_W*TEX_DATA_H+1] =
  8458. {
  8459. "..- -XXXXXXX- X - X -XXXXXXX - XXXXXXX"
  8460. "..- -X.....X- X.X - X.X -X.....X - X.....X"
  8461. "--- -XXX.XXX- X...X - X...X -X....X - X....X"
  8462. "X - X.X - X.....X - X.....X -X...X - X...X"
  8463. "XX - X.X -X.......X- X.......X -X..X.X - X.X..X"
  8464. "X.X - X.X -XXXX.XXXX- XXXX.XXXX -X.X X.X - X.X X.X"
  8465. "X..X - X.X - X.X - X.X -XX X.X - X.X XX"
  8466. "X...X - X.X - X.X - XX X.X XX - X.X - X.X "
  8467. "X....X - X.X - X.X - X.X X.X X.X - X.X - X.X "
  8468. "X.....X - X.X - X.X - X..X X.X X..X - X.X - X.X "
  8469. "X......X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X XX-XX X.X "
  8470. "X.......X - X.X - X.X -X.....................X- X.X X.X-X.X X.X "
  8471. "X........X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X..X-X..X.X "
  8472. "X.........X -XXX.XXX- X.X - X..X X.X X..X - X...X-X...X "
  8473. "X..........X-X.....X- X.X - X.X X.X X.X - X....X-X....X "
  8474. "X......XXXXX-XXXXXXX- X.X - XX X.X XX - X.....X-X.....X "
  8475. "X...X..X --------- X.X - X.X - XXXXXXX-XXXXXXX "
  8476. "X..X X..X - -XXXX.XXXX- XXXX.XXXX ------------------------------------"
  8477. "X.X X..X - -X.......X- X.......X - XX XX - "
  8478. "XX X..X - - X.....X - X.....X - X.X X.X - "
  8479. " X..X - X...X - X...X - X..X X..X - "
  8480. " XX - X.X - X.X - X...XXXXXXXXXXXXX...X - "
  8481. "------------ - X - X -X.....................X- "
  8482. " ----------------------------------- X...XXXXXXXXXXXXX...X - "
  8483. " - X..X X..X - "
  8484. " - X.X X.X - "
  8485. " - XX XX - "
  8486. };
  8487. ImVector<stbrp_rect>& rects = *(ImVector<stbrp_rect>*)p_rects;
  8488. if (pass == 0)
  8489. {
  8490. stbrp_rect r;
  8491. memset(&r, 0, sizeof(r));
  8492. r.w = (TEX_DATA_W*2)+1;
  8493. r.h = TEX_DATA_H+1;
  8494. rects.push_back(r);
  8495. }
  8496. else if (pass == 1)
  8497. {
  8498. // Copy pixels
  8499. const stbrp_rect& r = rects[0];
  8500. for (int y = 0, n = 0; y < TEX_DATA_H; y++)
  8501. for (int x = 0; x < TEX_DATA_W; x++, n++)
  8502. {
  8503. const int offset0 = (int)(r.x + x) + (int)(r.y + y) * TexWidth;
  8504. const int offset1 = offset0 + 1 + TEX_DATA_W;
  8505. TexPixelsAlpha8[offset0] = texture_data[n] == '.' ? 0xFF : 0x00;
  8506. TexPixelsAlpha8[offset1] = texture_data[n] == 'X' ? 0xFF : 0x00;
  8507. }
  8508. const ImVec2 tex_uv_scale(1.0f / TexWidth, 1.0f / TexHeight);
  8509. TexUvWhitePixel = ImVec2(r.x + 0.5f, r.y + 0.5f) * tex_uv_scale;
  8510. const ImVec2 cursor_datas[ImGuiMouseCursor_Count_][3] =
  8511. {
  8512. // Pos ........ Size ......... Offset ......
  8513. { ImVec2(0,3), ImVec2(12,19), ImVec2( 0, 0) }, // ImGuiMouseCursor_Arrow
  8514. { ImVec2(13,0), ImVec2(7,16), ImVec2( 4, 8) }, // ImGuiMouseCursor_TextInput
  8515. { ImVec2(31,0), ImVec2(23,23), ImVec2(11,11) }, // ImGuiMouseCursor_Move
  8516. { ImVec2(21,0), ImVec2( 9,23), ImVec2( 5,11) }, // ImGuiMouseCursor_ResizeNS
  8517. { ImVec2(55,18),ImVec2(23, 9), ImVec2(11, 5) }, // ImGuiMouseCursor_ResizeEW
  8518. { ImVec2(73,0), ImVec2(17,17), ImVec2( 9, 9) }, // ImGuiMouseCursor_ResizeNESW
  8519. { ImVec2(55,0), ImVec2(17,17), ImVec2( 9, 9) }, // ImGuiMouseCursor_ResizeNWSE
  8520. };
  8521. for (int type = 0; type < ImGuiMouseCursor_Count_; type++)
  8522. {
  8523. ImGuiMouseCursorData& cursor_data = GImGui->MouseCursorData[type];
  8524. ImVec2 pos = cursor_datas[type][0] + ImVec2((float)r.x, (float)r.y);
  8525. const ImVec2 size = cursor_datas[type][1];
  8526. cursor_data.Type = type;
  8527. cursor_data.Size = size;
  8528. cursor_data.Offset = cursor_datas[type][2];
  8529. cursor_data.TexUvMin[0] = (pos) * tex_uv_scale;
  8530. cursor_data.TexUvMax[0] = (pos + size) * tex_uv_scale;
  8531. pos.x += TEX_DATA_W+1;
  8532. cursor_data.TexUvMin[1] = (pos) * tex_uv_scale;
  8533. cursor_data.TexUvMax[1] = (pos + size) * tex_uv_scale;
  8534. }
  8535. }
  8536. }
  8537. // Retrieve list of range (2 int per range, values are inclusive)
  8538. const ImWchar* ImFontAtlas::GetGlyphRangesDefault()
  8539. {
  8540. static const ImWchar ranges[] =
  8541. {
  8542. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  8543. 0,
  8544. };
  8545. return &ranges[0];
  8546. }
  8547. const ImWchar* ImFontAtlas::GetGlyphRangesChinese()
  8548. {
  8549. static const ImWchar ranges[] =
  8550. {
  8551. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  8552. 0x3000, 0x30FF, // Punctuations, Hiragana, Katakana
  8553. 0x31F0, 0x31FF, // Katakana Phonetic Extensions
  8554. 0xFF00, 0xFFEF, // Half-width characters
  8555. 0x4e00, 0x9FAF, // CJK Ideograms
  8556. 0,
  8557. };
  8558. return &ranges[0];
  8559. }
  8560. const ImWchar* ImFontAtlas::GetGlyphRangesJapanese()
  8561. {
  8562. // Store the 1946 ideograms code points as successive offsets from the initial unicode codepoint 0x4E00. Each offset has an implicit +1.
  8563. // This encoding helps us reduce the source code size.
  8564. static const short offsets_from_0x4E00[] =
  8565. {
  8566. -1,0,1,3,0,0,0,0,1,0,5,1,1,0,7,4,6,10,0,1,9,9,7,1,3,19,1,10,7,1,0,1,0,5,1,0,6,4,2,6,0,0,12,6,8,0,3,5,0,1,0,9,0,0,8,1,1,3,4,5,13,0,0,8,2,17,
  8567. 4,3,1,1,9,6,0,0,0,2,1,3,2,22,1,9,11,1,13,1,3,12,0,5,9,2,0,6,12,5,3,12,4,1,2,16,1,1,4,6,5,3,0,6,13,15,5,12,8,14,0,0,6,15,3,6,0,18,8,1,6,14,1,
  8568. 5,4,12,24,3,13,12,10,24,0,0,0,1,0,1,1,2,9,10,2,2,0,0,3,3,1,0,3,8,0,3,2,4,4,1,6,11,10,14,6,15,3,4,15,1,0,0,5,2,2,0,0,1,6,5,5,6,0,3,6,5,0,0,1,0,
  8569. 11,2,2,8,4,7,0,10,0,1,2,17,19,3,0,2,5,0,6,2,4,4,6,1,1,11,2,0,3,1,2,1,2,10,7,6,3,16,0,8,24,0,0,3,1,1,3,0,1,6,0,0,0,2,0,1,5,15,0,1,0,0,2,11,19,
  8570. 1,4,19,7,6,5,1,0,0,0,0,5,1,0,1,9,0,0,5,0,2,0,1,0,3,0,11,3,0,2,0,0,0,0,0,9,3,6,4,12,0,14,0,0,29,10,8,0,14,37,13,0,31,16,19,0,8,30,1,20,8,3,48,
  8571. 21,1,0,12,0,10,44,34,42,54,11,18,82,0,2,1,2,12,1,0,6,2,17,2,12,7,0,7,17,4,2,6,24,23,8,23,39,2,16,23,1,0,5,1,2,15,14,5,6,2,11,0,8,6,2,2,2,14,
  8572. 20,4,15,3,4,11,10,10,2,5,2,1,30,2,1,0,0,22,5,5,0,3,1,5,4,1,0,0,2,2,21,1,5,1,2,16,2,1,3,4,0,8,4,0,0,5,14,11,2,16,1,13,1,7,0,22,15,3,1,22,7,14,
  8573. 22,19,11,24,18,46,10,20,64,45,3,2,0,4,5,0,1,4,25,1,0,0,2,10,0,0,0,1,0,1,2,0,0,9,1,2,0,0,0,2,5,2,1,1,5,5,8,1,1,1,5,1,4,9,1,3,0,1,0,1,1,2,0,0,
  8574. 2,0,1,8,22,8,1,0,0,0,0,4,2,1,0,9,8,5,0,9,1,30,24,2,6,4,39,0,14,5,16,6,26,179,0,2,1,1,0,0,0,5,2,9,6,0,2,5,16,7,5,1,1,0,2,4,4,7,15,13,14,0,0,
  8575. 3,0,1,0,0,0,2,1,6,4,5,1,4,9,0,3,1,8,0,0,10,5,0,43,0,2,6,8,4,0,2,0,0,9,6,0,9,3,1,6,20,14,6,1,4,0,7,2,3,0,2,0,5,0,3,1,0,3,9,7,0,3,4,0,4,9,1,6,0,
  8576. 9,0,0,2,3,10,9,28,3,6,2,4,1,2,32,4,1,18,2,0,3,1,5,30,10,0,2,2,2,0,7,9,8,11,10,11,7,2,13,7,5,10,0,3,40,2,0,1,6,12,0,4,5,1,5,11,11,21,4,8,3,7,
  8577. 8,8,33,5,23,0,0,19,8,8,2,3,0,6,1,1,1,5,1,27,4,2,5,0,3,5,6,3,1,0,3,1,12,5,3,3,2,0,7,7,2,1,0,4,0,1,1,2,0,10,10,6,2,5,9,7,5,15,15,21,6,11,5,20,
  8578. 4,3,5,5,2,5,0,2,1,0,1,7,28,0,9,0,5,12,5,5,18,30,0,12,3,3,21,16,25,32,9,3,14,11,24,5,66,9,1,2,0,5,9,1,5,1,8,0,8,3,3,0,1,15,1,4,8,1,2,7,0,7,2,
  8579. 8,3,7,5,3,7,10,2,1,0,0,2,25,0,6,4,0,10,0,4,2,4,1,12,5,38,4,0,4,1,10,5,9,4,0,14,4,2,5,18,20,21,1,3,0,5,0,7,0,3,7,1,3,1,1,8,1,0,0,0,3,2,5,2,11,
  8580. 6,0,13,1,3,9,1,12,0,16,6,2,1,0,2,1,12,6,13,11,2,0,28,1,7,8,14,13,8,13,0,2,0,5,4,8,10,2,37,42,19,6,6,7,4,14,11,18,14,80,7,6,0,4,72,12,36,27,
  8581. 7,7,0,14,17,19,164,27,0,5,10,7,3,13,6,14,0,2,2,5,3,0,6,13,0,0,10,29,0,4,0,3,13,0,3,1,6,51,1,5,28,2,0,8,0,20,2,4,0,25,2,10,13,10,0,16,4,0,1,0,
  8582. 2,1,7,0,1,8,11,0,0,1,2,7,2,23,11,6,6,4,16,2,2,2,0,22,9,3,3,5,2,0,15,16,21,2,9,20,15,15,5,3,9,1,0,0,1,7,7,5,4,2,2,2,38,24,14,0,0,15,5,6,24,14,
  8583. 5,5,11,0,21,12,0,3,8,4,11,1,8,0,11,27,7,2,4,9,21,59,0,1,39,3,60,62,3,0,12,11,0,3,30,11,0,13,88,4,15,5,28,13,1,4,48,17,17,4,28,32,46,0,16,0,
  8584. 18,11,1,8,6,38,11,2,6,11,38,2,0,45,3,11,2,7,8,4,30,14,17,2,1,1,65,18,12,16,4,2,45,123,12,56,33,1,4,3,4,7,0,0,0,3,2,0,16,4,2,4,2,0,7,4,5,2,26,
  8585. 2,25,6,11,6,1,16,2,6,17,77,15,3,35,0,1,0,5,1,0,38,16,6,3,12,3,3,3,0,9,3,1,3,5,2,9,0,18,0,25,1,3,32,1,72,46,6,2,7,1,3,14,17,0,28,1,40,13,0,20,
  8586. 15,40,6,38,24,12,43,1,1,9,0,12,6,0,6,2,4,19,3,7,1,48,0,9,5,0,5,6,9,6,10,15,2,11,19,3,9,2,0,1,10,1,27,8,1,3,6,1,14,0,26,0,27,16,3,4,9,6,2,23,
  8587. 9,10,5,25,2,1,6,1,1,48,15,9,15,14,3,4,26,60,29,13,37,21,1,6,4,0,2,11,22,23,16,16,2,2,1,3,0,5,1,6,4,0,0,4,0,0,8,3,0,2,5,0,7,1,7,3,13,2,4,10,
  8588. 3,0,2,31,0,18,3,0,12,10,4,1,0,7,5,7,0,5,4,12,2,22,10,4,2,15,2,8,9,0,23,2,197,51,3,1,1,4,13,4,3,21,4,19,3,10,5,40,0,4,1,1,10,4,1,27,34,7,21,
  8589. 2,17,2,9,6,4,2,3,0,4,2,7,8,2,5,1,15,21,3,4,4,2,2,17,22,1,5,22,4,26,7,0,32,1,11,42,15,4,1,2,5,0,19,3,1,8,6,0,10,1,9,2,13,30,8,2,24,17,19,1,4,
  8590. 4,25,13,0,10,16,11,39,18,8,5,30,82,1,6,8,18,77,11,13,20,75,11,112,78,33,3,0,0,60,17,84,9,1,1,12,30,10,49,5,32,158,178,5,5,6,3,3,1,3,1,4,7,6,
  8591. 19,31,21,0,2,9,5,6,27,4,9,8,1,76,18,12,1,4,0,3,3,6,3,12,2,8,30,16,2,25,1,5,5,4,3,0,6,10,2,3,1,0,5,1,19,3,0,8,1,5,2,6,0,0,0,19,1,2,0,5,1,2,5,
  8592. 1,3,7,0,4,12,7,3,10,22,0,9,5,1,0,2,20,1,1,3,23,30,3,9,9,1,4,191,14,3,15,6,8,50,0,1,0,0,4,0,0,1,0,2,4,2,0,2,3,0,2,0,2,2,8,7,0,1,1,1,3,3,17,11,
  8593. 91,1,9,3,2,13,4,24,15,41,3,13,3,1,20,4,125,29,30,1,0,4,12,2,21,4,5,5,19,11,0,13,11,86,2,18,0,7,1,8,8,2,2,22,1,2,6,5,2,0,1,2,8,0,2,0,5,2,1,0,
  8594. 2,10,2,0,5,9,2,1,2,0,1,0,4,0,0,10,2,5,3,0,6,1,0,1,4,4,33,3,13,17,3,18,6,4,7,1,5,78,0,4,1,13,7,1,8,1,0,35,27,15,3,0,0,0,1,11,5,41,38,15,22,6,
  8595. 14,14,2,1,11,6,20,63,5,8,27,7,11,2,2,40,58,23,50,54,56,293,8,8,1,5,1,14,0,1,12,37,89,8,8,8,2,10,6,0,0,0,4,5,2,1,0,1,1,2,7,0,3,3,0,4,6,0,3,2,
  8596. 19,3,8,0,0,0,4,4,16,0,4,1,5,1,3,0,3,4,6,2,17,10,10,31,6,4,3,6,10,126,7,3,2,2,0,9,0,0,5,20,13,0,15,0,6,0,2,5,8,64,50,3,2,12,2,9,0,0,11,8,20,
  8597. 109,2,18,23,0,0,9,61,3,0,28,41,77,27,19,17,81,5,2,14,5,83,57,252,14,154,263,14,20,8,13,6,57,39,38,
  8598. };
  8599. static int ranges_unpacked = false;
  8600. static ImWchar ranges[8 + IM_ARRAYSIZE(offsets_from_0x4E00)*2 + 1] =
  8601. {
  8602. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  8603. 0x3000, 0x30FF, // Punctuations, Hiragana, Katakana
  8604. 0x31F0, 0x31FF, // Katakana Phonetic Extensions
  8605. 0xFF00, 0xFFEF, // Half-width characters
  8606. };
  8607. if (!ranges_unpacked)
  8608. {
  8609. // Unpack
  8610. int codepoint = 0x4e00;
  8611. ImWchar* dst = &ranges[8];
  8612. for (int n = 0; n < IM_ARRAYSIZE(offsets_from_0x4E00); n++, dst += 2)
  8613. dst[0] = dst[1] = (ImWchar)(codepoint += (offsets_from_0x4E00[n] + 1));
  8614. dst[0] = 0;
  8615. ranges_unpacked = true;
  8616. }
  8617. return &ranges[0];
  8618. }
  8619. const ImWchar* ImFontAtlas::GetGlyphRangesCyrillic()
  8620. {
  8621. static const ImWchar ranges[] =
  8622. {
  8623. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  8624. 0x0400, 0x052F, // Cyrillic + Cyrillic Supplement
  8625. 0x2DE0, 0x2DFF, // Cyrillic Extended-A
  8626. 0xA640, 0xA69F, // Cyrillic Extended-B
  8627. 0,
  8628. };
  8629. return &ranges[0];
  8630. }
  8631. //-----------------------------------------------------------------------------
  8632. // ImFont
  8633. //-----------------------------------------------------------------------------
  8634. ImFont::ImFont()
  8635. {
  8636. Scale = 1.0f;
  8637. FallbackChar = (ImWchar)'?';
  8638. Clear();
  8639. }
  8640. ImFont::~ImFont()
  8641. {
  8642. // Invalidate active font so that the user gets a clear crash instead of a dangling pointer.
  8643. // If you want to delete fonts you need to do it between Render() and NewFrame().
  8644. ImGuiState& g = *GImGui;
  8645. if (g.Font == this)
  8646. g.Font = NULL;
  8647. Clear();
  8648. }
  8649. void ImFont::Clear()
  8650. {
  8651. FontSize = 0.0f;
  8652. DisplayOffset = ImVec2(-0.5f, 0.5f);
  8653. Ascent = Descent = 0.0f;
  8654. ContainerAtlas = NULL;
  8655. Glyphs.clear();
  8656. FallbackGlyph = NULL;
  8657. FallbackXAdvance = 0.0f;
  8658. IndexXAdvance.clear();
  8659. IndexLookup.clear();
  8660. }
  8661. void ImFont::BuildLookupTable()
  8662. {
  8663. int max_codepoint = 0;
  8664. for (size_t i = 0; i != Glyphs.size(); i++)
  8665. max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint);
  8666. IndexXAdvance.clear();
  8667. IndexXAdvance.resize((size_t)max_codepoint + 1);
  8668. IndexLookup.clear();
  8669. IndexLookup.resize((size_t)max_codepoint + 1);
  8670. for (size_t i = 0; i < (size_t)max_codepoint + 1; i++)
  8671. {
  8672. IndexXAdvance[i] = -1.0f;
  8673. IndexLookup[i] = -1;
  8674. }
  8675. for (size_t i = 0; i < Glyphs.size(); i++)
  8676. {
  8677. const size_t codepoint = (int)Glyphs[i].Codepoint;
  8678. IndexXAdvance[codepoint] = Glyphs[i].XAdvance;
  8679. IndexLookup[codepoint] = (int)i;
  8680. }
  8681. // Create a glyph to handle TAB
  8682. // FIXME: Needs proper TAB handling but it needs to be contextualized (can arbitrary say that each string starts at "column 0"
  8683. if (FindGlyph((unsigned short)' '))
  8684. {
  8685. if (Glyphs.back().Codepoint != '\t') // So we can call this function multiple times
  8686. Glyphs.resize(Glyphs.size() + 1);
  8687. ImFont::Glyph& tab_glyph = Glyphs.back();
  8688. tab_glyph = *FindGlyph((unsigned short)' ');
  8689. tab_glyph.Codepoint = '\t';
  8690. tab_glyph.XAdvance *= 4;
  8691. IndexXAdvance[(size_t)tab_glyph.Codepoint] = (float)tab_glyph.XAdvance;
  8692. IndexLookup[(size_t)tab_glyph.Codepoint] = (int)(Glyphs.size()-1);
  8693. }
  8694. FallbackGlyph = NULL;
  8695. FallbackGlyph = FindGlyph(FallbackChar);
  8696. FallbackXAdvance = FallbackGlyph ? FallbackGlyph->XAdvance : 0.0f;
  8697. for (size_t i = 0; i < (size_t)max_codepoint + 1; i++)
  8698. if (IndexXAdvance[i] < 0.0f)
  8699. IndexXAdvance[i] = FallbackXAdvance;
  8700. }
  8701. void ImFont::SetFallbackChar(ImWchar c)
  8702. {
  8703. FallbackChar = c;
  8704. BuildLookupTable();
  8705. }
  8706. const ImFont::Glyph* ImFont::FindGlyph(unsigned short c) const
  8707. {
  8708. if (c < (int)IndexLookup.size())
  8709. {
  8710. const int i = IndexLookup[c];
  8711. if (i != -1)
  8712. return &Glyphs[i];
  8713. }
  8714. return FallbackGlyph;
  8715. }
  8716. // Convert UTF-8 to 32-bits character, process single character input.
  8717. // Based on stb_from_utf8() from github.com/nothings/stb/
  8718. // We handle UTF-8 decoding error by skipping forward.
  8719. static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end)
  8720. {
  8721. unsigned int c = (unsigned int)-1;
  8722. const unsigned char* str = (const unsigned char*)in_text;
  8723. if (!(*str & 0x80))
  8724. {
  8725. c = (unsigned int)(*str++);
  8726. *out_char = c;
  8727. return 1;
  8728. }
  8729. if ((*str & 0xe0) == 0xc0)
  8730. {
  8731. *out_char = 0;
  8732. if (in_text_end && in_text_end - (const char*)str < 2) return 0;
  8733. if (*str < 0xc2) return 0;
  8734. c = (unsigned int)((*str++ & 0x1f) << 6);
  8735. if ((*str & 0xc0) != 0x80) return 0;
  8736. c += (*str++ & 0x3f);
  8737. *out_char = c;
  8738. return 2;
  8739. }
  8740. if ((*str & 0xf0) == 0xe0)
  8741. {
  8742. *out_char = 0;
  8743. if (in_text_end && in_text_end - (const char*)str < 3) return 0;
  8744. if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return 0;
  8745. if (*str == 0xed && str[1] > 0x9f) return 0; // str[1] < 0x80 is checked below
  8746. c = (unsigned int)((*str++ & 0x0f) << 12);
  8747. if ((*str & 0xc0) != 0x80) return 0;
  8748. c += (unsigned int)((*str++ & 0x3f) << 6);
  8749. if ((*str & 0xc0) != 0x80) return 0;
  8750. c += (*str++ & 0x3f);
  8751. *out_char = c;
  8752. return 3;
  8753. }
  8754. if ((*str & 0xf8) == 0xf0)
  8755. {
  8756. *out_char = 0;
  8757. if (in_text_end && in_text_end - (const char*)str < 4) return 0;
  8758. if (*str > 0xf4) return 0;
  8759. if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return 0;
  8760. if (*str == 0xf4 && str[1] > 0x8f) return 0; // str[1] < 0x80 is checked below
  8761. c = (unsigned int)((*str++ & 0x07) << 18);
  8762. if ((*str & 0xc0) != 0x80) return 0;
  8763. c += (unsigned int)((*str++ & 0x3f) << 12);
  8764. if ((*str & 0xc0) != 0x80) return 0;
  8765. c += (unsigned int)((*str++ & 0x3f) << 6);
  8766. if ((*str & 0xc0) != 0x80) return 0;
  8767. c += (*str++ & 0x3f);
  8768. // utf-8 encodings of values used in surrogate pairs are invalid
  8769. if ((c & 0xFFFFF800) == 0xD800) return 0;
  8770. *out_char = c;
  8771. return 4;
  8772. }
  8773. *out_char = 0;
  8774. return 0;
  8775. }
  8776. static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end, const char** in_text_remaining)
  8777. {
  8778. ImWchar* buf_out = buf;
  8779. ImWchar* buf_end = buf + buf_size;
  8780. while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text)
  8781. {
  8782. unsigned int c;
  8783. in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
  8784. if (c == 0)
  8785. break;
  8786. if (c < 0x10000) // FIXME: Losing characters that don't fit in 2 bytes
  8787. *buf_out++ = (ImWchar)c;
  8788. }
  8789. *buf_out = 0;
  8790. if (in_text_remaining)
  8791. *in_text_remaining = in_text;
  8792. return buf_out - buf;
  8793. }
  8794. static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end)
  8795. {
  8796. int char_count = 0;
  8797. while ((!in_text_end || in_text < in_text_end) && *in_text)
  8798. {
  8799. unsigned int c;
  8800. in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
  8801. if (c == 0)
  8802. break;
  8803. if (c < 0x10000)
  8804. char_count++;
  8805. }
  8806. return char_count;
  8807. }
  8808. // Based on stb_to_utf8() from github.com/nothings/stb/
  8809. static inline int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int c)
  8810. {
  8811. if (c < 0x80)
  8812. {
  8813. buf[0] = (char)c;
  8814. return 1;
  8815. }
  8816. if (c < 0x800)
  8817. {
  8818. if (buf_size < 2) return 0;
  8819. buf[0] = (char)(0xc0 + (c >> 6));
  8820. buf[1] = (char)(0x80 + (c & 0x3f));
  8821. return 2;
  8822. }
  8823. if (c >= 0xdc00 && c < 0xe000)
  8824. {
  8825. return 0;
  8826. }
  8827. if (c >= 0xd800 && c < 0xdc00)
  8828. {
  8829. if (buf_size < 4) return 0;
  8830. buf[0] = (char)(0xf0 + (c >> 18));
  8831. buf[1] = (char)(0x80 + ((c >> 12) & 0x3f));
  8832. buf[2] = (char)(0x80 + ((c >> 6) & 0x3f));
  8833. buf[3] = (char)(0x80 + ((c ) & 0x3f));
  8834. return 4;
  8835. }
  8836. //else if (c < 0x10000)
  8837. {
  8838. if (buf_size < 3) return 0;
  8839. buf[0] = (char)(0xe0 + (c >> 12));
  8840. buf[1] = (char)(0x80 + ((c>> 6) & 0x3f));
  8841. buf[2] = (char)(0x80 + ((c ) & 0x3f));
  8842. return 3;
  8843. }
  8844. }
  8845. static inline int ImTextCountUtf8BytesFromChar(unsigned int c)
  8846. {
  8847. if (c < 0x80) return 1;
  8848. if (c < 0x800) return 2;
  8849. if (c >= 0xdc00 && c < 0xe000) return 0;
  8850. if (c >= 0xd800 && c < 0xdc00) return 4;
  8851. return 3;
  8852. }
  8853. static ptrdiff_t ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end)
  8854. {
  8855. char* buf_out = buf;
  8856. const char* buf_end = buf + buf_size;
  8857. while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text)
  8858. {
  8859. unsigned int c = (unsigned int)(*in_text++);
  8860. if (c < 0x80)
  8861. *buf_out++ = (char)c;
  8862. else
  8863. buf_out += ImTextCharToUtf8(buf_out, (uintptr_t)(buf_end-buf_out-1), c);
  8864. }
  8865. *buf_out = 0;
  8866. return buf_out - buf;
  8867. }
  8868. static int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end)
  8869. {
  8870. int bytes_count = 0;
  8871. while ((!in_text_end || in_text < in_text_end) && *in_text)
  8872. {
  8873. unsigned int c = (unsigned int)(*in_text++);
  8874. if (c < 0x80)
  8875. bytes_count++;
  8876. else
  8877. bytes_count += ImTextCountUtf8BytesFromChar(c);
  8878. }
  8879. return bytes_count;
  8880. }
  8881. const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const
  8882. {
  8883. // Simple word-wrapping for English, not full-featured. Please submit failing cases!
  8884. // 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.)
  8885. // For references, possible wrap point marked with ^
  8886. // "aaa bbb, ccc,ddd. eee fff. ggg!"
  8887. // ^ ^ ^ ^ ^__ ^ ^
  8888. // List of hardcoded separators: .,;!?'"
  8889. // Skip extra blanks after a line returns (that includes not counting them in width computation)
  8890. // e.g. "Hello world" --> "Hello" "World"
  8891. // Cut words that cannot possibly fit within one line.
  8892. // e.g.: "The tropical fish" with ~5 characters worth of width --> "The tr" "opical" "fish"
  8893. float line_width = 0.0f;
  8894. float word_width = 0.0f;
  8895. float blank_width = 0.0f;
  8896. const char* word_end = text;
  8897. const char* prev_word_end = NULL;
  8898. bool inside_word = true;
  8899. const char* s = text;
  8900. while (s < text_end)
  8901. {
  8902. unsigned int c = (unsigned int)*s;
  8903. const char* next_s;
  8904. if (c < 0x80)
  8905. next_s = s + 1;
  8906. else
  8907. next_s = s + ImTextCharFromUtf8(&c, s, text_end);
  8908. if (c == 0)
  8909. break;
  8910. if (c < 32)
  8911. {
  8912. if (c == '\n')
  8913. {
  8914. line_width = word_width = blank_width = 0.0f;
  8915. inside_word = true;
  8916. s = next_s;
  8917. continue;
  8918. }
  8919. if (c == '\r')
  8920. {
  8921. s = next_s;
  8922. continue;
  8923. }
  8924. }
  8925. const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance;
  8926. if (ImCharIsSpace(c))
  8927. {
  8928. if (inside_word)
  8929. {
  8930. line_width += blank_width;
  8931. blank_width = 0.0f;
  8932. }
  8933. blank_width += char_width;
  8934. inside_word = false;
  8935. }
  8936. else
  8937. {
  8938. word_width += char_width;
  8939. if (inside_word)
  8940. {
  8941. word_end = next_s;
  8942. }
  8943. else
  8944. {
  8945. prev_word_end = word_end;
  8946. line_width += word_width + blank_width;
  8947. word_width = blank_width = 0.0f;
  8948. }
  8949. // Allow wrapping after punctuation.
  8950. inside_word = !(c == '.' || c == ',' || c == ';' || c == '!' || c == '?' || c == '\"');
  8951. }
  8952. // We ignore blank width at the end of the line (they can be skipped)
  8953. if (line_width + word_width >= wrap_width)
  8954. {
  8955. // Words that cannot possibly fit within an entire line will be cut anywhere.
  8956. if (word_width < wrap_width)
  8957. s = prev_word_end ? prev_word_end : word_end;
  8958. break;
  8959. }
  8960. s = next_s;
  8961. }
  8962. return s;
  8963. }
  8964. ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining) const
  8965. {
  8966. if (!text_end)
  8967. text_end = text_begin + strlen(text_begin); // FIXME-OPT: Need to avoid this.
  8968. const float line_height = size;
  8969. const float scale = size / FontSize;
  8970. ImVec2 text_size = ImVec2(0,0);
  8971. float line_width = 0.0f;
  8972. const bool word_wrap_enabled = (wrap_width > 0.0f);
  8973. const char* word_wrap_eol = NULL;
  8974. const char* s = text_begin;
  8975. while (s < text_end)
  8976. {
  8977. if (word_wrap_enabled)
  8978. {
  8979. // 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.
  8980. if (!word_wrap_eol)
  8981. {
  8982. word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - line_width);
  8983. if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
  8984. 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
  8985. }
  8986. if (s >= word_wrap_eol)
  8987. {
  8988. if (text_size.x < line_width)
  8989. text_size.x = line_width;
  8990. text_size.y += line_height;
  8991. line_width = 0.0f;
  8992. word_wrap_eol = NULL;
  8993. // Wrapping skips upcoming blanks
  8994. while (s < text_end)
  8995. {
  8996. const char c = *s;
  8997. if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; }
  8998. }
  8999. continue;
  9000. }
  9001. }
  9002. // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
  9003. const char* prev_s = s;
  9004. unsigned int c = (unsigned int)*s;
  9005. if (c < 0x80)
  9006. {
  9007. s += 1;
  9008. }
  9009. else
  9010. {
  9011. s += ImTextCharFromUtf8(&c, s, text_end);
  9012. if (c == 0)
  9013. break;
  9014. }
  9015. if (c < 32)
  9016. {
  9017. if (c == '\n')
  9018. {
  9019. text_size.x = ImMax(text_size.x, line_width);
  9020. text_size.y += line_height;
  9021. line_width = 0.0f;
  9022. continue;
  9023. }
  9024. if (c == '\r')
  9025. continue;
  9026. }
  9027. const float char_width = ((size_t)c < IndexXAdvance.size() ? IndexXAdvance[(size_t)c] : FallbackXAdvance) * scale;
  9028. if (line_width + char_width >= max_width)
  9029. {
  9030. s = prev_s;
  9031. break;
  9032. }
  9033. line_width += char_width;
  9034. }
  9035. if (text_size.x < line_width)
  9036. text_size.x = line_width;
  9037. if (line_width > 0 || text_size.y == 0.0f)
  9038. text_size.y += line_height;
  9039. if (remaining)
  9040. *remaining = s;
  9041. return text_size;
  9042. }
  9043. void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawList* draw_list, float wrap_width, bool cpu_fine_clip) const
  9044. {
  9045. if (!text_end)
  9046. text_end = text_begin + strlen(text_begin);
  9047. // Align to be pixel perfect
  9048. pos.x = (float)(int)pos.x + DisplayOffset.x;
  9049. pos.y = (float)(int)pos.y + DisplayOffset.y;
  9050. float x = pos.x;
  9051. float y = pos.y;
  9052. if (y > clip_rect.w)
  9053. return;
  9054. const float scale = size / FontSize;
  9055. const float line_height = FontSize * scale;
  9056. const bool word_wrap_enabled = (wrap_width > 0.0f);
  9057. const char* word_wrap_eol = NULL;
  9058. ImDrawVert* out_vertices = draw_list->vtx_write;
  9059. const char* s = text_begin;
  9060. if (!word_wrap_enabled && y + line_height < clip_rect.y)
  9061. while (s < text_end && *s != '\n') // Fast-forward to next line
  9062. s++;
  9063. while (s < text_end)
  9064. {
  9065. if (word_wrap_enabled)
  9066. {
  9067. // 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.
  9068. if (!word_wrap_eol)
  9069. {
  9070. word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - pos.x));
  9071. if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
  9072. 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
  9073. }
  9074. if (s >= word_wrap_eol)
  9075. {
  9076. x = pos.x;
  9077. y += line_height;
  9078. word_wrap_eol = NULL;
  9079. // Wrapping skips upcoming blanks
  9080. while (s < text_end)
  9081. {
  9082. const char c = *s;
  9083. if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; }
  9084. }
  9085. continue;
  9086. }
  9087. }
  9088. // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
  9089. unsigned int c = (unsigned int)*s;
  9090. if (c < 0x80)
  9091. {
  9092. s += 1;
  9093. }
  9094. else
  9095. {
  9096. s += ImTextCharFromUtf8(&c, s, text_end);
  9097. if (c == 0)
  9098. break;
  9099. }
  9100. if (c < 32)
  9101. {
  9102. if (c == '\n')
  9103. {
  9104. x = pos.x;
  9105. y += line_height;
  9106. if (y > clip_rect.w)
  9107. break;
  9108. if (!word_wrap_enabled && y + line_height < clip_rect.y)
  9109. while (s < text_end && *s != '\n') // Fast-forward to next line
  9110. s++;
  9111. continue;
  9112. }
  9113. if (c == '\r')
  9114. continue;
  9115. }
  9116. float char_width = 0.0f;
  9117. if (const Glyph* glyph = FindGlyph((unsigned short)c))
  9118. {
  9119. char_width = glyph->XAdvance * scale;
  9120. // Clipping on Y is more likely
  9121. if (c != ' ' && c != '\t')
  9122. {
  9123. // We don't do a second finer clipping test on the Y axis (todo: do some measurement see if it is worth it, probably not)
  9124. float y1 = (float)(y + glyph->YOffset * scale);
  9125. float y2 = (float)(y1 + glyph->Height * scale);
  9126. float x1 = (float)(x + glyph->XOffset * scale);
  9127. float x2 = (float)(x1 + glyph->Width * scale);
  9128. if (x1 <= clip_rect.z && x2 >= clip_rect.x)
  9129. {
  9130. // Render a character
  9131. float u1 = glyph->U0;
  9132. float v1 = glyph->V0;
  9133. float u2 = glyph->U1;
  9134. float v2 = glyph->V1;
  9135. // CPU side clipping used to fit text in their frame when the frame is too small. Only does clipping for axis aligned quads
  9136. if (cpu_fine_clip)
  9137. {
  9138. if (x1 < clip_rect.x)
  9139. {
  9140. u1 = u1 + (1.0f - (x2 - clip_rect.x) / (x2 - x1)) * (u2 - u1);
  9141. x1 = clip_rect.x;
  9142. }
  9143. if (y1 < clip_rect.y)
  9144. {
  9145. v1 = v1 + (1.0f - (y2 - clip_rect.y) / (y2 - y1)) * (v2 - v1);
  9146. y1 = clip_rect.y;
  9147. }
  9148. if (x2 > clip_rect.z)
  9149. {
  9150. u2 = u1 + ((clip_rect.z - x1) / (x2 - x1)) * (u2 - u1);
  9151. x2 = clip_rect.z;
  9152. }
  9153. if (y2 > clip_rect.w)
  9154. {
  9155. v2 = v1 + ((clip_rect.w - y1) / (y2 - y1)) * (v2 - v1);
  9156. y2 = clip_rect.w;
  9157. }
  9158. }
  9159. // NB: we are not calling PrimRectUV() here because non-inlined causes too much overhead in a debug build.
  9160. out_vertices[0].pos = ImVec2(x1, y1);
  9161. out_vertices[0].uv = ImVec2(u1, v1);
  9162. out_vertices[0].col = col;
  9163. out_vertices[1].pos = ImVec2(x2, y1);
  9164. out_vertices[1].uv = ImVec2(u2, v1);
  9165. out_vertices[1].col = col;
  9166. out_vertices[2].pos = ImVec2(x2, y2);
  9167. out_vertices[2].uv = ImVec2(u2, v2);
  9168. out_vertices[2].col = col;
  9169. out_vertices[3] = out_vertices[0];
  9170. out_vertices[4] = out_vertices[2];
  9171. out_vertices[5].pos = ImVec2(x1, y2);
  9172. out_vertices[5].uv = ImVec2(u1, v2);
  9173. out_vertices[5].col = col;
  9174. out_vertices += 6;
  9175. }
  9176. }
  9177. }
  9178. x += char_width;
  9179. }
  9180. draw_list->vtx_write = out_vertices;
  9181. }
  9182. //-----------------------------------------------------------------------------
  9183. // PLATFORM DEPENDANT HELPERS
  9184. //-----------------------------------------------------------------------------
  9185. #if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS)
  9186. #ifndef _WINDOWS_
  9187. #define WIN32_LEAN_AND_MEAN
  9188. #include <windows.h>
  9189. #endif
  9190. #pragma comment(lib, "user32")
  9191. // Win32 API clipboard implementation
  9192. static const char* GetClipboardTextFn_DefaultImpl()
  9193. {
  9194. static char* buf_local = NULL;
  9195. if (buf_local)
  9196. {
  9197. ImGui::MemFree(buf_local);
  9198. buf_local = NULL;
  9199. }
  9200. if (!OpenClipboard(NULL))
  9201. return NULL;
  9202. HANDLE wbuf_handle = GetClipboardData(CF_UNICODETEXT);
  9203. if (wbuf_handle == NULL)
  9204. return NULL;
  9205. if (ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle))
  9206. {
  9207. int buf_len = ImTextCountUtf8BytesFromStr(wbuf_global, NULL) + 1;
  9208. buf_local = (char*)ImGui::MemAlloc(buf_len * sizeof(char));
  9209. ImTextStrToUtf8(buf_local, buf_len, wbuf_global, NULL);
  9210. }
  9211. GlobalUnlock(wbuf_handle);
  9212. CloseClipboard();
  9213. return buf_local;
  9214. }
  9215. // Win32 API clipboard implementation
  9216. static void SetClipboardTextFn_DefaultImpl(const char* text)
  9217. {
  9218. if (!OpenClipboard(NULL))
  9219. return;
  9220. const int wbuf_length = ImTextCountCharsFromUtf8(text, NULL) + 1;
  9221. HGLOBAL wbuf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)wbuf_length * sizeof(ImWchar));
  9222. if (wbuf_handle == NULL)
  9223. return;
  9224. ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle);
  9225. ImTextStrFromUtf8(wbuf_global, wbuf_length, text, NULL);
  9226. GlobalUnlock(wbuf_handle);
  9227. EmptyClipboard();
  9228. SetClipboardData(CF_UNICODETEXT, wbuf_handle);
  9229. CloseClipboard();
  9230. }
  9231. #else
  9232. // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
  9233. static const char* GetClipboardTextFn_DefaultImpl()
  9234. {
  9235. return GImGui->PrivateClipboard;
  9236. }
  9237. // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
  9238. static void SetClipboardTextFn_DefaultImpl(const char* text)
  9239. {
  9240. ImGuiState& g = *GImGui;
  9241. if (g.PrivateClipboard)
  9242. {
  9243. ImGui::MemFree(g.PrivateClipboard);
  9244. g.PrivateClipboard = NULL;
  9245. }
  9246. const char* text_end = text + strlen(text);
  9247. g.PrivateClipboard = (char*)ImGui::MemAlloc((size_t)(text_end - text) + 1);
  9248. memcpy(g.PrivateClipboard, text, (size_t)(text_end - text));
  9249. g.PrivateClipboard[(size_t)(text_end - text)] = 0;
  9250. }
  9251. #endif
  9252. #if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS)
  9253. #ifndef _WINDOWS_
  9254. #define WIN32_LEAN_AND_MEAN
  9255. #include <windows.h>
  9256. #endif
  9257. #include <Imm.h>
  9258. #pragma comment(lib, "imm32")
  9259. static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y)
  9260. {
  9261. // Notify OS Input Method Editor of text input position
  9262. if (HWND hwnd = (HWND)GImGui->IO.ImeWindowHandle)
  9263. if (HIMC himc = ImmGetContext(hwnd))
  9264. {
  9265. COMPOSITIONFORM cf;
  9266. cf.ptCurrentPos.x = x;
  9267. cf.ptCurrentPos.y = y;
  9268. cf.dwStyle = CFS_FORCE_POSITION;
  9269. ImmSetCompositionWindow(himc, &cf);
  9270. }
  9271. }
  9272. #else
  9273. static void ImeSetInputScreenPosFn_DefaultImpl(int, int)
  9274. {
  9275. }
  9276. #endif
  9277. #ifdef IMGUI_DISABLE_TEST_WINDOWS
  9278. void ImGui::ShowUserGuide() {}
  9279. void ImGui::ShowStyleEditor(ImGuiStyle*) {}
  9280. void ImGui::ShowTestWindow(bool*) {}
  9281. void ImGui::ShowMetricsWindow(bool*) {}
  9282. #else
  9283. //-----------------------------------------------------------------------------
  9284. // HELP
  9285. //-----------------------------------------------------------------------------
  9286. void ImGui::ShowUserGuide()
  9287. {
  9288. ImGui::BulletText("Double-click on title bar to collapse window.");
  9289. ImGui::BulletText("Click and drag on lower right corner to resize window.");
  9290. ImGui::BulletText("Click and drag on any empty space to move window.");
  9291. ImGui::BulletText("Mouse Wheel to scroll.");
  9292. if (ImGui::GetIO().FontAllowUserScaling)
  9293. ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents.");
  9294. ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields.");
  9295. ImGui::BulletText("CTRL+Click on a slider or drag box to input text.");
  9296. ImGui::BulletText(
  9297. "While editing text:\n"
  9298. "- Hold SHIFT or use mouse to select text\n"
  9299. "- CTRL+Left/Right to word jump\n"
  9300. "- CTRL+A or double-click to select all\n"
  9301. "- CTRL+X,CTRL+C,CTRL+V clipboard\n"
  9302. "- CTRL+Z,CTRL+Y undo/redo\n"
  9303. "- ESCAPE to revert\n"
  9304. "- You can apply arithmetic operators +,*,/ on numerical values.\n"
  9305. " Use +- to subtract.\n");
  9306. }
  9307. void ImGui::ShowStyleEditor(ImGuiStyle* ref)
  9308. {
  9309. ImGuiStyle& style = ImGui::GetStyle();
  9310. const ImGuiStyle def; // Default style
  9311. if (ImGui::Button("Revert Style"))
  9312. style = ref ? *ref : def;
  9313. if (ref)
  9314. {
  9315. ImGui::SameLine();
  9316. if (ImGui::Button("Save Style"))
  9317. *ref = style;
  9318. }
  9319. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.55f);
  9320. if (ImGui::TreeNode("Sizes"))
  9321. {
  9322. 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.
  9323. ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f");
  9324. ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f");
  9325. ImGui::SliderFloat("ChildWindowRounding", &style.ChildWindowRounding, 0.0f, 16.0f, "%.0f");
  9326. ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f");
  9327. ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 16.0f, "%.0f");
  9328. ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f");
  9329. ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f");
  9330. ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f");
  9331. ImGui::SliderFloat("IndentSpacing", &style.IndentSpacing, 0.0f, 30.0f, "%.0f");
  9332. ImGui::SliderFloat("ScrollbarWidth", &style.ScrollbarWidth, 1.0f, 20.0f, "%.0f");
  9333. ImGui::SliderFloat("ScrollbarRounding", &style.ScrollbarRounding, 0.0f, 16.0f, "%.0f");
  9334. ImGui::SliderFloat("GrabMinSize", &style.GrabMinSize, 1.0f, 20.0f, "%.0f");
  9335. ImGui::TreePop();
  9336. }
  9337. if (ImGui::TreeNode("Colors"))
  9338. {
  9339. static int output_dest = 0;
  9340. static bool output_only_modified = false;
  9341. if (ImGui::Button("Output Colors"))
  9342. {
  9343. if (output_dest == 0)
  9344. ImGui::LogToClipboard();
  9345. else
  9346. ImGui::LogToTTY();
  9347. ImGui::LogText("ImGuiStyle& style = ImGui::GetStyle();" IM_NEWLINE);
  9348. for (int i = 0; i < ImGuiCol_COUNT; i++)
  9349. {
  9350. const ImVec4& col = style.Colors[i];
  9351. const char* name = ImGui::GetStyleColName(i);
  9352. if (!output_only_modified || memcmp(&col, (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0)
  9353. ImGui::LogText("style.Colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff);" IM_NEWLINE, name, 22 - strlen(name), "", col.x, col.y, col.z, col.w);
  9354. }
  9355. ImGui::LogFinish();
  9356. }
  9357. ImGui::SameLine(); ImGui::PushItemWidth(120); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY"); ImGui::PopItemWidth();
  9358. ImGui::SameLine(); ImGui::Checkbox("Only Modified Fields", &output_only_modified);
  9359. static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB;
  9360. ImGui::RadioButton("RGB", &edit_mode, ImGuiColorEditMode_RGB);
  9361. ImGui::SameLine();
  9362. ImGui::RadioButton("HSV", &edit_mode, ImGuiColorEditMode_HSV);
  9363. ImGui::SameLine();
  9364. ImGui::RadioButton("HEX", &edit_mode, ImGuiColorEditMode_HEX);
  9365. //ImGui::Text("Tip: Click on colored square to change edit mode.");
  9366. static ImGuiTextFilter filter;
  9367. filter.Draw("Filter colors", 200);
  9368. ImGui::BeginChild("#colors", ImVec2(0, 300), true);
  9369. ImGui::ColorEditMode(edit_mode);
  9370. for (int i = 0; i < ImGuiCol_COUNT; i++)
  9371. {
  9372. const char* name = ImGui::GetStyleColName(i);
  9373. if (!filter.PassFilter(name))
  9374. continue;
  9375. ImGui::PushID(i);
  9376. ImGui::ColorEdit4(name, (float*)&style.Colors[i], true);
  9377. if (memcmp(&style.Colors[i], (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0)
  9378. {
  9379. ImGui::SameLine(); if (ImGui::Button("Revert")) style.Colors[i] = ref ? ref->Colors[i] : def.Colors[i];
  9380. if (ref) { ImGui::SameLine(); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i]; }
  9381. }
  9382. ImGui::PopID();
  9383. }
  9384. ImGui::EndChild();
  9385. ImGui::TreePop();
  9386. }
  9387. ImGui::PopItemWidth();
  9388. }
  9389. //-----------------------------------------------------------------------------
  9390. // SAMPLE CODE
  9391. //-----------------------------------------------------------------------------
  9392. static void ShowExampleAppConsole(bool* opened);
  9393. static void ShowExampleAppLayout(bool* opened);
  9394. static void ShowExampleAppLongText(bool* opened);
  9395. static void ShowExampleAppAutoResize(bool* opened);
  9396. static void ShowExampleAppFixedOverlay(bool* opened);
  9397. static void ShowExampleAppManipulatingWindowTitle(bool* opened);
  9398. static void ShowExampleAppCustomRendering(bool* opened);
  9399. static void ShowExampleAppMainMenuBar();
  9400. static void ShowExampleMenuFile();
  9401. static void ShowHelpMarker(const char* desc)
  9402. {
  9403. ImGui::TextDisabled("(?)");
  9404. if (ImGui::IsItemHovered())
  9405. ImGui::SetTooltip(desc);
  9406. }
  9407. // Demonstrate most ImGui features (big function!)
  9408. void ImGui::ShowTestWindow(bool* opened)
  9409. {
  9410. // Examples apps
  9411. static bool show_app_metrics = false;
  9412. static bool show_app_main_menu_bar = false;
  9413. static bool show_app_console = false;
  9414. static bool show_app_layout = false;
  9415. static bool show_app_long_text = false;
  9416. static bool show_app_auto_resize = false;
  9417. static bool show_app_fixed_overlay = false;
  9418. static bool show_app_custom_rendering = false;
  9419. static bool show_app_manipulating_window_title = false;
  9420. if (show_app_metrics) ImGui::ShowMetricsWindow(&show_app_metrics);
  9421. if (show_app_main_menu_bar) ShowExampleAppMainMenuBar();
  9422. if (show_app_console) ShowExampleAppConsole(&show_app_console);
  9423. if (show_app_layout) ShowExampleAppLayout(&show_app_layout);
  9424. if (show_app_long_text) ShowExampleAppLongText(&show_app_long_text);
  9425. if (show_app_auto_resize) ShowExampleAppAutoResize(&show_app_auto_resize);
  9426. if (show_app_fixed_overlay) ShowExampleAppFixedOverlay(&show_app_fixed_overlay);
  9427. if (show_app_manipulating_window_title) ShowExampleAppManipulatingWindowTitle(&show_app_manipulating_window_title);
  9428. if (show_app_custom_rendering) ShowExampleAppCustomRendering(&show_app_custom_rendering);
  9429. static bool no_titlebar = false;
  9430. static bool no_border = true;
  9431. static bool no_resize = false;
  9432. static bool no_move = false;
  9433. static bool no_scrollbar = false;
  9434. static bool no_collapse = false;
  9435. static bool no_menu = false;
  9436. static float bg_alpha = 0.65f;
  9437. // Demonstrate the various window flags. Typically you would just use the default.
  9438. ImGuiWindowFlags window_flags = 0;
  9439. if (no_titlebar) window_flags |= ImGuiWindowFlags_NoTitleBar;
  9440. if (!no_border) window_flags |= ImGuiWindowFlags_ShowBorders;
  9441. if (no_resize) window_flags |= ImGuiWindowFlags_NoResize;
  9442. if (no_move) window_flags |= ImGuiWindowFlags_NoMove;
  9443. if (no_scrollbar) window_flags |= ImGuiWindowFlags_NoScrollbar;
  9444. if (no_collapse) window_flags |= ImGuiWindowFlags_NoCollapse;
  9445. if (!no_menu) window_flags |= ImGuiWindowFlags_MenuBar;
  9446. if (!ImGui::Begin("ImGui Test", opened, ImVec2(550,680), bg_alpha, window_flags))
  9447. {
  9448. // Early out if the window is collapsed, as an optimization.
  9449. ImGui::End();
  9450. return;
  9451. }
  9452. //ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); // 2/3 of the space for widget and 1/3 for labels
  9453. ImGui::PushItemWidth(-140); // Right align, keep 140 pixels for labels
  9454. ImGui::Text("ImGui says hello.");
  9455. // Menu
  9456. if (ImGui::BeginMenuBar())
  9457. {
  9458. if (ImGui::BeginMenu("Menu"))
  9459. {
  9460. ShowExampleMenuFile();
  9461. ImGui::EndMenu();
  9462. }
  9463. if (ImGui::BeginMenu("Examples"))
  9464. {
  9465. ImGui::MenuItem("Metrics", NULL, &show_app_metrics);
  9466. ImGui::MenuItem("Main menu bar", NULL, &show_app_main_menu_bar);
  9467. ImGui::MenuItem("Console", NULL, &show_app_console);
  9468. ImGui::MenuItem("Simple layout", NULL, &show_app_layout);
  9469. ImGui::MenuItem("Long text display", NULL, &show_app_long_text);
  9470. ImGui::MenuItem("Auto-resizing window", NULL, &show_app_auto_resize);
  9471. ImGui::MenuItem("Simple overlay", NULL, &show_app_fixed_overlay);
  9472. ImGui::MenuItem("Manipulating window title", NULL, &show_app_manipulating_window_title);
  9473. ImGui::MenuItem("Custom rendering", NULL, &show_app_custom_rendering);
  9474. ImGui::EndMenu();
  9475. }
  9476. ImGui::EndMenuBar();
  9477. }
  9478. ImGui::Spacing();
  9479. if (ImGui::CollapsingHeader("Help"))
  9480. {
  9481. ImGui::TextWrapped("This window is being created by the ShowTestWindow() function. Please refer to the code for programming reference.\n\nUser Guide:");
  9482. ImGui::ShowUserGuide();
  9483. }
  9484. if (ImGui::CollapsingHeader("Window options"))
  9485. {
  9486. ImGui::Checkbox("no titlebar", &no_titlebar); ImGui::SameLine(150);
  9487. ImGui::Checkbox("no border", &no_border); ImGui::SameLine(300);
  9488. ImGui::Checkbox("no resize", &no_resize);
  9489. ImGui::Checkbox("no move", &no_move); ImGui::SameLine(150);
  9490. ImGui::Checkbox("no scrollbar", &no_scrollbar); ImGui::SameLine(300);
  9491. ImGui::Checkbox("no collapse", &no_collapse);
  9492. ImGui::Checkbox("no menu", &no_menu);
  9493. ImGui::SliderFloat("bg alpha", &bg_alpha, 0.0f, 1.0f);
  9494. if (ImGui::TreeNode("Style"))
  9495. {
  9496. ImGui::ShowStyleEditor();
  9497. ImGui::TreePop();
  9498. }
  9499. if (ImGui::TreeNode("Fonts", "Fonts (%d)", (int)ImGui::GetIO().Fonts->Fonts.size()))
  9500. {
  9501. ImGui::TextWrapped("Tip: Load fonts with GetIO().Fonts->AddFontFromFileTTF().");
  9502. for (size_t i = 0; i < ImGui::GetIO().Fonts->Fonts.size(); i++)
  9503. {
  9504. ImFont* font = ImGui::GetIO().Fonts->Fonts[i];
  9505. ImGui::BulletText("Font %d: %.2f pixels, %d glyphs", i, font->FontSize, font->Glyphs.size());
  9506. ImGui::TreePush((void*)i);
  9507. ImGui::PushFont(font);
  9508. ImGui::Text("The quick brown fox jumps over the lazy dog");
  9509. ImGui::PopFont();
  9510. if (i > 0 && ImGui::Button("Set as default"))
  9511. {
  9512. ImGui::GetIO().Fonts->Fonts[i] = ImGui::GetIO().Fonts->Fonts[0];
  9513. ImGui::GetIO().Fonts->Fonts[0] = font;
  9514. }
  9515. ImGui::SliderFloat("font scale", &font->Scale, 0.3f, 2.0f, "%.1f"); // scale only this font
  9516. ImGui::TreePop();
  9517. }
  9518. static float window_scale = 1.0f;
  9519. ImGui::SliderFloat("this window scale", &window_scale, 0.3f, 2.0f, "%.1f"); // scale only this window
  9520. ImGui::SliderFloat("global scale", &ImGui::GetIO().FontGlobalScale, 0.3f, 2.0f, "%.1f"); // scale everything
  9521. ImGui::SetWindowFontScale(window_scale);
  9522. ImGui::TreePop();
  9523. }
  9524. if (ImGui::TreeNode("Logging"))
  9525. {
  9526. ImGui::TextWrapped("The logging API redirects all text output of ImGui so you can easily capture the content of a window or a block. Tree nodes can be automatically expanded. You can also call ImGui::LogText() to output directly to the log without a visual output.");
  9527. ImGui::LogButtons();
  9528. ImGui::TreePop();
  9529. }
  9530. }
  9531. if (ImGui::CollapsingHeader("Widgets"))
  9532. {
  9533. static bool a=false;
  9534. if (ImGui::Button("Button")) { printf("Clicked\n"); a ^= 1; }
  9535. if (a)
  9536. {
  9537. ImGui::SameLine();
  9538. ImGui::Text("Thanks for clicking me!");
  9539. }
  9540. if (ImGui::TreeNode("Tree"))
  9541. {
  9542. for (size_t i = 0; i < 5; i++)
  9543. {
  9544. if (ImGui::TreeNode((void*)i, "Child %d", i))
  9545. {
  9546. ImGui::Text("blah blah");
  9547. ImGui::SameLine();
  9548. if (ImGui::SmallButton("print"))
  9549. printf("Child %d pressed", (int)i);
  9550. ImGui::TreePop();
  9551. }
  9552. }
  9553. ImGui::TreePop();
  9554. }
  9555. if (ImGui::TreeNode("Bullets"))
  9556. {
  9557. ImGui::BulletText("Bullet point 1");
  9558. ImGui::BulletText("Bullet point 2\nOn multiple lines");
  9559. ImGui::Bullet(); ImGui::Text("Bullet point 3 (two calls)");
  9560. ImGui::Bullet(); ImGui::SmallButton("Button");
  9561. ImGui::TreePop();
  9562. }
  9563. if (ImGui::TreeNode("Colored Text"))
  9564. {
  9565. // Using shortcut. You can use PushStyleColor()/PopStyleColor() for more flexibility.
  9566. ImGui::TextColored(ImVec4(1.0f,0.0f,1.0f,1.0f), "Pink");
  9567. ImGui::TextColored(ImVec4(1.0f,1.0f,0.0f,1.0f), "Yellow");
  9568. ImGui::TextDisabled("Disabled");
  9569. ImGui::TreePop();
  9570. }
  9571. if (ImGui::TreeNode("Word Wrapping"))
  9572. {
  9573. // Using shortcut. You can use PushTextWrapPos()/PopTextWrapPos() for more flexibility.
  9574. ImGui::TextWrapped("This text should automatically wrap on the edge of the window. The current implementation for text wrapping follows simple rules suitable for English and possibly other languages.");
  9575. ImGui::Spacing();
  9576. static float wrap_width = 200.0f;
  9577. ImGui::SliderFloat("Wrap width", &wrap_width, -20, 600, "%.0f");
  9578. ImGui::Text("Test paragraph 1:");
  9579. ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF);
  9580. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  9581. ImGui::Text("lazy dog. This paragraph is made to fit within %.0f pixels. The quick brown fox jumps over the lazy dog.", wrap_width);
  9582. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), 0xFF00FFFF);
  9583. ImGui::PopTextWrapPos();
  9584. ImGui::Text("Test paragraph 2:");
  9585. ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF);
  9586. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  9587. ImGui::Text("aaaaaaaa bbbbbbbb, cccccccc,dddddddd. eeeeeeee ffffffff. gggggggg!hhhhhhhh");
  9588. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), 0xFF00FFFF);
  9589. ImGui::PopTextWrapPos();
  9590. ImGui::TreePop();
  9591. }
  9592. if (ImGui::TreeNode("UTF-8 Text"))
  9593. {
  9594. // UTF-8 test with Japanese characters
  9595. // (needs a suitable font, try Arial Unicode or M+ fonts http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html)
  9596. // Most compiler appears to support UTF-8 in source code (with Visual Studio you need to save your file as 'UTF-8 without signature')
  9597. // 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.
  9598. // In your own application be reasonable and use UTF-8 in source or retrieve the data from file system!
  9599. // Note that characters values are preserved even if the font cannot be displayed, so you can safely copy & paste garbled characters into another application.
  9600. ImGui::TextWrapped("CJK text will only appears if the font was loaded with the appropriate CJK character ranges. Call io.Font->LoadFromFileTTF() manually to load extra character ranges.");
  9601. ImGui::Text("Hiragana: \xe3\x81\x8b\xe3\x81\x8d\xe3\x81\x8f\xe3\x81\x91\xe3\x81\x93 (kakikukeko)");
  9602. ImGui::Text("Kanjis: \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e (nihongo)");
  9603. static char buf[32] = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e";
  9604. ImGui::InputText("UTF-8 input", buf, IM_ARRAYSIZE(buf));
  9605. ImGui::TreePop();
  9606. }
  9607. if (ImGui::TreeNode("Clipping"))
  9608. {
  9609. static ImVec2 size(100, 100), offset(50, 20);
  9610. ImGui::TextWrapped("On a per-widget basis we are occasionally clipping text CPU-side if it won't fit in its frame. Otherwise we are doing coarser clipping + passing a scissor rectangle to the renderer. The system is designed to try minimizing both execution and CPU/GPU rendering cost.");
  9611. ImGui::DragFloat2("size", (float*)&size, 0.5f, 0.0f, 200.0f, "%.0f");
  9612. ImGui::DragFloat2("offset", (float*)&offset, 0.5f, -200, 200.0f, "%.0f");
  9613. ImVec2 pos = ImGui::GetCursorScreenPos();
  9614. ImVec4 clip_rect(pos.x, pos.y, pos.x+size.x, pos.y+size.y);
  9615. ImGui::GetWindowDrawList()->AddRectFilled(pos, pos+size, ImColor(90,90,120,255));
  9616. ImGui::GetWindowDrawList()->AddText(ImGui::GetWindowFont(), ImGui::GetWindowFontSize()*2.0f, pos+offset, ImColor(255,255,255,255), "Line 1 hello\nLine 2 clip me!", NULL, 0.0f, &clip_rect);
  9617. ImGui::Dummy(size);
  9618. ImGui::TreePop();
  9619. }
  9620. if (ImGui::TreeNode("Images"))
  9621. {
  9622. ImGui::TextWrapped("Below we are displaying the font texture (which is the only texture we have access to in this demo). Use the 'ImTextureID' type as storage to pass pointers or identifier to your own texture data. Hover the texture for a zoomed view!");
  9623. ImVec2 tex_screen_pos = ImGui::GetCursorScreenPos();
  9624. float tex_w = (float)ImGui::GetIO().Fonts->TexWidth;
  9625. float tex_h = (float)ImGui::GetIO().Fonts->TexHeight;
  9626. ImTextureID tex_id = ImGui::GetIO().Fonts->TexID;
  9627. ImGui::Image(tex_id, ImVec2(tex_w, tex_h), ImVec2(0,0), ImVec2(1,1), ImColor(255,255,255,255), ImColor(255,255,255,128));
  9628. if (ImGui::IsItemHovered())
  9629. {
  9630. ImGui::BeginTooltip();
  9631. float focus_sz = 32.0f;
  9632. float focus_x = ImClamp(ImGui::GetMousePos().x - tex_screen_pos.x - focus_sz * 0.5f, 0.0f, tex_w - focus_sz);
  9633. float focus_y = ImClamp(ImGui::GetMousePos().y - tex_screen_pos.y - focus_sz * 0.5f, 0.0f, tex_h - focus_sz);
  9634. ImGui::Text("Min: (%.2f, %.2f)", focus_x, focus_y);
  9635. ImGui::Text("Max: (%.2f, %.2f)", focus_x + focus_sz, focus_y + focus_sz);
  9636. ImVec2 uv0 = ImVec2((focus_x) / tex_w, (focus_y) / tex_h);
  9637. ImVec2 uv1 = ImVec2((focus_x + focus_sz) / tex_w, (focus_y + focus_sz) / tex_h);
  9638. ImGui::Image(tex_id, ImVec2(128,128), uv0, uv1, ImColor(255,255,255,255), ImColor(255,255,255,128));
  9639. ImGui::EndTooltip();
  9640. }
  9641. ImGui::TextWrapped("And now some textured buttons..");
  9642. static int pressed_count = 0;
  9643. for (int i = 0; i < 8; i++)
  9644. {
  9645. if (i > 0)
  9646. ImGui::SameLine();
  9647. ImGui::PushID(i);
  9648. int frame_padding = -1 + i; // -1 = uses default padding
  9649. if (ImGui::ImageButton(tex_id, ImVec2(32,32), ImVec2(0,0), ImVec2(32.0f/tex_w,32/tex_h), frame_padding, ImColor(0,0,0,255)))
  9650. pressed_count += 1;
  9651. ImGui::PopID();
  9652. }
  9653. ImGui::Text("Pressed %d times.", pressed_count);
  9654. ImGui::TreePop();
  9655. }
  9656. if (ImGui::TreeNode("Selectables"))
  9657. {
  9658. if (ImGui::TreeNode("Basic"))
  9659. {
  9660. static bool selected[3] = { false, true, false };
  9661. ImGui::Selectable("1. I am selectable", &selected[0]);
  9662. ImGui::Selectable("2. I am selectable", &selected[1]);
  9663. ImGui::Text("3. I am not selectable");
  9664. ImGui::Selectable("4. I am selectable", &selected[2]);
  9665. ImGui::TreePop();
  9666. }
  9667. if (ImGui::TreeNode("Rendering more text into the same block"))
  9668. {
  9669. static bool selected[3] = { false, false, false };
  9670. ImGui::Selectable("main.c", &selected[0]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes");
  9671. ImGui::Selectable("Hello.cpp", &selected[1]); ImGui::SameLine(300); ImGui::Text("12,345 bytes");
  9672. ImGui::Selectable("Hello.h", &selected[2]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes");
  9673. ImGui::TreePop();
  9674. }
  9675. if (ImGui::TreeNode("Grid"))
  9676. {
  9677. static bool selected[16] = { true, false, false, false, false, true, false, false, false, false, true, false, false, false, false, true };
  9678. for (int i = 0; i < 16; i++)
  9679. {
  9680. ImGui::PushID(i);
  9681. if (ImGui::Selectable("Me", &selected[i], 0, ImVec2(50,50)))
  9682. {
  9683. int x = i % 4, y = i / 4;
  9684. if (x > 0) selected[i - 1] ^= 1;
  9685. if (x < 3) selected[i + 1] ^= 1;
  9686. if (y > 0) selected[i - 4] ^= 1;
  9687. if (y < 3) selected[i + 4] ^= 1;
  9688. }
  9689. if ((i % 4) < 3) ImGui::SameLine();
  9690. ImGui::PopID();
  9691. }
  9692. ImGui::TreePop();
  9693. }
  9694. ImGui::TreePop();
  9695. }
  9696. if (ImGui::TreeNode("Filtered Text Input"))
  9697. {
  9698. static char buf1[64] = ""; ImGui::InputText("default", buf1, 64);
  9699. static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal);
  9700. static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
  9701. static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase);
  9702. static char buf5[64] = ""; ImGui::InputText("no blank", buf5, 64, ImGuiInputTextFlags_CharsNoBlank);
  9703. struct TextFilters { static int FilterImGuiLetters(ImGuiTextEditCallbackData* data) { if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar)) return 0; return 1; } };
  9704. static char buf6[64] = ""; ImGui::InputText("\"imgui\" letters", buf6, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters);
  9705. ImGui::TreePop();
  9706. }
  9707. if (ImGui::TreeNode("Multi-line Text Input"))
  9708. {
  9709. static char text[1024*16] = "// F00F bug\nlabel:\n\tlock cmpxchg8b eax\n";
  9710. ImGui::PushItemWidth(-1.0f);
  9711. ImGui::InputTextMultiline("##source", text, IM_ARRAYSIZE(text), ImVec2(0.f, ImGui::GetTextLineHeight() * 16), ImGuiInputTextFlags_AllowTabInput);
  9712. ImGui::PopItemWidth();
  9713. ImGui::TreePop();
  9714. }
  9715. if (ImGui::TreeNode("Dragging"))
  9716. {
  9717. ImGui::TextWrapped("You can use ImGui::GetItemActiveDragDelta() to query for the dragged amount on any widget.");
  9718. ImGui::Button("Drag Me");
  9719. if (ImGui::IsItemActive())
  9720. {
  9721. // Draw a line between the button and the mouse cursor
  9722. ImDrawList* draw_list = ImGui::GetWindowDrawList();
  9723. draw_list->PushClipRectFullScreen();
  9724. draw_list->AddLine(ImGui::CalcItemRectClosestPoint(ImGui::GetIO().MousePos, true, -2.0f), ImGui::GetIO().MousePos, ImColor(ImGui::GetStyle().Colors[ImGuiCol_Button]), 4.0f);
  9725. draw_list->PopClipRect();
  9726. ImVec2 value_raw = ImGui::GetMouseDragDelta(0, 0.0f);
  9727. ImVec2 value_with_lock_threshold = ImGui::GetMouseDragDelta(0);
  9728. ImGui::SameLine(); ImGui::Text("Raw (%.1f, %.1f), WithLockThresold (%.1f, %.1f)", value_raw.x, value_raw.y, value_with_lock_threshold.x, value_with_lock_threshold.y);
  9729. }
  9730. ImGui::TreePop();
  9731. }
  9732. static bool check = true;
  9733. ImGui::Checkbox("checkbox", &check);
  9734. static int e = 0;
  9735. ImGui::RadioButton("radio a", &e, 0); ImGui::SameLine();
  9736. ImGui::RadioButton("radio b", &e, 1); ImGui::SameLine();
  9737. ImGui::RadioButton("radio c", &e, 2);
  9738. // Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style.
  9739. for (int i = 0; i < 7; i++)
  9740. {
  9741. if (i > 0) ImGui::SameLine();
  9742. ImGui::PushID(i);
  9743. ImGui::PushStyleColor(ImGuiCol_Button, ImColor::HSV(i/7.0f, 0.6f, 0.6f));
  9744. ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImColor::HSV(i/7.0f, 0.7f, 0.7f));
  9745. ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImColor::HSV(i/7.0f, 0.8f, 0.8f));
  9746. ImGui::Button("Click");
  9747. ImGui::PopStyleColor(3);
  9748. ImGui::PopID();
  9749. }
  9750. ImGui::Text("Hover over me");
  9751. if (ImGui::IsItemHovered())
  9752. ImGui::SetTooltip("I am a tooltip");
  9753. ImGui::SameLine();
  9754. ImGui::Text("- or me");
  9755. if (ImGui::IsItemHovered())
  9756. {
  9757. ImGui::BeginTooltip();
  9758. ImGui::Text("I am a fancy tooltip");
  9759. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  9760. ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr));
  9761. ImGui::EndTooltip();
  9762. }
  9763. // Testing IMGUI_ONCE_UPON_A_FRAME macro
  9764. //for (int i = 0; i < 5; i++)
  9765. //{
  9766. // IMGUI_ONCE_UPON_A_FRAME
  9767. // {
  9768. // ImGui::Text("This will be displayed only once.");
  9769. // }
  9770. //}
  9771. ImGui::Separator();
  9772. ImGui::LabelText("label", "Value");
  9773. static int item = 1;
  9774. ImGui::Combo("combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0"); // Combo using values packed in a single constant string (for really quick combo)
  9775. const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK" };
  9776. static int item2 = -1;
  9777. ImGui::Combo("combo scroll", &item2, items, IM_ARRAYSIZE(items)); // Combo using proper array. You can also pass a callback to retrieve array value, no need to create/copy an array just for that.
  9778. {
  9779. static char str0[128] = "Hello, world!";
  9780. static int i0=123;
  9781. static float f0=0.001f;
  9782. ImGui::InputText("input text", str0, IM_ARRAYSIZE(str0));
  9783. ImGui::SameLine(); ShowHelpMarker("Hold SHIFT or use mouse to select text.\n" "CTRL+Left/Right to word jump.\n" "CTRL+A or double-click to select all.\n" "CTRL+X,CTRL+C,CTRL+V clipboard.\n" "CTRL+Z,CTRL+Y undo/redo.\n" "ESCAPE to revert.\n");
  9784. ImGui::InputInt("input int", &i0);
  9785. ImGui::SameLine(); ShowHelpMarker("You can apply arithmetic operators +,*,/ on numerical values.\n e.g. [ 100 ], input \'*2\', result becomes [ 200 ]\nUse +- to subtract.\n");
  9786. ImGui::InputFloat("input float", &f0, 0.01f, 1.0f);
  9787. static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
  9788. ImGui::InputFloat3("input float3", vec4a);
  9789. }
  9790. {
  9791. static int i1=50, i2=42;
  9792. ImGui::DragInt("drag int", &i1, 1);
  9793. ImGui::SameLine(); ShowHelpMarker("Click and drag to edit value.\nHold SHIFT/ALT for faster/slower edit.\nDouble-click or CTRL+click to input text.");
  9794. ImGui::DragInt("drag int 0..100", &i2, 1, 0, 100, "%.0f%%");
  9795. static float f1=1.00f, f2=0.0067f;
  9796. ImGui::DragFloat("drag float", &f1, 0.005f);
  9797. ImGui::DragFloat("drag small float", &f2, 0.0001f, 0.0f, 0.0f, "%.06f ns");
  9798. }
  9799. {
  9800. static int i1=0;
  9801. ImGui::SliderInt("slider int", &i1, -1, 3);
  9802. ImGui::SameLine(); ShowHelpMarker("CTRL+click to input value.");
  9803. static float f1=0.123f, f2=0.0f;
  9804. ImGui::SliderFloat("slider float", &f1, 0.0f, 1.0f, "ratio = %.3f");
  9805. ImGui::SliderFloat("slider log float", &f2, -10.0f, 10.0f, "%.4f", 3.0f);
  9806. static float angle = 0.0f;
  9807. ImGui::SliderAngle("slider angle", &angle);
  9808. }
  9809. static float col1[3] = { 1.0f,0.0f,0.2f };
  9810. static float col2[4] = { 0.4f,0.7f,0.0f,0.5f };
  9811. ImGui::ColorEdit3("color 1", col1);
  9812. ImGui::SameLine(); ShowHelpMarker("Click on the colored square to change edit mode.\nCTRL+click on individual component to input value.\n");
  9813. ImGui::ColorEdit4("color 2", col2);
  9814. const char* listbox_items[] = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon" };
  9815. static int listbox_item_current = 1;
  9816. ImGui::ListBox("listbox\n(single select)", &listbox_item_current, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
  9817. //static int listbox_item_current2 = 2;
  9818. //ImGui::PushItemWidth(-1);
  9819. //ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
  9820. //ImGui::PopItemWidth();
  9821. if (ImGui::TreeNode("Ranges"))
  9822. {
  9823. ImGui::Unindent();
  9824. static float begin = 10, end = 90;
  9825. static int begin_i = 100, end_i = 1000;
  9826. ImGui::DragFloatRange2("range", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%");
  9827. ImGui::DragIntRange2("range int (no bounds)", &begin_i, &end_i, 5, 0, 0, "Min: %.0f units", "Max: %.0f units");
  9828. ImGui::Indent();
  9829. ImGui::TreePop();
  9830. }
  9831. if (ImGui::TreeNode("Multi-component Widgets"))
  9832. {
  9833. ImGui::Unindent();
  9834. static float vec4f[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
  9835. static int vec4i[4] = { 1, 5, 100, 255 };
  9836. ImGui::InputFloat2("input float2", vec4f);
  9837. ImGui::DragFloat2("drag float2", vec4f, 0.01f, 0.0f, 1.0f);
  9838. ImGui::SliderFloat2("slider float2", vec4f, 0.0f, 1.0f);
  9839. ImGui::DragInt2("drag int2", vec4i, 1, 0, 255);
  9840. ImGui::InputInt2("input int2", vec4i);
  9841. ImGui::SliderInt2("slider int2", vec4i, 0, 255);
  9842. ImGui::Spacing();
  9843. ImGui::InputFloat3("input float3", vec4f);
  9844. ImGui::DragFloat3("drag float3", vec4f, 0.01f, 0.0f, 1.0f);
  9845. ImGui::SliderFloat3("slider float3", vec4f, 0.0f, 1.0f);
  9846. ImGui::DragInt3("drag int3", vec4i, 1, 0, 255);
  9847. ImGui::InputInt3("input int3", vec4i);
  9848. ImGui::SliderInt3("slider int3", vec4i, 0, 255);
  9849. ImGui::Spacing();
  9850. ImGui::InputFloat4("input float4", vec4f);
  9851. ImGui::DragFloat4("drag float4", vec4f, 0.01f, 0.0f, 1.0f);
  9852. ImGui::SliderFloat4("slider float4", vec4f, 0.0f, 1.0f);
  9853. ImGui::InputInt4("input int4", vec4i);
  9854. ImGui::DragInt4("drag int4", vec4i, 1, 0, 255);
  9855. ImGui::SliderInt4("slider int4", vec4i, 0, 255);
  9856. ImGui::Indent();
  9857. ImGui::TreePop();
  9858. }
  9859. if (ImGui::TreeNode("Vertical Sliders"))
  9860. {
  9861. ImGui::Unindent();
  9862. const float spacing = 4;
  9863. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(spacing, spacing));
  9864. static int int_value = 0;
  9865. ImGui::VSliderInt("##int", ImVec2(18,160), &int_value, 0, 5);
  9866. ImGui::SameLine();
  9867. static float values[7] = { 0.0f, 0.60f, 0.35f, 0.9f, 0.70f, 0.20f, 0.0f };
  9868. ImGui::PushID("set1");
  9869. for (int i = 0; i < 7; i++)
  9870. {
  9871. if (i > 0) ImGui::SameLine();
  9872. ImGui::PushID(i);
  9873. ImGui::PushStyleColor(ImGuiCol_FrameBg, ImColor::HSV(i/7.0f, 0.5f, 0.5f));
  9874. ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImColor::HSV(i/7.0f, 0.6f, 0.5f));
  9875. ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImColor::HSV(i/7.0f, 0.7f, 0.5f));
  9876. ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImColor::HSV(i/7.0f, 0.9f, 0.9f));
  9877. ImGui::VSliderFloat("##v", ImVec2(18,160), &values[i], 0.0f, 1.0f, "");
  9878. if (ImGui::IsItemActive() || ImGui::IsItemHovered())
  9879. ImGui::SetTooltip("%.3f", values[i]);
  9880. ImGui::PopStyleColor(4);
  9881. ImGui::PopID();
  9882. }
  9883. ImGui::PopID();
  9884. ImGui::SameLine();
  9885. ImGui::PushID("set2");
  9886. static float values2[4] = { 0.20f, 0.80f, 0.40f, 0.25f };
  9887. const int rows = 3;
  9888. const ImVec2 small_slider_size(18, (160.0f-(rows-1)*spacing)/rows);
  9889. for (int nx = 0; nx < 4; nx++)
  9890. {
  9891. if (nx > 0) ImGui::SameLine();
  9892. ImGui::BeginGroup();
  9893. for (int ny = 0; ny < rows; ny++)
  9894. {
  9895. ImGui::PushID(nx*rows+ny);
  9896. ImGui::VSliderFloat("##v", small_slider_size, &values2[nx], 0.0f, 1.0f, "");
  9897. if (ImGui::IsItemActive() || ImGui::IsItemHovered())
  9898. ImGui::SetTooltip("%.3f", values2[nx]);
  9899. ImGui::PopID();
  9900. }
  9901. ImGui::EndGroup();
  9902. }
  9903. ImGui::PopID();
  9904. ImGui::SameLine();
  9905. ImGui::PushID("set3");
  9906. for (int i = 0; i < 4; i++)
  9907. {
  9908. if (i > 0) ImGui::SameLine();
  9909. ImGui::PushID(i);
  9910. ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, 40);
  9911. ImGui::VSliderFloat("##v", ImVec2(40,160), &values[i], 0.0f, 1.0f, "%.2f");
  9912. ImGui::PopStyleVar();
  9913. ImGui::PopID();
  9914. }
  9915. ImGui::PopID();
  9916. ImGui::PopStyleVar();
  9917. ImGui::Indent();
  9918. ImGui::TreePop();
  9919. }
  9920. }
  9921. if (ImGui::CollapsingHeader("Graphs widgets"))
  9922. {
  9923. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  9924. ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr));
  9925. static bool pause;
  9926. static ImVector<float> values; if (values.empty()) { values.resize(90); memset(&values.front(), 0, values.size()*sizeof(float)); }
  9927. static size_t values_offset = 0;
  9928. if (!pause)
  9929. {
  9930. static float refresh_time = ImGui::GetTime(); // Create dummy data at fixed 60 hz rate for the demo
  9931. for (; ImGui::GetTime() > refresh_time + 1.0f/60.0f; refresh_time += 1.0f/60.0f)
  9932. {
  9933. static float phase = 0.0f;
  9934. values[values_offset] = cosf(phase);
  9935. values_offset = (values_offset+1)%values.size();
  9936. phase += 0.10f*values_offset;
  9937. }
  9938. }
  9939. ImGui::PlotLines("##Graph", &values.front(), (int)values.size(), (int)values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80));
  9940. ImGui::SameLine(0, (int)ImGui::GetStyle().ItemInnerSpacing.x);
  9941. ImGui::BeginGroup();
  9942. ImGui::Text("Graph");
  9943. ImGui::Checkbox("pause", &pause);
  9944. ImGui::EndGroup();
  9945. ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,80));
  9946. }
  9947. if (ImGui::CollapsingHeader("Layout"))
  9948. {
  9949. if (ImGui::TreeNode("Child regions"))
  9950. {
  9951. ImGui::Text("Without border");
  9952. static int line = 50;
  9953. bool goto_line = ImGui::Button("Goto");
  9954. ImGui::SameLine();
  9955. ImGui::PushItemWidth(100);
  9956. goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue);
  9957. ImGui::PopItemWidth();
  9958. ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowWidth() * 0.5f,300));
  9959. for (int i = 0; i < 100; i++)
  9960. {
  9961. ImGui::Text("%04d: scrollable region", i);
  9962. if (goto_line && line == i)
  9963. ImGui::SetScrollHere();
  9964. }
  9965. if (goto_line && line >= 100)
  9966. ImGui::SetScrollHere();
  9967. ImGui::EndChild();
  9968. ImGui::SameLine();
  9969. ImGui::PushStyleVar(ImGuiStyleVar_ChildWindowRounding, 5.0f);
  9970. ImGui::BeginChild("Sub2", ImVec2(0,300), true);
  9971. ImGui::Text("With border");
  9972. ImGui::Columns(2);
  9973. for (int i = 0; i < 100; i++)
  9974. {
  9975. if (i == 50)
  9976. ImGui::NextColumn();
  9977. char buf[32];
  9978. sprintf(buf, "%08x", i*5731);
  9979. ImGui::Button(buf);
  9980. }
  9981. ImGui::EndChild();
  9982. ImGui::PopStyleVar();
  9983. ImGui::TreePop();
  9984. }
  9985. if (ImGui::TreeNode("Widgets Alignment"))
  9986. {
  9987. static float f = 0.0f;
  9988. ImGui::Text("Fixed: 100 pixels");
  9989. ImGui::PushItemWidth(100);
  9990. ImGui::InputFloat("float##1", &f);
  9991. ImGui::PopItemWidth();
  9992. ImGui::Text("Proportional: 50%% of window width");
  9993. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
  9994. ImGui::InputFloat("float##2", &f);
  9995. ImGui::PopItemWidth();
  9996. ImGui::Text("Right-aligned: Leave 100 pixels for label");
  9997. ImGui::PushItemWidth(-100);
  9998. ImGui::InputFloat("float##3", &f);
  9999. ImGui::PopItemWidth();
  10000. ImGui::TreePop();
  10001. }
  10002. if (ImGui::TreeNode("Basic Horizontal Layout"))
  10003. {
  10004. ImGui::TextWrapped("(Use ImGui::SameLine() to keep adding items to the right of the preceeding item)");
  10005. // Text
  10006. ImGui::Text("Two items: Hello"); ImGui::SameLine();
  10007. ImGui::TextColored(ImVec4(1,1,0,1), "Sailor");
  10008. // Adjust spacing
  10009. ImGui::Text("More spacing: Hello"); ImGui::SameLine(0, 20);
  10010. ImGui::TextColored(ImVec4(1,1,0,1), "Sailor");
  10011. // Button
  10012. ImGui::AlignFirstTextHeightToWidgets();
  10013. ImGui::Text("Normal buttons"); ImGui::SameLine();
  10014. ImGui::Button("Banana"); ImGui::SameLine();
  10015. ImGui::Button("Apple"); ImGui::SameLine();
  10016. ImGui::Button("Corniflower");
  10017. // Button
  10018. ImGui::Text("Small buttons"); ImGui::SameLine();
  10019. ImGui::SmallButton("Like this one"); ImGui::SameLine();
  10020. ImGui::Text("can fit within a text block.");
  10021. // Aligned to arbitrary position. Easy/cheap column.
  10022. ImGui::Text("Aligned");
  10023. ImGui::SameLine(150); ImGui::Text("x=150");
  10024. ImGui::SameLine(300); ImGui::Text("x=300");
  10025. ImGui::Text("Aligned");
  10026. ImGui::SameLine(150); ImGui::SmallButton("x=150");
  10027. ImGui::SameLine(300); ImGui::SmallButton("x=300");
  10028. // Checkbox
  10029. static bool c1=false,c2=false,c3=false,c4=false;
  10030. ImGui::Checkbox("My", &c1); ImGui::SameLine();
  10031. ImGui::Checkbox("Tailor", &c2); ImGui::SameLine();
  10032. ImGui::Checkbox("Is", &c3); ImGui::SameLine();
  10033. ImGui::Checkbox("Rich", &c4);
  10034. // Various
  10035. static float f0=1.0f, f1=2.0f, f2=3.0f;
  10036. ImGui::PushItemWidth(80);
  10037. const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD" };
  10038. static int item = -1;
  10039. ImGui::Combo("Combo", &item, items, IM_ARRAYSIZE(items)); ImGui::SameLine();
  10040. ImGui::SliderFloat("X", &f0, 0.0f,5.0f); ImGui::SameLine();
  10041. ImGui::SliderFloat("Y", &f1, 0.0f,5.0f); ImGui::SameLine();
  10042. ImGui::SliderFloat("Z", &f2, 0.0f,5.0f);
  10043. ImGui::PopItemWidth();
  10044. ImGui::PushItemWidth(80);
  10045. ImGui::Text("Lists:");
  10046. static int selection[4] = { 0, 1, 2, 3 };
  10047. for (int i = 0; i < 4; i++)
  10048. {
  10049. if (i > 0) ImGui::SameLine();
  10050. ImGui::PushID(i);
  10051. ImGui::ListBox("", &selection[i], items, IM_ARRAYSIZE(items));
  10052. ImGui::PopID();
  10053. //if (ImGui::IsItemHovered()) ImGui::SetTooltip("ListBox %d hovered", i);
  10054. }
  10055. ImGui::PopItemWidth();
  10056. // Dummy
  10057. ImVec2 sz(30,30);
  10058. ImGui::Button("A", sz); ImGui::SameLine();
  10059. ImGui::Dummy(sz); ImGui::SameLine();
  10060. ImGui::Button("B", sz);
  10061. ImGui::TreePop();
  10062. }
  10063. if (ImGui::TreeNode("Groups"))
  10064. {
  10065. ImGui::TextWrapped("(Using ImGui::BeginGroup()/EndGroup() to layout items)");
  10066. ImGui::BeginGroup();
  10067. {
  10068. ImGui::BeginGroup();
  10069. ImGui::Button("AAA");
  10070. ImGui::SameLine();
  10071. ImGui::Button("BBB");
  10072. ImGui::SameLine();
  10073. ImGui::BeginGroup();
  10074. ImGui::Button("CCC");
  10075. ImGui::Button("DDD");
  10076. ImGui::EndGroup();
  10077. if (ImGui::IsItemHovered())
  10078. ImGui::SetTooltip("Group hovered");
  10079. ImGui::SameLine();
  10080. ImGui::Button("EEE");
  10081. ImGui::EndGroup();
  10082. }
  10083. // Capture the group size and create widgets using the same size
  10084. ImVec2 size = ImGui::GetItemRectSize();
  10085. const float values[5] = { 0.5f, 0.20f, 0.80f, 0.60f, 0.25f };
  10086. ImGui::PlotHistogram("##values", values, IM_ARRAYSIZE(values), 0, NULL, 0.0f, 1.0f, size);
  10087. ImGui::Button("ACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y));
  10088. ImGui::SameLine();
  10089. ImGui::Button("REACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y));
  10090. ImGui::EndGroup();
  10091. ImGui::SameLine();
  10092. ImGui::Button("LEVERAGE\nBUZZWORD", size);
  10093. ImGui::SameLine();
  10094. ImGui::ListBoxHeader("List", size);
  10095. ImGui::Selectable("Selected", true);
  10096. ImGui::Selectable("Not Selected", false);
  10097. ImGui::ListBoxFooter();
  10098. ImGui::TreePop();
  10099. }
  10100. if (ImGui::TreeNode("Text Baseline Alignment"))
  10101. {
  10102. ImGui::TextWrapped("(This is testing the vertical alignment that occurs on text to keep it at the same baseline as widgets. Lines only composed of text or \"small\" widgets fit in less vertical spaces than lines with normal widgets)");
  10103. ImGui::Text("One\nTwo\nThree"); ImGui::SameLine();
  10104. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  10105. ImGui::Text("Banana");
  10106. ImGui::Text("Banana"); ImGui::SameLine();
  10107. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  10108. ImGui::Text("One\nTwo\nThree");
  10109. ImGui::Button("HOP"); ImGui::SameLine();
  10110. ImGui::Text("Banana"); ImGui::SameLine();
  10111. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  10112. ImGui::Text("Banana");
  10113. ImGui::Button("HOP"); ImGui::SameLine();
  10114. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  10115. ImGui::Text("Banana");
  10116. ImGui::Button("TEST"); ImGui::SameLine();
  10117. ImGui::Text("TEST"); ImGui::SameLine();
  10118. ImGui::SmallButton("TEST");
  10119. ImGui::AlignFirstTextHeightToWidgets(); // If your line starts with text, call this to align it to upcoming widgets.
  10120. ImGui::Text("Text aligned to Widget"); ImGui::SameLine();
  10121. ImGui::Button("Widget"); ImGui::SameLine();
  10122. ImGui::Text("Widget"); ImGui::SameLine();
  10123. ImGui::SmallButton("Widget");
  10124. ImGui::TreePop();
  10125. }
  10126. if (ImGui::TreeNode("Scrolling"))
  10127. {
  10128. ImGui::TextWrapped("Use SetScrollHere() or SetScrollFromPosY() to scroll to a given position.");
  10129. static bool track = true;
  10130. static int track_line = 50, scroll_to_px = 200;
  10131. ImGui::Checkbox("Track", &track);
  10132. ImGui::SameLine(130); track |= ImGui::DragInt("##line", &track_line, 0.25f, 0, 9999, "Line %.0f");
  10133. bool scroll_to = ImGui::Button("Scroll To");
  10134. ImGui::SameLine(130); scroll_to |= ImGui::DragInt("##pos_y", &scroll_to_px, 1.00f, 0, 9999, "y = %.0f px");
  10135. if (scroll_to) track = false;
  10136. for (int i = 0; i < 5; i++)
  10137. {
  10138. if (i > 0) ImGui::SameLine();
  10139. ImGui::BeginGroup();
  10140. ImGui::Text("%s", i == 0 ? "Top" : i == 1 ? "25%" : i == 2 ? "Center" : i == 3 ? "75%" : "Bottom");
  10141. ImGui::BeginChild(ImGui::GetID((void *)(intptr_t)i), ImVec2(ImGui::GetWindowWidth() * 0.17f, 200.0f), true);
  10142. if (scroll_to)
  10143. ImGui::SetScrollFromPosY(ImGui::GetCursorStartPos().y + scroll_to_px, i * 0.25f);
  10144. for (int line = 0; line < 100; line++)
  10145. {
  10146. if (track && line == track_line)
  10147. {
  10148. ImGui::TextColored(ImColor(255,255,0), "Line %d", line);
  10149. ImGui::SetScrollHere(i * 0.25f); // 0.0f:top, 0.5f:center, 1.0f:bottom
  10150. }
  10151. else
  10152. {
  10153. ImGui::Text("Line %d", line);
  10154. }
  10155. }
  10156. ImGui::EndChild();
  10157. ImGui::EndGroup();
  10158. }
  10159. ImGui::TreePop();
  10160. }
  10161. }
  10162. if (ImGui::CollapsingHeader("Popups & Modal windows"))
  10163. {
  10164. if (ImGui::TreeNode("Popups"))
  10165. {
  10166. ImGui::TextWrapped("When a popup is active, it inhibits interacting with windows that are behind the popup. Clicking outside the popup closes it.");
  10167. static int selected_fish = -1;
  10168. const char* names[] = { "Bream", "Haddock", "Mackerel", "Pollock", "Tilefish" };
  10169. static bool toggles[] = { true, false, false, false, false };
  10170. if (ImGui::Button("Select.."))
  10171. ImGui::OpenPopup("select");
  10172. ImGui::SameLine();
  10173. ImGui::Text(selected_fish == -1 ? "<None>" : names[selected_fish]);
  10174. if (ImGui::BeginPopup("select"))
  10175. {
  10176. ImGui::Text("Aquarium");
  10177. ImGui::Separator();
  10178. for (int i = 0; i < IM_ARRAYSIZE(names); i++)
  10179. if (ImGui::Selectable(names[i]))
  10180. selected_fish = i;
  10181. ImGui::EndPopup();
  10182. }
  10183. if (ImGui::Button("Toggle.."))
  10184. ImGui::OpenPopup("toggle");
  10185. if (ImGui::BeginPopup("toggle"))
  10186. {
  10187. for (int i = 0; i < IM_ARRAYSIZE(names); i++)
  10188. ImGui::MenuItem(names[i], "", &toggles[i]);
  10189. if (ImGui::BeginMenu("Sub-menu"))
  10190. {
  10191. ImGui::MenuItem("Click me");
  10192. ImGui::EndMenu();
  10193. }
  10194. ImGui::Separator();
  10195. ImGui::Text("Tooltip here");
  10196. if (ImGui::IsItemHovered())
  10197. ImGui::SetTooltip("I am a tooltip over a popup");
  10198. if (ImGui::Button("Stacked Popup"))
  10199. ImGui::OpenPopup("another popup");
  10200. if (ImGui::BeginPopup("another popup"))
  10201. {
  10202. for (int i = 0; i < IM_ARRAYSIZE(names); i++)
  10203. ImGui::MenuItem(names[i], "", &toggles[i]);
  10204. if (ImGui::BeginMenu("Sub-menu"))
  10205. {
  10206. ImGui::MenuItem("Click me");
  10207. ImGui::EndMenu();
  10208. }
  10209. ImGui::EndPopup();
  10210. }
  10211. ImGui::EndPopup();
  10212. }
  10213. if (ImGui::Button("Popup Menu.."))
  10214. ImGui::OpenPopup("popup from button");
  10215. if (ImGui::BeginPopup("popup from button"))
  10216. {
  10217. ShowExampleMenuFile();
  10218. ImGui::EndPopup();
  10219. }
  10220. ImGui::TreePop();
  10221. }
  10222. if (ImGui::TreeNode("Context menus"))
  10223. {
  10224. static float value = 0.5f;
  10225. ImGui::Text("Value = %.3f (<-- right-click here)", value);
  10226. if (ImGui::BeginPopupContextItem("item context menu"))
  10227. {
  10228. if (ImGui::Selectable("Set to zero")) value = 0.0f;
  10229. if (ImGui::Selectable("Set to PI")) value = 3.1415f;
  10230. ImGui::EndPopup();
  10231. }
  10232. static ImVec4 color = ImColor(1.0f, 0.0f, 1.0f, 1.0f);
  10233. ImGui::ColorButton(color);
  10234. if (ImGui::BeginPopupContextItem("color context menu"))
  10235. {
  10236. ImGui::Text("Edit color");
  10237. ImGui::ColorEdit3("##edit", (float*)&color);
  10238. if (ImGui::Button("Close"))
  10239. ImGui::CloseCurrentPopup();
  10240. ImGui::EndPopup();
  10241. }
  10242. ImGui::SameLine(); ImGui::Text("(<-- right-click here)");
  10243. ImGui::TreePop();
  10244. }
  10245. if (ImGui::TreeNode("Modals"))
  10246. {
  10247. ImGui::TextWrapped("Modal windows are like popups but the user cannot close them by clicking outside the window.");
  10248. if (ImGui::Button("Delete.."))
  10249. ImGui::OpenPopup("Delete?");
  10250. if (ImGui::BeginPopupModal("Delete?", NULL, ImGuiWindowFlags_AlwaysAutoResize))
  10251. {
  10252. ImGui::Text("All those beautiful files will be deleted.\nThis operation cannot be undone!\n\n");
  10253. ImGui::Separator();
  10254. static bool dont_ask_me_next_time = false;
  10255. ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
  10256. ImGui::Checkbox("Don't ask me next time", &dont_ask_me_next_time);
  10257. ImGui::PopStyleVar();
  10258. if (ImGui::Button("OK", ImVec2(120,0))) { ImGui::CloseCurrentPopup(); }
  10259. ImGui::SameLine();
  10260. if (ImGui::Button("Cancel", ImVec2(120,0))) { ImGui::CloseCurrentPopup(); }
  10261. ImGui::EndPopup();
  10262. }
  10263. if (ImGui::Button("Stacked modals.."))
  10264. ImGui::OpenPopup("Stacked 1");
  10265. if (ImGui::BeginPopupModal("Stacked 1"))
  10266. {
  10267. ImGui::Text("Hello from Stacked The First");
  10268. if (ImGui::Button("Another one.."))
  10269. ImGui::OpenPopup("Stacked 2");
  10270. if (ImGui::BeginPopupModal("Stacked 2"))
  10271. {
  10272. ImGui::Text("Hello from Stacked The Second");
  10273. if (ImGui::Button("Close"))
  10274. ImGui::CloseCurrentPopup();
  10275. ImGui::EndPopup();
  10276. }
  10277. if (ImGui::Button("Close"))
  10278. ImGui::CloseCurrentPopup();
  10279. ImGui::EndPopup();
  10280. }
  10281. ImGui::TreePop();
  10282. }
  10283. }
  10284. if (ImGui::CollapsingHeader("Columns"))
  10285. {
  10286. // Basic columns
  10287. ImGui::Text("Basic:");
  10288. ImGui::Columns(4, "mycolumns");
  10289. ImGui::Separator();
  10290. ImGui::Text("ID"); ImGui::NextColumn();
  10291. ImGui::Text("Name"); ImGui::NextColumn();
  10292. ImGui::Text("Path"); ImGui::NextColumn();
  10293. ImGui::Text("Flags"); ImGui::NextColumn();
  10294. ImGui::Separator();
  10295. const char* names[3] = { "One", "Two", "Three" };
  10296. const char* paths[3] = { "/path/one", "/path/two", "/path/three" };
  10297. static int selected = -1;
  10298. for (int i = 0; i < 3; i++)
  10299. {
  10300. char label[32];
  10301. sprintf(label, "%04d", i);
  10302. if (ImGui::Selectable(label, selected == i, ImGuiSelectableFlags_SpanAllColumns))
  10303. selected = i;
  10304. ImGui::NextColumn();
  10305. ImGui::Text(names[i]); ImGui::NextColumn();
  10306. ImGui::Text(paths[i]); ImGui::NextColumn();
  10307. ImGui::Text("...."); ImGui::NextColumn();
  10308. }
  10309. ImGui::Columns(1);
  10310. ImGui::Separator();
  10311. ImGui::Spacing();
  10312. // Scrolling columns
  10313. /*
  10314. ImGui::Text("Scrolling:");
  10315. ImGui::BeginChild("##header", ImVec2(0, ImGui::GetTextLineHeightWithSpacing()+ImGui::GetStyle().ItemSpacing.y));
  10316. ImGui::Columns(3);
  10317. ImGui::Text("ID"); ImGui::NextColumn();
  10318. ImGui::Text("Name"); ImGui::NextColumn();
  10319. ImGui::Text("Path"); ImGui::NextColumn();
  10320. ImGui::Columns(1);
  10321. ImGui::Separator();
  10322. ImGui::EndChild();
  10323. ImGui::BeginChild("##scrollingregion", ImVec2(0, 60));
  10324. ImGui::Columns(3);
  10325. for (int i = 0; i < 10; i++)
  10326. {
  10327. ImGui::Text("%04d", i); ImGui::NextColumn();
  10328. ImGui::Text("Foobar"); ImGui::NextColumn();
  10329. ImGui::Text("/path/foobar/%04d/", i); ImGui::NextColumn();
  10330. }
  10331. ImGui::Columns(1);
  10332. ImGui::EndChild();
  10333. ImGui::Separator();
  10334. ImGui::Spacing();
  10335. */
  10336. // Create multiple items in a same cell before switching to next column
  10337. ImGui::Text("Mixed items:");
  10338. ImGui::Columns(3, "mixed");
  10339. ImGui::Separator();
  10340. static int e = 0;
  10341. ImGui::Text("Hello");
  10342. ImGui::Button("Banana");
  10343. ImGui::RadioButton("radio a", &e, 0);
  10344. ImGui::NextColumn();
  10345. ImGui::Text("ImGui");
  10346. ImGui::Button("Apple");
  10347. ImGui::RadioButton("radio b", &e, 1);
  10348. static float foo = 1.0f;
  10349. ImGui::InputFloat("red", &foo, 0.05f, 0, 3);
  10350. ImGui::Text("An extra line here.");
  10351. ImGui::NextColumn();
  10352. ImGui::Text("Sailor");
  10353. ImGui::Button("Corniflower");
  10354. ImGui::RadioButton("radio c", &e, 2);
  10355. static float bar = 1.0f;
  10356. ImGui::InputFloat("blue", &bar, 0.05f, 0, 3);
  10357. ImGui::NextColumn();
  10358. if (ImGui::CollapsingHeader("Category A")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  10359. if (ImGui::CollapsingHeader("Category B")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  10360. if (ImGui::CollapsingHeader("Category C")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  10361. ImGui::Columns(1);
  10362. ImGui::Separator();
  10363. ImGui::Spacing();
  10364. // Tree items
  10365. ImGui::Text("Tree items:");
  10366. ImGui::Columns(2, "tree items");
  10367. ImGui::Separator();
  10368. if (ImGui::TreeNode("Hello")) { ImGui::BulletText("Sailor"); ImGui::TreePop(); } ImGui::NextColumn();
  10369. if (ImGui::TreeNode("Bonjour")) { ImGui::BulletText("Marin"); ImGui::TreePop(); } ImGui::NextColumn();
  10370. ImGui::Columns(1);
  10371. ImGui::Separator();
  10372. ImGui::Spacing();
  10373. // Word-wrapping
  10374. ImGui::Text("Word-wrapping:");
  10375. ImGui::Columns(2, "word-wrapping");
  10376. ImGui::Separator();
  10377. ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
  10378. ImGui::Text("Hello Left");
  10379. ImGui::NextColumn();
  10380. ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
  10381. ImGui::Text("Hello Right");
  10382. ImGui::Columns(1);
  10383. ImGui::Separator();
  10384. ImGui::Spacing();
  10385. if (ImGui::TreeNode("Inside a tree.."))
  10386. {
  10387. if (ImGui::TreeNode("node 1 (with borders)"))
  10388. {
  10389. ImGui::Columns(4);
  10390. for (int i = 0; i < 8; i++)
  10391. {
  10392. ImGui::Text("%c%c%c", 'a'+i, 'a'+i, 'a'+i);
  10393. ImGui::NextColumn();
  10394. }
  10395. ImGui::Columns(1);
  10396. ImGui::TreePop();
  10397. }
  10398. if (ImGui::TreeNode("node 2 (without borders)"))
  10399. {
  10400. ImGui::Columns(4, NULL, false);
  10401. for (int i = 0; i < 8; i++)
  10402. {
  10403. ImGui::Text("%c%c%c", 'a'+i, 'a'+i, 'a'+i);
  10404. ImGui::NextColumn();
  10405. }
  10406. ImGui::Columns(1);
  10407. ImGui::TreePop();
  10408. }
  10409. ImGui::TreePop();
  10410. }
  10411. }
  10412. if (ImGui::CollapsingHeader("Filtering"))
  10413. {
  10414. static ImGuiTextFilter filter;
  10415. ImGui::Text("Filter usage:\n"
  10416. " \"\" display all lines\n"
  10417. " \"xxx\" display lines containing \"xxx\"\n"
  10418. " \"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n"
  10419. " \"-xxx\" hide lines containing \"xxx\"");
  10420. filter.Draw();
  10421. const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" };
  10422. for (size_t i = 0; i < IM_ARRAYSIZE(lines); i++)
  10423. if (filter.PassFilter(lines[i]))
  10424. ImGui::BulletText("%s", lines[i]);
  10425. }
  10426. if (ImGui::CollapsingHeader("Keyboard, Mouse & Focus"))
  10427. {
  10428. if (ImGui::TreeNode("Tabbing"))
  10429. {
  10430. ImGui::Text("Use TAB/SHIFT+TAB to cycle through keyboard editable fields.");
  10431. static char buf[32] = "dummy";
  10432. ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
  10433. ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
  10434. ImGui::InputText("3", buf, IM_ARRAYSIZE(buf));
  10435. ImGui::PushAllowKeyboardFocus(false);
  10436. ImGui::InputText("4 (tab skip)", buf, IM_ARRAYSIZE(buf));
  10437. //ImGui::SameLine(); ShowHelperMarker("Use ImGui::PushAllowKeyboardFocus(bool)\nto disable tabbing through certain widgets.");
  10438. ImGui::PopAllowKeyboardFocus();
  10439. ImGui::InputText("5", buf, IM_ARRAYSIZE(buf));
  10440. ImGui::TreePop();
  10441. }
  10442. if (ImGui::TreeNode("Focus from code"))
  10443. {
  10444. bool focus_1 = ImGui::Button("Focus on 1"); ImGui::SameLine();
  10445. bool focus_2 = ImGui::Button("Focus on 2"); ImGui::SameLine();
  10446. bool focus_3 = ImGui::Button("Focus on 3");
  10447. int has_focus = 0;
  10448. static char buf[128] = "click on a button to set focus";
  10449. if (focus_1) ImGui::SetKeyboardFocusHere();
  10450. ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
  10451. if (ImGui::IsItemActive()) has_focus = 1;
  10452. if (focus_2) ImGui::SetKeyboardFocusHere();
  10453. ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
  10454. if (ImGui::IsItemActive()) has_focus = 2;
  10455. ImGui::PushAllowKeyboardFocus(false);
  10456. if (focus_3) ImGui::SetKeyboardFocusHere();
  10457. ImGui::InputText("3 (tab skip)", buf, IM_ARRAYSIZE(buf));
  10458. if (ImGui::IsItemActive()) has_focus = 3;
  10459. ImGui::PopAllowKeyboardFocus();
  10460. if (has_focus)
  10461. ImGui::Text("Item with focus: %d", has_focus);
  10462. else
  10463. ImGui::Text("Item with focus: <none>");
  10464. ImGui::TextWrapped("Cursor & selection are preserved when refocusing last used item in code.");
  10465. ImGui::TreePop();
  10466. }
  10467. if (ImGui::TreeNode("Keyboard & Mouse State"))
  10468. {
  10469. ImGuiIO& io = ImGui::GetIO();
  10470. ImGui::Text("MousePos: (%g, %g)", io.MousePos.x, io.MousePos.y);
  10471. ImGui::Text("Mouse down:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (io.MouseDownDuration[i] >= 0.0f) { ImGui::SameLine(); ImGui::Text("%d (%.02f secs)", i, io.MouseDownDuration[i]); }
  10472. ImGui::Text("Mouse clicked:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseClicked(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
  10473. ImGui::Text("Mouse released:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseReleased(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
  10474. ImGui::Text("MouseWheel: %.1f", io.MouseWheel);
  10475. ImGui::Text("Keys down:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (io.KeysDownDuration[i] >= 0.0f) { ImGui::SameLine(); ImGui::Text("%d (%.02f secs)", i, io.KeysDownDuration[i]); }
  10476. ImGui::Text("Keys pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyPressed(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
  10477. ImGui::Text("Keys release:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyReleased(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
  10478. ImGui::Text("KeyMods: %s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "");
  10479. ImGui::Text("WantCaptureMouse: %s", io.WantCaptureMouse ? "true" : "false");
  10480. ImGui::Text("WantCaptureKeyboard: %s", io.WantCaptureKeyboard ? "true" : "false");
  10481. ImGui::Button("Hover me\nto enforce\ninputs capture");
  10482. if (ImGui::IsItemHovered())
  10483. ImGui::CaptureKeyboardFromApp();
  10484. ImGui::TreePop();
  10485. }
  10486. if (ImGui::TreeNode("Mouse cursors"))
  10487. {
  10488. ImGui::TextWrapped("Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. You can also set io.MouseDrawCursor to ask ImGui to render the cursor for you in software.");
  10489. ImGui::Checkbox("io.MouseDrawCursor", &ImGui::GetIO().MouseDrawCursor);
  10490. ImGui::Text("Hover to see mouse cursors:");
  10491. for (int i = 0; i < ImGuiMouseCursor_Count_; i++)
  10492. {
  10493. char label[32];
  10494. sprintf(label, "Mouse cursor %d", i);
  10495. ImGui::Bullet(); ImGui::Selectable(label, false);
  10496. if (ImGui::IsItemHovered())
  10497. ImGui::SetMouseCursor(i);
  10498. }
  10499. ImGui::TreePop();
  10500. }
  10501. }
  10502. ImGui::End();
  10503. }
  10504. void ImGui::ShowMetricsWindow(bool* opened)
  10505. {
  10506. if (ImGui::Begin("ImGui Metrics", opened))
  10507. {
  10508. ImGui::Text("ImGui %s", ImGui::GetVersion());
  10509. ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  10510. ImGui::Text("%d vertices", ImGui::GetIO().MetricsRenderVertices);
  10511. ImGui::Text("%d allocations", ImGui::GetIO().MetricsAllocs);
  10512. ImGui::Separator();
  10513. struct Funcs
  10514. {
  10515. static void NodeDrawList(ImDrawList* draw_list, const char* label)
  10516. {
  10517. bool node_opened = ImGui::TreeNode(draw_list, "%s: %d vtx, %d cmds", label, draw_list->vtx_buffer.size(), draw_list->commands.size());
  10518. if (draw_list == ImGui::GetWindowDrawList())
  10519. {
  10520. ImGui::SameLine();
  10521. ImGui::TextColored(ImColor(255,100,100), "CURRENTLY APPENDING"); // Can't display stats for active draw list! (we don't have the data double-buffered)
  10522. }
  10523. if (!node_opened)
  10524. return;
  10525. for (const ImDrawCmd* pcmd = draw_list->commands.begin(); pcmd < draw_list->commands.end(); pcmd++)
  10526. if (pcmd->user_callback)
  10527. ImGui::BulletText("Callback %p, user_data %p", pcmd->user_callback, pcmd->user_callback_data);
  10528. else
  10529. ImGui::BulletText("Draw %d vtx, tex = %p", pcmd->vtx_count, pcmd->texture_id);
  10530. ImGui::TreePop();
  10531. }
  10532. static void NodeWindows(ImVector<ImGuiWindow*>& windows, const char* label)
  10533. {
  10534. if (!ImGui::TreeNode(label, "%s (%d)", label, (int)windows.size()))
  10535. return;
  10536. for (int i = 0; i < (int)windows.size(); i++)
  10537. Funcs::NodeWindow(windows[i], "Window");
  10538. ImGui::TreePop();
  10539. }
  10540. static void NodeWindow(ImGuiWindow* window, const char* label)
  10541. {
  10542. if (!ImGui::TreeNode(window, "%s '%s', %d @ 0x%p", label, window->Name, window->Active || window->WasActive, window))
  10543. return;
  10544. NodeDrawList(window->DrawList, "DrawList");
  10545. if (window->RootWindow != window) NodeWindow(window->RootWindow, "RootWindow");
  10546. if (window->DC.ChildWindows.size() > 0) NodeWindows(window->DC.ChildWindows, "ChildWindows");
  10547. ImGui::BulletText("Storage: %d bytes", (int)window->StateStorage.Data.size() * sizeof(ImGuiStorage::Pair));
  10548. ImGui::TreePop();
  10549. }
  10550. };
  10551. ImGuiState& g = *GImGui; // Access private state
  10552. g.DisableHideTextAfterDoubleHash++; // Not exposed (yet). Disable processing that hides text after '##' markers.
  10553. Funcs::NodeWindows(g.Windows, "Windows");
  10554. if (ImGui::TreeNode("DrawList", "Active DrawLists (%d)", (int)g.RenderDrawLists[0].size()))
  10555. {
  10556. for (int i = 0; i < (int)g.RenderDrawLists[0].size(); i++)
  10557. Funcs::NodeDrawList(g.RenderDrawLists[0][i], "DrawList");
  10558. ImGui::TreePop();
  10559. }
  10560. if (ImGui::TreeNode("Popups", "Opened Popups (%d)", (int)g.OpenedPopupStack.size()))
  10561. {
  10562. for (int i = 0; i < (int)g.OpenedPopupStack.size(); i++)
  10563. ImGui::BulletText("PopupID: %08x, Window: '%s'", g.OpenedPopupStack[i].PopupID, g.OpenedPopupStack[i].Window ? g.OpenedPopupStack[i].Window->Name : "NULL");
  10564. ImGui::TreePop();
  10565. }
  10566. g.DisableHideTextAfterDoubleHash--;
  10567. }
  10568. ImGui::End();
  10569. }
  10570. static void ShowExampleAppMainMenuBar()
  10571. {
  10572. if (ImGui::BeginMainMenuBar())
  10573. {
  10574. if (ImGui::BeginMenu("File"))
  10575. {
  10576. ShowExampleMenuFile();
  10577. ImGui::EndMenu();
  10578. }
  10579. if (ImGui::BeginMenu("Edit"))
  10580. {
  10581. if (ImGui::MenuItem("Undo", "CTRL+Z")) {}
  10582. if (ImGui::MenuItem("Redo", "CTRL+Y", false, false)) {} // Disabled item
  10583. ImGui::Separator();
  10584. if (ImGui::MenuItem("Cut", "CTRL+X")) {}
  10585. if (ImGui::MenuItem("Copy", "CTRL+C")) {}
  10586. if (ImGui::MenuItem("Paste", "CTRL+V")) {}
  10587. ImGui::EndMenu();
  10588. }
  10589. ImGui::EndMainMenuBar();
  10590. }
  10591. }
  10592. static void ShowExampleMenuFile()
  10593. {
  10594. ImGui::MenuItem("(dummy menu)", NULL, false, false);
  10595. if (ImGui::MenuItem("New")) {}
  10596. if (ImGui::MenuItem("Open", "Ctrl+O")) {}
  10597. if (ImGui::BeginMenu("Open Recent"))
  10598. {
  10599. ImGui::MenuItem("fish_hat.c");
  10600. ImGui::MenuItem("fish_hat.inl");
  10601. ImGui::MenuItem("fish_hat.h");
  10602. if (ImGui::BeginMenu("More.."))
  10603. {
  10604. ImGui::MenuItem("Hello");
  10605. ImGui::MenuItem("Sailor");
  10606. if (ImGui::BeginMenu("Recurse.."))
  10607. {
  10608. ShowExampleMenuFile();
  10609. ImGui::EndMenu();
  10610. }
  10611. ImGui::EndMenu();
  10612. }
  10613. ImGui::EndMenu();
  10614. }
  10615. if (ImGui::MenuItem("Save", "Ctrl+S")) {}
  10616. if (ImGui::MenuItem("Save As..")) {}
  10617. ImGui::Separator();
  10618. if (ImGui::BeginMenu("Options"))
  10619. {
  10620. static bool enabled = true;
  10621. ImGui::MenuItem("Enabled", "", &enabled);
  10622. ImGui::BeginChild("child", ImVec2(0, 60), true);
  10623. for (int i = 0; i < 10; i++)
  10624. ImGui::Text("Scrolling Text %d", i);
  10625. ImGui::EndChild();
  10626. static float f = 0.5f;
  10627. ImGui::SliderFloat("Value", &f, 0.0f, 1.0f);
  10628. ImGui::InputFloat("Input", &f, 0.1f);
  10629. ImGui::EndMenu();
  10630. }
  10631. if (ImGui::BeginMenu("Colors"))
  10632. {
  10633. for (int i = 0; i < ImGuiCol_COUNT; i++)
  10634. ImGui::MenuItem(ImGui::GetStyleColName((ImGuiCol)i));
  10635. ImGui::EndMenu();
  10636. }
  10637. if (ImGui::BeginMenu("Disabled", false)) // Disabled
  10638. {
  10639. IM_ASSERT(0);
  10640. }
  10641. if (ImGui::MenuItem("Checked", NULL, true)) {}
  10642. if (ImGui::MenuItem("Quit", "Alt+F4")) {}
  10643. }
  10644. static void ShowExampleAppAutoResize(bool* opened)
  10645. {
  10646. if (!ImGui::Begin("Example: Auto-resizing window", opened, ImGuiWindowFlags_AlwaysAutoResize))
  10647. {
  10648. ImGui::End();
  10649. return;
  10650. }
  10651. static int lines = 10;
  10652. ImGui::Text("Window will resize every-frame to the size of its content.\nNote that you probably don't want to query the window size to\noutput your content because that would create a feedback loop.");
  10653. ImGui::SliderInt("Number of lines", &lines, 1, 20);
  10654. for (int i = 0; i < lines; i++)
  10655. ImGui::Text("%*sThis is line %d", i*4, "", i); // Pad with space to extend size horizontally
  10656. ImGui::End();
  10657. }
  10658. static void ShowExampleAppFixedOverlay(bool* opened)
  10659. {
  10660. ImGui::SetNextWindowPos(ImVec2(10,10));
  10661. if (!ImGui::Begin("Example: Fixed Overlay", opened, ImVec2(0,0), 0.3f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoSavedSettings))
  10662. {
  10663. ImGui::End();
  10664. return;
  10665. }
  10666. ImGui::Text("Simple overlay\non the top-left side of the screen.");
  10667. ImGui::Separator();
  10668. ImGui::Text("Mouse Position: (%.1f,%.1f)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
  10669. ImGui::End();
  10670. }
  10671. static void ShowExampleAppManipulatingWindowTitle(bool* opened)
  10672. {
  10673. (void)opened;
  10674. // By default, Windows are uniquely identified by their title.
  10675. // You can use the "##" and "###" markers to manipulate the display/ID. Read FAQ at the top of this file!
  10676. // Using "##" to display same title but have unique identifier.
  10677. ImGui::SetNextWindowPos(ImVec2(100,100), ImGuiSetCond_FirstUseEver);
  10678. ImGui::Begin("Same title as another window##1");
  10679. ImGui::Text("This is window 1.\nMy title is the same as window 2, but my identifier is unique.");
  10680. ImGui::End();
  10681. ImGui::SetNextWindowPos(ImVec2(100,200), ImGuiSetCond_FirstUseEver);
  10682. ImGui::Begin("Same title as another window##2");
  10683. ImGui::Text("This is window 2.\nMy title is the same as window 1, but my identifier is unique.");
  10684. ImGui::End();
  10685. // Using "###" to display a changing title but keep a static identifier "AnimatedTitle"
  10686. char buf[128];
  10687. ImFormatString(buf, IM_ARRAYSIZE(buf), "Animated title %c %d###AnimatedTitle", "|/-\\"[(int)(ImGui::GetTime()/0.25f)&3], rand());
  10688. ImGui::SetNextWindowPos(ImVec2(100,300), ImGuiSetCond_FirstUseEver);
  10689. ImGui::Begin(buf);
  10690. ImGui::Text("This window has a changing title.");
  10691. ImGui::End();
  10692. }
  10693. static void ShowExampleAppCustomRendering(bool* opened)
  10694. {
  10695. ImGui::SetNextWindowSize(ImVec2(300,350), ImGuiSetCond_FirstUseEver);
  10696. if (!ImGui::Begin("Example: Custom rendering", opened))
  10697. {
  10698. ImGui::End();
  10699. return;
  10700. }
  10701. // Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of overloaded operators, etc.
  10702. // Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your types and ImVec2/ImVec4.
  10703. // ImGui defines overloaded operators but they are internal to imgui.cpp and not exposed outside (to avoid messing with your types)
  10704. // In this example we aren't using the operators.
  10705. static ImVector<ImVec2> points;
  10706. static bool adding_line = false;
  10707. if (ImGui::Button("Clear")) points.clear();
  10708. if (points.size() >= 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) { points.pop_back(); points.pop_back(); } }
  10709. ImGui::Text("Left-click and drag to add lines");
  10710. ImGui::Text("Right-click to undo");
  10711. ImDrawList* draw_list = ImGui::GetWindowDrawList();
  10712. // Here we are using InvisibleButton() as a convenience to 1) advance the cursor and 2) allows us to use IsItemHovered()
  10713. // However you can draw directly and poll mouse/keyboard by yourself. You can manipulate the cursor using GetCursorPos() and SetCursorPos().
  10714. // If you only use the ImDrawList API, you can notify the owner window of its extends by using SetCursorPos(max).
  10715. ImVec2 canvas_pos = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
  10716. ImVec2 canvas_size = ImVec2(ImMax(50.0f,ImGui::GetWindowContentRegionMax().x-ImGui::GetCursorPos().x), ImMax(50.0f,ImGui::GetWindowContentRegionMax().y-ImGui::GetCursorPos().y)); // Resize canvas what's available
  10717. draw_list->AddRect(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), 0xFFFFFFFF);
  10718. bool adding_preview = false;
  10719. ImGui::InvisibleButton("canvas", canvas_size);
  10720. if (ImGui::IsItemHovered())
  10721. {
  10722. ImVec2 mouse_pos_in_canvas = ImVec2(ImGui::GetIO().MousePos.x - canvas_pos.x, ImGui::GetIO().MousePos.y - canvas_pos.y);
  10723. if (!adding_line && ImGui::GetIO().MouseClicked[0])
  10724. {
  10725. points.push_back(mouse_pos_in_canvas);
  10726. adding_line = true;
  10727. }
  10728. if (adding_line)
  10729. {
  10730. adding_preview = true;
  10731. points.push_back(mouse_pos_in_canvas);
  10732. if (!ImGui::GetIO().MouseDown[0])
  10733. adding_line = adding_preview = false;
  10734. }
  10735. if (ImGui::GetIO().MouseClicked[1] && !points.empty())
  10736. {
  10737. adding_line = false;
  10738. points.pop_back();
  10739. points.pop_back();
  10740. }
  10741. }
  10742. draw_list->PushClipRect(ImVec4(canvas_pos.x, canvas_pos.y, canvas_pos.x+canvas_size.x, canvas_pos.y+canvas_size.y)); // clip lines within the canvas (if we resize it, etc.)
  10743. for (int i = 0; i < (int)points.size() - 1; i += 2)
  10744. draw_list->AddLine(ImVec2(canvas_pos.x + points[i].x, canvas_pos.y + points[i].y), ImVec2(canvas_pos.x + points[i+1].x, canvas_pos.y + points[i+1].y), 0xFF00FFFF);
  10745. draw_list->PopClipRect();
  10746. if (adding_preview)
  10747. points.pop_back();
  10748. ImGui::End();
  10749. }
  10750. // For the console example, here we are using a more C++ like approach of declaring a class to hold the data and the functions.
  10751. struct ExampleAppConsole
  10752. {
  10753. char InputBuf[256];
  10754. ImVector<char*> Items;
  10755. bool ScrollToBottom;
  10756. ImVector<char*> History;
  10757. int HistoryPos; // -1: new line, 0..History.size()-1 browsing history.
  10758. ImVector<const char*> Commands;
  10759. ExampleAppConsole()
  10760. {
  10761. ClearLog();
  10762. HistoryPos = -1;
  10763. Commands.push_back("HELP");
  10764. Commands.push_back("HISTORY");
  10765. Commands.push_back("CLEAR");
  10766. Commands.push_back("CLASSIFY"); // "classify" is here to provide an example of "C"+[tab] completing to "CL" and displaying matches.
  10767. }
  10768. ~ExampleAppConsole()
  10769. {
  10770. ClearLog();
  10771. for (size_t i = 0; i < Items.size(); i++)
  10772. free(History[i]);
  10773. }
  10774. void ClearLog()
  10775. {
  10776. for (size_t i = 0; i < Items.size(); i++)
  10777. free(Items[i]);
  10778. Items.clear();
  10779. ScrollToBottom = true;
  10780. }
  10781. void AddLog(const char* fmt, ...)
  10782. {
  10783. char buf[1024];
  10784. va_list args;
  10785. va_start(args, fmt);
  10786. ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  10787. va_end(args);
  10788. Items.push_back(strdup(buf));
  10789. ScrollToBottom = true;
  10790. }
  10791. void Run(const char* title, bool* opened)
  10792. {
  10793. ImGui::SetNextWindowSize(ImVec2(520,600), ImGuiSetCond_FirstUseEver);
  10794. if (!ImGui::Begin(title, opened))
  10795. {
  10796. ImGui::End();
  10797. return;
  10798. }
  10799. ImGui::TextWrapped("This example implements a console with basic coloring, completion and history. A more elaborate implementation may want to store entries along with extra data such as timestamp, emitter, etc.");
  10800. ImGui::TextWrapped("Enter 'HELP' for help, press TAB to use text completion.");
  10801. // TODO: display items starting from the bottom
  10802. if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.size()); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine();
  10803. if (ImGui::SmallButton("Add Dummy Error")) AddLog("[error] something went wrong"); ImGui::SameLine();
  10804. if (ImGui::SmallButton("Clear")) ClearLog();
  10805. //static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); }
  10806. ImGui::Separator();
  10807. ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
  10808. static ImGuiTextFilter filter;
  10809. filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
  10810. ImGui::PopStyleVar();
  10811. ImGui::Separator();
  10812. // 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());
  10813. // NB- if you have thousands of entries this approach may be too inefficient. You can seek and display only the lines that are visible - CalcListClipping() is a helper to compute this information.
  10814. // If your items are of variable size you may want to implement code similar to what CalcListClipping() does. Or split your data into fixed height items to allow random-seeking into your list.
  10815. ImGui::BeginChild("ScrollingRegion", ImVec2(0,-ImGui::GetItemsLineHeightWithSpacing()));
  10816. if (ImGui::BeginPopupContextWindow())
  10817. {
  10818. if (ImGui::Selectable("Clear")) ClearLog();
  10819. ImGui::EndPopup();
  10820. }
  10821. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing
  10822. for (size_t i = 0; i < Items.size(); i++)
  10823. {
  10824. const char* item = Items[i];
  10825. if (!filter.PassFilter(item))
  10826. continue;
  10827. ImVec4 col = ImColor(255,255,255); // A better implementation may store a type per-item. For the sample let's just parse the text.
  10828. if (strstr(item, "[error]")) col = ImColor(255,100,100);
  10829. else if (strncmp(item, "# ", 2) == 0) col = ImColor(255,200,150);
  10830. ImGui::PushStyleColor(ImGuiCol_Text, col);
  10831. ImGui::TextUnformatted(item);
  10832. ImGui::PopStyleColor();
  10833. }
  10834. if (ScrollToBottom)
  10835. ImGui::SetScrollHere();
  10836. ScrollToBottom = false;
  10837. ImGui::PopStyleVar();
  10838. ImGui::EndChild();
  10839. ImGui::Separator();
  10840. // Command-line
  10841. if (ImGui::InputText("Input", InputBuf, IM_ARRAYSIZE(InputBuf), ImGuiInputTextFlags_EnterReturnsTrue|ImGuiInputTextFlags_CallbackCompletion|ImGuiInputTextFlags_CallbackHistory, &TextEditCallbackStub, (void*)this))
  10842. {
  10843. char* input_end = InputBuf+strlen(InputBuf);
  10844. while (input_end > InputBuf && input_end[-1] == ' ') input_end--; *input_end = 0;
  10845. if (InputBuf[0])
  10846. ExecCommand(InputBuf);
  10847. strcpy(InputBuf, "");
  10848. }
  10849. // Demonstrate keeping auto focus on the input box
  10850. if (ImGui::IsItemHovered() || (ImGui::IsRootWindowOrAnyChildFocused() && !ImGui::IsAnyItemActive() && !ImGui::IsMouseClicked(0)))
  10851. ImGui::SetKeyboardFocusHere(-1); // Auto focus
  10852. ImGui::End();
  10853. }
  10854. void ExecCommand(const char* command_line)
  10855. {
  10856. AddLog("# %s\n", command_line);
  10857. // Insert into history. First find match and delete it so it can be pushed to the back. This isn't trying to be smart or optimal.
  10858. HistoryPos = -1;
  10859. for (int i = (int)History.size()-1; i >= 0; i--)
  10860. if (ImStricmp(History[i], command_line) == 0)
  10861. {
  10862. free(History[i]);
  10863. History.erase(History.begin() + i);
  10864. break;
  10865. }
  10866. History.push_back(strdup(command_line));
  10867. // Process command
  10868. if (ImStricmp(command_line, "CLEAR") == 0)
  10869. {
  10870. ClearLog();
  10871. }
  10872. else if (ImStricmp(command_line, "HELP") == 0)
  10873. {
  10874. AddLog("Commands:");
  10875. for (size_t i = 0; i < Commands.size(); i++)
  10876. AddLog("- %s", Commands[i]);
  10877. }
  10878. else if (ImStricmp(command_line, "HISTORY") == 0)
  10879. {
  10880. for (size_t i = History.size() >= 10 ? History.size() - 10 : 0; i < History.size(); i++)
  10881. AddLog("%3d: %s\n", i, History[i]);
  10882. }
  10883. else
  10884. {
  10885. AddLog("Unknown command: '%s'\n", command_line);
  10886. }
  10887. }
  10888. static int TextEditCallbackStub(ImGuiTextEditCallbackData* data) // In C++11 you are better off using lambdas for this sort of forwarding callbacks
  10889. {
  10890. ExampleAppConsole* console = (ExampleAppConsole*)data->UserData;
  10891. return console->TextEditCallback(data);
  10892. }
  10893. int TextEditCallback(ImGuiTextEditCallbackData* data)
  10894. {
  10895. //AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
  10896. switch (data->EventFlag)
  10897. {
  10898. case ImGuiInputTextFlags_CallbackCompletion:
  10899. {
  10900. // Example of TEXT COMPLETION
  10901. // Locate beginning of current word
  10902. const char* word_end = data->Buf + data->CursorPos;
  10903. const char* word_start = word_end;
  10904. while (word_start > data->Buf)
  10905. {
  10906. const char c = word_start[-1];
  10907. if (ImCharIsSpace(c) || c == ',' || c == ';')
  10908. break;
  10909. word_start--;
  10910. }
  10911. // Build a list of candidates
  10912. ImVector<const char*> candidates;
  10913. for (size_t i = 0; i < Commands.size(); i++)
  10914. if (ImStrnicmp(Commands[i], word_start, (int)(word_end-word_start)) == 0)
  10915. candidates.push_back(Commands[i]);
  10916. if (candidates.size() == 0)
  10917. {
  10918. // No match
  10919. AddLog("No match for \"%.*s\"!\n", word_end-word_start, word_start);
  10920. }
  10921. else if (candidates.size() == 1)
  10922. {
  10923. // Single match. Delete the beginning of the word and replace it entirely so we've got nice casing
  10924. data->DeleteChars((int)(word_start-data->Buf), (int)(word_end-word_start));
  10925. data->InsertChars(data->CursorPos, candidates[0]);
  10926. data->InsertChars(data->CursorPos, " ");
  10927. }
  10928. else
  10929. {
  10930. // Multiple matches. Complete as much as we can, so inputing "C" will complete to "CL" and display "CLEAR" and "CLASSIFY"
  10931. int match_len = (int)(word_end - word_start);
  10932. for (;;)
  10933. {
  10934. int c = 0;
  10935. bool all_candidates_matches = true;
  10936. for (size_t i = 0; i < candidates.size() && all_candidates_matches; i++)
  10937. if (i == 0)
  10938. c = toupper(candidates[i][match_len]);
  10939. else if (c != toupper(candidates[i][match_len]))
  10940. all_candidates_matches = false;
  10941. if (!all_candidates_matches)
  10942. break;
  10943. match_len++;
  10944. }
  10945. if (match_len > 0)
  10946. {
  10947. data->DeleteChars((int)(word_start - data->Buf), (int)(word_end-word_start));
  10948. data->InsertChars(data->CursorPos, candidates[0], candidates[0] + match_len);
  10949. }
  10950. // List matches
  10951. AddLog("Possible matches:\n");
  10952. for (size_t i = 0; i < candidates.size(); i++)
  10953. AddLog("- %s\n", candidates[i]);
  10954. }
  10955. break;
  10956. }
  10957. case ImGuiInputTextFlags_CallbackHistory:
  10958. {
  10959. // Example of HISTORY
  10960. const int prev_history_pos = HistoryPos;
  10961. if (data->EventKey == ImGuiKey_UpArrow)
  10962. {
  10963. if (HistoryPos == -1)
  10964. HistoryPos = (int)(History.size() - 1);
  10965. else if (HistoryPos > 0)
  10966. HistoryPos--;
  10967. }
  10968. else if (data->EventKey == ImGuiKey_DownArrow)
  10969. {
  10970. if (HistoryPos != -1)
  10971. if (++HistoryPos >= (int)History.size())
  10972. HistoryPos = -1;
  10973. }
  10974. // A better implementation would preserve the data on the current input line along with cursor position.
  10975. if (prev_history_pos != HistoryPos)
  10976. {
  10977. ImFormatString(data->Buf, data->BufSize, "%s", (HistoryPos >= 0) ? History[HistoryPos] : "");
  10978. data->BufDirty = true;
  10979. data->CursorPos = data->SelectionStart = data->SelectionEnd = (int)strlen(data->Buf);
  10980. }
  10981. }
  10982. }
  10983. return 0;
  10984. }
  10985. };
  10986. static void ShowExampleAppConsole(bool* opened)
  10987. {
  10988. static ExampleAppConsole console;
  10989. console.Run("Example: Console", opened);
  10990. }
  10991. static void ShowExampleAppLayout(bool* opened)
  10992. {
  10993. ImGui::SetNextWindowSize(ImVec2(500, 440), ImGuiSetCond_FirstUseEver);
  10994. if (ImGui::Begin("Example: Layout", opened, ImGuiWindowFlags_MenuBar))
  10995. {
  10996. if (ImGui::BeginMenuBar())
  10997. {
  10998. if (ImGui::BeginMenu("File"))
  10999. {
  11000. if (ImGui::MenuItem("Close")) *opened = false;
  11001. ImGui::EndMenu();
  11002. }
  11003. ImGui::EndMenuBar();
  11004. }
  11005. // left
  11006. static int selected = 0;
  11007. ImGui::BeginChild("left pane", ImVec2(150, 0), true);
  11008. for (int i = 0; i < 100; i++)
  11009. {
  11010. char label[128];
  11011. sprintf(label, "MyObject %d", i);
  11012. if (ImGui::Selectable(label, selected == i))
  11013. selected = i;
  11014. }
  11015. ImGui::EndChild();
  11016. ImGui::SameLine();
  11017. // right
  11018. ImGui::BeginGroup();
  11019. ImGui::BeginChild("item view", ImVec2(0, -ImGui::GetItemsLineHeightWithSpacing())); // Leave room for 1 line below us
  11020. ImGui::Text("MyObject: %d", selected);
  11021. ImGui::Separator();
  11022. ImGui::TextWrapped("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ");
  11023. ImGui::EndChild();
  11024. ImGui::BeginChild("buttons");
  11025. if (ImGui::Button("Revert")) {}
  11026. ImGui::SameLine();
  11027. if (ImGui::Button("Save")) {}
  11028. ImGui::EndChild();
  11029. ImGui::EndGroup();
  11030. }
  11031. ImGui::End();
  11032. }
  11033. static void ShowExampleAppLongText(bool* opened)
  11034. {
  11035. ImGui::SetNextWindowSize(ImVec2(520,600), ImGuiSetCond_FirstUseEver);
  11036. if (!ImGui::Begin("Example: Long text display", opened))
  11037. {
  11038. ImGui::End();
  11039. return;
  11040. }
  11041. static int test_type = 0;
  11042. static ImGuiTextBuffer log;
  11043. static int lines = 0;
  11044. ImGui::Text("Printing unusually long amount of text.");
  11045. ImGui::Combo("Test type", &test_type, "Single call to TextUnformatted()\0Multiple calls to Text(), clipped manually\0Multiple calls to Text(), not clipped");
  11046. ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size());
  11047. if (ImGui::Button("Clear")) { log.clear(); lines = 0; }
  11048. ImGui::SameLine();
  11049. if (ImGui::Button("Add 1000 lines"))
  11050. {
  11051. for (int i = 0; i < 1000; i++)
  11052. log.append("%i The quick brown fox jumps over the lazy dog\n", lines+i);
  11053. lines += 1000;
  11054. }
  11055. ImGui::BeginChild("Log");
  11056. switch (test_type)
  11057. {
  11058. case 0:
  11059. // Single call to TextUnformatted() with a big buffer
  11060. ImGui::TextUnformatted(log.begin(), log.end());
  11061. break;
  11062. case 1:
  11063. // Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the CalcListClipping() helper.
  11064. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0,0));
  11065. int display_start, display_end;
  11066. ImGui::CalcListClipping(lines, ImGui::GetTextLineHeight(), &display_start, &display_end);
  11067. ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (display_start) * ImGui::GetTextLineHeight());
  11068. for (int i = display_start; i < display_end; i++)
  11069. ImGui::Text("%i The quick brown fox jumps over the lazy dog\n", i);
  11070. ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (lines - display_end) * ImGui::GetTextLineHeight());
  11071. ImGui::PopStyleVar();
  11072. break;
  11073. case 2:
  11074. // Multiple calls to Text(), not clipped (slow)
  11075. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0,0));
  11076. for (int i = 0; i < lines; i++)
  11077. ImGui::Text("%i The quick brown fox jumps over the lazy dog\n", i);
  11078. ImGui::PopStyleVar();
  11079. break;
  11080. }
  11081. ImGui::EndChild();
  11082. ImGui::End();
  11083. }
  11084. // End of Sample code
  11085. #endif
  11086. //-----------------------------------------------------------------------------
  11087. // FONT DATA
  11088. //-----------------------------------------------------------------------------
  11089. // Compressed with stb_compress() then converted to a C array.
  11090. // Use the program in extra_fonts/binary_to_compressed_c.cpp to create the array from a TTF file.
  11091. // Decompression from stb.h (public domain) by Sean Barrett https://github.com/nothings/stb/blob/master/stb.h
  11092. //-----------------------------------------------------------------------------
  11093. static unsigned int stb_decompress_length(unsigned char *input)
  11094. {
  11095. return (input[8] << 24) + (input[9] << 16) + (input[10] << 8) + input[11];
  11096. }
  11097. static unsigned char *stb__barrier, *stb__barrier2, *stb__barrier3, *stb__barrier4;
  11098. static unsigned char *stb__dout;
  11099. static void stb__match(unsigned char *data, unsigned int length)
  11100. {
  11101. // INVERSE of memmove... write each byte before copying the next...
  11102. IM_ASSERT (stb__dout + length <= stb__barrier);
  11103. if (stb__dout + length > stb__barrier) { stb__dout += length; return; }
  11104. if (data < stb__barrier4) { stb__dout = stb__barrier+1; return; }
  11105. while (length--) *stb__dout++ = *data++;
  11106. }
  11107. static void stb__lit(unsigned char *data, unsigned int length)
  11108. {
  11109. IM_ASSERT (stb__dout + length <= stb__barrier);
  11110. if (stb__dout + length > stb__barrier) { stb__dout += length; return; }
  11111. if (data < stb__barrier2) { stb__dout = stb__barrier+1; return; }
  11112. memcpy(stb__dout, data, length);
  11113. stb__dout += length;
  11114. }
  11115. #define stb__in2(x) ((i[x] << 8) + i[(x)+1])
  11116. #define stb__in3(x) ((i[x] << 16) + stb__in2((x)+1))
  11117. #define stb__in4(x) ((i[x] << 24) + stb__in3((x)+1))
  11118. static unsigned char *stb_decompress_token(unsigned char *i)
  11119. {
  11120. if (*i >= 0x20) { // use fewer if's for cases that expand small
  11121. if (*i >= 0x80) stb__match(stb__dout-i[1]-1, i[0] - 0x80 + 1), i += 2;
  11122. else if (*i >= 0x40) stb__match(stb__dout-(stb__in2(0) - 0x4000 + 1), i[2]+1), i += 3;
  11123. else /* *i >= 0x20 */ stb__lit(i+1, i[0] - 0x20 + 1), i += 1 + (i[0] - 0x20 + 1);
  11124. } else { // more ifs for cases that expand large, since overhead is amortized
  11125. if (*i >= 0x18) stb__match(stb__dout-(stb__in3(0) - 0x180000 + 1), i[3]+1), i += 4;
  11126. else if (*i >= 0x10) stb__match(stb__dout-(stb__in3(0) - 0x100000 + 1), stb__in2(3)+1), i += 5;
  11127. else if (*i >= 0x08) stb__lit(i+2, stb__in2(0) - 0x0800 + 1), i += 2 + (stb__in2(0) - 0x0800 + 1);
  11128. else if (*i == 0x07) stb__lit(i+3, stb__in2(1) + 1), i += 3 + (stb__in2(1) + 1);
  11129. else if (*i == 0x06) stb__match(stb__dout-(stb__in3(1)+1), i[4]+1), i += 5;
  11130. else if (*i == 0x04) stb__match(stb__dout-(stb__in3(1)+1), stb__in2(4)+1), i += 6;
  11131. }
  11132. return i;
  11133. }
  11134. static unsigned int stb_adler32(unsigned int adler32, unsigned char *buffer, unsigned int buflen)
  11135. {
  11136. const unsigned long ADLER_MOD = 65521;
  11137. unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16;
  11138. unsigned long blocklen, i;
  11139. blocklen = buflen % 5552;
  11140. while (buflen) {
  11141. for (i=0; i + 7 < blocklen; i += 8) {
  11142. s1 += buffer[0], s2 += s1;
  11143. s1 += buffer[1], s2 += s1;
  11144. s1 += buffer[2], s2 += s1;
  11145. s1 += buffer[3], s2 += s1;
  11146. s1 += buffer[4], s2 += s1;
  11147. s1 += buffer[5], s2 += s1;
  11148. s1 += buffer[6], s2 += s1;
  11149. s1 += buffer[7], s2 += s1;
  11150. buffer += 8;
  11151. }
  11152. for (; i < blocklen; ++i)
  11153. s1 += *buffer++, s2 += s1;
  11154. s1 %= ADLER_MOD, s2 %= ADLER_MOD;
  11155. buflen -= blocklen;
  11156. blocklen = 5552;
  11157. }
  11158. return (unsigned int)(s2 << 16) + (unsigned int)s1;
  11159. }
  11160. static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length)
  11161. {
  11162. unsigned int olen;
  11163. if (stb__in4(0) != 0x57bC0000) return 0;
  11164. if (stb__in4(4) != 0) return 0; // error! stream is > 4GB
  11165. olen = stb_decompress_length(i);
  11166. stb__barrier2 = i;
  11167. stb__barrier3 = i+length;
  11168. stb__barrier = output + olen;
  11169. stb__barrier4 = output;
  11170. i += 16;
  11171. stb__dout = output;
  11172. for (;;) {
  11173. unsigned char *old_i = i;
  11174. i = stb_decompress_token(i);
  11175. if (i == old_i) {
  11176. if (*i == 0x05 && i[1] == 0xfa) {
  11177. IM_ASSERT(stb__dout == output + olen);
  11178. if (stb__dout != output + olen) return 0;
  11179. if (stb_adler32(1, output, olen) != (unsigned int) stb__in4(2))
  11180. return 0;
  11181. return olen;
  11182. } else {
  11183. IM_ASSERT(0); /* NOTREACHED */
  11184. return 0;
  11185. }
  11186. }
  11187. IM_ASSERT(stb__dout <= output + olen);
  11188. if (stb__dout > output + olen)
  11189. return 0;
  11190. }
  11191. }
  11192. //-----------------------------------------------------------------------------
  11193. // ProggyClean.ttf
  11194. // Copyright (c) 2004, 2005 Tristan Grimmer
  11195. // MIT license (see License.txt in http://www.upperbounds.net/download/ProggyClean.ttf.zip)
  11196. // Download and more information at http://upperbounds.net
  11197. //-----------------------------------------------------------------------------
  11198. static const unsigned int proggy_clean_ttf_compressed_size = 9583;
  11199. static const unsigned int proggy_clean_ttf_compressed_data[9584/4] =
  11200. {
  11201. 0x0000bc57, 0x00000000, 0xf8a00000, 0x00000400, 0x00010037, 0x000c0000, 0x00030080, 0x2f534f40, 0x74eb8832, 0x01000090, 0x2c158248, 0x616d634e,
  11202. 0x23120270, 0x03000075, 0x241382a0, 0x74766352, 0x82178220, 0xfc042102, 0x02380482, 0x66796c67, 0x5689af12, 0x04070000, 0x80920000, 0x64616568,
  11203. 0xd36691d7, 0xcc201b82, 0x36210382, 0x27108268, 0xc3014208, 0x04010000, 0x243b0f82, 0x78746d68, 0x807e008a, 0x98010000, 0x06020000, 0x61636f6c,
  11204. 0xd8b0738c, 0x82050000, 0x0402291e, 0x7078616d, 0xda00ae01, 0x28201f82, 0x202c1082, 0x656d616e, 0x96bb5925, 0x84990000, 0x9e2c1382, 0x74736f70,
  11205. 0xef83aca6, 0x249b0000, 0xd22c3382, 0x70657270, 0x12010269, 0xf4040000, 0x08202f82, 0x012ecb84, 0x553c0000, 0x0f5fd5e9, 0x0300f53c, 0x00830008,
  11206. 0x7767b722, 0x002b3f82, 0xa692bd00, 0xfe0000d7, 0x83800380, 0x21f1826f, 0x00850002, 0x41820120, 0x40fec026, 0x80030000, 0x05821083, 0x07830120,
  11207. 0x0221038a, 0x24118200, 0x90000101, 0x82798200, 0x00022617, 0x00400008, 0x2009820a, 0x82098276, 0x82002006, 0x9001213b, 0x0223c883, 0x828a02bc,
  11208. 0x858f2010, 0xc5012507, 0x00023200, 0x04210083, 0x91058309, 0x6c412b03, 0x40007374, 0xac200000, 0x00830008, 0x01000523, 0x834d8380, 0x80032103,
  11209. 0x012101bf, 0x23b88280, 0x00800000, 0x0b830382, 0x07820120, 0x83800021, 0x88012001, 0x84002009, 0x2005870f, 0x870d8301, 0x2023901b, 0x83199501,
  11210. 0x82002015, 0x84802000, 0x84238267, 0x88002027, 0x8561882d, 0x21058211, 0x13880000, 0x01800022, 0x05850d85, 0x0f828020, 0x03208384, 0x03200582,
  11211. 0x47901b84, 0x1b850020, 0x1f821d82, 0x3f831d88, 0x3f410383, 0x84058405, 0x210982cd, 0x09830000, 0x03207789, 0xf38a1384, 0x01203782, 0x13872384,
  11212. 0x0b88c983, 0x0d898f84, 0x00202982, 0x23900383, 0x87008021, 0x83df8301, 0x86118d03, 0x863f880d, 0x8f35880f, 0x2160820f, 0x04830300, 0x1c220382,
  11213. 0x05820100, 0x4c000022, 0x09831182, 0x04001c24, 0x11823000, 0x0800082e, 0x00000200, 0xff007f00, 0xffffac20, 0x00220982, 0x09848100, 0xdf216682,
  11214. 0x843586d5, 0x06012116, 0x04400684, 0xa58120d7, 0x00b127d8, 0x01b88d01, 0x2d8685ff, 0xc100c621, 0xf4be0801, 0x9e011c01, 0x88021402, 0x1403fc02,
  11215. 0x9c035803, 0x1404de03, 0x50043204, 0xa2046204, 0x66051605, 0x1206bc05, 0xd6067406, 0x7e073807, 0x4e08ec07, 0x96086c08, 0x1009d008, 0x88094a09,
  11216. 0x800a160a, 0x560b040b, 0x2e0cc80b, 0xea0c820c, 0xa40d5e0d, 0x500eea0d, 0x280f960e, 0x1210b00f, 0xe0107410, 0xb6115211, 0x6e120412, 0x4c13c412,
  11217. 0xf613ac13, 0xae145814, 0x4015ea14, 0xa6158015, 0x1216b815, 0xc6167e16, 0x8e173417, 0x5618e017, 0xee18ba18, 0x96193619, 0x481ad419, 0xf01a9c1a,
  11218. 0xc81b5c1b, 0x4c1c041c, 0xea1c961c, 0x921d2a1d, 0x401ed21d, 0xe01e8e1e, 0x761f241f, 0xa61fa61f, 0x01821020, 0x8a202e34, 0xc820b220, 0x74211421,
  11219. 0xee219821, 0x86226222, 0x01820c23, 0x83238021, 0x23983c01, 0x24d823b0, 0x244a2400, 0x24902468, 0x250625ae, 0x25822560, 0x26f825f8, 0x82aa2658,
  11220. 0xd8be0801, 0x9a274027, 0x68280a28, 0x0e29a828, 0xb8292029, 0x362af829, 0x602a602a, 0x2a2b022b, 0xac2b5e2b, 0x202ce62b, 0x9a2c342c, 0x5c2d282d,
  11221. 0xaa2d782d, 0x262ee82d, 0x262fa62e, 0xf42fb62f, 0xc8305e30, 0xb4313e31, 0x9e321e32, 0x82331e33, 0x5c34ee33, 0x3a35ce34, 0xd4358635, 0x72362636,
  11222. 0x7637e636, 0x3a38d837, 0x1239a638, 0xae397439, 0x9a3a2e3a, 0x7c3b063b, 0x3a3ce83b, 0x223d963c, 0xec3d863d, 0xc63e563e, 0x9a3f2a3f, 0x6a401240,
  11223. 0x3641d040, 0x0842a241, 0x7a424042, 0xf042b842, 0xcc436243, 0x8a442a44, 0x5845ee44, 0xe245b645, 0xb4465446, 0x7a471447, 0x5448da47, 0x4049c648,
  11224. 0x15462400, 0x034d0808, 0x0b000700, 0x13000f00, 0x1b001700, 0x23001f00, 0x2b002700, 0x33002f00, 0x3b003700, 0x43003f00, 0x4b004700, 0x53004f00,
  11225. 0x5b005700, 0x63005f00, 0x6b006700, 0x73006f00, 0x7b007700, 0x83007f00, 0x8b008700, 0x00008f00, 0x15333511, 0x20039631, 0x20178205, 0xd3038221,
  11226. 0x20739707, 0x25008580, 0x028080fc, 0x05be8080, 0x04204a85, 0x05ce0685, 0x0107002a, 0x02000080, 0x00000400, 0x250d8b41, 0x33350100, 0x03920715,
  11227. 0x13820320, 0x858d0120, 0x0e8d0320, 0xff260d83, 0x00808000, 0x54820106, 0x04800223, 0x845b8c80, 0x41332059, 0x078b068f, 0x82000121, 0x82fe2039,
  11228. 0x84802003, 0x83042004, 0x23598a0e, 0x00180000, 0x03210082, 0x42ab9080, 0x73942137, 0x2013bb41, 0x8f978205, 0x2027a39b, 0x20b68801, 0x84b286fd,
  11229. 0x91c88407, 0x41032011, 0x11a51130, 0x15000027, 0x80ff8000, 0x11af4103, 0x841b0341, 0x8bd983fd, 0x9be99bc9, 0x8343831b, 0x21f1821f, 0xb58300ff,
  11230. 0x0f84e889, 0xf78a0484, 0x8000ff22, 0x0020eeb3, 0x14200082, 0x2130ef41, 0xeb431300, 0x4133200a, 0xd7410ecb, 0x9a07200b, 0x2027871b, 0x21238221,
  11231. 0xe7828080, 0xe784fd20, 0xe8848020, 0xfe808022, 0x08880d85, 0xba41fd20, 0x82248205, 0x85eab02a, 0x008022e7, 0x2cd74200, 0x44010021, 0xd34406eb,
  11232. 0x44312013, 0xcf8b0eef, 0x0d422f8b, 0x82332007, 0x0001212f, 0x8023cf82, 0x83000180, 0x820583de, 0x830682d4, 0x820020d4, 0x82dc850a, 0x20e282e9,
  11233. 0xb2ff85fe, 0x010327e9, 0x02000380, 0x0f440400, 0x0c634407, 0x68825982, 0x85048021, 0x260a825d, 0x010b0000, 0x4400ff00, 0x2746103f, 0x08d74209,
  11234. 0x4d440720, 0x0eaf4406, 0xc3441d20, 0x23078406, 0xff800002, 0x04845b83, 0x8d05b241, 0x1781436f, 0x6b8c87a5, 0x1521878e, 0x06474505, 0x01210783,
  11235. 0x84688c00, 0x8904828e, 0x441e8cf7, 0x0b270cff, 0x80008000, 0x45030003, 0xfb430fab, 0x080f4107, 0x410bf942, 0xd34307e5, 0x070d4207, 0x80800123,
  11236. 0x205d85fe, 0x849183fe, 0x20128404, 0x82809702, 0x00002217, 0x41839a09, 0x6b4408cf, 0x0733440f, 0x3b460720, 0x82798707, 0x97802052, 0x0000296f,
  11237. 0xff800004, 0x01800100, 0x0021ef89, 0x0a914625, 0x410a4d41, 0x00250ed4, 0x00050000, 0x056d4280, 0x210a7b46, 0x21481300, 0x46ed8512, 0x00210bd1,
  11238. 0x89718202, 0x21738877, 0x2b850001, 0x00220582, 0x87450a00, 0x0ddb4606, 0x41079b42, 0x9d420c09, 0x0b09420b, 0x8d820720, 0x9742fc84, 0x42098909,
  11239. 0x00241e0f, 0x00800014, 0x0b47da82, 0x0833442a, 0x49078d41, 0x2f450f13, 0x42278f17, 0x01200751, 0x22063742, 0x44808001, 0x20450519, 0x88068906,
  11240. 0x83fe2019, 0x4203202a, 0x1a941a58, 0x00820020, 0xe7a40e20, 0x420ce146, 0x854307e9, 0x0fcb4713, 0xff20a182, 0xfe209b82, 0x0c867f8b, 0x0021aea4,
  11241. 0x219fa40f, 0x7d41003b, 0x07194214, 0xbf440520, 0x071d4206, 0x6941a590, 0x80802309, 0x028900ff, 0xa9a4b685, 0xc5808021, 0x449b82ab, 0x152007eb,
  11242. 0x42134d46, 0x61440a15, 0x051e4208, 0x222b0442, 0x47001100, 0xfd412913, 0x17194714, 0x410f5b41, 0x02220773, 0x09428080, 0x21a98208, 0xd4420001,
  11243. 0x481c840d, 0x00232bc9, 0x42120000, 0xe74c261b, 0x149d4405, 0x07209d87, 0x410db944, 0x14421c81, 0x42fd2005, 0x80410bd2, 0x203d8531, 0x06874100,
  11244. 0x48256f4a, 0xcb420c95, 0x13934113, 0x44075d44, 0x044c0855, 0x00ff2105, 0xfe228185, 0x45448000, 0x22c5b508, 0x410c0000, 0x7b412087, 0x1bb74514,
  11245. 0x32429c85, 0x0a574805, 0x21208943, 0x8ba01300, 0x440dfb4e, 0x77431437, 0x245b4113, 0x200fb145, 0x41108ffe, 0x80203562, 0x00200082, 0x46362b42,
  11246. 0x1742178d, 0x4527830f, 0x0f830b2f, 0x4a138146, 0x802409a1, 0xfe8000ff, 0x94419982, 0x09294320, 0x04000022, 0x49050f4f, 0xcb470a63, 0x48032008,
  11247. 0x2b48067b, 0x85022008, 0x82638338, 0x00002209, 0x05af4806, 0x900e9f49, 0x84c5873f, 0x214285bd, 0x064900ff, 0x0c894607, 0x00000023, 0x4903820a,
  11248. 0x714319f3, 0x0749410c, 0x8a07a145, 0x02152507, 0xfe808000, 0x74490386, 0x8080211b, 0x0c276f82, 0x00018000, 0x48028003, 0x2b2315db, 0x43002f00,
  11249. 0x6f82142f, 0x44011521, 0x93510da7, 0x20e68508, 0x06494d80, 0x8e838020, 0x06821286, 0x124bff20, 0x25f3830c, 0x03800080, 0xe74a0380, 0x207b8715,
  11250. 0x876b861d, 0x4a152007, 0x07870775, 0xf6876086, 0x8417674a, 0x0a0021f2, 0x431c9743, 0x8d421485, 0x200b830b, 0x06474d03, 0x71828020, 0x04510120,
  11251. 0x42da8606, 0x1f831882, 0x001a0022, 0xff4d0082, 0x0b0f532c, 0x0d449b94, 0x4e312007, 0x074f12e7, 0x0bf3490b, 0xbb412120, 0x413f820a, 0xef490857,
  11252. 0x80002313, 0xe2830001, 0x6441fc20, 0x8b802006, 0x00012108, 0xfd201582, 0x492c9b48, 0x802014ff, 0x51084347, 0x0f4327f3, 0x17bf4a14, 0x201b7944,
  11253. 0x06964201, 0x134ffe20, 0x20d6830b, 0x25d78280, 0xfd800002, 0x05888000, 0x9318dc41, 0x21d282d4, 0xdb481800, 0x0dff542a, 0x45107743, 0xe14813f5,
  11254. 0x0f034113, 0x83135d45, 0x47b28437, 0xe4510e73, 0x21f58e06, 0x2b8400fd, 0x1041fcac, 0x08db4b0b, 0x421fdb41, 0xdf4b18df, 0x011d210a, 0x420af350,
  11255. 0x6e8308af, 0xac85cb86, 0x1e461082, 0x82b7a407, 0x411420a3, 0xa34130ab, 0x178f4124, 0x41139741, 0x86410d93, 0x82118511, 0x057243d8, 0x8941d9a4,
  11256. 0x3093480c, 0x4a13474f, 0xfb5016a9, 0x07ad4108, 0x4a0f9d42, 0xfe200fad, 0x4708aa41, 0x83482dba, 0x288f4d06, 0xb398c3bb, 0x44267b41, 0xb34439d7,
  11257. 0x0755410f, 0x200ebb45, 0x0f5f4215, 0x20191343, 0x06df5301, 0xf04c0220, 0x2ba64d07, 0x82050841, 0x430020ce, 0xa78f3627, 0x5213ff42, 0x2f970bc1,
  11258. 0x4305ab55, 0xa084111b, 0x450bac45, 0x5f4238b8, 0x010c2106, 0x0220ed82, 0x441bb344, 0x875010af, 0x0737480f, 0x490c5747, 0x0c840c03, 0x4c204b42,
  11259. 0x8ba905d7, 0x8b948793, 0x510c0c51, 0xfb4b24b9, 0x1b174107, 0x5709d74c, 0xd1410ca5, 0x079d480f, 0x201ff541, 0x06804780, 0x7d520120, 0x80002205,
  11260. 0x20a983fe, 0x47bb83fe, 0x1b8409b4, 0x81580220, 0x4e00202c, 0x4f41282f, 0x0eab4f17, 0x57471520, 0x0e0f4808, 0x8221e041, 0x3e1b4a8b, 0x4407175d,
  11261. 0x1b4b071f, 0x4a0f8b07, 0x174a0703, 0x0ba5411b, 0x430fb141, 0x0120057b, 0xfc20dd82, 0x4a056047, 0xf4850c0c, 0x01221982, 0x02828000, 0x1a5d088b,
  11262. 0x20094108, 0x8c0e3941, 0x4900200e, 0x7744434f, 0x200b870b, 0x0e4b5a33, 0x2b41f78b, 0x8b138307, 0x0b9f450b, 0x2406f741, 0xfd808001, 0x09475a00,
  11263. 0x84000121, 0x5980200e, 0x85450e5d, 0x832c8206, 0x4106831e, 0x00213814, 0x28b34810, 0x410c2f4b, 0x5f4a13d7, 0x0b2b4113, 0x6e43a883, 0x11174b05,
  11264. 0x4b066a45, 0xcc470541, 0x5000202b, 0xcb472f4b, 0x44b59f0f, 0xc5430b5b, 0x0d654907, 0x21065544, 0xd6828080, 0xfe201982, 0x8230ec4a, 0x120025c2,
  11265. 0x80ff8000, 0x4128d74d, 0x3320408b, 0x410a9f50, 0xdb822793, 0x822bd454, 0x61134b2e, 0x410b214a, 0xad4117c9, 0x0001211f, 0x4206854f, 0x4b430596,
  11266. 0x06bb5530, 0x2025cf46, 0x0ddd5747, 0x500ea349, 0x0f840fa7, 0x5213c153, 0x634e08d1, 0x0bbe4809, 0x59316e4d, 0x5b50053f, 0x203f6323, 0x5117eb46,
  11267. 0x94450a63, 0x246e410a, 0x63410020, 0x0bdb5f2f, 0x4233ab44, 0x39480757, 0x112d4a07, 0x7241118f, 0x000e2132, 0x9f286f41, 0x0f8762c3, 0x33350723,
  11268. 0x094e6415, 0x2010925f, 0x067252fe, 0xd0438020, 0x63a68225, 0x11203a4f, 0x480e6360, 0x5748131f, 0x079b521f, 0x200e2f43, 0x864b8315, 0x113348e7,
  11269. 0x85084e48, 0x06855008, 0x5880fd21, 0x7c420925, 0x0c414824, 0x37470c86, 0x1b8b422b, 0x5b0a8755, 0x23410c21, 0x0b83420b, 0x5a082047, 0xf482067f,
  11270. 0xa80b4c47, 0x0c0021cf, 0x20207b42, 0x0fb74100, 0x420b8744, 0xeb43076f, 0x0f6f420b, 0x4261fe20, 0x439aa00c, 0x215034e3, 0x0ff9570f, 0x4b1f2d5d,
  11271. 0x2d5d0c6f, 0x09634d0b, 0x1f51b8a0, 0x620f200c, 0xaf681e87, 0x24f94d07, 0x4e0f4945, 0xfe200c05, 0x22139742, 0x57048080, 0x23950c20, 0x97601585,
  11272. 0x4813201f, 0xad620523, 0x200f8f0f, 0x9e638f15, 0x00002181, 0x41342341, 0x0f930f0b, 0x210b4b62, 0x978f0001, 0xfe200f84, 0x8425c863, 0x2704822b,
  11273. 0x80000a00, 0x00038001, 0x610e9768, 0x834514bb, 0x0bc3430f, 0x2107e357, 0x80848080, 0x4400fe21, 0x2e410983, 0x00002a1a, 0x00000700, 0x800380ff,
  11274. 0x0fdf5800, 0x59150021, 0xd142163d, 0x0c02410c, 0x01020025, 0x65800300, 0x00240853, 0x1d333501, 0x15220382, 0x35420001, 0x44002008, 0x376406d7,
  11275. 0x096f6b19, 0x480bc142, 0x8f4908a7, 0x211f8b1f, 0x9e830001, 0x0584fe20, 0x4180fd21, 0x11850910, 0x8d198259, 0x000021d4, 0x5a08275d, 0x275d1983,
  11276. 0x06d9420e, 0x9f08b36a, 0x0f7d47b5, 0x8d8a2f8b, 0x4c0e0b57, 0xe7410e17, 0x42d18c1a, 0xb351087a, 0x1ac36505, 0x4b4a2f20, 0x0b9f450d, 0x430beb53,
  11277. 0xa7881015, 0xa5826a83, 0x80200f82, 0x86185a65, 0x4100208e, 0x176c3367, 0x0fe7650b, 0x4a17ad4b, 0x0f4217ed, 0x112e4206, 0x41113a42, 0xf7423169,
  11278. 0x0cb34737, 0x560f8b46, 0xa75407e5, 0x5f01200f, 0x31590c48, 0x80802106, 0x42268841, 0x0020091e, 0x4207ef64, 0x69461df7, 0x138d4114, 0x820f5145,
  11279. 0x53802090, 0xff200529, 0xb944b183, 0x417e8505, 0x00202561, 0x15210082, 0x42378200, 0x9b431cc3, 0x004f220d, 0x0dd54253, 0x4213f149, 0x7d41133b,
  11280. 0x42c9870b, 0x802010f9, 0x420b2c42, 0x8f441138, 0x267c4408, 0x600cb743, 0x8f4109d3, 0x05ab701d, 0x83440020, 0x3521223f, 0x0b794733, 0xfb62fe20,
  11281. 0x4afd2010, 0xaf410ae7, 0x25ce8525, 0x01080000, 0x7b6b0000, 0x0973710b, 0x82010021, 0x49038375, 0x33420767, 0x052c4212, 0x58464b85, 0x41fe2005,
  11282. 0x50440c27, 0x000c2209, 0x1cb36b80, 0x9b06df44, 0x0f93566f, 0x52830220, 0xfe216e8d, 0x200f8200, 0x0fb86704, 0xb057238d, 0x050b5305, 0x7217eb47,
  11283. 0xbd410b6b, 0x0f214610, 0x871f9956, 0x1e91567e, 0x2029b741, 0x20008200, 0x18b7410a, 0x27002322, 0x41095543, 0x0f8f0fb3, 0x41000121, 0x889d111c,
  11284. 0x14207b82, 0x00200382, 0x73188761, 0x475013a7, 0x6e33200c, 0x234e0ea3, 0x9b138313, 0x08e54d17, 0x9711094e, 0x2ee74311, 0x4908875e, 0xd75d1f1f,
  11285. 0x19ab5238, 0xa2084d48, 0x63a7a9b3, 0x55450b83, 0x0fd74213, 0x440d814c, 0x4f481673, 0x05714323, 0x13000022, 0x412e1f46, 0xdf493459, 0x21c7550f,
  11286. 0x8408215f, 0x201d49cb, 0xb1103043, 0x0f0d65d7, 0x452b8d41, 0x594b0f8d, 0x0b004605, 0xb215eb46, 0x000a24d7, 0x47000080, 0x002118cf, 0x06436413,
  11287. 0x420bd750, 0x2b500743, 0x076a470c, 0x4105c050, 0xd942053f, 0x0d00211a, 0x5f44779c, 0x0ce94805, 0x51558186, 0x14a54c0b, 0x49082b41, 0x0a4b0888,
  11288. 0x8080261f, 0x0d000000, 0x20048201, 0x1deb6a03, 0x420cb372, 0x07201783, 0x4306854d, 0x8b830c59, 0x59093c74, 0x0020250f, 0x67070f4a, 0x2341160b,
  11289. 0x00372105, 0x431c515d, 0x554e17ef, 0x0e5d6b05, 0x41115442, 0xb74a1ac1, 0x2243420a, 0x5b4f878f, 0x7507200f, 0x384b086f, 0x09d45409, 0x0020869a,
  11290. 0x12200082, 0xab460382, 0x10075329, 0x54138346, 0xaf540fbf, 0x1ea75413, 0x9a0c9e54, 0x0f6b44c1, 0x41000021, 0x47412a4f, 0x07374907, 0x5310bf76,
  11291. 0xff2009b4, 0x9a09a64c, 0x8200208d, 0x34c34500, 0x970fe141, 0x1fd74b0f, 0x440a3850, 0x206411f0, 0x27934609, 0x470c5d41, 0x555c2947, 0x1787540f,
  11292. 0x6e0f234e, 0x7d540a1b, 0x1d736b08, 0x0026a088, 0x80000e00, 0x9b5200ff, 0x08ef4318, 0x450bff77, 0x1d4d0b83, 0x081f7006, 0xcb691b86, 0x4b022008,
  11293. 0xc34b0b33, 0x1d0d4a0c, 0x8025a188, 0x0b000000, 0x52a38201, 0xbf7d0873, 0x0c234511, 0x8f0f894a, 0x4101200f, 0x0c880c9d, 0x2b418ea1, 0x06c74128,
  11294. 0x66181341, 0x7b4c0bb9, 0x0c06630b, 0xfe200c87, 0x9ba10882, 0x27091765, 0x01000008, 0x02800380, 0x48113f4e, 0x29430cf5, 0x09a75a0b, 0x31618020,
  11295. 0x6d802009, 0x61840e33, 0x8208bf51, 0x0c637d61, 0x7f092379, 0x4f470f4b, 0x1797510c, 0x46076157, 0xf5500fdf, 0x0f616910, 0x1171fe20, 0x82802006,
  11296. 0x08696908, 0x41127a4c, 0x3f4a15f3, 0x01042607, 0x0200ff00, 0x1cf77700, 0xff204185, 0x00235b8d, 0x43100000, 0x3b22243f, 0x3b4d3f00, 0x0b937709,
  11297. 0xad42f18f, 0x0b1f420f, 0x51084b43, 0x8020104a, 0xb557ff83, 0x052b7f2a, 0x0280ff22, 0x250beb78, 0x00170013, 0xbf6d2500, 0x07db760e, 0x410e2b7f,
  11298. 0x00230e4f, 0x49030000, 0x0582055b, 0x07000326, 0x00000b00, 0x580bcd46, 0x00200cdd, 0x57078749, 0x8749160f, 0x0f994f0a, 0x41134761, 0x01200b31,
  11299. 0xeb796883, 0x0b41500b, 0x0e90b38e, 0x202e7b51, 0x05d95801, 0x41080570, 0x1d530fc9, 0x0b937a0f, 0xaf8eb387, 0xf743b98f, 0x07c74227, 0x80000523,
  11300. 0x0fcb4503, 0x430ca37b, 0x7782077f, 0x8d0a9947, 0x08af4666, 0xeb798020, 0x6459881e, 0xc3740bbf, 0x0feb6f0b, 0x20072748, 0x052b6102, 0x435e0584,
  11301. 0x7d088308, 0x03200afd, 0x92109e41, 0x28aa8210, 0x80001500, 0x80030000, 0x0fdb5805, 0x209f4018, 0xa7418d87, 0x0aa3440f, 0x20314961, 0x073a52ff,
  11302. 0x6108505d, 0x43181051, 0x00223457, 0xe7820500, 0x50028021, 0x81410d33, 0x063d7108, 0xdb41af84, 0x4d888205, 0x00201198, 0x463d835f, 0x152106d7,
  11303. 0x0a355a33, 0x6917614e, 0x75411f4d, 0x184b8b07, 0x1809c344, 0x21091640, 0x0b828000, 0x42808021, 0x26790519, 0x86058605, 0x2428422d, 0x22123b42,
  11304. 0x42000080, 0xf587513b, 0x7813677b, 0xaf4d139f, 0x00ff210c, 0x5e0a1d57, 0x3b421546, 0x01032736, 0x02000380, 0x41180480, 0x2f420f07, 0x0c624807,
  11305. 0x00000025, 0x18000103, 0x83153741, 0x430120c3, 0x042106b2, 0x088d4d00, 0x2f830620, 0x1810434a, 0x18140345, 0x8507fb41, 0x5ee582ea, 0x0023116c,
  11306. 0x8d000600, 0x053b56af, 0xa6554fa2, 0x0d704608, 0x40180d20, 0x47181a43, 0xd37b07ff, 0x0b79500c, 0x420fd745, 0x47450bd9, 0x8471830a, 0x095a777e,
  11307. 0x84137542, 0x82002013, 0x2f401800, 0x0007213b, 0x4405e349, 0x0d550ff3, 0x16254c0c, 0x820ffe4a, 0x0400218a, 0x89066f41, 0x106b414f, 0xc84d0120,
  11308. 0x80802206, 0x0c9a4b03, 0x00100025, 0x68000200, 0x9d8c2473, 0x44134344, 0xf36a0f33, 0x4678860f, 0x1b440a25, 0x41988c0a, 0x80201879, 0x43079b5e,
  11309. 0x4a18080b, 0x0341190b, 0x1259530c, 0x43251552, 0x908205c8, 0x0cac4018, 0x86000421, 0x0e504aa2, 0x0020b891, 0xfb450082, 0x51132014, 0x8f5205f3,
  11310. 0x35052108, 0x8505cb59, 0x0f6d4f70, 0x82150021, 0x29af5047, 0x4f004b24, 0x75795300, 0x1b595709, 0x460b6742, 0xbf4b0f0d, 0x5743870b, 0xcb6d1461,
  11311. 0x08f64505, 0x4e05ab6c, 0x334126c3, 0x0bcb6b0d, 0x1811034d, 0x4111ef4b, 0x814f1ce5, 0x20af8227, 0x07fd7b80, 0x41188e84, 0xef410f33, 0x80802429,
  11312. 0x410d0000, 0xa34205ab, 0x76b7881c, 0xff500b89, 0x0741430f, 0x20086f4a, 0x209d8200, 0x234c18fd, 0x05d4670a, 0x4509af51, 0x9642078d, 0x189e831d,
  11313. 0x7c1cc74b, 0xcd4c07b9, 0x0e7c440f, 0x8b7b0320, 0x21108210, 0xc76c8080, 0x03002106, 0x6b23bf41, 0xc549060b, 0x7946180b, 0x0ff7530f, 0x17ad4618,
  11314. 0x200ecd45, 0x208c83fd, 0x5e0488fe, 0x032009c6, 0x420d044e, 0x0d8f0d7f, 0x00820020, 0x18001021, 0x6d273b45, 0xfd4c0c93, 0xcf451813, 0x0fe5450f,
  11315. 0x5a47c382, 0x820a8b0a, 0x282b4998, 0x410a8b5b, 0x4b232583, 0x54004f00, 0x978f0ce3, 0x500f1944, 0xa95f1709, 0x0280220b, 0x05ba7080, 0xa1530682,
  11316. 0x06324c13, 0x91412582, 0x05536e2c, 0x63431020, 0x0f434706, 0x8c11374c, 0x176143d7, 0x4d0f454c, 0xd3680bed, 0x0bee4d17, 0x212b9a41, 0x0f530a00,
  11317. 0x140d531c, 0x43139143, 0x95610e8d, 0x0f094415, 0x4205fb56, 0x1b4205cf, 0x17015225, 0x5e0c477f, 0xaf6e0aeb, 0x0ff36218, 0x04849a84, 0x0a454218,
  11318. 0x9c430420, 0x23c6822b, 0x04000102, 0x45091b4b, 0xf05f0955, 0x82802007, 0x421c2023, 0x5218282b, 0x7b53173f, 0x0fe7480c, 0x74173b7f, 0x47751317,
  11319. 0x634d1807, 0x0f6f430f, 0x24086547, 0xfc808002, 0x0b3c7f80, 0x10840120, 0x188d1282, 0x20096b43, 0x0fc24403, 0x00260faf, 0x0180000b, 0x3f500280,
  11320. 0x18002019, 0x450b4941, 0xf3530fb9, 0x18002010, 0x8208a551, 0x06234d56, 0xcb58a39b, 0xc3421805, 0x1313461e, 0x0f855018, 0xd34b0120, 0x6cfe2008,
  11321. 0x574f0885, 0x09204114, 0x07000029, 0x00008000, 0x44028002, 0x01420f57, 0x10c95c10, 0x11184c18, 0x80221185, 0x7f421e00, 0x00732240, 0x09cd4977,
  11322. 0x6d0b2b42, 0x4f180f8f, 0x8f5a0bcb, 0x9b0f830f, 0x0fb9411f, 0x230b5756, 0x00fd8080, 0x82060745, 0x000121d5, 0x8e0fb277, 0x4a8d4211, 0x24061c53,
  11323. 0x04000007, 0x12275280, 0x430c954c, 0x80201545, 0x200f764f, 0x20008200, 0x20ce8308, 0x09534f02, 0x660edf64, 0x73731771, 0xe7411807, 0x20a2820c,
  11324. 0x13b64404, 0x8f5d6682, 0x1d6b4508, 0x0cff4d18, 0x3348c58f, 0x0fc34c07, 0x31558b84, 0x8398820f, 0x17514712, 0x240b0e46, 0x80000a00, 0x093b4502,
  11325. 0x420f9759, 0xa54c0bf1, 0x0f2b470c, 0x410d314b, 0x2584170c, 0x73b30020, 0xb55fe782, 0x204d8410, 0x08e043fe, 0x4f147e41, 0x022008ab, 0x4b055159,
  11326. 0x2950068f, 0x00022208, 0x48511880, 0x82002009, 0x00112300, 0x634dff00, 0x24415f27, 0x180f6d43, 0x4d0b5d45, 0x4d5f05ef, 0x01802317, 0x56188000,
  11327. 0xa7840807, 0xc6450220, 0x21ca8229, 0x4b781a00, 0x3359182c, 0x0cf3470f, 0x180bef46, 0x420b0354, 0xff470b07, 0x4515200a, 0x9758239b, 0x4a80200c,
  11328. 0xd2410a26, 0x05fb4a08, 0x4b05e241, 0x03200dc9, 0x92290941, 0x00002829, 0x00010900, 0x5b020001, 0x23201363, 0x460d776a, 0xef530fdb, 0x209a890c,
  11329. 0x13fc4302, 0x00008024, 0xc4820104, 0x08820220, 0x20086b5b, 0x18518700, 0x8408d349, 0x0da449a1, 0x00080024, 0x7b690280, 0x4c438b1a, 0x01220f63,
  11330. 0x4c878000, 0x5c149c53, 0xfb430868, 0x2f56181e, 0x0ccf7b1b, 0x0f075618, 0x2008e347, 0x14144104, 0x00207f83, 0x00207b82, 0x201adf47, 0x16c35a13,
  11331. 0x540fdf47, 0x802006c8, 0x5418f185, 0x29430995, 0x00002419, 0x58001600, 0x5720316f, 0x4d051542, 0x4b7b1b03, 0x138f4707, 0xb747b787, 0x4aab8213,
  11332. 0x058305fc, 0x20115759, 0x82128401, 0x0a0b44e8, 0x46800121, 0xe64210d0, 0x82129312, 0x4bffdffe, 0x3b41171b, 0x9b27870f, 0x808022ff, 0x085c68fe,
  11333. 0x41800021, 0x01410b20, 0x001a213a, 0x47480082, 0x11374e12, 0x56130b4c, 0xdf4b0c65, 0x0b0f590b, 0x0f574c18, 0x830feb4b, 0x075f480f, 0x480b4755,
  11334. 0x40490b73, 0x80012206, 0x09d74280, 0x80fe8022, 0x80210e86, 0x056643ff, 0x10820020, 0x420b2646, 0x0b58391a, 0xd74c1808, 0x078b4e22, 0x2007f55f,
  11335. 0x4b491807, 0x83802017, 0x65aa82a7, 0x3152099e, 0x068b7616, 0x9b431220, 0x09bb742c, 0x500e376c, 0x8342179b, 0x0a4d5d0f, 0x8020a883, 0x180cd349,
  11336. 0x2016bb4b, 0x14476004, 0x84136c43, 0x08cf7813, 0x4f4c0520, 0x156f420f, 0x20085f42, 0x6fd3be03, 0xd4d30803, 0xa7411420, 0x004b222c, 0x0d3b614f,
  11337. 0x3f702120, 0x1393410a, 0x8f132745, 0x47421827, 0x41e08209, 0xb05e2bb9, 0x18b7410c, 0x18082647, 0x4107a748, 0xeb8826bf, 0x0ca76018, 0x733ecb41,
  11338. 0xd0410d83, 0x43ebaf2a, 0x0420067f, 0x721dab4c, 0x472005bb, 0x4105d341, 0x334844cb, 0x20dba408, 0x47d6ac00, 0x034e3aef, 0x0f8f421b, 0x930f134d,
  11339. 0x3521231f, 0xb7421533, 0x42f5ad0a, 0x1e961eaa, 0x17000022, 0x4c367b50, 0x7d491001, 0x0bf5520f, 0x4c18fda7, 0xb8460c55, 0x83fe2005, 0x00fe25b9,
  11340. 0x80000180, 0x9e751085, 0x261b5c12, 0x82110341, 0x001123fb, 0x4518fe80, 0xf38c2753, 0x6d134979, 0x295107a7, 0xaf5f180f, 0x0fe3660c, 0x180b6079,
  11341. 0x2007bd5f, 0x9aab9103, 0x2f4d1811, 0x05002109, 0x44254746, 0x1d200787, 0x450bab75, 0x4f180f57, 0x4f181361, 0x3b831795, 0xeb4b0120, 0x0b734805,
  11342. 0x84078f48, 0x2e1b47bc, 0x00203383, 0xaf065f45, 0x831520d7, 0x130f51a7, 0x1797bf97, 0x2b47d783, 0x18fe2005, 0x4a18a44f, 0xa64d086d, 0x1ab0410d,
  11343. 0x6205a258, 0xdbab069f, 0x4f06f778, 0xa963081d, 0x133b670a, 0x8323d141, 0x13195b23, 0x530f5e70, 0xe5ad0824, 0x58001421, 0x1f472b4b, 0x47bf410c,
  11344. 0x82000121, 0x83fe20cb, 0x07424404, 0x68068243, 0xd7ad0d3d, 0x00010d26, 0x80020000, 0x4a1c6f43, 0x23681081, 0x10a14f13, 0x8a070e57, 0x430a848f,
  11345. 0x7372243e, 0x4397a205, 0xb56c1021, 0x43978f0f, 0x64180505, 0x99aa0ff2, 0x0e000022, 0x20223341, 0x094b4f37, 0x074a3320, 0x2639410a, 0xfe208e84,
  11346. 0x8b0e0048, 0x508020a3, 0x9e4308fe, 0x073f4115, 0xe3480420, 0x0c9b5f1b, 0x7c137743, 0x9a95185b, 0x6122b148, 0x979b08df, 0x0fe36c18, 0x48109358,
  11347. 0x23441375, 0x0ffd5c0b, 0x180fc746, 0x2011d157, 0x07e95702, 0x58180120, 0x18770ac3, 0x51032008, 0x7d4118e3, 0x80802315, 0x3b4c1900, 0xbb5a1830,
  11348. 0x0ceb6109, 0x5b0b3d42, 0x4f181369, 0x4f180b8d, 0x4f180f75, 0x355a1b81, 0x200d820d, 0x18e483fd, 0x4528854f, 0x89420846, 0x1321411f, 0x44086b60,
  11349. 0x07421d77, 0x107d4405, 0x4113fd41, 0x5a181bf1, 0x4f180db3, 0x8021128f, 0x20f68280, 0x44a882fe, 0x334d249a, 0x052f6109, 0x1520c3a7, 0xef4eb783,
  11350. 0x4ec39b1b, 0xc4c90ee7, 0x20060b4d, 0x256f4905, 0x4d0cf761, 0xcf9b1f13, 0xa213d74e, 0x0e1145d4, 0x50135b42, 0xcb4e398f, 0x20d79f27, 0x08865d80,
  11351. 0x186d5018, 0xa90f7142, 0x067342d7, 0x3f450420, 0x65002021, 0xe3560771, 0x24d38f23, 0x15333531, 0x0eb94d01, 0x451c9f41, 0x384322fb, 0x00092108,
  11352. 0x19af6b18, 0x6e0c6f5a, 0xbd770bfb, 0x22bb7718, 0x20090f57, 0x25e74204, 0x4207275a, 0xdb5408ef, 0x1769450f, 0x1b1b5518, 0x210b1f57, 0x5e4c8001,
  11353. 0x55012006, 0x802107f1, 0x0a306a80, 0x45808021, 0x0d850b88, 0x31744f18, 0x1808ec54, 0x2009575b, 0x45ffa505, 0x1b420c73, 0x180f9f0f, 0x4a0cf748,
  11354. 0x501805b2, 0x00210f40, 0x4d118f80, 0xd6823359, 0x072b5118, 0x314ad7aa, 0x8fc79f08, 0x45d78b1f, 0xfe20058f, 0x23325118, 0x7b54d9b5, 0x9fc38f46,
  11355. 0x10bb410f, 0x41077b42, 0xc1410faf, 0x27cf441d, 0x46051b4f, 0x04200683, 0x2121d344, 0x8f530043, 0x8fcf9f0e, 0x21df8c1f, 0x50188000, 0x5d180e52,
  11356. 0xfd201710, 0x4405c341, 0xd68528e3, 0x20071f6b, 0x1b734305, 0x6b080957, 0x7d422b1f, 0x67002006, 0x7f8317b1, 0x2024cb48, 0x08676e00, 0x8749a39b,
  11357. 0x18132006, 0x410a6370, 0x8f490b47, 0x7e1f8f13, 0x551805c3, 0x4c180915, 0xfe200e2f, 0x244d5d18, 0x270bcf44, 0xff000019, 0x04800380, 0x5f253342,
  11358. 0xff520df7, 0x13274c18, 0x5542dd93, 0x0776181b, 0xf94a1808, 0x084a4c0c, 0x4308ea5b, 0xde831150, 0x7900fd21, 0x00492c1e, 0x060f4510, 0x17410020,
  11359. 0x0ce74526, 0x6206b341, 0x1f561083, 0x9d6c181b, 0x08a0500e, 0x112e4118, 0x60000421, 0xbf901202, 0x4408e241, 0xc7ab0513, 0xb40f0950, 0x055943c7,
  11360. 0x4f18ff20, 0xc9ae1cad, 0x32b34f18, 0x7a180120, 0x3d520a05, 0x53d1b40a, 0x80200813, 0x1b815018, 0x832bf86f, 0x67731847, 0x297f4308, 0x6418d54e,
  11361. 0x734213f7, 0x056b4b27, 0xdba5fe20, 0x1828aa4e, 0x2031a370, 0x06cb6101, 0x2040ad41, 0x07365300, 0x2558d985, 0x83fe200c, 0x0380211c, 0x542c4743,
  11362. 0x052006b7, 0x6021df45, 0x897b0707, 0x18d3c010, 0x20090e70, 0x1d5843ff, 0x540a0e44, 0x002126c5, 0x322f7416, 0x636a5720, 0x0f317409, 0x610fe159,
  11363. 0x294617e7, 0x08555213, 0x2006a75d, 0x6cec84fd, 0xfb5907be, 0x3a317405, 0x83808021, 0x180f20ea, 0x4626434a, 0x531818e3, 0xdb59172d, 0x0cbb460c,
  11364. 0x2013d859, 0x18b94502, 0x8f46188d, 0x77521842, 0x0a184e38, 0x9585fd20, 0x6a180684, 0xc64507e9, 0x51cbb230, 0xd3440cf3, 0x17ff6a0f, 0x450f5b42,
  11365. 0x276407c1, 0x4853180a, 0x21ccb010, 0xcf580013, 0x0c15442d, 0x410a1144, 0x1144359d, 0x5cfe2006, 0xa1410a43, 0x2bb64519, 0x2f5b7618, 0xb512b745,
  11366. 0x0cfd6fd1, 0x42089f59, 0xb8450c70, 0x0000232d, 0x50180900, 0xb9491ae3, 0x0fc37610, 0x01210f83, 0x0f3b4100, 0xa01b2742, 0x0ccd426f, 0x6e8f6f94,
  11367. 0x9c808021, 0xc7511870, 0x17c74b08, 0x9b147542, 0x44fe2079, 0xd5480c7e, 0x95ef861d, 0x101b597b, 0xf5417594, 0x9f471808, 0x86868d0e, 0x3733491c,
  11368. 0x690f4d6d, 0x43440b83, 0x1ba94c0b, 0x660cd16b, 0x802008ae, 0x74126448, 0xcb4f38a3, 0x2cb74b0b, 0x47137755, 0xe3971777, 0x1b5d0120, 0x057a4108,
  11369. 0x6e08664d, 0x17421478, 0x11af4208, 0x850c3f42, 0x08234f0c, 0x4321eb4a, 0xf3451095, 0x0f394e0f, 0x4310eb45, 0xc09707b1, 0x54431782, 0xaec08d1d,
  11370. 0x0f434dbb, 0x9f0c0b45, 0x0a3b4dbb, 0x4618bdc7, 0x536032eb, 0x17354213, 0x4d134169, 0xc7a30c2f, 0x4e254342, 0x174332cf, 0x43cdae17, 0x6b4706e4,
  11371. 0x0e16430d, 0x530b5542, 0x2f7c26bb, 0x13075f31, 0x43175342, 0x60181317, 0x6550114e, 0x28624710, 0x58070021, 0x59181683, 0x2d540cf5, 0x05d5660c,
  11372. 0x20090c7b, 0x0e157e02, 0x8000ff2b, 0x14000080, 0x80ff8000, 0x27137e03, 0x336a4b20, 0x0f817107, 0x13876e18, 0x730f2f7e, 0x2f450b75, 0x6d02200b,
  11373. 0x6d66094c, 0x4b802009, 0x15820a02, 0x2f45fe20, 0x5e032006, 0x00202fd9, 0x450af741, 0xeb412e0f, 0x0ff3411f, 0x420a8b65, 0xf7410eae, 0x1c664810,
  11374. 0x540e1145, 0xbfa509f3, 0x42302f58, 0x80200c35, 0xcb066c47, 0x4b1120c1, 0x41492abb, 0x34854110, 0xa7097b72, 0x251545c7, 0x4b2c7f56, 0xc5b40bab,
  11375. 0x940cd54e, 0x2e6151c8, 0x09f35f18, 0x4b420420, 0x09677121, 0x8f24f357, 0x1b5418e1, 0x08915a1f, 0x3143d894, 0x22541805, 0x1b9b4b0e, 0x8c0d3443,
  11376. 0x1400240d, 0x18ff8000, 0x582e6387, 0xf99b2b3b, 0x8807a550, 0x17a14790, 0x2184fd20, 0x5758fe20, 0x2354882c, 0x15000080, 0x5e056751, 0x334c2c2f,
  11377. 0x97c58f0c, 0x1fd7410f, 0x0d4d4018, 0x4114dc41, 0x04470ed6, 0x0dd54128, 0x00820020, 0x02011523, 0x22008700, 0x86480024, 0x0001240a, 0x8682001a,
  11378. 0x0002240b, 0x866c000e, 0x8a03200b, 0x8a042017, 0x0005220b, 0x22218614, 0x84060000, 0x86012017, 0x8212200f, 0x250b8519, 0x000d0001, 0x0b850031,
  11379. 0x07000224, 0x0b862600, 0x11000324, 0x0b862d00, 0x238a0420, 0x0a000524, 0x17863e00, 0x17840620, 0x01000324, 0x57820904, 0x0b85a783, 0x0b85a785,
  11380. 0x0b85a785, 0x22000325, 0x85007a00, 0x85a7850b, 0x85a7850b, 0x22a7850b, 0x82300032, 0x00342201, 0x0805862f, 0x35003131, 0x54207962, 0x74736972,
  11381. 0x47206e61, 0x6d6d6972, 0x65527265, 0x616c7567, 0x58545472, 0x6f725020, 0x43796767, 0x6e61656c, 0x30325454, 0x822f3430, 0x35313502, 0x79006200,
  11382. 0x54002000, 0x69007200, 0x74007300, 0x6e006100, 0x47200f82, 0x6d240f84, 0x65006d00, 0x52200982, 0x67240582, 0x6c007500, 0x72201d82, 0x54222b82,
  11383. 0x23825800, 0x19825020, 0x67006f22, 0x79220182, 0x1b824300, 0x3b846520, 0x1f825420, 0x41000021, 0x1422099b, 0x0b410000, 0x87088206, 0x01012102,
  11384. 0x78080982, 0x01020101, 0x01040103, 0x01060105, 0x01080107, 0x010a0109, 0x010c010b, 0x010e010d, 0x0110010f, 0x01120111, 0x01140113, 0x01160115,
  11385. 0x01180117, 0x011a0119, 0x011c011b, 0x011e011d, 0x0020011f, 0x00040003, 0x00060005, 0x00080007, 0x000a0009, 0x000c000b, 0x000e000d, 0x0010000f,
  11386. 0x00120011, 0x00140013, 0x00160015, 0x00180017, 0x001a0019, 0x001c001b, 0x001e001d, 0x08bb821f, 0x22002142, 0x24002300, 0x26002500, 0x28002700,
  11387. 0x2a002900, 0x2c002b00, 0x2e002d00, 0x30002f00, 0x32003100, 0x34003300, 0x36003500, 0x38003700, 0x3a003900, 0x3c003b00, 0x3e003d00, 0x40003f00,
  11388. 0x42004100, 0x4b09f382, 0x00450044, 0x00470046, 0x00490048, 0x004b004a, 0x004d004c, 0x004f004e, 0x00510050, 0x00530052, 0x00550054, 0x00570056,
  11389. 0x00590058, 0x005b005a, 0x005d005c, 0x005f005e, 0x01610060, 0x01220121, 0x01240123, 0x01260125, 0x01280127, 0x012a0129, 0x012c012b, 0x012e012d,
  11390. 0x0130012f, 0x01320131, 0x01340133, 0x01360135, 0x01380137, 0x013a0139, 0x013c013b, 0x013e013d, 0x0140013f, 0x00ac0041, 0x008400a3, 0x00bd0085,
  11391. 0x00e80096, 0x008e0086, 0x009d008b, 0x00a400a9, 0x008a00ef, 0x008300da, 0x00f20093, 0x008d00f3, 0x00880097, 0x00de00c3, 0x009e00f1, 0x00f500aa,
  11392. 0x00f600f4, 0x00ad00a2, 0x00c700c9, 0x006200ae, 0x00900063, 0x00cb0064, 0x00c80065, 0x00cf00ca, 0x00cd00cc, 0x00e900ce, 0x00d30066, 0x00d100d0,
  11393. 0x006700af, 0x009100f0, 0x00d400d6, 0x006800d5, 0x00ed00eb, 0x006a0089, 0x006b0069, 0x006c006d, 0x00a0006e, 0x0071006f, 0x00720070, 0x00750073,
  11394. 0x00760074, 0x00ea0077, 0x007a0078, 0x007b0079, 0x007c007d, 0x00a100b8, 0x007e007f, 0x00810080, 0x00ee00ec, 0x6e750eba, 0x646f6369, 0x78302365,
  11395. 0x31303030, 0x32200e8d, 0x33200e8d, 0x34200e8d, 0x35200e8d, 0x36200e8d, 0x37200e8d, 0x38200e8d, 0x39200e8d, 0x61200e8d, 0x62200e8d, 0x63200e8d,
  11396. 0x64200e8d, 0x65200e8d, 0x66200e8d, 0x31210e8c, 0x8d0e8d30, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef,
  11397. 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x66312def, 0x6c656406, 0x04657465, 0x6f727545, 0x3820ec8c, 0x3820ec8d,
  11398. 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d,
  11399. 0x3820ec8d, 0x200ddc41, 0x0ddc4139, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920,
  11400. 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0x00663923, 0x48fa0500, 0x00f762f9,
  11401. };
  11402. static void GetDefaultCompressedFontDataTTF(const void** ttf_compressed_data, unsigned int* ttf_compressed_size)
  11403. {
  11404. *ttf_compressed_data = proggy_clean_ttf_compressed_data;
  11405. *ttf_compressed_size = proggy_clean_ttf_compressed_size;
  11406. }
  11407. //-----------------------------------------------------------------------------
  11408. //---- Include imgui_user.inl at the end of imgui.cpp
  11409. //---- So you can include code that extends ImGui using its private data/functions.
  11410. #ifdef IMGUI_INCLUDE_IMGUI_USER_INL
  11411. #include "imgui_user.inl"
  11412. #endif
  11413. //-----------------------------------------------------------------------------