Struct penrose_ui::core::Draw
source · pub struct Draw { /* private fields */ }
Expand description
A minimal back end for rendering simple text based UIs.
NOTE: Your application should create a single Draw struct to manage the windows and surfaces it needs to render your UI. See the Context struct for how to draw to the surfaces you have created.
§Fonts
§Specifying fonts
Font names need to be in a form that can be parsed by xft
. The simplest way to find the valid
font names on your system is via the fc-list
program like so:
$ fc-list -f '%{family}\n' | sort -u
Draw will automtically append :size={point_size}
to the font name when loading the font via
xft. The Arch wiki page on fonts is a useful resource on how X11 fonts work if you are
interested in futher reading.
§Font fallback for missing glyphs
Draw makes use of fontconfig to locate appropriate fallback fonts on your system when a glyph is encountered that the primary font does not support. If you wish to modify how fallback fonts are selected you will need to modify your font-conf (the Arch wiki has a good page on how to do this if you are looking for a reference).
§Example usage
Please see the crate examples directory for more examples.
use penrose::{
pure::geometry::Rect,
x::{Atom, WinType},
Color,
};
use penrose_ui::Draw;
use std::{thread::sleep, time::Duration};
let fg = Color::try_from("#EBDBB2").unwrap();
let bg = Color::try_from("#282828").unwrap();
let mut drw = Draw::new("mono", 12, bg).unwrap();
let w = drw.new_window(
WinType::InputOutput(Atom::NetWindowTypeDock),
Rect::new(0, 0, 300, 50),
false,
).unwrap();
let mut ctx = drw.context_for(w).unwrap();
ctx.draw_text("Hello from penrose_ui!", 0, (10, 0), fg).unwrap();
ctx.flush();
drw.flush(w).unwrap();
sleep(Duration::from_secs(2));
Implementations§
source§impl Draw
impl Draw
sourcepub fn new_window(&mut self, ty: WinType, r: Rect, managed: bool) -> Result<Xid>
pub fn new_window(&mut self, ty: WinType, r: Rect, managed: bool) -> Result<Xid>
Create a new X window with an initialised surface for drawing.
Destroying this window should be carried out using the destroy_window_and_surface
method
so that the associated graphics state is also cleaned up correctly.
sourcepub fn destroy_window_and_surface(&mut self, id: Xid) -> Result<()>
pub fn destroy_window_and_surface(&mut self, id: Xid) -> Result<()>
Destroy the specified window along with any surface and graphics context state held within this draw.
sourcepub fn set_font(&mut self, font: &str, point_size: u8) -> Result<()>
pub fn set_font(&mut self, font: &str, point_size: u8) -> Result<()>
Set the font being used for rendering text and clear the existing cache of fallback fonts for characters that are not supported by the primary font.