RichText Razor Panels
Carson Kompon Carson Kompon Library update 9mo ago

RichText Razor Panels

Adds a <RichText/> element which can parse text into custom Razor Panels

favorite3favorites
thumb_up4upvotes
hard_drive 0 MB folder 8 files build Engine v22 history Last update 288d ago
open_in_new View on sbox.game

About This Package

What is this?

This adds a custom <RichText Text=""/> UI element which can be given text which will be parsed into custom UI panels. You can define as many custom panel types as you want and they can be as simple as adding asterisks for italics or as complex as URLs automatically becoming an embedded WebPanel.

How do I use it?

First you need to create your own razor panel that includes the [RichTextPanel] attribute. It can take either a single regex pattern as an argument, or the start and end strings which it will use to form a proper regex pattern.
@attribute [RichTextPanel("**", "**")]

<root>
</root>

<style>
    label {
        font-weight: 800;
    }
</style>
The text will be added to this panel as a child Label, so you can style it however you want from here, and even pre-include children in the root.

However, if you find yourself wanting more control than just styling the text, you can implement IRichTextPanel and it's ParseRichText() function.
Here's an example that allows you to do <i>item_resource_name<i> in RichText and have it display an item's icon and name
@attribute [RichTextPanel( @"<i>(.+?)</i>" )]
@implements IRichTextPanel

<root>
	@if ( Item is null ) return;
	<img src=@Item.Icon />
	<label>@Item.Name</label>
</root>

@code
{
	ItemResource Item;
	public void ParseRichText ( string text )
	{
		Item = ResourceLibrary.GetAll<ItemResource>().FirstOrDefault(x => x.ResourceName == text);
	}

	protected override int BuildHash () => Item.GetHashCode();
}
Then when you're ready to use the RichText element itself, you just do the following:
<RichText Text="**You have unlocked** the <i>wooden_sword</i>!" />

How do I get the examples from the picture???

You can find the example project here!

Media (2)

No usage statistics available
This package may be new or not widely used yet. Usage data becomes available as more users install and play with the package.
Package ID: carsonk.richtextpanels
Created: 2025-09-24 17:16 UTC
Updated: 2025-09-25 15:26 UTC
Type: library
Public: Yes
Version: 119218
files: 8
Size: 0.0 MB
Engine Version: 22
Asset Version ID: 119218
Version Created: 2025-09-25 15:26 UTC
Hash: 3649433941004024318
Manifest: Open manifest
Compiler: Sandbox, SANDBOX;ADDON;DEBUG, 1701;1702;1591;, , , , Debug, Array, Array, Array, Array
Resources:
Code Package References:
new_releases Latest Update Sep 25, 2025
Priority and CSS Fixes
tag v119218 folder 8 files hard_drive 0.0 MB build Engine v22
119218 Sep 25, 2025
Priority and CSS Fixes
folder 8 files hard_drive 10.19 KB build Engine v22
119175 Sep 24, 2025
Capture Regex Wrappers
folder 8 files hard_drive 10.02 KB build Engine v22
119173 Sep 24, 2025
Fix regex capturing
folder 8 files hard_drive 9.89 KB build Engine v22
119149 Sep 24, 2025
Changes on 2025-09-24
folder 8 files hard_drive 8.93 KB build Engine v22