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

Add support for vertical status bar? #28

Open
e-matteson opened this issue Oct 21, 2017 · 2 comments
Open

Add support for vertical status bar? #28

e-matteson opened this issue Oct 21, 2017 · 2 comments

Comments

@e-matteson
Copy link

I've been looking for a status bar that's positioned along the left or right edge of the screen, with text rotated 90 degrees. It seems like a good way to save precious vertical space on tiny laptop screens, but I haven't found any status bars with this option. So writing / modifying one myself seems like the thing to do. I'm here at cnx because rust, and because it has the most readable source of any status bar I've looked at.

So, how do you feel about having Position::Left and Position::Right options for a vertical statusbar? Do you have any advice on the best way to implement it, without making a mess of your existing code?

I just spent a few minutes messing around with Position::Left, and it seems simple to get the struts and the surface in more or less the right place. The text rendering is more complicated, though, and I have no experience with cairo. Maybe all the text can be rendered normally, using the screen height as the text "width", and then the whole cairo context can be rotate 90 degrees? I tried adding context.rotate(PI / 2.), and it rotates the background rectangle, but there's no text visible.

@mjkillough
Copy link
Owner

mjkillough commented Oct 23, 2017

Apologies for the delay @e-matteson - I didn't see this in my inbox until now!

because it has the most readable source of any status bar I've looked at.

I'm very pleased to hear that! :)

I've been meaning to document the stuff in text.rs as part of an API for allowing external crates to make their own widgets, but I haven't got around to it yet. If you have any questions, please do ask them!

So, how do you feel about having Position::Left and Position::Right options for a vertical statusbar?

That'd be great!

I tried adding context.rotate(PI / 2.), and it rotates the background rectangle, but there's no text visible.

If I add a context.rotate() in Text::compute() and ComputedText::render() immediately after creating each context, I get rotated text. (I don't have all your other changes though, so the text quickly goes out of the bounds of the bar).

Where are you trying the context.rotate()?

Do you have any advice on the best way to implement it, without making a mess of your existing code?

It'd be nice if there were a way for it to keep all the rendering horizontal but then have it all magically translated, but I can't see an easy way to do that with Cairo.

I think you're on the right track. I think once you get the text actually rendering vertically, it'll mostly be a case of doing something like:

  • Updating Bar::redraw_entire_bar() to refer to space_per_stretched and then switch between calculating width/height based on whether the bar is vertical or horizontal.
  • Updating the calculation for redraw_entire_bar in Bar::update_widget_contents() to look for changes to (not_stretch && diff_height) for vertical bars.

... but don't worry about messing that existing code up too much: those two functions are a bit of a mess anyway, so you might even improve them. If you manage to get something working, please do raise a PR and we can discuss anything you're unsure or unhappy with.

@mjkillough
Copy link
Owner

In case you haven't found it, the Gnome documentation for Cairo is pretty good: https://www.cairographics.org/documentation/cairomm/reference/classCairo_1_1Context.html#a332811cd74028c20b5832501ec46d67e

It's usually obvious how to translate it to the Rust bindings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants