Skip to content

Commit

Permalink
#272 fixing text offset
Browse files Browse the repository at this point in the history
  • Loading branch information
sminez committed Jul 15, 2023
1 parent a2f1baf commit 76d83a6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
rust-version: ${{ matrix.rust }}

- name: Install C deps
run: sudo apt-get update && sudo apt-get install -y libxrandr-dev libx11-xcb-dev libxcb-randr0-dev libpango1.0-dev libcairo2-dev --fix-missing
run: sudo apt-get update && sudo apt-get install -y libxrandr-dev libx11-xcb-dev libxcb-randr0-dev --fix-missing

- name: Run tests
run: cargo test --workspace --features ${{ matrix.features }} --verbose
Expand All @@ -55,7 +55,7 @@ jobs:
- uses: hecrj/setup-rust-action@v1
with:
components: clippy
- run: sudo apt-get update && sudo apt-get install -y libxrandr-dev libx11-xcb-dev libxcb-randr0-dev libpango1.0-dev libcairo2-dev --fix-missing
- run: sudo apt-get update && sudo apt-get install -y libxrandr-dev libx11-xcb-dev libxcb-randr0-dev --fix-missing
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -70,5 +70,5 @@ jobs:
- uses: hecrj/setup-rust-action@v1
with:
rust-version: nightly
- run: sudo apt-get update && sudo apt-get install -y libxrandr-dev libx11-xcb-dev libxcb-randr0-dev libpango1.0-dev libcairo2-dev --fix-missing
- run: sudo apt-get update && sudo apt-get install -y libxrandr-dev libx11-xcb-dev libxcb-randr0-dev --fix-missing
- run: cargo rustdoc --all-features
4 changes: 0 additions & 4 deletions crates/penrose_ui/src/bar/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ impl<X: XConn> Widget<X> for Text {
}

let (ew, eh) = <Self as Widget<X>>::current_extent(self, ctx, h)?;
// ctx.font(&self.font, self.point_size)?;
// ctx.color(&self.fg);

let offset = w as i32 - ew as i32;
let right_justify = self.right_justified && self.is_greedy && offset > 0;
if right_justify {
Expand All @@ -165,7 +162,6 @@ impl<X: XConn> Widget<X> for Text {
Some(extent) => Ok(extent),
None => {
let (l, r) = self.padding;
// ctx.font(&self.font, self.point_size)?;
let (w, h) = ctx.text_extent(&self.txt)?;
let extent = (w + l + r, h);
self.extent = Some(extent);
Expand Down
8 changes: 4 additions & 4 deletions crates/penrose_ui/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<'a> Context<'a> {
/// Render a rectangular border using the supplied color.
pub fn draw_rect(&mut self, Rect { x, y, w, h }: Rect, color: Color) -> Result<()> {
let xcol = self.get_or_try_init_xcolor(color)?;
let (x, y) = (x as i32, y as i32);
let (x, y) = (self.dx + x as i32, self.dy + y as i32);

unsafe {
XSetForeground(self.dpy, self.s.gc, (*xcol).pixel);
Expand All @@ -229,7 +229,7 @@ impl<'a> Context<'a> {
/// Render a filled rectangle using the supplied color.
pub fn fill_rect(&mut self, Rect { x, y, w, h }: Rect, color: Color) -> Result<()> {
let xcol = self.get_or_try_init_xcolor(color)?;
let (x, y) = (x as i32, y as i32);
let (x, y) = (self.dx + x as i32, self.dy + y as i32);

unsafe {
XSetForeground(self.dpy, self.s.gc, (*xcol).pixel);
Expand Down Expand Up @@ -261,7 +261,7 @@ impl<'a> Context<'a> {
};

let (lpad, rpad) = (padding.0 as i32, padding.1);
let (mut x, y) = (lpad + self.dx, self.dy + h_offset as i32);
let (mut x, y) = (lpad + self.dx, self.dy);
let (mut total_w, mut total_h) = (x as u32, 0);
let xcol = self.get_or_try_init_xcolor(c)?;

Expand All @@ -270,7 +270,7 @@ impl<'a> Context<'a> {
let (chunk_w, chunk_h) = fnt.get_exts(self.dpy, chunk)?;

// SAFETY: fnt pointer is non-null
let chunk_y = unsafe { y + (h_offset + chunk_h) as i32 / 2 + (*fnt.xfont).ascent };
let chunk_y = unsafe { y + h_offset as i32 + (*fnt.xfont).ascent };
let c_str = CString::new(chunk)?;

unsafe {
Expand Down

0 comments on commit 76d83a6

Please sign in to comment.