mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
font: use explicit error sets where we can
This commit is contained in:
@ -83,7 +83,7 @@ pub const Region = extern struct {
|
|||||||
height: u32,
|
height: u32,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn init(alloc: Allocator, size: u32, format: Format) !Atlas {
|
pub fn init(alloc: Allocator, size: u32, format: Format) Allocator.Error!Atlas {
|
||||||
var result = Atlas{
|
var result = Atlas{
|
||||||
.data = try alloc.alloc(u8, size * size * format.depth()),
|
.data = try alloc.alloc(u8, size * size * format.depth()),
|
||||||
.size = size,
|
.size = size,
|
||||||
@ -111,7 +111,12 @@ pub fn deinit(self: *Atlas, alloc: Allocator) void {
|
|||||||
///
|
///
|
||||||
/// May allocate to add a new rectangle into the internal list of rectangles.
|
/// May allocate to add a new rectangle into the internal list of rectangles.
|
||||||
/// This will not automatically enlarge the texture if it is full.
|
/// This will not automatically enlarge the texture if it is full.
|
||||||
pub fn reserve(self: *Atlas, alloc: Allocator, width: u32, height: u32) !Region {
|
pub fn reserve(
|
||||||
|
self: *Atlas,
|
||||||
|
alloc: Allocator,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
) (Allocator.Error || Error)!Region {
|
||||||
// x, y are populated within :best_idx below
|
// x, y are populated within :best_idx below
|
||||||
var region: Region = .{ .x = 0, .y = 0, .width = width, .height = height };
|
var region: Region = .{ .x = 0, .y = 0, .width = width, .height = height };
|
||||||
|
|
||||||
@ -312,7 +317,7 @@ pub fn dump(self: Atlas, writer: anytype) !void {
|
|||||||
else => {
|
else => {
|
||||||
log.err("Unsupported format for dump: {}", .{self.format});
|
log.err("Unsupported format for dump: {}", .{self.format});
|
||||||
@panic("Cannot dump this atlas format.");
|
@panic("Cannot dump this atlas format.");
|
||||||
}
|
},
|
||||||
}),
|
}),
|
||||||
self.size,
|
self.size,
|
||||||
self.size,
|
self.size,
|
||||||
|
@ -102,7 +102,11 @@ pub const Canvas = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Write the data in this drawing to the atlas.
|
/// Write the data in this drawing to the atlas.
|
||||||
pub fn writeAtlas(self: *Canvas, alloc: Allocator, atlas: *font.Atlas) !font.Atlas.Region {
|
pub fn writeAtlas(
|
||||||
|
self: *Canvas,
|
||||||
|
alloc: Allocator,
|
||||||
|
atlas: *font.Atlas,
|
||||||
|
) (Allocator.Error || font.Atlas.Error)!font.Atlas.Region {
|
||||||
assert(atlas.format == .grayscale);
|
assert(atlas.format == .grayscale);
|
||||||
|
|
||||||
const width = @as(u32, @intCast(self.sfc.getWidth()));
|
const width = @as(u32, @intCast(self.sfc.getWidth()));
|
||||||
|
Reference in New Issue
Block a user