Skip to content

add constructor for default font#529

Merged
brandmooffin merged 2 commits intodevfrom
update/cclabel-default-font-constructor
Feb 17, 2026
Merged

add constructor for default font#529
brandmooffin merged 2 commits intodevfrom
update/cclabel-default-font-constructor

Conversation

@brandmooffin
Copy link
Owner

@brandmooffin brandmooffin commented Feb 17, 2026

Summary by CodeRabbit

  • New Features
    • Streamlined label creation with text and font size initialization support.
    • Ensured consistent default font rendering when font is unspecified.

Copilot AI review requested due to automatic review settings February 17, 2026 20:26
@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

Warning

Rate limit exceeded

@brandmooffin has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 19 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

A new public constructor for the CCLabel class was introduced to simplify label creation with text and font size parameters using Arial as the default font. Additionally, the SystemFont getter now returns "Arial" as a fallback when no font name is set.

Changes

Cohort / File(s) Summary
Label Constructor Enhancement
cocos2d/label_nodes/CCLabel.cs
Added convenience constructor CCLabel(string text, float fontSize) with Arial font defaults. Modified SystemFont getter to return "Arial" when m_FontName is null, providing a sensible fallback.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A label born with text so bright,
Arial font, a cozy sight,
Constructor simple, clean, and true,
With defaults set, there's much less to do! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new constructor for CCLabel that uses a default font (Arial).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch update/cclabel-default-font-constructor

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
cocos2d/label_nodes/CCLabel.cs (2)

43-55: SystemFont getter fallback doesn't protect internal usages of m_FontName.

The ?? "Arial" fallback only applies when external code reads SystemFont. Internally, m_FontName is used directly in Draw() (Line 365, 371), Text setter (Line 89), SystemFontSize setter (Line 63), and SystemFontSpacing setter (Line 76) — all of which will still see null if no font was explicitly set (e.g., via the parameterless constructor).

Consider using the property SystemFont in those internal call sites, or assigning the default in the field initializer:

Option A: Default at field level
-        protected string m_FontName;
+        protected string m_FontName = "Arial";

