diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-26 15:45:33 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-26 15:45:33 +0100 |
| commit | feeedb0bf31314b182e7bbc135182f6e0bc859b2 (patch) | |
| tree | 163948cd874729925c2bf57d0927619065d2322d /src/app/components/gallery | |
| parent | 91d9b6992ac0ebee13704a3faefa8fd41a00075e (diff) | |
update zilch
Diffstat (limited to 'src/app/components/gallery')
| -rw-r--r-- | src/app/components/gallery/index.css | 33 | ||||
| -rw-r--r-- | src/app/components/gallery/index.html | 14 | ||||
| -rw-r--r-- | src/app/components/gallery/root.zig | 60 |
3 files changed, 99 insertions, 8 deletions
diff --git a/src/app/components/gallery/index.css b/src/app/components/gallery/index.css index c6a5817..35cab60 100644 --- a/src/app/components/gallery/index.css +++ b/src/app/components/gallery/index.css @@ -1,3 +1,34 @@ :host { - background: gray; + background: black; + --gallery-splits: 5; + display: flex; + flex-wrap: wrap; + overflow: auto; +} + +#control { + position: absolute; + bottom: 10px; + right: 70px; + width: 100px; + height: 50px; + background: var(--primary); + border-radius: 50px; + display: grid; + grid-template-columns: 1fr 1fr; + cursor: pointer; + user-select: none; + + div { + user-select: none; + color: var(--color); + width: 50px; + height: 50px; + text-align: center; + align-content: center; + } +} + +app-image { + width: calc(100% / var(--gallery-splits)); } diff --git a/src/app/components/gallery/index.html b/src/app/components/gallery/index.html index 8b13789..efa58a3 100644 --- a/src/app/components/gallery/index.html +++ b/src/app/components/gallery/index.html @@ -1 +1,13 @@ - +<div id="control"> + <div onclick="@zoomIn"> + <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus" viewBox="0 0 16 16"> + <path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4"> + </path> + </svg> + </div> + <div onclick="@zoomOut"> + <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-dash" viewBox="0 0 16 16"> + <path d="M4 8a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7A.5.5 0 0 1 4 8"></path> + </svg> + </div> +</div> diff --git a/src/app/components/gallery/root.zig b/src/app/components/gallery/root.zig index 7a06d5f..1eef707 100644 --- a/src/app/components/gallery/root.zig +++ b/src/app/components/gallery/root.zig @@ -1,4 +1,6 @@ const std = @import("std"); +const gpa = std.heap.wasm_allocator; + const zilch = @import("zilch"); const Object = zilch.Object; const components = @import("../root.zig"); @@ -16,23 +18,69 @@ pub const component: zilch.Component = .build(.{ const Self = @This(); element: *Object, -image: *Image, body: *Object, +pool: std.heap.MemoryPool(Image), +images: std.ArrayList(*Image), +style: *zilch.Object, +splits: usize, pub fn init(self: *Self, element: *Object) !void { var env: zilch.Env = .default; defer env.deinit(); self.element = element; + self.style = blk: { + var style = self.element.get(&env, "style"); + break :blk try style.await(&env, *zilch.Object); + }; + self.pool = .empty; + self.images = .empty; + self.splits = 5; + + const number_of_boxes: u32 = 1000; - self.image = try std.heap.wasm_allocator.create(Image); - var el = Image.component.new(self.image, &env); - try self.image.init(try el.await(&env)); + { + var elements: []zilch.Env.Future(*Object) = try gpa.alloc(zilch.Env.Future(*Object), number_of_boxes); + defer gpa.free(elements); + for (0..number_of_boxes) |index| { + const image = try self.pool.create(gpa); + elements[index] = Image.component.new(image, &env); + try self.images.append(gpa, image); + } + + for (elements[0..], self.images.items) |*el, image| { + try image.init(try el.await(&env)); + var future = image.setUrl(&env, "image/1"); + future.ignore(&env); + } + } var body = self.element.get(&env, "shadowRoot"); - var append_call = Object.call(body, &env, "append", .{self.image.element}); - append_call.ignore(&env); + for (self.images.items) |image| { + var append_call = Object.call(body, &env, "append", .{image.element}); + append_call.ignore(&env); + } self.body = try body.await(&env, *Object); } + +pub fn zoomIn(self: *Self) !void { + var env: zilch.Env = .default; + defer env.deinit(); + + self.splits = @max(1, self.splits - 1); + + var future = self.style.call(&env, "setProperty", .{ "--gallery-splits", self.splits }); + future.ignore(&env); +} + +pub fn zoomOut(self: *Self) !void { + var env: zilch.Env = .default; + defer env.deinit(); + + self.splits = @min(10, self.splits + 1); + + var future = self.style.call(&env, "setProperty", .{ "--gallery-splits", self.splits }); + future.ignore(&env); +} |