My libcosmic calculator is now an MVP.

I have written a calculator in Rust and libcosmic, the design is copied from gnome-calculator; I discovered 2 things:

  1. I don't like working on UIs.
  2. I have no idea how to transform

cosmic::widget::button::Builder

to

cosmic::widget::Button;

this code would be so much cleaner if I could return a button::standard() from a function.

The source code.

23 points · 2 comments · view on lemmy.world

2 Comments

edfloreshz@lemmy.ml · 4 pts · 2y

Very nice work! Consider adding your project to COSMIC Project Collection.

https://github.com/edfloreshz/cosmic-project-collection

mmstick@lemmy.world · 3 pts · 2y

You can either return cosmic::Element<Message>, impl Into<cosmic::Element<Message>>, or cosmic::widget::Button<Message> with your functions.

Every widget can .into() or .apply(Element::from) into a cosmic::Element.

I'd recommend using the Grid widget so that your buttons can scale with the window.

cosmic::widget::grid()
    .push(widget1())
    .push(widget2())
    .push(widget3())
    .insert_row()
    .push(widget4())
    .push(widget5())
    .push(widget6())
    .row_spacing(12)
    .column_spacing(12)
    .justify_content(JustifyContent::Stretch)
    .width(Length::Fill)
    .height(Length::Fill)
    .into()