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