Comments (5)
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.
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 callitem.label()
which ignores the style, and here we only callprinter.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 newstyled_label()
method to get the label, and usePrinter::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 (regularPrinter::print
) for each space, and one (Printer::print_styled
) for the styled label.
- Right now we use
from cursive.
I can take this on if you could point me in the right direction. I'm not yet familiar with the sources
from cursive.
Wow, thanks for the thorough instructions. The fix seems to work, I will test it and prepare a proper PR soon
![cool](https://private-user-images.githubusercontent.com/2899800/334515256-4fafe2d0-9930-4406-92ba-111a3d2c9275.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4NjI4MDIsIm5iZiI6MTcyMzg2MjUwMiwicGF0aCI6Ii8yODk5ODAwLzMzNDUxNTI1Ni00ZmFmZTJkMC05OTMwLTQ0MDYtOTJiYS0xMTFhM2QyYzkyNzUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTdUMDI0MTQyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MWE2Mzg3OTBiYjYxODA3MGQ1NGFmNGJkZWE1YzkyNTFmNzgwMTMzODkwNTVmZTJkOTliOWNmM2EyYzY0NDUxMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.1cw6ub7qBP-7_W_gb43_z6rHyGlskGaXJ3pY4nv_vIA)
from cursive.
merged #784
from cursive.
Related Issues (20)
- [FEATURE] How would I bring form, panel, and menu into this? HOT 1
- [BUG] Calling find_name() in the wrong order makes things unfindable HOT 2
- Documentation issue about textarea set_cursor HOT 2
- [BUG] While using cursive, stacktrace (on panic) are never printed to (non-alternate) screen HOT 2
- [FEATURE] more keys in `event::Keys` HOT 2
- [BUG] Shift+Up/Down do not work w/ Termion backend HOT 2
- [BUG] cursive.clear() does not work. HOT 2
- [FEATURE] `CheckBox` as multichoice with similarity to `RadioGroup` HOT 2
- [BUG] Button gets pressed on mouse hover with crossterm HOT 4
- [FEATURE] Multiline EditView HOT 2
- Inconsistency between documentation and code implementation HOT 3
- [FEATURE] Feature Request or Guidance on Customizing Submit Key for SelectView HOT 1
- [BUG] Limit subview size HOT 2
- [BUG] Panic when opening empty menubar subtree HOT 2
- [FEATURE] Add the capacity to disable or enabled the Views. Buttons, Edit and others. Even Full Layouts. HOT 1
- [BUG] cursive exits immediately when asked to display a string with a null byte HOT 6
- [FEATURE] gradient colors HOT 4
- [BUG] The recent "Move examples to the repo root" commit broke rust-analyzer for the examples HOT 5
- [BUG] tests fail with unicode-width 0.1.12 but not with 0.1.13 (should we support both in tests too?) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cursive.