Remove text widget and add limit-width attribute to label

This commit is contained in:
elkowar 2020-10-20 21:39:54 +02:00
parent ca079d149d
commit 715e8e6ecc
3 changed files with 7 additions and 15 deletions

View file

@ -148,12 +148,12 @@ impl EwwState {
&mut self,
window_name: &WindowName,
local_env: &HashMap<VarName, AttrValue>,
attributes: HashMap<AttrName, AttrValue>,
required_attributes: HashMap<AttrName, AttrValue>,
set_value: F,
) {
let handler = StateChangeHandler {
func: Box::new(set_value),
unresolved_values: attributes
unresolved_values: required_attributes
.into_iter()
.map(|(attr_name, attr_value)| (attr_name, attr_value.resolve_one_level(local_env)))
.collect(),

View file

@ -6,7 +6,7 @@ use super::*;
/// A value assigned to an attribute in a widget.
/// This can be a primitive String that contains any amount of variable
/// references, as would be generated by the string "foo {{var}} bar".
#[derive(Serialize, Deserialize, Clone, PartialEq, derive_more::Into, derive_more::From)]
#[derive(Serialize, Deserialize, Clone, PartialEq, derive_more::Into, derive_more::From, Default)]
pub struct AttrValue(Vec<AttrValueElement>);
impl fmt::Debug for AttrValue {

View file

@ -1,11 +1,10 @@
use super::{run_command, BuilderArgs};
use crate::{config, eww_state, resolve_block, value::AttrValue};
use anyhow::*;
use gdk_pixbuf;
use gtk::{prelude::*, ImageExt};
use std::{cell::RefCell, rc::Rc};
use gdk_pixbuf;
// TODO figure out how to
// TODO https://developer.gnome.org/gtk3/stable/GtkFixed.html
@ -18,7 +17,6 @@ pub(super) fn widget_to_gtk_widget(bargs: &mut BuilderArgs) -> Result<Option<gtk
"image" => build_gtk_image(bargs)?.upcast(),
"button" => build_gtk_button(bargs)?.upcast(),
"label" => build_gtk_label(bargs)?.upcast(),
"text" => build_gtk_text(bargs)?.upcast(),
"literal" => build_gtk_literal(bargs)?.upcast(),
"input" => build_gtk_input(bargs)?.upcast(),
"calendar" => build_gtk_calendar(bargs)?.upcast(),
@ -270,19 +268,13 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result<gtk::Label> {
let gtk_widget = gtk::Label::new(None);
resolve_block!(bargs, gtk_widget, {
// @prop - the text to display
prop(text: as_string) { gtk_widget.set_text(&text) },
prop(text: as_string, limit_width: as_i32 = i32::MAX) {
gtk_widget.set_text(&text.chars().take(limit_width as usize).collect::<String>())
},
});
Ok(gtk_widget)
}
/// @widget text
fn build_gtk_text(_bargs: &mut BuilderArgs) -> Result<gtk::Box> {
let gtk_widget = gtk::Box::new(gtk::Orientation::Horizontal, 0);
gtk_widget.set_halign(gtk::Align::Center);
gtk_widget.set_homogeneous(false);
Ok(gtk_widget)
}
/// @widget literal
/// @desc a tag that allows you to render arbitrary XML.
fn build_gtk_literal(bargs: &mut BuilderArgs) -> Result<gtk::Frame> {