commit 74ead297d5c7381636f187116e4cf050a711027b Author: Roman Pytkov Date: Sat Dec 6 17:21:56 2025 +0300 Пустое окно diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f56bdc0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# ---> Zig +.zig-cache/ +zig-out/ + diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d810150 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Zig: Debug (lldb)", + "type": "lldb", + "request": "launch", + "program": "${workspaceFolder}/zig-out/bin/Zivro", + "args": [], + "cwd": "${workspaceFolder}", + "preLaunchTask": "zig: build" + }, + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..c800678 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,20 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "zig: build", + "type": "shell", + "command": "zig build", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": ["$gcc"], + "presentation": { + "reveal": "always", + "panel": "shared", + "showReuseMessage": true + } + } + ] +} diff --git a/.zigversion b/.zigversion new file mode 100644 index 0000000..a12760e --- /dev/null +++ b/.zigversion @@ -0,0 +1 @@ +0.15.2 \ No newline at end of file diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..369ac0a --- /dev/null +++ b/build.zig @@ -0,0 +1,44 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const dvui_dep = b.dependency("dvui", .{ .target = target, .optimize = optimize, .backend = .sdl3 }); + + const exe = b.addExecutable(.{ + .name = "Zivro", + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + + .imports = &.{ + .{ .name = "dvui", .module = dvui_dep.module("dvui_sdl3") }, + .{ .name = "sdl-backend", .module = dvui_dep.module("sdl3") }, + }, + }), + }); + + b.installArtifact(exe); + + const run_step = b.step("run", "Run the app"); + + const run_cmd = b.addRunArtifact(exe); + run_step.dependOn(&run_cmd.step); + + run_cmd.step.dependOn(b.getInstallStep()); + + if (b.args) |args| { + run_cmd.addArgs(args); + } + + const exe_tests = b.addTest(.{ + .root_module = exe.root_module, + }); + + const run_exe_tests = b.addRunArtifact(exe_tests); + + const test_step = b.step("test", "Run tests"); + test_step.dependOn(&run_exe_tests.step); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..c0ed749 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,86 @@ +.{ + // This is the default name used by packages depending on this one. For + // example, when a user runs `zig fetch --save `, this field is used + // as the key in the `dependencies` table. Although the user can choose a + // different name, most users will stick with this provided value. + // + // It is redundant to include "zig" in this name because it is already + // within the Zig package namespace. + .name = .Zivro, + // This is a [Semantic Version](https://semver.org/). + // In a future version of Zig it will be used for package deduplication. + .version = "0.0.0", + // Together with name, this represents a globally unique package + // identifier. This field is generated by the Zig toolchain when the + // package is first created, and then *never changes*. This allows + // unambiguous detection of one package being an updated version of + // another. + // + // When forking a Zig project, this id should be regenerated (delete the + // field and run `zig build`) if the upstream project is still maintained. + // Otherwise, the fork is *hostile*, attempting to take control over the + // original project's identity. Thus it is recommended to leave the comment + // on the following line intact, so that it shows up in code reviews that + // modify the field. + .fingerprint = 0x62d7eba14686811e, // Changing this has security and trust implications. + // Tracks the earliest Zig version that the package considers to be a + // supported use case. + .minimum_zig_version = "0.15.2", + // This field is optional. + // Each dependency must either provide a `url` and `hash`, or a `path`. + // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. + // Once all dependencies are fetched, `zig build` no longer requires + // internet connectivity. + .dependencies = .{ + .dvui = .{ + .url = "https://github.com/david-vanderson/dvui/archive/main.tar.gz", + .hash = "dvui-0.4.0-dev-AQFJmev72QC6e0ojhnW8a_wRhZDgzWWLgeyoNuIPZc2m", + }, + + // See `zig fetch --save ` for a command-line interface for adding dependencies. + //.example = .{ + // // When updating this field to a new URL, be sure to delete the corresponding + // // `hash`, otherwise you are communicating that you expect to find the old hash at + // // the new URL. If the contents of a URL change this will result in a hash mismatch + // // which will prevent zig from using it. + // .url = "https://example.com/foo.tar.gz", + // + // // This is computed from the file contents of the directory of files that is + // // obtained after fetching `url` and applying the inclusion rules given by + // // `paths`. + // // + // // This field is the source of truth; packages do not come from a `url`; they + // // come from a `hash`. `url` is just one of many possible mirrors for how to + // // obtain a package matching this `hash`. + // // + // // Uses the [multihash](https://multiformats.io/multihash/) format. + // .hash = "...", + // + // // When this is provided, the package is found in a directory relative to the + // // build root. In this case the package's hash is irrelevant and therefore not + // // computed. This field and `url` are mutually exclusive. + // .path = "foo", + // + // // When this is set to `true`, a package is declared to be lazily + // // fetched. This makes the dependency only get fetched if it is + // // actually used. + // .lazy = false, + //}, + }, + // Specifies the set of files and directories that are included in this package. + // Only files and directories listed here are included in the `hash` that + // is computed for this package. Only files listed here will remain on disk + // when using the zig package manager. As a rule of thumb, one should list + // files required for compilation plus any license(s). + // Paths are relative to the build root. Use the empty string (`""`) to refer to + // the build root itself. + // A directory listed here means that all files within, recursively, are included. + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + // For example... + //"LICENSE", + //"README.md", + }, +} diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..321e9a9 --- /dev/null +++ b/src/main.zig @@ -0,0 +1,65 @@ +const std = @import("std"); +const builtin = @import("builtin"); +const dvui = @import("dvui"); +const SDLBackend = @import("sdl-backend"); + +pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + const allocator = gpa.allocator(); + + var backend = try SDLBackend.initWindow(.{ + .allocator = allocator, + .size = .{ .w = 800.0, .h = 600.0 }, + .title = "My DVUI App", + .vsync = true, + }); + defer backend.deinit(); + + var win = try dvui.Window.init(@src(), allocator, backend.backend(), .{ + .theme = switch (backend.preferredColorScheme() orelse .light) { + .light => dvui.Theme.builtin.adwaita_light, + .dark => dvui.Theme.builtin.adwaita_dark, + }, + }); + defer win.deinit(); + + var interrupted = false; + + main_loop: while (true) { + // beginWait coordinates with waitTime below to run frames only when needed + const nstime = win.beginWait(interrupted); + + // marks the beginning of a frame for dvui, can call dvui functions after this + try win.begin(nstime); + + // send all SDL events to dvui for processing + try backend.addAllEvents(&win); + + // if dvui widgets might not cover the whole window, then need to clear + // the previous frame's render + _ = SDLBackend.c.SDL_SetRenderDrawColor(backend.renderer, 0, 0, 0, 255); + _ = SDLBackend.c.SDL_RenderClear(backend.renderer); + + const keep_running = gui_frame(); + if (!keep_running) break :main_loop; + + // marks end of dvui frame, don't call dvui functions after this + // - sends all dvui stuff to backend for rendering, must be called before renderPresent() + const end_micros = try win.end(.{}); + + // cursor management + try backend.setCursor(win.cursorRequested()); + try backend.textInputRect(win.textInputRequested()); + + // render frame to OS + try backend.renderPresent(); + + // waitTime and beginWait combine to achieve variable framerates + const wait_event_micros = win.waitTime(end_micros); + interrupted = try backend.waitEventTimeout(wait_event_micros); + } +} + +fn gui_frame() bool { + return true; +}