Struct penrose_ui::core::Context

source ·
pub struct Context<'a> { /* private fields */ }
Expand description

A minimal drawing context for rendering text based UI elements

A Context provides you with a backing pixmap for rendering your UI using simple offset and rendering operations. By default, the context will be positioned in the top left corner of the parent window created by your Draw. You can use the translate and set/reset offset methods to modify where the next drawing operation will take place.

It is worthwhile looking at the implementation of the StatusBar struct and how it handles rendering child widgets for a real example of how to make use of the offseting functionality of this struct.

Implementations§

source§

impl<'a> Context<'a>

source

pub fn clear(&mut self) -> Result<()>

Clear the underlying surface, restoring it to the background color.

source

pub fn translate(&mut self, dx: i32, dy: i32)

Offset future drawing operations by an additional (dx, dy)

source

pub fn set_offset(&mut self, x: i32, y: i32)

Set future drawing operations to apply from a specified point.

source

pub fn set_x_offset(&mut self, x: i32)

Set an absolute x offset for future drawing operations.

source

pub fn set_y_offset(&mut self, y: i32)

Set an absolute y offset for future drawing operations.

source

pub fn reset_offset(&mut self)

Set future drawing operations to apply from the origin.

source

pub fn draw_rect(&mut self, _: Rect, color: Color) -> Result<()>

Render a rectangular border using the supplied color.

source

pub fn fill_rect(&mut self, _: Rect, color: Color) -> Result<()>

Render a filled rectangle using the supplied color.

source

pub fn fill_polygon(&mut self, points: &[Point], color: Color) -> Result<()>

Render a filled rectangle using the supplied color.

source

pub fn fill_bg(&mut self, r: Rect) -> Result<()>

Fill the specified area with this Context’s background color

source

pub fn draw_text( &mut self, txt: &str, h_offset: u32, padding: (u32, u32), c: Color, ) -> Result<(u32, u32)>

Render the provided text at the current context offset using the supplied color.

source

pub fn text_extent(&mut self, txt: &str) -> Result<(u32, u32)>

Determine the width and height taken up by a given string in pixels.

source

pub fn flush(&self)

Flush pending requests to the X server.

This method does not need to be called explicitly if the flush method for the parent Draw is being called as well.

Trait Implementations§

source§

impl<'a> Debug for Context<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Context<'a>

§

impl<'a> RefUnwindSafe for Context<'a>

§

impl<'a> !Send for Context<'a>

§

impl<'a> !Sync for Context<'a>

§

impl<'a> Unpin for Context<'a>

§

impl<'a> !UnwindSafe for Context<'a>

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,