applyPropertyPatch
This commit is contained in:
@@ -380,6 +380,11 @@ fn drawStatsPanel(stats: RenderStats, frame_index: u64) void {
|
||||
panel.deinit();
|
||||
}
|
||||
|
||||
fn applyPropertyPatch(canvas: *Canvas, obj: *Document.Object, patch: Property) void {
|
||||
obj.setProperty(canvas.allocator, patch) catch {};
|
||||
canvas.requestRedraw();
|
||||
}
|
||||
|
||||
fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Property, row_index: usize) void {
|
||||
const row_id: usize = row_index * 16;
|
||||
const is_even = row_index % 2 == 0;
|
||||
@@ -421,8 +426,7 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
||||
changed = res.changed or changed;
|
||||
}
|
||||
if (changed) {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .position = next } }) catch {};
|
||||
canvas.requestRedraw();
|
||||
applyPropertyPatch(canvas, obj, .{ .data = .{ .position = next } });
|
||||
}
|
||||
},
|
||||
.angle => |angle| {
|
||||
@@ -435,8 +439,7 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
||||
subrow.deinit();
|
||||
if (res.changed) {
|
||||
next = degrees * std.math.pi / 180.0;
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .angle = next } }) catch {};
|
||||
canvas.requestRedraw();
|
||||
applyPropertyPatch(canvas, obj, .{ .data = .{ .angle = next } });
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -460,29 +463,25 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
||||
changed = res.changed or changed;
|
||||
}
|
||||
if (changed) {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .scale = next } }) catch {};
|
||||
canvas.requestRedraw();
|
||||
applyPropertyPatch(canvas, obj, .{ .data = .{ .scale = next } });
|
||||
}
|
||||
},
|
||||
.visible => |v| {
|
||||
var next = v;
|
||||
if (dvui.checkbox(@src(), &next, "Visible", .{})) {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .visible = next } }) catch {};
|
||||
canvas.requestRedraw();
|
||||
applyPropertyPatch(canvas, obj, .{ .data = .{ .visible = next } });
|
||||
}
|
||||
},
|
||||
.opacity => |opacity| {
|
||||
var next = opacity;
|
||||
if (dvui.sliderEntry(@src(), "{d:0.2}", .{ .value = &next, .min = 0.0, .max = 1.0, .interval = 0.01 }, .{ .expand = .horizontal })) {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .opacity = next } }) catch {};
|
||||
canvas.requestRedraw();
|
||||
applyPropertyPatch(canvas, obj, .{ .data = .{ .opacity = next } });
|
||||
}
|
||||
},
|
||||
.locked => |v| {
|
||||
var next = v;
|
||||
if (dvui.checkbox(@src(), &next, "Locked", .{})) {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .locked = next } }) catch {};
|
||||
canvas.requestRedraw();
|
||||
applyPropertyPatch(canvas, obj, .{ .data = .{ .locked = next } });
|
||||
}
|
||||
},
|
||||
.size => |size| {
|
||||
@@ -505,8 +504,7 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
||||
changed = res.changed or changed;
|
||||
}
|
||||
if (changed) {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .size = next } }) catch {};
|
||||
canvas.requestRedraw();
|
||||
applyPropertyPatch(canvas, obj, .{ .data = .{ .size = next } });
|
||||
}
|
||||
},
|
||||
.radii => |radii| {
|
||||
@@ -529,15 +527,13 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
||||
changed = res.changed or changed;
|
||||
}
|
||||
if (changed) {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .radii = next } }) catch {};
|
||||
canvas.requestRedraw();
|
||||
applyPropertyPatch(canvas, obj, .{ .data = .{ .radii = next } });
|
||||
}
|
||||
},
|
||||
.arc_percent => |pct| {
|
||||
var next = pct;
|
||||
if (dvui.sliderEntry(@src(), "{d:0.0}%", .{ .value = &next, .min = 0.0, .max = 100.0, .interval = 1.0 }, .{ .expand = .horizontal })) {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .arc_percent = next } }) catch {};
|
||||
canvas.requestRedraw();
|
||||
applyPropertyPatch(canvas, obj, .{ .data = .{ .arc_percent = next } });
|
||||
}
|
||||
},
|
||||
.end_point => |pt| {
|
||||
@@ -560,8 +556,7 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
||||
changed = res.changed or changed;
|
||||
}
|
||||
if (changed) {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .end_point = next } }) catch {};
|
||||
canvas.requestRedraw();
|
||||
applyPropertyPatch(canvas, obj, .{ .data = .{ .end_point = next } });
|
||||
}
|
||||
},
|
||||
.points => |points| {
|
||||
@@ -704,23 +699,20 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
||||
const res = dvui.textEntryNumber(@src(), T, .{ .value = &next, .min = @as(T, 0.0), .max = @as(T, 100.0) }, .{ .expand = .horizontal });
|
||||
subrow.deinit();
|
||||
if (res.changed) {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .thickness = next } }) catch {};
|
||||
canvas.requestRedraw();
|
||||
applyPropertyPatch(canvas, obj, .{ .data = .{ .thickness = next } });
|
||||
}
|
||||
}
|
||||
},
|
||||
.closed => |v| {
|
||||
var next = v;
|
||||
if (dvui.checkbox(@src(), &next, "Closed", .{})) {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .closed = next } }) catch {};
|
||||
canvas.requestRedraw();
|
||||
applyPropertyPatch(canvas, obj, .{ .data = .{ .closed = next } });
|
||||
}
|
||||
},
|
||||
.filled => |v| {
|
||||
var next = v;
|
||||
if (dvui.checkbox(@src(), &next, "Filled", .{})) {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .filled = next } }) catch {};
|
||||
canvas.requestRedraw();
|
||||
applyPropertyPatch(canvas, obj, .{ .data = .{ .filled = next } });
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -736,12 +728,11 @@ fn drawColorEditor(canvas: *Canvas, obj: *Document.Object, rgba: u32, is_fill: b
|
||||
.{ .expand = .horizontal },
|
||||
)) {
|
||||
const next = colorToRgba(hsv.toColor());
|
||||
if (is_fill) {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .fill_rgba = next } }) catch {};
|
||||
} else {
|
||||
obj.setProperty(canvas.allocator, .{ .data = .{ .stroke_rgba = next } }) catch {};
|
||||
}
|
||||
canvas.requestRedraw();
|
||||
const patch: Property = if (is_fill)
|
||||
.{ .data = .{ .fill_rgba = next } }
|
||||
else
|
||||
.{ .data = .{ .stroke_rgba = next } };
|
||||
applyPropertyPatch(canvas, obj, patch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user