live preview: Introduce a SelectionRectangle struct

This commit is contained in:
Tobias Hunger 2024-03-14 17:31:51 +01:00 committed by Tobias Hunger
parent b5a7408774
commit 543bff941f
2 changed files with 27 additions and 23 deletions

View file

@ -629,10 +629,12 @@ fn set_selections(
.iter()
.enumerate()
.map(|(i, g)| ui::Selection {
width: g.size.width,
height: g.size.height,
x: g.origin.x,
y: g.origin.y,
geometry: ui::SelectionRectangle {
width: g.size.width,
height: g.size.height,
x: g.origin.x,
y: g.origin.y,
},
border_color: if i == main_index { border_color } else { secondary_border_color },
is_primary: i == main_index,
is_moveable,

View file

@ -13,11 +13,15 @@ enum SelectionKind {
select_up_or_down,
}
export struct Selection {
struct SelectionRectangle {
x: length,
y: length,
width: length,
height: length,
}
export struct Selection {
geometry: SelectionRectangle,
border-color: color,
is-primary: bool,
is-moveable: bool,
@ -28,10 +32,10 @@ component SelectionFrame {
in property <Selection> selection;
in property <bool> interactive: true;
x: root.selection.x;
y: root.selection.y;
width: root.selection.width;
height: root.selection.height;
x: root.selection.geometry.x;
y: root.selection.geometry.y;
width: root.selection.geometry.width;
height: root.selection.geometry.height;
callback update-geometry(/* x */ length, /* y */ length, /* width */ length, /* height */ length);
callback select-behind(/* x */ length, /* y */ length, /* enter component? */ bool, /* same file? */ bool);
@ -79,21 +83,19 @@ component SelectionFrame {
}
// Size label:
if selection.is-resizable: Rectangle {
x: 0;
y: root.height + 5px;
width: root.width;
if selection.is-resizable && root.selection.is-primary && interactive: Rectangle {
x: (root.width - label.width) * 0.5;
y: root.height + 3px;
width: label.width;
height: label.height;
HorizontalLayout {
alignment: center;
Rectangle {
background: root.selection.border-color;
width: label.width * 1.2;
height: label.height * 1.2;
label := Text {
color: Colors.white;
text: Math.round(root.selection.width/1px) + "x" + Math.round(root.selection.height/1px);
}
label := Rectangle {
background: root.selection.border-color;
width: label-text.width * 1.2;
height: label-text.height * 1.2;
label-text := Text {
color: Colors.white;
text: Math.round(root.width/1px) + "x" + Math.round(root.height/1px);
}
}
}