Добавлены остальные инструменты
This commit is contained in:
@@ -9,12 +9,12 @@ pub const ToolDescriptor = struct {
|
||||
};
|
||||
|
||||
tools: []const ToolDescriptor,
|
||||
selected_index: usize,
|
||||
selected_index: ?usize,
|
||||
|
||||
pub fn init(tools_list: []const ToolDescriptor) Toolbar {
|
||||
return .{
|
||||
.tools = tools_list,
|
||||
.selected_index = 0,
|
||||
.selected_index = null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,9 +22,22 @@ pub fn deinit(_: *Toolbar) void {}
|
||||
|
||||
pub fn currentDescriptor(self: *const Toolbar) ?*const ToolDescriptor {
|
||||
if (self.tools.len == 0) return null;
|
||||
return &self.tools[self.selected_index];
|
||||
if (self.selected_index) |index| {
|
||||
return &self.tools[index];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn select(self: *Toolbar, index: usize) void {
|
||||
if (index < self.tools.len) self.selected_index = index;
|
||||
pub fn select(self: *Toolbar, index: ?usize) void {
|
||||
if (index == self.selected_index) {
|
||||
self.selected_index = null;
|
||||
return;
|
||||
}
|
||||
if (index) |i| {
|
||||
if (i < self.tools.len) {
|
||||
self.selected_index = i;
|
||||
}
|
||||
} else {
|
||||
self.selected_index = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user