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

source

pub fn new(font: &str, point_size: u8, bg: impl Into<Color>) -> Result<Self>

Construct a new Draw instance using the specified font and background color.

§Font names

See the top level docs for Draw for details on how fonts are specified.

§Errors

This method will error if it is unable to establish a connection with the X server.

source

pub fn conn(&self) -> &impl XConn

Get access to the underlying XConn used by this Draw.

source

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.

source

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.

source

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.

source

pub fn context_for(&mut self, id: Xid) -> Result<Context<'_>>

Retrieve the drawing Context for the given window Xid.

This method will error if the requested id does not already have an initialised surface. See the new_window method for details.

source

pub fn flush(&self, id: Xid) -> Result<()>

Flush any pending requests to the X server and map the specifed window to the screen.

Trait Implementations§

source§

impl Debug for Draw

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Draw

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !Freeze for Draw

§

impl RefUnwindSafe for Draw

§

impl !Send for Draw

§

impl !Sync for Draw

§

impl Unpin for Draw

§

impl UnwindSafe for Draw

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Any for T
where T: Any,