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>
impl<'a> Context<'a>
sourcepub fn clear(&mut self) -> Result<()>
pub fn clear(&mut self) -> Result<()>
Clear the underlying surface, restoring it to the background color.
sourcepub fn translate(&mut self, dx: i32, dy: i32)
pub fn translate(&mut self, dx: i32, dy: i32)
Offset future drawing operations by an additional (dx, dy)
sourcepub fn set_offset(&mut self, x: i32, y: i32)
pub fn set_offset(&mut self, x: i32, y: i32)
Set future drawing operations to apply from a specified point.
sourcepub fn set_x_offset(&mut self, x: i32)
pub fn set_x_offset(&mut self, x: i32)
Set an absolute x offset for future drawing operations.
sourcepub fn set_y_offset(&mut self, y: i32)
pub fn set_y_offset(&mut self, y: i32)
Set an absolute y offset for future drawing operations.
sourcepub fn reset_offset(&mut self)
pub fn reset_offset(&mut self)
Set future drawing operations to apply from the origin.
sourcepub fn draw_rect(&mut self, _: Rect, color: Color) -> Result<()>
pub fn draw_rect(&mut self, _: Rect, color: Color) -> Result<()>
Render a rectangular border using the supplied color.
sourcepub fn fill_rect(&mut self, _: Rect, color: Color) -> Result<()>
pub fn fill_rect(&mut self, _: Rect, color: Color) -> Result<()>
Render a filled rectangle using the supplied color.
sourcepub fn fill_polygon(&mut self, points: &[Point], color: Color) -> Result<()>
pub fn fill_polygon(&mut self, points: &[Point], color: Color) -> Result<()>
Render a filled rectangle using the supplied color.
sourcepub fn fill_bg(&mut self, r: Rect) -> Result<()>
pub fn fill_bg(&mut self, r: Rect) -> Result<()>
Fill the specified area with this Context’s background color
sourcepub fn draw_text(
&mut self,
txt: &str,
h_offset: u32,
padding: (u32, u32),
c: Color,
) -> Result<(u32, u32)>
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.