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

Improvements to the StatusView #852

Merged
merged 10 commits into from
Feb 28, 2022
Merged

Conversation

jgmdev
Copy link
Member

@jgmdev jgmdev commented Feb 21, 2022

Features implemented:

  • Support for predicates by introducing add_item().
  • Support for performing click actions on items.
  • Support for optional tooltips on item hover.
  • Deprecate the usage of get_item().

Other stuff for the future that I'm not sure could implement now:

  • Hide items that are too huge by rendering with clip_rect
  • Ability to drag the left or right if too many items to display.
  • Properly detect the visible part of an item for click and mouse hover events.

Demonstration

statusview-changes.mp4

* Support for predicates by introducing add_item().
* Support for performing click actions on items.
* Support for optional tooltips on item hover.
* Deprecate the usage of get_item().
@jgmdev
Copy link
Member Author

jgmdev commented Feb 21, 2022

Forgot to mention that I also documented parts of the StatusView code using EmmyLua which can serve as an experiment of how one would document the core code directly.

* Items are now objects that can be retrieved and manipulated.
* clip rect is used for left and right panes
* initial support for items to do their own custom drawing by also
  doing a clip rect for them
* a custom background color can be specified for the item.
* a command or function can be executed on item click.
* Introduced functionality to easily hide or show all or specific items.
* Better handling of deprecated get_items()
* Spacing is automatically added to items and cleaned on deprecated
  items.
* Default items where separated and given the names:
  doc:file, doc:position, doc:indentation, doc:lines,
  doc:line-ending, core.commandview.
* Some default right or left click actions where given to the default
  items.
* Started adding required bits to support dragging to left and right
  panes when some items aren't visible.

Note: should work well enough already but maybe some repetitive stuff can be
cleaned out.
@jgmdev
Copy link
Member Author

jgmdev commented Feb 23, 2022

Restructured almost everything that I did before, borrowed some ideas from vsc statusbar api and Implemented some more features as described on latest commit, for convenience will also paste them here:

  • Items are now objects that can be retrieved and manipulated.
  • clip rect is used for left and right panes
  • initial support for items to do their own custom drawing (this was takase idea) by also doing a clip rect for them
  • a custom background color can be specified for the item.
  • a command or function can be executed on item click.
  • Introduced functionality to easily hide or show all or specific items.
  • Better handling of deprecated get_items()
  • Spacing is automatically added to items and cleaned on deprecated items.
  • Default items where separated and given the names: doc:file, doc:position, doc:indentation, doc:lines, doc:line-ending, core.commandview.
  • Some default right or left click actions where given to the default items.
  • Started adding required bits to support dragging to left and right panes when some items aren't visible.

Note: should work well enough already but maybe some repetitive stuff can be cleaned out.

Also here a screen capture showing some of the things that can be done now:

statusview-latest.mp4

@jgmdev jgmdev force-pushed the statusview-enhacements branch from c11f447 to 3452d49 Compare February 23, 2022 10:08
@jgmdev
Copy link
Member Author

jgmdev commented Feb 23, 2022

Dragging and scrolling left or right panels is now supported, now last missing bit is detecting the visible area of an item for click and mouse hover events:

statusview-drag-scroll.mp4

@jgmdev jgmdev force-pushed the statusview-enhacements branch from 20dc06b to ae8890f Compare February 24, 2022 07:50
@jgmdev jgmdev force-pushed the statusview-enhacements branch from ae8890f to 128e10b Compare February 24, 2022 17:58
@jgmdev
Copy link
Member Author

jgmdev commented Feb 25, 2022

For reference, leaving some sample code on how to do custom drawing into the status bar:

if not core.status_view:get_item("my:custom-item") then
  local item = core.status_view:add_item(nil, "my:custom-item", StatusView.Item.LEFT)
  item.on_draw = function(x, y, h, calc_only)
    --true when the status bar needs to know the width of drawing area
    if calc_only then
      return 100
    end
    --if calc_only not true is time to draw
    renderer.draw_text(style.font, "Hello", x, y, style.text)
  end
  item.background_color = { common.color "#0f6773" }
  item.tooltip = "my item"
end

Copy link
Member

@Guldoman Guldoman left a comment

Choose a reason for hiding this comment

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

What do you think about having an hovered background color for items with on_click commands?
If so, an Item.background_color_hovered would be needed. Also the hovered status should be passed to on_draw.

This isn't too important, but resizing doesn't gracefully update the scrolled position:

ugly_resize.mp4

---@return table right
function StatusView:get_items(nowarn)
if not nowarn and not self.get_items_warn then
core.error(
Copy link
Member

Choose a reason for hiding this comment

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

We should really add a warning log level.

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, and change the error icon maybe to X and use the error icon ! for warnings with some orange or yellow color.

@jgmdev
Copy link
Member Author

jgmdev commented Feb 28, 2022

What do you think about having an hovered background color for items with on_click commands? If so, an Item.background_color_hovered would be needed. Also the hovered status should be passed to on_draw.

Implemented:

statusview-hoverbg.mp4

This isn't too important, but resizing doesn't gracefully update the scrolled position:

Fixed (sorry for flickering on preview seems my mesa opengl driver has wayland issues with sdl when doing that):

statusview-resizing.mp4

@jgmdev jgmdev merged commit be5f94e into lite-xl:master Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants