text: Implement TextField.background, disable it by default
This commit is contained in:
parent
26ffbdfe23
commit
df6aa85948
|
@ -122,6 +122,7 @@ pub fn create_proto<'gc>(
|
||||||
with_text_field_props!(
|
with_text_field_props!(
|
||||||
object, gc_context, fn_proto,
|
object, gc_context, fn_proto,
|
||||||
"autoSize" => [auto_size, set_auto_size],
|
"autoSize" => [auto_size, set_auto_size],
|
||||||
|
"background" => [background, set_background],
|
||||||
"backgroundColor" => [background_color, set_background_color],
|
"backgroundColor" => [background_color, set_background_color],
|
||||||
"border" => [border, set_border],
|
"border" => [border, set_border],
|
||||||
"borderColor" => [border_color, set_border_color],
|
"borderColor" => [border_color, set_border_color],
|
||||||
|
@ -391,6 +392,23 @@ pub fn set_html_text<'gc>(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn background<'gc>(
|
||||||
|
this: EditText<'gc>,
|
||||||
|
_activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
|
Ok(this.has_background().into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_background<'gc>(
|
||||||
|
this: EditText<'gc>,
|
||||||
|
activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
value: Value<'gc>,
|
||||||
|
) -> Result<(), Error<'gc>> {
|
||||||
|
let has_background = value.as_bool(activation.current_swf_version());
|
||||||
|
this.set_has_background(activation.context.gc_context, has_background);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn background_color<'gc>(
|
pub fn background_color<'gc>(
|
||||||
this: EditText<'gc>,
|
this: EditText<'gc>,
|
||||||
_activation: &mut Activation<'_, 'gc, '_>,
|
_activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
|
|
@ -90,7 +90,10 @@ pub struct EditTextData<'gc> {
|
||||||
/// If this is a password input field
|
/// If this is a password input field
|
||||||
is_password: bool,
|
is_password: bool,
|
||||||
|
|
||||||
/// The color of the background fill. Only applied when has_border.
|
/// If the text field should have a background. Only applied when has_border.
|
||||||
|
has_background: bool,
|
||||||
|
|
||||||
|
/// The color of the background fill. Only applied when has_border and has_background.
|
||||||
background_color: u32,
|
background_color: u32,
|
||||||
|
|
||||||
/// If the text field should have a border.
|
/// If the text field should have a border.
|
||||||
|
@ -195,6 +198,7 @@ impl<'gc> EditText<'gc> {
|
||||||
swf_tag.is_device_font,
|
swf_tag.is_device_font,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let has_background = false;
|
||||||
let background_color = 0xFFFFFF; // Default is white
|
let background_color = 0xFFFFFF; // Default is white
|
||||||
let has_border = swf_tag.has_border;
|
let has_border = swf_tag.has_border;
|
||||||
let border_color = 0; // Default is black
|
let border_color = 0; // Default is black
|
||||||
|
@ -252,6 +256,7 @@ impl<'gc> EditText<'gc> {
|
||||||
is_editable,
|
is_editable,
|
||||||
is_word_wrap,
|
is_word_wrap,
|
||||||
is_password,
|
is_password,
|
||||||
|
has_background,
|
||||||
background_color,
|
background_color,
|
||||||
has_border,
|
has_border,
|
||||||
border_color,
|
border_color,
|
||||||
|
@ -513,6 +518,15 @@ impl<'gc> EditText<'gc> {
|
||||||
self.relayout(context);
|
self.relayout(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_background(self) -> bool {
|
||||||
|
self.0.read().has_background
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_has_background(self, context: MutationContext<'gc, '_>, has_background: bool) {
|
||||||
|
self.0.write(context).has_background = has_background;
|
||||||
|
self.redraw_border(context);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn background_color(self) -> u32 {
|
pub fn background_color(self) -> u32 {
|
||||||
self.0.read().background_color
|
self.0.read().background_color
|
||||||
}
|
}
|
||||||
|
@ -673,12 +687,16 @@ impl<'gc> EditText<'gc> {
|
||||||
Twips::new(1),
|
Twips::new(1),
|
||||||
swf::Color::from_rgb(border_color, 0xFF),
|
swf::Color::from_rgb(border_color, 0xFF),
|
||||||
)));
|
)));
|
||||||
|
if write.has_background {
|
||||||
write
|
write
|
||||||
.drawing
|
.drawing
|
||||||
.set_fill_style(Some(swf::FillStyle::Color(swf::Color::from_rgb(
|
.set_fill_style(Some(swf::FillStyle::Color(swf::Color::from_rgb(
|
||||||
background_color,
|
background_color,
|
||||||
0xFF,
|
0xFF,
|
||||||
))));
|
))));
|
||||||
|
} else {
|
||||||
|
write.drawing.set_fill_style(None);
|
||||||
|
}
|
||||||
write.drawing.draw_command(DrawCommand::MoveTo {
|
write.drawing.draw_command(DrawCommand::MoveTo {
|
||||||
x: Twips::new(0),
|
x: Twips::new(0),
|
||||||
y: Twips::new(0),
|
y: Twips::new(0),
|
||||||
|
|
Loading…
Reference in New Issue