Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move some editor styling to floem style props #398

Merged
merged 12 commits into from
Mar 27, 2024

Conversation

jrmoulton
Copy link
Collaborator

This works and I think works really well.

I'm marking this as a draft because I still need to add docs and update the examples.

@MinusGix review on this would be good especially for things that might need to be changed to work with Lapce.
Mostly that is around SimpleStyling which now is only for properties that require line information

Copy link
Member

@MinusGix MinusGix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I like the idea/impl.
I was initially envisioning the floem style being inside SimpleStyling, but this is fine and works better in various cases.

Somewhat uncertain about changing phantom_text to take &EditorStyle instead. I was initially envisoning it as "user can downcast &dyn Styling if they have a custom impl to get arbitrary styling information".
That's what I'd have done in Lapce if we didn't already have config on our document for phantom text coloration (because lapce's phantom text has things like diagnostics and background color).
But I think that's fine enough.

I think it would be good to have some way of doing a decent default dark/light theme, since that seems no longer used.
(if we're going with "floem should just have very basic styles", I'm admittedly a bit skeptical of that)

examples/editor/src/main.rs Outdated Show resolved Hide resolved
examples/syntax-editor/src/main.rs Outdated Show resolved Hide resolved
src/style.rs Outdated Show resolved Hide resolved
src/views/editor/gutter.rs Outdated Show resolved Hide resolved
EditorView::paint_text(cx, &ed, viewport, &screen_lines, &self.editor_view_style);

// TODO: what is going on here? Why is this necessary
EditorView::paint_scroll_bar(cx, viewport, &self.editor_view_style);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lapce paints its own scrollbar.
image

(initially the editor scrollbar was broken in floem, then someone did something that made it weirdly thick but working properly, so I didn't bother looking at it more)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Possibly we could/should just remove the custom scrollbar painting code from floem-editor as Lapce has to write its own function on top for extra git map stuff anyway. Unsure)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Possibly we could/should just remove the custom scrollbar painting code from floem-editor as Lapce has to write its own function on top for extra git map stuff anyway. Unsure)

I'll look at removing it would be more consistent with the rest of floem if it just used the one from the scroll view.

src/views/editor/view.rs Outdated Show resolved Hide resolved
src/views/editor/visual_line.rs Outdated Show resolved Hide resolved
src/views/editor/text_document.rs Outdated Show resolved Hide resolved
src/views/editor/mod.rs Outdated Show resolved Hide resolved
src/views/editor/mod.rs Outdated Show resolved Hide resolved
@jrmoulton
Copy link
Collaborator Author

I think it would be good to have some way of doing a decent default dark/light theme, since that seems no longer used.
(if we're going with "floem should just have very basic styles", I'm admittedly a bit skeptical of that)

I was planning on using the colors from the previous SimpleStyling::light and dark and turning them into floem::styles that can be easily applied

@jrmoulton
Copy link
Collaborator Author

jrmoulton commented Mar 27, 2024

I figured out how to revert the whitespace changes so this should clearer to review now.

@jrmoulton
Copy link
Collaborator Author

I've fixed several issues that I had and now need to actually go back and add docs and update the examples

GutterStyle {
accent_color: TextColor,
dim_color: DimColor,
left_padding: LeftOfCenterPadding,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the ability to customize the gutter padding

@@ -152,14 +184,44 @@ impl Widget for EditorGutterView {
let mut text_layout = TextLayout::new();
if line == current_line {
text_layout.set_text(&text, current_line_attrs_list.clone());
if let Some(current_line_color) = self.gutter_style.current_line_color() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the ability to have the gutter show the highlighted line. This appears continuous with the editor highlighted line.

@jrmoulton jrmoulton marked this pull request as ready for review March 27, 2024 07:43
@jrmoulton
Copy link
Collaborator Author

That was a lot more work than I was expecting when I started. But now everything but line/syntax specific properties in the editor can be styled using floem styles and the editor_style method makes it super easy to use and obvious what is stylable.

Copy link
Member

@MinusGix MinusGix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me :)

@dzhou121 dzhou121 merged commit 402c58c into lapce:main Mar 27, 2024
7 checks passed
@dominikwilkowski
Copy link
Contributor

This fixes #393 no? Or are you expecting to move even more styles over?

@jrmoulton
Copy link
Collaborator Author

Oh yeah I just forgot to reference it as fixed. This fixes it

@@ -359,50 +356,64 @@ pub trait Styling {
}
}

pub fn default_light_color(color: EditorColor) -> Color {
pub fn default_light_theme(mut style: EditorCustomStyle) -> EditorCustomStyle {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name for light variant was changed but name of dark variant wasn't. Is there some reason for the difference or why was it changed?

@jrmoulton jrmoulton deleted the editor-styling branch September 18, 2024 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants