feat: implement CharType treevents and fix font stuff
This commit is contained in:
parent
078e47775a
commit
a25844b948
4 changed files with 36 additions and 38 deletions
|
@ -10,8 +10,8 @@
|
|||
.dependencies = .{
|
||||
.zenolith = .{
|
||||
//.path = "../zenolith",
|
||||
.url = "git+https://git.mzte.de/zenolith/zenolith.git#d55439e94ebd67b764dc2906ea5f2dee520a3956",
|
||||
.hash = "12208b7dd8669c55155d4e39b016b2836adb321b4dc2be30ddb3eb6888e0b6a82ae4",
|
||||
.url = "git+https://git.mzte.de/zenolith/zenolith.git#f84d6be6be10724f8baba1cf51da8fd03701d84c",
|
||||
.hash = "12207777d676529c333c17b8d6909e325b7205220b8f4057e48bfa3ccd71c84a9d6d",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ pub fn main() !void {
|
|||
defer platform.deinit();
|
||||
|
||||
var font = zenolith.text.Font.create(try platform.createFont(.{
|
||||
.source = .{ .path = "/usr/share/fonts/noto/NotoSans-Regular.ttf" },
|
||||
.source = .{ .path = "/usr/share/fonts/liberation/LiberationSans-Regular.ttf" },
|
||||
}), {});
|
||||
defer font.deinit();
|
||||
var zplatform = zenolith.platform.Platform.create(platform, .{});
|
||||
|
@ -30,24 +30,7 @@ pub fn main() !void {
|
|||
errdefer attrs.deinit(alloc);
|
||||
|
||||
(try attrs.mod(alloc, zenolith.attreebute.CurrentFont)).* = .{ .font = &font };
|
||||
(try attrs.mod(alloc, zenolith.attreebute.ButtonStyle)).* = .{
|
||||
.background = .{
|
||||
.stroked = .{
|
||||
.stroke = zenolith.Color.fromInt(0xeba0acff),
|
||||
.fill = zenolith.Color.fromInt(0x1e1e2eff),
|
||||
.width = 4,
|
||||
},
|
||||
},
|
||||
.background_hovered = .{
|
||||
.stroked = .{
|
||||
.stroke = zenolith.Color.fromInt(0xeba0acff),
|
||||
.fill = zenolith.Color.fromInt(0x313244ff),
|
||||
.width = 3,
|
||||
},
|
||||
},
|
||||
.padding = 10,
|
||||
.font_style = .{},
|
||||
};
|
||||
try zenolith.Theme.catppuccin_mocha.apply(alloc, &attrs);
|
||||
|
||||
root.data.attreebutes = attrs;
|
||||
}
|
||||
|
@ -56,24 +39,18 @@ pub fn main() !void {
|
|||
try root.downcast(zenolith.widget.Box).?.addChildPositioned(
|
||||
root,
|
||||
null,
|
||||
try zenolith.widget.Label.init(alloc, .{
|
||||
.font = &font,
|
||||
.text = "Hello, Zenolith!",
|
||||
.style = .{ .size = 64 },
|
||||
}),
|
||||
try zenolith.widget.Label.init(alloc, "Hello, Zenolith!"),
|
||||
.center,
|
||||
);
|
||||
|
||||
try root.addChild(null, try zenolith.widget.Label.init(alloc, .{
|
||||
.font = &font,
|
||||
.text = "Labels!",
|
||||
.style = .{ .size = 32 },
|
||||
}));
|
||||
try root.addChild(null, try zenolith.widget.Label.init(alloc, "Labels!"));
|
||||
|
||||
try root.addChild(null, try zenolith.widget.Button.init(alloc, "Button 1"));
|
||||
try root.addChild(null, try zenolith.widget.Button.init(alloc, "Button 2"));
|
||||
try root.addChild(null, try zenolith.widget.Button.init(alloc, "Button 3"));
|
||||
|
||||
try root.addChild(null, try zenolith.widget.Spacer.init(alloc, .{.flex = 1}));
|
||||
|
||||
{
|
||||
var chunk = zenolith.text.Chunk.init(alloc);
|
||||
errdefer chunk.deinit();
|
||||
|
|
|
@ -66,11 +66,19 @@ pub fn getGlyph(self: *Sdl2Font, codepoint: u21, style: zenolith.text.Style) !ze
|
|||
}
|
||||
|
||||
pub fn yOffset(self: *Sdl2Font, size: u31) u31 {
|
||||
if (c.FT_Set_Pixel_Sizes(self.face, 0, @intCast(size)) != 0)
|
||||
// TODO: wonk
|
||||
@panic("Unable to FT_Set_Pixel_Sizes for determining y offset");
|
||||
_ = self;
|
||||
// What is supposed to work:
|
||||
//if (c.FT_Set_Pixel_Sizes(self.face, 0, @intCast(size)) != 0)
|
||||
// @panic("Unable to FT_Set_Pixel_Sizes for determining y offset");
|
||||
|
||||
return @intCast(self.face.*.size.*.metrics.height >> 6);
|
||||
// All these produce equally nonsensical results and there seems to be no consensus which one is actually correct:
|
||||
//return @intCast(self.face.*.size.*.metrics.height >> 6);
|
||||
//return @intCast((self.face.*.size.*.metrics.ascender - self.face.*.size.*.metrics.descender) >> 6);
|
||||
//return @intCast((c.FT_MulFix(self.face.*.bbox.yMax, self.face.*.size.*.metrics.y_scale) >> 6) -
|
||||
// (c.FT_MulFix(self.face.*.bbox.yMin, self.face.*.size.*.metrics.y_scale) >> 6));
|
||||
|
||||
// What actually works:
|
||||
return size;
|
||||
}
|
||||
|
||||
fn getSize(self: *Sdl2Font) zenolith.layout.Size {
|
||||
|
|
|
@ -224,7 +224,7 @@ pub fn run(
|
|||
|
||||
switch (ev.type) {
|
||||
c.SDL_KEYUP => {
|
||||
try zenolith.treevent.ptrFire(root, zenolith.treevent.KeyPress{
|
||||
try zenolith.treevent.fire(root, zenolith.treevent.KeyPress{
|
||||
.scancode = sc,
|
||||
.modifiers = mods,
|
||||
.action = .up,
|
||||
|
@ -232,14 +232,14 @@ pub fn run(
|
|||
},
|
||||
c.SDL_KEYDOWN => {
|
||||
if (ev.key.repeat == 0) {
|
||||
try zenolith.treevent.ptrFire(root, zenolith.treevent.KeyPress{
|
||||
try zenolith.treevent.fire(root, zenolith.treevent.KeyPress{
|
||||
.scancode = sc,
|
||||
.modifiers = mods,
|
||||
.action = .down,
|
||||
});
|
||||
}
|
||||
|
||||
try zenolith.treevent.ptrFire(root, zenolith.treevent.KeyPress{
|
||||
try zenolith.treevent.fire(root, zenolith.treevent.KeyPress{
|
||||
.scancode = sc,
|
||||
.modifiers = mods,
|
||||
.action = .press,
|
||||
|
@ -252,6 +252,19 @@ pub fn run(
|
|||
}
|
||||
},
|
||||
|
||||
c.SDL_TEXTINPUT => {
|
||||
var iter = std.unicode.Utf8Iterator{
|
||||
.bytes = std.mem.sliceTo(&ev.text.text, 0),
|
||||
.i = 0,
|
||||
};
|
||||
|
||||
while (iter.nextCodepoint()) |codepoint| {
|
||||
try zenolith.treevent.fire(root, zenolith.treevent.CharType{
|
||||
.codepoint = codepoint,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
else => {},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue