Rebrand to Galaxy, major improvements to Bedrock support, still needs some TLC though
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use std::borrow::Cow;
|
||||
pub mod root_view;
|
||||
|
||||
extern crate galaxyui;
|
||||
use rust_embed::RustEmbed;
|
||||
use galaxyui::{platform, AssetProvider};
|
||||
|
||||
#[derive(Clone, Copy, RustEmbed)]
|
||||
#[folder = "examples/assets"]
|
||||
pub struct Assets;
|
||||
|
||||
// The static assets we need to load in app.
|
||||
pub static ASSETS: Assets = Assets;
|
||||
|
||||
// Implement the AssetProvider trait here (required by App::new).
|
||||
impl AssetProvider for Assets {
|
||||
fn get(&self, path: &str) -> Result<Cow<'_, [u8]>> {
|
||||
<Assets as RustEmbed>::get(path)
|
||||
.map(|f| f.data)
|
||||
.ok_or_else(|| anyhow!("no asset exists at path {}", path))
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let app_builder =
|
||||
platform::AppBuilder::new(platform::AppCallbacks::default(), Box::new(ASSETS), None);
|
||||
let _ = app_builder.run(move |ctx| {
|
||||
ctx.add_window(
|
||||
galaxyui::AddWindowOptions::default(),
|
||||
root_view::RootView::new,
|
||||
);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
use galaxyui::elements::ClippedScrollStateHandle;
|
||||
use galaxyui::elements::ClippedScrollable;
|
||||
|
||||
use galaxyui::{
|
||||
elements::{ConstrainedBox, Container, Flex, ParentElement, Rect, ScrollbarWidth, Stack},
|
||||
AppContext, Element, Entity, TypedActionView, View, ViewContext,
|
||||
};
|
||||
|
||||
use galaxyui::color::ColorU;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RootView {
|
||||
pub clipped_scroll_state: ClippedScrollStateHandle,
|
||||
}
|
||||
|
||||
impl RootView {
|
||||
pub fn new(_ctx: &mut ViewContext<Self>) -> Self {
|
||||
RootView::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Entity for RootView {
|
||||
type Event = ();
|
||||
}
|
||||
impl View for RootView {
|
||||
fn ui_name() -> &'static str {
|
||||
"RootView"
|
||||
}
|
||||
|
||||
fn render(&self, _: &AppContext) -> Box<dyn Element> {
|
||||
let mut column = Flex::column();
|
||||
|
||||
// Create 10 rows, where each row has 10 rectanges (each of size 50*50).
|
||||
// By the end, `column` will be 500 * 500.
|
||||
for i in 0..10 {
|
||||
let mut row = Flex::row();
|
||||
for j in 0..10 {
|
||||
let color = (i + j) % 3;
|
||||
let color = if color == 0 {
|
||||
ColorU::new(255, 0, 0, 255)
|
||||
} else if color == 1 {
|
||||
ColorU::new(0, 255, 0, 255)
|
||||
} else {
|
||||
ColorU::new(0, 0, 255, 255)
|
||||
};
|
||||
|
||||
row.add_child(
|
||||
Container::new(
|
||||
ConstrainedBox::new(Rect::new().finish())
|
||||
.with_height(50.)
|
||||
.with_width(50.)
|
||||
.finish(),
|
||||
)
|
||||
.with_background_color(color)
|
||||
.finish(),
|
||||
);
|
||||
}
|
||||
column.add_child(row.finish());
|
||||
}
|
||||
|
||||
// Change this to [`ClippedScrollable::vertical`] to see what a vertically scrollable element looks like.
|
||||
let horizontally_scrollable = ClippedScrollable::horizontal(
|
||||
self.clipped_scroll_state.clone(),
|
||||
column.finish(),
|
||||
ScrollbarWidth::Auto,
|
||||
ColorU::white().into(),
|
||||
ColorU::white().into(),
|
||||
ColorU::new(100, 100, 100, 255).into(),
|
||||
);
|
||||
|
||||
let constrained = ConstrainedBox::new(horizontally_scrollable.finish())
|
||||
.with_height(250.)
|
||||
.with_width(250.);
|
||||
|
||||
Stack::new()
|
||||
.with_child(Rect::new().with_background_color(ColorU::black()).finish())
|
||||
.with_child(constrained.finish())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl TypedActionView for RootView {
|
||||
type Action = ();
|
||||
}
|
||||
Reference in New Issue
Block a user