Отказ от слайдеров
This commit is contained in:
@@ -28,7 +28,8 @@ pub fn drawLine(ctx: *DrawContext, x0: f32, y0: f32, x1: f32, y1: f32, color: Co
|
|||||||
const b1 = ctx.worldToBuffer(w1.x, w1.y);
|
const b1 = ctx.worldToBuffer(w1.x, w1.y);
|
||||||
const t = &ctx.transform;
|
const t = &ctx.transform;
|
||||||
const scale = @sqrt(t.scale.scale_x * ctx.scale_x * t.scale.scale_y * ctx.scale_y);
|
const scale = @sqrt(t.scale.scale_x * ctx.scale_x * t.scale.scale_y * ctx.scale_y);
|
||||||
const thickness_px: u32 = @max(@as(u32, 1), @as(u32, @intFromFloat(std.math.round(thickness * scale))));
|
const thickness_px: u32 = @as(u32, @intFromFloat(std.math.round(thickness * scale)));
|
||||||
|
if (thickness_px > 0)
|
||||||
drawLineInBuffer(ctx, b0.x, b0.y, b1.x, b1.y, color, thickness_px);
|
drawLineInBuffer(ctx, b0.x, b0.y, b1.x, b1.y, color, thickness_px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -356,8 +356,22 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
|||||||
const min_y = -doc.size.h;
|
const min_y = -doc.size.h;
|
||||||
const max_y = doc.size.h;
|
const max_y = doc.size.h;
|
||||||
var changed = false;
|
var changed = false;
|
||||||
changed = dvui.sliderEntry(@src(), "x: {d:0.2}", .{ .value = &next.x, .min = min_x, .max = max_x, .interval = 0.1 }, .{ .expand = .horizontal }) or changed;
|
{
|
||||||
changed = dvui.sliderEntry(@src(), "y: {d:0.2}", .{ .value = &next.y, .min = min_y, .max = max_y, .interval = 0.1 }, .{ .expand = .horizontal }) or changed;
|
var subrow = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal });
|
||||||
|
dvui.labelNoFmt(@src(), "x:", .{}, .{});
|
||||||
|
const T = @TypeOf(next.x);
|
||||||
|
const res = dvui.textEntryNumber(@src(), T, .{ .value = &next.x, .min = @as(T, min_x), .max = @as(T, max_x) }, .{ .expand = .horizontal });
|
||||||
|
subrow.deinit();
|
||||||
|
changed = res.changed or changed;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var subrow = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal });
|
||||||
|
dvui.labelNoFmt(@src(), "y:", .{}, .{});
|
||||||
|
const T = @TypeOf(next.y);
|
||||||
|
const res = dvui.textEntryNumber(@src(), T, .{ .value = &next.y, .min = @as(T, min_y), .max = @as(T, max_y) }, .{ .expand = .horizontal });
|
||||||
|
subrow.deinit();
|
||||||
|
changed = res.changed or changed;
|
||||||
|
}
|
||||||
if (changed) {
|
if (changed) {
|
||||||
obj.setProperty(canvas.document.allocator, .{ .data = .{ .position = next } }) catch {};
|
obj.setProperty(canvas.document.allocator, .{ .data = .{ .position = next } }) catch {};
|
||||||
canvas.requestRedraw();
|
canvas.requestRedraw();
|
||||||
@@ -365,16 +379,38 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
|||||||
},
|
},
|
||||||
.angle => |angle| {
|
.angle => |angle| {
|
||||||
var next = angle;
|
var next = angle;
|
||||||
if (dvui.sliderEntry(@src(), "{d:0.2} rad", .{ .value = &next, .min = -std.math.pi * 2.0, .max = std.math.pi * 2.0, .interval = 0.01 }, .{ .expand = .horizontal })) {
|
{
|
||||||
|
var subrow = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal });
|
||||||
|
dvui.labelNoFmt(@src(), "deg:", .{}, .{});
|
||||||
|
var degrees: f32 = next * 180.0 / std.math.pi;
|
||||||
|
const res = dvui.textEntryNumber(@src(), f32, .{ .value = °rees }, .{ .expand = .horizontal });
|
||||||
|
subrow.deinit();
|
||||||
|
if (res.changed) {
|
||||||
|
next = degrees * std.math.pi / 180.0;
|
||||||
obj.setProperty(canvas.document.allocator, .{ .data = .{ .angle = next } }) catch {};
|
obj.setProperty(canvas.document.allocator, .{ .data = .{ .angle = next } }) catch {};
|
||||||
canvas.requestRedraw();
|
canvas.requestRedraw();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
.scale => |scale| {
|
.scale => |scale| {
|
||||||
var next = scale;
|
var next = scale;
|
||||||
var changed = false;
|
var changed = false;
|
||||||
changed = dvui.sliderEntry(@src(), "x: {d:0.2}", .{ .value = &next.scale_x, .min = 0.0, .max = 10.0, .interval = 0.01 }, .{ .expand = .horizontal }) or changed;
|
{
|
||||||
changed = dvui.sliderEntry(@src(), "y: {d:0.2}", .{ .value = &next.scale_y, .min = 0.0, .max = 10.0, .interval = 0.01 }, .{ .expand = .horizontal }) or changed;
|
var subrow = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal });
|
||||||
|
dvui.labelNoFmt(@src(), "x:", .{}, .{});
|
||||||
|
const T = @TypeOf(next.scale_x);
|
||||||
|
const res = dvui.textEntryNumber(@src(), T, .{ .value = &next.scale_x, .min = @as(T, 0.0), .max = @as(T, 10.0) }, .{ .expand = .horizontal });
|
||||||
|
subrow.deinit();
|
||||||
|
changed = res.changed or changed;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var subrow = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal });
|
||||||
|
dvui.labelNoFmt(@src(), "y:", .{}, .{});
|
||||||
|
const T = @TypeOf(next.scale_y);
|
||||||
|
const res = dvui.textEntryNumber(@src(), T, .{ .value = &next.scale_y, .min = @as(T, 0.0), .max = @as(T, 10.0) }, .{ .expand = .horizontal });
|
||||||
|
subrow.deinit();
|
||||||
|
changed = res.changed or changed;
|
||||||
|
}
|
||||||
if (changed) {
|
if (changed) {
|
||||||
obj.setProperty(canvas.document.allocator, .{ .data = .{ .scale = next } }) catch {};
|
obj.setProperty(canvas.document.allocator, .{ .data = .{ .scale = next } }) catch {};
|
||||||
canvas.requestRedraw();
|
canvas.requestRedraw();
|
||||||
@@ -405,8 +441,22 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
|||||||
var next = size;
|
var next = size;
|
||||||
const doc = canvas.document;
|
const doc = canvas.document;
|
||||||
var changed = false;
|
var changed = false;
|
||||||
changed = dvui.sliderEntry(@src(), "w: {d:0.2}", .{ .value = &next.w, .min = 0.0, .max = doc.size.w, .interval = 1.0 }, .{ .expand = .horizontal }) or changed;
|
{
|
||||||
changed = dvui.sliderEntry(@src(), "h: {d:0.2}", .{ .value = &next.h, .min = 0.0, .max = doc.size.h, .interval = 1.0 }, .{ .expand = .horizontal }) or changed;
|
var subrow = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal });
|
||||||
|
dvui.labelNoFmt(@src(), "w:", .{}, .{});
|
||||||
|
const T = @TypeOf(next.w);
|
||||||
|
const res = dvui.textEntryNumber(@src(), T, .{ .value = &next.w, .min = @as(T, 0.0), .max = @as(T, doc.size.w) }, .{ .expand = .horizontal });
|
||||||
|
subrow.deinit();
|
||||||
|
changed = res.changed or changed;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var subrow = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal });
|
||||||
|
dvui.labelNoFmt(@src(), "h:", .{}, .{});
|
||||||
|
const T = @TypeOf(next.h);
|
||||||
|
const res = dvui.textEntryNumber(@src(), T, .{ .value = &next.h, .min = @as(T, 0.0), .max = @as(T, doc.size.h) }, .{ .expand = .horizontal });
|
||||||
|
subrow.deinit();
|
||||||
|
changed = res.changed or changed;
|
||||||
|
}
|
||||||
if (changed) {
|
if (changed) {
|
||||||
obj.setProperty(canvas.document.allocator, .{ .data = .{ .size = next } }) catch {};
|
obj.setProperty(canvas.document.allocator, .{ .data = .{ .size = next } }) catch {};
|
||||||
canvas.requestRedraw();
|
canvas.requestRedraw();
|
||||||
@@ -416,8 +466,22 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
|||||||
var next = radii;
|
var next = radii;
|
||||||
const doc = canvas.document;
|
const doc = canvas.document;
|
||||||
var changed = false;
|
var changed = false;
|
||||||
changed = dvui.sliderEntry(@src(), "x: {d:0.2}", .{ .value = &next.x, .min = 0.0, .max = doc.size.w, .interval = 1.0 }, .{ .expand = .horizontal }) or changed;
|
{
|
||||||
changed = dvui.sliderEntry(@src(), "y: {d:0.2}", .{ .value = &next.y, .min = 0.0, .max = doc.size.h, .interval = 1.0 }, .{ .expand = .horizontal }) or changed;
|
var subrow = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal });
|
||||||
|
dvui.labelNoFmt(@src(), "x:", .{}, .{});
|
||||||
|
const T = @TypeOf(next.x);
|
||||||
|
const res = dvui.textEntryNumber(@src(), T, .{ .value = &next.x, .min = @as(T, 0.0), .max = @as(T, doc.size.w) }, .{ .expand = .horizontal });
|
||||||
|
subrow.deinit();
|
||||||
|
changed = res.changed or changed;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var subrow = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal });
|
||||||
|
dvui.labelNoFmt(@src(), "y:", .{}, .{});
|
||||||
|
const T = @TypeOf(next.y);
|
||||||
|
const res = dvui.textEntryNumber(@src(), T, .{ .value = &next.y, .min = @as(T, 0.0), .max = @as(T, doc.size.h) }, .{ .expand = .horizontal });
|
||||||
|
subrow.deinit();
|
||||||
|
changed = res.changed or changed;
|
||||||
|
}
|
||||||
if (changed) {
|
if (changed) {
|
||||||
obj.setProperty(canvas.document.allocator, .{ .data = .{ .radii = next } }) catch {};
|
obj.setProperty(canvas.document.allocator, .{ .data = .{ .radii = next } }) catch {};
|
||||||
canvas.requestRedraw();
|
canvas.requestRedraw();
|
||||||
@@ -431,8 +495,22 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
|||||||
const min_y = -doc.size.h;
|
const min_y = -doc.size.h;
|
||||||
const max_y = doc.size.h;
|
const max_y = doc.size.h;
|
||||||
var changed = false;
|
var changed = false;
|
||||||
changed = dvui.sliderEntry(@src(), "x: {d:0.2}", .{ .value = &next.x, .min = min_x, .max = max_x, .interval = 0.1 }, .{ .expand = .horizontal }) or changed;
|
{
|
||||||
changed = dvui.sliderEntry(@src(), "y: {d:0.2}", .{ .value = &next.y, .min = min_y, .max = max_y, .interval = 0.1 }, .{ .expand = .horizontal }) or changed;
|
var subrow = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal });
|
||||||
|
dvui.labelNoFmt(@src(), "x:", .{}, .{});
|
||||||
|
const T = @TypeOf(next.x);
|
||||||
|
const res = dvui.textEntryNumber(@src(), T, .{ .value = &next.x, .min = @as(T, min_x), .max = @as(T, max_x) }, .{ .expand = .horizontal });
|
||||||
|
subrow.deinit();
|
||||||
|
changed = res.changed or changed;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var subrow = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal });
|
||||||
|
dvui.labelNoFmt(@src(), "y:", .{}, .{});
|
||||||
|
const T = @TypeOf(next.y);
|
||||||
|
const res = dvui.textEntryNumber(@src(), T, .{ .value = &next.y, .min = @as(T, min_y), .max = @as(T, max_y) }, .{ .expand = .horizontal });
|
||||||
|
subrow.deinit();
|
||||||
|
changed = res.changed or changed;
|
||||||
|
}
|
||||||
if (changed) {
|
if (changed) {
|
||||||
obj.setProperty(canvas.document.allocator, .{ .data = .{ .end_point = next } }) catch {};
|
obj.setProperty(canvas.document.allocator, .{ .data = .{ .end_point = next } }) catch {};
|
||||||
canvas.requestRedraw();
|
canvas.requestRedraw();
|
||||||
@@ -449,10 +527,17 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
|||||||
},
|
},
|
||||||
.thickness => |t| {
|
.thickness => |t| {
|
||||||
var next = t;
|
var next = t;
|
||||||
if (dvui.sliderEntry(@src(), "{d:0.2}", .{ .value = &next, .min = 0.0, .max = 100.0, .interval = 0.1 }, .{ .expand = .horizontal })) {
|
{
|
||||||
|
var subrow = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal });
|
||||||
|
dvui.labelNoFmt(@src(), "thickness:", .{}, .{});
|
||||||
|
const T = @TypeOf(next);
|
||||||
|
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.document.allocator, .{ .data = .{ .thickness = next } }) catch {};
|
obj.setProperty(canvas.document.allocator, .{ .data = .{ .thickness = next } }) catch {};
|
||||||
canvas.requestRedraw();
|
canvas.requestRedraw();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user