pub struct Font {
pub handle: HFONT,
}
Expand description
Represent a system font.
Can be used with any controls that draws text. Due to the very limited way win32 can draw text, only family, size and weight can be configured.
Example:
use native_windows_gui as nwg;
fn build_font() -> nwg::Font {
let mut font = nwg::Font::default();
nwg::Font::builder()
.size(16)
.family("Arial")
.weight(1000)
.build(&mut font);
font
}
Fields§
§handle: HFONT
Implementations§
Source§impl Font
impl Font
pub fn builder<'a>() -> FontBuilder<'a>
Sourcepub fn set_global_default(font: Option<Font>) -> Option<Font>
pub fn set_global_default(font: Option<Font>) -> Option<Font>
Set the default (application global!) font that will be used when creating controls and return the old one
Sourcepub fn set_global_family(family: &str) -> Result<Option<Font>, NwgError>
pub fn set_global_family(family: &str) -> Result<Option<Font>, NwgError>
Set the default (application global!) font that will be used when creating controls
This is a shortcut over Font::set_global_default
Examples found in repository?
More examples
Sourcepub fn global_default() -> Option<Font>
pub fn global_default() -> Option<Font>
Return the default font that was previously set using Font::set_default
Sourcepub fn add_font(path: &str) -> bool
pub fn add_font(path: &str) -> bool
Add a font to the system font table. Don’t forget to call Font::remove_font(path)
once you’re done.
Returns false
if the font could not be added. Windows won’t tell you why though.
Other info:
- The value of
path
can be attf
or aotf
font. - Adding the same font multiple time increase the internal refcount
- Use
Font::families()
to return the available system font families
Sourcepub fn remove_font(path: &str)
pub fn remove_font(path: &str)
Remove a font that was previously added by Font::add_font
Sourcepub fn add_memory_font(bin: &mut [u8]) -> Result<MemFont, ()>
pub fn add_memory_font(bin: &mut [u8]) -> Result<MemFont, ()>
Add a font resource from a binary source. Returns a memory font handle if the font was loaded succesfully.
Send the handle to remove_memory_font
at the end of your program to free the font from memory.
Sourcepub fn remove_memory_font(font: MemFont)
pub fn remove_memory_font(font: MemFont)
Remove a font that was previously added by Font::add_memory_font