show names on tabs in tabbed layout
This commit is contained in:
+48
-2
@@ -1,8 +1,8 @@
|
||||
//! Minimal wl_shm buffer pool for the tab bar.
|
||||
//!
|
||||
//! The tab bar is the only thing att_wm draws itself, and it draws nothing but
|
||||
//! solid rectangles, so this deliberately stops at "memfd, mmap, fill" rather
|
||||
//! than pulling in pixman or a font stack.
|
||||
//! solid rectangles and text in the bitmap font from `font.zig`, so this
|
||||
//! deliberately stops at "memfd, mmap, fill" rather than pulling in pixman.
|
||||
|
||||
const std = @import("std");
|
||||
const posix = std.posix;
|
||||
@@ -12,6 +12,7 @@ const sys = @import("sys.zig");
|
||||
const wayland = @import("wayland");
|
||||
const wl = wayland.client.wl;
|
||||
|
||||
const font = @import("font.zig");
|
||||
const layout = @import("layout.zig");
|
||||
const Box = layout.Box;
|
||||
|
||||
@@ -58,6 +59,51 @@ pub const Buffer = struct {
|
||||
}
|
||||
}
|
||||
|
||||
/// Fill a rectangle, clipped to `clip` as well as to the buffer.
|
||||
pub fn fillClipped(self: *Buffer, rect: Box, clip: Box, argb: u32) void {
|
||||
const x0 = @max(rect.x, clip.x);
|
||||
const y0 = @max(rect.y, clip.y);
|
||||
const x1 = @min(rect.x + rect.width, clip.x + clip.width);
|
||||
const y1 = @min(rect.y + rect.height, clip.y + clip.height);
|
||||
if (x1 <= x0 or y1 <= y0) return;
|
||||
self.fill(.{ .x = x0, .y = y0, .width = x1 - x0, .height = y1 - y0 }, argb);
|
||||
}
|
||||
|
||||
/// Draw text with the top left of its first cell at (x, y), clipped to
|
||||
/// `clip`, and return the x the next cell would start at. The font has no
|
||||
/// antialiasing, so lit pixels are simply written: nothing to blend.
|
||||
pub fn drawText(self: *Buffer, text: []const u8, x: i32, y: i32, scale: i32, argb: u32, clip: Box) i32 {
|
||||
var pen = x;
|
||||
var it: font.Iterator = .{ .bytes = text };
|
||||
while (it.next()) |cp| {
|
||||
// Stop as soon as the pen leaves the clip rather than walking the
|
||||
// rest of a long title a pixel at a time.
|
||||
if (pen >= clip.x + clip.width) break;
|
||||
self.drawGlyph(cp, pen, y, scale, argb, clip);
|
||||
pen += font.advance * scale;
|
||||
}
|
||||
return pen;
|
||||
}
|
||||
|
||||
pub fn drawGlyph(self: *Buffer, cp: u21, x: i32, y: i32, scale: i32, argb: u32, clip: Box) void {
|
||||
const rows = font.glyph(cp);
|
||||
for (rows, 0..) |bits, row| {
|
||||
if (bits == 0) continue;
|
||||
const py = y + @as(i32, @intCast(row)) * scale;
|
||||
var col: u3 = 0;
|
||||
while (col < font.cell_width) : (col += 1) {
|
||||
const mask = @as(u8, 1) << @intCast(font.cell_width - 1 - col);
|
||||
if (bits & mask == 0) continue;
|
||||
self.fillClipped(.{
|
||||
.x = x + @as(i32, col) * scale,
|
||||
.y = py,
|
||||
.width = scale,
|
||||
.height = scale,
|
||||
}, clip, argb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn deinit(self: *Buffer, gpa: Allocator) void {
|
||||
self.wl_buffer.destroy();
|
||||
posix.munmap(self.data);
|
||||
|
||||
Reference in New Issue
Block a user