Skip to content

Commit 65b1b10

Browse files
author
Jay
committed
Add clear_image and clear_background_image
1 parent ead1d48 commit 65b1b10

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

build.zig.zon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.{
22
.name = .engine,
3-
.version = "0.7.6",
3+
.version = "0.7.7",
44
.fingerprint = 0xe8a81a8d0aa558d5,
55
.minimum_zig_version = "0.15.2",
66
.dependencies = .{
@@ -17,8 +17,8 @@
1717
.hash = "zigimg-0.1.0-8_eo2vBrFQBhsrLpexdcDQY-zrlzkyFZfKuYX-Nry6KN",
1818
},
1919
.resources = .{
20-
.url = "git+https://github.com/loftafi/resources.git#0776cc10cdcfa686543c3f92be6cbc2f36384541",
21-
.hash = "resources-0.7.4-J0GwI9E6AgDyFTZKD7THemvJZGHYjueSxU27ZCZ2L1jq",
20+
.url = "git+https://github.com/loftafi/resources.git#b65dd592bc1fb1eadbb5b1b6ca8cf8015ee8a669",
21+
.hash = "resources-0.7.5-J0GwI0o7AgAv3hn0V03TUNxFQBnPSlKv85pkJDd2boL4",
2222
},
2323
},
2424
.paths = .{

src/animator.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ pub const Ease = enum {
2424
stretch,
2525
};
2626

27+
target: *Element,
2728
mode: Mode = .move,
2829
movement: Ease = .ease,
2930
start: Rect = undefined,
3031
end: Rect = undefined,
3132
duration: i64 = 0, // number of nanoseconds to animate over
32-
on_end: ?*const fn (display: *Display, element: *Element) void = null,
33+
on_end: engine.Callback = .{ .func = null },
3334

3435
setup: bool = false,
3536
start_time: i64 = 0,
3637
end_time: i64 = 0,
37-
target: *Element,
3838

3939
/// Reposition/adjust an element based on the current_time in nanoseconds.
4040
/// When an animation starts, an `Ease` formula calculates the current

src/engine.zig

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,17 @@ pub const Element = struct {
805805
return texture;
806806
}
807807

808+
pub inline fn clear_image(
809+
self: *Element,
810+
gpa: Allocator,
811+
display: *Display,
812+
) void {
813+
if (self.texture != null) {
814+
display.release_texture_resource(gpa, self.texture.?);
815+
self.texture = null;
816+
}
817+
}
818+
808819
pub inline fn set_background_image(
809820
self: *Element,
810821
gpa: Allocator,
@@ -827,6 +838,17 @@ pub const Element = struct {
827838
return texture;
828839
}
829840

841+
pub inline fn clear_background_image(
842+
self: *Element,
843+
gpa: Allocator,
844+
display: *Display,
845+
) void {
846+
if (self.background.image != null) {
847+
display.release_texture_resource(gpa, self.background.image.?);
848+
self.background.image = null;
849+
}
850+
}
851+
830852
/// set_text updates the `text` and `translation` fields of labels,
831853
/// checkboxes and buttons, and regenerates the grahpics/image
832854
/// textures for each word if the text was changed or `forced`
@@ -3353,12 +3375,12 @@ pub const Display = struct {
33533375
// do start/centre/end alignment.
33543376
if (expanders.len > 0) {
33553377
// Relayout the children with expanders
3356-
trace("expanders: {s} has {any}. needed_height: {d} available_height: {d}", .{
3357-
parent.name,
3358-
expanders.len,
3359-
needed_height,
3360-
parent.rect.height,
3361-
});
3378+
//trace("expanders: {s} has {any}. needed_height: {d} available_height: {d}", .{
3379+
// parent.name,
3380+
// expanders.len,
3381+
// needed_height,
3382+
// parent.rect.height,
3383+
//});
33623384

33633385
if (parent.rect.height > needed_height) {
33643386
const spare_height = parent.rect.height - needed_height;
@@ -3368,10 +3390,10 @@ pub const Display = struct {
33683390
}
33693391
const percent = expander.type.expander.weight / expander_weights;
33703392
expander.rect.height = @trunc(spare_height * percent);
3371-
trace(" expander: weight {d} given: {d}", .{
3372-
percent,
3373-
expander.rect.height,
3374-
});
3393+
//trace(" expander: weight {d} given: {d}", .{
3394+
// percent,
3395+
// expander.rect.height,
3396+
//});
33753397
}
33763398
var new_y: f32 = parent.rect.y + parent.pad.top;
33773399
for (parent.type.panel.children.items) |child| {
@@ -3560,8 +3582,8 @@ pub const Display = struct {
35603582
old.start_time,
35613583
old.end_time,
35623584
});
3563-
if (old.on_end) |callback| {
3564-
callback(display, old.target);
3585+
if (old.on_end.func) |callback| {
3586+
try callback(old.on_end.ptr, display, old.target, display.allocator);
35653587
}
35663588
display.allocator.destroy(old);
35673589
} else {
@@ -3644,7 +3666,14 @@ pub const Display = struct {
36443666

36453667
/// Add an animator that points to a currently active/valid element.
36463668
/// The element must not be destroyed for the lifetime of the animation.
3647-
pub inline fn add_animator(self: *Display, allocator: Allocator, animator: Animator) error{OutOfMemory}!void {
3669+
pub inline fn add_animator(self: *Display, allocator: Allocator, animator: Animator) Allocator.Error!void {
3670+
//err("add animator: {t} {d}x{d} -> {d}x{d}", .{
3671+
// animator.mode,
3672+
// animator.start.x,
3673+
// animator.start.y,
3674+
// animator.end.x,
3675+
// animator.end.y,
3676+
//});
36483677
var new_animator = try allocator.create(Animator);
36493678
new_animator.* = animator;
36503679
new_animator.setup = false;

0 commit comments

Comments
 (0)