feat: things
This commit is contained in:
@@ -3,7 +3,7 @@ const Model = struct {
|
||||
crash: bool = false,
|
||||
allocator: std.mem.Allocator,
|
||||
current_items_view: *vxfw.ListView,
|
||||
core_model: CoreModel,
|
||||
app_common_model: AppCommonModel,
|
||||
root_provider: *RootProvider,
|
||||
|
||||
/// Helper function to return a vxfw.Widget struct
|
||||
@@ -35,7 +35,9 @@ const Model = struct {
|
||||
// return ctx.requestFocus(vm.current_items_view.widget());
|
||||
// }
|
||||
|
||||
handle_key(key, &vm.core_model.appState) catch {};
|
||||
var arena = std.heap.ArenaAllocator.init(vm.allocator);
|
||||
defer arena.deinit();
|
||||
handle_key(key, &vm.app_common_model.appState, arena.allocator()) catch {};
|
||||
},
|
||||
.focus_in => return ctx.requestFocus(vm.current_items_view.widget()),
|
||||
else => {},
|
||||
@@ -88,7 +90,7 @@ const Model = struct {
|
||||
};
|
||||
try rootWidgets.append(list_surface);
|
||||
|
||||
const current_location_text = if (vm.core_model.appState.currentTab.currentLocation) |loc| loc.item.fullName.path else "";
|
||||
const current_location_text = if (vm.app_common_model.appState.currentTab.currentLocation) |loc| loc.item.fullName.path else "";
|
||||
const current_location_text_element = try ctx.arena.create(vxfw.Text);
|
||||
current_location_text_element.* = vxfw.Text{
|
||||
.text = current_location_text,
|
||||
@@ -117,9 +119,9 @@ const Model = struct {
|
||||
fn createCurrentItems(ctx: vxfw.DrawContext, vm: *Model) !void {
|
||||
if (vm.crash) @panic("asd123");
|
||||
|
||||
vm.core_model.current_items.mutex.lock();
|
||||
defer vm.core_model.current_items.mutex.unlock();
|
||||
const text_items = if (vm.core_model.current_items.data) |items| blk: {
|
||||
vm.app_common_model.current_items.mutex.lock();
|
||||
defer vm.app_common_model.current_items.mutex.unlock();
|
||||
const text_items = if (vm.app_common_model.current_items.data) |items| blk: {
|
||||
const children = try ctx.arena.alloc(*vxfw.Text, items.len);
|
||||
for (0.., items[0..children.len]) |i, child| {
|
||||
const is_active = i == vm.current_items_view.cursor;
|
||||
@@ -264,20 +266,20 @@ pub fn main() !void {
|
||||
const model = try allocator.create(Model);
|
||||
defer allocator.destroy(model);
|
||||
|
||||
var core_model: CoreModel = undefined;
|
||||
try CoreModel.init(&core_model, std.heap.ArenaAllocator.init(allocator), appState);
|
||||
var app_common_model: AppCommonModel = undefined;
|
||||
try AppCommonModel.init(&app_common_model, std.heap.ArenaAllocator.init(allocator), appState);
|
||||
defer app_common_model.deinit();
|
||||
|
||||
model.* = .{
|
||||
.allocator = allocator,
|
||||
.core_model = core_model,
|
||||
.app_common_model = app_common_model,
|
||||
.current_items_view = &list,
|
||||
.root_provider = &rootProvider,
|
||||
};
|
||||
defer model.core_model.deinit();
|
||||
|
||||
model.core_model.usage_number.data += 1;
|
||||
model.app_common_model.usage_number.data += 1;
|
||||
|
||||
try pool.spawn(core.data_loop, .{&model.core_model});
|
||||
try pool.spawn(core.data_loop, .{&model.app_common_model});
|
||||
|
||||
var app = try vxfw.App.init(allocator);
|
||||
defer app.deinit();
|
||||
@@ -285,10 +287,10 @@ pub fn main() !void {
|
||||
try app.run(model.widget(), .{});
|
||||
// std.Thread.sleep(10 * std.time.ns_per_s);
|
||||
|
||||
model.core_model.usage_number.data -= 1;
|
||||
model.core_model.running = false;
|
||||
model.app_common_model.usage_number.data -= 1;
|
||||
model.app_common_model.running = false;
|
||||
|
||||
while (model.core_model.usage_number.data > 0) {
|
||||
while (model.app_common_model.usage_number.data > 0) {
|
||||
std.Thread.sleep(10 * std.time.ns_per_ms);
|
||||
}
|
||||
}
|
||||
@@ -303,7 +305,7 @@ const RootProvider = @import("../core/provider/root.zig").RootProvider;
|
||||
const local_provider = @import("../core/provider/local.zig");
|
||||
const Tab = @import("../core/tab/tab.zig").Tab;
|
||||
const locked = @import("../core/sync.zig").locked;
|
||||
const CoreModel = @import("../app_common/Model.zig");
|
||||
const AppCommonModel = @import("../app_common/Model.zig");
|
||||
const core = @import("../app_common/root.zig");
|
||||
const AppState = @import("../core/app_state.zig").AppState;
|
||||
const handle_key = @import("./action_map.zig").handle_key;
|
||||
|
||||
Reference in New Issue
Block a user