mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Start experimenting with replicating main menu
This commit is contained in:
parent
0305c1979a
commit
6a4b7b70c2
@ -4,7 +4,7 @@ use crate::{
|
||||
ui::{
|
||||
self,
|
||||
fonts::ConrodVoxygenFonts,
|
||||
ice::IcedUi,
|
||||
ice::{Element, IcedUi},
|
||||
img_ids::{BlankGraphic, ImageGraphic, VoxelGraphic},
|
||||
Graphic, Ui,
|
||||
},
|
||||
@ -19,7 +19,7 @@ use conrod_core::{
|
||||
widget::{text_box::Event as TextBoxEvent, Button, Image, List, Rectangle, Text, TextBox},
|
||||
widget_ids, Borderable, Color, Colorable, Labelable, Positionable, Sizeable, Widget,
|
||||
};
|
||||
use iced::Column;
|
||||
use iced::{Column, Row};
|
||||
use image::DynamicImage;
|
||||
use rand::{seq::SliceRandom, thread_rng, Rng};
|
||||
use std::time::Duration;
|
||||
@ -193,12 +193,19 @@ struct IcedState {
|
||||
}
|
||||
pub type Message = Event;
|
||||
impl IcedState {
|
||||
pub fn view(&mut self) -> iced::Column<Message, ui::ice::IcedRenderer> {
|
||||
Column::new().push(ui::ice::Image::new(
|
||||
(self.imgs.bg, ui::Rotation::None),
|
||||
500.0,
|
||||
500.0,
|
||||
))
|
||||
pub fn view(&mut self) -> Element<Message> {
|
||||
use iced::Length;
|
||||
|
||||
let image1 = ui::ice::Image::new((self.imgs.bg, ui::Rotation::None));
|
||||
let image2 = ui::ice::Image::new((self.imgs.bg, ui::Rotation::None));
|
||||
let image3 = ui::ice::Image::new((self.imgs.bg, ui::Rotation::None));
|
||||
|
||||
Row::with_children(vec![image1.into(), image2.into(), image3.into()])
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.spacing(20)
|
||||
.padding(20)
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn update(message: Message) {
|
||||
|
@ -16,9 +16,11 @@ use super::{
|
||||
};
|
||||
use crate::{render::Renderer, window::Window, Error};
|
||||
use clipboard::Clipboard;
|
||||
use iced::{Cache, Element, MouseCursor, Size, UserInterface};
|
||||
use iced::{Cache, MouseCursor, Size, UserInterface};
|
||||
use vek::*;
|
||||
|
||||
pub type Element<'a, M> = iced::Element<'a, M, IcedRenderer>;
|
||||
|
||||
pub struct IcedUi {
|
||||
renderer: IcedRenderer,
|
||||
cache: Option<Cache>,
|
||||
@ -87,7 +89,7 @@ impl IcedUi {
|
||||
}
|
||||
|
||||
// TODO: produce root internally???
|
||||
pub fn maintain<'a, M, E: Into<Element<'a, M, IcedRenderer>>>(
|
||||
pub fn maintain<'a, M, E: Into<Element<'a, M>>>(
|
||||
&mut self,
|
||||
root: E,
|
||||
renderer: &mut Renderer,
|
||||
|
@ -1,5 +1,6 @@
|
||||
mod column;
|
||||
mod image;
|
||||
mod row;
|
||||
|
||||
use super::{
|
||||
super::{
|
||||
@ -255,7 +256,7 @@ impl IcedRenderer {
|
||||
// let color =
|
||||
// srgba_to_linear(color.unwrap_or(conrod_core::color::WHITE).to_fsa().
|
||||
// into());
|
||||
let color = Rgba::from([1.0, 1.0, 1.0, 1.0]);
|
||||
let color = Rgba::from([1.0, 0.0, 1.0, 0.5]);
|
||||
|
||||
let resolution = Vec2::new(
|
||||
(gl_aabr.size().w * self.half_res.x).round() as u16,
|
||||
|
@ -5,7 +5,7 @@ impl column::Renderer for IcedRenderer {
|
||||
fn draw<M>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
content: &[Element<'_, M, Self>],
|
||||
children: &[Element<'_, M, Self>],
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
) -> Self::Output {
|
||||
@ -13,7 +13,7 @@ impl column::Renderer for IcedRenderer {
|
||||
|
||||
(
|
||||
Primitive::Group {
|
||||
primitives: content
|
||||
primitives: children
|
||||
.iter()
|
||||
.zip(layout.children())
|
||||
.map(|(child, layout)| {
|
||||
|
@ -10,13 +10,29 @@ pub type Handle = (graphic::Id, Rotation);
|
||||
|
||||
pub struct Image {
|
||||
handle: Handle,
|
||||
size: Size,
|
||||
width: Length,
|
||||
height: Length,
|
||||
}
|
||||
|
||||
impl Image {
|
||||
pub fn new(handle: Handle, w: f32, h: f32) -> Self {
|
||||
let size = Size::new(w, h);
|
||||
Self { handle, size }
|
||||
pub fn new(handle: Handle) -> Self {
|
||||
let width = Length::Fill;
|
||||
let height = Length::Fill;
|
||||
Self {
|
||||
handle,
|
||||
width,
|
||||
height,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,15 +40,15 @@ impl<M, R> Widget<M, R> for Image
|
||||
where
|
||||
R: self::Renderer,
|
||||
{
|
||||
fn width(&self) -> Length { Length::Fill }
|
||||
fn width(&self) -> Length { self.width }
|
||||
|
||||
fn height(&self) -> Length { Length::Fill }
|
||||
fn height(&self) -> Length { self.height }
|
||||
|
||||
fn layout(&self, _renderer: &R, _limits: &layout::Limits) -> layout::Node {
|
||||
fn layout(&self, _renderer: &R, limits: &layout::Limits) -> layout::Node {
|
||||
// We don't care about aspect ratios here :p
|
||||
layout::Node::new(self.size)
|
||||
// Infinite sizes confusing
|
||||
//layout::Node::new(limits.resolve(self.size))
|
||||
let size = limits.width(self.width).height(self.height).max();
|
||||
|
||||
layout::Node::new(size)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
@ -46,8 +62,8 @@ where
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
self.size.width.to_bits().hash(state);
|
||||
self.size.height.to_bits().hash(state);
|
||||
self.width.hash(state);
|
||||
self.height.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user