@@ -245,7 +245,7 @@ namespace ECS::Util
245245
246246 if (textTemplate.setFlags .wrapWidth )
247247 {
248- textComp.text = GenWrapText (textComp.rawText , font, textTemplate.size , textTemplate.borderSize , textTemplate.wrapWidth );
248+ textComp.text = GenWrapText (textComp.rawText , font, textTemplate.size , textTemplate.borderSize , textTemplate.wrapWidth , textTemplate. wrapIndent );
249249 }
250250
251251 vec2 textSize = font->CalculateTextSize (textComp.text .c_str (), textTemplate.size , textTemplate.borderSize );
@@ -339,6 +339,8 @@ namespace ECS::Util
339339 }
340340 }
341341
342+ uiSingleton.justFocusedEntity = uiSingleton.focusedEntity ;
343+
342344 entt::entity oldFocus = uiSingleton.focusedEntity ;
343345 if (oldFocus != entt::null)
344346 {
@@ -395,7 +397,7 @@ namespace ECS::Util
395397
396398 if (textTemplate.setFlags .wrapWidth )
397399 {
398- textComponent.text = GenWrapText (textComponent.rawText , font, textTemplate.size , textTemplate.borderSize , textTemplate.wrapWidth );
400+ textComponent.text = GenWrapText (textComponent.rawText , font, textTemplate.size , textTemplate.borderSize , textTemplate.wrapWidth , textTemplate. wrapIndent );
399401 }
400402
401403 textComponent.sizeChanged |= oldLength != textComponent.text .size ();
@@ -439,6 +441,25 @@ namespace ECS::Util
439441 registry->emplace_or_replace <ECS::Components::UI::DirtyCanvasTag>(widget.scriptWidget ->canvasEntity );
440442 }
441443
444+ void RefreshClipper (entt::registry* registry, entt::entity entity)
445+ {
446+ auto * clipper = registry->try_get <ECS::Components::UI::Clipper>(entity);
447+
448+ if (clipper == nullptr )
449+ return ;
450+
451+ if (clipper->clipRegionOverrideEntity == entt::null)
452+ {
453+ registry->emplace_or_replace <ECS::Components::UI::DirtyWidgetClipper>(entity);
454+ registry->emplace_or_replace <ECS::Components::UI::DirtyChildClipper>(entity);
455+ }
456+ else
457+ {
458+ registry->emplace_or_replace <ECS::Components::UI::DirtyWidgetClipper>(clipper->clipRegionOverrideEntity );
459+ registry->emplace_or_replace <ECS::Components::UI::DirtyChildClipper>(clipper->clipRegionOverrideEntity );
460+ }
461+ }
462+
442463 void ResetTemplate (entt::registry* registry, entt::entity entity)
443464 {
444465 auto & ctx = registry->ctx ();
@@ -614,25 +635,34 @@ namespace ECS::Util
614635 uiHandler->CallUIInputEvent (state, eventRef, inputEvent, widget, value);
615636 }
616637
617- void CallKeyboardEvent (i32 eventRef, Scripting::UI::Widget* widget, i32 key, i32 actionMask, i32 modifierMask)
638+ bool CallKeyboardEvent (i32 eventRef, Scripting::UI::Widget* widget, i32 key, i32 actionMask, i32 modifierMask)
618639 {
619640 Scripting::LuaManager* luaManager = ServiceLocator::GetLuaManager ();
620641 lua_State* state = luaManager->GetInternalState ();
621642
622643 Scripting::UI::UIHandler* uiHandler = luaManager->GetLuaHandler <Scripting::UI::UIHandler*>(Scripting::LuaHandlerType::UI);
623- uiHandler->CallKeyboardInputEvent (state, eventRef, widget, key, actionMask, modifierMask);
644+ return uiHandler->CallKeyboardInputEvent (state, eventRef, widget, key, actionMask, modifierMask);
624645 }
625646
626- void CallUnicodeEvent (i32 eventRef, Scripting::UI::Widget* widget, u32 unicode )
647+ bool CallKeyboardEvent (i32 eventRef, i32 key, i32 actionMask, i32 modifierMask )
627648 {
628649 Scripting::LuaManager* luaManager = ServiceLocator::GetLuaManager ();
629650 lua_State* state = luaManager->GetInternalState ();
630651
631652 Scripting::UI::UIHandler* uiHandler = luaManager->GetLuaHandler <Scripting::UI::UIHandler*>(Scripting::LuaHandlerType::UI);
632- uiHandler->CallKeyboardUnicodeEvent (state, eventRef, widget, unicode);
653+ return uiHandler->CallKeyboardInputEvent (state, eventRef, key, actionMask, modifierMask);
654+ }
655+
656+ bool CallUnicodeEvent (i32 eventRef, Scripting::UI::Widget* widget, u32 unicode)
657+ {
658+ Scripting::LuaManager* luaManager = ServiceLocator::GetLuaManager ();
659+ lua_State* state = luaManager->GetInternalState ();
660+
661+ Scripting::UI::UIHandler* uiHandler = luaManager->GetLuaHandler <Scripting::UI::UIHandler*>(Scripting::LuaHandlerType::UI);
662+ return uiHandler->CallKeyboardUnicodeEvent (state, eventRef, widget, unicode);
633663 }
634664
635- std::string GenWrapText (const std::string& text, Renderer::Font* font, f32 fontSize, f32 borderSize, f32 maxWidth)
665+ std::string GenWrapText (const std::string& text, Renderer::Font* font, f32 fontSize, f32 borderSize, f32 maxWidth, u8 indents )
636666 {
637667 // Early exit if entire text fits within maxWidth
638668 f32 totalWidth = 0 ;
@@ -658,6 +688,8 @@ namespace ECS::Util
658688 std::string buffer; // Batch write buffer
659689 buffer.reserve (text.size () + text.size () / 4 ); // Reserve for buffer to minimize reallocations
660690
691+ f32 indentWidth = font->CalculateCharWidth (' ' , fontSize, borderSize);
692+
661693 for (size_t i = 0 ; i < text.length (); ++i)
662694 {
663695 char c = text[i];
@@ -669,10 +701,17 @@ namespace ECS::Util
669701 {
670702 size_t wordLength = i - wordStart;
671703
704+ // Line is longer than maxWidth, wrap it
672705 if (currentLineWidth + currentWordWidth > maxWidth)
673706 {
674707 buffer += ' \n ' ;
675708 currentLineWidth = 0 ;
709+
710+ for (u8 j = 0 ; j < indents; ++j)
711+ {
712+ buffer += ' ' ; // Add indentation
713+ currentLineWidth += indentWidth;
714+ }
676715 }
677716
678717 buffer.append (text, wordStart, wordLength);
@@ -681,12 +720,18 @@ namespace ECS::Util
681720 if (c == ' ' )
682721 {
683722 buffer += ' ' ;
684- currentLineWidth += font-> CalculateCharWidth (c, fontSize, borderSize) ;
723+ currentLineWidth += indentWidth ;
685724 }
686725 else // Newline
687726 {
688727 buffer += ' \n ' ;
689728 currentLineWidth = 0 ;
729+
730+ for (u8 j = 0 ; j < indents; ++j)
731+ {
732+ buffer += ' ' ; // Add indentation
733+ currentLineWidth += indentWidth;
734+ }
690735 }
691736
692737 wordStart = i + 1 ;
@@ -697,23 +742,34 @@ namespace ECS::Util
697742 currentWordWidth += font->CalculateCharWidth (c, fontSize, borderSize);
698743
699744 // Force break for long words
700- if (currentWordWidth > maxWidth)
745+ if (currentLineWidth + currentWordWidth > maxWidth)
701746 {
702747 buffer.append (text, wordStart, i - wordStart);
703748 buffer += ' \n ' ;
704749 wordStart = i;
705750 currentWordWidth = font->CalculateCharWidth (c, fontSize, borderSize);
706751 currentLineWidth = currentWordWidth;
752+
753+ for (u8 j = 0 ; j < indents; ++j)
754+ {
755+ buffer += ' ' ; // Add indentation
756+ currentLineWidth += indentWidth;
757+ }
707758 }
708759 }
709760 }
710761
711- // Handle the last word
762+ // Handle the last word if we are force breaking
712763 if (wordStart < text.length ())
713764 {
714765 if (currentLineWidth + currentWordWidth > maxWidth)
715766 {
716767 buffer += ' \n ' ;
768+
769+ for (u8 j = 0 ; j < indents; ++j)
770+ {
771+ buffer += ' ' ; // Add indentation
772+ }
717773 }
718774 buffer.append (text, wordStart, text.length () - wordStart);
719775 }
0 commit comments