add back channel from device screen
This commit is contained in:
parent
ae26d2e1ba
commit
5c8a4ebb54
23
src/app.zig
23
src/app.zig
@ -7,6 +7,7 @@ const RangeF64 = @import("./range.zig").RangeF64;
|
||||
const Graph = @import("./graph.zig");
|
||||
const UI = @import("./ui.zig");
|
||||
const MainScreen = @import("./screens/main_screen.zig");
|
||||
const ChannelFromDeviceScreen = @import("./screens/channel_from_device.zig");
|
||||
const Platform = @import("./platform.zig");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
@ -574,6 +575,7 @@ screen: enum {
|
||||
add_channels
|
||||
} = .main,
|
||||
main_screen: MainScreen,
|
||||
channel_from_device: ChannelFromDeviceScreen,
|
||||
project: Project = .{},
|
||||
|
||||
collection_mutex: std.Thread.Mutex = .{},
|
||||
@ -589,7 +591,8 @@ pub fn init(self: *App, allocator: Allocator) !void {
|
||||
.allocator = allocator,
|
||||
.ui = UI.init(allocator),
|
||||
.main_screen = undefined,
|
||||
.collection_thread = undefined
|
||||
.collection_thread = undefined,
|
||||
.channel_from_device = undefined
|
||||
};
|
||||
try self.initUI();
|
||||
|
||||
@ -648,6 +651,7 @@ fn deinitProject(self: *App) void {
|
||||
fn initUI(self: *App) !void {
|
||||
self.ui = UI.init(self.allocator);
|
||||
self.main_screen = try MainScreen.init(self);
|
||||
self.channel_from_device = ChannelFromDeviceScreen.init(self);
|
||||
self.screen = .main;
|
||||
self.double_pass_ui = true;
|
||||
}
|
||||
@ -655,6 +659,7 @@ fn initUI(self: *App) !void {
|
||||
fn deinitUI(self: *App) void {
|
||||
self.ui.deinit();
|
||||
self.main_screen.deinit();
|
||||
self.channel_from_device.deinit();
|
||||
}
|
||||
|
||||
fn loadProject(self: *App) !void {
|
||||
@ -709,9 +714,7 @@ pub fn showUI(self: *App) !void {
|
||||
|
||||
switch (self.screen) {
|
||||
.main => try self.main_screen.tick(),
|
||||
.add_channels => {
|
||||
self.screen = .main;
|
||||
}
|
||||
.add_channels => try self.channel_from_device.tick()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1171,6 +1174,18 @@ pub fn isChannelOutputing(self: *App, id: Id) bool {
|
||||
return channel.output_task != null;
|
||||
}
|
||||
|
||||
pub fn getChannelByName(self: *App, channel_name: []const u8) ?*Channel {
|
||||
var channel_iter = self.project.channels.iterator();
|
||||
while (channel_iter.next()) |channel| {
|
||||
const name = utils.getBoundedStringZ(&channel.name);
|
||||
if (std.mem.eql(u8, name, channel_name)) {
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// ---------------- Views --------------------------------- //
|
||||
|
||||
pub inline fn getView(self: *App, id: Id) ?*View {
|
||||
|
@ -18,6 +18,13 @@ selected_channels: std.BoundedArray([:0]u8, 32) = .{},
|
||||
// TODO: Don't use arena
|
||||
channel_names: std.heap.ArenaAllocator,
|
||||
|
||||
pub fn init(app: *App) Screen {
|
||||
return Screen{
|
||||
.app = app,
|
||||
.channel_names = std.heap.ArenaAllocator.init(app.allocator)
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Screen) void {
|
||||
_ = self.channel_names.reset(.free_all);
|
||||
}
|
||||
@ -72,7 +79,7 @@ pub fn tick(self: *Screen) !void {
|
||||
var ui = &self.app.ui;
|
||||
|
||||
if (ui.isKeyboardPressed(.key_escape)) {
|
||||
self.app.current_screen = .main_menu;
|
||||
self.app.screen = .main;
|
||||
}
|
||||
|
||||
const root = ui.parentBox().?;
|
||||
@ -104,7 +111,7 @@ pub fn tick(self: *Screen) !void {
|
||||
channel_button.text_color = srcery.black;
|
||||
}
|
||||
|
||||
if (self.app.getChannelDeviceByName(channel) != null) {
|
||||
if (self.app.getChannelByName(channel) != null) {
|
||||
channel_button.text_color = srcery.white;
|
||||
channel_button.background = srcery.hard_black;
|
||||
} else {
|
||||
@ -209,9 +216,11 @@ pub fn tick(self: *Screen) !void {
|
||||
|
||||
const signal = ui.signal(add_button);
|
||||
if (signal.clicked()) {
|
||||
self.app.current_screen = .main_menu;
|
||||
self.app.screen = .main;
|
||||
for (self.selected_channels.slice()) |channel| {
|
||||
try self.app.appendChannelFromDevice(channel);
|
||||
_ = try self.app.addView(.{
|
||||
.channel = try self.app.addChannel(channel)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user