Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kayak UI 0.11
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Bevy Forks
Kayak UI 0.11
Commits
9c2e7fa0
Commit
9c2e7fa0
authored
3 years ago
by
MrGVSV
Browse files
Options
Downloads
Patches
Plain Diff
Documented FontMapping
parent
99a753b5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bevy_kayak_ui/src/render/unified/font/font_mapping.rs
+32
-0
32 additions, 0 deletions
bevy_kayak_ui/src/render/unified/font/font_mapping.rs
with
32 additions
and
0 deletions
bevy_kayak_ui/src/render/unified/font/font_mapping.rs
+
32
−
0
View file @
9c2e7fa0
...
...
@@ -6,6 +6,35 @@ use kayak_font::KayakFont;
use
crate
::
BevyContext
;
/// A resource used to manage fonts for use in a `KayakContext`
///
/// # Example
///
/// ```
/// use bevy::prelude::*;
/// use bevy_kayak_ui::FontMapping;
///
/// fn setup_ui(
/// # mut commands: Commands,
/// asset_server: Res<AssetServer>,
/// mut font_mapping: ResMut<FontMapping>
/// ) {
/// # commands.spawn_bundle(UICameraBundle::new());
/// #
/// font_mapping.add("Roboto", asset_server.load("roboto.kayak_font"));
/// // ...
/// #
/// # let context = BevyContext::new(|context| {
/// # render! {
/// # <App>
/// # <Text content={"Hello World!".to_string()} />
/// # </App>
/// # }
/// # });
/// #
/// # commands.insert_resource(context);
/// }
/// ```
pub
struct
FontMapping
{
font_ids
:
HashMap
<
Handle
<
KayakFont
>
,
String
>
,
font_handles
:
HashMap
<
String
,
Handle
<
KayakFont
>>
,
...
...
@@ -23,6 +52,7 @@ impl Default for FontMapping {
}
impl
FontMapping
{
/// Add a `KayakFont` to be tracked
pub
fn
add
(
&
mut
self
,
key
:
impl
Into
<
String
>
,
handle
:
Handle
<
KayakFont
>
)
{
let
key
=
key
.into
();
if
!
self
.font_ids
.contains_key
(
&
handle
)
{
...
...
@@ -37,12 +67,14 @@ impl FontMapping {
.extend
(
self
.font_handles
.keys
()
.map
(|
key
|
key
.clone
()));
}
/// Get the handle for the given font name
pub
fn
get_handle
(
&
self
,
id
:
String
)
->
Option
<
Handle
<
KayakFont
>>
{
self
.font_handles
.get
(
&
id
)
.and_then
(|
item
|
Some
(
item
.clone
()))
}
/// Get the font name for the given handle
pub
fn
get
(
&
self
,
font
:
&
Handle
<
KayakFont
>
)
->
Option
<
String
>
{
self
.font_ids
.get
(
font
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment