Crate carnelian

Source
Expand description

Carnelian

Carnelian is a prototype framework for writing Fuchsia applications in Rust.

Below is a tiny example of a Carnelian app.

The ViewAssistant trait is a good place to start when learning about Carnelian.

use anyhow::Error;
use carnelian::{
    make_app_assistant,
    render::{self},
    App, AppAssistant, ViewAssistant, ViewAssistantContext, ViewAssistantPtr, ViewKey,
};
use zx::Event;

#[derive(Default)]
struct SampleAppAssistant;

impl AppAssistant for SampleAppAssistant {
    fn setup(&mut self) -> Result<(), Error> {
        Ok(())
    }

    fn create_view_assistant(&mut self, _: ViewKey) -> Result<ViewAssistantPtr, Error> {
        SampleViewAssistant::new()
    }
}

struct SampleViewAssistant;

impl SampleViewAssistant {
    fn new() -> Result<ViewAssistantPtr, Error> {
        Ok(Box::new(Self {}))
    }
}

impl ViewAssistant for SampleViewAssistant {
    fn render(
        &mut self,
        _render_context: &mut render::Context,
        _buffer_ready_event: Event,
        _view_context: &ViewAssistantContext,
    ) -> Result<(), Error> {
        Ok(())
    }
}

fn main() -> Result<(), Error> {
    App::run(make_app_assistant::<SampleAppAssistant>())
}

Re-exports§

Modules§

  • Application related items
  • Color-related items
  • Drawing-related items Functions for drawing in Carnelian Carnelian uses the Render abstraction over Forma and Spinel to put pixels on screen. The items in this module are higher- level drawing primitives.
  • Geometry-related items.
  • Input-related items.
  • Extension items related to input.
  • Render-related items.
  • UI item abstraction

Macros§

  • Macro to implement a handle message trait method that delegates known types to other methods on the struct implementing ViewAssistant.
  • Macro to implement a handle message trait method that delegates known types to other methods on the struct implementing ViewAssistant.

Structs§

Traits§

  • Trait that allows Carnelian developers to customize the behavior of views.

Functions§

Type Aliases§

  • Message type
  • Reference to a view assistant. This type is likely to change in the future so using this type alias might make for easier forward migration.