app: simplify schema by introducing chatedit:min_height property.

This commit is contained in:
darkfi
2025-03-26 10:36:03 +01:00
parent 04209b29e2
commit 5ab2692975
3 changed files with 25 additions and 57 deletions

View File

@@ -314,7 +314,14 @@ pub fn create_chatedit(name: &str) -> SceneNode {
prop.set_ui_text("Is Focused", "A focused EditBox receives input");
node.add_property(prop).unwrap();
let prop = Property::new("max_height", PropertyType::Float32, PropertySubType::Pixel);
let mut prop = Property::new("min_height", PropertyType::Float32, PropertySubType::Pixel);
prop.set_ui_text("Min Height", "Minimum height");
prop.set_range_f32(0., f32::MAX);
node.add_property(prop).unwrap();
let mut prop = Property::new("max_height", PropertyType::Float32, PropertySubType::Pixel);
prop.set_ui_text("Max Height", "Maximum height");
prop.set_range_f32(0., f32::MAX);
node.add_property(prop).unwrap();
let prop = Property::new("height", PropertyType::Float32, PropertySubType::Pixel);

View File

@@ -59,6 +59,7 @@ mod android_ui_consts {
pub const BACKARROW_X: f32 = 50.;
pub const BACKARROW_Y: f32 = 70.;
pub const CHATEDIT_MIN_HEIGHT: f32 = 140.;
pub const CHATEDIT_MAX_HEIGHT: f32 = 1400.;
pub const CHATEDIT_HEIGHT: f32 = 140.;
pub const CHATEDIT_SINGLE_LINE_Y: f32 = 120.;
pub const CHATEDIT_BOTTOM_PAD: f32 = 10.;
@@ -127,6 +128,7 @@ mod ui_consts {
pub const BACKARROW_X: f32 = 38.;
pub const BACKARROW_Y: f32 = 26.;
pub const CHATEDIT_MIN_HEIGHT: f32 = 60.;
pub const CHATEDIT_MAX_HEIGHT: f32 = 600.;
pub const CHATEDIT_HEIGHT: f32 = 60.;
pub const CHATEDIT_SINGLE_LINE_Y: f32 = 58.;
pub const CHATEDIT_BOTTOM_PAD: f32 = 5.;
@@ -205,7 +207,6 @@ pub async fn make(
cc.add_const_f32("CHATEDIT_SINGLE_LINE_Y", CHATEDIT_SINGLE_LINE_Y);
cc.add_const_f32("CHATEDIT_BOTTOM_PAD", CHATEDIT_BOTTOM_PAD);
cc.add_const_f32("CHATEDIT_NEG_W", CHATEDIT_NEG_W);
cc.add_const_f32("CHATEDIT_MIN_HEIGHT", CHATEDIT_MIN_HEIGHT);
cc.add_const_f32("SENDARROW_NEG_X", SENDARROW_NEG_X);
cc.add_const_f32("SENDARROW_NEG_Y", SENDARROW_NEG_Y);
cc.add_const_f32("EMOJI_NEG_Y", EMOJI_NEG_Y);
@@ -476,19 +477,7 @@ pub async fn make(
prop.clone().set_f32(atom, Role::App, 1, CHATEDIT_HEIGHT).unwrap();
let code = cc.compile("w - 30").unwrap();
prop.clone().set_expr(atom, Role::App, 2, code).unwrap();
let code = cc
.compile(
"
height = if editz_h < CHATEDIT_MIN_HEIGHT {
CHATEDIT_MIN_HEIGHT
} else {
editz_h
};
h - CHATEDIT_HEIGHT - height - 2 * CHATEDIT_BOTTOM_PAD
",
)
.unwrap();
let code = cc.compile("h - CHATEDIT_HEIGHT - editz_h - 2 * CHATEDIT_BOTTOM_PAD").unwrap();
prop.clone().set_expr(atom, Role::App, 3, code).unwrap();
let chatview_rect_prop = prop.clone();
node.set_property_f32(atom, Role::App, "font_size", FONTSIZE).unwrap();
@@ -593,34 +582,10 @@ pub async fn make(
let node = create_vector_art("editbox_bg");
let prop = node.get_property("rect").unwrap();
prop.clone().set_f32(atom, Role::App, 0, 0.).unwrap();
let code = cc
.compile(
"
height = if editz_h < CHATEDIT_MIN_HEIGHT {
CHATEDIT_MIN_HEIGHT
} else {
editz_h
};
h - height - 2 * CHATEDIT_BOTTOM_PAD
",
)
.unwrap();
let code = cc.compile("h - editz_h - 2 * CHATEDIT_BOTTOM_PAD").unwrap();
prop.clone().set_expr(atom, Role::App, 1, code).unwrap();
prop.clone().set_expr(atom, Role::App, 2, expr::load_var("w")).unwrap();
let code = cc
.compile(
"
height = if editz_h < CHATEDIT_MIN_HEIGHT {
CHATEDIT_MIN_HEIGHT
} else {
editz_h
};
height + 2 * CHATEDIT_BOTTOM_PAD
",
)
.unwrap();
let code = cc.compile("editz_h + 2 * CHATEDIT_BOTTOM_PAD").unwrap();
prop.clone().set_expr(atom, Role::App, 3, code).unwrap();
node.set_property_u32(atom, Role::App, "z_index", 4).unwrap();
node.set_property_u32(atom, Role::App, "priority", 2).unwrap();
@@ -734,23 +699,12 @@ pub async fn make(
node.set_property_bool(atom, Role::App, "is_active", true).unwrap();
node.set_property_bool(atom, Role::App, "is_focused", true).unwrap();
node.set_property_f32(atom, Role::App, "max_height", 600.).unwrap();
node.set_property_f32(atom, Role::App, "min_height", CHATEDIT_MIN_HEIGHT).unwrap();
node.set_property_f32(atom, Role::App, "max_height", CHATEDIT_MAX_HEIGHT).unwrap();
let prop = node.get_property("rect").unwrap();
prop.clone().set_f32(atom, Role::App, 0, CHATEDIT_LHS_PAD).unwrap();
let code = cc
.compile(
"
height = if rect_h < CHATEDIT_MIN_HEIGHT {
CHATEDIT_SINGLE_LINE_Y
} else {
rect_h
};
parent_h - (height + CHATEDIT_BOTTOM_PAD)
",
)
.unwrap();
let code = cc.compile("parent_h - (rect_h + CHATEDIT_BOTTOM_PAD)").unwrap();
prop.clone().set_expr(atom, Role::App, 1, code).unwrap();
let code = cc.compile("parent_w - CHATEDIT_NEG_W").unwrap();
prop.clone().set_expr(atom, Role::App, 2, code).unwrap();

View File

@@ -469,6 +469,7 @@ pub struct ChatEdit {
is_active: PropertyBool,
is_focused: PropertyBool,
min_height: PropertyFloat32,
max_height: PropertyFloat32,
height: PropertyFloat32,
rect: PropertyRect,
@@ -530,6 +531,7 @@ impl ChatEdit {
let node_ref = &node.upgrade().unwrap();
let is_active = PropertyBool::wrap(node_ref, Role::Internal, "is_active", 0).unwrap();
let is_focused = PropertyBool::wrap(node_ref, Role::Internal, "is_focused", 0).unwrap();
let min_height = PropertyFloat32::wrap(node_ref, Role::Internal, "min_height", 0).unwrap();
let max_height = PropertyFloat32::wrap(node_ref, Role::Internal, "max_height", 0).unwrap();
let height = PropertyFloat32::wrap(node_ref, Role::Internal, "height", 0).unwrap();
let rect = PropertyRect::wrap(node_ref, Role::Internal, "rect").unwrap();
@@ -593,6 +595,7 @@ impl ChatEdit {
is_active,
is_focused,
min_height,
max_height,
height,
rect,
@@ -720,8 +723,8 @@ impl ChatEdit {
(atlas, wrapped_lines, selections, under_start, under_end)
};
let mut height = wrapped_lines.height() + self.descent.get();
height = height.clamp(0., self.max_height.get());
let real_height = wrapped_lines.height() + self.descent.get();
let height = real_height.clamp(self.min_height.get(), self.max_height.get());
self.rect.prop().set_f32(atom, Role::Internal, 3, height);
@@ -741,6 +744,10 @@ impl ChatEdit {
clip.x = 0.;
clip.y = 0.;
if real_height < height {
clip.y = (height - real_height) / 2.;
}
let mut mesh = MeshBuilder::with_clip(clip.clone());
let mut curr_y = -scroll;