|
| 1 | +--- |
| 2 | +title: "Capy 0.3 Release Notes" |
| 3 | +authors: ["Zen1th"] |
| 4 | +date: 2023-02-12T10:35:14+01:00 |
| 5 | +tags: ["capy", "release"] |
| 6 | +--- |
| 7 | + |
| 8 | +**Reminder: Capy is NOT ready for use in production as I'm still making breaking changes** |
| 9 | + |
| 10 | +[Capy](https://github.com/capy-ui/capy) is a **GUI framework** for Zig made with performance, cross-compilation and native widgets in mind. The goal is to be able to seamlessly cross-compile from any platform to any other one. This includes Windows, Linux, WebAssembly, and soon will include macOS, Android and iOS. |
| 11 | + |
| 12 | +It's been 6 months since the 0.2 update, but Capy is getting forward at its own slow pace. |
| 13 | + |
| 14 | + |
| 15 | +*[Balls](https://github.com/capy-ui/capy/blob/master/examples/balls.zig)* |
| 16 | + |
| 17 | +## Improved the build process |
| 18 | + |
| 19 | +The build process has been simplified as much as possible. |
| 20 | + |
| 21 | +The 50-line `install()` function you had to copy has been removed. So has the requirement to supply the path where Capy has been installed. Alongside that, a [template](https://github.com/capy-ui/zig-template) has been added which allows to get started with Capy much faster than before. |
| 22 | + |
| 23 | +In practice this means you can do that: |
| 24 | + |
| 25 | +```zig |
| 26 | +// Usual build functions.. |
| 27 | +const exe = b.addExecutable("my-gui-app", "src/main.zig"); |
| 28 | +exe.setTarget(target); |
| 29 | +exe.setBuildMode(mode); |
| 30 | +
|
| 31 | +// one-liner for using Capy |
| 32 | +try deps.imports.capy.install(exe, .{}); |
| 33 | +
|
| 34 | +// Usual build functions.. |
| 35 | +exe.install(); |
| 36 | +``` |
| 37 | + |
| 38 | +## New components |
| 39 | + |
| 40 | +I experimented with using Zig's comptime abilities so that one method could be used to |
| 41 | +get, set, and bind a property like if we were in a dynamic language. |
| 42 | +This allows to switch from `setText("Hello, World")` to `set("text", "Hello, World")`. |
| 43 | +I'm still wondering if this is better and whether `setProperty` would be a better name for it, |
| 44 | +but this atleast removes the burden of having to create 3 functions each time you add a property |
| 45 | +to a component. |
| 46 | + |
| 47 | +- Added `enabled` property to Button |
| 48 | +- Added `CheckBox` component |
| 49 | +- Added `Align` component. |
| 50 | + |
| 51 | +It's aim is to replace the former `alignX` and `alignY` properties which |
| 52 | +were a confusing bit of API design. Adding Align made the API should now be clearer and easier to understand, |
| 53 | +while also simplyfing the implementation of layouting. |
| 54 | + |
| 55 | +```zig |
| 56 | +Button(.{ .alignX = 0.5 }) |
| 57 | +``` |
| 58 | +becomes |
| 59 | +```zig |
| 60 | +Align(.{ .x = 0.5 }, Button(.{})) |
| 61 | +``` |
| 62 | + |
| 63 | +- Added an experimental for-each component (`ColumnList`). You can see it used in the [hacker-news example](https://github.com/capy-ui/capy/blob/master/examples/hacker-news.zig) but |
| 64 | +it is currently highly experimental. |
| 65 | +- Added ScrollView, which allows to make any component scrollable |
| 66 | + |
| 67 | +## Wrapping containers |
| 68 | +Added `wrapping` property, this allows the elements to wrap instead of going off to infinity. |
| 69 | + |
| 70 | +```zig |
| 71 | +capy.Row(.{ .wrapping = true, .spacing = 5 }, .{ |
| 72 | + capy.Button(.{ .label = "Button #0" }), |
| 73 | + capy.Button(.{ .label = "Button #1" }), |
| 74 | + capy.Button(.{ .label = "Button #2" }), |
| 75 | + capy.Button(.{ .label = "Button #3" }), |
| 76 | + // ... |
| 77 | +}) |
| 78 | +``` |
| 79 | + |
| 80 | +Here's a row with `wrapping` set to `false`, aka old behaviour: |
| 81 | + |
| 82 | +And here is it with `wrapping` set to `true`: |
| 83 | + |
| 84 | + |
| 85 | +Notice how with `wrapping` set to `false` (equivalent to the old behaviour) components take all the height of the Row, because the Row is only laying them out horizontally, so it gives them all the vertical space. |
| 86 | +However, with `wrapping` set to `true`, components may wrap over to bottom which means that Row is laying them out horizontally and vertically, so it gives components their preferred size instead. |
| 87 | + |
| 88 | +Hence, in both pictures, the buttons have the same width. |
| 89 | + |
| 90 | +## Optimized DataWrapper |
| 91 | + |
| 92 | +DataWrapper is what is responsible of giving data binding, animations and other [neat things](https://capy-ui.org/docs/guides/data-binding) to Capy. It's usually used whenever a property is required. This means that it's often used through the entire codebase and can end up in components that might be instantiated hundreds of times. Under this, it's logical to try to reduce the size overhead it gives. |
| 93 | +Thus, the data structures of DataWrapper were optimized for size, this resulted in |
| 94 | +the overhead being reduced, from 152 bytes down to 128 bytes. |
| 95 | + |
| 96 | +On the other hand, the`dependOn` function was added to DataWrapper. It's meant for values that depend on other values, while avoiding having to manually setup tons of change listeners. This can be used for things like a 'Submit' button, which can dependOn all fields being valid. You can quickly see how it can be used in the [flight booker example](https://github.com/capy-ui/capy/blob/master/examples/7gui/flight-booker.zig) |
| 97 | + |
| 98 | +Optional values can also now be animated using `animate(...)` |
| 99 | + |
| 100 | +### win32 fixes |
| 101 | +The native integration for High-DPI was added and is now functional. The only step remaining is to correctly |
| 102 | +implement the actual pixel scaling. When it's done, there won't be any change necessary on the |
| 103 | +application side as `Window.source_dpi` is already used well for that. |
| 104 | + |
| 105 | +Among that, there were a lot of bug fixes. |
| 106 | +- The background is now correctly cleared on resize ([c32e0e1](https://github.com/capy-ui/capy/commit/c32e0e16d62d0649deed63ba3b872e37c5c0f4b4)) |
| 107 | +- Improved performance and fixed flickering ([352a959](https://github.com/capy-ui/capy/commit/352a95974c4df0f109231100f292efd44b0bb435)) |
| 108 | +- You can now use `std.log` in Debug builds ([aed5e0f](https://github.com/capy-ui/capy/commit/aed5e0f28eb31bf37547707d8da999a4ebdb4b2f)) |
| 109 | +- Caption font is now used, this replaces win32's default GUI font that came from Windows 95 ([9bb59a1](https://github.com/capy-ui/capy/commit/9bb59a190089f693dba51e8c8e732f4d743fcbf1)) |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +## First steps on Android |
| 114 | +Recently, the first progress towards an Android backend were made. |
| 115 | + |
| 116 | +The Android backend is something I couldn't have managed to do without the efforts the Zig community put |
| 117 | +in [ZigAndroidTemplate](https://github.com/MasterQ32/ZigAndroidTemplate), so thanks to them. |
| 118 | + |
| 119 | +Secondly, Android is absolutely not made for native code that creates native views. |
| 120 | +But JNI truly can let you do anything Java can. |
| 121 | + |
| 122 | +<br> |
| 123 | +<img src="/img/capy-android-two-views.jpg" alt="We've got the TextView and the Button showing!" style="width: 15em;"></img> |
| 124 | +<br> |
| 125 | + |
| 126 | +Currently, it only supports TextField, Button, Canvas and Container. |
| 127 | + |
| 128 | +For more information, see the [blog post](/blog/porting-capy-to-android) detailing the port. |
| 129 | + |
| 130 | +## Baby steps on macOS |
| 131 | +As always, for macOS, I'm aiming at being able to build your app from Windows/Linux/macOS to macOS. |
| 132 | +So far, the plan is to download the macOS SDK automatically in `build.zig`, which is something you can do |
| 133 | +as long as you accept the [EULA](https://www.apple.com/legal/sla/docs/xcode.pdf). However this has not |
| 134 | +been done yet. |
| 135 | + |
| 136 | +Currently, what has been done is that, if you have a macOS SDK in the `macos-sdk` folder, you can build a basic non-functioning app. It doesn't work, but it calls the `NSWindow` APIs! We're onto a first step! |
| 137 | + |
| 138 | +## A note about the WebAssembly backend |
| 139 | +More functions were implemented on the WebAssembly, this quite notably allowed |
| 140 | +to run the [OpenStreetMap viewer example](/zig-osm/) online, without any |
| 141 | +platform-specific code. |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | +However, since Capy upgraded to the new Zig self-hosted compiler and it still hasn't yet reimplemented |
| 146 | +async, the backend is currently unusable due to this compiler regression. |
| 147 | + |
| 148 | +- Add viewport meta tag to run on mobile devices ([68dfda0](https://github.com/capy-ui/capy/commit/68dfda0eda529b915bc37d327320bab1af187224)) |
| 149 | + |
| 150 | + |
| 151 | +Lastly, an experimental HTTP module had been added ([03993dd](https://github.com/capy-ui/capy/commit/03993dd10e98d2d674708496ff2d9942f71666cd)) that used the Fetch API on WebAssembly. |
| 152 | +On desktop, it used [zfetch](https://github.com/truemedian/zfetch) but when it was archived by its |
| 153 | +creator, I had to switch to another library. Sadly no library was as simple to build as zfetch |
| 154 | +(that is where a simple `zig build run` is enough to setup everything quick enough and on all major |
| 155 | +platforms). |
| 156 | +I'm currently counting on Zig's efforts to implement a TLS library and an HTTP client in the standard library. I'll be able to switch once the changes brought in [#13980](https://github.com/ziglang/zig/pull/13980) are stabilized. |
| 157 | + |
| 158 | +## Documentation |
| 159 | + |
| 160 | +The documentation for Capy has switched from GitHub Wiki to a Docusaurus instance. |
| 161 | +It's still editable by the public on the [capy-ui/documentation](https://github.com/capy-ui/documentation) |
| 162 | +repository. |
0 commit comments