avm2: Implement TextField.getLineLength()
This commit is contained in:
parent
8569df9503
commit
57b371900b
|
@ -144,10 +144,7 @@ package flash.text {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLineLength(lineIndex:int):int {
|
public native function getLineLength(lineIndex:int):int;
|
||||||
stub_method("flash.text.TextField", "getLineLength");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public native function getLineText(lineIndex:int):String;
|
public native function getLineText(lineIndex:int):String;
|
||||||
|
|
||||||
|
|
|
@ -1147,6 +1147,30 @@ pub fn get_line_metrics<'gc>(
|
||||||
Ok(Value::Undefined)
|
Ok(Value::Undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_line_length<'gc>(
|
||||||
|
activation: &mut Activation<'_, 'gc>,
|
||||||
|
this: Object<'gc>,
|
||||||
|
args: &[Value<'gc>],
|
||||||
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
|
let Some(this) = this
|
||||||
|
.as_display_object()
|
||||||
|
.and_then(|this| this.as_edit_text())
|
||||||
|
else {
|
||||||
|
return Ok(Value::Undefined);
|
||||||
|
};
|
||||||
|
|
||||||
|
let line_num = args.get_i32(activation, 0)?;
|
||||||
|
if line_num < 0 {
|
||||||
|
return Err(make_error_2006(activation));
|
||||||
|
}
|
||||||
|
|
||||||
|
return if let Some(length) = this.line_length(line_num as usize) {
|
||||||
|
Ok(length.into())
|
||||||
|
} else {
|
||||||
|
Err(make_error_2006(activation))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_line_text<'gc>(
|
pub fn get_line_text<'gc>(
|
||||||
activation: &mut Activation<'_, 'gc>,
|
activation: &mut Activation<'_, 'gc>,
|
||||||
this: Object<'gc>,
|
this: Object<'gc>,
|
||||||
|
|
|
@ -1913,6 +1913,10 @@ impl<'gc> EditText<'gc> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn line_length(self, line: usize) -> Option<usize> {
|
||||||
|
Some(self.0.read().layout.lines().get(line)?.len())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn line_text(self, line: usize) -> Option<WString> {
|
pub fn line_text(self, line: usize) -> Option<WString> {
|
||||||
let read = self.0.read();
|
let read = self.0.read();
|
||||||
let line = read.layout.lines().get(line)?;
|
let line = read.layout.lines().get(line)?;
|
||||||
|
|
Loading…
Reference in New Issue