Giter Site home page Giter Site logo

Comments (11)

spirali avatar spirali commented on June 29, 2024 1

I have implemented "priority" for text styles that may help with your use case. PR #82 allows to run the following code (It is draft and now runs only in Inkscape mode, not Cairo mode):

    b = slide.box()
    b.set_style("grayout", TextStyle(color="gray", priority=1))  # <---- priority=1 is NEW
    b.code(
        "c",
        """~grayout{#include <stdio.h>
/* Hello world program */

int ~#A{main}() {}
    printf("Hello ~emph{world!\\n");}
    return 0;
}""",

That should look like this:

image

Is it ok for you?

from elsie.

spirali avatar spirali commented on June 29, 2024

It is done slightly on purpose. Can you share your use case? It cannot be switched off in the current version. But is like 3 lines of code to add this option. I will do it if it helps you.

from elsie.

tylerjw avatar tylerjw commented on June 29, 2024

Here is the function I wrote where I discovered this effect:

def grayed_before_after_code_slide(
    parent: Box,
    title: str,
    language: str,
    code: str,
    code_start: int,
    code_lines: int,
):
    code_bg = "#F6F8FA"
    box = parent.box(y=0, width="100%", height="100%", p_bottom=20, z_level=-2)
    box.rect(bg_color=code_bg, rx=20, ry=20)
    overlay = box.overlay()
    (before, code) = split_lines(code, code_start)
    (code, after) = split_lines(code, code_lines)
    before_box = overlay.sbox(
        name="before", x=0, y=0, p_left=20, p_right=20, p_top=20, p_bottom=20, z_level=0
    )
    before_box.code("", before, style="grayed")
    code_box = overlay.sbox(
        name="code", x=0, y=before_box.y("100%"), z_level=0, p_left=20, p_right=20
    )
    code_box.code(language, code)
    after_box = overlay.sbox(
        name="after", x=0, y=code_box.y("100%"), z_level=0, p_left=20, p_right=20
    )
    after_box.code("", after, style="grayed")

What I'm doing here is graying out code before and after some lines as a way of highlighting the lines I want to show in a larger context. I discovered that depending on where I split it will remove a newline.

Here is an example of calling this function:

@slides.slide(debug_boxes=False)
def details(slide):
    grayed_before_after_code_slide(
        slide,
        "ParameterDescriptor",
        "C++",
        """  auto param_desc  = rcl_interfaces::msg::ParameterDescriptor{};
  param_desc.description = "Mine!";
  param_desc.additional_constraints  = "One of [world, base, home]";
  params.my_string = node->declare_parameter("my_string",
    params.my_string, param_desc);

  param_desc  = rcl_interfaces::msg::ParameterDescriptor{};
  param_desc.description = "Who controls the universe?";
  param_desc.additional_constraints  = "A multiple of 23";
  params.my_number = node->declare_parameter("my_number",
    params.my_number, param_desc);
  // ...
""",
        6,
        5,
    )

And here is the resulting slide:
image

I presume the reason for this functionality is that you want the """ on one line with the code starting on the next without the newline showing up in your slide.

I've played around with implementing my function just using text and the grayed style instead of the code tag and have not yet gotten it to do what I want because I need the middle section to have syntax highlighting.

from elsie.

tylerjw avatar tylerjw commented on June 29, 2024

On the above code, here is a slight variation where I highlight the line before the line break and it is preserved:

@slides.slide(debug_boxes=False)
def details(slide):
    grayed_before_after_code_slide(
        slide,
        "ParameterDescriptor",
        "C++",
        """  auto param_desc  = rcl_interfaces::msg::ParameterDescriptor{};
  param_desc.description = "Mine!";
  param_desc.additional_constraints  = "One of [world, base, home]";
  params.my_string = node->declare_parameter("my_string",
    params.my_string, param_desc);

  param_desc  = rcl_interfaces::msg::ParameterDescriptor{};
  param_desc.description = "Who controls the universe?";
  param_desc.additional_constraints  = "A multiple of 23";
  params.my_number = node->declare_parameter("my_number",
    params.my_number, param_desc);
  // ...
""",
        4,
        6,
    )

image

from elsie.

tylerjw avatar tylerjw commented on June 29, 2024

Thank you for this. I'll try this out this weekend and see if I can make it work for my use-case. Thank you for your amazing work on this library.

from elsie.

tylerjw avatar tylerjw commented on June 29, 2024

I tried getting this to work for me but I can't seem to reproduce the behavior from the PR. I checked out the repo and installed it into my python virtual env with pip install .. When I try to set the priority flag and then use the style in the code function it does not seem to work:

.code(
            "C++",
            """~grayout{  auto param_desc  = rcl_interfaces::msg::ParameterDescriptor{};
  param_desc.description = "Mine!";
  param_desc.additional_constraints  = "One of [world, base, home]";
  params.my_string = node->declare_parameter("my_string",
    params.my_string, param_desc); }
  param_desc  = rcl_interfaces::msg::ParameterDescriptor{};
  param_desc.description = "Who controls the universe?";
  param_desc.additional_constraints  = "A multiple of 23";
  params.my_number = node->declare_parameter("my_number",
    params.my_number, param_desc);
  // ...
""",
        )

image

from elsie.

tylerjw avatar tylerjw commented on June 29, 2024

In case you want my full slides source they are here: https://github.com/tylerjw/tylerjw.dev/tree/main/slides

I'm presenting at roscon this week and both my main talk and my lighting talk I've put together with your tool.

from elsie.

spirali avatar spirali commented on June 29, 2024

I will look at it during the day more carefully. Did you try the branch "priority" (not the main branch)?.

from elsie.

tylerjw avatar tylerjw commented on June 29, 2024

Yes, I think I did. I installed it into a virtual environment.

from elsie.

spirali avatar spirali commented on June 29, 2024

Oh, this is my mistake. You need to enable use_styles=True. I accidently did not pasted the last line of my example:

    b.set_style("grayout", TextStyle(color="gray", priority=1))
    b.code(
        "c",
        """~grayout{#include <stdio.h>
/* Hello world program */

int ~#A{main}() {}
    printf("Hello ~emph{world!\\n");}
    return 0;
}""",
    use_styles=True)  # <----- THIS

from elsie.

spirali avatar spirali commented on June 29, 2024

This is necessary because by default .code does not parse user styles (to not clash with programming language)

from elsie.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.