GithubHelp home page GithubHelp logo

Comments (5)

gyscos avatar gyscos commented on July 24, 2024 1

Hi, and thanks for the report!

Indeed, it would be very nice to be able to use StyledStrings there! Especially to use bold or underscores to highlight shortcuts.

Right now the menu doesn't support these, mostly because it was written before styled strings were a thing. Shouldn't be too hard to add that!

from cursive.

gyscos avatar gyscos commented on July 24, 2024 1

Sure!

There's two parts to the menubar:

  • The backend menu tree representation, in menu.rs. Looks like I already updated that to support StyledStrings - yay!
  • The UI parts. There's 2 views used in the menu: the menubar itself, and the popups that open when a category is selected.
    • The menu popups. Here too, it has already been updated to support styled strings.
    • The menubar. Here too apparently I updated that to support StyledString, but I did not properly update the draw implementation: first we call item.label() which ignores the style, and here we only call printer.print((offset, 0), &format!(" {label} "));, which is not style-aware.

So to fix this last point, I would recommend making 2 changes:

  • Adding a menu::Item::styled_label(&self) -> SpannedStr<Style>, which returns either the styled string stored from the item, or an unstyled "|" if it's a delimiter:
// It's a bit cumbersome, but you can create a static slice of spans:
const PLAIN_1CHAR_SPAN: &'static [IndexedSpan<Style>] = &[IndexedSpan { 
    content: 
    attr: Style {
        effects: EnumSet::EMPTY,  // This needs a recent enough `enumset` dependency, we should bump the minimum version to 1.1.0
        color: ColorStyle {
            front: ColorType::InheritParent,
            back: ColorType::InheritParent,
        },
    },
    width: 1,
}];
// ...
// ... and here you can create a `SpannedStr<'static, Style>`:
SpannedStr::new("|", PLAIN_1CHAR_SPAN)

(Note for later: we should really try to make more functions const to help here! Right now we're often using the Into trait so that limits what we can const-ify, but hopefully it'll get better eventually...)

  • Updating the Menubar::draw implementation to call this new styled_label() method to get the label, and use Printer::print_styled to print it.
    • Right now we use format!(" {label} ") to add spaces around the label. It may be a better idea to instead make 3 print calls: one (regular Printer::print) for each space, and one (Printer::print_styled) for the styled label.

from cursive.

svfat avatar svfat commented on July 24, 2024

I can take this on if you could point me in the right direction. I'm not yet familiar with the sources

from cursive.

svfat avatar svfat commented on July 24, 2024

Wow, thanks for the thorough instructions. The fix seems to work, I will test it and prepare a proper PR soon

cool

from cursive.

svfat avatar svfat commented on July 24, 2024

merged #784

from cursive.

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.