This would make the getter fallback unnecessary and ensure consistent behavior everywhere.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cocos2d/label_nodes/CCLabel.cs` around lines 43 - 55, The SystemFont getter's
"?? 'Arial'" fallback doesn't protect internal code that accesses m_FontName
directly (used in Draw(), the Text setter, SystemFontSize setter, and
SystemFontSpacing setter), so either initialize m_FontName with the default
("Arial") at declaration or change all internal usages to read the SystemFont
property instead of m_FontName; update calls that pass m_FontName into
InitializeFont (and any places that set m_pConfiguration/m_bFontDirty) to use
SystemFont so the default is consistently applied across Draw(), Text,
SystemFontSize and SystemFontSpacing.

126-129: Consider extracting the default font name to a constant.

"Arial" appears as a magic string here and in the SystemFont getter (Line 45). A shared constant would keep them in sync and make the default easy to change later.

Suggested refactor
+        private const string DefaultFont = "Arial";
+
-        public CCLabel(string text, float fontSize) :
-            this(text, "Arial", fontSize, CCSize.Zero, CCTextAlignment.Left, CCVerticalTextAlignment.Top)
+        public CCLabel(string text, float fontSize) :
+            this(text, DefaultFont, fontSize, CCSize.Zero, CCTextAlignment.Left, CCVerticalTextAlignment.Top)
         {
         }

And update the getter:

-            get { return m_FontName ?? "Arial"; }
+            get { return m_FontName ?? DefaultFont; }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cocos2d/label_nodes/CCLabel.cs` around lines 126 - 129, Extract the magic
font name into a shared constant: add a new constant (e.g., DEFAULT_FONT_NAME)
and replace the literal "Arial" in the CCLabel constructor (public
CCLabel(string text, float fontSize)) and in the SystemFont getter with that
constant so both use the same default and are easy to change later; ensure the
constant is declared close to CCLabel (static readonly or const) and referenced
where the default font name is currently hard-coded.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cocos2d/label_nodes/CCLabel.cs`:
- Around line 43-55: The SystemFont getter's "?? 'Arial'" fallback doesn't
protect internal code that accesses m_FontName directly (used in Draw(), the
Text setter, SystemFontSize setter, and SystemFontSpacing setter), so either
initialize m_FontName with the default ("Arial") at declaration or change all
internal usages to read the SystemFont property instead of m_FontName; update
calls that pass m_FontName into InitializeFont (and any places that set
m_pConfiguration/m_bFontDirty) to use SystemFont so the default is consistently
applied across Draw(), Text, SystemFontSize and SystemFontSpacing.
- Around line 126-129: Extract the magic font name into a shared constant: add a
new constant (e.g., DEFAULT_FONT_NAME) and replace the literal "Arial" in the
CCLabel constructor (public CCLabel(string text, float fontSize)) and in the
SystemFont getter with that constant so both use the same default and are easy
to change later; ensure the constant is declared close to CCLabel (static
readonly or const) and referenced where the default font name is currently
hard-coded.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a convenience constructor to the CCLabel class that accepts only text and font size parameters, defaulting the font name to "Arial". It also updates the SystemFont property getter to provide a default value of "Arial" when the internal font name field is null.

Changes:

  • Added a new constructor CCLabel(string text, float fontSize) that defaults to Arial font
  • Modified the SystemFont property getter to return "Arial" when m_FontName is null

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@brandmooffin brandmooffin merged commit ce99fb6 into dev Feb 17, 2026
19 checks passed
@brandmooffin brandmooffin deleted the update/cclabel-default-font-constructor branch February 17, 2026 20:44
@coderabbitai coderabbitai bot mentioned this pull request Feb 21, 2026
brandmooffin added a commit that referenced this pull request Feb 21, 2026
* license update

* Update LICENSE

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update LICENSE

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* add directory build props for centralizing MG version

* Update/ttf font improvements (#512)

* add new cclabel test

* update autosize test

* add custom font

* adjust spacing for line height for vertical alignment space

* add more custom fonts for testing

* adjust label texture scaling to ignore adjusting fontsize

* clean up and add height padding prop

* Update/support runactions (#514)

* add support for RunActions

* better support for CCRepeat for CCSprite

* better check for sequence actions and return

* Fix tag propagation inconsistency in RepeatForever overloads (#515)

* Initial plan

* Fix tag handling inconsistency in RepeatForever overloads

Co-authored-by: brandmooffin <1774581+brandmooffin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: brandmooffin <1774581+brandmooffin@users.noreply.github.com>

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: brandmooffin <1774581+brandmooffin@users.noreply.github.com>

* add size prop for ccnode (#521)

* add size prop for ccnode

* update prop summary

* add constructor for default font (#529)

* add constructor for default font

* move font default

* Add CCGameView embeddable view support (#522)

* Initial plan

* Add CCGameView embeddable view support similar to CocosSharp

Co-authored-by: brandmooffin <1774581+brandmooffin@users.noreply.github.com>

* Address code review feedback for CCGameView implementation

Co-authored-by: brandmooffin <1774581+brandmooffin@users.noreply.github.com>

* Fix Android and iOS build errors by removing deprecated OpenTK types

Co-authored-by: brandmooffin <1774581+brandmooffin@users.noreply.github.com>

* Fix Matrix type ambiguity for Android build by adding explicit using alias

Co-authored-by: brandmooffin <1774581+brandmooffin@users.noreply.github.com>

* Fix Matrix type conflict by using fully qualified Microsoft.Xna.Framework.Matrix

Co-authored-by: brandmooffin <1774581+brandmooffin@users.noreply.github.com>

* improvements for support CCGameView

* add support for multiple views (#528)

* add support for multiple views

* changes from review comments

* adjustments from latest review

* Address review comments: add thread safety for secondary views, call RemoveExistingView, document CCDrawManagerState limitations

Co-authored-by: brandmooffin <1774581+brandmooffin@users.noreply.github.com>

* add embedded view tests

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: brandmooffin <1774581+brandmooffin@users.noreply.github.com>
Co-authored-by: brandmooffin <brandmooffin@outlook.com>

* bump version for release

* update release notes

* fixes from code review

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: brandmooffin <1774581+brandmooffin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants