Переход на object_id
This commit is contained in:
@@ -8,7 +8,7 @@ const PropertyData = @import("../models/Property.zig").Data;
|
||||
const Rect_i = @import("../models/basic_models.zig").Rect_i;
|
||||
const Tool = @import("../toolbar/Tool.zig");
|
||||
|
||||
pub fn canvasView(canvas: *Canvas, selected_object: ?*Document.Object, content_rect_scale: dvui.RectScale) void {
|
||||
pub fn canvasView(canvas: *Canvas, selected_object_id: ?u64, content_rect_scale: dvui.RectScale) void {
|
||||
var textured = dvui_ext.texturedBox(content_rect_scale, dvui.Rect.all(20));
|
||||
{
|
||||
var overlay = dvui.overlay(@src(), .{ .expand = .both });
|
||||
@@ -56,7 +56,8 @@ pub fn canvasView(canvas: *Canvas, selected_object: ?*Document.Object, content_r
|
||||
toolbar_box.deinit();
|
||||
|
||||
// Панель свойств поверх scroll (правый верхний угол)
|
||||
if (selected_object) |obj| {
|
||||
if (selected_object_id) |obj_id| {
|
||||
if (canvas.document.findObjectById(obj_id)) |obj| {
|
||||
var properties_box = dvui.box(
|
||||
@src(),
|
||||
.{ .dir = .horizontal },
|
||||
@@ -74,6 +75,7 @@ pub fn canvasView(canvas: *Canvas, selected_object: ?*Document.Object, content_r
|
||||
// Сохраняем rect панели свойств для следующего кадра — в handleCanvasMouse исключаем из него клики
|
||||
canvas.properties_rect_scale = properties_box.data().contentRectScale();
|
||||
properties_box.deinit();
|
||||
}
|
||||
}
|
||||
|
||||
dvui.label(@src(), "Canvas", .{}, .{ .gravity_x = 0.5, .gravity_y = 0.0 });
|
||||
|
||||
@@ -11,8 +11,8 @@ const panel_radius: f32 = 24;
|
||||
const fill_color = dvui.Color.black.opacity(0.2);
|
||||
|
||||
const ObjectTreeCallback = union(enum) {
|
||||
select: *Object,
|
||||
delete: *Object,
|
||||
select: u64,
|
||||
delete: u64,
|
||||
};
|
||||
|
||||
fn shapeLabel(shape: Object.ShapeKind) []const u8 {
|
||||
@@ -26,8 +26,8 @@ fn shapeLabel(shape: Object.ShapeKind) []const u8 {
|
||||
|
||||
fn objectTreeRow(open_doc: *WindowContext.OpenDocument, obj: *Object, depth: u32, object_callback: *?ObjectTreeCallback) void {
|
||||
const indent_px = depth * 18;
|
||||
const is_selected: bool = open_doc.selected_object == obj;
|
||||
const row_id = @intFromPtr(obj);
|
||||
const is_selected: bool = open_doc.selected_object_id == obj.id;
|
||||
const row_id: usize = @intCast(obj.id);
|
||||
|
||||
const focus_color = dvui.themeGet().focus;
|
||||
|
||||
@@ -83,14 +83,14 @@ fn objectTreeRow(open_doc: *WindowContext.OpenDocument, obj: *Object, depth: u32
|
||||
.gravity_x = 1.0,
|
||||
};
|
||||
if (dvui.buttonIcon(@src(), "Delete object", icons.trash, .{}, .{}, delete_opts)) {
|
||||
object_callback.* = .{ .delete = obj };
|
||||
object_callback.* = .{ .delete = obj.id };
|
||||
}
|
||||
}
|
||||
}
|
||||
content.deinit();
|
||||
|
||||
if (select_row) {
|
||||
object_callback.* = .{ .select = obj };
|
||||
object_callback.* = .{ .select = obj.id };
|
||||
}
|
||||
}
|
||||
row.deinit();
|
||||
@@ -113,16 +113,16 @@ fn objectTree(ctx: *WindowContext) void {
|
||||
}
|
||||
if (object_callback) |callback| {
|
||||
switch (callback) {
|
||||
.select => |obj| {
|
||||
if (open_doc.selected_object == obj) {
|
||||
open_doc.selected_object = null;
|
||||
.select => |obj_id| {
|
||||
if (open_doc.selected_object_id == obj_id) {
|
||||
open_doc.selected_object_id = null;
|
||||
} else {
|
||||
open_doc.selected_object = obj;
|
||||
open_doc.selected_object_id = obj_id;
|
||||
}
|
||||
},
|
||||
.delete => |obj| {
|
||||
_ = doc.removeObject(obj);
|
||||
open_doc.selected_object = null;
|
||||
.delete => |obj_id| {
|
||||
_ = doc.removeObjectById(obj_id);
|
||||
open_doc.selected_object_id = null;
|
||||
open_doc.canvas.requestRedraw();
|
||||
},
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ pub fn rightPanel(ctx: *WindowContext) void {
|
||||
const active_doc = ctx.activeDocument();
|
||||
if (active_doc) |doc| {
|
||||
const content_rect_scale = panel.data().contentRectScale();
|
||||
canvas_view.canvasView(&doc.canvas, doc.selected_object, content_rect_scale);
|
||||
canvas_view.canvasView(&doc.canvas, doc.selected_object_id, content_rect_scale);
|
||||
} else {
|
||||
noDocView(ctx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user