mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-03 03:18:12 +08:00
Set text color based on its fill when it's being edited
This commit is contained in:
@@ -15,10 +15,11 @@ use crate::message_prelude::*;
|
|||||||
use crate::viewport_tools::vector_editor::vector_shape::VectorShape;
|
use crate::viewport_tools::vector_editor::vector_shape::VectorShape;
|
||||||
use crate::EditorError;
|
use crate::EditorError;
|
||||||
|
|
||||||
|
use graphene::color::Color;
|
||||||
use graphene::document::Document as GrapheneDocument;
|
use graphene::document::Document as GrapheneDocument;
|
||||||
use graphene::layers::folder_layer::FolderLayer;
|
use graphene::layers::folder_layer::FolderLayer;
|
||||||
use graphene::layers::layer_info::LayerDataType;
|
use graphene::layers::layer_info::LayerDataType;
|
||||||
use graphene::layers::style::ViewMode;
|
use graphene::layers::style::{Fill, ViewMode};
|
||||||
use graphene::{DocumentError, DocumentResponse, LayerId, Operation as DocumentOperation};
|
use graphene::{DocumentError, DocumentResponse, LayerId, Operation as DocumentOperation};
|
||||||
|
|
||||||
use glam::{DAffine2, DVec2};
|
use glam::{DAffine2, DVec2};
|
||||||
@@ -1156,11 +1157,13 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
|
|||||||
let text = self.graphene_document.layer(&path).unwrap().as_text().unwrap();
|
let text = self.graphene_document.layer(&path).unwrap().as_text().unwrap();
|
||||||
responses.push_back(DocumentOperation::SetTextEditability { path, editable }.into());
|
responses.push_back(DocumentOperation::SetTextEditability { path, editable }.into());
|
||||||
if editable {
|
if editable {
|
||||||
|
let color = if let Fill::Solid(solid_color) = text.style.fill() { *solid_color } else { Color::BLACK };
|
||||||
responses.push_back(
|
responses.push_back(
|
||||||
FrontendMessage::DisplayEditableTextbox {
|
FrontendMessage::DisplayEditableTextbox {
|
||||||
text: text.text.clone(),
|
text: text.text.clone(),
|
||||||
line_width: text.line_width,
|
line_width: text.line_width,
|
||||||
font_size: text.size,
|
font_size: text.size,
|
||||||
|
color,
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub enum FrontendMessage {
|
|||||||
DisplayDialogError { title: String, description: String },
|
DisplayDialogError { title: String, description: String },
|
||||||
DisplayDialogPanic { panic_info: String, title: String, description: String },
|
DisplayDialogPanic { panic_info: String, title: String, description: String },
|
||||||
DisplayDocumentLayerTreeStructure { data_buffer: RawBuffer },
|
DisplayDocumentLayerTreeStructure { data_buffer: RawBuffer },
|
||||||
DisplayEditableTextbox { text: String, line_width: Option<f64>, font_size: f64 },
|
DisplayEditableTextbox { text: String, line_width: Option<f64>, font_size: f64, color: Color },
|
||||||
DisplayRemoveEditableTextbox,
|
DisplayRemoveEditableTextbox,
|
||||||
|
|
||||||
// Trigger prefix: cause a browser API to do something
|
// Trigger prefix: cause a browser API to do something
|
||||||
|
|||||||
@@ -400,6 +400,7 @@ export default defineComponent({
|
|||||||
this.textInput.style.width = displayEditableTextbox.line_width ? `${displayEditableTextbox.line_width}px` : "max-content";
|
this.textInput.style.width = displayEditableTextbox.line_width ? `${displayEditableTextbox.line_width}px` : "max-content";
|
||||||
this.textInput.style.height = "auto";
|
this.textInput.style.height = "auto";
|
||||||
this.textInput.style.fontSize = `${displayEditableTextbox.font_size}px`;
|
this.textInput.style.fontSize = `${displayEditableTextbox.font_size}px`;
|
||||||
|
this.textInput.style.color = displayEditableTextbox.color.toRgbaCSS();
|
||||||
|
|
||||||
this.textInput.oninput = (): void => {
|
this.textInput.oninput = (): void => {
|
||||||
if (this.textInput) this.editor.instance.update_bounds(textInputCleanup(this.textInput.innerText));
|
if (this.textInput) this.editor.instance.update_bounds(textInputCleanup(this.textInput.innerText));
|
||||||
|
|||||||
@@ -303,6 +303,9 @@ export class DisplayEditableTextbox extends JsMessage {
|
|||||||
readonly line_width!: undefined | number;
|
readonly line_width!: undefined | number;
|
||||||
|
|
||||||
readonly font_size!: number;
|
readonly font_size!: number;
|
||||||
|
|
||||||
|
@Type(() => Color)
|
||||||
|
readonly color!: Color;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DisplayRemoveEditableTextbox extends JsMessage {}
|
export class DisplayRemoveEditableTextbox extends JsMessage {}
|
||||||
|
|||||||
Reference in New Issue
Block a user